[Libguestfs] [PATCH v3 8/8] lib/canonical-name.c: Hide EINVAL error from underlying API call.

Martin Kletzander mkletzan at redhat.com
Fri Oct 9 09:47:28 UTC 2020


On Thu, Sep 17, 2020 at 01:40:04PM +0100, Richard W.M. Jones wrote:
>When guestfs_lvm_canonical_lv_name was called with a /dev/dm* or
>/dev/mapper* name which was not an LV then a noisy error would be
>printed.  This would typically have happened with encrypted disks, and
>now happens very noticably when inspecting Windows BitLocker-
>encrypted guests.
>
>Using the modified error behaviour of this API from the previous
>commit we can now hide that error in that specific case.  (Even in
>this case the underlying error message still gets logged in debug
>output).
>---
> lib/canonical-name.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
>diff --git a/lib/canonical-name.c b/lib/canonical-name.c
>index 052bbf12c..e0c7918b4 100644
>--- a/lib/canonical-name.c
>+++ b/lib/canonical-name.c
>@@ -46,9 +46,14 @@ guestfs_impl_canonical_device_name (guestfs_h *g, const char *device)
>   }
>   else if (STRPREFIX (device, "/dev/mapper/") ||
>            STRPREFIX (device, "/dev/dm-")) {
>-    /* XXX hide errors */
>+    guestfs_push_error_handler (g, NULL, NULL);

Doesn't this hide the other error which might be important as well?  The only
one I can find it the file not existing, but it means this function might fail
without an error message if I understand it correctly.

>     ret = guestfs_lvm_canonical_lv_name (g, device);
>-    if (ret == NULL)
>+    guestfs_pop_error_handler (g);
>+    /* EINVAL is expected if the device is somelike a LUKS- or
>+     * BitLocker-encrypted volume, so simply return the original
>+     * name in that case.
>+     */
>+    if (ret == NULL && guestfs_last_errno (g) == EINVAL)
>       ret = safe_strdup (g, device);
>   }
>   else
>-- 
>2.27.0
>
>_______________________________________________
>Libguestfs mailing list
>Libguestfs at redhat.com
>https://www.redhat.com/mailman/listinfo/libguestfs
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20201009/865284dd/attachment.sig>


More information about the Libguestfs mailing list