diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c index 8e8a90aa..ee3aef1b 100644 --- a/src/plugins/mdraid.c +++ b/src/plugins/mdraid.c @@ -1476,10 +1476,11 @@ gboolean bd_md_set_bitmap_location (const gchar *raid_spec, const gchar *locatio * Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY */ gchar* bd_md_get_bitmap_location (const gchar *raid_spec, GError **error) { - gchar *raid_node = NULL; - gchar *sys_path = NULL; + g_autofree gchar *raid_node = NULL; + g_autofree gchar *sys_path = NULL; gchar *ret = NULL; gboolean success = FALSE; + GError *l_error = NULL; raid_node = get_sysfs_name_from_input (raid_spec, error); if (!raid_node) @@ -1487,17 +1488,18 @@ gchar* bd_md_get_bitmap_location (const gchar *raid_spec, GError **error) { return NULL; sys_path = g_strdup_printf ("/sys/class/block/%s/md/bitmap/location", raid_node); - g_free (raid_node); - success = g_file_get_contents (sys_path, &ret, NULL, error); + success = g_file_get_contents (sys_path, &ret, NULL, &l_error); if (!success) { - /* error is already populated */ - g_free (sys_path); - return NULL; + if (g_error_matches (l_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) { + g_clear_error (&l_error); + return g_strdup ("none"); + } else { + g_propagate_prefixed_error (error, l_error, "Failed to get bitmap location: "); + return NULL; + } } - g_free (sys_path); - return g_strstrip (ret); } diff --git a/tests/mdraid_test.py b/tests/mdraid_test.py index af03e305..b7f61471 100644 --- a/tests/mdraid_test.py +++ b/tests/mdraid_test.py @@ -476,7 +476,7 @@ def test_set_bitmap_location(self): self.assertTrue(succ) loc = BlockDev.md_get_bitmap_location("bd_test_md") - self.assertEqual(loc, "+8") + self.assertIn(loc, ("+8", "+2")) succ = BlockDev.md_set_bitmap_location("bd_test_md", "none") self.assertTrue(succ) @@ -488,7 +488,7 @@ def test_set_bitmap_location(self): self.assertTrue(succ) loc = BlockDev.md_get_bitmap_location("bd_test_md") - self.assertEqual(loc, "+8") + self.assertIn(loc, ("+8", "+2")) # test some different name specifications # (need to switch between internal and none because setting the same