From 0773e654b2eb446518692535bb349f8abcd17af0 Mon Sep 17 00:00:00 2001 From: Vratislav Podzimek Date: Tue, 4 Oct 2016 19:08:06 +0200 Subject: [PATCH 1/3] Use 'mdadm --examine --export' to get MD RAID level It may not be reported properly in the 'mdadm --examine' output (e.g. for IMSM FW RAID). Related: rhbz#1379865 (cherry-picked from commit 075c21c6a474674c1370472b2cf74f93dff28c38) Signed-off-by: Vratislav Podzimek --- src/plugins/mdraid.c | 20 ++++++++++++++++++++ tests/md_test.py | 2 +- tests/mdadm_fw_RAID_examine/mdadm | 10 ++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c index 723b756..7e6b2da 100644 --- a/src/plugins/mdraid.c +++ b/src/plugins/mdraid.c @@ -798,6 +798,26 @@ BDMDExamineData* bd_md_examine (gchar *device, GError **error) { g_free (orig_data); } + argv[2] = "--export"; + success = bd_utils_exec_and_capture_output (argv, &output, error); + if (!success) + /* error is already populated */ + return FALSE; + + /* try to get a better information about RAID level because it may be + misleading in the output without --export */ + output_fields = g_strsplit (output, "\n", 0); + g_free (output); + output = NULL; + for (i=0; (i < g_strv_length (output_fields) - 1); i++) + if (g_str_has_prefix (output_fields[i], "MD_LEVEL=")) { + value = strchr (output_fields[i], '='); + value++; + g_free (ret->level); + ret->level = g_strdup (value); + } + g_strfreev (output_fields); + argv[2] = "--brief"; success = bd_utils_exec_and_capture_output (argv, &output, error); if (!success) diff --git a/tests/md_test.py b/tests/md_test.py index df90582..4b4d898 100644 --- a/tests/md_test.py +++ b/tests/md_test.py @@ -410,7 +410,7 @@ class FakeMDADMutilTest(unittest.TestCase): with fake_utils("tests/mdadm_fw_RAID_examine"): ex_data = BlockDev.md_examine("fake_dev") - self.assertEqual(ex_data.level, "0") + self.assertEqual(ex_data.level, "container") self.assertEqual(ex_data.num_devices, 1) def test_no_metadata_examine(self): diff --git a/tests/mdadm_fw_RAID_examine/mdadm b/tests/mdadm_fw_RAID_examine/mdadm index c939860..6fe7f64 100755 --- a/tests/mdadm_fw_RAID_examine/mdadm +++ b/tests/mdadm_fw_RAID_examine/mdadm @@ -3,11 +3,21 @@ echo "$@"|grep -- "--brief" &>/dev/null is_brief=$? +echo "$@"|grep -- "--export" &>/dev/null +is_export=$? + if [ $is_brief -eq 0 ]; then cat <