2013-09-30 21:19:31

by Carlos Maiolino

[permalink] [raw]
Subject: [PATCH] e2image: Add image consistency information and -f option to manpage

Adds information regarding image consistency when using e2image on a read-write
filesystem and about -f option used now to force the image creation of a
read-write filesystem

Signed-off-by: Carlos Maiolino <[email protected]>
---
misc/e2image.8.in | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/misc/e2image.8.in b/misc/e2image.8.in
index 84b9729..eb22f42 100644
--- a/misc/e2image.8.in
+++ b/misc/e2image.8.in
@@ -30,6 +30,18 @@ recovering catastrophically corrupted filesystems. In the future,
e2fsck will be enhanced to be able to use the image file to help
recover a badly damaged filesystem.
.PP
+When getting an image to be used for debugging purposes, is necessary that the
+filesystem be unmounted or in a Read-Only state, to ensure the image-file will
+be in a consistent state. Although, it's possible to force an image-file
+creation using the
+.B -f
+option. For images saved for metadata backup purposes (to be restored with
+.B -I
+option),
+.B e2image
+will be backing up only statically located metadata blocks, so, images taken
+from a read-write filesystem are not completely useless, and, although recommended, there is no real need to run it on a Read-Only or unmounted filesystem.
+.PP
If
.I image-file
is \-, then the output of
--
1.8.1.4



2013-10-12 02:54:20

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH] e2image: Add image consistency information and -f option to manpage

On Mon, Sep 30, 2013 at 06:19:25PM -0300, Carlos Maiolino wrote:
> Adds information regarding image consistency when using e2image on a read-write
> filesystem and about -f option used now to force the image creation of a
> read-write filesystem
>
> Signed-off-by: Carlos Maiolino <[email protected]>

Here is the combined commit which I've just added to my tree in the
maint branch. It includes the man page with some clarifications in
the wording. Also I've changed things so that we only print the error
message for e2image -r and e2image -Q.

- Ted

commit 6c327e9ca47fa4e51efe3a6601ad661b8c1a3964
Author: Carlos Maiolino <[email protected]>
Date: Fri Oct 11 21:38:53 2013 -0400

e2image: complain if running e2image -r or -Q on a mounted filesystem

Several users have used e2image on a mounted RW filesystem, resulting in
inconsistent, useless e2images for debugging purposes.

This commit will forbid this and print an error message, although the
user can override this using a new force option.

Signed-off-by: Carlos Maiolino <[email protected]>
Signed-off-by: Theodore Ts'o <[email protected]>

diff --git a/misc/e2image.8.in b/misc/e2image.8.in
index 84b9729..78f0682 100644
--- a/misc/e2image.8.in
+++ b/misc/e2image.8.in
@@ -30,6 +30,16 @@ recovering catastrophically corrupted filesystems. In the future,
e2fsck will be enhanced to be able to use the image file to help
recover a badly damaged filesystem.
.PP
+When saving an e2image for debugging purposes, using either the
+.B \-r
+or
+.B \-Q
+options, the filesystem must be unmounted or be mounted read/only, in order
+for the image file to be in a consistent state. This requirement can be
+overriden using the
+.B -f
+option, but the resulting image file is very likely not going to be useful.
+.PP
If
.I image-file
is \-, then the output of
diff --git a/misc/e2image.c b/misc/e2image.c
index 885a794..4a5bb22 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,19 @@ int main (int argc, char ** argv)
device_name = argv[optind];
image_fn = argv[optind+1];

+ ext2fs_check_if_mounted(device_name, &mount_flags);
+
+ if (img_type && !ignore_rw_mount &&
+ (mount_flags & EXT2_MF_MOUNTED) &&
+ !(mount_flags & EXT2_MF_READONLY)) {
+ fprintf(stderr, "\nRunning e2image on a R/W mounted "
+ "filesystem can result in an\n"
+ "inconsistent image which will not be useful "
+ "for debugging purposes.\n"
+ "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);

2013-10-14 13:08:07

by Carlos Maiolino

[permalink] [raw]
Subject: Re: [PATCH] e2image: Add image consistency information and -f option to manpage

Thanks Ted :-)

On Fri, Oct 11, 2013 at 10:49:05PM -0400, Theodore Ts'o wrote:
> On Mon, Sep 30, 2013 at 06:19:25PM -0300, Carlos Maiolino wrote:
> > Adds information regarding image consistency when using e2image on a read-write
> > filesystem and about -f option used now to force the image creation of a
> > read-write filesystem
> >
> > Signed-off-by: Carlos Maiolino <[email protected]>
>
> Here is the combined commit which I've just added to my tree in the
> maint branch. It includes the man page with some clarifications in
> the wording. Also I've changed things so that we only print the error
> message for e2image -r and e2image -Q.
>
> - Ted
>
> commit 6c327e9ca47fa4e51efe3a6601ad661b8c1a3964
> Author: Carlos Maiolino <[email protected]>
> Date: Fri Oct 11 21:38:53 2013 -0400
>
> e2image: complain if running e2image -r or -Q on a mounted filesystem
>
> Several users have used e2image on a mounted RW filesystem, resulting in
> inconsistent, useless e2images for debugging purposes.
>
> This commit will forbid this and print an error message, although the
> user can override this using a new force option.
>
> Signed-off-by: Carlos Maiolino <[email protected]>
> Signed-off-by: Theodore Ts'o <[email protected]>
>
> diff --git a/misc/e2image.8.in b/misc/e2image.8.in
> index 84b9729..78f0682 100644
> --- a/misc/e2image.8.in
> +++ b/misc/e2image.8.in
> @@ -30,6 +30,16 @@ recovering catastrophically corrupted filesystems. In the future,
> e2fsck will be enhanced to be able to use the image file to help
> recover a badly damaged filesystem.
> .PP
> +When saving an e2image for debugging purposes, using either the
> +.B \-r
> +or
> +.B \-Q
> +options, the filesystem must be unmounted or be mounted read/only, in order
> +for the image file to be in a consistent state. This requirement can be
> +overriden using the
> +.B -f
> +option, but the resulting image file is very likely not going to be useful.
> +.PP
> If
> .I image-file
> is \-, then the output of
> diff --git a/misc/e2image.c b/misc/e2image.c
> index 885a794..4a5bb22 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,19 @@ int main (int argc, char ** argv)
> device_name = argv[optind];
> image_fn = argv[optind+1];
>
> + ext2fs_check_if_mounted(device_name, &mount_flags);
> +
> + if (img_type && !ignore_rw_mount &&
> + (mount_flags & EXT2_MF_MOUNTED) &&
> + !(mount_flags & EXT2_MF_READONLY)) {
> + fprintf(stderr, "\nRunning e2image on a R/W mounted "
> + "filesystem can result in an\n"
> + "inconsistent image which will not be useful "
> + "for debugging purposes.\n"
> + "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);
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

--
Carlos