Compare commits

...

No commits in common. "c9-beta" and "c10s" have entirely different histories.

20 changed files with 364 additions and 1195 deletions

5
.gitignore vendored
View File

@ -1,2 +1,3 @@
SOURCES/guestfs-tools-1.52.2.tar.gz
SOURCES/libguestfs.keyring
*~
/guestfs-tools-*.tar.gz
/guestfs-tools-*.tar.gz.sig

View File

@ -1,2 +0,0 @@
6eb02f4f70cb224548567ce7e4b67712c8ebb643 SOURCES/guestfs-tools-1.52.2.tar.gz
1bbc40f501a7fef9eef2a39b701a71aee2fea7c4 SOURCES/libguestfs.keyring

View File

@ -0,0 +1,33 @@
From bf4fef4f2b45a2016c42094f8e4fe18abc8d90e2 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 21 May 2025 15:02:44 +0100
Subject: [PATCH] docs: Move release note about GNU gettext to build section
Fixes: commit 9b7410c220f1111e6acef88efbbaee3fea4019b8
Updates: commit 80ce443e5eb7323e9b7b5cef30b8f7673ca51d67
---
docs/guestfs-tools-release-notes-1.54.pod | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/docs/guestfs-tools-release-notes-1.54.pod b/docs/guestfs-tools-release-notes-1.54.pod
index b44eb19a2..ab9062303 100644
--- a/docs/guestfs-tools-release-notes-1.54.pod
+++ b/docs/guestfs-tools-release-notes-1.54.pod
@@ -78,6 +78,8 @@ Some deprecated autoconf macros are no longer used.
Fix some issues when building on macOS (Mohamed Akram).
+Fix compatibility with GNU gettext 0.25.
+
=head2 Internals
The tests were modified to use a set of common functions and remove
@@ -87,8 +89,6 @@ nbdkit.
Some internal OCaml List and String functions that we used have been
replaced by ones from the OCaml stdlib, reducing code maintenance.
-Fix compatibility with GNU gettext 0.25.
-
=head2 Bugs fixed
=begin comment

View File

@ -0,0 +1,123 @@
From bbc262b2166f226937d4331ac80b631cab7c1129 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 24 May 2025 13:27:00 +0100
Subject: [PATCH] builder: Build fedora-42 template
Thanks: Jeff Layton
---
builder/templates/fedora-42.index-fragment | 22 +++++++++
builder/templates/fedora-42.ks | 48 ++++++++++++++++++++
builder/templates/fedora-42.virt-install-cmd | 20 ++++++++
3 files changed, 90 insertions(+)
create mode 100644 builder/templates/fedora-42.index-fragment
create mode 100644 builder/templates/fedora-42.ks
create mode 100644 builder/templates/fedora-42.virt-install-cmd
diff --git a/builder/templates/fedora-42.index-fragment b/builder/templates/fedora-42.index-fragment
new file mode 100644
index 000000000..6d21b742c
--- /dev/null
+++ b/builder/templates/fedora-42.index-fragment
@@ -0,0 +1,22 @@
+[fedora-42]
+name=Fedora® 42 Server
+osinfo=fedora42
+arch=x86_64
+file=fedora-42.xz
+checksum[sha512]=dda921f3c522da8d8a67e31948260f52a9aa5bdeca4382a5c557635d77ad91d11b9aded70a225f59503b268ec73815ceac2eac5b70c1d47f22056febdd9da6bb
+format=raw
+size=6442450944
+compressed_size=927728896
+expand=/dev/sda3
+notes=Fedora® 42 Server
+
+ This Fedora image contains only unmodified @Core group packages.
+
+ Fedora and the Infinity design logo are trademarks of Red Hat, Inc.
+ Source and further information is available from http://fedoraproject.org/
+
+ This template was generated by a script in the libguestfs source tree:
+ builder/templates/make-template.ml
+ Associated files used to prepare this template can be found in the
+ same directory.
+
diff --git a/builder/templates/fedora-42.ks b/builder/templates/fedora-42.ks
new file mode 100644
index 000000000..17e2e3f15
--- /dev/null
+++ b/builder/templates/fedora-42.ks
@@ -0,0 +1,48 @@
+# Kickstart file for fedora-42
+# Generated by libguestfs.git/builder/templates/make-template.ml
+
+text
+reboot
+lang en_US.UTF-8
+keyboard us
+network --bootproto dhcp
+rootpw builder
+firewall --enabled --ssh
+timezone --utc America/New_York
+selinux --enforcing
+
+bootloader --location=mbr --append="console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH"
+
+
+zerombr
+clearpart --all --initlabel --disklabel=gpt
+autopart --type=plain
+
+# Halt the system once configuration has finished.
+poweroff
+
+%packages
+@core
+%end
+
+%post
+# Ensure the installation is up-to-date.
+dnf -y --best upgrade
+# This required otherwise the kernel will not be bootable, see
+# https://bugzilla.redhat.com/show_bug.cgi?id=1911177
+# https://bugzilla.redhat.com/show_bug.cgi?id=1945835#c24
+grub2-mkconfig -o '/etc/grub2.cfg'
+# Enable Xen domU support.
+pushd /etc/dracut.conf.d
+echo 'add_drivers+=" xen:vbd xen:vif "' > virt-builder-xen-drivers.conf
+popd
+# To make dracut config changes permanent, we need to rerun dracut.
+# Rerun dracut for the installed kernel (not the running kernel).
+# See commit 0fa52e4e45d80874bc5ea5f112f74be1d3f3472f and
+# https://www.redhat.com/archives/libguestfs/2014-June/thread.html#00045
+KERNEL_VERSION="$(rpm -q kernel --qf '%{version}-%{release}.%{arch}\n' |
+ sort -V | tail -1)"
+dracut -f /boot/initramfs-$KERNEL_VERSION.img $KERNEL_VERSION
+%end
+
+# EOF
diff --git a/builder/templates/fedora-42.virt-install-cmd b/builder/templates/fedora-42.virt-install-cmd
new file mode 100644
index 000000000..2a3256bbd
--- /dev/null
+++ b/builder/templates/fedora-42.virt-install-cmd
@@ -0,0 +1,20 @@
+# This is the virt-install command which was used to create
+# the virt-builder template 'fedora-42'
+# NB: This file is generated for documentation purposes ONLY!
+# This script was never run, and is not intended to be run.
+
+'virt-install' \
+ '--transient' \
+ '--name=tmp-oeg15xnl' \
+ '--ram=4096' \
+ '--arch=x86_64' \
+ '--cpu=host' \
+ '--vcpus=4' \
+ '--os-variant=fedora34' \
+ '--initrd-inject=fedora-42.ks' \
+ '--extra-args=inst.ks=file:/fedora-42.ks console=tty0 console=ttyS0,115200 rd_NO_PLYMOUTH' \
+ '--disk=/home/rjones/d/guestfs-tools/builder/templates/tmp-oeg15xnl.img,size=6,format=raw' \
+ '--location=https://lon.mirror.rackspace.com/fedora/releases/42/Server/x86_64/os/' \
+ '--serial=pty' \
+ '--nographics'
+

View File

@ -0,0 +1,22 @@
From 5a2458f38d40e5c6f3eceb8e7de162724ff9e374 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 3 Jun 2025 08:29:57 +0100
Subject: [PATCH] builder: Update link to templates to use https
Fixes: https://issues.redhat.com/browse/RHEL-94873
Reported-by: Xiang Hua Chen
---
builder/libguestfs.conf.in | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builder/libguestfs.conf.in b/builder/libguestfs.conf.in
index 8d8feab75..08b6a6234 100644
--- a/builder/libguestfs.conf.in
+++ b/builder/libguestfs.conf.in
@@ -1,5 +1,5 @@
[libguestfs.org]
-uri=http://builder.libguestfs.org/index.asc
+uri=https://builder.libguestfs.org/index.asc
gpgkey=file://@SYSCONFDIR@/virt-builder/repos.d/libguestfs.gpg
[archive.libguestfs.org]

View File

@ -1,4 +1,4 @@
From 1107ededf2cad9982befb4d4b90353117b29d474 Mon Sep 17 00:00:00 2001
From 38a47670f0699232cd040e7cffa2c815a69531c3 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 7 Jul 2015 09:28:03 -0400
Subject: [PATCH] RHEL: Reject use of libguestfs-winsupport features except for
@ -11,7 +11,7 @@ edits.
1 file changed, 1 insertion(+)
diff --git a/test-data/phony-guests/make-windows-img.sh b/test-data/phony-guests/make-windows-img.sh
index 16debd129..1c13ddac3 100755
index 0ec6b4851..9fa29f98b 100755
--- a/test-data/phony-guests/make-windows-img.sh
+++ b/test-data/phony-guests/make-windows-img.sh
@@ -37,6 +37,7 @@ fi

View File

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

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# guestfs-tools
The guestfs-tools package

View File

@ -1,254 +0,0 @@
From 1cb20d561c6b2e93980ba9c7c7269b32f6d768eb Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 16 May 2024 12:49:24 +0100
Subject: [PATCH] customize: Implement --inject-blnsvr operation
Also updates the common submodule with the generated changes from
libguestfs, and the implementation of Inject_virtio_win.inject_blnsvr.
(cherry picked from commit 80d258baa49214c8e59b91d6085595c9b989fc0d)
---
common | 2 +-
customize/customize_run.ml | 13 +++++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
Submodule common 7cbb3ba35...a78839676:
diff --git a/common/mlcustomize/customize-options.pod b/common/mlcustomize/customize-options.pod
index ff93630d8..b2ac57526 100644
--- a/common/mlcustomize/customize-options.pod
+++ b/common/mlcustomize/customize-options.pod
@@ -193,6 +193,18 @@ L<virt-builder(1)/INSTALLING PACKAGES>.
Set the hostname of the guest to C<HOSTNAME>. You can use a
dotted hostname.domainname (FQDN) if you want.
+=item B<--inject-blnsvr> METHOD
+
+Inject the Balloon Server (F<blnsvr.exe>) into a Windows guest.
+This operation also injects a firstboot script so that the Balloon
+Server is installed when the guest boots.
+
+The parameter is the same as used by the I<--inject-virtio-win> operation.
+
+Note that to do a full conversion of a Windows guest from a
+foreign hypervisor like VMware (which involves many other operations)
+you should use the L<virt-v2v(1)> tool instead of this.
+
=item B<--inject-qemu-ga> METHOD
Inject the QEMU Guest Agent into a Windows guest. The guest
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-blnsvr METHOD]
+ [--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
@@ -286,6 +288,12 @@ let rec argspec () =
s_"Set the hostname"
),
Some "HOSTNAME", "Set the hostname of the guest to C<HOSTNAME>. You can use a\ndotted hostname.domainname (FQDN) if you want.";
+ (
+ [ L"inject-blnsvr" ],
+ Getopt.String (s_"METHOD", fun s -> List.push_front (`InjectBalloonServer s) ops),
+ s_"Inject the Balloon Server into a Windows guest"
+ ),
+ Some "METHOD", "Inject the Balloon Server (F<blnsvr.exe>) into a Windows guest.\nThis operation also injects a firstboot script so that the Balloon\nServer is installed when the guest boots.\n\nThe parameter is the same as used by the I<--inject-virtio-win> operation.\n\nNote that to do a full conversion of a Windows guest from a\nforeign hypervisor like VMware (which involves many other operations)\nyou should use the L<virt-v2v(1)> tool instead of this.";
(
[ L"inject-qemu-ga" ],
Getopt.String (s_"METHOD", fun s -> List.push_front (`InjectQemuGA s) ops),
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/inject_virtio_win.ml b/common/mlcustomize/inject_virtio_win.ml
index 0a4b8dac0..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 *)
@@ -274,6 +276,25 @@ and inject_qemu_ga ({ g; root } as t) =
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
@@ -358,6 +379,11 @@ and copy_qemu_ga t tempdir =
(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."))
+
(* Copy all files from virtio_win directory/ISO located in [srcdir]
* subdirectory and all its subdirectories to the [destdir]. The directory
* hierarchy is not preserved, meaning all files will be directly in [destdir].
@@ -452,10 +478,7 @@ and virtio_iso_path_matches_guest_os t path =
* "./drivers/amd64/Win2012R2/netkvm.sys".
* Note we check lowercase paths.
*)
- let pathelem elem =
- String.find lc_path ("/" ^ elem ^ "/") >= 0 ||
- String.is_prefix lc_path (elem ^ "/")
- in
+ let pathelem elem = String.find lc_path ("/" ^ elem ^ "/") >= 0 in
let p_arch =
if pathelem "x86" || pathelem "i386" then "i386"
else if pathelem "amd64" then "x86_64"
@@ -499,11 +522,7 @@ and virtio_iso_path_matches_guest_os t path =
else
raise Not_found in
- let p_sriov = pathelem "sriov" in
-
- arch = p_arch &&
- not p_sriov && (* always ignored, see RHEL-56383 *)
- os_major = p_os_major && os_minor = p_os_minor &&
+ arch = p_arch && os_major = p_os_major && os_minor = p_os_minor &&
match_os_variant os_variant &&
match_osinfo osinfo
@@ -527,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].
*
@@ -591,3 +614,10 @@ and configure_qemu_ga t tempdir_win files =
) files;
Firstboot.add_firstboot_powershell t.g t.root "install-qemu-ga" !script
+
+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/customize/customize_run.ml b/customize/customize_run.ml
index 1314d6e30..1d7c13eaf 100644
--- a/customize/customize_run.ml
+++ b/customize/customize_run.ml
@@ -113,8 +113,8 @@ let run (g : G.guestfs) root (ops : ops) =
Hashtbl.replace passwords user pw
in
- (* Helper function to convert --inject-qemu-ga/--inject-virtio-win
- * method parameter into a virtio-win handle.
+ (* Helper function to convert --inject-blnsvr/--inject-qemu-ga/
+ * --inject-virtio-win method parameter into a virtio-win handle.
*)
let get_virtio_win_handle op meth =
if g#inspect_get_type root <> "windows" then (
@@ -216,6 +216,15 @@ 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 meth ->
+ (match get_virtio_win_handle "--inject-blnsvr" meth with
+ | None -> ()
+ | Some t ->
+ if not (Inject_virtio_win.inject_blnsvr t) then
+ warning (f_"--inject-blnsvr: blnsvr.exe not found in \
+ virtio-win source that you specified")
+ )
+
| `InjectQemuGA meth ->
(match get_virtio_win_handle "--inject-qemu-ga" meth with
| None -> ()

View File

@ -1,33 +0,0 @@
From 9cdb27fb0fde8b2eb57453480c4fed4746414aeb Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 22 Oct 2024 11:01:25 +0100
Subject: [PATCH] build: Add new dependency on json-c
This will eventually replace Jansson for all JSON parsing. However
this commit simply introduces the new dependency in the configure
script and documents it.
I chose json-c 0.14 as the baseline since that is the version in RHEL 9.
Probably earlier versions would work.
(cherry picked from libguestfs commit 53872a0a1a267040677572c30b68bd1e8b62ebe3)
(cherry picked from commit 0d7fe8a0b0b429152ea02fc7a7e4f5a1b0eba590)
---
m4/guestfs-libraries.m4 | 3 +++
1 file changed, 3 insertions(+)
diff --git a/m4/guestfs-libraries.m4 b/m4/guestfs-libraries.m4
index 32f93afda..b76511982 100644
--- a/m4/guestfs-libraries.m4
+++ b/m4/guestfs-libraries.m4
@@ -167,6 +167,9 @@ LIBS="$old_LIBS"
dnl Check for Jansson JSON library (required).
PKG_CHECK_MODULES([JANSSON], [jansson >= 2.7])
+dnl Check for JSON-C library (required).
+PKG_CHECK_MODULES([JSON_C], [json-c >= 0.14])
+
dnl Check for libosinfo (mandatory)
PKG_CHECK_MODULES([LIBOSINFO], [libosinfo-1.0])

View File

@ -1,267 +0,0 @@
From 02a911960b5916df93bf896afc94c8d250797f17 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 22 Oct 2024 11:07:01 +0100
Subject: [PATCH] builder: Replace jansson with json-c
This pulls in the following common module commit which ports the
JSON_parser module from jansson to json-c:
Richard W.M. Jones (1):
mltools: Replace jansson with json-c
(cherry picked from commit 12997768d231b80dc219a518c287ecf10c83ff0e)
---
builder/Makefile.am | 2 +-
common | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builder/Makefile.am b/builder/Makefile.am
index b474f0c9d..0761eff4c 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -206,7 +206,7 @@ OCAMLCLIBS = \
$(LIBLZMA_LIBS) \
$(LIBXML2_LIBS) \
$(LIBOSINFO_LIBS) \
- $(JANSSON_LIBS) \
+ $(JSON_C_LIBS) \
$(LIBINTL) \
-lgnu
Submodule common a78839676..766384a45:
diff --git a/common/mltools/JSON_parser-c.c b/common/mltools/JSON_parser-c.c
index bf38dd1bf..fb67b4632 100644
--- a/common/mltools/JSON_parser-c.c
+++ b/common/mltools/JSON_parser-c.c
@@ -23,7 +23,7 @@
#include <caml/memory.h>
#include <caml/mlvalues.h>
-#include <jansson.h>
+#include <json.h>
#include <stdio.h>
#include <string.h>
@@ -40,7 +40,7 @@ value virt_builder_json_parser_tree_parse (value stringv);
value virt_builder_json_parser_tree_parse_file (value stringv);
static value
-convert_json_t (json_t *val, int level)
+convert_json_t (json_object *val, int level)
{
CAMLparam0 ();
CAMLlocal5 (rv, v, tv, sv, consv);
@@ -48,9 +48,11 @@ convert_json_t (json_t *val, int level)
if (level > 20)
caml_invalid_argument ("too many levels of object/array nesting");
- if (json_is_object (val)) {
+ switch (json_object_get_type (val)) {
+ case json_type_object: {
+ struct json_object_iterator it, itend;
const char *key;
- json_t *jvalue;
+ json_object *jvalue;
rv = caml_alloc (1, JSON_DICT_TAG);
v = Val_int (0);
@@ -60,29 +62,39 @@ convert_json_t (json_t *val, int level)
* matter (eg. simplestreams which incorrectly uses a dict when it
* really should use an array).
*/
- json_object_foreach (val, key, jvalue) {
+ it = json_object_iter_begin (val);
+ itend = json_object_iter_end (val);
+ while (!json_object_iter_equal (&it, &itend)) {
+ key = json_object_iter_peek_name (&it);
tv = caml_alloc_tuple (2);
sv = caml_copy_string (key);
Store_field (tv, 0, sv);
+
+ jvalue = json_object_iter_peek_value (&it);
sv = convert_json_t (jvalue, level + 1);
Store_field (tv, 1, sv);
+
consv = caml_alloc (2, 0);
Store_field (consv, 1, v);
Store_field (consv, 0, tv);
v = consv;
+
+ json_object_iter_next (&it);
}
Store_field (rv, 0, v);
+ break;
}
- else if (json_is_array (val)) {
- const size_t len = json_array_size (val);
+
+ case json_type_array: {
+ const size_t len = json_object_array_length (val);
size_t i;
- json_t *jvalue;
+ json_object *jvalue;
rv = caml_alloc (1, JSON_LIST_TAG);
v = Val_int (0);
for (i = 0; i < len; ++i) {
/* Note we have to create the OCaml list backwards. */
- jvalue = json_array_get (val, len-i-1);
+ jvalue = json_object_array_get_idx (val, len-i-1);
tv = convert_json_t (jvalue, level + 1);
consv = caml_alloc (2, 0);
Store_field (consv, 1, v);
@@ -90,32 +102,36 @@ convert_json_t (json_t *val, int level)
v = consv;
}
Store_field (rv, 0, v);
+ break;
}
- else if (json_is_string (val)) {
+
+ case json_type_string:
rv = caml_alloc (1, JSON_STRING_TAG);
- v = caml_copy_string (json_string_value (val));
+ v = caml_copy_string (json_object_get_string (val));
Store_field (rv, 0, v);
- }
- else if (json_is_real (val)) {
+ break;
+
+ case json_type_double:
rv = caml_alloc (1, JSON_FLOAT_TAG);
- v = caml_copy_double (json_real_value (val));
+ v = caml_copy_double (json_object_get_double (val));
Store_field (rv, 0, v);
- }
- else if (json_is_integer (val)) {
+ break;
+
+ case json_type_int:
rv = caml_alloc (1, JSON_INT_TAG);
- v = caml_copy_int64 (json_integer_value (val));
+ v = caml_copy_int64 (json_object_get_int64 (val));
Store_field (rv, 0, v);
- }
- else if (json_is_true (val)) {
+ break;
+
+ case json_type_boolean:
rv = caml_alloc (1, JSON_BOOL_TAG);
- Store_field (rv, 0, Val_true);
- }
- else if (json_is_false (val)) {
- rv = caml_alloc (1, JSON_BOOL_TAG);
- Store_field (rv, 0, Val_false);
- }
- else
+ Store_field (rv, 0, json_object_get_boolean (val) ? Val_true : Val_false);
+ break;
+
+ case json_type_null:
rv = JSON_NULL;
+ break;
+ }
CAMLreturn (rv);
}
@@ -125,45 +141,28 @@ virt_builder_json_parser_tree_parse (value stringv)
{
CAMLparam1 (stringv);
CAMLlocal1 (rv);
- json_t *tree;
- json_error_t err;
+ json_object *tree = NULL;
+ json_tokener *tok = NULL;
+ enum json_tokener_error err;
- tree = json_loads (String_val (stringv), JSON_DECODE_ANY, &err);
- if (tree == NULL) {
- char buf[256 + JSON_ERROR_TEXT_LENGTH];
- if (strlen (err.text) > 0)
- snprintf (buf, sizeof buf, "JSON parse error: %s", err.text);
- else
- snprintf (buf, sizeof buf, "unknown JSON parse error");
+ tok = json_tokener_new ();
+ json_tokener_set_flags (tok,
+ JSON_TOKENER_STRICT | JSON_TOKENER_VALIDATE_UTF8);
+ tree = json_tokener_parse_ex (tok,
+ String_val (stringv),
+ caml_string_length (stringv));
+ err = json_tokener_get_error (tok);
+ if (err != json_tokener_success) {
+ char buf[256];
+ snprintf (buf, sizeof buf, "JSON parse error: %s",
+ json_tokener_error_desc (err));
+ json_tokener_free (tok);
caml_invalid_argument (buf);
}
+ json_tokener_free (tok);
rv = convert_json_t (tree, 1);
- json_decref (tree);
-
- CAMLreturn (rv);
-}
-
-value
-virt_builder_json_parser_tree_parse_file (value filev)
-{
- CAMLparam1 (filev);
- CAMLlocal1 (rv);
- json_t *tree;
- json_error_t err;
-
- tree = json_load_file (String_val (filev), JSON_DECODE_ANY, &err);
- if (tree == NULL) {
- char buf[1024 + JSON_ERROR_TEXT_LENGTH];
- if (strlen (err.text) > 0)
- snprintf (buf, sizeof buf, "%s: JSON parse error: %s", String_val (filev), err.text);
- else
- snprintf (buf, sizeof buf, "%s: unknown JSON parse error", String_val (filev));
- caml_invalid_argument (buf);
- }
-
- rv = convert_json_t (tree, 1);
- json_decref (tree);
+ json_object_put (tree);
CAMLreturn (rv);
}
diff --git a/common/mltools/JSON_parser.ml b/common/mltools/JSON_parser.ml
index 933057277..8bc35abdc 100644
--- a/common/mltools/JSON_parser.ml
+++ b/common/mltools/JSON_parser.ml
@@ -21,7 +21,10 @@ open Tools_utils
open Common_gettext.Gettext
external json_parser_tree_parse : string -> JSON.json_t = "virt_builder_json_parser_tree_parse"
-external json_parser_tree_parse_file : string -> JSON.json_t = "virt_builder_json_parser_tree_parse_file"
+
+let json_parser_tree_parse_file filename =
+ let content = read_whole_file filename in
+ json_parser_tree_parse content
let object_find_optional key = function
| JSON.Dict fields ->
diff --git a/common/mltools/Makefile.am b/common/mltools/Makefile.am
index f510a6747..684c26946 100644
--- a/common/mltools/Makefile.am
+++ b/common/mltools/Makefile.am
@@ -116,7 +116,7 @@ libmltools_a_CFLAGS = \
$(LIBVIRT_CFLAGS) \
$(LIBXML2_CFLAGS) \
$(LIBGUESTFS_CFLAGS) \
- $(JANSSON_CFLAGS) \
+ $(JSON_C_CFLAGS) \
$(LIBOSINFO_CFLAGS) \
-fPIC
@@ -148,7 +148,7 @@ OCAMLCLIBS = \
$(LIBCRYPT_LIBS) \
$(LIBVIRT_LIBS) \
$(LIBXML2_LIBS) \
- $(JANSSON_LIBS) \
+ $(JSON_C_LIBS) \
$(LIBOSINFO_LIBS) \
$(LIBINTL) \
-lgnu

View File

@ -1,27 +0,0 @@
From 5879249a32d50ab746f515abc2679b91f64a2098 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 22 Oct 2024 15:22:18 +0100
Subject: [PATCH] build: Remove Jansson dependency
After previous changes, this library is no longer used. We have
switched to json-c, for better compatibility with libvirt.
(cherry picked from commit e6dcf7e3a7e9170978e57ce6df1b34f92fac5ae3)
---
m4/guestfs-libraries.m4 | 3 ---
1 file changed, 3 deletions(-)
diff --git a/m4/guestfs-libraries.m4 b/m4/guestfs-libraries.m4
index b76511982..80f9425f0 100644
--- a/m4/guestfs-libraries.m4
+++ b/m4/guestfs-libraries.m4
@@ -164,9 +164,6 @@ LIBS="$LIBS $LIBXML2_LIBS"
AC_CHECK_FUNCS([xmlBufferDetach])
LIBS="$old_LIBS"
-dnl Check for Jansson JSON library (required).
-PKG_CHECK_MODULES([JANSSON], [jansson >= 2.7])
-
dnl Check for JSON-C library (required).
PKG_CHECK_MODULES([JSON_C], [json-c >= 0.14])

View File

@ -1,151 +0,0 @@
From 065f95e7afa45bf465e8799baa11c019f9403bd6 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 19 Feb 2025 15:15:30 +0000
Subject: [PATCH] test-data: phony fedora: Add simple static /bin/sh
This is able to do enough to run commands via g#sh and related calls
inside the phony Fedora image.
(cherry picked from commit 4c5854f54e1da0d96807acb1b047bbf34694a0bb)
---
cat/test-virt-ls.sh | 1 +
test-data/phony-guests/fedora.c | 76 +++++++++++++++++++++--
test-data/phony-guests/make-fedora-img.pl | 6 +-
3 files changed, 76 insertions(+), 7 deletions(-)
diff --git a/cat/test-virt-ls.sh b/cat/test-virt-ls.sh
index e98faa42b..577a44860 100755
--- a/cat/test-virt-ls.sh
+++ b/cat/test-virt-ls.sh
@@ -24,6 +24,7 @@ skip_if_skipped
# Read out the test directory using virt-ls.
if [ "$($VG virt-ls --format=raw -a ../test-data/phony-guests/fedora.img /bin)" != "ls
rpm
+sh
test1
test2
test3
diff --git a/test-data/phony-guests/fedora.c b/test-data/phony-guests/fedora.c
index c57fa57cc..df097e9e6 100644
--- a/test-data/phony-guests/fedora.c
+++ b/test-data/phony-guests/fedora.c
@@ -16,13 +16,14 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-/* This is "just enough" of a binary to look like RPM and dracut, as
- * far as virt-v2v is concerned.
+/* This is "just enough" of a binary to look like /bin/sh, RPM and
+ * dracut, as far as virt-v2v is concerned.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
/* NB: This is also defined in make-fedora-img.pl */
#define KVER "5.19.0-0.rc1.14.fc37.x86_64"
@@ -34,6 +35,27 @@ get_basename (const char *str)
return ret == NULL ? str : ret + 1;
}
+static void
+add_str (char ***argv, size_t *argc, char *str)
+{
+ (*argc)++;
+ (*argv) = realloc (*argv, *argc * sizeof (char *));
+ (*argv)[*argc-1] = str;
+}
+
+static void
+add_null (char ***argv, size_t *argc)
+{
+ add_str (argv, argc, NULL);
+}
+
+static void
+add (char ***argv, size_t *argc, const char *s, size_t len)
+{
+ char *copy = strndup (s, len);
+ add_str (argv, argc, copy);
+}
+
int
main (int argc, char *argv[])
{
@@ -57,10 +79,54 @@ main (int argc, char *argv[])
strcmp (get_basename (argv[0]), "dracut") == 0) {
// do nothing, pretend to rebuild the initramfs
}
+ else if (argc == 3 &&
+ strcmp (get_basename (argv[0]), "sh") == 0 &&
+ strcmp (argv[1], "-c") == 0) {
+ /* Split the command and execute it. Only handles trivial cases. */
+ char *cmd = argv[2];
+ char **cmdv = NULL;
+ size_t i, cmdvlen = 0, n;
+ const size_t len = strlen (cmd);
+
+ for (i = 0; i < len;) {
+ switch (cmd[i]) {
+ case ' ': case '\t':
+ i++;
+ continue;
+
+ case '"':
+ n = strcspn (&cmd[i+1], "\"");
+ add (&cmdv, &cmdvlen, &cmd[i+1], n);
+ i += n+2;
+ break;
+
+ case '\'':
+ n = strcspn (&cmd[i+1], "'");
+ add (&cmdv, &cmdvlen, &cmd[i+1], n);
+ i += n+2;
+ break;
+
+ default:
+ n = strcspn (&cmd[i], " \t");
+ add (&cmdv, &cmdvlen, &cmd[i], n);
+ i += n;
+ }
+ }
+ add_null (&cmdv, &cmdvlen);
+
+ execvp (cmdv[0], cmdv);
+ perror (cmdv[0]);
+ exit (EXIT_FAILURE);
+ }
else {
- fprintf (stderr, "phony Fedora: unknown command\n");
- exit (1);
+ int i;
+
+ fprintf (stderr, "ERROR: test-data/phony-guests/fedora.c: "
+ "unexpected command:\n");
+ for (i = 0; i < argc; ++i)
+ fprintf (stderr, "argv[%d] = %s\n", i, argv[i]);
+ exit (EXIT_FAILURE);
}
- exit (0);
+ exit (EXIT_SUCCESS);
}
diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl
index 0de506324..fef8ce032 100755
--- a/test-data/phony-guests/make-fedora-img.pl
+++ b/test-data/phony-guests/make-fedora-img.pl
@@ -369,8 +369,10 @@ $g->ln_s ('/bin/test1', '/bin/test5');
$g->mkfifo (0777, '/bin/test6');
$g->mknod (0777, 10, 10, '/bin/test7');
-# Virt-v2v needs an RPM command, or at least something which acts
-# similarly, and also a dracut command.
+# Virt-v2v needs a /bin/sh, an RPM command and a dracut command, or at
+# least something which acts similarly to those.
+$g->upload ('fedora-static-bin', '/bin/sh');
+$g->chmod (0777, '/bin/sh');
$g->upload ('fedora-static-bin', '/bin/rpm');
$g->chmod (0777, '/bin/rpm');
$g->upload ('fedora-static-bin', '/sbin/dracut');

View File

@ -1,343 +0,0 @@
From 777f3ac82c20469c9e438b9fd88a57007fd2c2bb Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 19 Feb 2025 14:16:13 +0000
Subject: [PATCH] drivers: Handle large output from 'rpm -ql' command
This requires the new guestfs_sh_out API from libguestfs 1.55.6.
Update common submodule to include:
Richard W.M. Jones (3):
mlstdutils: Reimplement String.find, add String.find_from
mlstdutils: Reimplement String.nsplit tail recursively
mldrivers: Handle large output from 'rpm -ql' command
Fixes: https://issues.redhat.com/browse/RHEL-80214
Reported-by: Nijin Ashok
(cherry picked from commit 5520f1cfae55377c2fe1db3f2974f6006822e0ea)
---
common | 2 +-
m4/guestfs-libraries.m4 | 5 ++---
2 files changed, 3 insertions(+), 4 deletions(-)
Submodule common 766384a45..ee88791e1:
diff --git a/common/mldrivers/linux.ml b/common/mldrivers/linux.ml
index 4e30a8e1f..0dec15495 100644
--- a/common/mldrivers/linux.ml
+++ b/common/mldrivers/linux.ml
@@ -58,76 +58,84 @@ and do_remove g root packages =
let file_list_of_package (g : Guestfs.guestfs) root app =
let package_format = g#inspect_get_package_format root in
- match package_format with
- | "deb" ->
- let cmd = [| "dpkg"; "-L"; app.G.app2_name |] in
- debug "%s" (String.concat " " (Array.to_list cmd));
- let files = g#command_lines cmd in
- let files = Array.to_list files in
+
+ let cmd =
+ match package_format with
+ | "deb" -> sprintf "dpkg -L %s" (quote app.G.app2_name)
+
+ | "rpm" ->
+ (* Since RPM allows multiple packages installed with the same
+ * name, always check the full NEVR here (RHBZ#1161250).
+ *
+ * In RPM < 4.11 query commands that use the epoch number in the
+ * package name did not work.
+ *
+ * For example:
+ * RHEL 6 (rpm 4.8.0):
+ * $ rpm -q tar-2:1.23-11.el6.x86_64
+ * package tar-2:1.23-11.el6.x86_64 is not installed
+ * Fedora 20 (rpm 4.11.2):
+ * $ rpm -q tar-2:1.26-30.fc20.x86_64
+ * tar-1.26-30.fc20.x86_64
+ *)
+ let is_rpm_lt_4_11 () =
+ let ver =
+ try
+ (* Since we're going to run 'rpm' below anyway, seems safe
+ * to run it here and assume the binary works.
+ *)
+ let cmd = [| "rpm"; "--version" |] in
+ debug "%s" (String.concat " " (Array.to_list cmd));
+ let ver = g#command_lines cmd in
+ let ver =
+ if Array.length ver > 0 then ver.(0) else raise Not_found in
+ debug "%s" ver;
+ let ver = String.nsplit " " ver in
+ let ver =
+ match ver with
+ | [ "RPM"; "version"; ver ] -> ver
+ | _ -> raise Not_found in
+ if not (PCRE.matches re_version ver) then raise Not_found;
+ (int_of_string (PCRE.sub 1), int_of_string (PCRE.sub 2))
+ with Not_found ->
+ (* 'rpm' not installed? Hmm... *)
+ (0, 0) in
+ ver < (4, 11)
+ in
+ let pkg_name =
+ if app.G.app2_epoch = Int32.zero || is_rpm_lt_4_11 () then
+ sprintf "%s-%s-%s" app.G.app2_name app.G.app2_version
+ app.G.app2_release
+ else
+ sprintf "%s-%ld:%s-%s" app.G.app2_name app.G.app2_epoch
+ app.G.app2_version app.G.app2_release in
+ sprintf "rpm -ql %s" (quote pkg_name)
+
+ | format ->
+ error (f_"dont know how to get list of files from package using %s")
+ format in
+
+ debug "file_list_of_package: running: %s" cmd;
+
+ (* Some packages have a lot of files, too many to list without
+ * breaking the maximum message size assumption in libguestfs.
+ * To cope with this, use guestfs_sh_out, added in 1.55.6.
+ * https://issues.redhat.com/browse/RHEL-80080
+ *)
+ let tmpfile = Filename.temp_file "v2vcmd" ".out" in
+ On_exit.unlink tmpfile;
+ g#sh_out cmd tmpfile;
+ let files = read_whole_file tmpfile in
+
+ (* RPM prints "(contains no files)" on stdout when a package
+ * has no files in it:
+ * https://github.com/rpm-software-management/rpm/issues/962
+ *)
+ if String.is_prefix files "(contains no files)" then []
+ else (
+ let files = String.nsplit "\n" files in
List.sort compare files
-
- | "rpm" ->
- (* Since RPM allows multiple packages installed with the same
- * name, always check the full NEVR here (RHBZ#1161250).
- *
- * In RPM < 4.11 query commands that use the epoch number in the
- * package name did not work.
- *
- * For example:
- * RHEL 6 (rpm 4.8.0):
- * $ rpm -q tar-2:1.23-11.el6.x86_64
- * package tar-2:1.23-11.el6.x86_64 is not installed
- * Fedora 20 (rpm 4.11.2):
- * $ rpm -q tar-2:1.26-30.fc20.x86_64
- * tar-1.26-30.fc20.x86_64
- *)
- let is_rpm_lt_4_11 () =
- let ver =
- try
- (* Since we're going to run 'rpm' below anyway, seems safe
- * to run it here and assume the binary works.
- *)
- let cmd = [| "rpm"; "--version" |] in
- debug "%s" (String.concat " " (Array.to_list cmd));
- let ver = g#command_lines cmd in
- let ver = if Array.length ver > 0 then ver.(0) else raise Not_found in
- debug "%s" ver;
- let ver = String.nsplit " " ver in
- let ver =
- match ver with
- | [ "RPM"; "version"; ver ] -> ver
- | _ -> raise Not_found in
- if not (PCRE.matches re_version ver) then raise Not_found;
- (int_of_string (PCRE.sub 1), int_of_string (PCRE.sub 2))
- with Not_found ->
- (* 'rpm' not installed? Hmm... *)
- (0, 0) in
- ver < (4, 11)
- in
- let pkg_name =
- if app.G.app2_epoch = Int32.zero || is_rpm_lt_4_11 () then
- sprintf "%s-%s-%s" app.G.app2_name app.G.app2_version
- app.G.app2_release
- else
- sprintf "%s-%ld:%s-%s" app.G.app2_name app.G.app2_epoch
- app.G.app2_version app.G.app2_release in
- let cmd = [| "rpm"; "-ql"; pkg_name |] in
- debug "%s" (String.concat " " (Array.to_list cmd));
- let files = g#command_lines cmd in
- (* RPM prints "(contains no files)" on stdout when a package
- * has no files in it:
- * https://github.com/rpm-software-management/rpm/issues/962
- *)
- if files = [| "(contains no files)" |] then
- []
- else (
- let files = Array.to_list files in
- List.sort compare files
- )
-
- | format ->
- error (f_"dont know how to get list of files from package using %s")
- format
+ )
let is_file_owned (g : G.guestfs) root path =
let package_format = g#inspect_get_package_format root in
diff --git a/common/mlstdutils/std_utils.ml b/common/mlstdutils/std_utils.ml
index 86b21a7c5..1a36ab772 100644
--- a/common/mlstdutils/std_utils.ml
+++ b/common/mlstdutils/std_utils.ml
@@ -98,24 +98,27 @@ module String = struct
and len = length str in
len >= sufflen && sub str (len - sufflen) sufflen = suffix
- let rec find s sub =
- let len = length s in
+ let find_from str pos sub =
let sublen = length sub in
- let rec loop i =
- if i <= len-sublen then (
- let rec loop2 j =
- if j < sublen then (
- if s.[i+j] = sub.[j] then loop2 (j+1)
- else -1
- ) else
- i (* found *)
- in
- let r = loop2 0 in
- if r = -1 then loop (i+1) else r
- ) else
- -1 (* not found *)
- in
- loop 0
+ if sublen = 0 then
+ 0
+ else (
+ let found = ref 0 in
+ let len = length str in
+ try
+ for i = pos to len - sublen do
+ let j = ref 0 in
+ while unsafe_get str (i + !j) = unsafe_get sub !j do
+ incr j;
+ if !j = sublen then begin found := i; raise Exit; end;
+ done;
+ done;
+ -1
+ with
+ Exit -> !found
+ )
+
+ let find str sub = find_from str 0 sub
let rec replace s s1 s2 =
let len = length s in
@@ -145,7 +148,7 @@ module String = struct
else if n >= len then str, ""
else sub str 0 n, sub str n (len-n)
- let rec split sep str =
+ let split sep str =
let seplen = length sep in
let strlen = length str in
let i = find str sep in
@@ -154,20 +157,36 @@ module String = struct
sub str 0 i, sub str (i + seplen) (strlen - i - seplen)
)
- and nsplit ?(max = 0) sep str =
+ let nsplit ?(max = 0) sep str =
if max < 0 then
invalid_arg "String.nsplit: max parameter should not be negative";
- (* If we reached the limit, OR if the pattern does not match the string
- * at all, return the rest of the string as a single element list.
- *)
- if max = 1 || find str sep = -1 then
- [str]
- else (
- let s1, s2 = split sep str in
- let max = if max = 0 then 0 else max - 1 in
- s1 :: nsplit ~max sep s2
- )
+ let len = String.length str in
+ let seplen = String.length sep in
+
+ let rec loop iters posn acc =
+ (* If we reached the limit, OR if the pattern does not match
+ * the string at all, return the rest of the string.
+ *)
+ if max > 0 && iters = max then (
+ let rest =
+ if posn = 0 then str else String.sub str posn (len-posn) in
+ List.rev (rest :: acc)
+ )
+ else (
+ let end_ = find_from str posn sep in
+ if end_ = -1 then (
+ let rest =
+ if posn = 0 then str else String.sub str posn (len-posn) in
+ List.rev (rest :: acc)
+ )
+ else (
+ let acc = String.sub str posn (end_-posn) :: acc in
+ loop (iters+1) (end_+seplen) acc
+ )
+ )
+ in
+ loop 1 0 []
let rec lines_split str =
let buf = Buffer.create 16 in
diff --git a/common/mlstdutils/std_utils.mli b/common/mlstdutils/std_utils.mli
index a39ac5f3b..7bd55fbae 100644
--- a/common/mlstdutils/std_utils.mli
+++ b/common/mlstdutils/std_utils.mli
@@ -82,6 +82,10 @@ module String : sig
val find : string -> string -> int
(** [find str sub] searches for [sub] as a substring of [str]. If
found it returns the index. If not found, it returns [-1]. *)
+ val find_from : string -> int -> string -> int
+ (** [find_from str start sub] searches for [sub] as a substring of [str],
+ starting at index [start]. If found it returns the index.
+ If not found, it returns [-1]. *)
val replace : string -> string -> string -> string
(** [replace str s1 s2] replaces all instances of [s1] appearing in
[str] with [s2]. *)
diff --git a/common/mlstdutils/std_utils_tests.ml b/common/mlstdutils/std_utils_tests.ml
index 3f5bb1a86..4e368152f 100644
--- a/common/mlstdutils/std_utils_tests.ml
+++ b/common/mlstdutils/std_utils_tests.ml
@@ -113,13 +113,19 @@ let test_string_nsplit ctx =
assert_equal_stringlist [""] (String.nsplit " " "");
assert_equal_stringlist ["abc"] (String.nsplit " " "abc");
assert_equal_stringlist ["a"; "b"; "c"] (String.nsplit " " "a b c");
+ assert_equal_stringlist ["abc"; "d"; "e"] (String.nsplit " " "abc d e");
assert_equal_stringlist ["a"; "b"; "c"; ""] (String.nsplit " " "a b c ");
assert_equal_stringlist [""; "a"; "b"; "c"] (String.nsplit " " " a b c");
assert_equal_stringlist [""; "a"; "b"; "c"; ""] (String.nsplit " " " a b c ");
assert_equal_stringlist ["a b c d"] (String.nsplit ~max:1 " " "a b c d");
assert_equal_stringlist ["a"; "b c d"] (String.nsplit ~max:2 " " "a b c d");
assert_equal_stringlist ["a"; "b"; "c d"] (String.nsplit ~max:3 " " "a b c d");
- assert_equal_stringlist ["a"; "b"; "c"; "d"] (String.nsplit ~max:10 " " "a b c d")
+ assert_equal_stringlist ["a"; "b"; "c"; "d"] (String.nsplit ~max:10 " " "a b c d");
+
+ (* Test that nsplit can handle large strings. *)
+ let xs = Array.to_list (Array.make 10_000_000 "xyz") in
+ let xs_concat = String.concat " " xs in
+ assert_equal_stringlist xs (String.nsplit " " xs_concat)
(* Test Std_utils.String.lines_split. *)
let test_string_lines_split ctx =
diff --git a/m4/guestfs-libraries.m4 b/m4/guestfs-libraries.m4
index 80f9425f0..7c66853dd 100644
--- a/m4/guestfs-libraries.m4
+++ b/m4/guestfs-libraries.m4
@@ -19,9 +19,8 @@ dnl Any C libraries required by the libguestfs C library (not the daemon).
dnl Of course we need libguestfs.
dnl
-dnl We need libguestfs 1.49.8 for guestfs_inspect_get_build_id in
-dnl virt-drivers.
-PKG_CHECK_MODULES([LIBGUESTFS], [libguestfs >= 1.49.8])
+dnl We need libguestfs >= 1:1.54.0-4.el9_6 for guestfs_sh_out.
+PKG_CHECK_MODULES([LIBGUESTFS], [libguestfs >= 1.54.0])
dnl Test if it's GNU or XSI strerror_r.
AC_FUNC_STRERROR_R

View File

@ -1,17 +0,0 @@
-----BEGIN PGP SIGNATURE-----
iQJFBAABCAAvFiEE93dPsa0HSn6Mh2fqkXOPc+G3aKAFAmb+mWcRHHJpY2hAYW5u
ZXhpYS5vcmcACgkQkXOPc+G3aKBPWRAAmHJHvz8GRAsFEpZS6/6FjgxjASRTtMZO
02vo8KZLpF3pX0zjsgcYPsTgj90kQ8z9rsdXk70HbOvnJIuVShuT9Q/bGiYf60YB
CEvRy3b5HMgsk4Dk46Ux0RpOHTFmVKOxSdNrk1G0qRMjIYdy19KxRnMJyQXv4QRg
y6RYOt2Zm6Luj53Id+zTLiqnz5Z8PBkupWH3y1zSrN3OcASIvSKYnPUA/c63+Fzk
YZHGIf3DCHEAnzHfPMaF58L+Np3ZaC4vGBfnDfLiyTd/d2J/Ci18LcI9hC9l6SV1
ePlNBH/LV1+YYuWLhd9XPVsCiKi2zY3/DMxoxZcYhl+JalVTeK6FZk2Abe+0c9XZ
wAaQG+aLqweDHNiLJ0AxoPqinWsa2EpciZMKAzzCGM83IABm+pKSZlN077riiYNa
YRZIw/i6LFfuQSxBaav+/d6cOpxx4AklmaV1ymu4Xr2JTm4u93O72722oyhCzbAn
3DQac1H5XgJsBh6Un9Ybl3PkUGS2AlCCDTFbyWDB8i9aiWv5m/yuLD4c6hk9sRWQ
DNiH0AKaem/cPt33FV3C2viyppmGnhZDNrrKKzJCxCkRY7XU2rzEJ1SmU9CACCOj
ick58Flv52CYSeonC+7uO9jqlDcgVmJIDitCCHhIl1Kipr1mzCMQV1Vq0LP3Hv8f
MSbFdmbrh5I=
=Gu1k
-----END PGP SIGNATURE-----

View File

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

6
gating.yaml Executable file
View File

@ -0,0 +1,6 @@
--- !Policy
product_versions:
- rhel-*
decision_context: osci_compose_gate
rules:
- !PassingTestCaseRule {test_case_name: xen-ci.brew-build.tier1.functional}

View File

@ -7,19 +7,16 @@
# Verify tarball signature with GPGv2.
%global verify_tarball_signature 1
# If there are patches which touch autotools files, set this to 1.
%global patches_touch_autotools 1
# The source directory.
%global source_directory 1.52-stable
%global source_directory 1.54-stable
# Filter perl provides.
%{?perl_default_filter}
Summary: Tools to access and modify virtual machine disk images
Name: guestfs-tools
Version: 1.52.2
Release: 3%{?dist}
Version: 1.54.0
Release: 2%{?dist}
License: GPL-2.0-or-later AND LGPL-2.0-or-later
# Build only for architectures that have a kernel
@ -45,26 +42,21 @@ Source2: libguestfs.keyring
Source3: copy-patches.sh
# Patches are maintained in the following repository:
# https://github.com/rwmjones/guestfs-tools/commits/rhel-9.6
# https://github.com/rwmjones/guestfs-tools/commits/rhel-10.1
# Patches.
Patch0001: 0001-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch
Patch0002: 0002-RHEL-builder-Disable-opensuse-repository.patch
Patch0003: 0003-customize-Implement-inject-blnsvr-operation.patch
Patch0004: 0004-build-Add-new-dependency-on-json-c.patch
Patch0005: 0005-builder-Replace-jansson-with-json-c.patch
Patch0006: 0006-build-Remove-Jansson-dependency.patch
Patch0007: 0007-test-data-phony-fedora-Add-simple-static-bin-sh.patch
Patch0008: 0008-drivers-Handle-large-output-from-rpm-ql-command.patch
%if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool, gettext-devel
%endif
Patch0001: 0001-docs-Move-release-note-about-GNU-gettext-to-build-se.patch
Patch0002: 0002-builder-Build-fedora-42-template.patch
Patch0003: 0003-builder-Update-link-to-templates-to-use-https.patch
Patch0004: 0004-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch
Patch0005: 0005-RHEL-builder-Disable-opensuse-repository.patch
# Basic build requirements.
BuildRequires: autoconf, automake, libtool, gettext-devel
BuildRequires: gcc, gcc-c++
BuildRequires: make
BuildRequires: libguestfs-devel >= 1:1.54.0-4.el9
BuildRequires: glibc-utils
BuildRequires: libguestfs-devel >= 1:1.49.8-1
BuildRequires: libguestfs-xfs
BuildRequires: perl(Pod::Simple)
BuildRequires: perl(Pod::Man)
@ -82,12 +74,10 @@ BuildRequires: ncurses-devel
%ifarch x86_64
BuildRequires: glibc-static
%endif
BuildRequires: ocaml >= 4.08
BuildRequires: ocaml-libguestfs-devel
BuildRequires: ocaml-findlib-devel
BuildRequires: ocaml-gettext-devel
%if !0%{?rhel}
BuildRequires: ocaml-ounit-devel
%endif
BuildRequires: flex
BuildRequires: bison
BuildRequires: xz-devel
@ -113,8 +103,9 @@ BuildRequires: gnupg2
%endif
# Ensure a minimum version of libguestfs is installed. This contains
# new APIs sh-out and command-out, required by virt-drivers.
Requires: libguestfs >= 1:1.54.0-4.el9
# a workaround for openssl bug RHBZ#2133884 and the hang where we
# called setenv between fork and exec.
Requires: libguestfs >= 1.49.6-1
# For virt-builder:
Requires: curl
@ -259,13 +250,12 @@ for %{name}.
%setup -q
%autopatch -p1
%if 0%{patches_touch_autotools}
autoreconf -i
%endif
%build
%{configure}
autoreconf -fiv
# Preserve timestamps when copying files. Otherwise, the time of the
# build ends up in the header added by gzip when it compresses files.
%{configure} INSTALL='/usr/bin/install -p'
# Building index-parse.c by hand works around a race condition in the
# autotools cruft, where two or more copies of yacc race with each
@ -413,90 +403,173 @@ end
%changelog
* Tue Feb 25 2025 Richard W.M. Jones <rjones@redhat.com> - 1.52.2-3
- Fix virt-drivers fails on opensuse guest if kernel-source is installed
resolves: RHEL-80214
* Tue Jun 10 2025 Richard W.M. Jones <rjones@redhat.com> - 1.54.0-2
- Rebase to guestfs-tools 1.54.0
resolves: RHEL-81734
- virt-builder, virt-v2v & other tools with -v and --install causes dnf5 error
resolves: RHEL-83201
- virt-drivers fails on opensuse guest if kernel-source is installed
resolves: RHEL-92604
- builder: Update link to templates to use https
resolves: RHEL-94873
* Wed Oct 30 2024 Richard W.M. Jones <rjones@redhat.com> - 1.52.2-2
- Rebase to guestfs-tools 1.52.2
resolves: RHEL-56811
resolves: RHEL-56812
- Replace Jansson with json-c
resolves: RHEL-65294
resolves: RHEL-65295
* Tue Aug 27 2024 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-5
* Tue Aug 27 2024 Richard W.M. Jones <rjones@redhat.com> - 1.52.1-1
- New stable version 1.52.1
- Rebase on top of patches from RHEL 9.5
- Reboot Windows between each firstboot script to improve reliability
resolves: RHEL-55759
* Thu May 16 2024 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-4
- Add support for nbd+unix:// URIs
resolves: RHEL-33956
resolves: RHEL-56319
- customize: Implement --inject-blnsvr operation
resolves: RHEL-36634
resolves: RHEL-56330
- Add support for nbd+unix:// URIs
resolves: RHEL-56332
* 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
* Tue Jun 25 2024 Troy Dawson <tdawson@redhat.com> - 1.52.0-6
- Bump release for June 2024 mass rebuild
* Thu Jun 08 2023 Laszlo Ersek <lersek@redhat.com> - 1.50.1-3
- let virt-inspector recognize "--key /dev/mapper/VG-LV:key:password"
- reenable "make check"; we now use "-cpu max" (libguestfs 30f74f38bd6e)
resolves: rhbz#2209280
* Wed Jun 19 2024 Richard W.M. Jones <rjones@redhat.com> - 1.52.0-5
- OCaml 5.2.0 ppc64le fix
* Thu Apr 06 2023 Richard W.M. Jones <rjones@redhat.com> - 1.50.1-1
- Rebase to guestfs-tools 1.50.1
resolves: rhbz#2168626
- Fix virt-drivers inspection of RHEL 9.2 guests
resolves: rhbz#2184963
* Fri May 31 2024 Richard W.M. Jones <rjones@redhat.com> - 1.52.0-4
- Rebuild for OCaml 5.2
* Thu Nov 24 2022 Richard W.M. Jones <rjones@redhat.com> - 1.48.2-8
- Support Rocky Linux in virt-customize
resolves: rhbz#2133443
- Disable OpenSUSE repo in virt-builder
resolves: rhbz#2145160
* Wed Jan 24 2024 Fedora Release Engineering <releng@fedoraproject.org> - 1.52.0-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_40_Mass_Rebuild
* Fri Jul 15 2022 Richard W.M. Jones <rjones@redhat.com> - 1.48.2-5
- Rebase to guestfs-tools 1.48.2
resolves: rhbz#2059286
- Default to --selinux-relabel in various tools
resolves: rhbz#2075718, rhbz#2089748
- Add lvm system.devices cleanup operation to virt-sysprep
resolves: rhbz#2072493
- Refactor virt-customize --install, --update options in common submodule
- Add support for Clevis & Tang
resolves: rhbz#1809453
- Fix CVE-2022-2211 Denial of Service in --key parameter
resolves: rhbz#2102721
- Fix virt-sysprep and LUKS-on-LVM guests
resolves: rhbz#2106286
* Fri Jan 19 2024 Richard W.M. Jones <rjones@redhat.com> - 1.52.0-2
- Fix virt-customize --chown invalid format error
- New upstream github repository.
* Sat Dec 04 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-6
- Clean up NetworkManager connection files
- Add the copy-patches.sh script from virt-v2v
resolves: rhbz#1980922
* Thu Jan 4 2024 Richard W.M. Jones <rjones@redhat.com> - 1.52.0-1
- New stable version 1.52.0
* Tue Nov 23 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-5
- Fix detection of Kylin Desktop
resolves: rhbz#2025950
* Tue Dec 19 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.7-1
- New development version 1.51.7
* Mon Aug 09 2021 Mohan Boddu <mboddu@redhat.com> - 1.46.1-4.1
- Rebuilt for IMA sigs, glibc 2.34, aarch64 flags
Related: rhbz#1991688
* Mon Dec 18 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-5
- OCaml 5.1.1 + s390x code gen fix for Fedora 40
* Wed Jun 2 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-3.el9.1
* Tue Dec 12 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-4
- Bump release and rebuild
* Tue Dec 12 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-3
- OCaml 5.1.1 rebuild for Fedora 40
* Sat Dec 9 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.6-2
- New development version 1.51.6
* Mon Nov 27 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.5-2
- Fix build for libxml2 2.12.1
* Thu Nov 02 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.5-1
- New development version 1.51.5
* Thu Oct 05 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.4-2
- OCaml 5.1 rebuild for Fedora 40
* Thu Jul 20 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.4-1
- New development version 1.51.4
* Thu Jul 20 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.51.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_39_Mass_Rebuild
* Fri Jul 14 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.3-1
- New development version 1.51.3
* Mon Jun 05 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.2-2
- Migrated to SPDX license
* Thu Apr 06 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.2-1
- New development version 1.51.2
* Tue Feb 21 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.1-2
- Fix BR hwdata-devel for PCI IDs data
* Mon Feb 20 2023 Richard W.M. Jones <rjones@redhat.com> - 1.51.1-1
- New development version 1.51.1
- virt-drivers: Add BuildRequires and runtime Recommends on hwdata.
* Tue Feb 14 2023 Richard W.M. Jones <rjones@redhat.com> - 1.50.0-2
- Remove virt-dib (RHBZ#2169550)
* Tue Feb 07 2023 Richard W.M. Jones <rjones@redhat.com> - 1.50.0-1
- New upstream stable version 1.50.0
* Thu Jan 26 2023 Richard W.M. Jones <rjones@redhat.com> - 1.49.10-1
- New upstream development version 1.49.10
* Thu Jan 19 2023 Richard W.M. Jones <rjones@redhat.com> - 1.49.9-1
- New upstream development version 1.49.9
- New tool: virt-drivers
- Add BR glibc-static for tests on x86_64.
* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 1.49.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
* Tue Jan 17 2023 Richard W.M. Jones <rjones@redhat.com> - 1.49.8-2
- New upstream development version 1.49.8
- +BR libosinfo-devel
* Sat Dec 10 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.7-2
- New upstream development version 1.49.7
* Fri Nov 25 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.6-1
- New upstream development version 1.49.6
- Enable opensuse repository again
* Mon Nov 21 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.5-2
- Disable opensuse repository
* Wed Oct 12 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.5-1
- New upstream development version 1.49.5
* Mon Aug 01 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.4-1
- New upstream development version 1.49.4
* Thu Jul 21 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.49.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_37_Mass_Rebuild
* Fri Jul 01 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.3-1
- New upstream development version 1.49.3
* Thu May 26 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.2-1
- New upstream development version 1.49.2
* Thu May 12 2022 Richard W.M. Jones <rjones@redhat.com> - 1.49.1-1
- New upstream development version 1.49.1
* Mon Mar 14 2022 Richard W.M. Jones <rjones@redhat.com> - 1.48.0-1
- New upstream stable branch version 1.48.0
* Tue Mar 08 2022 Richard W.M. Jones <rjones@redhat.com> - 1.47.5-1
- New upstream development version 1.47.8
- Add new guestfs-tools-release-notes-1.48(1) man page.
* Tue Mar 01 2022 Richard W.M. Jones <rjones@redhat.com> - 1.47.4-1
- New upstream development version 1.47.4
* Thu Jan 20 2022 Fedora Release Engineering <releng@fedoraproject.org> - 1.47.3-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_36_Mass_Rebuild
* Sat Dec 04 2021 Richard W.M. Jones <rjones@redhat.com> - 1.47.3-1
- New upstream development version 1.47.3
* Thu Jul 22 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.47.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_35_Mass_Rebuild
* Wed Jun 16 2021 Richard W.M. Jones <rjones@redhat.com> - 1.47.2-1
- New upstream development version 1.47.2
* Wed Jun 2 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-3
- Add gating tests (for RHEL 9)
* Mon May 17 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-3
- Fix virt-win-reg --version
resolves: rhbz#1961160
* Thu May 13 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-2
- BR perl-generators so deps of virt-win-reg subpackage are correct.
resolves: rhbz#1960191
* Sat May 08 2021 Richard W.M. Jones <rjones@redhat.com> - 1.46.1-1
- New stable branch version 1.46.1.

BIN
libguestfs.keyring Normal file

Binary file not shown.

2
sources Normal file
View File

@ -0,0 +1,2 @@
SHA512 (guestfs-tools-1.54.0.tar.gz) = db76a1cbfaa8b53b5c4609030f545b9d043161cebf54379da6418800086855f11cb3a0e5d135184c2a885094a6a7120155774377a6641a2d7fbd45206ff9ec87
SHA512 (guestfs-tools-1.54.0.tar.gz.sig) = c503f858ba5c2f79814f1f896f41c0b7558cc55534d800bafc2992c929e9a709cb7ab043205a9f5efd2cd9bcbbe3a2273970e116f00ad6625cbb86adaa42accd