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

Tao Ma tao.ma at oracle.com
Thu Sep 18 08:01: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         |   79 ++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 0 deletions(-)

diff --git a/fsck.ocfs2/include/slot_recovery.h b/fsck.ocfs2/include/slot_recovery.h
index 2d8e756..a5cb513 100644
--- a/fsck.ocfs2/include/slot_recovery.h
+++ b/fsck.ocfs2/include/slot_recovery.h
@@ -26,6 +26,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 276309b..f4d7528 100644
--- a/fsck.ocfs2/slot_recovery.c
+++ b/fsck.ocfs2/slot_recovery.c
@@ -21,6 +21,7 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 021110-1307, USA.
  */
+#include <ocfs2/bitops.h>
 #include "util.h"
 #include "slot_recovery.h"
 
@@ -82,3 +83,81 @@ 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)
+{
+	errcode_t ret = 0;
+	int bit_off, left, count, start, was_set = 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;
+		}
+
+		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);
+
+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