Pino Toscano
2016-Mar-02 13:45 UTC
[Libguestfs] [PATCH] daemon: do not fail list-disk-labels w/o labels set
If there are no labels set for the disks, the directory with the symlinks will not even exists, causing list-disk-labels to fail with ENOENT. In this situation, act as if the directory was there, but empty. --- daemon/devsparts.c | 7 +++++++ generator/actions.ml | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/daemon/devsparts.c b/daemon/devsparts.c index 7b92bf6..7c690f8 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -316,6 +316,13 @@ do_list_disk_labels (void) dir = opendir (GUESTFSDIR); if (!dir) { + if (errno == ENOENT) { + /* The directory does not exist, and usually this happens when + * there are no labels set. In this case, act as if the directory + * was empty. + */ + return empty_list (); + } reply_with_perror ("opendir: %s", GUESTFSDIR); return NULL; } diff --git a/generator/actions.ml b/generator/actions.ml index 9c34463..287d7f5 100644 --- a/generator/actions.ml +++ b/generator/actions.ml @@ -11336,6 +11336,18 @@ silently create an ext2 filesystem instead." }; name = "list_disk_labels"; added = (1, 19, 49); style = RHashtable "labels", [], []; proc_nr = Some 369; + tests = [ + (* The test disks have no labels, so we can be sure there are + * no labels. See in tests/disk-labels/ for tests checking + * for actual disk labels. + * + * Also, we make use of the assumption that RHashtable is a + * char*[] in C, so an empty hash has just a NULL element. + *) + InitScratchFS, Always, TestResult ( + [["list_disk_labels"]], + "is_string_list (ret, 0)"), []; + ]; shortdesc = "mapping of disk labels to devices"; longdesc = "\ If you add drives using the optional C<label> parameter -- 2.5.0
Richard W.M. Jones
2016-Mar-02 15:45 UTC
Re: [Libguestfs] [PATCH] daemon: do not fail list-disk-labels w/o labels set
On Wed, Mar 02, 2016 at 02:45:04PM +0100, Pino Toscano wrote:> If there are no labels set for the disks, the directory with the > symlinks will not even exists, causing list-disk-labels to fail with > ENOENT. In this situation, act as if the directory was there, but > empty. > --- > daemon/devsparts.c | 7 +++++++ > generator/actions.ml | 12 ++++++++++++ > 2 files changed, 19 insertions(+) > > diff --git a/daemon/devsparts.c b/daemon/devsparts.c > index 7b92bf6..7c690f8 100644 > --- a/daemon/devsparts.c > +++ b/daemon/devsparts.c > @@ -316,6 +316,13 @@ do_list_disk_labels (void) > > dir = opendir (GUESTFSDIR); > if (!dir) { > + if (errno == ENOENT) { > + /* The directory does not exist, and usually this happens when > + * there are no labels set. In this case, act as if the directory > + * was empty. > + */ > + return empty_list (); > + } > reply_with_perror ("opendir: %s", GUESTFSDIR); > return NULL; > } > diff --git a/generator/actions.ml b/generator/actions.ml > index 9c34463..287d7f5 100644 > --- a/generator/actions.ml > +++ b/generator/actions.ml > @@ -11336,6 +11336,18 @@ silently create an ext2 filesystem instead." }; > name = "list_disk_labels"; added = (1, 19, 49); > style = RHashtable "labels", [], []; > proc_nr = Some 369; > + tests = [ > + (* The test disks have no labels, so we can be sure there are > + * no labels. See in tests/disk-labels/ for tests checking > + * for actual disk labels. > + * > + * Also, we make use of the assumption that RHashtable is a > + * char*[] in C, so an empty hash has just a NULL element. > + *) > + InitScratchFS, Always, TestResult ( > + [["list_disk_labels"]], > + "is_string_list (ret, 0)"), []; > + ]; > shortdesc = "mapping of disk labels to devices"; > longdesc = "\ > If you add drives using the optional C<label> parameter > --ACK. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Apparently Analagous Threads
- [PATCH 1/2] daemon: free the string on stringsbuf add failure
- [PATCH 2/2] daemon: fix cleanup of stringsbuf usages
- [PATCH v3 0/3] Add support for disk labels and hotplugging.
- [PATCH v4 0/5] Finish hotplugging support.
- [PATCH 1/2] daemon: Fix part-to-dev when the partition name includes p<N>.