Richard W.M. Jones
2010-Jun-01 14:34 UTC
[Libguestfs] [PATCH 0/4] Fix RHBZ#597112 (get-e2uuid command)
This series of patches fixes: https://bugzilla.redhat.com/show_bug.cgi?id=597112 -- 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
Richard W.M. Jones
2010-Jun-01 14:36 UTC
[Libguestfs] [PATCH 1/4] daemon: Generalize the implementation of vfs-type.
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From 85c71f8fff3e80f549342bf995b686ba7303c2b4 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Tue, 1 Jun 2010 13:39:25 +0100 Subject: [PATCH 1/4] daemon: Generalize the implementation of vfs-type. Note that there is no change to the semantics of the code. --- daemon/blkid.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-) diff --git a/daemon/blkid.c b/daemon/blkid.c index dcfac65..1ddc8cd 100644 --- a/daemon/blkid.c +++ b/daemon/blkid.c @@ -27,14 +27,14 @@ #include "daemon.h" #include "actions.h" -char * -do_vfs_type (const char *device) +static char * +get_blkid_tag (const char *device, const char *tag) { char *out, *err; int r; r = command (&out, &err, - "blkid", "-o", "value", "-s", "TYPE", device, NULL); + "blkid", "-o", "value", "-s", tag, device, NULL); if (r == -1) { reply_with_error ("%s: %s", device, err); free (out); @@ -51,3 +51,9 @@ do_vfs_type (const char *device) return out; /* caller frees */ } + +char * +do_vfs_type (const char *device) +{ + return get_blkid_tag (device, "TYPE"); +} -- 1.6.6.1
Richard W.M. Jones
2010-Jun-01 14:37 UTC
[Libguestfs] [PATCH 2/4] daemon: Kill blkid cache to improve reliability of blkid commands.
-- 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 -------------- next part -------------->From 21c42e9fabf6cea3d564e338a314479ef120502a Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Tue, 1 Jun 2010 15:27:57 +0100 Subject: [PATCH 2/4] daemon: Kill blkid cache to improve reliability of blkid commands. By killing the cache file, we make blkid work in situations such as a just-created filesystem. --- daemon/blkid.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/daemon/blkid.c b/daemon/blkid.c index 1ddc8cd..a619730 100644 --- a/daemon/blkid.c +++ b/daemon/blkid.c @@ -33,6 +33,13 @@ get_blkid_tag (const char *device, const char *tag) char *out, *err; int r; + /* Kill the cache file, forcing blkid to reread values from the + * original filesystems. In blkid there is a '-p' option which is + * supposed to do this, but (a) it doesn't work and (b) that option + * is not supported in RHEL 5. + */ + unlink ("/etc/blkid/blkid.tab"); + r = command (&out, &err, "blkid", "-o", "value", "-s", tag, device, NULL); if (r == -1) { -- 1.6.6.1
Richard W.M. Jones
2010-Jun-01 14:37 UTC
[Libguestfs] [PATCH 3/4] New APIs: vfs-label and vfs-uuid return label and uuid for many fs types.
-- 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 -------------- next part -------------->From 27b730a6820b80a49a4da1af9f4c8e8a952f735e Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Tue, 1 Jun 2010 13:57:12 +0100 Subject: [PATCH 3/4] New APIs: vfs-label and vfs-uuid return label and uuid for many fs types. These APIs generalize the existing 'get-e2label' and 'get-e2uuid' calls, to provide calls which should be able to get the label and UUID for most filesystem types. These use 'blkid' to do the work. I have tested that the blkid commands themselves work on RHEL 5. (Suggested by Yufang Zhang). --- daemon/blkid.c | 12 ++++++++++++ src/MAX_PROC_NR | 2 +- src/generator.ml | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletions(-) diff --git a/daemon/blkid.c b/daemon/blkid.c index a619730..108eee6 100644 --- a/daemon/blkid.c +++ b/daemon/blkid.c @@ -64,3 +64,15 @@ do_vfs_type (const char *device) { return get_blkid_tag (device, "TYPE"); } + +char * +do_vfs_label (const char *device) +{ + return get_blkid_tag (device, "LABEL"); +} + +char * +do_vfs_uuid (const char *device) +{ + return get_blkid_tag (device, "UUID"); +} diff --git a/src/MAX_PROC_NR b/src/MAX_PROC_NR index 2197544..f1aaa90 100644 --- a/src/MAX_PROC_NR +++ b/src/MAX_PROC_NR @@ -1 +1 @@ -252 +254 diff --git a/src/generator.ml b/src/generator.ml index 58eaee4..85a867e 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4754,6 +4754,29 @@ Do not confuse this with the guestfish-specific C<alloc> and C<sparse> commands which create a file in the host and attach it as a device."); + ("vfs_label", (RString "label", [Device "device"]), 253, [], + [InitBasicFS, Always, TestOutput ( + [["set_e2label"; "/dev/sda1"; "LTEST"]; + ["vfs_label"; "/dev/sda1"]], "LTEST")], + "get the filesystem label", + "\ +This returns the filesystem label of the filesystem on +C<device>. + +If the filesystem is unlabeled, this returns the empty string."); + + ("vfs_uuid", (RString "uuid", [Device "device"]), 254, [], + (let uuid = uuidgen () in + [InitBasicFS, Always, TestOutput ( + [["set_e2uuid"; "/dev/sda1"; uuid]; + ["vfs_uuid"; "/dev/sda1"]], uuid)]), + "get the filesystem UUID", + "\ +This returns the filesystem UUID of the filesystem on +C<device>. + +If the filesystem does not have a UUID, this returns the empty string."); + ] let all_functions = non_daemon_functions @ daemon_functions -- 1.6.6.1
Richard W.M. Jones
2010-Jun-01 14:38 UTC
[Libguestfs] [PATCH 4/4] Fix and deprecate get_e2label and get_e2uuid (RHBZ#597112).
-- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/ -------------- next part -------------->From da4812ab6b44c29cb3cf181c7aa896420ecb8aa6 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Tue, 1 Jun 2010 14:04:51 +0100 Subject: [PATCH 4/4] Fix and deprecate get_e2label and get_e2uuid (RHBZ#597112). Fix these calls (see description in RHBZ#597112), but also deprecate them since the new calls vfs_label and vfs_uuid can work on any filesystem type. This also adds a regression test for the original bug reported in RHBZ#597112. --- daemon/ext2.c | 84 +---------------------------------------------------- src/generator.ml | 11 +++++-- 2 files changed, 10 insertions(+), 85 deletions(-) diff --git a/daemon/ext2.c b/daemon/ext2.c index 3a075e5..7f9d2e0 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -170,29 +170,7 @@ do_set_e2label (const char *device, const char *label) char * do_get_e2label (const char *device) { - int r, len; - char *out, *err; - - char prog[] = "e2label"; - if (e2prog (prog) == -1) - return NULL; - - r = command (&out, &err, prog, device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - return NULL; - } - - free (err); - - /* Remove any trailing \n from the label. */ - len = strlen (out); - if (len > 0 && out[len-1] == '\n') - out[len-1] = '\0'; - - return out; /* caller frees */ + return do_vfs_label (device); } int @@ -219,65 +197,7 @@ do_set_e2uuid (const char *device, const char *uuid) char * do_get_e2uuid (const char *device) { - int r; - char *out, *err, *p, *q; - - /* It's not so straightforward to get the volume UUID. We have - * to use tune2fs -l and then look for a particular string in - * the output. - */ - char prog[] = "tune2fs"; - if (e2prog (prog) == -1) - return NULL; - - r = command (&out, &err, prog, "-l", device, NULL); - if (r == -1) { - reply_with_error ("%s", err); - free (out); - free (err); - return NULL; - } - - free (err); - - /* Look for /\nFilesystem UUID:\s+/ in the output. */ - p = strstr (out, "\nFilesystem UUID:"); - if (p == NULL) { - reply_with_error ("no Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - p += 17; - while (*p && c_isspace (*p)) - p++; - if (!*p) { - reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - /* Now 'p' hopefully points to the start of the UUID. */ - q = p; - while (*q && (c_isxdigit (*q) || *q == '-')) - q++; - if (!*q) { - reply_with_error ("malformed Filesystem UUID in the output of tune2fs -l"); - free (out); - return NULL; - } - - *q = '\0'; - - p = strdup (p); - if (!p) { - reply_with_perror ("strdup"); - free (out); - return NULL; - } - - free (out); - return p; /* caller frees */ + return do_vfs_uuid (device); } int diff --git a/src/generator.ml b/src/generator.ml index 85a867e..ff772f5 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2222,7 +2222,7 @@ C<device> to C<label>. Filesystem labels are limited to You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label> to return the existing label on a filesystem."); - ("get_e2label", (RString "label", [Device "device"]), 81, [], + ("get_e2label", (RString "label", [Device "device"]), 81, [DeprecatedBy "vfs_label"], [], "get the ext2/3/4 filesystem label", "\ @@ -2252,8 +2252,13 @@ L<tune2fs(8)> manpage. You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid> to return the existing UUID of a filesystem."); - ("get_e2uuid", (RString "uuid", [Device "device"]), 83, [], - [], + ("get_e2uuid", (RString "uuid", [Device "device"]), 83, [DeprecatedBy "vfs_uuid"], + (* Regression test for RHBZ#597112. *) + (let uuid = uuidgen () in + [InitBasicFS, Always, TestOutput ( + [["mke2journal"; "1024"; "/dev/sdb"]; + ["set_e2uuid"; "/dev/sdb"; uuid]; + ["get_e2uuid"; "/dev/sdb"]], uuid)]), "get the ext2/3/4 filesystem UUID", "\ This returns the ext2/3/4 filesystem UUID of the filesystem on -- 1.6.6.1