[PATCH 1/2] ext2: tweak the error returned message of resize2fs-M(BZ755729)
Tweak the error message "e2fsck -f" and "e2fsck -fy" to "e2fsck-f" and "e2fsck-fy". Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 79fd354..9fe938e 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -277,9 +277,25 @@ do_resize2fs_M (const char *device) if (e2prog (prog) == -1) return -1; - r = command (NULL, &err, prog, "-M" , device, NULL); + r = command (NULL, &err, prog, "-M", device, NULL); if (r == -1) { - reply_with_error ("%s", err); + int i = 0; + int len = strlen (err); + char *err_wrap = malloc (len + 1); + if (!err_wrap) + goto err_out; + char *p = strstr (err, "e2fsck -f"); + if (p) { + strncpy (err_wrap, err, p - err); + err_wrap[p - err] = '\0'; + sprintf(err_wrap + (p - err), "%s%s", "e2fsck-f", p + 9); + reply_with_error ("%s", err_wrap); + } else { + reply_with_error ("%s", err); + } + + free (err_wrap); +err_out: free (err); return -1; } -- 1.7.8
Add a new api e2fsck-fy for resize2fs. Sometimes e2fsck-f is not enough. If resiz2fs return the message says: " Please use e2fsck-fy first", we just haven't such a command, it's so awkward. Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 21 +++++++++++++++++++++ generator/generator_actions.ml | 15 +++++++++++++++ src/MAX_PROC_NR | 2 +- 3 files changed, 37 insertions(+), 1 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 9fe938e..4f3710d 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -333,6 +333,27 @@ do_e2fsck_f (const char *device) } int +do_e2fsck_fy (const char *device) +{ + char *err; + int r; + + char prog[] = "e2fsck"; + if (e2prog (prog) == -1) + return -1; + + r = commandr (NULL, &err, prog, "-f", "-y", device, NULL); + if (r == -1 || r >= 2) { + reply_with_error ("%s", err); + free (err); + return -1; + } + + free (err); + return 0; +} + +int do_mke2journal (int blocksize, const char *device) { char *err; diff --git a/generator/generator_actions.ml b/generator/generator_actions.ml index fb82bb6..fc3193a 100644 --- a/generator/generator_actions.ml +++ b/generator/generator_actions.ml @@ -3454,6 +3454,7 @@ are activated or deactivated."); ["umount"; "/"]; ["lvresize"; "/dev/VG/LV"; "20"]; ["e2fsck_f"; "/dev/VG/LV"]; + ["e2fsck_fy"; "/dev/VG/LV"]; ["resize2fs"; "/dev/VG/LV"]; ["mount_options"; ""; "/dev/VG/LV"; "/"]; ["cat"; "/new"]], "test content"); @@ -6597,6 +6598,20 @@ The usage of this device, for example C<filesystem> or C<raid>. =back"); + ("e2fsck_fy", (RErr, [Device "device"], []), 304, [], + [], (* lvresize tests this *) + "check an ext2/ext3 filesystem", + "\ +This force to check the filesystem even it appears to be clean, +and assume an answer of 'yes' to all questions, allows e2fsck +to be used no-interactively. + +This command is only needed when C<guestfs_e2fsck_f> even can't do +things for C<guestfs_resize2fs> (q.v.). Normally you should use +C<guestfs_fsck>. + +When using this, you should know clearly what are you doing now."); + ] let all_functions = non_daemon_functions @ daemon_functions diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 8160622..873b744 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -303 +304 -- 1.7.8
On Fri, Jan 13, 2012 at 02:27:50PM +0800, Wanlong Gao wrote:
Add a new api e2fsck-fy for resize2fs. Sometimes e2fsck-f is not enough.
If resiz2fs return the message says: " Please use e2fsck-fy first", we just haven't such a command, it's so awkward.
Since we are going to rewrite the error message, can we change it to say "use e2fsck-f first"? It's not really clear to me what the difference is between 'e2fsck -p -f' (which is what we use for the 'e2fsck-f' command) and 'e2fsck -y -f'. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
On 01/13/2012 06:12 PM, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 02:27:50PM +0800, Wanlong Gao wrote:
Add a new api e2fsck-fy for resize2fs. Sometimes e2fsck-f is not enough.
If resiz2fs return the message says: " Please use e2fsck-fy first", we just haven't such a command, it's so awkward.
Since we are going to rewrite the error message, can we change it to say "use e2fsck-f first"?
Yes, normally it will say "use e2fsck-f", but after use e2fsck-f, then resize2fs still fails, it'll say "use e2fsck-fy".
It's not really clear to me what the difference is between 'e2fsck -p -f' (which is what we use for the 'e2fsck-f' command) and 'e2fsck -y -f'.
"-p" : correct the errors which is not dangerous, but say "n" to some "may be dangerous" ones. "-y" : always say "y" to try to fix the errors whether it is safe or not. so, when using "-y", you should know what are you doing now. Thanks -Wanlong Gao
Rich.
On Fri, Jan 13, 2012 at 07:09:38PM +0800, Wanlong Gao wrote:
On 01/13/2012 06:12 PM, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 02:27:50PM +0800, Wanlong Gao wrote:
Add a new api e2fsck-fy for resize2fs. Sometimes e2fsck-f is not enough.
If resiz2fs return the message says: " Please use e2fsck-fy first", we just haven't such a command, it's so awkward.
Since we are going to rewrite the error message, can we change it to say "use e2fsck-f first"?
Yes, normally it will say "use e2fsck-f", but after use e2fsck-f, then resize2fs still fails, it'll say "use e2fsck-fy".
It's not really clear to me what the difference is between 'e2fsck -p -f' (which is what we use for the 'e2fsck-f' command) and 'e2fsck -y -f'.
"-p" : correct the errors which is not dangerous, but say "n" to some "may be dangerous" ones. "-y" : always say "y" to try to fix the errors whether it is safe or not. so, when using "-y", you should know what are you doing now.
I see. How about designing a new API called "e2fsck" which has optional arguments: OBool "correct" (* same as "-p" *); OBool "forceall" (* same as "-y" *) The advantage of the new API is that we can extend it in future. That would change the first patch: Instead of rewriting the error message, just replace it, eg something like this: if (strstr (err, "e2fsck -f")) { free (err); reply_with_error ("you need to run e2fsck with the correct and/or forceall options first"); } else { reply_with_error ("%s", err); } Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
On 01/13/2012 09:08 PM, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 07:09:38PM +0800, Wanlong Gao wrote:
On 01/13/2012 06:12 PM, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 02:27:50PM +0800, Wanlong Gao wrote:
Add a new api e2fsck-fy for resize2fs. Sometimes e2fsck-f is not enough.
If resiz2fs return the message says: " Please use e2fsck-fy first", we just haven't such a command, it's so awkward.
Since we are going to rewrite the error message, can we change it to say "use e2fsck-f first"?
Yes, normally it will say "use e2fsck-f", but after use e2fsck-f, then resize2fs still fails, it'll say "use e2fsck-fy".
It's not really clear to me what the difference is between 'e2fsck -p -f' (which is what we use for the 'e2fsck-f' command) and 'e2fsck -y -f'.
"-p" : correct the errors which is not dangerous, but say "n" to some "may be dangerous" ones. "-y" : always say "y" to try to fix the errors whether it is safe or not. so, when using "-y", you should know what are you doing now.
I see.
How about designing a new API called "e2fsck" which has optional arguments:
OBool "correct" (* same as "-p" *); OBool "forceall" (* same as "-y" *)
The advantage of the new API is that we can extend it in future.
That would change the first patch: Instead of rewriting the error message, just replace it, eg something like this:
if (strstr (err, "e2fsck -f")) { free (err); reply_with_error ("you need to run e2fsck with the correct and/or forceall options first"); } else { reply_with_error ("%s", err); }
yeah, it's better, will do like this. Thanks Rich -Wanlong Gao
Rich.
On Fri, Jan 13, 2012 at 02:27:49PM +0800, Wanlong Gao wrote:
Tweak the error message "e2fsck -f" and "e2fsck -fy" to "e2fsck-f" and "e2fsck-fy".
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 79fd354..9fe938e 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -277,9 +277,25 @@ do_resize2fs_M (const char *device) if (e2prog (prog) == -1) return -1;
- r = command (NULL, &err, prog, "-M" , device, NULL); + r = command (NULL, &err, prog, "-M", device, NULL); if (r == -1) { - reply_with_error ("%s", err); + int i = 0; + int len = strlen (err);
Use 'size_t' (instead of 'int') for the return value of strlen. What is 'i' used for?
+ char *err_wrap = malloc (len + 1); + if (!err_wrap) + goto err_out;
You need to call 'reply_with_error' or 'reply_with_perror' exactly once on each error path. So here you'd need to call reply_with_perror ("malloc"); before the 'goto'.
+ char *p = strstr (err, "e2fsck -f"); + if (p) { + strncpy (err_wrap, err, p - err);
Isn't it better to use memcpy here? AFAIK using strncpy is almost always wrong. (Jim?)
+ err_wrap[p - err] = '\0'; + sprintf(err_wrap + (p - err), "%s%s", "e2fsck-f", p + 9); + reply_with_error ("%s", err_wrap); + } else { + reply_with_error ("%s", err); + } + + free (err_wrap); +err_out: free (err); return -1; }
Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 80 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
On 01/13/2012 06:08 PM, Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 02:27:49PM +0800, Wanlong Gao wrote:
Tweak the error message "e2fsck -f" and "e2fsck -fy" to "e2fsck-f" and "e2fsck-fy".
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 79fd354..9fe938e 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -277,9 +277,25 @@ do_resize2fs_M (const char *device) if (e2prog (prog) == -1) return -1;
- r = command (NULL, &err, prog, "-M" , device, NULL); + r = command (NULL, &err, prog, "-M", device, NULL); if (r == -1) { - reply_with_error ("%s", err); + int i = 0; + int len = strlen (err);
Use 'size_t' (instead of 'int') for the return value of strlen.
yeah.
What is 'i' used for?
mistake, forgot to remove it.
+ char *err_wrap = malloc (len + 1); + if (!err_wrap) + goto err_out;
You need to call 'reply_with_error' or 'reply_with_perror' exactly once on each error path. So here you'd need to call reply_with_perror ("malloc"); before the 'goto'.
yes, I see.
+ char *p = strstr (err, "e2fsck -f"); + if (p) { + strncpy (err_wrap, err, p - err);
Isn't it better to use memcpy here? AFAIK using strncpy is almost always wrong. (Jim?)
yes, you are right, I'll change to memcpy. Thanks a lot -Wanlong Gao
+ err_wrap[p - err] = '\0'; + sprintf(err_wrap + (p - err), "%s%s", "e2fsck-f", p + 9); + reply_with_error ("%s", err_wrap); + } else { + reply_with_error ("%s", err); + } + + free (err_wrap); +err_out: free (err); return -1; }
Rich.
Richard W.M. Jones wrote:
On Fri, Jan 13, 2012 at 02:27:49PM +0800, Wanlong Gao wrote:
Tweak the error message "e2fsck -f" and "e2fsck -fy" to "e2fsck-f" and "e2fsck-fy".
Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com> --- daemon/ext2.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/daemon/ext2.c b/daemon/ext2.c index 79fd354..9fe938e 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -277,9 +277,25 @@ do_resize2fs_M (const char *device) if (e2prog (prog) == -1) return -1;
- r = command (NULL, &err, prog, "-M" , device, NULL); + r = command (NULL, &err, prog, "-M", device, NULL); if (r == -1) { - reply_with_error ("%s", err); + int i = 0; + int len = strlen (err);
Use 'size_t' (instead of 'int') for the return value of strlen.
What is 'i' used for?
+ char *err_wrap = malloc (len + 1); + if (!err_wrap) + goto err_out;
You need to call 'reply_with_error' or 'reply_with_perror' exactly once on each error path. So here you'd need to call reply_with_perror ("malloc"); before the 'goto'.
+ char *p = strstr (err, "e2fsck -f"); + if (p) { + strncpy (err_wrap, err, p - err);
Isn't it better to use memcpy here? AFAIK using strncpy is almost always wrong. (Jim?)
I would. The fact that strncpy does not always NUL-terminate makes it hard to use correctly. Better to avoid it in general.
+ err_wrap[p - err] = '\0'; + sprintf(err_wrap + (p - err), "%s%s", "e2fsck-f", p + 9);
Also, as a general rule, it is easier to code and maintain uses of asprintf than separate malloc+sprintf. You can depend on asprintf, since it is provided by gnulib, if needed. And, technically sprintf can fail (with glibc, it may even invoke malloc!), so you should handle failure.
participants (4)
-
Jim Meyering -
Richard W.M. Jones -
Wanlong Gao -
Wanlong Gao