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

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