From 5c12914d465edf608a4596bff4e4caa70897b7fe Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Tue, 2 Jun 2020 10:46:31 +0200 Subject: [PATCH 165/193] mdraid: Do not try to activate already active MDRAID devices --- src/plugins/mdraid.c | 16 ++++++++++++++++ tests/mdraid_test.py | 5 +++++ 2 files changed, 21 insertions(+) diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c index e5be1b1..af5f913 100644 --- a/src/plugins/mdraid.c +++ b/src/plugins/mdraid.c @@ -720,10 +720,26 @@ gboolean bd_md_activate (const gchar *raid_spec, const gchar **members, const gc guint argv_top = 0; guint i = 0; gboolean ret = FALSE; + BDMDDetailData *data = NULL; if (!check_deps (&avail_deps, DEPS_MDADM_MASK, deps, DEPS_LAST, &deps_check_lock, error)) return FALSE; + if (raid_spec) { + data = bd_md_detail (raid_spec, error); + if (!data) + g_clear_error (error); + else { + bd_utils_log_format (BD_UTILS_LOG_INFO, + "RAID array '%s' is already active with %"G_GUINT64_FORMAT" devices" + " (%"G_GUINT64_FORMAT" active, %"G_GUINT64_FORMAT" spare)", + raid_spec, data->total_devices, + data->active_devices, data->spare_devices); + bd_md_detail_data_free (data); + return TRUE; + } + } + /* mdadm, --assemble, raid_spec/--scan, --run, --uuid=uuid, member1, member2,..., NULL*/ argv = g_new0 (const gchar*, num_members + 6); diff --git a/tests/mdraid_test.py b/tests/mdraid_test.py index 0b2bdc9..9c6cd17 100644 --- a/tests/mdraid_test.py +++ b/tests/mdraid_test.py @@ -245,6 +245,11 @@ class MDTestActivateDeactivate(MDTestCase): [self.loop_dev, self.loop_dev2, self.loop_dev3], None) self.assertTrue(succ) + # try to activate again, should not fail, just no-op + succ = BlockDev.md_activate("bd_test_md", + [self.loop_dev, self.loop_dev2, self.loop_dev3], None) + self.assertTrue(succ) + # try to deactivate using the node instead of name with wait_for_action("resync"): succ = BlockDev.md_deactivate(BlockDev.md_node_from_name("bd_test_md")) -- 1.8.3.1