cluster-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Andrew Price <anprice@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [PATCH 5/7] gfs2_edit: Use the metadata description in get_block_type
Date: Fri, 28 Feb 2014 09:35:32 +0000	[thread overview]
Message-ID: <1393580134-21574-6-git-send-email-anprice@redhat.com> (raw)
In-Reply-To: <1393580134-21574-1-git-send-email-anprice@redhat.com>

Replace the large switch statement in get_block_type() with calls to
lgfs2_get_block_type() and lgfs2_find_mtype().

Signed-off-by: Andrew Price <anprice@redhat.com>
---
 gfs2/edit/hexedit.c | 68 ++++++-----------------------------------------------
 1 file changed, 7 insertions(+), 61 deletions(-)

diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 0aa0771..ac91c83 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -578,69 +578,15 @@ static void print_usage(void)
 /* ------------------------------------------------------------------------ */
 uint32_t get_block_type(const struct gfs2_buffer_head *lbh, int *structlen)
 {
-	const struct gfs2_meta_header *mh = lbh->iov.iov_base;
-	uint32_t ty;
+	uint32_t ty = lgfs2_get_block_type(lbh);
 
-	if (!be32_to_cpu(mh->mh_magic) == GFS2_MAGIC)
-		return 0;
-
-	ty = be32_to_cpu(mh->mh_type);
-	if (structlen == NULL)
-		return ty;
-	switch (ty) {
-	case GFS2_METATYPE_SB:   /* 1 */
-		if (sbd.gfs1)
-			*structlen = sizeof(struct gfs_sb);
-		else
-			*structlen = sizeof(struct gfs2_sb);
-		break;
-	case GFS2_METATYPE_RG:   /* 2 */
-		*structlen = sizeof(struct gfs2_rgrp);
-		break;
-	case GFS2_METATYPE_RB:   /* 3 */
-		*structlen = sizeof(struct gfs2_meta_header);
-		break;
-	case GFS2_METATYPE_DI:   /* 4 */
-		*structlen = sizeof(struct gfs2_dinode);
-		break;
-	case GFS2_METATYPE_IN:   /* 5 */
-		if (sbd.gfs1)
-			*structlen = sizeof(struct gfs_indirect);
-		else
-			*structlen = sizeof(struct gfs2_meta_header);
-		break;
-	case GFS2_METATYPE_LF:   /* 6 */
-		*structlen = sizeof(struct gfs2_leaf);
-		break;
-	case GFS2_METATYPE_JD:
-		*structlen = sizeof(struct gfs2_meta_header);
-		break;
-	case GFS2_METATYPE_LH:
-		*structlen = sizeof(struct gfs2_log_header);
-		break;
-	case GFS2_METATYPE_LD:
-		if (sbd.gfs1)
-			*structlen = sizeof(struct gfs_log_descriptor);
+	if (ty != 0 && structlen != NULL) {
+		unsigned ver = sbd.gfs1 ? LGFS2_MD_GFS1 : LGFS2_MD_GFS2;
+		const struct lgfs2_metadata *mtype = lgfs2_find_mtype(ty, ver);
+		if (mtype != NULL)
+			*structlen = mtype->size;
 		else
-			*structlen = sizeof(struct gfs2_log_descriptor);
-		break;
-	case GFS2_METATYPE_EA:
-		*structlen = sizeof(struct gfs2_meta_header) +
-			sizeof(struct gfs2_ea_header);
-		break;
-	case GFS2_METATYPE_ED:
-		*structlen = sizeof(struct gfs2_meta_header) +
-			sizeof(struct gfs2_ea_header);
-		break;
-	case GFS2_METATYPE_LB:
-		*structlen = sizeof(struct gfs2_meta_header);
-		break;
-	case GFS2_METATYPE_QC:
-		*structlen = sizeof(struct gfs2_quota_change);
-		break;
-	default:
-		*structlen = sbd.bsize;
-		break;
+			*structlen = sbd.bsize;
 	}
 	return ty;
 }
-- 
1.8.5.3



  parent reply	other threads:[~2014-02-28  9:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-28  9:35 [Cluster-devel] [PATCH 0/7] gfs2_edit journalX block reference feature and fixes Andrew Price
2014-02-28  9:35 ` [Cluster-devel] [PATCH 1/7] libgfs2: Remove another exit() call Andrew Price
2014-02-28  9:35 ` [Cluster-devel] [PATCH 2/7] gfs2-utils: Fix up some errors reported by clang Andrew Price
2014-02-28  9:35 ` [Cluster-devel] [PATCH 3/7] gfs2_edit: Separate out the journal-related functions to journal.c Andrew Price
2014-02-28  9:35 ` [Cluster-devel] [PATCH 4/7] gfs2_edit: Add more intelligence to journal dumps Andrew Price
2014-02-28  9:35 ` Andrew Price [this message]
2014-02-28  9:35 ` [Cluster-devel] [PATCH 6/7] gfs2_edit: Report referencing block address in the new journal code Andrew Price
2014-02-28  9:35 ` [Cluster-devel] [PATCH 7/7] gfs2_edit: More static analysis fixes Andrew Price
2014-03-03 16:57 ` [Cluster-devel] [PATCH] gfs2_edit: Corrections to log descriptor reference parsing Bob Peterson
2014-03-03 18:56   ` Andrew Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393580134-21574-6-git-send-email-anprice@redhat.com \
    --to=anprice@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).