[Ocfs2-tools-devel] [PATCH 45/50] fswreck: Add inode corruptions.

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


Add some basic inode corruptions:
EXTENT_MARKED_REFCOUNTED, REFCOUNT_FLAG_INVALID and
REFCOUNT_LOC_INVALID.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 fswreck/corrupt.c           |    7 +++++++
 fswreck/extent.c            |   12 ++++++++++++
 fswreck/include/fsck_type.h |    5 +++++
 fswreck/inode.c             |   21 ++++++++++++++++++++-
 fswreck/main.c              |    7 +++++++
 5 files changed, 51 insertions(+), 1 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index f0c89cf..a69ae20 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -127,6 +127,7 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
 		func = mess_up_extent_block;
 		break;
 	case EXTENT_MARKED_UNWRITTEN:
+	case EXTENT_MARKED_REFCOUNTED:
 	case EXTENT_BLKNO_UNALIGNED:
 		func = mess_up_extent_record;
 		break;
@@ -258,6 +259,12 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
 	case DUP_CLUSTERS_SYSFILE_CLONE:
 		func = mess_up_dup_clusters;
 		break;
+	case REFCOUNT_FLAG_INVALID:
+		func = mess_up_inode_field;
+		break;
+	case REFCOUNT_LOC_INVALID:
+		func = mess_up_inode_field;
+		break;
 	default:
 		FSWRK_FATAL("Invalid code=%d", type);
 	}
diff --git a/fswreck/extent.c b/fswreck/extent.c
index 8ea0a46..e36deb9 100644
--- a/fswreck/extent.c
+++ b/fswreck/extent.c
@@ -310,6 +310,18 @@ static void mess_up_record(ocfs2_filesys *fs, uint64_t blkno,
 				"at cpos %"PRIu32" unwritten\n",
 				blkno, er->e_cpos);
 			break;
+		case EXTENT_MARKED_REFCOUNTED:
+			if (ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
+				FSWRK_FATAL("Cannot exercise "
+					    "EXTENT_MARKED_REFCOUNTED on a "
+					    "filesystem with refcounted "
+					    "extents supported (obviously)");
+			er->e_flags |= OCFS2_EXT_REFCOUNTED;
+			fprintf(stdout, "EXTENT_MARKED_REFCOUNTED: "
+				"Corrupt inode#%"PRIu64", mark extent "
+				"at cpos %"PRIu32" refcounted\n",
+				blkno, er->e_cpos);
+			break;
 		case EXTENT_BLKNO_UNALIGNED: 
 			er->e_blkno += 1;
 			fprintf(stdout, "EXTENT_BLKNO_UNALIGNED: "
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 1faa538..5721817 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -37,6 +37,7 @@ enum fsck_type
 	EB_GEN,
 	EB_GEN_FIX,
 	EXTENT_MARKED_UNWRITTEN,
+	EXTENT_MARKED_REFCOUNTED,
 	EXTENT_BLKNO_UNALIGNED,
 	EXTENT_CLUSTERS_OVERRUN,
 	EXTENT_EB_INVALID,
@@ -134,6 +135,8 @@ enum fsck_type
 	DQBLK_INVALID,
 	DUP_DQBLK_INVALID,
 	DUP_DQBLK_VALID,
+	REFCOUNT_FLAG_INVALID,
+	REFCOUNT_LOC_INVALID,
 	NUM_FSCK_TYPE
 };
 
@@ -219,5 +222,7 @@ enum fsck_type
  * Duplicate clusters error:	DUP_CLUSTERS_CLONE, DUP_CLUSTERS_DELETE
  *				DUP_CLUSTERS_SYSFILE_CLONE
  *
+ * refcount tree error:	EXTENT_MARKED_REFCOUNTED, REFCOUNT_FLAG_INVALID,
+ *			REFCOUNT_LOC_INVALID
  */
 #endif
diff --git a/fswreck/inode.c b/fswreck/inode.c
index afd4284..88b96e1 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -128,6 +128,19 @@ static void damage_inode(ocfs2_filesys *fs, uint64_t blkno,
 			"Corrupte inode#%"PRIu64", set link count to 0\n",
 			blkno);
 		break;
+	case REFCOUNT_FLAG_INVALID:
+		di->i_dyn_features |= OCFS2_HAS_REFCOUNT_FL;
+		fprintf(stdout, "REFCOUNT_FLAG_INVALD: "
+			"Corrupt inode#%"PRIu64", add refcount feature\n",
+			blkno);
+		break;
+	case REFCOUNT_LOC_INVALID:
+		di->i_refcount_loc = 100;
+		fprintf(stdout, "INLINE_DATA_COUNT_INVALID: "
+			"Create an inode#%"PRIu64","
+			"whose i_refcount_loc has been messed up.\n",
+			blkno);
+		break;
 	default:
 		FSWRK_FATAL("Invalid type[%d]\n", type);
 	}
@@ -185,6 +198,13 @@ void mess_up_inode_field(ocfs2_filesys *fs, enum fsck_type type, uint64_t blkno)
 			FSWRK_COM_FATAL(progname, ret);
 	}
 
+	if (type == REFCOUNT_FLAG_INVALID &&
+	    ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
+		FSWRK_FATAL("should specfiy a norefcount volume\n");
+	if (type == REFCOUNT_LOC_INVALID &&
+	    !ocfs2_refcount_tree(OCFS2_RAW_SB(fs->fs_super)))
+		FSWRK_FATAL("Should specify a refcount supported volume\n");
+
 	damage_inode(fs, tmpblkno, type);
 	return;
 }
@@ -505,4 +525,3 @@ void mess_up_dup_clusters(ocfs2_filesys *fs, enum fsck_type type,
 
 	ocfs2_free(&buf);
 }
-
diff --git a/fswreck/main.c b/fswreck/main.c
index 0910188..bcd4469 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -62,6 +62,9 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 	define_prompt_code(EXTENT_MARKED_UNWRITTEN, corrupt_file,
 			   "Mark an extent unwritten when the filesystem "
 			   "does not support it"),
+	define_prompt_code(EXTENT_MARKED_REFCOUNTED, corrupt_file,
+			   "Mark an extent refcounted when the filesystem "
+			   "does not support it"),
 	define_prompt_code(EXTENT_BLKNO_UNALIGNED, corrupt_file,
 			   "Corrupt extent record's e_blkno"),
 	define_prompt_code(EXTENT_CLUSTERS_OVERRUN, corrupt_file,
@@ -259,6 +262,10 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 			   "Duplicate a invalid quota limits."),
 	define_prompt_code(DUP_DQBLK_VALID, corrupt_sys_file,
 			   "Duplicate a valid quota limits."),
+	define_prompt_code(REFCOUNT_FLAG_INVALID, corrupt_file,
+			   "Create a refcounted inode on a unsupported volume"),
+	define_prompt_code(REFCOUNT_LOC_INVALID, corrupt_file,
+			   "Corrupt a refcounted file's refcount location"),
 };
 
 #undef define_prompt_code
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list