Cédric Bosdonnat
2016-Jun-08 12:57 UTC
[Libguestfs] [PATCH] filesystems: don't try to get the size of btrfs subvolume
virt-filesystem -l tries to get the size of btrfs subvolumes, which results in an error. Teach it to skip the subvolumes. --- cat/filesystems.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/cat/filesystems.c b/cat/filesystems.c index f1c2852..f679517 100644 --- a/cat/filesystems.c +++ b/cat/filesystems.c @@ -476,9 +476,27 @@ do_output_filesystems (void) } } if ((columns & COLUMN_SIZE)) { - size = guestfs_blockdev_getsize64 (g, fses[i]); - if (size == -1) + CLEANUP_FREE char *device = guestfs_mountable_device (g, fses[i]); + CLEANUP_FREE char *subvolume = NULL; + + guestfs_push_error_handler (g, NULL, NULL); + + subvolume = guestfs_mountable_subvolume (g, fses[i]); + if (subvolume == NULL && guestfs_last_errno (g) != EINVAL) { + fprintf (stderr, + _("%s: cannot determine the subvolume for %s: %s (%d)\n"), + guestfs_int_program_name, fses[i], + guestfs_last_error (g), guestfs_last_errno (g)); exit (EXIT_FAILURE); + } + + guestfs_pop_error_handler (g); + + if (!device || !subvolume) { + size = guestfs_blockdev_getsize64 (g, fses[i]); + if (size == -1) + exit (EXIT_FAILURE); + } } if (is_md (fses[i])) -- 2.6.6
Richard W.M. Jones
2016-Jun-09 11:18 UTC
Re: [Libguestfs] [PATCH] filesystems: don't try to get the size of btrfs subvolume
On Wed, Jun 08, 2016 at 02:57:07PM +0200, Cédric Bosdonnat wrote:> virt-filesystem -l tries to get the size of btrfs subvolumes, which > results in an error. Teach it to skip the subvolumes. > --- > cat/filesystems.c | 22 ++++++++++++++++++++-- > 1 file changed, 20 insertions(+), 2 deletions(-) > > diff --git a/cat/filesystems.c b/cat/filesystems.c > index f1c2852..f679517 100644 > --- a/cat/filesystems.c > +++ b/cat/filesystems.c > @@ -476,9 +476,27 @@ do_output_filesystems (void) > } > } > if ((columns & COLUMN_SIZE)) { > - size = guestfs_blockdev_getsize64 (g, fses[i]); > - if (size == -1) > + CLEANUP_FREE char *device = guestfs_mountable_device (g, fses[i]); > + CLEANUP_FREE char *subvolume = NULL; > + > + guestfs_push_error_handler (g, NULL, NULL); > + > + subvolume = guestfs_mountable_subvolume (g, fses[i]); > + if (subvolume == NULL && guestfs_last_errno (g) != EINVAL) { > + fprintf (stderr, > + _("%s: cannot determine the subvolume for %s: %s (%d)\n"), > + guestfs_int_program_name, fses[i], > + guestfs_last_error (g), guestfs_last_errno (g));Don't print the raw errno here. You can write: fprintf (stderr, _("%s: cannot determine the subvolume for %s: %s: %s\n"), guestfs_int_program_name, fses[i], guestfs_last_error (g), strerror (guestfs_last_errno (g))); Rich.> exit (EXIT_FAILURE); > + } > + > + guestfs_pop_error_handler (g); > + > + if (!device || !subvolume) { > + size = guestfs_blockdev_getsize64 (g, fses[i]); > + if (size == -1) > + exit (EXIT_FAILURE); > + } > } > > if (is_md (fses[i])) > -- > 2.6.6 > > _______________________________________________ > Libguestfs mailing list > Libguestfs@redhat.com > https://www.redhat.com/mailman/listinfo/libguestfs-- 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
Maybe Matching Threads
- [PATCH v2] filesystems: don't try to get the size of btrfs subvolume
- [PATCH] filesystems: fix size reporting for filesystems
- Re: [PATCH 3/3] fish: fix btrfs subvolumes display in error case
- [PATCH v2 3/3] fish: fix btrfs subvolumes display in error case
- [PATCH 3/3] fish: fix btrfs subvolumes display in error case