[v2] btrfs-progs: add mount status check for btrfs-image
diff mbox

Message ID 1404698211-4236-1-git-send-email-guihc.fnst@cn.fujitsu.com
State Accepted
Headers show

Commit Message

Gui Hecheng July 7, 2014, 1:56 a.m. UTC
When btrfs-image run on a mounted filesystem,
the undergoing fs operations may change what you have imaged a while ago.
In this case, give a warning to remind the user that he may not
get a consistent image he wants.

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
changelog:
	v1->v2: just give a warning if device mounted and let it continue
---
 btrfs-image.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Patch
diff mbox

diff --git a/btrfs-image.c b/btrfs-image.c
index 985aa26..e1d5482 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2570,10 +2570,18 @@  int main(int argc, char *argv[])
 			num_threads = 1;
 	}
 
-	if (create)
+	if (create) {
+		ret = check_mounted(source);
+		if (ret < 0) {
+			fprintf(stderr, "Could not check mount status: %s\n",
+				strerror(-ret));
+			exit(1);
+		} else if (ret)
+			fprintf(stderr, "WARNING: The device is mounted. Make sure you didn't do modifications.\n");
+
 		ret = create_metadump(source, out, num_threads,
 				      compress_level, sanitize, walk_trees);
-	else
+	} else
 		ret = restore_metadump(source, out, old_restore, 1,
 				       multi_devices);
 	if (ret) {