import guestfs-tools-1.51.6-3.el9_4

i9c changed/i9c/guestfs-tools-1.51.6-3.el9_4
MSVSphere Packaging Team 4 months ago
parent ba562c681b
commit d35bdae3d8

2
.gitignore vendored

@ -1,2 +1,2 @@
SOURCES/guestfs-tools-1.50.1.tar.gz SOURCES/guestfs-tools-1.51.6.tar.gz
SOURCES/libguestfs.keyring SOURCES/libguestfs.keyring

@ -1,2 +1,2 @@
e1fbf090056a2c559f85df7fffe10d2e28a88c37 SOURCES/guestfs-tools-1.50.1.tar.gz 7a64ba52bca3a3591d2e639a6bc9002d61e7d374 SOURCES/guestfs-tools-1.51.6.tar.gz
1bbc40f501a7fef9eef2a39b701a71aee2fea7c4 SOURCES/libguestfs.keyring 1bbc40f501a7fef9eef2a39b701a71aee2fea7c4 SOURCES/libguestfs.keyring

@ -0,0 +1,26 @@
From 28ecb8693bbded3e1c70c1baa57f3498a6b8127e Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 9 Dec 2023 12:59:13 +0000
Subject: [PATCH] Update common submodule
Pick up this bug fix:
mltools/libosinfo-c.c: Fix off-by-one error
---
common | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Submodule common cd29aee91..0dba002c2:
diff --git a/common/mltools/libosinfo-c.c b/common/mltools/libosinfo-c.c
index 93357fd91..a48c8989f 100644
--- a/common/mltools/libosinfo-c.c
+++ b/common/mltools/libosinfo-c.c
@@ -296,7 +296,7 @@ v2v_osinfo_os_get_device_drivers (value osv)
driver = OSINFO_DEVICE_DRIVER(osinfo_list_get_nth (OSINFO_LIST(list), i));
- vi = caml_alloc (6, 0);
+ vi = caml_alloc (7, 0);
str = osinfo_device_driver_get_architecture (driver);
copyv = caml_copy_string (str);
Store_field (vi, 0, copyv);

@ -0,0 +1,63 @@
From 5f9beb89443f84640efc52ee6cd68f7f880fb66b Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 19 Jan 2024 13:22:51 +0000
Subject: [PATCH] builder: Add a test of the --chown parameter
Also update the libguestfs common submodule, pulling in this change
from libguestfs:
generator/customize.ml: Split --chown parameter on ':' character
and this patch to common/mltools:
mltools/libosinfo-c.c: Fix off-by-one error
(cherry picked from commit 299dc5ec2a0bdd9adecef75adc6a5eca0dc685b1)
---
builder/test-virt-builder.sh | 4 ++++
common | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/builder/test-virt-builder.sh b/builder/test-virt-builder.sh
index 705788a3c..f839fd7af 100755
--- a/builder/test-virt-builder.sh
+++ b/builder/test-virt-builder.sh
@@ -69,6 +69,7 @@ virt-builder phony-fedora \
--write '/etc/append6:
' \
--append-line '/etc/append6:line2' \
+ --chown 1:1:/etc/append6 \
--firstboot Makefile --firstboot-command 'echo "hello"' \
--firstboot-install "minicom,inkscape"
@@ -112,6 +113,7 @@ echo append5:
cat /etc/append5
echo append6:
cat /etc/append6
+stat /etc/append6 | grep '^[ug]id:'
echo -----
EOF
@@ -154,6 +156,8 @@ append6:
line2
+uid: 1
+gid: 1
-----" ]; then
echo "$0: unexpected output:"
cat test-virt-builder.out
Submodule common 0dba002c2..54869c987:
diff --git a/common/mlcustomize/customize_cmdline.ml b/common/mlcustomize/customize_cmdline.ml
index 245d9960a..48ee33445 100644
--- a/common/mlcustomize/customize_cmdline.ml
+++ b/common/mlcustomize/customize_cmdline.ml
@@ -157,7 +157,7 @@ let rec argspec () =
let len = String.length arg in
String.sub arg 0 i, String.sub arg (i+1) (len-(i+1))
and split_string_triplet option_name arg =
- match String.nsplit ~max:3 "," arg with
+ match String.nsplit ~max:3 ":" arg with
| [a; b; c] -> a, b, c
| _ ->
error (f_"invalid format for '--%s' parameter, see the man page")

@ -1,4 +1,4 @@
From b4f4e1906b8de6286889690047e35969d2dfaa91 Mon Sep 17 00:00:00 2001 From b5fdf9eac368a1c5df4ddd93ce40884924e6092a Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 7 Jul 2015 09:28:03 -0400 Date: Tue, 7 Jul 2015 09:28:03 -0400
Subject: [PATCH] RHEL: Reject use of libguestfs-winsupport features except for Subject: [PATCH] RHEL: Reject use of libguestfs-winsupport features except for

File diff suppressed because it is too large Load Diff

@ -1,4 +1,4 @@
From 01ebf5d7d5656b45168de9081906522a32008080 Mon Sep 17 00:00:00 2001 From 511de43cdca80381d52360e050bf57f7079f46d6 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 21 Nov 2022 13:03:22 +0000 Date: Mon, 21 Nov 2022 13:03:22 +0000
Subject: [PATCH] RHEL: builder: Disable opensuse repository Subject: [PATCH] RHEL: builder: Disable opensuse repository

@ -1,480 +0,0 @@
From ec06f62df5340cd0a9466a532aa9806fb0e2e560 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 18 Feb 2023 12:04:04 +0000
Subject: [PATCH] drivers: Look up vendor and device names in PCI and USB IDs
database
(cherry picked from commit ca21ee4918cd7d4472bd875a495752a03a03fa87)
---
.gitignore | 1 +
configure.ac | 1 +
drivers/Makefile.am | 6 +-
drivers/drivers.ml | 31 +++++
drivers/hwdata.ml | 187 +++++++++++++++++++++++++++
drivers/hwdata.mli | 31 +++++
drivers/hwdata_config.ml.in | 26 ++++
drivers/hwdata_config.mli | 35 +++++
drivers/test-virt-drivers-windows.sh | 13 +-
m4/guestfs-libraries.m4 | 3 +
po/POTFILES-ml | 2 +
11 files changed, 333 insertions(+), 3 deletions(-)
create mode 100644 drivers/hwdata.ml
create mode 100644 drivers/hwdata.mli
create mode 100644 drivers/hwdata_config.ml.in
create mode 100644 drivers/hwdata_config.mli
diff --git a/.gitignore b/.gitignore
index b0ada2e3c..c0ca330a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -95,6 +95,7 @@ Makefile.in
/customize/virt-customize
/df/virt-df
/drivers/.depend
+/drivers/hwdata_config.ml
/drivers/virt-drivers
/diff/virt-diff
/edit/virt-edit
diff --git a/configure.ac b/configure.ac
index 34c66b80e..e9fadcc9b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -138,6 +138,7 @@ AC_CONFIG_FILES([Makefile
df/Makefile
diff/Makefile
drivers/Makefile
+ drivers/hwdata_config.ml
edit/Makefile
format/Makefile
get-kernel/Makefile
diff --git a/drivers/Makefile.am b/drivers/Makefile.am
index d27fc2e27..7e0ef659c 100644
--- a/drivers/Makefile.am
+++ b/drivers/Makefile.am
@@ -27,9 +27,13 @@ EXTRA_DIST = \
virt-drivers.pod
SOURCES_MLI = \
- drivers.mli
+ drivers.mli \
+ hwdata_config.mli \
+ hwdata.mli
SOURCES_ML = \
+ hwdata_config.ml \
+ hwdata.ml \
drivers.ml
SOURCES_C = \
diff --git a/drivers/drivers.ml b/drivers/drivers.ml
index 57cfb557c..f02165fa4 100644
--- a/drivers/drivers.ml
+++ b/drivers/drivers.ml
@@ -235,8 +235,14 @@ and windows_hardware_to_xml = function
(Option.map (fun v -> ("class", sprintf "%06LX" v)) pci_class);
List.may_push_back attrs
(Option.map (fun v -> ("vendor", sprintf "%04LX" v)) pci_vendor);
+ let vendorname = get_pci_vendor pci_vendor in
+ List.may_push_back attrs
+ (Option.map (fun v -> "vendorname", v) vendorname);
List.may_push_back attrs
(Option.map (fun v -> ("device", sprintf "%04LX" v)) pci_device);
+ let devicename = get_pci_device pci_vendor pci_device in
+ List.may_push_back attrs
+ (Option.map (fun v -> "devicename", v) devicename);
List.may_push_back attrs
(Option.map (fun v -> ("subsystem", sprintf "%08LX" v)) pci_subsys);
List.may_push_back attrs
@@ -261,8 +267,14 @@ and windows_hardware_to_xml = function
let attrs = ref [] in
List.may_push_back attrs
(Option.map (fun v -> ("vendor", sprintf "%04LX" v)) usb_vendor);
+ let vendorname = get_usb_vendor usb_vendor in
+ List.may_push_back attrs
+ (Option.map (fun v -> "vendorname", v) vendorname);
List.may_push_back attrs
(Option.map (fun v -> ("product", sprintf "%04LX" v)) usb_product);
+ let productname = get_usb_device usb_vendor usb_product in
+ List.may_push_back attrs
+ (Option.map (fun v -> "productname", v) productname);
List.may_push_back attrs
(Option.map (fun v -> ("revision", sprintf "%02LX" v)) usb_rev);
List.may_push_back attrs
@@ -272,6 +284,25 @@ and windows_hardware_to_xml = function
| Other path ->
Comment (sprintf "unknown DeviceId: %s" (String.concat "\\" path))
+and get_pci_vendor v = get_hwdata'1 Hwdata.pci_vendor v
+and get_pci_device v d = get_hwdata'2 Hwdata.pci_device v d
+and get_usb_vendor v = get_hwdata'1 Hwdata.usb_vendor v
+and get_usb_device v d = get_hwdata'2 Hwdata.usb_device v d
+
+and get_hwdata'1 f = function
+ | Some i64 when i64 >= 0_L && i64 <= 0xffff_L ->
+ let i32 = Int64.to_int32 i64 in
+ f i32
+ | _ -> None
+
+and get_hwdata'2 f v d =
+ match v, d with
+ | Some v64, Some d64 when v64 >= 0_L && v64 <= 0xffff_L &&
+ d64 >= 0_L && d64 <= 0xffff_L ->
+ let v32 = Int64.to_int32 v64 and d32 = Int64.to_int32 d64 in
+ f v32 d32
+ | _ -> None
+
(* Main program. *)
let main () =
let add, ks = parse_cmdline () in
diff --git a/drivers/hwdata.ml b/drivers/hwdata.ml
new file mode 100644
index 000000000..4b46eff68
--- /dev/null
+++ b/drivers/hwdata.ml
@@ -0,0 +1,187 @@
+(* virt-drivers
+ * Copyright (C) 2009-2023 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Std_utils
+open Tools_utils
+open Common_gettext.Gettext
+
+open Printf
+open Scanf
+
+module DBKey = struct
+ type t =
+ | Vendor of int32
+ | Device of int32 * int32
+ let compare = compare
+end
+module DB = Map.Make (DBKey)
+
+let is_4_digit_hex id =
+ String.length id = 4 &&
+ Char.isxdigit id.[0] &&
+ Char.isxdigit id.[1] &&
+ Char.isxdigit id.[2] &&
+ Char.isxdigit id.[3]
+let hex_to_int32 id = sscanf id "%lx" identity
+
+(* Loads one of the [*.ids] files, returning the entries as a
+ * 3 level map. Returns [None] if the file could not be opened
+ * or parsed.
+ *)
+let load filename =
+ try
+ let lines = read_whole_file filename in
+ let lines = String.lines_split lines in
+
+ (* This loop drops blank lines and comments, splits the fields of
+ * the database, and returns [(lineno, indent, key, label) list].
+ *)
+ let rec loop lineno acc = function
+ | [] -> List.rev acc
+ (* Blank lines. *)
+ | "" :: lines ->
+ loop (lineno+1) acc lines
+ (* Note that # only starts a comment at the beginning of the line. *)
+ | comment :: lines when String.is_prefix comment "#" ->
+ loop (lineno+1) acc lines
+ (* Otherwise its some data. *)
+ | line :: lines ->
+ let len = String.length line in
+ let indent =
+ let rec counttabs i =
+ if i < len && line.[i] = '\t' then 1 + counttabs (i+1) else 0
+ in
+ counttabs 0 in
+ let line = String.sub line indent (len - indent) in
+
+ let n = String.cspan line " \t" in
+ let key, label = String.break n line in
+ let n = String.span label " \t" in
+ let _, label = String.break n label in
+
+ let acc =
+ if key = "" && label = "" then acc
+ else (lineno, indent, key, label) :: acc in
+
+ loop (lineno+1) acc lines
+ in
+ let lines = loop 1 [] lines in
+
+ (* Since the format is essentially a space-saving one where
+ * vendor name
+ * \t device name
+ * is short for:
+ * vendor name
+ * vendor device name
+ * pull the fields from previous lines down, resulting in
+ * a flat list.
+ *)
+ let rec loop keys acc = function
+ | [] -> List.rev acc
+ | (lineno, indent, key, label) :: lines ->
+ let prefix = List.take indent keys in
+ let keys = prefix @ [ key ] in
+ let acc = (lineno, keys, label) :: acc in
+ loop keys acc lines
+ in
+ let lines = loop [] [] lines in
+
+ (*
+ List.iter (
+ fun (lineno, keys, label) ->
+ eprintf "[%s] -> %s # line %d\n"
+ (String.concat ";" keys) label lineno
+ ) lines;
+ *)
+
+ (* Now we can finally process the database.
+ *
+ * We currently ignore the [C] (class) and other records
+ * that appear at the end of the file. We might want to
+ * try parsing these in future. It will require changes to
+ * the code above because the label isn't parsed right.
+ *)
+ let db =
+ List.fold_left (
+ fun db (lineno, keys, label) ->
+ let loc = filename, lineno in
+ match keys with
+ | [vendor] when is_4_digit_hex vendor ->
+ let vendor = hex_to_int32 vendor in
+ DB.add (Vendor vendor) (label, loc) db
+ | [vendor; device] when is_4_digit_hex vendor &&
+ is_4_digit_hex device ->
+ let vendor = hex_to_int32 vendor in
+ let device = hex_to_int32 device in
+ DB.add (Device (vendor, device)) (label, loc) db
+ | _ ->
+ db
+ ) DB.empty lines in
+
+ Some db
+ with exn ->
+ warning (f_"hwdata: %s: %s") filename (Printexc.to_string exn);
+ None
+
+(* Lazily load the PCI database, if present. *)
+let pci_db =
+ let filename = Hwdata_config.pci_ids in
+ lazy (match filename with None -> None | Some filename -> load filename)
+
+(* Look up PCI vendor and device ID. *)
+let pci_vendor vendor =
+ let db = Lazy.force pci_db in
+ match db with
+ | None -> None
+ | Some db ->
+ match DB.find_opt (Vendor vendor) db with
+ | None -> None
+ | Some (label, _) -> Some label
+
+let pci_device vendor device =
+ let db = Lazy.force pci_db in
+ match db with
+ | None -> None
+ | Some db ->
+ match DB.find_opt (Device (vendor, device)) db with
+ | None -> None
+ | Some (label, _) -> Some label
+
+(* Lazily load the USB database, if present. *)
+let usb_db =
+ let filename = Hwdata_config.usb_ids in
+ lazy (match filename with None -> None | Some filename -> load filename)
+
+(* Look up USB vendor and device ID. *)
+let usb_vendor vendor =
+ let db = Lazy.force usb_db in
+ match db with
+ | None -> None
+ | Some db ->
+ match DB.find_opt (Vendor vendor) db with
+ | None -> None
+ | Some (label, _) -> Some label
+
+let usb_device vendor device =
+ let db = Lazy.force usb_db in
+ match db with
+ | None -> None
+ | Some db ->
+ match DB.find_opt (Device (vendor, device)) db with
+ | None -> None
+ | Some (label, _) -> Some label
diff --git a/drivers/hwdata.mli b/drivers/hwdata.mli
new file mode 100644
index 000000000..972dfe1f6
--- /dev/null
+++ b/drivers/hwdata.mli
@@ -0,0 +1,31 @@
+(* virt-drivers
+ * Copyright (C) 2013-2023 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(** Look up PCI and USB vendor and device IDs. *)
+
+val pci_vendor : int32 -> string option
+(** Look up the PCI vendor ID. If found, return the name. *)
+
+val pci_device : int32 -> int32 -> string option
+(** Look up the PCI vendor & device ID. If found, return the name. *)
+
+val usb_vendor : int32 -> string option
+(** Look up the USB vendor ID. If found, return the name. *)
+
+val usb_device : int32 -> int32 -> string option
+(** Look up the USB vendor & device ID. If found, return the name. *)
diff --git a/drivers/hwdata_config.ml.in b/drivers/hwdata_config.ml.in
new file mode 100644
index 000000000..fa792c086
--- /dev/null
+++ b/drivers/hwdata_config.ml.in
@@ -0,0 +1,26 @@
+(* virt-drivers
+ * @configure_input@
+ * Copyright (C) 2009-2023 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Std_utils
+
+let dir = "@HWDATA_PKGDATADIR@"
+let dir = if dir = "" then None else Some dir
+
+let pci_ids = Option.map (fun d -> d // "pci.ids") dir
+let usb_ids = Option.map (fun d -> d // "usb.ids") dir
diff --git a/drivers/hwdata_config.mli b/drivers/hwdata_config.mli
new file mode 100644
index 000000000..877e9e28a
--- /dev/null
+++ b/drivers/hwdata_config.mli
@@ -0,0 +1,35 @@
+(* virt-drivers
+ * Copyright (C) 2013-2023 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+val dir : string option
+(** [pkgdatadir] variable defined by hwdata.pc
+
+ This is the name of the directory containing [pci.ids] and
+ related files which contain the PCI IDs. *)
+
+val pci_ids : string option
+(** Path to the [pci.ids] file.
+
+ Note at runtime this is an optional dependency, so it may
+ not at exist even if not [None]. *)
+
+val usb_ids : string option
+(** Path to the [usb.ids] file.
+
+ Note at runtime this is an optional dependency, so it may
+ not at exist even if not [None]. *)
diff --git a/drivers/test-virt-drivers-windows.sh b/drivers/test-virt-drivers-windows.sh
index df3f36c64..4131f6e5e 100755
--- a/drivers/test-virt-drivers-windows.sh
+++ b/drivers/test-virt-drivers-windows.sh
@@ -22,9 +22,18 @@ $TEST_FUNCTIONS
skip_if_skipped
skip_unless_phony_guest windows.img
-rm -f actual-windows.xml
+rm -f actual-windows.xml actual-windows.xml.bak
$VG virt-drivers --format=raw -a ../test-data/phony-guests/windows.img > actual-windows.xml
+
+# We can't predict if hwdata is available, so we don't know if
+# vendorname and devicename fields will be present. If present,
+# remove them before comparison.
+mv actual-windows.xml actual-windows.xml.bak
+sed -e "s/ vendorname='\([^']*\)'//g" \
+ -e "s/ devicename='\([^']*\)'//g" \
+ < actual-windows.xml.bak > actual-windows.xml
+
diff -ur -I "generated by" expected-windows.xml actual-windows.xml
-rm actual-windows.xml
+rm actual-windows.xml actual-windows.xml.bak
diff --git a/m4/guestfs-libraries.m4 b/m4/guestfs-libraries.m4
index 2d252bf9e..32f93afda 100644
--- a/m4/guestfs-libraries.m4
+++ b/m4/guestfs-libraries.m4
@@ -169,3 +169,6 @@ PKG_CHECK_MODULES([JANSSON], [jansson >= 2.7])
dnl Check for libosinfo (mandatory)
PKG_CHECK_MODULES([LIBOSINFO], [libosinfo-1.0])
+
+dnl Check for hwdata directory (containing pci.ids) (optional, for virt-drivers)
+PKG_CHECK_VAR([HWDATA_PKGDATADIR], [hwdata], [pkgdatadir])
diff --git a/po/POTFILES-ml b/po/POTFILES-ml
index 73984796f..7632f374d 100644
--- a/po/POTFILES-ml
+++ b/po/POTFILES-ml
@@ -79,6 +79,8 @@ dib/output_format_tgz.ml
dib/output_format_vhd.ml
dib/utils.ml
drivers/drivers.ml
+drivers/hwdata.ml
+drivers/hwdata_config.ml
get-kernel/get_kernel.ml
resize/resize.ml
sparsify/cmdline.ml

@ -0,0 +1,536 @@
From 31b4b33ec87560182f338a088bd242d571bc79e7 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 27 Aug 2024 13:46:46 +0100
Subject: [PATCH] Update common submodule
Pick up the commits below. In particular this makes several
refinements to the Windows firstboot code to make it more reliable.
Fixes: https://issues.redhat.com/browse/RHEL-55824
Ben Brown (1):
Initialise bar->fp as NULL
Richard W.M. Jones (16):
mlcustomize: Update virt-customize generated files
options: Allow nbd+unix:// URIs
mlcustomize: Add virt-customize --inject-blnsvr generated files
mlcustomize: Add Inject_virtio_win.inject_blnsvr implementation
mlcustomize: firstboot: Use Linux path for Powershell script path
mlcustomize: firstboot: Use powershell.exe instead of path
mlcustomize: firstboot: Use Powershell -NoProfile flag
mlcustomize: Revert delay installation of qemu-ga MSI
mldrivers/linux_kernels.ml: Prefix general information with ^info:
mlcustomize: Use Start-Process -Wait to run qemu-ga installer
mlcustomize: Add Firstboot.firstboot_dir function
mlcustomize: Place powershell scripts into <firstboot_dir>\Temp
mlcustomize: Inject qemu-ga & blnsvr into <firstboot_dir>/Temp
mlcustomize: Write qemu-ga log file name to log.txt
mlcustomize: Add some comments to firstboot batch file
mlcustomize: Reboot Windows between each firstboot script
---
common | 2 +-
customize/customize_run.ml | 3 +++
2 files changed, 4 insertions(+), 1 deletion(-)
Submodule common 54869c987..a78839676:
diff --git a/common/mlcustomize/customize-synopsis.pod b/common/mlcustomize/customize-synopsis.pod
index bb0ce1255..957de8cf2 100644
--- a/common/mlcustomize/customize-synopsis.pod
+++ b/common/mlcustomize/customize-synopsis.pod
@@ -3,16 +3,16 @@
[--copy SOURCE:DEST] [--copy-in LOCALPATH:REMOTEDIR]
[--delete PATH] [--edit FILE:EXPR] [--firstboot SCRIPT]
[--firstboot-command 'CMD+ARGS'] [--firstboot-install PKG,PKG..]
- [--hostname HOSTNAME] [--inject-qemu-ga METHOD]
- [--inject-virtio-win METHOD] [--install PKG,PKG..]
- [--link TARGET:LINK[:LINK..]] [--mkdir DIR] [--move SOURCE:DEST]
- [--password USER:SELECTOR] [--root-password SELECTOR]
- [--run SCRIPT] [--run-command 'CMD+ARGS'] [--scrub FILE]
- [--sm-attach SELECTOR] [--sm-register] [--sm-remove]
- [--sm-unregister] [--ssh-inject USER[:SELECTOR]]
- [--tar-in TARFILE:REMOTEDIR] [--timezone TIMEZONE] [--touch FILE]
- [--truncate FILE] [--truncate-recursive PATH]
- [--uninstall PKG,PKG..] [--update] [--upload FILE:DEST]
- [--write FILE:CONTENT] [--no-logfile]
+ [--hostname HOSTNAME]
+ [--inject-qemu-ga METHOD] [--inject-virtio-win METHOD]
+ [--install PKG,PKG..] [--link TARGET:LINK[:LINK..]] [--mkdir DIR]
+ [--move SOURCE:DEST] [--password USER:SELECTOR]
+ [--root-password SELECTOR] [--run SCRIPT]
+ [--run-command 'CMD+ARGS'] [--scrub FILE] [--sm-attach SELECTOR]
+ [--sm-register] [--sm-remove] [--sm-unregister]
+ [--ssh-inject USER[:SELECTOR]] [--tar-in TARFILE:REMOTEDIR]
+ [--timezone TIMEZONE] [--touch FILE] [--truncate FILE]
+ [--truncate-recursive PATH] [--uninstall PKG,PKG..] [--update]
+ [--upload FILE:DEST] [--write FILE:CONTENT] [--no-logfile]
[--password-crypto md5|sha256|sha512] [--no-selinux-relabel]
[--selinux-relabel] [--sm-credentials SELECTOR]
diff --git a/common/mlcustomize/customize_cmdline.ml b/common/mlcustomize/customize_cmdline.ml
index 48ee33445..c4d6a77d5 100644
--- a/common/mlcustomize/customize_cmdline.ml
+++ b/common/mlcustomize/customize_cmdline.ml
@@ -61,6 +61,8 @@ and op = [
(* --firstboot-install PKG,PKG.. *)
| `Hostname of string
(* --hostname HOSTNAME *)
+ | `InjectBalloonServer of string
+ (* --inject-blnsvr METHOD *)
| `InjectQemuGA of string
(* --inject-qemu-ga METHOD *)
| `InjectVirtioWin of string
diff --git a/common/mlcustomize/customize_cmdline.mli b/common/mlcustomize/customize_cmdline.mli
index 51a156eae..ee62961a1 100644
--- a/common/mlcustomize/customize_cmdline.mli
+++ b/common/mlcustomize/customize_cmdline.mli
@@ -53,6 +53,8 @@ and op = [
(* --firstboot-install PKG,PKG.. *)
| `Hostname of string
(* --hostname HOSTNAME *)
+ | `InjectBalloonServer of string
+ (* --inject-blnsvr METHOD *)
| `InjectQemuGA of string
(* --inject-qemu-ga METHOD *)
| `InjectVirtioWin of string
diff --git a/common/mlcustomize/firstboot.ml b/common/mlcustomize/firstboot.ml
index 5dc012340..52e76401e 100644
--- a/common/mlcustomize/firstboot.ml
+++ b/common/mlcustomize/firstboot.ml
@@ -239,7 +239,22 @@ WantedBy=%s
end
module Windows = struct
- let rec install_service (g : Guestfs.guestfs) root =
+ (* Create and return the firstboot directory. *)
+ let create_firstboot_dir (g : Guestfs.guestfs) =
+ let rec loop firstboot_dir firstboot_dir_win = function
+ | [] -> firstboot_dir, firstboot_dir_win
+ | dir :: path ->
+ let firstboot_dir =
+ if firstboot_dir = "" then "/" ^ dir else firstboot_dir // dir in
+ let firstboot_dir_win = firstboot_dir_win ^ "\\" ^ dir in
+ let firstboot_dir = g#case_sensitive_path firstboot_dir in
+ g#mkdir_p firstboot_dir;
+ loop firstboot_dir firstboot_dir_win path
+ in
+ loop "" "C:" ["Program Files"; "Guestfs"; "Firstboot"]
+
+ let rec install_service (g : Guestfs.guestfs) root
+ firstboot_dir firstboot_dir_win =
(* Either rhsrvany.exe or pvvxsvc.exe must exist.
*
* (Check also that it's not a dangling symlink but a real file).
@@ -254,20 +269,7 @@ module Windows = struct
error (f_"One of rhsrvany.exe or pvvxsvc.exe is missing in %s. One of them is required in order to install Windows firstboot scripts. You can get one by building rhsrvany (https://github.com/rwmjones/rhsrvany)")
(virt_tools_data_dir ()) in
- (* Create a directory for firstboot files in the guest. *)
- let firstboot_dir, firstboot_dir_win =
- let rec loop firstboot_dir firstboot_dir_win = function
- | [] -> firstboot_dir, firstboot_dir_win
- | dir :: path ->
- let firstboot_dir =
- if firstboot_dir = "" then "/" ^ dir else firstboot_dir // dir in
- let firstboot_dir_win = firstboot_dir_win ^ "\\" ^ dir in
- let firstboot_dir = g#case_sensitive_path firstboot_dir in
- g#mkdir_p firstboot_dir;
- loop firstboot_dir firstboot_dir_win path
- in
- loop "" "C:" ["Program Files"; "Guestfs"; "Firstboot"] in
-
+ (* Create a directory for firstboot scripts in the guest. *)
g#mkdir_p (firstboot_dir // "scripts");
(* Copy pvvxsvc or rhsrvany to the guest. *)
@@ -276,6 +278,9 @@ module Windows = struct
(* Write a firstboot.bat control script which just runs the other
* scripts in the directory. Note we need to use CRLF line endings
* in this script.
+ *
+ * XXX It would be better to use powershell here. For some ideas see
+ * https://github.com/HCK-CI/HLK-Setup-Scripts/
*)
let firstboot_script = sprintf "\
@echo off
@@ -297,6 +302,7 @@ if not exist \"%%scripts_done%%\" (
mkdir \"%%scripts_done%%\"
)
+:: Pick the next script to run.
for %%%%f in (\"%%scripts%%\"\\*.bat) do (
echo running \"%%%%f\"
move \"%%%%f\" \"%%scripts_done%%\"
@@ -305,8 +311,17 @@ for %%%%f in (\"%%scripts%%\"\\*.bat) do (
set elvl=!errorlevel!
echo .... exit code !elvl!
popd
+
+ :: Reboot the computer. This is necessary to free any locked
+ :: files which may prevent later scripts from running.
+ shutdown /r /t 0 /y
+
+ :: Exit the script (in case shutdown returns before rebooting).
+ :: On next boot, the whole firstboot service will be called again.
+ exit /b
)
+:: Fallthrough here if there are no scripts.
echo uninstalling firstboot service
\"%%firstboot%%\\%s\" -s firstboot uninstall
" firstboot_dir_win srvany in
@@ -339,11 +354,25 @@ echo uninstalling firstboot service
"PWD", REG_SZ firstboot_dir_win ];
] in
reg_import reg regedits
- );
-
- firstboot_dir
+ )
end
+let firstboot_dir (g : Guestfs.guestfs) root =
+ let typ = g#inspect_get_type root in
+
+ match typ with
+ | "linux" ->
+ let dir = Linux.firstboot_dir in
+ g#mkdir_p dir;
+ dir, None
+
+ | "windows" ->
+ let dir, dir_win = Windows.create_firstboot_dir g in
+ dir, Some dir_win
+
+ | _ ->
+ error (f_"guest type %s is not supported") typ
+
let script_count = ref 0
let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = 5000) name
@@ -363,7 +392,8 @@ let add_firstboot_script (g : Guestfs.guestfs) root ?(prio = 5000) name
g#chmod 0o755 filename
| "windows", _ ->
- let firstboot_dir = Windows.install_service g root in
+ let firstboot_dir, firstboot_dir_win = Windows.create_firstboot_dir g in
+ Windows.install_service g root firstboot_dir firstboot_dir_win;
let filename = firstboot_dir // "scripts" // filename ^ ".bat" in
g#write filename (String.unix2dos content)
@@ -382,21 +412,18 @@ let add_firstboot_powershell g root ?prio name code =
*)
assert (g#inspect_get_type root = "windows");
- let windows_systemroot = g#inspect_get_windows_systemroot root in
-
- (* Create the temporary directory to put the Powershell file. *)
- let tempdir = sprintf "%s/Temp" windows_systemroot in
+ (* Place the Powershell script into firstboot_dir/Temp *)
+ let firstboot_dir, firstboot_dir_win = Windows.create_firstboot_dir g in
+ let tempdir = sprintf "%s/Temp" firstboot_dir in
g#mkdir_p tempdir;
+
+ let ps_path = sprintf "%s/%s.ps1" tempdir name in
+ let ps_path_win = sprintf "%s\\Temp\\%s.ps1" firstboot_dir_win name in
let code = String.concat "\r\n" code ^ "\r\n" in
- g#write (sprintf "%s/%s" tempdir name) code;
+ g#write ps_path code;
- (* Powershell interpreter. Should we check this exists? XXX *)
- let ps_exe =
- windows_systemroot ^
- "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" in
-
- (* Windows path to the Powershell script. *)
- let ps_path = windows_systemroot ^ "\\Temp\\" ^ name in
-
- let fb = sprintf "%s -ExecutionPolicy ByPass -file %s" ps_exe ps_path in
+ (* Create a regular firstboot bat that just invokes powershell *)
+ let fb =
+ sprintf "powershell.exe -ExecutionPolicy ByPass -NoProfile -file \"%s\""
+ ps_path_win in
add_firstboot_script g root ?prio name fb
diff --git a/common/mlcustomize/firstboot.mli b/common/mlcustomize/firstboot.mli
index 8231af658..34ff06901 100644
--- a/common/mlcustomize/firstboot.mli
+++ b/common/mlcustomize/firstboot.mli
@@ -16,6 +16,23 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*)
+val firstboot_dir : Guestfs.guestfs -> string -> string * string option
+(** [firstboot_dir g root]
+ returns the path of the firstboot directory, creating it in
+ the guest if necessary.
+
+ This returns the name of the directory as a guestfs path, and
+ optionally the name as a Windows path (only for Windows guests).
+
+ For Linux this could be [/usr/lib/virt-sysprep, None]
+
+ For Windows this could be ["/Program Files/Guestfs/Firstboot",
+ Some "C:\Program Files\Guestfs\Firstboot"]
+
+ Additional files that are used during firstboot can be placed
+ in this directory, but be careful not to conflict with files
+ and scripts added by the firstboot process itself. *)
+
val add_firstboot_script : Guestfs.guestfs -> string -> ?prio:int -> string ->
string -> unit
(** [add_firstboot_script g root prio name content] adds a firstboot
diff --git a/common/mlcustomize/inject_virtio_win.ml b/common/mlcustomize/inject_virtio_win.ml
index 2a30b2008..afec1e456 100644
--- a/common/mlcustomize/inject_virtio_win.ml
+++ b/common/mlcustomize/inject_virtio_win.ml
@@ -24,6 +24,8 @@ open Common_gettext.Gettext
open Regedit
+let re_blnsvr = PCRE.compile ~caseless:true "\\bblnsvr\\.exe$"
+
type t = {
g : Guestfs.guestfs; (** guestfs handle *)
@@ -261,12 +263,38 @@ let rec inject_virtio_win_drivers ({ g } as t) reg =
}
)
-and inject_qemu_ga t =
- let msi_files = copy_qemu_ga t in
+and inject_qemu_ga ({ g; root } as t) =
+ (* Copy the qemu-ga MSI(s) to the guest. *)
+ let dir, dir_win = Firstboot.firstboot_dir g root in
+ let dir_win = Option.value dir_win ~default:dir in
+ let tempdir = sprintf "%s/Temp" dir in
+ let tempdir_win = sprintf "%s\\Temp" dir_win in
+ g#mkdir_p tempdir;
+
+ let msi_files = copy_qemu_ga t tempdir in
if msi_files <> [] then
- configure_qemu_ga t msi_files;
+ configure_qemu_ga t tempdir_win msi_files;
msi_files <> [] (* return true if we found some qemu-ga MSI files *)
+and inject_blnsvr ({ g; root } as t) =
+ (* Copy the files to the guest. *)
+ let dir, dir_win = Firstboot.firstboot_dir g root in
+ let dir_win = Option.value dir_win ~default:dir in
+ let tempdir = sprintf "%s/Temp" dir in
+ let tempdir_win = sprintf "%s\\Temp" dir_win in
+ g#mkdir_p tempdir;
+
+ let files = copy_blnsvr t tempdir in
+ match files with
+ | [] -> false (* Didn't find or install anything. *)
+
+ (* We usually find blnsvr.exe in two locations (drivers/by-os and
+ * drivers/by-driver). Pick the first.
+ *)
+ | blnsvr :: _ ->
+ configure_blnsvr t tempdir_win blnsvr;
+ true
+
and add_guestor_to_registry t ((g, root) as reg) drv_name drv_pciid =
let ddb_node = g#hivex_node_get_child root "DriverDatabase" in
@@ -346,8 +374,13 @@ and copy_drivers t driverdir =
(fun () ->
error (f_"root directory / is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log."))
-and copy_qemu_ga t =
- copy_from_virtio_win t "/" "/" (virtio_iso_path_matches_qemu_ga t)
+and copy_qemu_ga t tempdir =
+ copy_from_virtio_win t "/" tempdir (virtio_iso_path_matches_qemu_ga t)
+ (fun () ->
+ error (f_"root directory / is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log."))
+
+and copy_blnsvr t tempdir =
+ copy_from_virtio_win t "/" tempdir (virtio_iso_path_matches_blnsvr t)
(fun () ->
error (f_"root directory / is missing from the virtio-win directory or ISO.\n\nThis should not happen and may indicate that virtio-win or virt-v2v is broken in some way. Please report this as a bug with a full debug log."))
@@ -513,6 +546,10 @@ and virtio_iso_path_matches_qemu_ga t path =
| ("x86_64", "rhev-qga64.msi") -> true
| _ -> false
+(* Find blnsvr for the current Windows version. *)
+and virtio_iso_path_matches_blnsvr t path =
+ virtio_iso_path_matches_guest_os t path && PCRE.matches re_blnsvr path
+
(* Look up in libosinfo for the OS, and copy all the locally
* available files specified as drivers for that OS to the [destdir].
*
@@ -552,37 +589,35 @@ and copy_from_libosinfo { g; i_osinfo; i_arch } destdir =
) driver.Libosinfo.files
with Not_found -> []
-and configure_qemu_ga t files =
+(* Install qemu-ga. [files] is the non-empty list of possible qemu-ga
+ * installers we detected.
+ *)
+and configure_qemu_ga t tempdir_win files =
+ let script = ref [] in
+ let add = List.push_back script in
+
+ add "# Virt-v2v script which installs QEMU Guest Agent";
+ add "";
+ add "# Uncomment this line for lots of debug output.";
+ add "# Set-PSDebug -Trace 2";
+ add "";
+ add "Write-Host Installing QEMU Guest Agent";
+ add "";
+ add "# Run qemu-ga installers";
List.iter (
- fun msi_path ->
- (* Windows is a trashfire.
- * https://stackoverflow.com/a/18730884
- * https://bugzilla.redhat.com/show_bug.cgi?id=1895323
- *)
- let psh_script = ref [] in
- let add = List.push_back psh_script in
+ fun msi ->
+ add (sprintf "Write-Host \"Writing log to %s\\%s.log\""
+ tempdir_win msi);
+ (* [`] is an escape char for quotes *)
+ add (sprintf "Start-Process -Wait -FilePath \"%s\\%s\" -ArgumentList \"/norestart\",\"/qn\",\"/l+*vx\",\"`\"%s\\%s.log`\"\""
+ tempdir_win msi tempdir_win msi)
+ ) files;
- add "# Uncomment this line for lots of debug output.";
- add "# Set-PSDebug -Trace 2";
- add "";
- add "Write-Host Removing any previously scheduled qemu-ga installation";
- add "schtasks.exe /Delete /TN Firstboot-qemu-ga /F";
- add "";
- add (sprintf
- "Write-Host Scheduling delayed installation of qemu-ga from %s"
- msi_path);
- add "$d = (get-date).AddSeconds(120)";
- add "$dtfinfo = [System.Globalization.DateTimeFormatInfo]::CurrentInfo";
- add "$sdp = $dtfinfo.ShortDatePattern";
- add "$sdp = $sdp -replace 'y+', 'yyyy'";
- add "$sdp = $sdp -replace 'M+', 'MM'";
- add "$sdp = $sdp -replace 'd+', 'dd'";
- add "schtasks.exe /Create /SC ONCE `";
- add " /ST $d.ToString('HH:mm') /SD $d.ToString($sdp) `";
- add " /RU SYSTEM /TN Firstboot-qemu-ga `";
- add (sprintf " /TR \"C:\\%s /forcerestart /qn /l+*vx C:\\%s.log\""
- msi_path msi_path);
+ Firstboot.add_firstboot_powershell t.g t.root "install-qemu-ga" !script
- Firstboot.add_firstboot_powershell t.g t.root
- (sprintf "install-%s.ps1" msi_path) !psh_script;
- ) files
+and configure_blnsvr t tempdir_win blnsvr =
+ let cmd = sprintf "\
+ @echo off\n\
+ echo Installing %s\n\
+ \"%s\\%s\" -i\n" blnsvr tempdir_win blnsvr in
+ Firstboot.add_firstboot_script t.g t.root "install-blnsvr" cmd
diff --git a/common/mlcustomize/inject_virtio_win.mli b/common/mlcustomize/inject_virtio_win.mli
index d14f04973..d273c4dd3 100644
--- a/common/mlcustomize/inject_virtio_win.mli
+++ b/common/mlcustomize/inject_virtio_win.mli
@@ -93,3 +93,11 @@ val inject_qemu_ga : t -> bool
the MSI(s).
Returns [true] iff we were able to inject qemu-ga. *)
+
+val inject_blnsvr : t -> bool
+(** Inject the Balloon Server ([blnsvr.exe]) into a Windows guest.
+
+ A firstboot script is also injected which should install
+ the server by running [blnsvr -i].
+
+ Returns [true] iff we were able to inject the Balloon Server. *)
diff --git a/common/mldrivers/linux_kernels.ml b/common/mldrivers/linux_kernels.ml
index 23ff76a55..e0b6b8a00 100644
--- a/common/mldrivers/linux_kernels.ml
+++ b/common/mldrivers/linux_kernels.ml
@@ -102,7 +102,7 @@ let detect_kernels (g : G.guestfs) root bootloader apps =
) apps in
if verbose () then (
let names = List.map (fun { G.app2_name = name } -> name) kernel_pkgs in
- eprintf "candidate kernel packages in this guest: %s%!\n"
+ eprintf "info: candidate kernel packages in this guest: %s%!\n"
(String.concat " " names)
);
List.filter_map (
@@ -306,7 +306,7 @@ let detect_kernels (g : G.guestfs) root bootloader apps =
) kernel_pkgs in
if verbose () then (
- eprintf "installed kernel packages in this guest:\n";
+ eprintf "info: installed kernel packages in this guest:\n";
List.iter (print_kernel_info stderr "\t") installed_kernels;
flush stderr
);
@@ -343,7 +343,7 @@ let detect_kernels (g : G.guestfs) root bootloader apps =
) vmlinuzes in
if verbose () then (
- eprintf "kernels offered by the bootloader in this guest (first in list is default):\n";
+ eprintf "info: kernels offered by the bootloader in this guest (first in list is default):\n";
List.iter (print_kernel_info stderr "\t") bootloader_kernels;
flush stderr
);
diff --git a/common/options/uri.c b/common/options/uri.c
index 84d393c1e..9180d6a27 100644
--- a/common/options/uri.c
+++ b/common/options/uri.c
@@ -99,7 +99,7 @@ is_uri (const char *arg)
return 0;
for (p--; p >= arg; p--) {
- if (!c_islower (*p))
+ if (! (c_islower (*p) || *p == '+'))
return 0;
}
@@ -148,7 +148,10 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
}
*/
- *protocol_ret = strdup (uri->scheme);
+ if (STREQ (uri->scheme, "nbd+unix"))
+ *protocol_ret = strdup ("nbd");
+ else
+ *protocol_ret = strdup (uri->scheme);
if (*protocol_ret == NULL) {
perror ("strdup: protocol");
return -1;
@@ -194,7 +197,7 @@ parse (const char *arg, char **path_ret, char **protocol_ret,
if (path && path[0] == '/' &&
(STREQ (uri->scheme, "gluster") ||
STREQ (uri->scheme, "iscsi") ||
- STREQ (uri->scheme, "nbd") ||
+ STRPREFIX (uri->scheme, "nbd") ||
STREQ (uri->scheme, "rbd") ||
STREQ (uri->scheme, "sheepdog")))
path++;
diff --git a/common/progress/progress.c b/common/progress/progress.c
index e4b30663f..5848abd70 100644
--- a/common/progress/progress.c
+++ b/common/progress/progress.c
@@ -123,6 +123,7 @@ progress_bar_init (unsigned flags)
bar->machine_readable = 1;
bar->utf8_mode = 0;
bar->have_terminfo = 0;
+ bar->fp = NULL;
} else {
bar->machine_readable = 0;
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
index 1314d6e30..afced8c84 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -216,6 +216,9 @@ let run (g : G.guestfs) root (ops : ops) =
if not (Hostname.set_hostname g root hostname) then
warning (f_"hostname could not be set for this type of guest")
+ | `InjectBalloonServer _ ->
+ error "injecting the balloon server is not supported in RHEL 9.4, use RHEL 9.5 or above"
+
| `InjectQemuGA meth ->
(match get_virtio_win_handle "--inject-qemu-ga" meth with
| None -> ()

@ -1,203 +0,0 @@
From a55dcd5162e51a952ee6c23c4a89c1b098f304f4 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Fri, 19 May 2023 17:55:05 +0200
Subject: [PATCH] update common submodule
Laszlo Ersek (2):
options/keys: key_store_import_key(): un-constify "key" parameter
options/keys: introduce unescape_device_mapper_lvm()
Richard W.M. Jones (1):
mlcustomize/SELinux_relabel.ml: Use Array.mem
Roman Kagan (1):
mlcustomize: skip SELinux relabeling if it's disabled
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20230519155507.369494-2-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 4ddcae7e8543d2a63d907729d5b0d22f659d071f)
---
common | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Submodule common 70c10a079..b636c3f20:
diff --git a/common/options/options.h b/common/options/options.h
index 94573ee06..94e8b9eef 100644
--- a/common/options/options.h
+++ b/common/options/options.h
@@ -169,7 +169,8 @@ extern struct matching_key *get_keys (struct key_store *ks, const char *device,
const char *uuid, size_t *nr_matches);
extern void free_keys (struct matching_key *keys, size_t nr_matches);
extern struct key_store *key_store_add_from_selector (struct key_store *ks, const char *selector);
-extern struct key_store *key_store_import_key (struct key_store *ks, const struct key_store_key *key);
+extern struct key_store *key_store_import_key (struct key_store *ks,
+ struct key_store_key *key);
extern bool key_store_requires_network (const struct key_store *ks);
extern void free_key_store (struct key_store *ks);
diff --git a/common/mlcustomize/SELinux_relabel.ml b/common/mlcustomize/SELinux_relabel.ml
index 5ecf7bd7e..2f3a09bf7 100644
--- a/common/mlcustomize/SELinux_relabel.ml
+++ b/common/mlcustomize/SELinux_relabel.ml
@@ -24,10 +24,6 @@ open Printf
module G = Guestfs
-(* Simple reimplementation of Array.mem, available only with OCaml >= 4.03. *)
-let array_find a l =
- List.mem a (Array.to_list l)
-
let rec relabel (g : G.guestfs) =
(* Is the guest using SELinux? (Otherwise this is a no-op). *)
if is_selinux_guest g then (
@@ -59,14 +55,24 @@ and use_setfiles g =
g#aug_load ();
debug_augeas_errors g;
+ let config_path = "/files/etc/selinux/config" in
+ let config_keys = g#aug_ls config_path in
+ (* SELinux may be disabled via a setting in config file *)
+ let selinux_disabled =
+ let selinuxmode_path = config_path ^ "/SELINUX" in
+ if Array.mem selinuxmode_path config_keys then
+ g#aug_get selinuxmode_path = "disabled"
+ else
+ false in
+ if selinux_disabled then
+ failwith "selinux disabled";
+
(* Get the SELinux policy name, eg. "targeted", "minimum".
* Use "targeted" if not specified, just like libselinux does.
*)
let policy =
- let config_path = "/files/etc/selinux/config" in
let selinuxtype_path = config_path ^ "/SELINUXTYPE" in
- let keys = g#aug_ls config_path in
- if array_find selinuxtype_path keys then
+ if Array.mem selinuxtype_path config_keys then
g#aug_get selinuxtype_path
else
"targeted" in
diff --git a/common/options/keys.c b/common/options/keys.c
index 48f1bc7c7..52b273690 100644
--- a/common/options/keys.c
+++ b/common/options/keys.c
@@ -260,8 +260,107 @@ key_store_add_from_selector (struct key_store *ks, const char *selector)
return key_store_import_key (ks, &key);
}
+/* Turn /dev/mapper/VG-LV into /dev/VG/LV, in-place. */
+static void
+unescape_device_mapper_lvm (char *id)
+{
+ static const char dev[] = "/dev/", dev_mapper[] = "/dev/mapper/";
+ const char *input_start;
+ char *output;
+ enum { M_SCAN, M_FILL, M_DONE } mode;
+
+ if (!STRPREFIX (id, dev_mapper))
+ return;
+
+ /* Start parsing "VG-LV" from "id" after "/dev/mapper/". */
+ input_start = id + (sizeof dev_mapper - 1);
+
+ /* Start writing the unescaped "VG/LV" output after "/dev/". */
+ output = id + (sizeof dev - 1);
+
+ for (mode = M_SCAN; mode < M_DONE; ++mode) {
+ char c;
+ const char *input = input_start;
+ const char *hyphen_buffered = NULL;
+ bool single_hyphen_seen = false;
+
+ do {
+ c = *input;
+
+ switch (c) {
+ case '-':
+ if (hyphen_buffered == NULL)
+ /* This hyphen may start an escaped hyphen, or it could be the
+ * separator in VG-LV.
+ */
+ hyphen_buffered = input;
+ else {
+ /* This hyphen completes an escaped hyphen; unescape it. */
+ if (mode == M_FILL)
+ *output++ = '-';
+ hyphen_buffered = NULL;
+ }
+ break;
+
+ case '/':
+ /* Slash characters are forbidden in VG-LV anywhere. If there's any,
+ * we'll find it in the first (i.e., scanning) phase, before we output
+ * anything back to "id".
+ */
+ assert (mode == M_SCAN);
+ return;
+
+ default:
+ /* Encountered a non-slash, non-hyphen character -- which also may be
+ * the terminating NUL.
+ */
+ if (hyphen_buffered != NULL) {
+ /* The non-hyphen character comes after a buffered hyphen, so the
+ * buffered hyphen is supposed to be the single hyphen that separates
+ * VG from LV in VG-LV. There are three requirements for this
+ * separator: (a) it must be unique (we must not have seen another
+ * such separator earlier), (b) it must not be at the start of VG-LV
+ * (because VG would be empty that way), (c) it must not be at the end
+ * of VG-LV (because LV would be empty that way). Should any of these
+ * be violated, we'll catch that during the first (i.e., scanning)
+ * phase, before modifying "id".
+ */
+ if (single_hyphen_seen || hyphen_buffered == input_start ||
+ c == '\0') {
+ assert (mode == M_SCAN);
+ return;
+ }
+
+ /* Translate the separator hyphen to a slash character. */
+ if (mode == M_FILL)
+ *output++ = '/';
+ hyphen_buffered = NULL;
+ single_hyphen_seen = true;
+ }
+
+ /* Output the non-hyphen character (including the terminating NUL)
+ * regardless of whether there was a buffered hyphen separator (which,
+ * by now, we'll have attempted to translate and flush).
+ */
+ if (mode == M_FILL)
+ *output++ = c;
+ }
+
+ ++input;
+ } while (c != '\0');
+
+ /* We must have seen the VG-LV separator. If that's not the case, we'll
+ * catch it before modifying "id".
+ */
+ if (!single_hyphen_seen) {
+ assert (mode == M_SCAN);
+ return;
+ }
+ }
+}
+
struct key_store *
-key_store_import_key (struct key_store *ks, const struct key_store_key *key)
+key_store_import_key (struct key_store *ks, struct key_store_key *key)
{
struct key_store_key *new_keys;
@@ -278,6 +377,7 @@ key_store_import_key (struct key_store *ks, const struct key_store_key *key)
error (EXIT_FAILURE, errno, "realloc");
ks->keys = new_keys;
+ unescape_device_mapper_lvm (key->id);
ks->keys[ks->nr_keys] = *key;
++ks->nr_keys;

@ -1,88 +0,0 @@
From 9ac1ea9d5269c72874ea662cd70803b3781d0876 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Fri, 19 May 2023 17:55:06 +0200
Subject: [PATCH] inspector: rename VGs and LVs in LUKS-on-LVM test
In preparation for a subsequent patch, rename "VG" to "Volume-Group", and
"LV<n>" to "Logical-Volume-<n>", in the LUKS-on-LVM virt-inspector test.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20230519155507.369494-3-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 46a381efcf2bf74f1534ecb198f9570ee5baaccd)
---
inspector/test-virt-inspector-luks-on-lvm.sh | 11 +++----
test-data/phony-guests/make-fedora-img.pl | 30 +++++++++++---------
2 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/inspector/test-virt-inspector-luks-on-lvm.sh b/inspector/test-virt-inspector-luks-on-lvm.sh
index b9989433d..35454e630 100755
--- a/inspector/test-virt-inspector-luks-on-lvm.sh
+++ b/inspector/test-virt-inspector-luks-on-lvm.sh
@@ -36,14 +36,15 @@ if [ "$(guestfish version | grep minor | awk '{print $2}')" -lt 47 ]; then
fi
f=../test-data/phony-guests/fedora-luks-on-lvm.img
-keys=(--key /dev/VG/Root:key:FEDORA-Root
- --key /dev/VG/LV1:key:FEDORA-LV1
- --key /dev/VG/LV2:key:FEDORA-LV2
- --key /dev/VG/LV3:key:FEDORA-LV3)
+keys=(--key /dev/Volume-Group/Root:key:FEDORA-Root
+ --key /dev/Volume-Group/Logical-Volume-1:key:FEDORA-LV1
+ --key /dev/Volume-Group/Logical-Volume-2:key:FEDORA-LV2
+ --key /dev/Volume-Group/Logical-Volume-3:key:FEDORA-LV3)
# Ignore zero-sized file.
if [ -s "$f" ]; then
- uuid_root=$(guestfish --ro -i -a "$f" "${keys[@]}" luks-uuid /dev/VG/Root)
+ uuid_root=$(guestfish --ro -i -a "$f" "${keys[@]}" \
+ luks-uuid /dev/Volume-Group/Root)
b=$(basename "$f")
$VG virt-inspector "${keys[@]}" --format=raw -a "$f" > "actual-$b.xml"
# Check the generated output validate the schema.
diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl
index ffa7e0f10..9721ce4a9 100755
--- a/test-data/phony-guests/make-fedora-img.pl
+++ b/test-data/phony-guests/make-fedora-img.pl
@@ -224,23 +224,27 @@ EOF
# Create the Volume Group on /dev/sda2.
$g->pvcreate ('/dev/sda2');
- $g->vgcreate ('VG', ['/dev/sda2']);
- $g->lvcreate ('Root', 'VG', 256);
- $g->lvcreate ('LV1', 'VG', 32);
- $g->lvcreate ('LV2', 'VG', 32);
- $g->lvcreate ('LV3', 'VG', 64);
+ $g->vgcreate ('Volume-Group', ['/dev/sda2']);
+ $g->lvcreate ('Root', 'Volume-Group', 256);
+ $g->lvcreate ('Logical-Volume-1', 'Volume-Group', 32);
+ $g->lvcreate ('Logical-Volume-2', 'Volume-Group', 32);
+ $g->lvcreate ('Logical-Volume-3', 'Volume-Group', 64);
# Format each Logical Group as a LUKS device, with a different password.
- $g->luks_format ('/dev/VG/Root', 'FEDORA-Root', 0);
- $g->luks_format ('/dev/VG/LV1', 'FEDORA-LV1', 0);
- $g->luks_format ('/dev/VG/LV2', 'FEDORA-LV2', 0);
- $g->luks_format ('/dev/VG/LV3', 'FEDORA-LV3', 0);
+ $g->luks_format ('/dev/Volume-Group/Root', 'FEDORA-Root', 0);
+ $g->luks_format ('/dev/Volume-Group/Logical-Volume-1', 'FEDORA-LV1', 0);
+ $g->luks_format ('/dev/Volume-Group/Logical-Volume-2', 'FEDORA-LV2', 0);
+ $g->luks_format ('/dev/Volume-Group/Logical-Volume-3', 'FEDORA-LV3', 0);
# Open the LUKS devices. This creates nodes like /dev/mapper/*-luks.
- $g->cryptsetup_open ('/dev/VG/Root', 'FEDORA-Root', 'Root-luks');
- $g->cryptsetup_open ('/dev/VG/LV1', 'FEDORA-LV1', 'LV1-luks');
- $g->cryptsetup_open ('/dev/VG/LV2', 'FEDORA-LV2', 'LV2-luks');
- $g->cryptsetup_open ('/dev/VG/LV3', 'FEDORA-LV3', 'LV3-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Root',
+ 'FEDORA-Root', 'Root-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Logical-Volume-1',
+ 'FEDORA-LV1', 'LV1-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Logical-Volume-2',
+ 'FEDORA-LV2', 'LV2-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Logical-Volume-3',
+ 'FEDORA-LV3', 'LV3-luks');
# Phony root filesystem.
$g->mkfs ('ext2', '/dev/mapper/Root-luks', blocksize => 4096, label => 'ROOT');

@ -1,48 +0,0 @@
From d8d1e7213716835f263a4f20d9e6cf8719c210c0 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Fri, 19 May 2023 17:55:07 +0200
Subject: [PATCH] inspector: test /dev/mapper/VG-LV translation in LUKS-on-LVM
test
In the LUKS-on-LVM virt-inspector test, run virt-inspector one more time,
now with such "--key" options that exercise the recent "/dev/mapper/VG-LV"
-> "/dev/VG/LV" translation (unescaping) from libguestfs-common. Verify
that virt-inspector outputs the same XML as it did when we passed it the
"/dev/VG/LV" format "--key" options.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20230519155507.369494-4-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 569bd1dd29da7f3a7b3399ad85340f84d59b3a10)
---
inspector/test-virt-inspector-luks-on-lvm.sh | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/inspector/test-virt-inspector-luks-on-lvm.sh b/inspector/test-virt-inspector-luks-on-lvm.sh
index 35454e630..13b25e338 100755
--- a/inspector/test-virt-inspector-luks-on-lvm.sh
+++ b/inspector/test-virt-inspector-luks-on-lvm.sh
@@ -41,6 +41,11 @@ keys=(--key /dev/Volume-Group/Root:key:FEDORA-Root
--key /dev/Volume-Group/Logical-Volume-2:key:FEDORA-LV2
--key /dev/Volume-Group/Logical-Volume-3:key:FEDORA-LV3)
+keys_mapper=(--key /dev/mapper/Volume--Group-Root:key:FEDORA-Root
+ --key /dev/mapper/Volume--Group-Logical--Volume--1:key:FEDORA-LV1
+ --key /dev/mapper/Volume--Group-Logical--Volume--2:key:FEDORA-LV2
+ --key /dev/mapper/Volume--Group-Logical--Volume--3:key:FEDORA-LV3)
+
# Ignore zero-sized file.
if [ -s "$f" ]; then
uuid_root=$(guestfish --ro -i -a "$f" "${keys[@]}" \
@@ -53,4 +58,10 @@ if [ -s "$f" ]; then
# are any differences.
sed -e "s/ROOTUUID/$uuid_root/" < "$srcdir/expected-$b.xml" \
| diff -u - "actual-$b.xml"
+
+ # Re-run virt-inspector with keys using the /dev/mapper/VG-LV format; verify
+ # only that the XML output matches the output from the previous
+ # virt-inspector invocation (which used the /dev/VG/LV format).
+ $VG virt-inspector "${keys_mapper[@]}" --format=raw -a "$f" \
+ | diff -u "actual-$b.xml" -
fi

@ -7,7 +7,7 @@ set -e
# ./copy-patches.sh # ./copy-patches.sh
project=guestfs-tools project=guestfs-tools
rhel_version=9.3 rhel_version=9.4
# Check we're in the right directory. # Check we're in the right directory.
if [ ! -f $project.spec ]; then if [ ! -f $project.spec ]; then

@ -1,17 +0,0 @@
-----BEGIN PGP SIGNATURE-----
iQJFBAABCAAvFiEE93dPsa0HSn6Mh2fqkXOPc+G3aKAFAmQusKARHHJpY2hAYW5u
ZXhpYS5vcmcACgkQkXOPc+G3aKDmZxAAsk+1QC36YwCXF0LgerjrB40a73YZfifN
X8jgziSD3jDBVGgRTUWuFRedDEhzHMP4Fa2TGQjQ2MGRQ/Ay9T/frAujaqPtBSN+
ixmVLOJl/kHz2S4BZEpdL8T5FvDtXgSBn/3MyWRlBZdLw2jgQ3+ZKsZnCOsu74ej
qhHGFCp0xkhUIuVPXRBIPQ6VcbBZn/0/TIHY4gXTaAisb22kLGp/HTyAi6kwiOnx
cHgSLalToT3cJqGxZV9EyCF08AlT5zMP6jxYb7Xno1csnq7vQWwN/pCQyqupWeLs
BGlGfJ39AgCibXEaIAUU7fZ77rPxDzbrOAuZd3n4Z7cmn0VWTWoUGZlX9gw38nyZ
SusH7y/R8WTMLfLkuDsWov/cXRCwCQEWcCyDyVJkshkWhqVAUGKLgHFQsWsne6nc
BoMkEst3XR4OlI/XtC4aTHoWDoWSpp/KzfXRsU2/5r/I612AZXzAQFwBeiK5CIHR
cDu3KLYqqrJFS4ELxsF8lERiamZq7iKzNGsAwsiA3rEtjpGjzui26e9pSUczxJOT
VaduPKcuVJguQok+af3LOm/Xu5k4r99beshuqTpeOPXouKDB67cebI1NAC5d1CyT
45ByPZyQcgnvg1mZsBY2/plF/mmg4oh8i58pFg1exXHP9og+C8EBc4W1Cu6Fj4yi
ni4oBJbEefM=
=65Sq
-----END PGP SIGNATURE-----

@ -0,0 +1,17 @@
-----BEGIN PGP SIGNATURE-----
iQJFBAABCAAvFiEE93dPsa0HSn6Mh2fqkXOPc+G3aKAFAmV0UtkRHHJpY2hAYW5u
ZXhpYS5vcmcACgkQkXOPc+G3aKArQQ/8DR2NMjDy8zyXfLSAoSPcChx+wS36RRhj
rYGSNzD2aNhMzB+WGZHomiW4ahLqj7OAuXQlmpUMjLVsAfyja8aNW7rsnfTM1l5u
p6GS3DFTk34XgVrZO01pEBLWk9blr+xhAFP+qNIwWKv76+xO0QjNa0D5gJvBojZf
J3ct9l1ibKqDh4eG9ReSSUh76WOxm97JwP80ZRBKCpcNJe+fceJGHdBhl5UJFw/N
lAKY+d7MESk9aKZCNy6BRrls6IeIlsOBB8HbG5mXqMv4IfwarB91zZTG9NJRpmSN
MzZ/GIwSCJy9U9hmG3dA/70xFu3HQkshaCisXb4FrzCnlTHZFNCvwdhY2k3qIzZr
PuvsA3ETQqYUj66AlOOD/3TqAu36kFEeeateH75cIiOYfkUUmrO7FF76hY2jNs+q
puTm14dg/MA0OROQv5ykcuN2ukvfsyEsCFao+76am5MG8CViy1tSnL/ZSBN0itLl
jalFbag3GbDCwVt+lpPQbrLDTWNVabAEeN9LlMMcsciIGWDiz99Ntmwe1yxwLLl3
kk8f9xFiWXU7C0yrPY4HzPGNjzklsaNlpzVnqgkWpR1gzpLr37HWx0E1Ct6OlJBJ
7vllv9L9bZErUwyvlSuGcY/6rHd+KnWSS0IBvEfE/eveQErzwgiuGiBUnvGB6NUT
l868E59pb84=
=cEbV
-----END PGP SIGNATURE-----

@ -11,16 +11,16 @@
%global patches_touch_autotools 1 %global patches_touch_autotools 1
# The source directory. # The source directory.
%global source_directory 1.50-stable %global source_directory 1.51-development
# Filter perl provides. # Filter perl provides.
%{?perl_default_filter} %{?perl_default_filter}
Summary: Tools to access and modify virtual machine disk images Summary: Tools to access and modify virtual machine disk images
Name: guestfs-tools Name: guestfs-tools
Version: 1.50.1 Version: 1.51.6
Release: 3%{?dist} Release: 3%{?dist}
License: GPLv2+ License: GPL-2.0-or-later AND LGPL-2.0-or-later
# Build only for architectures that have a kernel # Build only for architectures that have a kernel
ExclusiveArch: %{kernel_arches} ExclusiveArch: %{kernel_arches}
@ -45,16 +45,14 @@ Source2: libguestfs.keyring
Source3: copy-patches.sh Source3: copy-patches.sh
# Patches are maintained in the following repository: # Patches are maintained in the following repository:
# https://github.com/rwmjones/guestfs-tools/commits/rhel-9.3 # https://github.com/rwmjones/guestfs-tools/commits/rhel-9.4
# Patches. # Patches.
Patch0001: 0001-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch Patch0001: 0001-Update-common-submodule.patch
Patch0002: 0002-RHEL-builder-Disable-opensuse-repository.patch Patch0002: 0002-builder-Add-a-test-of-the-chown-parameter.patch
Patch0003: 0003-Remove-virt-dib.patch Patch0003: 0003-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch
Patch0004: 0004-drivers-Look-up-vendor-and-device-names-in-PCI-and-U.patch Patch0004: 0004-RHEL-builder-Disable-opensuse-repository.patch
Patch0005: 0005-update-common-submodule.patch Patch0005: 0005-Update-common-submodule.patch
Patch0006: 0006-inspector-rename-VGs-and-LVs-in-LUKS-on-LVM-test.patch
Patch0007: 0007-inspector-test-dev-mapper-VG-LV-translation-in-LUKS-.patch
%if 0%{patches_touch_autotools} %if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool, gettext-devel BuildRequires: autoconf, automake, libtool, gettext-devel
@ -207,7 +205,7 @@ Virt-tail follows (tails) a log file within a guest, like 'tail -f'.
%package -n virt-win-reg %package -n virt-win-reg
Summary: Access and modify the Windows Registry of a Windows VM Summary: Access and modify the Windows Registry of a Windows VM
License: GPLv2+ License: GPL-2.0-or-later
BuildArch: noarch BuildArch: noarch
# This replaces the libguestfs-tools package. # This replaces the libguestfs-tools package.
@ -413,6 +411,19 @@ end
%changelog %changelog
* Tue Aug 27 2024 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-3
- Reboot Windows between each firstboot script to improve reliability
resolves: RHEL-55824
* Fri Jan 19 2024 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-2
- Rebase to guestfs-tools 1.51.6
- Implement --key all:...
resolves: RHEL-19030
- Fix crash because of off-by-one error
resolves: RHEL-19062
- Fix virt-customize --chown invalid format
resolves: RHEL-21899
* Thu Jun 08 2023 Laszlo Ersek <lersek@redhat.com> - 1.50.1-3 * Thu Jun 08 2023 Laszlo Ersek <lersek@redhat.com> - 1.50.1-3
- let virt-inspector recognize "--key /dev/mapper/VG-LV:key:password" - let virt-inspector recognize "--key /dev/mapper/VG-LV:key:password"
- reenable "make check"; we now use "-cpu max" (libguestfs 30f74f38bd6e) - reenable "make check"; we now use "-cpu max" (libguestfs 30f74f38bd6e)

Loading…
Cancel
Save