neil / rpms / libblockdev

Forked from rpms/libblockdev a year ago
Clone

Blame 0013-ddf-mdadm-uuid-parse-fix.patch

Vojtech Trefny abd838
From 9bcaddbe97067f10e643a7d99fa13716126f6e60 Mon Sep 17 00:00:00 2001
Vojtech Trefny abd838
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny abd838
Date: Tue, 25 Aug 2020 14:09:18 +0200
Vojtech Trefny abd838
Subject: [PATCH 1/4] mdraid: Do not ignore errors from bd_md_canonicalize_uuid
Vojtech Trefny abd838
 in bd_md_examine
Vojtech Trefny abd838
Vojtech Trefny abd838
---
Vojtech Trefny abd838
 src/plugins/mdraid.c | 12 ++++++++++++
Vojtech Trefny abd838
 1 file changed, 12 insertions(+)
Vojtech Trefny abd838
Vojtech Trefny abd838
diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c
Vojtech Trefny abd838
index b97bc641..d41b6372 100644
Vojtech Trefny abd838
--- a/src/plugins/mdraid.c
Vojtech Trefny abd838
+++ b/src/plugins/mdraid.c
Vojtech Trefny abd838
@@ -983,12 +983,24 @@ BDMDExamineData* bd_md_examine (const gchar *device, GError **error) {
Vojtech Trefny abd838
     orig_data = ret->uuid;
Vojtech Trefny abd838
     if (orig_data) {
Vojtech Trefny abd838
         ret->uuid = bd_md_canonicalize_uuid (orig_data, error);
Vojtech Trefny abd838
+        if (!ret->uuid) {
Vojtech Trefny abd838
+            g_prefix_error (error, "Failed to canonicalize MD UUID '%s': ", orig_data);
Vojtech Trefny abd838
+            g_free (orig_data);
Vojtech Trefny abd838
+            bd_md_examine_data_free (ret);
Vojtech Trefny abd838
+            return NULL;
Vojtech Trefny abd838
+        }
Vojtech Trefny abd838
         g_free (orig_data);
Vojtech Trefny abd838
     }
Vojtech Trefny abd838
 
Vojtech Trefny abd838
     orig_data = ret->dev_uuid;
Vojtech Trefny abd838
     if (orig_data) {
Vojtech Trefny abd838
         ret->dev_uuid = bd_md_canonicalize_uuid (orig_data, error);
Vojtech Trefny abd838
+        if (!ret->uuid) {
Vojtech Trefny abd838
+            g_prefix_error (error, "Failed to canonicalize MD UUID '%s': ", orig_data);
Vojtech Trefny abd838
+            g_free (orig_data);
Vojtech Trefny abd838
+            bd_md_examine_data_free (ret);
Vojtech Trefny abd838
+            return NULL;
Vojtech Trefny abd838
+        }
Vojtech Trefny abd838
         g_free (orig_data);
Vojtech Trefny abd838
     }
Vojtech Trefny abd838
 
Vojtech Trefny abd838
-- 
Vojtech Trefny abd838
2.37.1
Vojtech Trefny abd838
Vojtech Trefny abd838
Vojtech Trefny abd838
From 1805734e8315d5fb73f036dae043312c88f3c3ec Mon Sep 17 00:00:00 2001
Vojtech Trefny abd838
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny abd838
Date: Tue, 25 Aug 2020 14:12:52 +0200
Vojtech Trefny abd838
Subject: [PATCH 2/4] mdraid: Try harder to get container UUID in bd_md_examine
Vojtech Trefny abd838
Vojtech Trefny abd838
For containers UUID is not printed in 'mdadm --examine' but it is
Vojtech Trefny abd838
printed when using the '--export' option.
Vojtech Trefny abd838
---
Vojtech Trefny abd838
 src/plugins/mdraid.c | 11 +++++++++++
Vojtech Trefny abd838
 1 file changed, 11 insertions(+)
Vojtech Trefny abd838
Vojtech Trefny abd838
diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c
Vojtech Trefny abd838
index d41b6372..3a23cf2e 100644
Vojtech Trefny abd838
--- a/src/plugins/mdraid.c
Vojtech Trefny abd838
+++ b/src/plugins/mdraid.c
Vojtech Trefny abd838
@@ -1023,6 +1023,17 @@ BDMDExamineData* bd_md_examine (const gchar *device, GError **error) {
Vojtech Trefny abd838
             value++;
Vojtech Trefny abd838
             g_free (ret->level);
Vojtech Trefny abd838
             ret->level = g_strdup (value);
Vojtech Trefny abd838
+        } else if (!ret->uuid && g_str_has_prefix (output_fields[i], "MD_UUID=")) {
Vojtech Trefny abd838
+            value = strchr (output_fields[i], '=');
Vojtech Trefny abd838
+            value++;
Vojtech Trefny abd838
+            ret->uuid = bd_md_canonicalize_uuid (value, error);
Vojtech Trefny abd838
+            if (!ret->uuid) {
Vojtech Trefny abd838
+                g_prefix_error (error, "Failed to canonicalize MD UUID '%s': ", orig_data);
Vojtech Trefny abd838
+                g_free (orig_data);
Vojtech Trefny abd838
+                bd_md_examine_data_free (ret);
Vojtech Trefny abd838
+                g_strfreev (output_fields);
Vojtech Trefny abd838
+                return NULL;
Vojtech Trefny abd838
+            }
Vojtech Trefny abd838
         }
Vojtech Trefny abd838
     g_strfreev (output_fields);
Vojtech Trefny abd838
 
Vojtech Trefny abd838
-- 
Vojtech Trefny abd838
2.37.1
Vojtech Trefny abd838
Vojtech Trefny abd838
Vojtech Trefny abd838
From 166756338f90d90b32ae0989db706dd52f7df234 Mon Sep 17 00:00:00 2001
Vojtech Trefny abd838
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny abd838
Date: Thu, 4 Aug 2022 12:47:53 +0200
Vojtech Trefny abd838
Subject: [PATCH 3/4] mdraid: Try harder to get container UUID in bd_md_detail
Vojtech Trefny abd838
Vojtech Trefny abd838
Similarly to bd_md_examine (see a10ad4e0), "mdadm --detail"
Vojtech Trefny abd838
doesn't contain container UUID, we need to need "--export" for
Vojtech Trefny abd838
that.
Vojtech Trefny abd838
---
Vojtech Trefny abd838
 src/plugins/mdraid.c | 43 +++++++++++++++++++++++++++++++++++--------
Vojtech Trefny abd838
 1 file changed, 35 insertions(+), 8 deletions(-)
Vojtech Trefny abd838
Vojtech Trefny abd838
diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c
Vojtech Trefny abd838
index 3a23cf2e..67bdc1f9 100644
Vojtech Trefny abd838
--- a/src/plugins/mdraid.c
Vojtech Trefny abd838
+++ b/src/plugins/mdraid.c
Vojtech Trefny abd838
@@ -1093,13 +1093,16 @@ BDMDExamineData* bd_md_examine (const gchar *device, GError **error) {
Vojtech Trefny abd838
  * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
Vojtech Trefny abd838
  */
Vojtech Trefny abd838
 BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error) {
Vojtech Trefny abd838
-    const gchar *argv[] = {"mdadm", "--detail", NULL, NULL};
Vojtech Trefny abd838
+    const gchar *argv[] = {"mdadm", "--detail", NULL, NULL, NULL};
Vojtech Trefny abd838
     gchar *output = NULL;
Vojtech Trefny abd838
     gboolean success = FALSE;
Vojtech Trefny abd838
     GHashTable *table = NULL;
Vojtech Trefny abd838
     guint num_items = 0;
Vojtech Trefny abd838
     gchar *orig_uuid = NULL;
Vojtech Trefny abd838
-    gchar *mdadm_spec = NULL;
Vojtech Trefny abd838
+    g_autofree gchar *mdadm_spec = NULL;
Vojtech Trefny abd838
+    gchar *value = NULL;
Vojtech Trefny abd838
+    gchar **output_fields = NULL;
Vojtech Trefny abd838
+    guint i = 0;
Vojtech Trefny abd838
     BDMDDetailData *ret = NULL;
Vojtech Trefny abd838
 
Vojtech Trefny abd838
     if (!check_deps (&avail_deps, DEPS_MDADM_MASK, deps, DEPS_LAST, &deps_check_lock, error))
Vojtech Trefny abd838
@@ -1113,16 +1116,13 @@ BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error) {
Vojtech Trefny abd838
     argv[2] = mdadm_spec;
Vojtech Trefny abd838
 
Vojtech Trefny abd838
     success = bd_utils_exec_and_capture_output (argv, NULL, &output, error);
Vojtech Trefny abd838
-    if (!success) {
Vojtech Trefny abd838
-        g_free (mdadm_spec);
Vojtech Trefny abd838
+    if (!success)
Vojtech Trefny abd838
         /* error is already populated */
Vojtech Trefny abd838
         return NULL;
Vojtech Trefny abd838
-    }
Vojtech Trefny abd838
 
Vojtech Trefny abd838
     table = parse_mdadm_vars (output, "\n", ":", &num_items);
Vojtech Trefny abd838
     g_free (output);
Vojtech Trefny abd838
     if (!table || (num_items == 0)) {
Vojtech Trefny abd838
-        g_free (mdadm_spec);
Vojtech Trefny abd838
         /* something bad happened or some expected items were missing  */
Vojtech Trefny abd838
         g_set_error (error, BD_MD_ERROR, BD_MD_ERROR_PARSE, "Failed to parse mddetail data");
Vojtech Trefny abd838
         if (table)
Vojtech Trefny abd838
@@ -1132,7 +1132,6 @@ BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error) {
Vojtech Trefny abd838
 
Vojtech Trefny abd838
     ret = get_detail_data_from_table (table, TRUE);
Vojtech Trefny abd838
     if (!ret) {
Vojtech Trefny abd838
-        g_free (mdadm_spec);
Vojtech Trefny abd838
         g_set_error (error, BD_MD_ERROR, BD_MD_ERROR_PARSE, "Failed to get mddetail data");
Vojtech Trefny abd838
         return NULL;
Vojtech Trefny abd838
     }
Vojtech Trefny abd838
@@ -1145,7 +1144,35 @@ BDMDDetailData* bd_md_detail (const gchar *raid_spec, GError **error) {
Vojtech Trefny abd838
         g_free (orig_uuid);
Vojtech Trefny abd838
     }
Vojtech Trefny abd838
 
Vojtech Trefny abd838
-    g_free (mdadm_spec);
Vojtech Trefny abd838
+    if (!ret->uuid) {
Vojtech Trefny abd838
+        argv[2] = "--export";
Vojtech Trefny abd838
+        argv[3] = mdadm_spec;
Vojtech Trefny abd838
+        success = bd_utils_exec_and_capture_output (argv, NULL, &output, error);
Vojtech Trefny abd838
+        if (!success) {
Vojtech Trefny abd838
+            /* error is already populated */
Vojtech Trefny abd838
+            bd_md_detail_data_free (ret);
Vojtech Trefny abd838
+            return NULL;
Vojtech Trefny abd838
+        }
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+        /* try to get a better information about RAID level because it may be
Vojtech Trefny abd838
+           missing in the output without --export */
Vojtech Trefny abd838
+        output_fields = g_strsplit (output, "\n", 0);
Vojtech Trefny abd838
+        g_free (output);
Vojtech Trefny abd838
+        output = NULL;
Vojtech Trefny abd838
+        for (i = 0; (i < g_strv_length (output_fields) - 1); i++)
Vojtech Trefny abd838
+            if (g_str_has_prefix (output_fields[i], "MD_UUID=")) {
Vojtech Trefny abd838
+                value = strchr (output_fields[i], '=');
Vojtech Trefny abd838
+                value++;
Vojtech Trefny abd838
+                ret->uuid = bd_md_canonicalize_uuid (value, error);
Vojtech Trefny abd838
+                if (!ret->uuid) {
Vojtech Trefny abd838
+                    g_prefix_error (error, "Failed to canonicalize MD UUID '%s': ", value);
Vojtech Trefny abd838
+                    bd_md_detail_data_free (ret);
Vojtech Trefny abd838
+                    g_strfreev (output_fields);
Vojtech Trefny abd838
+                    return NULL;
Vojtech Trefny abd838
+                }
Vojtech Trefny abd838
+            }
Vojtech Trefny abd838
+        g_strfreev (output_fields);
Vojtech Trefny abd838
+    }
Vojtech Trefny abd838
 
Vojtech Trefny abd838
     return ret;
Vojtech Trefny abd838
 }
Vojtech Trefny abd838
-- 
Vojtech Trefny abd838
2.37.1
Vojtech Trefny abd838
Vojtech Trefny abd838
Vojtech Trefny abd838
From 25dd2f8c7cc3cf540902fc40e808faabda3c691a Mon Sep 17 00:00:00 2001
Vojtech Trefny abd838
From: Vojtech Trefny <vtrefny@redhat.com>
Vojtech Trefny abd838
Date: Thu, 4 Aug 2022 12:51:48 +0200
Vojtech Trefny abd838
Subject: [PATCH 4/4] Add a test case for DDF arrays/containers
Vojtech Trefny abd838
Vojtech Trefny abd838
---
Vojtech Trefny abd838
 tests/mdraid_test.py | 51 ++++++++++++++++++++++++++++++++++++++++----
Vojtech Trefny abd838
 1 file changed, 47 insertions(+), 4 deletions(-)
Vojtech Trefny abd838
Vojtech Trefny abd838
diff --git a/tests/mdraid_test.py b/tests/mdraid_test.py
Vojtech Trefny abd838
index 0b2bdc9b..38f43a0d 100644
Vojtech Trefny abd838
--- a/tests/mdraid_test.py
Vojtech Trefny abd838
+++ b/tests/mdraid_test.py
Vojtech Trefny abd838
@@ -6,7 +6,7 @@ from contextlib import contextmanager
Vojtech Trefny abd838
 import overrides_hack
Vojtech Trefny abd838
 import six
Vojtech Trefny abd838
 
Vojtech Trefny abd838
-from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test
Vojtech Trefny abd838
+from utils import create_sparse_tempfile, create_lio_device, delete_lio_device, fake_utils, fake_path, TestTags, tag_test, run_command
Vojtech Trefny abd838
 from gi.repository import BlockDev, GLib
Vojtech Trefny abd838
 
Vojtech Trefny abd838
 
Vojtech Trefny abd838
@@ -90,14 +90,16 @@ class MDNoDevTestCase(MDTest):
Vojtech Trefny abd838
 
Vojtech Trefny abd838
 class MDTestCase(MDTest):
Vojtech Trefny abd838
 
Vojtech Trefny abd838
+    _sparse_size = 10 * 1024**2
Vojtech Trefny abd838
+
Vojtech Trefny abd838
     def setUp(self):
Vojtech Trefny abd838
         if os.uname()[-1] == "i686":
Vojtech Trefny abd838
             self.skipTest("Skipping hanging MD RAID tests on i686")
Vojtech Trefny abd838
 
Vojtech Trefny abd838
         self.addCleanup(self._clean_up)
Vojtech Trefny abd838
-        self.dev_file = create_sparse_tempfile("md_test", 10 * 1024**2)
Vojtech Trefny abd838
-        self.dev_file2 = create_sparse_tempfile("md_test", 10 * 1024**2)
Vojtech Trefny abd838
-        self.dev_file3 = create_sparse_tempfile("md_test", 10 * 1024**2)
Vojtech Trefny abd838
+        self.dev_file = create_sparse_tempfile("md_test", self._sparse_size)
Vojtech Trefny abd838
+        self.dev_file2 = create_sparse_tempfile("md_test", self._sparse_size)
Vojtech Trefny abd838
+        self.dev_file3 = create_sparse_tempfile("md_test", self._sparse_size)
Vojtech Trefny abd838
 
Vojtech Trefny abd838
         try:
Vojtech Trefny abd838
             self.loop_dev = create_lio_device(self.dev_file)
Vojtech Trefny abd838
@@ -586,6 +588,47 @@ class MDTestRequestSyncAction(MDTestCase):
Vojtech Trefny abd838
             action = f.read().strip()
Vojtech Trefny abd838
         self.assertEqual(action, "check")
Vojtech Trefny abd838
 
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+class MDTestDDFRAID(MDTestCase):
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+    _sparse_size = 50 * 1024**2
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+    def _clean_up(self):
Vojtech Trefny abd838
+        try:
Vojtech Trefny abd838
+            BlockDev.md_deactivate("bd_test_ddf")
Vojtech Trefny abd838
+        except:
Vojtech Trefny abd838
+            pass
Vojtech Trefny abd838
+        try:
Vojtech Trefny abd838
+            BlockDev.md_deactivate(BlockDev.md_node_from_name("bd_test_ddf"))
Vojtech Trefny abd838
+        except:
Vojtech Trefny abd838
+            pass
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+        super(MDTestDDFRAID, self)._clean_up()
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+    def test_examine_ddf_container(self):
Vojtech Trefny abd838
+        succ = BlockDev.md_create("bd_test_md", "container",
Vojtech Trefny abd838
+                                  [self.loop_dev, self.loop_dev2],
Vojtech Trefny abd838
+                                  0, "ddf", False)
Vojtech Trefny abd838
+        self.assertTrue(succ)
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+        # we cannot create the array with libblockdev because we cannot pass the --raid-devices option
Vojtech Trefny abd838
+        ret, _out, err = run_command("mdadm --create /dev/md/bd_test_ddf --run --level=raid0 --raid-devices=2 /dev/md/bd_test_md")
Vojtech Trefny abd838
+        self.assertEqual(ret, 0, msg="Failed to create RAID for DDF test: %s" % err)
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+        edata = BlockDev.md_examine(self.loop_dev)
Vojtech Trefny abd838
+        self.assertIsNotNone(edata)
Vojtech Trefny abd838
+        self.assertIsNotNone(edata.uuid)
Vojtech Trefny abd838
+        self.assertEqual(edata.level, "container")
Vojtech Trefny abd838
+        self.assertEqual(edata.metadata, "ddf")
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+        ddata = BlockDev.md_detail("bd_test_md")
Vojtech Trefny abd838
+        self.assertIsNotNone(ddata)
Vojtech Trefny abd838
+        self.assertIsNotNone(ddata.uuid)
Vojtech Trefny abd838
+        self.assertEqual(ddata.uuid, edata.uuid)
Vojtech Trefny abd838
+        self.assertEqual(ddata.level, "container")
Vojtech Trefny abd838
+        self.assertEqual(ddata.metadata, "ddf")
Vojtech Trefny abd838
+
Vojtech Trefny abd838
+
Vojtech Trefny abd838
 class FakeMDADMutilTest(MDTest):
Vojtech Trefny abd838
     # no setUp nor tearDown needed, we are gonna use fake utils
Vojtech Trefny abd838
     @tag_test(TestTags.NOSTORAGE)
Vojtech Trefny abd838
-- 
Vojtech Trefny abd838
2.37.1
Vojtech Trefny abd838