[Ocfs2-tools-devel] [PATCH 6/6] ocfs2: add fswreck support to ocfs2 local alloc rec

Srinivas Eeda srinivas.eeda at oracle.com
Mon May 7 16:49:10 PDT 2012


This patch enhances fswreck to handle new ocfs2 local alloc record

Signed-off-by: Srinivas Eeda <srinivas.eeda at oracle.com>
---
 fswreck/corrupt.c           |   15 ++++++++
 fswreck/include/fsck_type.h |    7 ++++
 fswreck/local_alloc.c       |   81 +++++++++++++++++++++++++++++--------------
 fswreck/main.c              |    8 ----
 4 files changed, 77 insertions(+), 34 deletions(-)

diff --git a/fswreck/corrupt.c b/fswreck/corrupt.c
index 533481e..4abc845 100644
--- a/fswreck/corrupt.c
+++ b/fswreck/corrupt.c
@@ -371,6 +371,12 @@ void corrupt_local_alloc(ocfs2_filesys *fs, enum fsck_type type,
 	case LALLOC_NZ_BM:
 		func = mess_up_local_alloc_empty;
 		break;
+	case LALLOC_NZ_REC_COUNT:
+		func = mess_up_local_alloc_empty;
+		break;
+	case LALLOC_NZ_BM_COUNT:
+		func = mess_up_local_alloc_empty;
+		break;
 	case LALLOC_BM_OVERRUN:
 		func = mess_up_local_alloc_bitmap;
 		break;
@@ -380,12 +386,21 @@ void corrupt_local_alloc(ocfs2_filesys *fs, enum fsck_type type,
 	case LALLOC_BM_SIZE:
 		func = mess_up_local_alloc_bitmap;
 		break;
+	case LALLOC_BM_START:
+		func = mess_up_local_alloc_bitmap;
+		break;
 	case LALLOC_USED_OVERRUN:
 		func = mess_up_local_alloc_used;
 		break;
 	case LALLOC_CLEAR:
 		func = mess_up_local_alloc_used;
 		break;
+	case LALLOC_REC_COUNT:
+		func = mess_up_local_alloc_used;
+		break;
+	case LALLOC_CLSTR_COUNT:
+		func = mess_up_local_alloc_used;
+		break;
 	default:
 		FSWRK_FATAL("Invalid code = %d", type);
 	}
diff --git a/fswreck/include/fsck_type.h b/fswreck/include/fsck_type.h
index 3999647..ccbbea7 100644
--- a/fswreck/include/fsck_type.h
+++ b/fswreck/include/fsck_type.h
@@ -81,13 +81,20 @@ enum fsck_type
 	INODE_ALLOC_REPAIR,
 	INODE_SUBALLOC,
 	LALLOC_SIZE,
+	LALLOC_REC_ZERO,
 	LALLOC_NZ_USED,
 	LALLOC_NZ_BM,
+	LALLOC_NZ_REC_COUNT,
+	LALLOC_NZ_BM_COUNT,
 /*50*/	LALLOC_BM_OVERRUN,
 	LALLOC_BM_SIZE,
 	LALLOC_BM_STRADDLE,
+	LALLOC_BM_START,
 	LALLOC_USED_OVERRUN,
+	LALLOC_REC_COUNT,
+	LALLOC_CLSTR_COUNT,
 	LALLOC_CLEAR,
+	LALLOC_REC_OVERRUN,
 	DEALLOC_COUNT,
 	DEALLOC_USED,
 	TRUNCATE_REC_START_RANGE,
diff --git a/fswreck/local_alloc.c b/fswreck/local_alloc.c
index 9d7c3da..38be344 100644
--- a/fswreck/local_alloc.c
+++ b/fswreck/local_alloc.c
@@ -54,6 +54,8 @@ static void create_local_alloc(ocfs2_filesys *fs, uint64_t blkno)
 	struct ocfs2_local_alloc *la;
 	uint32_t la_size, found;
 	uint64_t la_off;
+	void *bitmap;
+	int i;
 
 	ret = ocfs2_malloc_block(fs->fs_io, &buf);
 	if (ret)
@@ -79,18 +81,25 @@ static void create_local_alloc(ocfs2_filesys *fs, uint64_t blkno)
 
 	la_size = get_local_alloc_window_bits();
 
-	ret = ocfs2_new_clusters(fs, 1, la_size, &la_off, &found);
-	if (ret)
-		FSWRK_COM_FATAL(progname, ret);
-	if(la_size != found)
-		FSWRK_FATAL("can't allocate enough clusters for local alloc");
-
 	la = &(di->id2.i_lab);
-
-	la->la_bm_off = la_off;
-	di->id1.bitmap1.i_total = la_size;
+	i = 0;
+	while (la_size > 0) {
+		la_size >>= 2;
+		ret = ocfs2_new_clusters(fs, 1, la_size, &la_off, &found);
+		if (ret)
+			FSWRK_COM_FATAL(progname, ret);
+		if (la_size != found)
+			FSWRK_FATAL("can't allocate enough clusters for local "
+				    "alloc");
+		la->la_recs[i].la_start = la_off;
+		la->la_recs[i].la_clusters = found;
+		di->id1.bitmap1.i_total += found;
+		la->la_rec_count++;
+		i++;
+	}
+	bitmap = OCFS2_LOCAL_ALLOC_BITMAP(la);
+	memset(bitmap, 0, la->la_size);
 	di->id1.bitmap1.i_used = 0;
-	memset(la->la_bitmap, 0, la->la_size);
 	
 	ret = ocfs2_write_inode(fs, blkno, buf);
 	if (ret)
@@ -133,7 +142,8 @@ static void damage_local_alloc(ocfs2_filesys *fs,
 	 * So check it first.
 	 */
 	if (type == LALLOC_BM_OVERRUN || type == LALLOC_BM_STRADDLE ||
-		type == LALLOC_BM_SIZE || type == LALLOC_USED_OVERRUN)
+	    type == LALLOC_BM_SIZE || type == LALLOC_USED_OVERRUN ||
+	    type == LALLOC_BM_START || type == LALLOC_REC_COUNT)
 		if (di->id1.bitmap1.i_total == 0) {
 			FSWRK_WARN("local inode#%"PRIu64" is empty, so can't"
 					"corrupt it for type[%d]\n",
@@ -161,23 +171,19 @@ static void damage_local_alloc(ocfs2_filesys *fs,
 			" used =  %d\n",blkno,  di->id1.bitmap1.i_total,
 			di->id1.bitmap1.i_used);
 		break;
-	case LALLOC_NZ_BM:
+	case LALLOC_NZ_REC_COUNT:
 		di->id1.bitmap1.i_total = 0;
-		la->la_bm_off = 100;
-		fprintf(stdout, "LALLOC_NZ_BM: "
-			"Corrupt local alloc inode#%"PRIu64", total = %d "
-			" la_bm_off =  %d\n",blkno,  di->id1.bitmap1.i_total,
-			la->la_bm_off);
+		la->la_rec_count = 10;
+		fprintf(stdout, "LALLOC_NZ_REC_COUNT:: "
+			"Corrupt local alloc inode#%"PRIu64", la_rec_count = %d"
+			", total = %d\n", blkno, la->la_rec_count,
+			di->id1.bitmap1.i_total);
 		break;
-	case LALLOC_BM_OVERRUN:
-	case LALLOC_BM_STRADDLE:
-		la->la_bm_off = fs->fs_clusters + 10;
-		if (type == LALLOC_BM_OVERRUN)
-			fprintf(stdout, "LALLOC_BM_OVERRUN: ");
-		else
-			fprintf(stdout, "LALLOC_BM_STRADDLE: ");
-		fprintf(stdout, "Corrupt local alloc inode#%"PRIu64
-			", la_bm_off =%u\n", blkno,  la->la_bm_off);
+	case LALLOC_REC_COUNT:
+		la->la_rec_count = OCFS2_MAX_LOCAL_ALLOC_REC_LIMIT + 10;
+		fprintf(stdout, "LALLOC_NZ_REC_ZERO: "
+			"Corrupt local alloc inode#%"PRIu64", la_rec_count = %d"
+			"\n", blkno, la->la_rec_count);
 		break;
 	case LALLOC_BM_SIZE:
 		fprintf(stdout, "LALLOC_SIZE: "
@@ -185,6 +191,20 @@ static void damage_local_alloc(ocfs2_filesys *fs,
 			" from %u to %u\n", blkno, di->id1.bitmap1.i_total,
 			(la->la_size * 8 + 10));
 		di->id1.bitmap1.i_total = la->la_size * 8 + 10;
+	case LALLOC_NZ_BM_COUNT:
+		di->id1.bitmap1.i_total = 10;
+		la->la_rec_count = 0;
+		fprintf(stdout, "LALLOC_NZ_BM_COUNT:: "
+			"Corrupt local alloc inode#%"PRIu64", la_rec_count = %d"
+			", total = %d\n", blkno, la->la_rec_count,
+			di->id1.bitmap1.i_total);
+		break;
+	case LALLOC_REC_OVERRUN:
+		la->la_recs[0].la_start = (uint32_t)-1;
+		la->la_recs[0].la_clusters = 0;
+		fprintf(stdout, "LALLOC_REC_OVERRUN: "
+			"Corrupt local alloc inode#%"PRIu64", la_start = %d"
+			"\n", blkno, la->la_recs[0].la_start);
 		break;
 	case LALLOC_USED_OVERRUN:
 		fprintf(stdout, "LALLOC_USED_OVERRUN: "
@@ -193,6 +213,15 @@ static void damage_local_alloc(ocfs2_filesys *fs,
 			(di->id1.bitmap1.i_total + 10));
 		di->id1.bitmap1.i_used = di->id1.bitmap1.i_total + 10;
 		break;
+	case LALLOC_CLSTR_COUNT:
+		la->la_rec_count = 10;
+		la->la_recs[0].la_clusters = 10;
+		di->id1.bitmap1.i_total = 5;
+		fprintf(stdout, "LALLOC_CLSTR_COUNT: "
+			"Corrupt local alloc inode#%"PRIu64", total cluster "
+			"count %d greater than total bits %d\n", blkno,
+			la->la_recs[0].la_clusters, di->id1.bitmap1.i_total);
+		break;
 	default:
 		FSWRK_FATAL("Unknown type = %d", type);
 	}
diff --git a/fswreck/main.c b/fswreck/main.c
index 3164ce0..1271aa1 100644
--- a/fswreck/main.c
+++ b/fswreck/main.c
@@ -241,20 +241,12 @@ static struct prompt_code prompt_codes[NUM_FSCK_TYPE] = {
 			   "Create an invalid inode"),
 	define_prompt_code(CLUSTER_GROUP_DESC, corrupt_group_desc, "", 1,
 			   "Corrupt chain group's clusters and free bits"),
-	define_prompt_code(LALLOC_SIZE, corrupt_local_alloc, "", 1,
-			   "Corrupt local alloc's size"),
 	define_prompt_code(LALLOC_NZ_USED, corrupt_local_alloc, "", 1,
 			   "Corrupt local alloc's used and total clusters"),
 	define_prompt_code(LALLOC_NZ_BM, corrupt_local_alloc, "", 1,
 			   "Corrupt local alloc's starting bit offset"),
 	define_prompt_code(LALLOC_BM_OVERRUN, corrupt_local_alloc, "", 1,
 			   "Overrun local alloc's starting bit offset"),
-	define_prompt_code(LALLOC_BM_STRADDLE, corrupt_local_alloc, "", 1,
-			   "Straddle local alloc's starting bit offset"),
-	define_prompt_code(LALLOC_BM_SIZE, corrupt_local_alloc, "", 1,
-			   "Corrupt local alloc bitmap's i_total"),
-	define_prompt_code(LALLOC_USED_OVERRUN, corrupt_local_alloc, "", 1,
-			   "Corrupt local alloc bitmap's i_used"),
 	define_prompt_code(LALLOC_CLEAR, corrupt_local_alloc, "", 1,
 			   "Corrupt local alloc's size"),
 	define_prompt_code(LALLOC_REPAIR, NULL, "", 1,
-- 
1.5.4.3




More information about the Ocfs2-tools-devel mailing list