Blame SOURCES/0001-sysprep-remove-lvm2-s-default-system.devices-file.patch

7b180b
From 37c002682a9e5b87d5793f1567c4ddfb8ca72d11 Mon Sep 17 00:00:00 2001
7b180b
From: Laszlo Ersek <lersek@redhat.com>
7b180b
Date: Sun, 10 Apr 2022 13:38:34 +0200
7b180b
Subject: [PATCH] sysprep: remove lvm2's default "system.devices" file
7b180b
7b180b
(Background: lvm2 commit 83fe6e720f42, "device usage based on devices
7b180b
file", 2021-02-23; first released in v2_03_12.)
7b180b
7b180b
"lvm pvscan" may be -- and in RHEL9, will soon be -- restricted to those
7b180b
block devices whose WWIDs are listed in "/etc/lvm/devices/system.devices".
7b180b
This is a problem when cloning a VM, as cloning may change the WWIDs of
7b180b
the domain's disk devices, and then physical volumes underlying the guest
7b180b
filesystems may not be found. Example:
7b180b
<https://bugzilla.redhat.com/show_bug.cgi?id=2059545#c12>.
7b180b
7b180b
Add the "lvm-system-devices" operation for removing this file, so that
7b180b
"lvm pvscan" investigate all block devices for PVs.
7b180b
7b180b
(Note that this operation is independent from "lvm-uuids". The libguestfs
7b180b
appliance creates a pristine LVM_SYSTEM_DIR in "appliance/init" (see
7b180b
libguestfs commit dd162d2cd56a), thus, when "lvm-uuids" calls "g#pvs" and
7b180b
"g#vgs", those APIs can never be affected by an
7b180b
"$LVM_SYSTEM_DIR/devices/system.devices" file.)
7b180b
7b180b
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2072493
7b180b
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
7b180b
Message-Id: <20220410113834.6258-1-lersek@redhat.com>
7b180b
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
7b180b
(cherry picked from commit 4fe8a03cd2d3e4570f4298245bb184ccdc4da0cd)
7b180b
---
7b180b
 sysprep/Makefile.am                           |  1 +
7b180b
 .../sysprep_operation_lvm_system_devices.ml   | 44 +++++++++++++++++++
7b180b
 2 files changed, 45 insertions(+)
7b180b
 create mode 100644 sysprep/sysprep_operation_lvm_system_devices.ml
7b180b
7b180b
diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
7b180b
index 0e3afc8a0..7d5e8aadf 100644
7b180b
--- a/sysprep/Makefile.am
7b180b
+++ b/sysprep/Makefile.am
7b180b
@@ -46,6 +46,7 @@ operations = \
7b180b
 	ipa_client \
7b180b
 	kerberos_data \
7b180b
 	kerberos_hostkeytab \
7b180b
+	lvm_system_devices \
7b180b
 	lvm_uuids \
7b180b
 	logfiles \
7b180b
 	machine_id \
7b180b
diff --git a/sysprep/sysprep_operation_lvm_system_devices.ml b/sysprep/sysprep_operation_lvm_system_devices.ml
7b180b
new file mode 100644
7b180b
index 000000000..b41fa5dbc
7b180b
--- /dev/null
7b180b
+++ b/sysprep/sysprep_operation_lvm_system_devices.ml
7b180b
@@ -0,0 +1,44 @@
7b180b
+(* virt-sysprep
7b180b
+ * Copyright (C) 2012-2022 Red Hat Inc.
7b180b
+ *
7b180b
+ * This program is free software; you can redistribute it and/or modify
7b180b
+ * it under the terms of the GNU General Public License as published by
7b180b
+ * the Free Software Foundation; either version 2 of the License, or
7b180b
+ * (at your option) any later version.
7b180b
+ *
7b180b
+ * This program is distributed in the hope that it will be useful,
7b180b
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
7b180b
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
7b180b
+ * GNU General Public License for more details.
7b180b
+ *
7b180b
+ * You should have received a copy of the GNU General Public License along
7b180b
+ * with this program; if not, write to the Free Software Foundation, Inc.,
7b180b
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
7b180b
+ *)
7b180b
+
7b180b
+open Sysprep_operation
7b180b
+open Common_gettext.Gettext
7b180b
+
7b180b
+module G = Guestfs
7b180b
+
7b180b
+let system_devices_file = "/etc/lvm/devices/system.devices"
7b180b
+
7b180b
+let rec lvm_system_devices_perform g root side_effects =
7b180b
+  let typ = g#inspect_get_type root in
7b180b
+  if typ = "linux" then g#rm_f system_devices_file
7b180b
+
7b180b
+let op = {
7b180b
+  defaults with
7b180b
+    name = "lvm-system-devices";
7b180b
+    enabled_by_default = true;
7b180b
+    heading = s_"Remove LVM2 system.devices file";
7b180b
+    pod_description =
7b180b
+      Some (s_"On Linux guests, LVM2's scanning for physical volumes (PVs) may \
7b180b
+               be restricted to those block devices whose WWIDs are listed in \
7b180b
+               C<" ^ system_devices_file ^ ">.  When cloning VMs, WWIDs may \
7b180b
+               change, breaking C<lvm pvscan>.  Remove \
7b180b
+               C<" ^ system_devices_file ^ ">.");
7b180b
+    perform_on_filesystems = Some lvm_system_devices_perform;
7b180b
+}
7b180b
+
7b180b
+let () = register_operation op
7b180b
-- 
7b180b
2.31.1
7b180b