[Ocfs2-tools-devel] [PATCH 49/50] fswreck: Add corruption for refcount record.

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


Add corruption for refcount record:
REFCOUNT_REC_REDUNDANT and REFCOUNT_COUNT_INVALID.

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

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 3dd2c40..51e3133 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -485,6 +485,8 @@ void corrupt_refcount(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
 	case REFCOUNT_CLUSTER_RANGE:
 	case REFCOUNT_CLUSTER_COLLISION:
 	case REFCOUNT_LIST_EMPTY:
+	case REFCOUNT_REC_REDUNDANT:
+	case REFCOUNT_COUNT_INVALID:
 		func = mess_up_refcount_tree_block;
 		break;
 	case REFCOUNT_CLUSTERS:
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 8a9d92c..d689171 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -149,6 +149,8 @@ enum fsck_type
 	REFCOUNT_CLUSTER_COLLISION,
 	REFCOUNT_LIST_EMPTY,
 	REFCOUNT_CLUSTERS,
+	REFCOUNT_REC_REDUNDANT,
+	REFCOUNT_COUNT_INVALID,
 	NUM_FSCK_TYPE
 };
 
@@ -240,6 +242,7 @@ enum fsck_type
  *			REFCOUNT_ROOT_BLOCK_INVALID, REFCOUNT_LIST_COUNT,
  *			REFCOUNT_LIST_USED, REFCOUNT_CLUSTER_RANGE,
  *			REFCOUNT_CLUSTER_COLLISION, REFCOUNT_LIST_EMPTY
- *			REFCOUNT_CLUSTERS
+ *			REFCOUNT_CLUSTERS, REFCOUNT_REC_REDUNDANT,
+ *			REFCOUNT_COUNT_INVALID
  */
 #endif
diff --git a/fswreck/main.c b/fswreck/main.c
index 0e8ca45..39196f8 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -290,6 +290,10 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 			   "corrupt the refcount list in a refcount block"),
 	define_prompt_code(REFCOUNT_CLUSTERS, corrupt_refcount,
 			   "corrupt the rf_clusters for a refcount tree"),
+	define_prompt_code(REFCOUNT_REC_REDUNDANT, corrupt_refcount,
+			   "corrupt the refcount record in a refcount block"),
+	define_prompt_code(REFCOUNT_COUNT_INVALID, corrupt_refcount,
+			   "corrupt the refcount record in a refcount block"),
 };
 
 #undef define_prompt_code
diff --git a/fswreck/refcount.c b/fswreck/refcount.c
index f8d38d3..b360f15 100644
--- a/fswreck/refcount.c
+++ b/fswreck/refcount.c
@@ -222,6 +222,40 @@ static void damage_refcount_list(ocfs2_filesys *fs, enum fsck_type type,
 		FSWRK_FATAL("Invalid type=%d", type);
 	}
 }
+
+static void damage_refcount_record(ocfs2_filesys *fs, enum fsck_type type,
+				   struct ocfs2_refcount_block *rb)
+{
+	uint32_t oldno;
+	uint64_t oldblkno;
+
+	switch (type) {
+	case REFCOUNT_REC_REDUNDANT:
+		oldblkno = rb->rf_records.rl_recs[0].r_cpos;
+		rb->rf_records.rl_recs[0].r_cpos = 1;
+		rb->rf_records.rl_recs[1].r_clusters += 1;
+		rb->rf_records.rl_recs[3].r_cpos -= 1;
+		rb->rf_records.rl_recs[3].r_clusters += 10;
+		fprintf(stdout, "REFCOUNT_REC_REDUNDANT: Corrupt refcount "
+			"record in block %"PRIu64", change recs[0].r_cpos "
+			"from %"PRIu64" to 1, add recs[1].r_clusters by 1,"
+			"decrease recs[3].r_cpos by 1 and "
+			"increase r_clusters by 100\n",
+			(uint64_t)rb->rf_blkno, oldblkno);
+		break;
+	case REFCOUNT_COUNT_INVALID:
+		oldno = rb->rf_records.rl_recs[0].r_refcount;
+		rb->rf_records.rl_recs[0].r_refcount = 100;
+		fprintf(stdout, "REFCOUNT_COUNT_INVALID: Corrupt refcount "
+			"record in block %"PRIu64", change recs[0].r_count "
+			"from %u to 100\n",
+			(uint64_t)rb->rf_blkno, oldno);
+		break;
+	default:
+		FSWRK_FATAL("Invalid type=%d", type);
+	}
+}
+
 void mess_up_refcount_tree_block(ocfs2_filesys *fs, enum fsck_type type,
 				 uint64_t blkno)
 {
@@ -294,6 +328,11 @@ void mess_up_refcount_tree_block(ocfs2_filesys *fs, enum fsck_type type,
 		damage_refcount_list(fs, type, rb1);
 		damage_refcount_list(fs, type, rb2_leaf);
 		break;
+	case REFCOUNT_REC_REDUNDANT:
+	case REFCOUNT_COUNT_INVALID:
+		damage_refcount_record(fs, type, rb1);
+		damage_refcount_record(fs, type, rb2_leaf);
+		break;
 	default:
 		FSWRK_FATAL("Invalid type[%d]\n", type);
 	}
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list