[Ocfs2-tools-devel] [PATCH 3/9] fsck.ocfs2: Add o2fsck_abort()

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


When a void function wants to exit o2fsck, it can't just exit(1).  o2fsck
may have cluster state and locks that need cleaning.  o2fsck_abort()
will send SIGTERM to fsck, thus triggering a clean abort.

Signed-off-by: Joel Becker <joel.becker at oracle.com>
---
 fsck.ocfs2/include/util.h |    3 +++
 fsck.ocfs2/util.c         |   31 ++++++++++++++++---------------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/fsck.ocfs2/include/util.h b/fsck.ocfs2/include/util.h
index c4e58ba..e36c6ae 100644
--- a/fsck.ocfs2/include/util.h
+++ b/fsck.ocfs2/include/util.h
@@ -66,6 +66,9 @@ errcode_t handle_slots_system_file(ocfs2_filesys *fs,
 						     struct ocfs2_dinode *di,
 						     int slot));
 
+/* How to abort but clean up the cluster state */
+void o2fsck_abort(void);
+
 /*
  * Wrap the ocfs2 bitmap functions to abort when errors are found.  They're
  * not supposed to fail, so we want to handle it.
diff --git a/fsck.ocfs2/util.c b/fsck.ocfs2/util.c
index 6c9e0fd..d0211c6 100644
--- a/fsck.ocfs2/util.c
+++ b/fsck.ocfs2/util.c
@@ -77,7 +77,7 @@ void o2fsck_mark_cluster_allocated(o2fsck_state *ost, uint32_t cluster)
 		if (ret) {
 			com_err(whoami, ret,
 				"while allocating duplicate cluster bitmap");
-			return;
+			o2fsck_abort();
 		}
 	}
 
@@ -305,14 +305,9 @@ void __o2fsck_bitmap_set(ocfs2_bitmap *bitmap, uint64_t bitno, int *oldval,
 
 	ret = ocfs2_bitmap_set(bitmap, bitno, oldval);
 	if (ret) {
-		com_err(where, ret,
-			"while trying to set bit %"PRIu64", aborting\n",
+		com_err(where, ret, "while trying to set bit %"PRIu64,
 			bitno);
-		/*
-		 * We abort with SIGTERM so that the signal handler can
-		 * clean up the cluster stack.
-		 */
-		kill(getpid(), SIGTERM);
+		o2fsck_abort();
 	}
 }
 
@@ -323,13 +318,19 @@ void __o2fsck_bitmap_clear(ocfs2_bitmap *bitmap, uint64_t bitno, int *oldval,
 
 	ret = ocfs2_bitmap_clear(bitmap, bitno, oldval);
 	if (ret) {
-		com_err(where, ret,
-			"while trying to clear bit %"PRIu64", aborting\n",
+		com_err(where, ret, "while trying to clear bit %"PRIu64,
 			bitno);
-		/*
-		 * We abort with SIGTERM so that the signal handler can
-		 * clean up the cluster stack.
-		 */
-		kill(getpid(), SIGTERM);
+		o2fsck_abort();
 	}
 }
+
+/*
+ * What if we're somewhere we can't set an error and we need to abort fsck?
+ * We don't want to just exit(1), as we may have some cluster locks, etc.
+ * If we SIGTERM ourselves, our signal handler should do the right thing.
+ */
+void o2fsck_abort(void)
+{
+	fprintf(stderr, "Aborting\n");
+	kill(getpid(), SIGTERM);
+}
-- 
1.6.3.3




More information about the Ocfs2-tools-devel mailing list