[Ocfs2-tools-devel] [PATCH 3/3] fsck.ocfs2: Detect locally mounted volume

Sunil Mushran sunil.mushran at oracle.com
Fri Jul 24 17:04:27 PDT 2009


Detect if the volume is mounted locally. If so, warn the user of
the consequences of running fsck on a mounted volume.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 fsck.ocfs2/fsck.c |   31 +++++++++++++++++++++++++------
 1 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/fsck.ocfs2/fsck.c b/fsck.ocfs2/fsck.c
index ae1031f..c89d245 100644
--- a/fsck.ocfs2/fsck.c
+++ b/fsck.ocfs2/fsck.c
@@ -637,6 +637,8 @@ int main(int argc, char **argv)
 	int fsck_mask = FSCK_OK;
 	int slot_recover_err = 0;
 	errcode_t ret;
+	int mount_flags;
+	int proceed = 1;
 
 	memset(ost, 0, sizeof(o2fsck_state));
 	ost->ost_ask = 1;
@@ -746,17 +748,34 @@ int main(int argc, char **argv)
 
 	print_version();
 
-	if (ost->ost_skip_o2cb) {
-		fprintf(stdout, "\nWARNING: YOU HAVE DISABLED THE CLUSTER CHECK. "
-			"CONTINUE ONLY IF YOU\nARE ABSOLUTELY SURE THAT NO "
-			"NODE HAS THIS FILESYSTEM MOUNTED OR IS\nOTHERWISE "
-			"ACCESSING IT. IF UNSURE, DO NOT PROCEED.\n\n");
-		fprintf(stdout, "Proceed (y/N): ");
+	ret = ocfs2_check_if_mounted(filename, &mount_flags);
+	if (ret) {
+		com_err(whoami, ret, "while determining whether %s is mounted.",
+			filename);
+		fsck_mask |= FSCK_ERROR;
+		goto out;
+	}
+
+	if (mount_flags & (OCFS2_MF_MOUNTED | OCFS2_MF_BUSY)) {
+		fprintf(stdout, "\nWARNING!!! Running fsck.ocfs2 on a mounted "
+			"filesystem may cause SEVERE filesystem damage.\n\n");
+		proceed = 0;
+	} else if (ost->ost_skip_o2cb) {
+		fprintf(stdout, "\nWARNING!!! You have disabled the cluster check. "
+			"Continue only if you\nare absolutely sure that NO "
+			"node has this filesystem mounted or is\notherwise "
+			"accessing it. If unsure, do NOT continue.\n\n");
+		proceed = 0;
+	}
+
+	if (!proceed) {
+		fprintf(stdout, "Do you really want to continue (y/N): ");
 		if (toupper(getchar()) != 'Y') {
 			printf("Aborting operation.\n");
 			fsck_mask |= FSCK_CANCELED;
 			goto out;
 		}
+		proceed = 1;
 	}
 
 	if (signal(SIGTERM, handle_signal) == SIG_ERR) {
-- 
1.6.0.4




More information about the Ocfs2-tools-devel mailing list