[Ocfs2-tools-devel] [PATCH] Make duplicate clusters via fswreck

Joel Becker Joel.Becker at oracle.com
Tue Jun 2 20:56:10 PDT 2009


Hey folks,
	Here's my quick and dirty change to fswreck that will allocate
the same cluster to two inodes.

Joel

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 50f063b..09ebe17 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * corrupt.c
  *
  * corruption routines
@@ -154,6 +156,9 @@ void corrupt_file(ocfs2_filesys *fs, int code, uint16_t slotnum)
 	case CORRUPT_INLINE_DATA_COUNT:
 		func = mess_up_inline_count;
 		break;
+	case CORRUPT_DUPLICATE_CLUSTERS:
+		func = mess_up_dup_clusters;
+		break;
 	default:
 		FSWRK_FATAL("Invalid code=%d", code);
 	}
diff --git a/fswreck/include/inode.h b/fswreck/include/inode.h
index 6094a0a..6f98e94 100644
--- a/fswreck/include/inode.h
+++ b/fswreck/include/inode.h
@@ -31,5 +31,6 @@ void mess_up_inode_orphaned(ocfs2_filesys *fs, uint16_t slotnum);
 void mess_up_inode_alloc(ocfs2_filesys *fs, uint16_t slotnum);
 void mess_up_inline_flag(ocfs2_filesys *fs, uint64_t blkno);
 void mess_up_inline_count(ocfs2_filesys *fs, uint64_t blkno);
+void mess_up_dup_clusters(ocfs2_filesys *fs, uint64_t blkno);
 
 #endif		/* __INODE_H */
diff --git a/fswreck/include/main.h b/fswreck/include/main.h
index e201672..96230f4 100644
--- a/fswreck/include/main.h
+++ b/fswreck/include/main.h
@@ -108,6 +108,7 @@ enum{
 	CORRUPT_CLUSTER_AND_GROUP_DESC,
 	CORRUPT_INLINE_DATA_FLAG,
 	CORRUPT_INLINE_DATA_COUNT,
+        CORRUPT_DUPLICATE_CLUSTERS,
 	MAX_CORRUPT
 };
 
diff --git a/fswreck/inode.c b/fswreck/inode.c
index 701472c..ac2dfff 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * inode.c
  *
  * inode fields corruptions
@@ -333,3 +335,75 @@ void mess_up_inline_count(ocfs2_filesys *fs, uint64_t blkno)
 
 	return;
 }
+
+void mess_up_dup_clusters(ocfs2_filesys *fs, uint64_t blkno)
+{
+	errcode_t err;
+	char *buf = NULL;
+	uint64_t inode1_blkno, inode2_blkno;
+	struct ocfs2_dinode *di1, *di2;
+	struct ocfs2_extent_list *el1, *el2;
+
+	err = ocfs2_malloc_blocks(fs->fs_io, 2, &buf);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	create_file(fs, blkno, &inode1_blkno);
+	create_file(fs, blkno, &inode2_blkno);
+
+	di1 = (struct ocfs2_dinode *)buf;
+	err = ocfs2_read_inode(fs, inode1_blkno, (char *)di1);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	di2 = (struct ocfs2_dinode *)(buf + fs->fs_blocksize);
+	err = ocfs2_read_inode(fs, inode2_blkno, (char *)di2);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	if (ocfs2_support_inline_data(OCFS2_RAW_SB(fs->fs_super))) {
+		if (di1->i_dyn_features & OCFS2_INLINE_DATA_FL) {
+			di1->i_dyn_features &= ~OCFS2_INLINE_DATA_FL;
+			err = ocfs2_write_inode(fs, inode1_blkno, (char *)di1);
+			if (err)
+				FSWRK_COM_FATAL(progname, err);
+		}
+		if (di2->i_dyn_features & OCFS2_INLINE_DATA_FL) {
+			di2->i_dyn_features &= ~OCFS2_INLINE_DATA_FL;
+			err = ocfs2_write_inode(fs, inode1_blkno, (char *)di2);
+			if (err)
+				FSWRK_COM_FATAL(progname, err);
+		}
+	}
+
+	err = ocfs2_extend_allocation(fs, inode1_blkno, 1);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	/* Re-read the inode with the allocation */
+	err = ocfs2_read_inode(fs, inode1_blkno, (char *)di1);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	/* Set i_size to non-zero so that the allocation is valid */
+	di1->i_size = fs->fs_clustersize;
+	err = ocfs2_write_inode(fs, inode1_blkno, (char *)di1);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	el1 = &(di1->id2.i_list);
+	el2 = &(di2->id2.i_list);
+
+	el2->l_next_free_rec = el1->l_next_free_rec;
+	el2->l_recs[0] = el1->l_recs[0];
+
+	di2->i_size = di1->i_size;
+	di2->i_clusters = di1->i_clusters;
+
+	err = ocfs2_write_inode(fs, inode2_blkno, (char *)di2);
+	if (err)
+		FSWRK_COM_FATAL(progname, err);
+
+	ocfs2_free(&buf);
+}
+
diff --git a/fswreck/main.c b/fswreck/main.c
index 39502e1..bc889d8 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -91,6 +91,7 @@ static struct corrupt_funcs cf[MAX_CORRUPT] = {
 	{ &corrupt_group_desc,	"Create an error of GROUP_FREE_BITS and CLUSTER_ALLOC_BITS, simulate bug841 in oss.oracle.com/bugzilla"},
 	{ &corrupt_file,        "Inline file dyn_features flag error: INLINE_DATA_FLAG_INVALID"},
 	{ &corrupt_file,        "Inline file id_count,i_clusters and i_size error: INLINE_DATA_COUNT_INVALID"},
+	{ &corrupt_file,        "Allocate the same cluster to two different files"},
 
 };
 
-- 

"The whole problem with the world is that fools and fanatics are always
 so certain of themselves, and wiser people so full of doubts."
	- Bertrand Russell

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-tools-devel mailing list