[Ocfs2-tools-devel] [PATCH 1/1] Add corrupt code for inline data in fswreck:Revised

tristan tristan.ye at oracle.com
Wed Aug 13 00:13:58 PDT 2008


Add corrupt code for inline data in fswreck,include both regular file
and directory.
Mainly aims at corrupting the newly added checking codes in
fsck.ocfs2.checks for inline-data.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 fswreck/corrupt.c           |   11 +++++-
 fswreck/dir.c               |    2 +-
 fswreck/include/dir.h       |    2 +
 fswreck/include/fsck_type.h |    6 +++
 fswreck/include/inode.h     |    2 +
 fswreck/include/main.h      |    3 +-
 fswreck/inode.c             |   81
+++++++++++++++++++++++++++++++++++++++++++
 fswreck/main.c              |    5 ++-
 8 files changed, 107 insertions(+), 5 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index f698cb0..50f063b 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -78,7 +78,8 @@ void corrupt_chains(ocfs2_filesys *fs, int code,
uint16_t slotnum)
 	return ;
 }
 
-static void create_directory(ocfs2_filesys *fs, char *dirname, uint64_t
*blkno)
+static void create_named_directory(ocfs2_filesys *fs, char *dirname,
+				   uint64_t *blkno)
 {
 	errcode_t ret;
 	struct ocfs2_super_block *sb = OCFS2_RAW_SB(fs->fs_super);
@@ -147,11 +148,17 @@ void corrupt_file(ocfs2_filesys *fs, int code,
uint16_t slotnum)
 	case CORRUPT_DIR_NOT_CONNECTED:
 		func = mess_up_dir_not_connected;
 		break;
+	case CORRUPT_INLINE_DATA_FLAG:
+		func = mess_up_inline_flag;
+		break;
+	case CORRUPT_INLINE_DATA_COUNT:
+		func = mess_up_inline_count;
+		break;
 	default:
 		FSWRK_FATAL("Invalid code=%d", code);
 	}
 
-	create_directory(fs, "tmp", &blkno);
+	create_named_directory(fs, "tmp", &blkno);
 
 	if (func)
 		func(fs, blkno);
diff --git a/fswreck/dir.c b/fswreck/dir.c
index 3338a17..694b07c 100644
--- a/fswreck/dir.c
+++ b/fswreck/dir.c
@@ -43,7 +43,7 @@
 
 extern char *progname;
 
-static void create_directory(ocfs2_filesys *fs,
+void create_directory(ocfs2_filesys *fs,
 				uint64_t parentblk, uint64_t *blkno)
 {
 	errcode_t ret;
diff --git a/fswreck/include/dir.h b/fswreck/include/dir.h
index 57afcfb..c534f1b 100644
--- a/fswreck/include/dir.h
+++ b/fswreck/include/dir.h
@@ -31,4 +31,6 @@ void mess_up_dir_ent(ocfs2_filesys *fs, uint64_t
blkno);
 void mess_up_dir_parent_dup(ocfs2_filesys *fs, uint64_t blkno);
 void mess_up_dir_not_connected(ocfs2_filesys *fs, uint64_t blkno);
 
+void create_directory(ocfs2_filesys *fs, uint64_t parentblk, uint64_t
*blkno);
+
 #endif		/* __DIR_H */
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index a6a4873..a03333d 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -112,6 +112,8 @@ enum fsck_type
 	INODE_NOT_CONNECTED,
 	INODE_COUNT,
 	INODE_ORPHANED,
+	INLINE_DATA_FLAG_INVALID,
+	INLINE_DATA_COUNT_INVALID,
 	NUM_FSCK_TYPE
 };
 
@@ -184,5 +186,9 @@ enum fsck_type
  *
  * Directory not connected error: DIR_NOT_CONNECTED
  *
+ * Inline file flag error:	INLINE_DATA_FLAG_INVALID
+ *
+ * Inline file id_count error:  INLINE_DATA_COUNT_INVALID
+ *
  */
 #endif
diff --git a/fswreck/include/inode.h b/fswreck/include/inode.h
index d604e65..6094a0a 100644
--- a/fswreck/include/inode.h
+++ b/fswreck/include/inode.h
@@ -29,5 +29,7 @@ void mess_up_inode_field(ocfs2_filesys *fs, uint64_t
blkno);
 void mess_up_inode_not_connected(ocfs2_filesys *fs, uint64_t blkno);
 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);
 
 #endif		/* __INODE_H */
diff --git a/fswreck/include/main.h b/fswreck/include/main.h
index de9b520..e201672 100644
--- a/fswreck/include/main.h
+++ b/fswreck/include/main.h
@@ -106,8 +106,9 @@ enum{
 	CORRUPT_DIR_PARENT_DUP,
 	CORRUPT_DIR_NOT_CONNECTED,
 	CORRUPT_CLUSTER_AND_GROUP_DESC,
+	CORRUPT_INLINE_DATA_FLAG,
+	CORRUPT_INLINE_DATA_COUNT,
 	MAX_CORRUPT
-	
 };
 
 #define ARRAY_ELEMENTS(arr) (sizeof(arr) / sizeof(arr[0]))
diff --git a/fswreck/inode.c b/fswreck/inode.c
index f823117..0d5555c 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -224,3 +224,84 @@ void mess_up_inode_alloc(ocfs2_filesys *fs,
uint16_t slotnum)
 		ocfs2_free(&buf);
 	return;
 }
+
+void mess_up_inline_flag(ocfs2_filesys *fs, uint64_t blkno)
+{
+
+	int i;
+	errcode_t ret;
+	char *buf = NULL;
+	uint64_t inline_blkno;
+	struct ocfs2_dinode *di;
+
+	for (i = 0; i < 2; i++) {
+		if (i == 0)
+			create_file(fs, blkno, &inline_blkno);
+		else
+			create_directory(fs, blkno, &inline_blkno);
+
+		ret = ocfs2_malloc_block(fs->fs_io, &buf);
+		if (ret)
+			FSWRK_COM_FATAL(progname, ret);
+		ret = ocfs2_read_inode(fs, inline_blkno, buf);
+		if (ret)
+			FSWRK_COM_FATAL(progname, ret);
+
+		di = (struct ocfs2_dinode *)buf;
+		if (!(di->i_dyn_features & OCFS2_INLINE_DATA_FL)) {
+			di->i_dyn_features |= OCFS2_INLINE_DATA_FL;
+			ret = ocfs2_write_inode(fs, inline_blkno, buf);
+			if (ret)
+				FSWRK_COM_FATAL(progname, ret);
+		}
+
+		if (buf)
+			ocfs2_free(&buf);
+	}
+
+	return;
+}
+
+void mess_up_inline_count(ocfs2_filesys *fs, uint64_t blkno)
+{
+	int i;
+	errcode_t ret;
+	char *buf = NULL;
+	uint64_t inline_blkno;
+	struct ocfs2_dinode *di;
+	uint16_t max_inline_sz;
+
+	for (i = 0; i < 2; i++) {
+		if (i == 0)
+			create_file(fs, blkno, &inline_blkno);
+		else
+			create_directory(fs, blkno, &inline_blkno);
+
+		ret = ocfs2_malloc_block(fs->fs_io, &buf);
+		if (ret)
+			FSWRK_COM_FATAL(progname, ret);
+
+		ret = ocfs2_read_inode(fs, inline_blkno, buf);
+		if (ret)
+			FSWRK_COM_FATAL(progname, ret);
+
+		di = (struct ocfs2_dinode *)buf;
+		max_inline_sz = ocfs2_max_inline_data(fs->fs_blocksize);
+
+		if (!(di->i_dyn_features & OCFS2_INLINE_DATA_FL))
+			di->i_dyn_features |= OCFS2_INLINE_DATA_FL;
+
+		di->id2.i_data.id_count = 0;
+		di->i_size = max_inline_sz + 1;
+		di->i_clusters = 1;
+
+		ret = ocfs2_write_inode(fs, inline_blkno, buf);
+		if (ret)
+			FSWRK_COM_FATAL(progname, ret);
+
+		if (buf)
+			ocfs2_free(&buf);
+	}
+
+	return;
+}
diff --git a/fswreck/main.c b/fswreck/main.c
index b8afe08..8e087dc 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -88,7 +88,10 @@ static struct corrupt_funcs cf[MAX_CORRUPT] = {
 	{ &corrupt_file,	"Dirent field error: DIRENT_ZERO,
DIRENT_NAME_CHARS,DIRENT_INODE_RANGE, DIRENT_INODE_FREE, DIRENT_TYPE,
DIRENT_DUPLICATE, DIRENT_LENGTH"}, 
 	{ &corrupt_file,	"Directory parent duplicate error: DIR_PARENT_DUP"},
 	{ &corrupt_file,	"Directory not connected error: DIR_NOT_CONNECTED"},
-	{ &corrupt_group_desc,	"Create an error of GROUP_FREE_BITS and
CLUSTER_ALLOC_BITS, simulate bug841 in oss.oracle.com/bugzilla"}
+	{ &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"},
+
 };
 
 static int corrupt[MAX_CORRUPT];
-- 
1.5.5





More information about the Ocfs2-tools-devel mailing list