[Ocfs2-tools-devel] [PATCH 48/50] fswreck: add corruption for rf_clusters.

Tao Ma tao.ma at oracle.com
Mon Jan 11 07:31:34 PST 2010


fswreck: add corruption for rf_clusters.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 fswreck/corrupt.c           |    3 ++
 fswreck/include/fsck_type.h |    2 +
 fswreck/include/refcount.h  |    2 +
 fswreck/main.c              |    2 +
 fswreck/refcount.c          |   44 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index df3cdad..3dd2c40 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -487,6 +487,9 @@ void corrupt_refcount(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
 	case REFCOUNT_LIST_EMPTY:
 		func = mess_up_refcount_tree_block;
 		break;
+	case REFCOUNT_CLUSTERS:
+		func = mess_up_refcount_tree;
+		break;
 	default:
 		FSWRK_FATAL("Invalid code = %d", type);
 	}
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 7781a26..8a9d92c 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -148,6 +148,7 @@ enum fsck_type
 	REFCOUNT_CLUSTER_RANGE,
 	REFCOUNT_CLUSTER_COLLISION,
 	REFCOUNT_LIST_EMPTY,
+	REFCOUNT_CLUSTERS,
 	NUM_FSCK_TYPE
 };
 
@@ -239,5 +240,6 @@ enum fsck_type
  *			REFCOUNT_ROOT_BLOCK_INVALID, REFCOUNT_LIST_COUNT,
  *			REFCOUNT_LIST_USED, REFCOUNT_CLUSTER_RANGE,
  *			REFCOUNT_CLUSTER_COLLISION, REFCOUNT_LIST_EMPTY
+ *			REFCOUNT_CLUSTERS
  */
 #endif
diff --git a/fswreck/include/refcount.h b/fswreck/include/refcount.h
index ab4967e..9eee1c0 100644
--- a/fswreck/include/refcount.h
+++ b/fswreck/include/refcount.h
@@ -20,4 +20,6 @@
 
 void mess_up_refcount_tree_block(ocfs2_filesys *fs, enum fsck_type type,
 				 uint64_t blkno);
+void mess_up_refcount_tree(ocfs2_filesys *fs, enum fsck_type type,
+			   uint64_t blkno);
 #endif		/* _FSWRECK_REFCOUNT_H_ */
diff --git a/fswreck/main.c b/fswreck/main.c
index 68b390a..0e8ca45 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -288,6 +288,8 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 			   "corrupt the refcount list in a refcount block"),
 	define_prompt_code(REFCOUNT_LIST_EMPTY, corrupt_refcount,
 			   "corrupt the refcount list in a refcount block"),
+	define_prompt_code(REFCOUNT_CLUSTERS, corrupt_refcount,
+			   "corrupt the rf_clusters for a refcount tree"),
 };
 
 #undef define_prompt_code
diff --git a/fswreck/refcount.c b/fswreck/refcount.c
index 816e663..f8d38d3 100644
--- a/fswreck/refcount.c
+++ b/fswreck/refcount.c
@@ -313,3 +313,47 @@ void mess_up_refcount_tree_block(ocfs2_filesys *fs, enum fsck_type type,
 
 	return;
 }
+
+void mess_up_refcount_tree(ocfs2_filesys *fs, enum fsck_type type,
+			   uint64_t blkno)
+{
+	errcode_t ret;
+	char *buf = NULL;
+	uint64_t rf_blkno;
+	uint32_t oldno;
+	struct ocfs2_refcount_block *rb;
+
+	if (!ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
+		FSWRK_FATAL("Should specify a refcount supported "
+			    "volume to do this corruption\n");
+
+	ret = ocfs2_malloc_block(fs->fs_io, &buf);
+	if (ret)
+		FSWRK_COM_FATAL(progname, ret);
+
+	create_refcount_tree(fs, blkno, &rf_blkno, 2);
+
+	ret = ocfs2_read_refcount_block(fs, rf_blkno, buf);
+	if (ret)
+		FSWRK_COM_FATAL(progname, ret);
+	rb = (struct ocfs2_refcount_block *)buf;
+
+	switch (type) {
+	case REFCOUNT_CLUSTERS:
+		oldno = rb->rf_clusters;
+		rb->rf_clusters = 1;
+		fprintf(stdout, "REFCOUNT_CLUSTERS: Corrupt refcount block #"
+			"%"PRIu64", change rf_clusters from %u to %u\n",
+			(uint64_t)rb->rf_blkno, oldno, rb->rf_clusters);
+		break;
+	default:
+		FSWRK_FATAL("Invalid type[%d]\n", type);
+	}
+
+	ret = ocfs2_write_refcount_block(fs, rf_blkno, buf);
+	if (ret)
+		FSWRK_COM_FATAL(progname, ret);
+	ocfs2_free(&buf);
+
+	return;
+}
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list