appliance: don't read extfs signature from QCOW2 image directly

If the appliance is a QCOW2 image, function get_root_uuid_with_file()
fails to read ext filesystem signature (0x53EF at offset 0x438) from it.
This results in the following error:

libguestfs: error: /usr/lib64/guestfs/appliance/root: appliance is not
an extfs filesystem

The error itself is harmless, but misleading.  So let's skip retrieving
the signature and UUID in case the image contains QCOW2 header.  It's
safe because in this case we'll retrieve it later from RAW image dumped
from that QCOW2 by "qemu-img dd".

Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
This commit is contained in:
Andrey Drobyshev
2022-04-25 22:35:47 +03:00
committed by Richard W.M. Jones
parent bc96e0b7d7
commit ef8c6593eb

View File

@@ -65,7 +65,7 @@
static char * static char *
get_root_uuid_with_file (guestfs_h *g, const char *appliance) get_root_uuid_with_file (guestfs_h *g, const char *appliance)
{ {
unsigned char magic[2], uuid[16]; unsigned char magic[4], uuid[16];
char *ret; char *ret;
int fd; int fd;
@@ -74,6 +74,10 @@ get_root_uuid_with_file (guestfs_h *g, const char *appliance)
perrorf (g, _("open: %s"), appliance); perrorf (g, _("open: %s"), appliance);
return NULL; return NULL;
} }
if (read (fd, magic, 4) != 4 || !strncmp ((char *) magic, "QFI\xfb", 4)) {
/* No point looking for extfs signature in QCOW2 directly. */
return NULL;
}
if (lseek (fd, 0x438, SEEK_SET) != 0x438) { if (lseek (fd, 0x438, SEEK_SET) != 0x438) {
magic_error: magic_error:
error (g, _("%s: cannot read extfs magic in superblock"), appliance); error (g, _("%s: cannot read extfs magic in superblock"), appliance);