Add workaround for broken "file" utility in Rawhide (RHBZ#1945122).

This commit is contained in:
Richard W.M. Jones 2021-03-31 13:46:53 +01:00
parent 8f6ba6d789
commit a6a11a65c9
6 changed files with 136 additions and 6 deletions

View File

@ -1,7 +1,7 @@
From 49b8b69cb8e10e5476bbe86a708ee1babfe330e8 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 30 Mar 2021 12:56:06 +0100
Subject: [PATCH 1/4] daemon/xfs.c: Fix error message.
Subject: [PATCH 1/5] daemon/xfs.c: Fix error message.
Fixes: commit 87206e4e9e3b0ca813a4ff7b5fac0eccc07a484a
---

View File

@ -1,7 +1,7 @@
From 2216ab2e328457ef172d6bfa534272edf2f81a3a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 30 Mar 2021 12:41:58 +0100
Subject: [PATCH 2/4] tests: Prefer xorriso over genisoimage to generate
Subject: [PATCH 2/5] tests: Prefer xorriso over genisoimage to generate
test.iso
This Debian page explains the upstream situation:

View File

@ -1,7 +1,7 @@
From efb8a766cac4ba8e413594946136bf91e176bb8c Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 30 Mar 2021 13:54:22 +0100
Subject: [PATCH 3/4] daemon: Allow xorriso as an alternative to isoinfo.
Subject: [PATCH 3/5] daemon: Allow xorriso as an alternative to isoinfo.
Currently the guestfs_isoinfo and guestfs_isoinfo_device APIs run
isoinfo inside the appliance to extract the information.

View File

@ -1,7 +1,7 @@
From 2f587bbaec718e414e46c7e6f2a3e2662c3a1c2a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 31 Mar 2021 10:32:52 +0100
Subject: [PATCH 4/4] daemon: Read ISO9660 Primary Volume Descriptor directly.
Subject: [PATCH 4/5] daemon: Read ISO9660 Primary Volume Descriptor directly.
It turns out we can read the information we need for the isoinfo API
directly from the ISO9660 PVD. We don't need to use either isoinfo or

View File

@ -0,0 +1,127 @@
From 278d0d3226f4bdb7c6586986ca46d0a25c976fe4 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 31 Mar 2021 13:40:11 +0100
Subject: [PATCH 5/5] lib/appliance-kcmdline.c: Read UUID directly from
appliance.
Instead of using the external file utility, read the UUID directly
from the extfs filesystem. file 5.40 broke parsing of UUIDs
(https://bugs.astron.com/view.php?id=253).
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1945122
---
lib/appliance-kcmdline.c | 75 +++++++++++++++++++++++++---------------
1 file changed, 48 insertions(+), 27 deletions(-)
diff --git a/lib/appliance-kcmdline.c b/lib/appliance-kcmdline.c
index 6d0deef86..8b78655eb 100644
--- a/lib/appliance-kcmdline.c
+++ b/lib/appliance-kcmdline.c
@@ -27,6 +27,9 @@
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
+#include <libintl.h>
+#include <sys/types.h>
#include "c-ctype.h"
#include "ignore-value.h"
@@ -56,49 +59,67 @@
#define EARLYPRINTK "earlyprintk=pl011,0x9000000"
#endif
-COMPILE_REGEXP (re_uuid, "UUID=([-0-9a-f]+)", 0)
-
-static void
-read_uuid (guestfs_h *g, void *retv, const char *line, size_t len)
-{
- char **ret = retv;
-
- *ret = match1 (g, line, re_uuid);
-}
-
/**
* Given a disk image containing an extX filesystem, return the UUID.
- * The L<file(1)> command does the hard work.
*/
static char *
get_root_uuid_with_file (guestfs_h *g, const char *appliance)
{
- CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
- char *ret = NULL;
- int r;
+ unsigned char magic[2], uuid[16];
+ char *ret;
+ int fd;
- guestfs_int_cmd_add_arg (cmd, "file");
- guestfs_int_cmd_add_arg (cmd, "--");
- guestfs_int_cmd_add_arg (cmd, appliance);
- guestfs_int_cmd_set_stdout_callback (cmd, read_uuid, &ret, 0);
- r = guestfs_int_cmd_run (cmd);
- if (r == -1) {
- if (ret) free (ret);
+ fd = open (appliance, O_RDONLY|O_CLOEXEC);
+ if (fd == -1) {
+ perrorf (g, _("open: %s"), appliance);
return NULL;
}
- if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
- guestfs_int_external_command_failed (g, r, "file", NULL);
- if (ret) free (ret);
+ if (lseek (fd, 0x438, SEEK_SET) != 0x438) {
+ magic_error:
+ error (g, _("%s: cannot read extfs magic in superblock"), appliance);
+ close (fd);
return NULL;
}
+ if (read (fd, magic, 2) != 2)
+ goto magic_error;
+ if (magic[0] != 0x53 || magic[1] != 0xEF) {
+ error (g, _("%s: appliance is not an extfs filesystem"), appliance);
+ close (fd);
+ return NULL;
+ }
+ if (lseek (fd, 0x468, SEEK_SET) != 0x468) {
+ super_error:
+ error (g, _("%s: cannot read UUID in superblock"), appliance);
+ close (fd);
+ return NULL;
+ }
+ if (read (fd, uuid, 16) != 16)
+ goto super_error;
+ close (fd);
+ /* The UUID is a binary blob, but we must return it as a printable
+ * string. The caller frees this.
+ */
+ ret = safe_asprintf (g,
+ "%02x%02x%02x%02x" "-"
+ "%02x%02x" "-"
+ "%02x%02x" "-"
+ "%02x%02x" "-"
+ "%02x%02x%02x%02x%02x%02x",
+ uuid[0], uuid[1], uuid[2], uuid[3],
+ uuid[4], uuid[5],
+ uuid[6], uuid[7],
+ uuid[8], uuid[9],
+ uuid[10], uuid[11], uuid[12], uuid[13],
+ uuid[14], uuid[15]);
return ret;
}
/**
- * Read the first 256k bytes of the in_file with L<qemu-img(1)> command
- * and write them into the out_file. That may be useful to get UUID of
- * the QCOW2 disk image with further L<file(1)> command.
+ * Read the first 256k bytes of the in_file with L<qemu-img(1)>
+ * command and write them into the out_file. That may be useful to get
+ * UUID of the QCOW2 disk image with C<get_root_uuid_with_file>.
+ *
* The function returns zero if successful, otherwise -1.
*/
static int
--
2.29.0.rc2

View File

@ -61,7 +61,7 @@ Summary: Access and modify virtual machine disk images
Name: libguestfs
Epoch: 1
Version: 1.45.3
Release: 5%{?dist}
Release: 6%{?dist}
License: LGPLv2+
# Build only for architectures that have a kernel
@ -96,6 +96,8 @@ Patch0001: 0001-daemon-xfs.c-Fix-error-message.patch
Patch0002: 0002-tests-Prefer-xorriso-over-genisoimage-to-generate-te.patch
Patch0003: 0003-daemon-Allow-xorriso-as-an-alternative-to-isoinfo.patch
Patch0004: 0004-daemon-Read-ISO9660-Primary-Volume-Descriptor-direct.patch
# Workaround for file 5.40 which is broken in Fedora Rawhide.
Patch0005: 0005-lib-appliance-kcmdline.c-Read-UUID-directly-from-app.patch
# Downstream (RHEL-only) patches.
%if 0%{?rhel}
@ -1124,8 +1126,9 @@ rm ocaml/html/.gitignore
%changelog
* Wed Mar 31 2021 Richard W.M. Jones <rjones@redhat.com> - 1:1.45.3-5
* Wed Mar 31 2021 Richard W.M. Jones <rjones@redhat.com> - 1:1.45.3-6
- Don't require genisoimage or xorriso for the appliance.
- Add workaround for broken "file" utility in Rawhide (RHBZ#1945122).
* Tue Mar 30 2021 Richard W.M. Jones <rjones@redhat.com> - 1:1.45.3-4
- Add downstream (RHEL-only) patches (RHBZ#1931724).