linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] e2image: Print a warning if running over a mounted filesystem
@ 2013-09-26 21:00 Carlos Maiolino
  2013-09-26 22:12 ` Eric Sandeen
  2013-09-26 23:56 ` Theodore Ts'o
  0 siblings, 2 replies; 10+ messages in thread
From: Carlos Maiolino @ 2013-09-26 21:00 UTC (permalink / raw)
  To: linux-ext4

Several users use to run e2image over a mounted filesystem, providing
inconsistent, useless e2images.
This patch adds a warning in such cases, notifying the user and also adds a
force option making e2image able to run over Read-only filesystems.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 misc/Makefile.in |  2 +-
 misc/e2image.c   | 18 ++++++++++++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/misc/Makefile.in b/misc/Makefile.in
index 8a69855..2e20b25 100644
--- a/misc/Makefile.in
+++ b/misc/Makefile.in
@@ -49,7 +49,7 @@ UUIDGEN_OBJS=	uuidgen.o
 UUIDD_OBJS=	uuidd.o
 DUMPE2FS_OBJS=	dumpe2fs.o
 BADBLOCKS_OBJS=	badblocks.o
-E2IMAGE_OBJS=	e2image.o
+E2IMAGE_OBJS=	e2image.o ismounted.o
 FSCK_OBJS=	fsck.o base_device.o ismounted.o
 BLKID_OBJS=	blkid.o
 FILEFRAG_OBJS=	filefrag.o
diff --git a/misc/e2image.c b/misc/e2image.c
index 885a794..6f6329a 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -49,6 +49,8 @@ extern int optind;
 
 #define QCOW_OFLAG_COPIED     (1LL << 63)
 
+/* ismounted.h */
+extern int is_mounted(const char *file);
 
 const char * program_name = "e2image";
 char * device_name = NULL;
@@ -87,7 +89,7 @@ static int get_bits_from_size(size_t size)
 
 static void usage(void)
 {
-	fprintf(stderr, _("Usage: %s [-rsIQa] device image_file\n"),
+	fprintf(stderr, _("Usage: %s [-rsIQaf] device image_file\n"),
 		program_name);
 	exit (1);
 }
@@ -1255,6 +1257,7 @@ int main (int argc, char ** argv)
 	int qcow2_fd = 0;
 	int fd = 0;
 	int ret = 0;
+	int ignore_mounted = 0;
 	struct stat st;
 
 #ifdef ENABLE_NLS
@@ -1269,7 +1272,7 @@ int main (int argc, char ** argv)
 	if (argc && *argv)
 		program_name = *argv;
 	add_error_table(&et_ext2_error_table);
-	while ((c = getopt(argc, argv, "rsIQa")) != EOF)
+	while ((c = getopt(argc, argv, "rsIQaf")) != EOF)
 		switch (c) {
 		case 'I':
 			flags |= E2IMAGE_INSTALL_FLAG;
@@ -1290,6 +1293,9 @@ int main (int argc, char ** argv)
 		case 'a':
 			all_data = 1;
 			break;
+		case 'f':
+			ignore_mounted = 1;
+			break;
 		default:
 			usage();
 		}
@@ -1305,6 +1311,14 @@ int main (int argc, char ** argv)
 	device_name = argv[optind];
 	image_fn = argv[optind+1];
 
+	if (is_mounted(device_name) && !ignore_mounted) {
+		fprintf(stderr, "\nWarning: Running e2image on a mounted "
+				"filesystem can result in an inconsistent "
+				"image which will not be useful. Use -f "
+				"option if you really want to do that.\n");
+		exit(1);
+	}
+
 	if (flags & E2IMAGE_INSTALL_FLAG) {
 		install_image(device_name, image_fn, img_type);
 		exit (0);
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread
* [PATCH] e2image: Print a warning if running over a mounted filesystem
@ 2013-09-27 19:01 Carlos Maiolino
  2013-09-27 20:00 ` Carlos Maiolino
  2013-09-30 20:24 ` Theodore Ts'o
  0 siblings, 2 replies; 10+ messages in thread
From: Carlos Maiolino @ 2013-09-27 19:01 UTC (permalink / raw)
  To: linux-ext4

Several users use to run e2image over a mounted RW filesystem, providing
inconsistent, useless e2images for debugging purposes.
This patch adds a warning in such cases, notifying the user and also adds a
force option making e2image able to run in such cases.
Also print a warning when not using qcow or raw formats but allows image
creation to proceed, since, such images might be used for metadata backup
purposes.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
 misc/e2image.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/misc/e2image.c b/misc/e2image.c
index 885a794..e467301 100644
--- a/misc/e2image.c
+++ b/misc/e2image.c
@@ -87,7 +87,7 @@ static int get_bits_from_size(size_t size)
 
 static void usage(void)
 {
-	fprintf(stderr, _("Usage: %s [-rsIQa] device image_file\n"),
+	fprintf(stderr, _("Usage: %s [-rsIQaf] device image_file\n"),
 		program_name);
 	exit (1);
 }
@@ -1252,9 +1252,11 @@ int main (int argc, char ** argv)
 	int open_flag = EXT2_FLAG_64BITS;
 	int img_type = 0;
 	int flags = 0;
+	int mount_flags = 0;
 	int qcow2_fd = 0;
 	int fd = 0;
 	int ret = 0;
+	int ignore_rw_mount = 0;
 	struct stat st;
 
 #ifdef ENABLE_NLS
@@ -1269,7 +1271,7 @@ int main (int argc, char ** argv)
 	if (argc && *argv)
 		program_name = *argv;
 	add_error_table(&et_ext2_error_table);
-	while ((c = getopt(argc, argv, "rsIQa")) != EOF)
+	while ((c = getopt(argc, argv, "rsIQaf")) != EOF)
 		switch (c) {
 		case 'I':
 			flags |= E2IMAGE_INSTALL_FLAG;
@@ -1290,6 +1292,9 @@ int main (int argc, char ** argv)
 		case 'a':
 			all_data = 1;
 			break;
+		case 'f':
+			ignore_rw_mount = 1;
+			break;
 		default:
 			usage();
 		}
@@ -1305,6 +1310,31 @@ int main (int argc, char ** argv)
 	device_name = argv[optind];
 	image_fn = argv[optind+1];
 
+	ext2fs_check_if_mounted(device_name, &mount_flags);
+
+	if ((mount_flags & EXT2_MF_MOUNTED) &&
+	   !(mount_flags & EXT2_MF_READONLY)) {
+		fprintf(stderr, "\nWarning: Running e2image on a mounted "
+				"RW filesystem can result in an inconsistent "
+				"image which will not be useful for "
+				"debugging purposes.\n");
+		/*
+		 * A force is required here once qcow and raw image
+		 * formats (img_type is set) are mostly used for
+		 * debugging purposes, while, a "normal" image is
+		 * usually collected for metadata backup.
+		 *
+		 * An inconsistent image is almost useless for
+		 * debugging, so we ensure the filesystem is read-only
+		 * before continue (unless the user force the image creation)
+		 */
+		if (img_type && !ignore_rw_mount) {
+			fprintf(stderr, "Use -f option if you really want to "
+					"do that.\n");
+			exit(1);
+		}
+	}
+
 	if (flags & E2IMAGE_INSTALL_FLAG) {
 		install_image(device_name, image_fn, img_type);
 		exit (0);
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-09-30 20:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-26 21:00 [PATCH] e2image: Print a warning if running over a mounted filesystem Carlos Maiolino
2013-09-26 22:12 ` Eric Sandeen
2013-09-26 23:56 ` Theodore Ts'o
2013-09-27  0:39   ` Eric Sandeen
2013-09-27  0:48     ` Carlos Maiolino
2013-09-30 20:19       ` Theodore Ts'o
  -- strict thread matches above, loose matches on Subject: below --
2013-09-27 19:01 Carlos Maiolino
2013-09-27 20:00 ` Carlos Maiolino
2013-09-30 20:24 ` Theodore Ts'o
2013-09-30 20:35   ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).