Wanlong Gao
2012-Jan-13 06:27 UTC
[Libguestfs] [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 at 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
Wanlong Gao
2012-Jan-13 06:27 UTC
[Libguestfs] [PATCH 2/2] NEW API: new api e2fsck-fy for resize2fs
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 at 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
Richard W.M. Jones
2012-Jan-13 10:08 UTC
[Libguestfs] [PATCH 1/2] ext2: tweak the error returned message of resize2fs-M(BZ755729)
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 at 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
Seemingly Similar Threads
- [PATCH 1/3] ext2: tweak the error returned message of resize2fs-M(BZ755729)
- [PATCH v2 1/3] ext2: tweak the error returned message of resize2fs-M(BZ755729)
- [PATCH 0/5] Fixes to resize2fs (RHBZ#755729, RHBZ#801640)
- [PATCH 0/4] Add various ntfs* tools and unify label setting.
- [PATCH v2] Add tune2fs command.