[Libguestfs] [guestfs-tools PATCH] sysprep: remove lvm2's default "system.devices" file

Richard W.M. Jones
Mon, 11 Apr 2022 07:58:56 -0000

On Sun, Apr 10, 2022 at 01:38:34PM +0200, Laszlo Ersek
wrote:
> (Background: lvm2 commit 83fe6e720f42, "device usage based on devices
> file", 2021-02-23; first released in v2_03_12.)
>
> "lvm pvscan" may be -- and in RHEL9, will soon be -- restricted
to those
> block devices whose WWIDs are listed in
"/etc/lvm/devices/system.devices".
> This is a problem when cloning a VM, as cloning may change the WWIDs of
> the domain's disk devices, and then physical volumes underlying the
guest
> filesystems may not be found. Example:
> <https://bugzilla.redhat.com/show_bug.cgi?id=2059545#c12>.
>
> Add the "lvm-system-devices" operation for removing this file, so
that
> "lvm pvscan" investigate all block devices for PVs.
>
> (Note that this operation is independent from "lvm-uuids". The
libguestfs
> appliance creates a pristine LVM_SYSTEM_DIR in "appliance/init"
(see
> libguestfs commit dd162d2cd56a), thus, when "lvm-uuids" calls
"g#pvs" and
> "g#vgs", those APIs can never be affected by an
> "$LVM_SYSTEM_DIR/devices/system.devices" file.)
>
> Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2072493
> Signed-off-by: Laszlo Ersek <lersek at redhat.com>
> ---
>  sysprep/Makefile.am                             |  1 +
>  sysprep/sysprep_operation_lvm_system_devices.ml | 44 ++++++++++++++++++++
>  2 files changed, 45 insertions(+)
>
> diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
> index 0e3afc8a01c7..7d5e8aadf448 100644
> --- a/sysprep/Makefile.am
> +++ b/sysprep/Makefile.am
> @@ -46,6 +46,7 @@ operations = \
>  	ipa_client \
>  	kerberos_data \
>  	kerberos_hostkeytab \
> +	lvm_system_devices \
>  	lvm_uuids \
>  	logfiles \
>  	machine_id \
> diff --git a/sysprep/sysprep_operation_lvm_system_devices.ml
b/sysprep/sysprep_operation_lvm_system_devices.ml
> new file mode 100644
> index 000000000000..b41fa5dbc23a
> --- /dev/null
> +++ b/sysprep/sysprep_operation_lvm_system_devices.ml
> @@ -0,0 +1,44 @@
> +(* virt-sysprep
> + * Copyright (C) 2012-2022 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 Sysprep_operation
> +open Common_gettext.Gettext
> +
> +module G = Guestfs
> +
> +let system_devices_file = "/etc/lvm/devices/system.devices"
> +
> +let rec lvm_system_devices_perform g root side_effects > +  let typ =
g#inspect_get_type root in
> +  if typ = "linux" then g#rm_f system_devices_file
> +
> +let op = {
> +  defaults with
> +    name = "lvm-system-devices";
> +    enabled_by_default = true;
> +    heading = s_"Remove LVM2 system.devices file";
> +    pod_description > +      Some (s_"On Linux guests, LVM2's
scanning for physical volumes (PVs) may \
> +               be restricted to those block devices whose WWIDs are listed
in \
> +               C<" ^ system_devices_file ^ ">.  When
cloning VMs, WWIDs may \
> +               change, breaking C<lvm pvscan>.  Remove \
> +               C<" ^ system_devices_file ^ ">.");
> +    perform_on_filesystems = Some lvm_system_devices_perform;
> +}
> +
> +let () = register_operation op

It wasn't clear from the bug description if we have to remove only
/etc/lvm/devices/system.devices or /etc/lvm/devices/*, but assuming
it's the first one then this patch looks fine to me.

Reviewed-by: Richard W.M. Jones <rjones at redhat.com>

Rich.

--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
nbdkit - Flexible, fast NBD server with plugins