[Ocfs2-tools-devel] [PATCH 1/3] fswreck: corrupt CRC and ECC value of extent block

zren at suse.com zren at suse.com
Wed Aug 26 22:40:03 PDT 2015


From: Eric Ren <zren at suse.com>

Add the ability of corrupting the crc and ecc value of extent
block to fswreck.

Signed-off-by: Eric Ren <zren at suse.com>
Reviewed-by: Gang He <ghe at suse.com>
---
 fswreck/corrupt.c           |  3 +++
 fswreck/extent.c            | 21 ++++++++++++++++++---
 fswreck/include/fsck_type.h |  3 ++-
 fswreck/main.c              |  2 ++
 include/ocfs2/ocfs2.h       |  2 ++
 libocfs2/extents.c          | 39 +++++++++++++++++++++++++++++++++++++++
 6 files changed, 66 insertions(+), 4 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 2f6074e..47eee41 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -71,6 +71,9 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
 	case EB_GEN_FIX:
 		func = mess_up_extent_block;
 		break;
+	case EB_ECC:
+		func = mess_up_extent_block;
+		break;
 	case EXTENT_EB_INVALID:
 		func = mess_up_extent_block;
 		break;
diff --git a/fswreck/extent.c b/fswreck/extent.c
index ab1f5d1..805c743 100644
--- a/fswreck/extent.c
+++ b/fswreck/extent.c
@@ -25,7 +25,8 @@
 
 /* This file will create the following errors for extent rec and blocks .
  *
- * Extent block error:	EB_BLKNO, EB_GEN, EB_GEN_FIX, EXTENT_EB_INVALID
+ * Extent block error:	EB_BLKNO, EB_GEN, EB_GEN_FIX, EXTENT_EB_INVALID,
+ *			EB_ECC
  *
  * Extent list error:	EB_LIST_DEPTH, EXTENT_LIST_COUNT, EXTENT_LIST_FREE 
  *
@@ -176,6 +177,15 @@ static void damage_extent_block(ocfs2_filesys *fs, uint64_t blkno,
 				"generation number from 0x%x to 0x%x\n",
 				blkno, oldno, eb->h_fs_generation);
 			break;
+		case EB_ECC:
+			fprintf(stdout, "EB_ECC: "
+				"Corrupt inode#%"PRIu64", change extent block#"
+				"%"PRIu64", set h_check.bc_crc32e=%"PRIu64" and "
+				"h_check.bc_ecc=%"PRIu64" to 0x1234\n", blkno,
+				eb->h_blkno, eb->h_check.bc_crc32e, eb->h_check.bc_ecc);
+			eb->h_check.bc_crc32e = 0x1234;
+			eb->h_check.bc_ecc = 0x1234;
+			break;
 		case EXTENT_EB_INVALID:
 			memset(eb->h_signature, 'a', sizeof(eb->h_signature));
 			fprintf(stdout, "Corrupt the signature of extent block "
@@ -210,8 +220,13 @@ static void damage_extent_block(ocfs2_filesys *fs, uint64_t blkno,
 			FSWRK_FATAL("Invalid type=%d", type);
 		}
 
-		ret = ocfs2_write_extent_block(fs, el->l_recs[0].e_blkno,
-					       extbuf);
+		if (type != EB_ECC)
+			ret = ocfs2_write_extent_block(fs, el->l_recs[0].e_blkno,
+						extbuf);
+		else
+			ret = ocfs2_write_extent_block_without_meta_ecc(fs, el->l_recs[0].e_blkno,
+						extbuf);
+
 		if (ret)
 			FSWRK_COM_FATAL(progname, ret);
 		
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 956a1e2..97c262a 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -168,7 +168,8 @@ enum fsck_type
 	DUP_CLUSTERS_ADD_REFCOUNT,
 	INODE_BLOCK_ECC,
 	INODE_VALID_FLAG,
-/*134*/	NUM_FSCK_TYPE
+	EB_ECC,
+/*135*/	NUM_FSCK_TYPE
 };
 
 /* 
diff --git a/fswreck/main.c b/fswreck/main.c
index 016fc03..ba2eb63 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -60,6 +60,8 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 	define_prompt_code(EB_GEN_FIX, corrupt_file, "", 1,
 			   "Corrupt an extent block's generation number "
 			   "so that fsck.ocfs2 can fix it"),
+	define_prompt_code(EB_ECC, corrupt_file, "", 1,
+			   "Corrupt an extent blocks's CRC and ECC value of meta"),
 	define_prompt_code(EXTENT_MARKED_UNWRITTEN, corrupt_file, "nounwritten", 1,
 			   "Mark an extent unwritten when the filesystem "
 			   "does not support it"),
diff --git a/include/ocfs2/ocfs2.h b/include/ocfs2/ocfs2.h
index d33a28d..107e595 100644
--- a/include/ocfs2/ocfs2.h
+++ b/include/ocfs2/ocfs2.h
@@ -464,6 +464,8 @@ errcode_t ocfs2_read_extent_block_nocheck(ocfs2_filesys *fs, uint64_t blkno,
 					  char *eb_buf);
 errcode_t ocfs2_write_extent_block(ocfs2_filesys *fs, uint64_t blkno,
        				   char *eb_buf);
+errcode_t ocfs2_write_extent_block_without_meta_ecc(ocfs2_filesys *fs, uint64_t blkno,
+				   char *eb_buf);
 void ocfs2_swap_refcount_list_to_cpu(ocfs2_filesys *fs, void *obj,
 				     struct ocfs2_refcount_list *rl);
 void ocfs2_swap_refcount_list_from_cpu(ocfs2_filesys *fs, void *obj,
diff --git a/libocfs2/extents.c b/libocfs2/extents.c
index d72ae66..4a05939 100644
--- a/libocfs2/extents.c
+++ b/libocfs2/extents.c
@@ -208,7 +208,46 @@ out:
 	return ret;
 }
 
+/**
+ * Same as ocfs2_write_extent_block, but without ocfs2_compute_meta_ecc function so
+ * that the extent block meta CRC and ECC value wouldn't be overwritten after corrupted
+ * in fswreck.
+ */
+errcode_t ocfs2_write_extent_block_without_meta_ecc(ocfs2_filesys *fs, uint64_t blkno,
+				   char *eb_buf)
+{
+	errcode_t ret;
+	char *blk;
+	struct ocfs2_extent_block *eb;
+
+	if (!(fs->fs_flags & OCFS2_FLAG_RW))
+		return OCFS2_ET_RO_FILESYS;
+
+	if ((blkno < OCFS2_SUPER_BLOCK_BLKNO) ||
+	    (blkno > fs->fs_blocks))
+		return OCFS2_ET_BAD_BLKNO;
+
+	ret = ocfs2_malloc_block(fs->fs_io, &blk);
+	if (ret)
+		return ret;
 
+	memcpy(blk, eb_buf, fs->fs_blocksize);
+
+	eb = (struct ocfs2_extent_block *) blk;
+	ocfs2_swap_extent_block_from_cpu(fs, eb);
+
+	ret = io_write_block(fs->fs_io, blkno, 1, blk);
+	if (ret)
+		goto out;
+
+	fs->fs_flags |= OCFS2_FLAG_CHANGED;
+	ret = 0;
+
+out:
+	ocfs2_free(&blk);
+
+	return ret;
+}
 
 struct extent_context {
 	ocfs2_filesys *fs;
-- 
2.1.4




More information about the Ocfs2-tools-devel mailing list