[Ocfs2-tools-devel] [PATCH 1/1] Ocfs2-tools: Update fswreck part to meet fsck's enhancement of solving multiply-claimed clusters v2.

Tristan Ye tristan.ye at oracle.com
Tue Aug 11 20:28:05 PDT 2009


Add support of codes 'DUP_CLUSTERS_SYSFILE_CLONE, DUP_CLUSTERS_CLONE, DUP_CLUSTERS_DELETE'
to fswreck to make it compatible with fsck part after joel's patches series of sovling
multiply-claimed clusters in fsck.ocfs2 get pushed.

Signed-off-by: Tristan Ye <tristan.ye at oracle.com>
---
 fswreck/corrupt.c           |    4 +-
 fswreck/include/fsck_type.h |    7 +++-
 fswreck/inode.c             |   99 ++++++++++++++++++++++++++++---------------
 fswreck/main.c              |    6 ++-
 4 files changed, 78 insertions(+), 38 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 160c6dd..146e1c2 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -252,7 +252,9 @@ void corrupt_file(ocfs2_filesys *fs, enum fsck_type type, uint16_t slotnum)
 	case INODE_INLINE_CLUSTERS:
 		func = mess_up_inline_inode;
 		break;
-	case DUPLICATE_CLUSTERS:
+	case DUP_CLUSTERS_CLONE:
+	case DUP_CLUSTERS_DELETE:
+	case DUP_CLUSTERS_SYSFILE_CLONE:
 		func = mess_up_dup_clusters;
 		break;
 	default:
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 94f7694..77ff1fa 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -121,7 +121,9 @@ enum fsck_type
 	INLINE_DATA_COUNT_INVALID,
 	INODE_INLINE_SIZE,
 	INODE_INLINE_CLUSTERS,
-	DUPLICATE_CLUSTERS,
+	DUP_CLUSTERS_SYSFILE_CLONE,
+	DUP_CLUSTERS_CLONE,
+	DUP_CLUSTERS_DELETE,
 	JOURNAL_FILE_INVALID,
 	JOURNAL_UNKNOWN_FEATURE,
 	JOURNAL_MISSING_FEATURE,
@@ -204,5 +206,8 @@ enum fsck_type
  * Inline file:	INLINE_DATA_FLAG_INVALID, INLINE_DATA_COUNT_INVALID
  *		INODE_INLINE_SIZE, INODE_INLINE_CLUSTERS
  *
+ * Duplicate clusters error:	DUP_CLUSTERS_CLONE, DUP_CLUSTERS_DELETE
+ *				DUP_CLUSTERS_SYSFILE_CLONE
+ *
  */
 #endif
diff --git a/fswreck/inode.c b/fswreck/inode.c
index 46f99a9..14091e5 100644
--- a/fswreck/inode.c
+++ b/fswreck/inode.c
@@ -407,18 +407,12 @@ void mess_up_dup_clusters(ocfs2_filesys *fs, enum fsck_type type,
 		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;
@@ -426,47 +420,82 @@ void mess_up_dup_clusters(ocfs2_filesys *fs, enum fsck_type type,
 			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);
+	if (type != DUP_CLUSTERS_SYSFILE_CLONE) {
+
+		create_file(fs, blkno, &inode2_blkno);
+		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 (di2->i_dyn_features & OCFS2_INLINE_DATA_FL) {
+				di2->i_dyn_features &= ~OCFS2_INLINE_DATA_FL;
+				err = ocfs2_write_inode(fs, inode2_blkno,
+							(char *)di2);
+				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);
+		err = ocfs2_extend_allocation(fs, inode2_blkno, 1);
+		if (err)
+			FSWRK_COM_FATAL(progname, err);
+
+		/* Re-read the inode with the allocation */
+		err = ocfs2_read_inode(fs, inode2_blkno, (char *)di2);
+		if (err)
+			FSWRK_COM_FATAL(progname, err);
+
+		/* Set i_size to non-zero so that the allocation is valid */
+		di2->i_size = fs->fs_clustersize;
+		err = ocfs2_write_inode(fs, inode2_blkno, (char *)di2);
+		if (err)
+			FSWRK_COM_FATAL(progname, err);
+
+		if (type == DUP_CLUSTERS_CLONE)
+			fprintf(stdout, "DUP_CLUSTERS_CLONE: "
+				"Create two inodes #%"PRIu64" and #%"PRIu64
+				" by allocating same cluster to them.\n",
+				inode1_blkno, inode2_blkno);
+		else
+			fprintf(stdout, "DUP_CLUSTERS_DELETE: "
+				"Create two inodes #%"PRIu64" and #%"PRIu64
+				" by allocating same cluster to them.\n",
+				inode1_blkno, inode2_blkno);
+	} else {
+		/* Here use journal file*/
+		err = ocfs2_lookup_system_inode(fs, JOURNAL_SYSTEM_INODE, 0,
+						&inode2_blkno);
+		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);
+
+		fprintf(stdout, "DUP_CLUSTERS_SYSFILE_CLONE: "
+			"Allocate same cluster to journal file "
+			"#%"PRIu64" and regular file #%"PRIu64".\n",
+			inode1_blkno, inode2_blkno);
+	}
 
 	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];
+	el1->l_next_free_rec = el2->l_next_free_rec;
+	el1->l_recs[0] = el2->l_recs[0];
 
-	di2->i_size = di1->i_size;
-	di2->i_clusters = di1->i_clusters;
+	di1->i_size = di2->i_size;
+	di1->i_clusters = di2->i_clusters;
 
-	err = ocfs2_write_inode(fs, inode2_blkno, (char *)di2);
+	err = ocfs2_write_inode(fs, inode1_blkno, (char *)di1);
 	if (err)
 		FSWRK_COM_FATAL(progname, err);
 
-	fprintf(stdout, "DUPLICATE_CLUSTERS: "
-		"Create two inodes #%"PRIu64" and #%"PRIu64
-		" by allocating same cluster to them.",
-		inode1_blkno, inode2_blkno);
-
 	ocfs2_free(&buf);
 }
 
diff --git a/fswreck/main.c b/fswreck/main.c
index 3debe70..d08f51a 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -149,8 +149,12 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 			   "Corrupt inlined inode's i_size"),
 	define_prompt_code(INODE_INLINE_CLUSTERS, corrupt_file,
 			   "Corrupt inlined inode's i_clusters"),
-	define_prompt_code(DUPLICATE_CLUSTERS, corrupt_file,
+	define_prompt_code(DUP_CLUSTERS_CLONE, corrupt_file,
 			   "Allocate same cluster to different files"),
+	define_prompt_code(DUP_CLUSTERS_DELETE, corrupt_file,
+			   "Allocate same cluster to different files"),
+	define_prompt_code(DUP_CLUSTERS_SYSFILE_CLONE, corrupt_file,
+			   "Allocate same cluster to different system files"),
 	define_prompt_code(CHAIN_COUNT, corrupt_sys_file,
 			   "Corrupt chain list's cl_count"),
 	define_prompt_code(CHAIN_NEXT_FREE, corrupt_sys_file,
-- 
1.5.5




More information about the Ocfs2-tools-devel mailing list