Skip to content

Commit 93c65c7

Browse files
authored
Fix dependency constraints, UUID parsing in libguestfs (#2113)
* Bring over libguestfs changes from 2.0 * Fix selinux-policy, file bugs in libguestfs
1 parent 875df84 commit 93c65c7

File tree

5 files changed

+316
-31
lines changed

5 files changed

+316
-31
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
From 278d0d3226f4bdb7c6586986ca46d0a25c976fe4 Mon Sep 17 00:00:00 2001
2+
From: "Richard W.M. Jones" <[email protected]>
3+
Date: Wed, 31 Mar 2021 13:40:11 +0100
4+
Subject: [PATCH] lib/appliance-kcmdline.c: Read UUID directly from appliance.
5+
6+
Instead of using the external file utility, read the UUID directly
7+
from the extfs filesystem. file 5.40 broke parsing of UUIDs
8+
(https://bugs.astron.com/view.php?id=253).
9+
10+
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1945122
11+
---
12+
lib/appliance-kcmdline.c | 75 +++++++++++++++++++++++++---------------
13+
1 file changed, 48 insertions(+), 27 deletions(-)
14+
15+
diff --git a/lib/appliance-kcmdline.c b/lib/appliance-kcmdline.c
16+
index 6d0deef867..8b78655eb2 100644
17+
--- a/lib/appliance-kcmdline.c
18+
+++ b/lib/appliance-kcmdline.c
19+
@@ -27,6 +27,9 @@
20+
#include <stdbool.h>
21+
#include <string.h>
22+
#include <unistd.h>
23+
+#include <fcntl.h>
24+
+#include <libintl.h>
25+
+#include <sys/types.h>
26+
27+
#include "c-ctype.h"
28+
#include "ignore-value.h"
29+
@@ -56,49 +59,67 @@
30+
#define EARLYPRINTK "earlyprintk=pl011,0x9000000"
31+
#endif
32+
33+
-COMPILE_REGEXP (re_uuid, "UUID=([-0-9a-f]+)", 0)
34+
-
35+
-static void
36+
-read_uuid (guestfs_h *g, void *retv, const char *line, size_t len)
37+
-{
38+
- char **ret = retv;
39+
-
40+
- *ret = match1 (g, line, re_uuid);
41+
-}
42+
-
43+
/**
44+
* Given a disk image containing an extX filesystem, return the UUID.
45+
- * The L<file(1)> command does the hard work.
46+
*/
47+
static char *
48+
get_root_uuid_with_file (guestfs_h *g, const char *appliance)
49+
{
50+
- CLEANUP_CMD_CLOSE struct command *cmd = guestfs_int_new_command (g);
51+
- char *ret = NULL;
52+
- int r;
53+
+ unsigned char magic[2], uuid[16];
54+
+ char *ret;
55+
+ int fd;
56+
57+
- guestfs_int_cmd_add_arg (cmd, "file");
58+
- guestfs_int_cmd_add_arg (cmd, "--");
59+
- guestfs_int_cmd_add_arg (cmd, appliance);
60+
- guestfs_int_cmd_set_stdout_callback (cmd, read_uuid, &ret, 0);
61+
- r = guestfs_int_cmd_run (cmd);
62+
- if (r == -1) {
63+
- if (ret) free (ret);
64+
+ fd = open (appliance, O_RDONLY|O_CLOEXEC);
65+
+ if (fd == -1) {
66+
+ perrorf (g, _("open: %s"), appliance);
67+
return NULL;
68+
}
69+
- if (!WIFEXITED (r) || WEXITSTATUS (r) != 0) {
70+
- guestfs_int_external_command_failed (g, r, "file", NULL);
71+
- if (ret) free (ret);
72+
+ if (lseek (fd, 0x438, SEEK_SET) != 0x438) {
73+
+ magic_error:
74+
+ error (g, _("%s: cannot read extfs magic in superblock"), appliance);
75+
+ close (fd);
76+
+ return NULL;
77+
+ }
78+
+ if (read (fd, magic, 2) != 2)
79+
+ goto magic_error;
80+
+ if (magic[0] != 0x53 || magic[1] != 0xEF) {
81+
+ error (g, _("%s: appliance is not an extfs filesystem"), appliance);
82+
+ close (fd);
83+
return NULL;
84+
}
85+
+ if (lseek (fd, 0x468, SEEK_SET) != 0x468) {
86+
+ super_error:
87+
+ error (g, _("%s: cannot read UUID in superblock"), appliance);
88+
+ close (fd);
89+
+ return NULL;
90+
+ }
91+
+ if (read (fd, uuid, 16) != 16)
92+
+ goto super_error;
93+
+ close (fd);
94+
95+
+ /* The UUID is a binary blob, but we must return it as a printable
96+
+ * string. The caller frees this.
97+
+ */
98+
+ ret = safe_asprintf (g,
99+
+ "%02x%02x%02x%02x" "-"
100+
+ "%02x%02x" "-"
101+
+ "%02x%02x" "-"
102+
+ "%02x%02x" "-"
103+
+ "%02x%02x%02x%02x%02x%02x",
104+
+ uuid[0], uuid[1], uuid[2], uuid[3],
105+
+ uuid[4], uuid[5],
106+
+ uuid[6], uuid[7],
107+
+ uuid[8], uuid[9],
108+
+ uuid[10], uuid[11], uuid[12], uuid[13],
109+
+ uuid[14], uuid[15]);
110+
return ret;
111+
}
112+
113+
/**
114+
- * Read the first 256k bytes of the in_file with L<qemu-img(1)> command
115+
- * and write them into the out_file. That may be useful to get UUID of
116+
- * the QCOW2 disk image with further L<file(1)> command.
117+
+ * Read the first 256k bytes of the in_file with L<qemu-img(1)>
118+
+ * command and write them into the out_file. That may be useful to get
119+
+ * UUID of the QCOW2 disk image with C<get_root_uuid_with_file>.
120+
+ *
121+
* The function returns zero if successful, otherwise -1.
122+
*/
123+
static int

SPECS-EXTENDED/libguestfs/libguestfs-ocaml413compat.patch

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,62 @@ index 4237ea5..8847717 100644
3030
| [] -> default
3131
| (y, y') :: _ when cmp x y = 0 -> y'
3232
| _ :: ys -> assoc_lbl ~cmp ~default x ys
33+
34+
From 5f499208cf53ebd3f05525918c213a36c3ca13b5 Mon Sep 17 00:00:00 2001
35+
From: "Richard W.M. Jones" <[email protected]>
36+
Date: Tue, 2 Mar 2021 10:42:49 +0000
37+
Subject: [PATCH] builder: Don't redefine Val_none (OCaml 4.12).
38+
39+
CC virt_builder-setlocale-c.o
40+
setlocale-c.c:38: error: "Val_none" redefined [-Werror]
41+
38 | #define Val_none (Val_int (0))
42+
|
43+
In file included from /usr/lib64/ocaml/caml/alloc.h:24,
44+
from setlocale-c.c:23:
45+
/usr/lib64/ocaml/caml/mlvalues.h:395: note: this is the location of the previous definition
46+
395 | #define Val_none Val_int(0)
47+
|
48+
---
49+
builder/setlocale-c.c | 2 ++
50+
1 file changed, 2 insertions(+)
51+
52+
diff --git a/builder/setlocale-c.c b/builder/setlocale-c.c
53+
index 6d877e7ac..1834c11df 100644
54+
--- a/builder/setlocale-c.c
55+
+++ b/builder/setlocale-c.c
56+
@@ -35,7 +35,9 @@ static const int lc_string_table[7] = {
57+
LC_MESSAGES
58+
};
59+
60+
+#ifndef Val_none
61+
#define Val_none (Val_int (0))
62+
+#endif
63+
64+
extern value virt_builder_setlocale (value val_category, value val_name);
65+
66+
--
67+
2.29.0.rc2
68+
69+
From 80abb37b53fc1297de7644ed5a3506c4c1f9375e Mon Sep 17 00:00:00 2001
70+
From: Stephane Glondu <[email protected]>
71+
Date: Sun, 26 Dec 2021 10:03:35 +0100
72+
Subject: [PATCH] Do not error on warning 6 [labels-omitted]
73+
74+
---
75+
m4/guestfs-ocaml.m4 | 2 +-
76+
2 files changed, 8 insertions(+), 1 deletion(-)
77+
diff --git a/m4/guestfs-ocaml.m4 b/m4/guestfs-ocaml.m4
78+
index bf07799..c40a173 100644
79+
--- a/m4/guestfs-ocaml.m4
80+
+++ b/m4/guestfs-ocaml.m4
81+
@@ -231,7 +231,7 @@ EOF
82+
])
83+
84+
dnl Flags we want to pass to every OCaml compiler call.
85+
-OCAML_WARN_ERROR="-warn-error CDEFLMPSUVYZX+52-3"
86+
+OCAML_WARN_ERROR="-warn-error +C+D+E+F+L+M+P+S+U+V+Y+Z+X+52-3-6"
87+
AC_SUBST([OCAML_WARN_ERROR])
88+
OCAML_FLAGS="-g -annot $safe_string_option"
89+
AC_SUBST([OCAML_FLAGS])
90+
--
91+
2.34.1

SPECS-EXTENDED/libguestfs/libguestfs.signatures.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"copy-patches.sh": "9e0112d9b85f80f48697ffefbb6cc3a1eda527ea5ff065f48e08440dfba573e8",
55
"guestfish.sh": "5efae0e6b38c7a137265bc1f3988dc9734a99a08a87ffbcfa1715aefe3982d29",
66
"libguestfs-1.44.0.tar.gz": "0ec7b44a4c50e928583c56099da31ceb9680766043bd7d468f3ca7b741c55d21",
7+
"tdnf-build-cache.repo": "646e3ff6dddf3b088edf141796b6b081fe6f82dba6f1f7f32b426581a065c7c6",
78
"yum.conf.in": "2ca1e0ea6814436211715f14975e211263db10f09fca1fdef51c5aa3fe52a357"
89
}
9-
}
10+
}

0 commit comments

Comments
 (0)