Skip to content

Commit 98d7f32

Browse files
BrooklynDewolfsandrobonazzola
authored andcommitted
storage: add --fs ignore to lvreduce on lvm > 2.03.17
Since LVM v2.03.17 (lvmteam/lvm2@f6f2737), 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 already handles checksize, making lvreduce redundant. Signed-off-by: Brooklyn Dewolf <[email protected]>
1 parent ade627e commit 98d7f32

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

lib/vdsm/osinfo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ def package_versions():
248248
'qemu-kvm': ('qemu-kvm', 'qemu-kvm-rhev', 'qemu-kvm-ev'),
249249
'spice-server': ('spice-server',),
250250
'vdsm': ('vdsm',),
251+
'lvm2': ('lvm2', 'lvm2-libs'),
251252
}
252253

253254
if glusterEnabled:
@@ -281,6 +282,7 @@ def package_versions():
281282
'qemu-kvm': 'qemu-kvm',
282283
'spice-server': 'libspice-server1',
283284
'vdsm': 'vdsmd',
285+
'lvm2': 'lvm2',
284286
}
285287

286288
if glusterEnabled:

lib/vdsm/storage/lvm.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from itertools import chain
2323

2424
from vdsm import constants
25+
from vdsm import osinfo
2526
from vdsm import utils
2627
from vdsm.common import commands
2728
from vdsm.common import errors
@@ -240,6 +241,15 @@ def __getattr__(self, attrName):
240241
USE_DEVICES = config.get("lvm", "config_method").lower() == "devices"
241242

242243

244+
def _get_lvm_version():
245+
packages = osinfo.package_versions()
246+
lvm_version = tuple(
247+
int(v)
248+
for v in packages['lvm2']['version'].split('.')
249+
)
250+
return lvm_version
251+
252+
243253
def _prepare_device_set(devs):
244254
devices = set(d.strip() for d in chain(devs, USER_DEV_LIST))
245255
devices.discard('')
@@ -1781,11 +1791,14 @@ def extendLV(vgName, lvName, size_mb, refresh=True):
17811791

17821792

17831793
def reduceLV(vgName, lvName, size_mb, force=False):
1794+
lvm_version = _get_lvm_version()
17841795
log.info("Reducing LV %s/%s to %s megabytes (force=%s)",
17851796
vgName, lvName, size_mb, force)
17861797
cmd = ("lvreduce",) + LVM_NOBACKUP
17871798
if force:
17881799
cmd += ("--force",)
1800+
if lvm_version >= (2, 3, 17):
1801+
cmd += ("--fs", "ignore")
17891802
cmd += ("--size", "%sm" % (size_mb,), "%s/%s" % (vgName, lvName))
17901803

17911804
try:

tests/lib/osinfo_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def test_kernel_args(test_input, expected_result):
3636
def test_package_versions():
3737
pkgs = osinfo.package_versions()
3838
assert 'kernel' in pkgs
39+
assert 'lvm2' in pkgs
3940

4041

4142
def test_get_boot_uuid(fake_findmnt):

tests/storage/lvm_test.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import uuid
1010

1111
import pytest
12+
from unittest import mock
1213

1314
from vdsm.common import commands
1415
from vdsm.common import concurrent
@@ -1776,6 +1777,27 @@ def test_lv_extend_reduce(tmp_storage):
17761777
assert int(lv.size) == 1 * GiB
17771778

17781779

1780+
@pytest.mark.parametrize("lvm_version, expected_cmd", [
1781+
((2, 3, 16), ("lvreduce", "--autobackup", "n", "--size",
1782+
"100m", "vg/lv")),
1783+
((2, 3, 17), ("lvreduce", "--autobackup", "n", "--fs", "ignore", "--size",
1784+
"100m", "vg/lv"))
1785+
])
1786+
def test_reducelv_with_different_lvm_versions(lvm_version, expected_cmd):
1787+
with mock.patch.object(lvm, "_get_lvm_version",
1788+
return_value=lvm_version), \
1789+
mock.patch.object(lvm._lvminfo,
1790+
"run_command") as mock_run_command, \
1791+
mock.patch.object(lvm._lvminfo, "_invalidatevgs"), \
1792+
mock.patch.object(lvm._lvminfo, "_invalidatelvs"):
1793+
1794+
lvm.reduceLV("vg", "lv", 100)
1795+
1796+
mock_run_command.assert_called_once_with(
1797+
expected_cmd, devices=mock.ANY
1798+
)
1799+
1800+
17791801
@requires_root
17801802
@pytest.mark.root
17811803
def test_lv_extend_with_refresh(tmp_storage):

0 commit comments

Comments
 (0)