Blame 0006-Allow-resizing-of-inactive-LVs-with-latest-LVM.patch

Vojtech Trefny 95db11
From 08d0ab8b93907ed3e2c7588dcaecb76bc4b26055 Mon Sep 17 00:00:00 2001
Vojtech Trefny 95db11
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 95db11
Date: Mon, 27 Feb 2023 11:29:29 +0100
Vojtech Trefny 95db11
Subject: [PATCH 1/2] Include LVM cli in the LVM DBus plugin dependencies
Vojtech Trefny 95db11
Vojtech Trefny 95db11
Strictly speaking the lvm command is not needed by the plugin, but
Vojtech Trefny 95db11
the LVM DBus daemon uses it so it must be present on the system
Vojtech Trefny 95db11
and we are already calling "lvm segtypes" from the plugin so if
Vojtech Trefny 95db11
the command is not available for us (for example not in $PATH) the
Vojtech Trefny 95db11
plugin wouldn't load anyway so an extra check isn't going to
Vojtech Trefny 95db11
change anything.
Vojtech Trefny 95db11
---
Vojtech Trefny 95db11
 src/plugins/lvm-dbus.c | 15 ++++++++++++---
Vojtech Trefny 95db11
 1 file changed, 12 insertions(+), 3 deletions(-)
Vojtech Trefny 95db11
Vojtech Trefny 95db11
diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c
Vojtech Trefny 95db11
index d4b542e2..8496a697 100644
Vojtech Trefny 95db11
--- a/src/plugins/lvm-dbus.c
Vojtech Trefny 95db11
+++ b/src/plugins/lvm-dbus.c
Vojtech Trefny 95db11
@@ -249,11 +249,14 @@ static volatile guint avail_features = 0;
Vojtech Trefny 95db11
 static volatile guint avail_module_deps = 0;
Vojtech Trefny 95db11
 static GMutex deps_check_lock;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
-#define DEPS_LVMDEVICES 0
Vojtech Trefny 95db11
+#define DEPS_LVM 0
Vojtech Trefny 95db11
+#define DEPS_LVM_MASK (1 << DEPS_LVM)
Vojtech Trefny 95db11
+#define DEPS_LVMDEVICES 1
Vojtech Trefny 95db11
 #define DEPS_LVMDEVICES_MASK (1 << DEPS_LVMDEVICES)
Vojtech Trefny 95db11
-#define DEPS_LAST 1
Vojtech Trefny 95db11
+#define DEPS_LAST 2
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
 static const UtilDep deps[DEPS_LAST] = {
Vojtech Trefny 95db11
+    {"lvm", LVM_MIN_VERSION, "version", "LVM version:\\s+([\\d\\.]+)"},
Vojtech Trefny 95db11
     {"lvmdevices", NULL, NULL, NULL},
Vojtech Trefny 95db11
 };
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
@@ -2121,6 +2124,7 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si
Vojtech Trefny 95db11
     GVariantBuilder builder;
Vojtech Trefny 95db11
     GVariantType *type = NULL;
Vojtech Trefny 95db11
     GVariant *params = NULL;
Vojtech Trefny 95db11
+    GVariant *extra_params = NULL;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
     g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
Vojtech Trefny 95db11
     g_variant_builder_add_value (&builder, g_variant_new ("t", size));
Vojtech Trefny 95db11
@@ -2130,7 +2134,12 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si
Vojtech Trefny 95db11
     params = g_variant_builder_end (&builder);
Vojtech Trefny 95db11
     g_variant_builder_clear (&builder);
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
-    call_lv_method_sync (vg_name, lv_name, "Resize", params, NULL, extra, TRUE, error);
Vojtech Trefny 95db11
+    g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY);
Vojtech Trefny 95db11
+    g_variant_builder_add (&builder, "{sv}", "--fs", g_variant_new ("s", "ignore"));
Vojtech Trefny 95db11
+    extra_params = g_variant_builder_end (&builder);
Vojtech Trefny 95db11
+    g_variant_builder_clear (&builder);
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    call_lv_method_sync (vg_name, lv_name, "Resize", params, extra_params, extra, TRUE, error);
Vojtech Trefny 95db11
     return (*error == NULL);
Vojtech Trefny 95db11
 }
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
-- 
Vojtech Trefny 95db11
2.39.2
Vojtech Trefny 95db11
Vojtech Trefny 95db11
Vojtech Trefny 95db11
From cfb23f424c2f318efea7d9fd60ec1bcdb365ee35 Mon Sep 17 00:00:00 2001
Vojtech Trefny 95db11
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny 95db11
Date: Mon, 27 Feb 2023 14:00:21 +0100
Vojtech Trefny 95db11
Subject: [PATCH 2/2] Allow resizing of inactive LVs with latest LVM
Vojtech Trefny 95db11
Vojtech Trefny 95db11
Latest LVM doesn't allow resizing of inactive LVs without the
Vojtech Trefny 95db11
"--fs ignore" option to protect users from corrupting their
Vojtech Trefny 95db11
filesystems. As a low level API we don't really want to offer this
Vojtech Trefny 95db11
kind of protection and we should allow to resize an inactive LV.
Vojtech Trefny 95db11
---
Vojtech Trefny 95db11
 src/plugins/lvm-dbus.c  | 28 ++++++++++++++++++++++++----
Vojtech Trefny 95db11
 src/plugins/lvm.c       | 31 ++++++++++++++++++++++++++++---
Vojtech Trefny 95db11
 tests/lvm_dbus_tests.py |  4 ++++
Vojtech Trefny 95db11
 tests/lvm_test.py       |  4 ++++
Vojtech Trefny 95db11
 4 files changed, 60 insertions(+), 7 deletions(-)
Vojtech Trefny 95db11
Vojtech Trefny 95db11
diff --git a/src/plugins/lvm-dbus.c b/src/plugins/lvm-dbus.c
Vojtech Trefny 95db11
index 8496a697..28f3bb25 100644
Vojtech Trefny 95db11
--- a/src/plugins/lvm-dbus.c
Vojtech Trefny 95db11
+++ b/src/plugins/lvm-dbus.c
Vojtech Trefny 95db11
@@ -32,6 +32,8 @@
Vojtech Trefny 95db11
 #define SECTOR_SIZE 512
Vojtech Trefny 95db11
 #define VDO_POOL_SUFFIX "vpool"
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
+#define LVM_VERSION_FSRESIZE "2.03.19"
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
 static GMutex global_config_lock;
Vojtech Trefny 95db11
 static gchar *global_config_str = NULL;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
@@ -2125,6 +2127,14 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si
Vojtech Trefny 95db11
     GVariantType *type = NULL;
Vojtech Trefny 95db11
     GVariant *params = NULL;
Vojtech Trefny 95db11
     GVariant *extra_params = NULL;
Vojtech Trefny 95db11
+    gboolean success = FALSE;
Vojtech Trefny 95db11
+    BDLVMLVdata *lvinfo = NULL;
Vojtech Trefny 95db11
+    GError *l_error = NULL;
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    lvinfo = bd_lvm_lvinfo (vg_name, lv_name, error);
Vojtech Trefny 95db11
+    if (!lvinfo)
Vojtech Trefny 95db11
+        /* error is already populated */
Vojtech Trefny 95db11
+        return FALSE;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
     g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
Vojtech Trefny 95db11
     g_variant_builder_add_value (&builder, g_variant_new ("t", size));
Vojtech Trefny 95db11
@@ -2134,10 +2144,20 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si
Vojtech Trefny 95db11
     params = g_variant_builder_end (&builder);
Vojtech Trefny 95db11
     g_variant_builder_clear (&builder);
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
-    g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY);
Vojtech Trefny 95db11
-    g_variant_builder_add (&builder, "{sv}", "--fs", g_variant_new ("s", "ignore"));
Vojtech Trefny 95db11
-    extra_params = g_variant_builder_end (&builder);
Vojtech Trefny 95db11
-    g_variant_builder_clear (&builder);
Vojtech Trefny 95db11
+    if (lvinfo->attr[4] != 'a') {
Vojtech Trefny 95db11
+        /* starting with 2.03.19 we need to add extra option to allow resizing of inactive LVs */
Vojtech Trefny 95db11
+        success = bd_utils_check_util_version (deps[DEPS_LVM].name, LVM_VERSION_FSRESIZE,
Vojtech Trefny 95db11
+                                            deps[DEPS_LVM].ver_arg, deps[DEPS_LVM].ver_regexp, &l_error);
Vojtech Trefny 95db11
+        if (success) {
Vojtech Trefny 95db11
+            g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY);
Vojtech Trefny 95db11
+            g_variant_builder_add (&builder, "{sv}", "--fs", g_variant_new ("s", "ignore"));
Vojtech Trefny 95db11
+            extra_params = g_variant_builder_end (&builder);
Vojtech Trefny 95db11
+            g_variant_builder_clear (&builder);
Vojtech Trefny 95db11
+        } else
Vojtech Trefny 95db11
+            g_clear_error (&l_error);
Vojtech Trefny 95db11
+    }
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    bd_lvm_lvdata_free (lvinfo);
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
     call_lv_method_sync (vg_name, lv_name, "Resize", params, extra_params, extra, TRUE, error);
Vojtech Trefny 95db11
     return (*error == NULL);
Vojtech Trefny 95db11
diff --git a/src/plugins/lvm.c b/src/plugins/lvm.c
Vojtech Trefny 95db11
index 03211f8a..f1e2941b 100644
Vojtech Trefny 95db11
--- a/src/plugins/lvm.c
Vojtech Trefny 95db11
+++ b/src/plugins/lvm.c
Vojtech Trefny 95db11
@@ -31,6 +31,8 @@
Vojtech Trefny 95db11
 #define SECTOR_SIZE 512
Vojtech Trefny 95db11
 #define VDO_POOL_SUFFIX "vpool"
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
+#define LVM_VERSION_FSRESIZE "2.03.19"
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
 static GMutex global_config_lock;
Vojtech Trefny 95db11
 static gchar *global_config_str = NULL;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
@@ -1606,15 +1608,38 @@ gboolean bd_lvm_lvrename (const gchar *vg_name, const gchar *lv_name, const gcha
Vojtech Trefny 95db11
  * Tech category: %BD_LVM_TECH_BASIC-%BD_LVM_TECH_MODE_MODIFY
Vojtech Trefny 95db11
  */
Vojtech Trefny 95db11
 gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 size, const BDExtraArg **extra, GError **error) {
Vojtech Trefny 95db11
-    const gchar *args[6] = {"lvresize", "--force", "-L", NULL, NULL, NULL};
Vojtech Trefny 95db11
+    const gchar *args[8] = {"lvresize", "--force", "-L", NULL, NULL, NULL, NULL, NULL};
Vojtech Trefny 95db11
     gboolean success = FALSE;
Vojtech Trefny 95db11
+    guint8 next_arg = 4;
Vojtech Trefny 95db11
+    g_autofree gchar *lvspec = NULL;
Vojtech Trefny 95db11
+    BDLVMLVdata *lvinfo = NULL;
Vojtech Trefny 95db11
+    GError *l_error = NULL;
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    lvinfo = bd_lvm_lvinfo (vg_name, lv_name, error);
Vojtech Trefny 95db11
+    if (!lvinfo)
Vojtech Trefny 95db11
+        /* error is already populated */
Vojtech Trefny 95db11
+        return FALSE;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
     args[3] = g_strdup_printf ("%"G_GUINT64_FORMAT"K", size/1024);
Vojtech Trefny 95db11
-    args[4] = g_strdup_printf ("%s/%s", vg_name, lv_name);
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    if (lvinfo->attr[4] != 'a') {
Vojtech Trefny 95db11
+        /* starting with 2.03.19 we need to add extra option to allow resizing of inactive LVs */
Vojtech Trefny 95db11
+        success = bd_utils_check_util_version (deps[DEPS_LVM].name, LVM_VERSION_FSRESIZE,
Vojtech Trefny 95db11
+                                               deps[DEPS_LVM].ver_arg, deps[DEPS_LVM].ver_regexp, &l_error);
Vojtech Trefny 95db11
+        if (success) {
Vojtech Trefny 95db11
+            args[next_arg++] = "--fs";
Vojtech Trefny 95db11
+            args[next_arg++] = "ignore";
Vojtech Trefny 95db11
+        } else
Vojtech Trefny 95db11
+            g_clear_error (&l_error);
Vojtech Trefny 95db11
+    }
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    bd_lvm_lvdata_free (lvinfo);
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
+    lvspec = g_strdup_printf ("%s/%s", vg_name, lv_name);
Vojtech Trefny 95db11
+    args[next_arg++] = lvspec;
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
     success = call_lvm_and_report_error (args, extra, TRUE, error);
Vojtech Trefny 95db11
     g_free ((gchar *) args[3]);
Vojtech Trefny 95db11
-    g_free ((gchar *) args[4]);
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
     return success;
Vojtech Trefny 95db11
 }
Vojtech Trefny 95db11
diff --git a/tests/lvm_dbus_tests.py b/tests/lvm_dbus_tests.py
Vojtech Trefny 95db11
index 61c898c1..fc12b55d 100644
Vojtech Trefny 95db11
--- a/tests/lvm_dbus_tests.py
Vojtech Trefny 95db11
+++ b/tests/lvm_dbus_tests.py
Vojtech Trefny 95db11
@@ -944,6 +944,10 @@ class LvmTestLVresize(LvmPVVGLVTestCase):
Vojtech Trefny 95db11
         succ = BlockDev.lvm_lvdeactivate("testVG", "testLV", None)
Vojtech Trefny 95db11
         self.assertTrue(succ)
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
+        # try to resize when deactivated
Vojtech Trefny 95db11
+        succ = BlockDev.lvm_lvresize("testVG", "testLV", 768 * 1024**2, None)
Vojtech Trefny 95db11
+        self.assertTrue(succ)
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
 @unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
Vojtech Trefny 95db11
 class LvmTestLVrename(LvmPVVGLVTestCase):
Vojtech Trefny 95db11
     def test_lvrename(self):
Vojtech Trefny 95db11
diff --git a/tests/lvm_test.py b/tests/lvm_test.py
Vojtech Trefny 95db11
index 36ff10ec..7ede4b59 100644
Vojtech Trefny 95db11
--- a/tests/lvm_test.py
Vojtech Trefny 95db11
+++ b/tests/lvm_test.py
Vojtech Trefny 95db11
@@ -877,6 +877,10 @@ class LvmTestLVresize(LvmPVVGLVTestCase):
Vojtech Trefny 95db11
         succ = BlockDev.lvm_lvdeactivate("testVG", "testLV", None)
Vojtech Trefny 95db11
         self.assertTrue(succ)
Vojtech Trefny 95db11
 
Vojtech Trefny 95db11
+        # try to resize when deactivated
Vojtech Trefny 95db11
+        succ = BlockDev.lvm_lvresize("testVG", "testLV", 768 * 1024**2, None)
Vojtech Trefny 95db11
+        self.assertTrue(succ)
Vojtech Trefny 95db11
+
Vojtech Trefny 95db11
 class LvmTestLVrename(LvmPVVGLVTestCase):
Vojtech Trefny 95db11
     def test_lvrename(self):
Vojtech Trefny 95db11
         """Verify that it's possible to rename an LV"""
Vojtech Trefny 95db11
-- 
Vojtech Trefny 95db11
2.39.2
Vojtech Trefny 95db11