From a6a11a65c9f195f68767ca3529508cc69bf5b491 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 31 Mar 2021 13:46:53 +0100 Subject: [PATCH] Add workaround for broken "file" utility in Rawhide (RHBZ#1945122). --- 0001-daemon-xfs.c-Fix-error-message.patch | 2 +- ...riso-over-genisoimage-to-generate-te.patch | 2 +- ...xorriso-as-an-alternative-to-isoinfo.patch | 2 +- ...660-Primary-Volume-Descriptor-direct.patch | 2 +- ...mdline.c-Read-UUID-directly-from-app.patch | 127 ++++++++++++++++++ libguestfs.spec | 7 +- 6 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 0005-lib-appliance-kcmdline.c-Read-UUID-directly-from-app.patch diff --git a/0001-daemon-xfs.c-Fix-error-message.patch b/0001-daemon-xfs.c-Fix-error-message.patch index af89cfa..e45d459 100644 --- a/0001-daemon-xfs.c-Fix-error-message.patch +++ b/0001-daemon-xfs.c-Fix-error-message.patch @@ -1,7 +1,7 @@ From 49b8b69cb8e10e5476bbe86a708ee1babfe330e8 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" 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 --- diff --git a/0002-tests-Prefer-xorriso-over-genisoimage-to-generate-te.patch b/0002-tests-Prefer-xorriso-over-genisoimage-to-generate-te.patch index 1a31fb2..4957a95 100644 --- a/0002-tests-Prefer-xorriso-over-genisoimage-to-generate-te.patch +++ b/0002-tests-Prefer-xorriso-over-genisoimage-to-generate-te.patch @@ -1,7 +1,7 @@ From 2216ab2e328457ef172d6bfa534272edf2f81a3a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" 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: diff --git a/0003-daemon-Allow-xorriso-as-an-alternative-to-isoinfo.patch b/0003-daemon-Allow-xorriso-as-an-alternative-to-isoinfo.patch index bf4adc4..d8a07a8 100644 --- a/0003-daemon-Allow-xorriso-as-an-alternative-to-isoinfo.patch +++ b/0003-daemon-Allow-xorriso-as-an-alternative-to-isoinfo.patch @@ -1,7 +1,7 @@ From efb8a766cac4ba8e413594946136bf91e176bb8c Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" 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. diff --git a/0004-daemon-Read-ISO9660-Primary-Volume-Descriptor-direct.patch b/0004-daemon-Read-ISO9660-Primary-Volume-Descriptor-direct.patch index c10fe0c..b965807 100644 --- a/0004-daemon-Read-ISO9660-Primary-Volume-Descriptor-direct.patch +++ b/0004-daemon-Read-ISO9660-Primary-Volume-Descriptor-direct.patch @@ -1,7 +1,7 @@ From 2f587bbaec718e414e46c7e6f2a3e2662c3a1c2a Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" 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 diff --git a/0005-lib-appliance-kcmdline.c-Read-UUID-directly-from-app.patch b/0005-lib-appliance-kcmdline.c-Read-UUID-directly-from-app.patch new file mode 100644 index 0000000..c1b70c0 --- /dev/null +++ b/0005-lib-appliance-kcmdline.c-Read-UUID-directly-from-app.patch @@ -0,0 +1,127 @@ +From 278d0d3226f4bdb7c6586986ca46d0a25c976fe4 Mon Sep 17 00:00:00 2001 +From: "Richard W.M. Jones" +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 + #include + #include ++#include ++#include ++#include + + #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 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 command +- * and write them into the out_file. That may be useful to get UUID of +- * the QCOW2 disk image with further L command. ++ * Read the first 256k bytes of the in_file with L ++ * command and write them into the out_file. That may be useful to get ++ * UUID of the QCOW2 disk image with C. ++ * + * The function returns zero if successful, otherwise -1. + */ + static int +-- +2.29.0.rc2 + diff --git a/libguestfs.spec b/libguestfs.spec index ab3d6a8..4899029 100644 --- a/libguestfs.spec +++ b/libguestfs.spec @@ -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 - 1:1.45.3-5 +* Wed Mar 31 2021 Richard W.M. Jones - 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 - 1:1.45.3-4 - Add downstream (RHEL-only) patches (RHBZ#1931724).