[Ocfs2-tools-devel] [PATCH 2/9] fsck.ocfs2: Allocate and use duplicate clusters bitmap.

Joel Becker joel.becker at oracle.com
Thu Jul 30 12:25:00 PDT 2009


This bitmap keeps track of any clusters claimed by multiple filesystem
objects.  We will correct the multiply-claimed clusters in latter
changes.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 fsck.ocfs2/fsck.c         |    5 +++++
 fsck.ocfs2/include/fsck.h |    5 ++++-
 fsck.ocfs2/pass1.c        |    4 ++++
 fsck.ocfs2/util.c         |   27 +++++++++++++++++++++++----
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/fsck.ocfs2/fsck.c b/fsck.ocfs2/fsck.c
index df66075..74c18ac 100644
--- a/fsck.ocfs2/fsck.c
+++ b/fsck.ocfs2/fsck.c
@@ -204,6 +204,11 @@ errcode_t o2fsck_state_reinit(ocfs2_filesys *fs, o2fsck_state *ost)
 	ocfs2_bitmap_free(ost->ost_allocated_clusters);
 	ost->ost_allocated_clusters = NULL;
 
+	if (ost->ost_duplicate_clusters) {
+		ocfs2_bitmap_free(ost->ost_duplicate_clusters);
+		ost->ost_duplicate_clusters = NULL;
+	}
+
 	o2fsck_icount_free(ost->ost_icount_in_inodes);
 	ost->ost_icount_in_inodes = NULL;
 
diff --git a/fsck.ocfs2/include/fsck.h b/fsck.ocfs2/include/fsck.h
index aec130d..240286c 100644
--- a/fsck.ocfs2/include/fsck.h
+++ b/fsck.ocfs2/include/fsck.h
@@ -1,4 +1,6 @@
-/*
+/* -*- mode: c; c-basic-offset: 8; -*-
+ * vim: noexpandtab sw=8 ts=8 sts=0:
+ *
  * fsck.h
  *
  * Copyright (C) 2002 Oracle Corporation.  All rights reserved.
@@ -37,6 +39,7 @@ typedef struct _o2fsck_state {
 	ocfs2_bitmap	*ost_reg_inodes;
 
 	ocfs2_bitmap	*ost_allocated_clusters;
+	ocfs2_bitmap    *ost_duplicate_clusters;
 
 	/* This is no more than a cache of what we know the i_link_count
 	 * in each inode to currently be.  If an inode is marked in used_inodes
diff --git a/fsck.ocfs2/pass1.c b/fsck.ocfs2/pass1.c
index ec9bd5b..ede1022 100644
--- a/fsck.ocfs2/pass1.c
+++ b/fsck.ocfs2/pass1.c
@@ -38,6 +38,10 @@
  *  - bitmap of which inodes are directories or regular files
  *  - directory blocks that it finds off of directory inodes
  *
+ * Pass 1 also compiles a bitmap of all clusters used by the filesystem.
+ * If any clusters are shared by more than one inode, a bitmap of
+ * duplicate clusters is also created.
+ *
  * The end of Pass 1 is when the found block bitmap should contain all the
  * blocks in the system that are in use.  This is used to derive the set of
  * clusters that should be allocated.  The cluster chain allocator is loaded
diff --git a/fsck.ocfs2/util.c b/fsck.ocfs2/util.c
index b12e3e1..6c9e0fd 100644
--- a/fsck.ocfs2/util.c
+++ b/fsck.ocfs2/util.c
@@ -58,13 +58,32 @@ void o2fsck_write_inode(o2fsck_state *ost, uint64_t blkno,
 
 void o2fsck_mark_cluster_allocated(o2fsck_state *ost, uint32_t cluster)
 {
-	int was_set;
+	int was_set = 0;
+	errcode_t ret;
+	const char *whoami = __FUNCTION__;
 
 	o2fsck_bitmap_set(ost->ost_allocated_clusters, cluster, &was_set);
 
-	if (was_set) /* XX can go away one all callers handle this */
-		com_err(__FUNCTION__, OCFS2_ET_INTERNAL_FAILURE,
-			"!! duplicate cluster %"PRIu32, cluster);
+	if (!was_set)
+		return;
+
+	if (!ost->ost_duplicate_clusters) {
+		fprintf(stderr,
+			"Duplicate clusters detected.  Pass 1b will be run\n");
+
+		ret = ocfs2_cluster_bitmap_new(ost->ost_fs,
+					       "duplicate clusters",
+					       &ost->ost_duplicate_clusters);
+		if (ret) {
+			com_err(whoami, ret,
+				"while allocating duplicate cluster bitmap");
+			return;
+		}
+	}
+
+	verbosef("Cluster %"PRIu32" is allocated to more than one object\n",
+		 cluster);
+	ocfs2_bitmap_set(ost->ost_duplicate_clusters, cluster, NULL);
 }
 
 void o2fsck_mark_clusters_allocated(o2fsck_state *ost, uint32_t cluster,
-- 
1.6.3.3




More information about the Ocfs2-tools-devel mailing list