[Ocfs2-tools-devel] [PATCH 3/6] fsck.ocfs2: Add local alloc free process.v4

Tao Ma tao.ma at oracle.com
Tue Oct 7 00:29:01 PDT 2008


Add local alloc free process in fsck.ocfs2.

Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
 fsck.ocfs2/include/slot_recovery.h |    1 +
 fsck.ocfs2/slot_recovery.c         |   84 ++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/fsck.ocfs2/include/slot_recovery.h b/fsck.ocfs2/include/slot_recovery.h
index 7b96c4e..dab34ca 100644
--- a/fsck.ocfs2/include/slot_recovery.h
+++ b/fsck.ocfs2/include/slot_recovery.h
@@ -23,6 +23,7 @@
 #include "fsck.h"
 
 errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs);
+errcode_t o2fsck_replay_local_allocs(ocfs2_filesys *fs);
 
 #endif /* __O2FSCK_SLOT_RECOVERY_H__ */
 
diff --git a/fsck.ocfs2/slot_recovery.c b/fsck.ocfs2/slot_recovery.c
index 77f6ed7..c4ae166 100644
--- a/fsck.ocfs2/slot_recovery.c
+++ b/fsck.ocfs2/slot_recovery.c
@@ -17,6 +17,7 @@
  * General Public License for more details.
  */
 
+#include <ocfs2/bitops.h>
 #include "util.h"
 #include "slot_recovery.h"
 
@@ -83,3 +84,86 @@ errcode_t o2fsck_replay_truncate_logs(ocfs2_filesys *fs)
 					TRUNCATE_LOG_SYSTEM_INODE,
 					ocfs2_clear_truncate_log);
 }
+
+static errcode_t ocfs2_clear_local_alloc(ocfs2_filesys *fs,
+					 struct ocfs2_dinode *di,
+					 int slot)
+{
+	errcode_t ret = 0;
+	int bit_off, left, count, start, was_set = 0, cleared = 0;
+	uint64_t la_start_blk;
+	uint64_t blkno;
+	void *bitmap;
+	struct ocfs2_local_alloc *la;
+
+	if (!(di->i_flags & OCFS2_VALID_FL) ||
+	    !(di->i_flags & OCFS2_SYSTEM_FL) ||
+	    !(di->i_flags & OCFS2_BITMAP_FL))
+		return OCFS2_ET_INVALID_ARGUMENT;
+
+	if (!di->id1.bitmap1.i_total)
+		goto bail;
+
+	la = &di->id2.i_lab;
+
+	if (di->id1.bitmap1.i_used == di->id1.bitmap1.i_total)
+		goto clear_inode;
+
+	la_start_blk = ocfs2_clusters_to_blocks(fs, la->la_bm_off);
+	bitmap = la->la_bitmap;
+	start = count = bit_off = 0;
+	left = di->id1.bitmap1.i_total;
+
+	while ((bit_off = ocfs2_find_next_bit_clear(bitmap, left, start))
+	       != -1) {
+		if ((bit_off < left) && (bit_off == start)) {
+			count++;
+			start++;
+			continue;
+		}
+		if (count) {
+			blkno = la_start_blk +
+				ocfs2_clusters_to_blocks(fs, start - count);
+
+			ret = ocfs2_test_clusters(fs, count,
+						  blkno, 1, &was_set);
+			if (ret)
+				goto bail;
+
+			if (!was_set) {
+				ret = OCFS2_ET_INVALID_BIT;
+				goto bail;
+			}
+
+			ret = ocfs2_free_clusters(fs, count, blkno);
+			if (ret)
+				goto bail;
+
+			cleared = 1;
+		}
+
+		if (bit_off >= left)
+			break;
+		count = 1;
+		start = bit_off + 1;
+	}
+clear_inode:
+	di->id1.bitmap1.i_total = 0;
+	di->id1.bitmap1.i_used = 0;
+	la->la_bm_off = 0;
+	memset(la->la_bitmap, 0, ocfs2_local_alloc_size(fs->fs_blocksize));
+
+	ret = ocfs2_write_inode(fs, di->i_blkno, (char *)di);
+	if (!ret && cleared)
+		printf("Slot %d's local alloc replayed successfully\n", slot);
+
+bail:
+	return ret;
+}
+
+errcode_t o2fsck_replay_local_allocs(ocfs2_filesys *fs)
+{
+	return handle_slots_system_file(fs,
+					LOCAL_ALLOC_SYSTEM_INODE,
+					ocfs2_clear_local_alloc);
+}
-- 
1.5.4.GIT




More information about the Ocfs2-tools-devel mailing list