[Ocfs2-tools-devel] [PATCH] o2image: add interactive mode flag

Mark Fasheh mfasheh at suse.com
Wed May 19 19:21:39 PDT 2010


There is very little danger to the user from taking an Ocfs2 image. We can
write the image out, and if we -ENOSPC the user will see it right away and
can free up space. Thus, there is no "data-integrity" need to query the
user.

The query in o2image isn't like most of our other tools either. o2image only
queries *after* the entire file system is scanned. This means that the user
will have to sit through an expensive operation before being queried to
create the image file.

A user trying to mkfs or tunefs a file system is queried almost immediately,
and always within the reasonable amount of time that an admin would expect a
tool to either finish, continue without interruption or "ask me something".

There is one good reason to query at this moment however - it could be that
the user is low on disk space and would need to free some up before
continuing. So while we want to allow a "fallback query", I don't feel it
should be the default and in fact it does more harm as the default since it
tends to generate confusion in first time users.

This patch changes o2image to proceed with image creation, unless the '-i'
or "interactive mode" switch is given. Users using this switch get exactly
the behavior we have today - once the image size is known, we tell them how
much space it will take so they have a chance to clean up files.

Writes of the image back to a block device are a seperate issue and are not
addressed by this patch. As the code is written today, o2image always
queries in "install" mode (-I).

Signed-off-by: Mark Fasheh <mfasheh at suse.com>
---
 o2image/o2image.8.in |    6 +++++-
 o2image/o2image.c    |   14 +++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/o2image/o2image.8.in b/o2image/o2image.8.in
index 59e0370..cfbf6fe 100644
--- a/o2image/o2image.8.in
+++ b/o2image/o2image.8.in
@@ -34,9 +34,13 @@ and let the tool create the image-file in the packed format.
 
 .TP
 \fB\-I\fR
-Restores meta-data from the image-file onto the device. \fBCAUTION: This option could
+Restores meta-data from the image-file onto the device.\fBCAUTION: This option could
 corrupt the file system.\fR
 
+.TP
+\fB\-i\fR
+Interactive mode - before writing out the image file print it's size and ask whether to proceed. This setting only applies when '-I' is not specified. It can be useful when the file system holding the image is low on disk space and the user might need to free up space once the target image size is calculated.
+
 .SH "EXAMPLES"
 
 .TS
diff --git a/o2image/o2image.c b/o2image/o2image.c
index aa73dfb..41d96e3 100644
--- a/o2image/o2image.c
+++ b/o2image/o2image.c
@@ -48,7 +48,7 @@ char *program_name = NULL;
 
 static void usage(void)
 {
-	fprintf(stderr, ("Usage: %s [-rI] device image_file\n"),
+	fprintf(stderr, ("Usage: %s [-frI] device image_file\n"),
 		program_name);
 	exit(1);
 }
@@ -569,7 +569,8 @@ int main(int argc, char **argv)
 	int open_flags		= 0;
 	int raw_flag      	= 0;
 	int install_flag  	= 0;
-	int fd            	= 0;
+	int interactive		= 0;
+	int fd            	= 1;
 	int c;
 
 	if (argc && *argv)
@@ -578,7 +579,7 @@ int main(int argc, char **argv)
 	initialize_ocfs_error_table();
 
 	optind = 0;
-	while((c = getopt(argc, argv, "rI")) != EOF) {
+	while((c = getopt(argc, argv, "irI")) != EOF) {
 		switch (c) {
 		case 'r':
 			raw_flag++;
@@ -586,6 +587,9 @@ int main(int argc, char **argv)
 		case 'I':
 			install_flag++;
 			break;
+		case 'i':
+			interactive = 1;
+			break;
 		default:
 			usage();
 		}
@@ -662,8 +666,8 @@ int main(int argc, char **argv)
 		fd = 1;
 	else {
 		/* prompt user for image creation */
-		if (!install_flag && !prompt_image_creation(ofs, raw_flag,
-					dest_file))
+		if (interactive && !install_flag &&
+		    !prompt_image_creation(ofs, raw_flag, dest_file))
 			goto out;
 		fd = open64(dest_file, O_CREAT|O_TRUNC|O_WRONLY, 0600);
 		if (fd < 0) {
-- 
1.6.4.2





More information about the Ocfs2-tools-devel mailing list