From 95db11f02e181a68244b12ae942ed35901e29b2b Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Apr 03 2023 10:51:47 +0000 Subject: - Allow resizing of inactive LVs with latest LVM Resolves: rhbz#2161181 - Fix test_swapon_pagesize on systems with 64k pages Resolves: rhbz#2168220 --- diff --git a/0006-Allow-resizing-of-inactive-LVs-with-latest-LVM.patch b/0006-Allow-resizing-of-inactive-LVs-with-latest-LVM.patch new file mode 100644 index 0000000..194ec15 --- /dev/null +++ b/0006-Allow-resizing-of-inactive-LVs-with-latest-LVM.patch @@ -0,0 +1,219 @@ +From 08d0ab8b93907ed3e2c7588dcaecb76bc4b26055 Mon Sep 17 00:00:00 2001 +From: Vojtech Trefny +Date: Mon, 27 Feb 2023 11:29:29 +0100 +Subject: [PATCH 1/2] Include LVM cli in the LVM DBus plugin dependencies + +Strictly speaking the lvm command is not needed by the plugin, but +the LVM DBus daemon uses it so it must be present on the system +and we are already calling "lvm segtypes" from the plugin so if +the command is not available for us (for example not in $PATH) the +plugin wouldn't load anyway so an extra check isn't going to +change anything. +--- + src/plugins/lvm-dbus.c | 15 ++++++++++++--- + 1 file changed, 12 insertions(+), 3 deletions(-) + +diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c +index d4b542e2..8496a697 100644 +--- a/src/plugins/lvm-dbus.c ++++ b/src/plugins/lvm-dbus.c +@@ -249,11 +249,14 @@ static volatile guint avail_features = 0; + static volatile guint avail_module_deps = 0; + static GMutex deps_check_lock; + +-#define DEPS_LVMDEVICES 0 ++#define DEPS_LVM 0 ++#define DEPS_LVM_MASK (1 << DEPS_LVM) ++#define DEPS_LVMDEVICES 1 + #define DEPS_LVMDEVICES_MASK (1 << DEPS_LVMDEVICES) +-#define DEPS_LAST 1 ++#define DEPS_LAST 2 + + static const UtilDep deps[DEPS_LAST] = { ++ {"lvm", LVM_MIN_VERSION, "version", "LVM version:\\s+([\\d\\.]+)"}, + {"lvmdevices", NULL, NULL, NULL}, + }; + +@@ -2121,6 +2124,7 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si + GVariantBuilder builder; + GVariantType *type = NULL; + GVariant *params = NULL; ++ GVariant *extra_params = NULL; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&builder, g_variant_new ("t", size)); +@@ -2130,7 +2134,12 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si + params = g_variant_builder_end (&builder); + g_variant_builder_clear (&builder); + +- call_lv_method_sync (vg_name, lv_name, "Resize", params, NULL, extra, TRUE, error); ++ g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY); ++ g_variant_builder_add (&builder, "{sv}", "--fs", g_variant_new ("s", "ignore")); ++ extra_params = g_variant_builder_end (&builder); ++ g_variant_builder_clear (&builder); ++ ++ call_lv_method_sync (vg_name, lv_name, "Resize", params, extra_params, extra, TRUE, error); + return (*error == NULL); + } + +-- +2.39.2 + + +From cfb23f424c2f318efea7d9fd60ec1bcdb365ee35 Mon Sep 17 00:00:00 2001 +From: Vojtech Trefny +Date: Mon, 27 Feb 2023 14:00:21 +0100 +Subject: [PATCH 2/2] Allow resizing of inactive LVs with latest LVM + +Latest LVM doesn't allow resizing of inactive LVs without the +"--fs ignore" option to protect users from corrupting their +filesystems. As a low level API we don't really want to offer this +kind of protection and we should allow to resize an inactive LV. +--- + src/plugins/lvm-dbus.c | 28 ++++++++++++++++++++++++---- + src/plugins/lvm.c | 31 ++++++++++++++++++++++++++++--- + tests/lvm_dbus_tests.py | 4 ++++ + tests/lvm_test.py | 4 ++++ + 4 files changed, 60 insertions(+), 7 deletions(-) + +diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c +index 8496a697..28f3bb25 100644 +--- a/src/plugins/lvm-dbus.c ++++ b/src/plugins/lvm-dbus.c +@@ -32,6 +32,8 @@ + #define SECTOR_SIZE 512 + #define VDO_POOL_SUFFIX "vpool" + ++#define LVM_VERSION_FSRESIZE "2.03.19" ++ + static GMutex global_config_lock; + static gchar *global_config_str = NULL; + +@@ -2125,6 +2127,14 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si + GVariantType *type = NULL; + GVariant *params = NULL; + GVariant *extra_params = NULL; ++ gboolean success = FALSE; ++ BDLVMLVdata *lvinfo = NULL; ++ GError *l_error = NULL; ++ ++ lvinfo = bd_lvm_lvinfo (vg_name, lv_name, error); ++ if (!lvinfo) ++ /* error is already populated */ ++ return FALSE; + + g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE); + g_variant_builder_add_value (&builder, g_variant_new ("t", size)); +@@ -2134,10 +2144,20 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si + params = g_variant_builder_end (&builder); + g_variant_builder_clear (&builder); + +- g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY); +- g_variant_builder_add (&builder, "{sv}", "--fs", g_variant_new ("s", "ignore")); +- extra_params = g_variant_builder_end (&builder); +- g_variant_builder_clear (&builder); ++ if (lvinfo->attr[4] != 'a') { ++ /* starting with 2.03.19 we need to add extra option to allow resizing of inactive LVs */ ++ success = bd_utils_check_util_version (deps[DEPS_LVM].name, LVM_VERSION_FSRESIZE, ++ deps[DEPS_LVM].ver_arg, deps[DEPS_LVM].ver_regexp, &l_error); ++ if (success) { ++ g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY); ++ g_variant_builder_add (&builder, "{sv}", "--fs", g_variant_new ("s", "ignore")); ++ extra_params = g_variant_builder_end (&builder); ++ g_variant_builder_clear (&builder); ++ } else ++ g_clear_error (&l_error); ++ } ++ ++ bd_lvm_lvdata_free (lvinfo); + + call_lv_method_sync (vg_name, lv_name, "Resize", params, extra_params, extra, TRUE, error); + return (*error == NULL); +diff --git a/src/plugins/lvm.c b/src/plugins/lvm.c +index 03211f8a..f1e2941b 100644 +--- a/src/plugins/lvm.c ++++ b/src/plugins/lvm.c +@@ -31,6 +31,8 @@ + #define SECTOR_SIZE 512 + #define VDO_POOL_SUFFIX "vpool" + ++#define LVM_VERSION_FSRESIZE "2.03.19" ++ + static GMutex global_config_lock; + static gchar *global_config_str = NULL; + +@@ -1606,15 +1608,38 @@ gboolean bd_lvm_lvrename (const gchar *vg_name, const gchar *lv_name, const gcha + * Tech category: %BD_LVM_TECH_BASIC-%BD_LVM_TECH_MODE_MODIFY + */ + gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 size, const BDExtraArg **extra, GError **error) { +- const gchar *args[6] = {"lvresize", "--force", "-L", NULL, NULL, NULL}; ++ const gchar *args[8] = {"lvresize", "--force", "-L", NULL, NULL, NULL, NULL, NULL}; + gboolean success = FALSE; ++ guint8 next_arg = 4; ++ g_autofree gchar *lvspec = NULL; ++ BDLVMLVdata *lvinfo = NULL; ++ GError *l_error = NULL; ++ ++ lvinfo = bd_lvm_lvinfo (vg_name, lv_name, error); ++ if (!lvinfo) ++ /* error is already populated */ ++ return FALSE; + + args[3] = g_strdup_printf ("%"G_GUINT64_FORMAT"K", size/1024); +- args[4] = g_strdup_printf ("%s/%s", vg_name, lv_name); ++ ++ if (lvinfo->attr[4] != 'a') { ++ /* starting with 2.03.19 we need to add extra option to allow resizing of inactive LVs */ ++ success = bd_utils_check_util_version (deps[DEPS_LVM].name, LVM_VERSION_FSRESIZE, ++ deps[DEPS_LVM].ver_arg, deps[DEPS_LVM].ver_regexp, &l_error); ++ if (success) { ++ args[next_arg++] = "--fs"; ++ args[next_arg++] = "ignore"; ++ } else ++ g_clear_error (&l_error); ++ } ++ ++ bd_lvm_lvdata_free (lvinfo); ++ ++ lvspec = g_strdup_printf ("%s/%s", vg_name, lv_name); ++ args[next_arg++] = lvspec; + + success = call_lvm_and_report_error (args, extra, TRUE, error); + g_free ((gchar *) args[3]); +- g_free ((gchar *) args[4]); + + return success; + } +diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py +index 61c898c1..fc12b55d 100644 +--- a/tests/lvm_dbus_tests.py ++++ b/tests/lvm_dbus_tests.py +@@ -944,6 +944,10 @@ class LvmTestLVresize(LvmPVVGLVTestCase): + succ = BlockDev.lvm_lvdeactivate("testVG", "testLV", None) + self.assertTrue(succ) + ++ # try to resize when deactivated ++ succ = BlockDev.lvm_lvresize("testVG", "testLV", 768 * 1024**2, None) ++ self.assertTrue(succ) ++ + @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running") + class LvmTestLVrename(LvmPVVGLVTestCase): + def test_lvrename(self): +diff --git a/tests/lvm_test.py b/tests/lvm_test.py +index 36ff10ec..7ede4b59 100644 +--- a/tests/lvm_test.py ++++ b/tests/lvm_test.py +@@ -877,6 +877,10 @@ class LvmTestLVresize(LvmPVVGLVTestCase): + succ = BlockDev.lvm_lvdeactivate("testVG", "testLV", None) + self.assertTrue(succ) + ++ # try to resize when deactivated ++ succ = BlockDev.lvm_lvresize("testVG", "testLV", 768 * 1024**2, None) ++ self.assertTrue(succ) ++ + class LvmTestLVrename(LvmPVVGLVTestCase): + def test_lvrename(self): + """Verify that it's possible to rename an LV""" +-- +2.39.2 + diff --git a/0007-tests-Fix-test_swapon_pagesize-on-systems-with-64k-p.patch b/0007-tests-Fix-test_swapon_pagesize-on-systems-with-64k-p.patch new file mode 100644 index 0000000..79e285d --- /dev/null +++ b/0007-tests-Fix-test_swapon_pagesize-on-systems-with-64k-p.patch @@ -0,0 +1,41 @@ +From 2c59bc22d30ebfc16d5d06b1f31c4d7bbede68e9 Mon Sep 17 00:00:00 2001 +From: Vojtech Trefny +Date: Mon, 31 Oct 2022 12:43:17 +0100 +Subject: [PATCH] tests: Fix test_swapon_pagesize on systems with 64k pages + +--- + tests/swap_test.py | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/tests/swap_test.py b/tests/swap_test.py +index 0a0f333d..e350f8e8 100644 +--- a/tests/swap_test.py ++++ b/tests/swap_test.py +@@ -1,5 +1,6 @@ + import unittest + import os ++import resource + import overrides_hack + + from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, run_command, run, TestTags, tag_test +@@ -102,8 +103,15 @@ class SwapTestCase(SwapTest): + def test_swapon_pagesize(self): + """Verify that activating swap with different pagesize fails""" + +- # create swap with 64k pagesize +- ret, out, err = run_command("mkswap --pagesize 65536 %s" % self.loop_dev) ++ # pick some wrong page size: 8k on 64k and 64k everywhere else ++ pagesize = resource.getpagesize() ++ if pagesize == 65536: ++ wrong_pagesize = 8192 ++ else: ++ wrong_pagesize = 65536 ++ ++ # create swap with "wrong" pagesize ++ ret, out, err = run_command("mkswap --pagesize %s %s" % (wrong_pagesize, self.loop_dev)) + if ret != 0: + self.fail("Failed to prepare swap for pagesize test: %s %s" % (out, err)) + +-- +2.39.2 + diff --git a/libblockdev.spec b/libblockdev.spec index 9d01c1e..0f60e38 100644 --- a/libblockdev.spec +++ b/libblockdev.spec @@ -129,7 +129,7 @@ Name: libblockdev Version: 2.28 -Release: 4%{?dist} +Release: 5%{?dist} Summary: A library for low-level manipulation with block devices License: LGPLv2+ URL: https://github.com/storaged-project/libblockdev @@ -140,6 +140,8 @@ Patch2: 0002-Add-support-for-creating-and-activating-integrity-de.patch Patch3: 0003-NVMe-plugin-backport.patch Patch4: 0004-Fix-double-free-in-write_escrow_data_file.patch Patch5: 0005-nvme-Fix-namespace-identifiers.patch +Patch6: 0006-Allow-resizing-of-inactive-LVs-with-latest-LVM.patch +Patch7: 0007-tests-Fix-test_swapon_pagesize-on-systems-with-64k-p.patch BuildRequires: make BuildRequires: glib2-devel @@ -726,6 +728,8 @@ A meta-package that pulls all the libblockdev plugins as dependencies. %patch3 -p1 %patch4 -p1 %patch5 -p1 +%patch6 -p1 +%patch7 -p1 %build autoreconf -ivf @@ -1044,6 +1048,12 @@ find %{buildroot} -type f -name "*.la" | xargs %{__rm} %files plugins-all %changelog +* Mon Apr 03 2023 Vojtech Trefny - 2.28-5 +- Allow resizing of inactive LVs with latest LVM + Resolves: rhbz#2161181 +- Fix test_swapon_pagesize on systems with 64k pages + Resolves: rhbz#2168220 + * Thu Jan 05 2023 Vojtech Trefny - 2.28-4 - nvme: Fix namespace identifiers Resolves: rhbz#2151535