[Ocfs2-tools-devel] [PATCH 31/32] debugfs.ocfs2: Improve block detection

Sunil Mushran sunil.mushran at oracle.com
Tue Sep 14 15:55:01 PDT 2010


The journal dump command now detects refcount, dxroot, dxleaf and xattr blocks.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 debugfs.ocfs2/dump.c         |   38 +++++++++++++++++++++++++++++++++++++-
 debugfs.ocfs2/include/dump.h |    5 +++++
 debugfs.ocfs2/journal.c      |   32 ++++++++++++++++++++++++++++++++
 include/ocfs2/ocfs2.h        |    3 +++
 libocfs2/dirblock.c          |    6 +++---
 5 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/debugfs.ocfs2/dump.c b/debugfs.ocfs2/dump.c
index d56121e..b392c10 100644
--- a/debugfs.ocfs2/dump.c
+++ b/debugfs.ocfs2/dump.c
@@ -870,6 +870,11 @@ void dump_jbd_metadata (FILE *out, enum dump_block_type type, char *buf,
 			uint64_t blknum)
 {
 	struct ocfs2_dir_block_trailer *trailer;
+	struct ocfs2_xattr_block *xb;
+	struct ocfs2_xattr_header *xh;
+	struct ocfs2_refcount_block *rb;
+	struct ocfs2_dx_root_block *dx_root;
+	struct ocfs2_dx_leaf *dx_leaf;
 
 	fprintf (out, "\tBlock %"PRIu64": ", blknum);
 	switch (type) {
@@ -906,6 +911,37 @@ void dump_jbd_metadata (FILE *out, enum dump_block_type type, char *buf,
 		dump_dir_block(out, buf);
 		fprintf (out, "\n");
 		break;
+	case DUMP_BLOCK_XATTR:
+		fprintf(out, "Xattr\n");
+		xb = (struct ocfs2_xattr_block *)buf;
+		ocfs2_swap_xattr_block_to_cpu(gbls.fs, xb);
+		if (!(xb->xb_flags & OCFS2_XATTR_INDEXED)) {
+			xh = &xb->xb_attrs.xb_header;
+			dump_xattr(out, xh);
+		}
+		fprintf (out, "\n");
+		break;
+	case DUMP_BLOCK_REFCOUNT:
+		fprintf(out, "Refcount\n");
+		rb = (struct ocfs2_refcount_block *)buf;
+		ocfs2_swap_refcount_block_to_cpu(gbls.fs, rb);
+		dump_refcount_block(out, rb);
+		fprintf (out, "\n");
+		break;
+	case DUMP_BLOCK_DXROOT:
+		fprintf(out, "DxRoot\n");
+		dx_root = (struct ocfs2_dx_root_block *)buf;
+		ocfs2_swap_dx_root_to_cpu(gbls.fs, dx_root);
+		dump_dx_root(out, dx_root);
+		fprintf (out, "\n");
+		break;
+	case DUMP_BLOCK_DXLEAF:
+		fprintf(out, "DxLeaf\n");
+		dx_leaf = (struct ocfs2_dx_leaf *)buf;
+		ocfs2_swap_dx_leaf_to_cpu(dx_leaf);
+		dump_dx_leaf(out, dx_leaf);
+		fprintf (out, "\n");
+		break;
 	default:
 		fprintf (out, "TODO\n\n");
 		break;
@@ -1023,7 +1059,7 @@ void dump_icheck(FILE *out, int hdr, uint64_t blkno, uint64_t inode,
 	fprintf(out, "\t%-15"PRIu64"   %-15s   %-15s\n", blkno, inostr, offstr);
 }
 
-static void dump_xattr(FILE *out, struct ocfs2_xattr_header *xh)
+void dump_xattr(FILE *out, struct ocfs2_xattr_header *xh)
 {
 	int i;
 
diff --git a/debugfs.ocfs2/include/dump.h b/debugfs.ocfs2/include/dump.h
index e8bbf74..0b4d250 100644
--- a/debugfs.ocfs2/include/dump.h
+++ b/debugfs.ocfs2/include/dump.h
@@ -26,6 +26,10 @@ enum dump_block_type {
 	DUMP_BLOCK_EXTENT_BLOCK,
 	DUMP_BLOCK_GROUP_DESCRIPTOR,
 	DUMP_BLOCK_DIR_BLOCK,
+	DUMP_BLOCK_XATTR,
+	DUMP_BLOCK_REFCOUNT,
+	DUMP_BLOCK_DXROOT,
+	DUMP_BLOCK_DXLEAF,
 };
 
 typedef struct _list_dir_opts {
@@ -76,6 +80,7 @@ void dump_icheck(FILE *out, int hdr, uint64_t blkno, uint64_t inode,
 void dump_block_check(FILE *out, struct ocfs2_block_check *bc, void *block);
 uint32_t dump_xattr_ibody(FILE *out, ocfs2_filesys *fs,
 			  struct ocfs2_dinode *in, int verbose);
+void dump_xattr(FILE *out, struct ocfs2_xattr_header *xh);
 errcode_t dump_xattr_block(FILE *out, ocfs2_filesys *fs,
 			   struct ocfs2_dinode *in,
 			   uint32_t *xattrs_block,
diff --git a/debugfs.ocfs2/journal.c b/debugfs.ocfs2/journal.c
index 0343d77..8f36317 100644
--- a/debugfs.ocfs2/journal.c
+++ b/debugfs.ocfs2/journal.c
@@ -167,6 +167,10 @@ static enum dump_block_type detect_block (char *buf)
 	struct ocfs2_extent_block *extent;
 	struct ocfs2_group_desc *group;
 	struct ocfs2_dir_block_trailer *trailer;
+	struct ocfs2_xattr_block *xb;
+	struct ocfs2_refcount_block *rb;
+	struct ocfs2_dx_root_block *dx_root;
+	struct ocfs2_dx_leaf *dx_leaf;
 	enum dump_block_type ret = DUMP_BLOCK_UNKNOWN;
 
 	inode = (struct ocfs2_dinode *)buf;
@@ -197,6 +201,34 @@ static enum dump_block_type detect_block (char *buf)
 		goto bail;
 	}
 
+	xb = (struct ocfs2_xattr_block *)buf;
+	if (!strncmp((char *)xb->xb_signature, OCFS2_XATTR_BLOCK_SIGNATURE,
+		     sizeof(xb->xb_signature))) {
+		ret = DUMP_BLOCK_XATTR;
+		goto bail;
+	}
+
+	rb = (struct ocfs2_refcount_block *)buf;
+	if (!strncmp((char *)rb->rf_signature, OCFS2_REFCOUNT_BLOCK_SIGNATURE,
+		     sizeof(rb->rf_signature))) {
+		ret = DUMP_BLOCK_REFCOUNT;
+		goto bail;
+	}
+
+	dx_root = (struct ocfs2_dx_root_block *)buf;
+	if (!strncmp((char *)dx_root->dr_signature, OCFS2_DX_ROOT_SIGNATURE,
+		     strlen(OCFS2_DX_ROOT_SIGNATURE))) {
+		ret = DUMP_BLOCK_DXROOT;
+		goto bail;
+	}
+
+	dx_leaf = (struct ocfs2_dx_leaf *)buf;
+	if (!strncmp(dx_leaf->dl_signature, OCFS2_DX_LEAF_SIGNATURE,
+		     strlen(OCFS2_DX_LEAF_SIGNATURE))) {
+		ret = DUMP_BLOCK_DXLEAF;
+		goto bail;
+	}
+
 bail:
 	return ret;
 }				/* detect_block */
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index 285970b..57aa078 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -499,6 +499,9 @@ int ocfs2_skip_dir_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 			   struct ocfs2_dir_entry *de, unsigned long offset);
 void ocfs2_init_dir_trailer(ocfs2_filesys *fs, struct ocfs2_dinode *di,
 			    uint64_t blkno, void *buf);
+void ocfs2_swap_dx_root_to_cpu(ocfs2_filesys *fs,
+			       struct ocfs2_dx_root_block *dx_root);
+void ocfs2_swap_dx_leaf_to_cpu(struct ocfs2_dx_leaf *dx_leaf);
 errcode_t ocfs2_read_dx_root(ocfs2_filesys *fs, uint64_t block,
 			     void *buf);
 errcode_t ocfs2_read_dx_leaf(ocfs2_filesys *fs, uint64_t block,
diff --git a/libocfs2/dirblock.c b/libocfs2/dirblock.c
index 24afd8c..4594000 100644
--- a/libocfs2/dirblock.c
+++ b/libocfs2/dirblock.c
@@ -273,8 +273,8 @@ static void ocfs2_swap_dx_entry_list_from_cpu(struct ocfs2_dx_entry_list *dl_lis
 	dl_list->de_num_used = bswap_16(dl_list->de_num_used);
 }
 
-static void ocfs2_swap_dx_root_to_cpu(ocfs2_filesys *fs,
-				struct ocfs2_dx_root_block *dx_root)
+void ocfs2_swap_dx_root_to_cpu(ocfs2_filesys *fs,
+			       struct ocfs2_dx_root_block *dx_root)
 {
 	if (cpu_is_little_endian)
 		return;
@@ -387,7 +387,7 @@ out:
 	return ret;
 }
 
-static void ocfs2_swap_dx_leaf_to_cpu(struct ocfs2_dx_leaf *dx_leaf)
+void ocfs2_swap_dx_leaf_to_cpu(struct ocfs2_dx_leaf *dx_leaf)
 {
 	if (cpu_is_little_endian)
 		return;
-- 
1.7.0.4




More information about the Ocfs2-tools-devel mailing list