Fix lvm-set-filter failed in guestfish with the latest lvm2 package

resolves: rhbz#1965941
This commit is contained in:
Richard W.M. Jones 2022-06-13 14:23:57 +01:00
parent 3189d98758
commit 86277c2cc0
2 changed files with 124 additions and 2 deletions

View File

@ -0,0 +1,119 @@
From 20eb220c0b1c8a7aaaadcc26fe5fdeae681341b4 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Mon, 30 May 2022 16:10:27 +0200
Subject: [PATCH] appliance, daemon: disable lvm2 devicesfile
In guestfs-tools commit 4fe8a03cd2d3 ('sysprep: remove lvm2's default
"system.devices" file', 2022-04-11), we disabled the use of LVM2's new
"devicesfile" feature, which could interfere with the cloning of virtual
machines.
We suspected in
https://bugzilla.redhat.com/show_bug.cgi?id=2072493#c6
that the same lvm2 feature could affect the libguestfs appliance itself,
but decided in
https://bugzilla.redhat.com/show_bug.cgi?id=2072493#c8
https://bugzilla.redhat.com/show_bug.cgi?id=2072493#c10
that this would not be the case, because "appliance/init" already
constructed a pristine LVM_SYSTEM_DIR.
Unfortunately, that's not enough: due to the "use_devicesfile=1" default
(on RHEL9 anyway), some "lvm" invocation, possibly inside the
lvm-set-filter API, *creates* "$LVM_SYSTEM_DIR/devices/system.devices".
And then we get (minimally) warnings such as
> Please remove the lvm.conf global_filter, it is ignored with the devices
> file.
> Please remove the lvm.conf filter, it is ignored with the devices file.
when using the lvm-set-filter API.
Explicitly disable the "devices file" in "appliance/init", and also
whenever we rewrite "lvm.conf" -- that is, in set_filter()
[daemon/lvm-filter.c]. In the former, check for the feature by locating
the devicesfile-related utilities "lvmdevices" and "vgimportdevices". In
the C code, invoke the utilities with the "--help" option instead. (In
"appliance/init", I thought it was best not to call any lvm2 utilities
even with "--help", with our lvm2.conf still under construction there.) If
either utility is available, set "use_devicesfile = 0".
Cc: David Teigland <teigland@redhat.com>
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1965941
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20220530141027.16167-1-lersek@redhat.com>
Acked-by: Richard W.M. Jones <rjones@redhat.com>
[lersek@redhat.com: style fix: break "devicesfile_feature" in the function
definition to a new line]
(cherry picked from commit 8fc4d167153a23ab91befafb2f7083db2d312ef8)
---
appliance/init | 11 +++++++++++
daemon/lvm-filter.c | 20 ++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/appliance/init b/appliance/init
index fe6497b4d..e67d88280 100755
--- a/appliance/init
+++ b/appliance/init
@@ -142,6 +142,17 @@ mdadm -As --auto=yes --no-degraded
# Empty LVM configuration file means "all defaults".
mkdir -p /tmp/lvm
touch /tmp/lvm/lvm.conf
+
+# If lvm2 supports a "devices file", we need to disable its use
+# (RHBZ#1965941).
+if command -v lvmdevices || command -v vgimportdevices; then
+ {
+ printf 'devices {\n'
+ printf '\tuse_devicesfile = 0\n'
+ printf '}\n'
+ } >> /tmp/lvm/lvm.conf
+fi
+
LVM_SYSTEM_DIR=/tmp/lvm
export LVM_SYSTEM_DIR
lvmetad
diff --git a/daemon/lvm-filter.c b/daemon/lvm-filter.c
index c6dd35156..00b36f826 100644
--- a/daemon/lvm-filter.c
+++ b/daemon/lvm-filter.c
@@ -68,6 +68,19 @@ free_lvm_system_dir (void)
free (lvm_system_dir);
}
+static bool
+devicesfile_feature (void)
+{
+ static bool checked, available;
+
+ if (!checked) {
+ checked = true;
+ available = command (NULL, NULL, "lvmdevices", "--help", NULL) == 0 ||
+ command (NULL, NULL, "vgimportdevices", "--help", NULL) == 0;
+ }
+ return available;
+}
+
/* Rewrite the 'filter = [ ... ]' line in lvm.conf. */
static int
set_filter (char *const *filters)
@@ -88,6 +101,13 @@ set_filter (char *const *filters)
}
fprintf (fp, "devices {\n");
+
+ /* If lvm2 supports a "devices file", we need to disable its use
+ * (RHBZ#1965941).
+ */
+ if (devicesfile_feature ())
+ fprintf (fp, " use_devicesfile = 0\n");
+
for (j = 0; filter_types[j] != NULL; ++j) {
fprintf (fp, " %s = [\n", filter_types[j]);
fprintf (fp, " ");
--
2.31.1

View File

@ -48,7 +48,7 @@ Summary: Access and modify virtual machine disk images
Name: libguestfs Name: libguestfs
Epoch: 1 Epoch: 1
Version: 1.48.3 Version: 1.48.3
Release: 1%{?dist} Release: 2%{?dist}
License: LGPLv2+ License: LGPLv2+
# Build only for architectures that have a kernel # Build only for architectures that have a kernel
@ -105,6 +105,7 @@ Patch0012: 0012-RHEL-Disable-unsupported-remote-drive-protocols-RHBZ.patch
Patch0013: 0013-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch Patch0013: 0013-RHEL-Reject-use-of-libguestfs-winsupport-features-ex.patch
Patch0014: 0014-RHEL-Create-etc-crypto-policies-back-ends-opensslcnf.patch Patch0014: 0014-RHEL-Create-etc-crypto-policies-back-ends-opensslcnf.patch
Patch0015: 0015-build-Pick-first-field-in-ID_LIKE.patch Patch0015: 0015-build-Pick-first-field-in-ID_LIKE.patch
Patch0016: 0016-appliance-daemon-disable-lvm2-devicesfile.patch
%if 0%{patches_touch_autotools} %if 0%{patches_touch_autotools}
BuildRequires: autoconf, automake, libtool, gettext-devel BuildRequires: autoconf, automake, libtool, gettext-devel
@ -1148,7 +1149,7 @@ rm ocaml/html/.gitignore
%changelog %changelog
* Thu May 26 2022 Richard W.M. Jones <rjones@redhat.com> - 1:1.48.3-1 * Mon Jun 13 2022 Richard W.M. Jones <rjones@redhat.com> - 1:1.48.3-2
- Rebase to new stable branch version 1.48.3 - Rebase to new stable branch version 1.48.3
resolves: rhbz#2059285 resolves: rhbz#2059285
- Disable 5-level page tables when using -cpu max - Disable 5-level page tables when using -cpu max
@ -1162,6 +1163,8 @@ rm ocaml/html/.gitignore
- Check return values from librpm calls (2089623) - Check return values from librpm calls (2089623)
- Document limitations of encrypted RBD disks - Document limitations of encrypted RBD disks
resolves: rhbz#2033247 resolves: rhbz#2033247
- Fix lvm-set-filter failed in guestfish with the latest lvm2 package
resolves: rhbz#1965941
* Thu Mar 17 2022 Richard W.M. Jones <rjones@redhat.com> - 1:1.48.0-2 * Thu Mar 17 2022 Richard W.M. Jones <rjones@redhat.com> - 1:1.48.0-2
- Disable signature checking in librpm - Disable signature checking in librpm