From 829f0e3a5753c372c0fdcc81768bcdfcc7b29dae Mon Sep 17 00:00:00 2001 From: Brooklyn Dewolf Date: Thu, 23 May 2024 09:56:11 +0200 Subject: [PATCH] Skip LVM Filesystem Check on Volume Reduction Since LVM v2.03.17 (https://github.com/lvmteam/lvm2/commit/f6f2737015746b1b6c7fbd0d297a4596c584749b), reducing a logical volume (LV) requires the LV to be active due to the default 'checksize' option, which requires an active LV. This results in the following error when attempting to reduce a non-active LV: ---- err=[\' The LV must be active to safely reduce (see --fs options.)\']' ---- To resolve this, we now check if the LVM version is newer than 2.03.17. If so, we bypass the 'checksize' by using the '--fs ignore' option. This approach is viable because the oVirt engine already handles checksize, making lvreduce redundant. Signed-off-by: Brooklyn Dewolf --- lib/vdsm/osinfo.py | 2 ++ lib/vdsm/storage/lvm.py | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/vdsm/osinfo.py b/lib/vdsm/osinfo.py index be404f575..fb158fb31 100644 --- a/lib/vdsm/osinfo.py +++ b/lib/vdsm/osinfo.py @@ -248,6 +248,7 @@ def package_versions(): 'qemu-kvm': ('qemu-kvm', 'qemu-kvm-rhev', 'qemu-kvm-ev'), 'spice-server': ('spice-server',), 'vdsm': ('vdsm',), + 'lvm2': ('lvm2', 'lvm2-libs'), } if glusterEnabled: @@ -281,6 +282,7 @@ def package_versions(): 'qemu-kvm': 'qemu-kvm', 'spice-server': 'libspice-server1', 'vdsm': 'vdsmd', + 'lvm2': 'lvm2', } if glusterEnabled: diff --git a/lib/vdsm/storage/lvm.py b/lib/vdsm/storage/lvm.py index 38d212c58..35933a580 100644 --- a/lib/vdsm/storage/lvm.py +++ b/lib/vdsm/storage/lvm.py @@ -23,6 +23,7 @@ from vdsm import constants from vdsm import utils +from vdsm import osinfo from vdsm.common import commands from vdsm.common import errors from vdsm.common import logutils @@ -240,6 +241,15 @@ def __getattr__(self, attrName): USE_DEVICES = config.get("lvm", "config_method").lower() == "devices" +def _get_lvm_version(): + packages = osinfo.package_versions() + lvm_version = tuple( + int(v) + for v in packages['lvm2']['version'].split('.') + ) + return lvm_version + + def _prepare_device_set(devs): devices = set(d.strip() for d in chain(devs, USER_DEV_LIST)) devices.discard('') @@ -1781,12 +1791,15 @@ def extendLV(vgName, lvName, size_mb, refresh=True): def reduceLV(vgName, lvName, size_mb, force=False): + lvm_version = _get_lvm_version() log.info("Reducing LV %s/%s to %s megabytes (force=%s)", vgName, lvName, size_mb, force) cmd = ("lvreduce",) + LVM_NOBACKUP if force: cmd += ("--force",) cmd += ("--size", "%sm" % (size_mb,), "%s/%s" % (vgName, lvName)) + if lvm_version >= (2, 3, 17): + cmd += ("--fs", "ignore") try: _lvminfo.run_command(cmd, devices=_lvminfo._getVGDevs((vgName,)))