Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions src/plugins/mdraid.c
Original file line number Diff line number Diff line change
Expand Up @@ -1476,28 +1476,30 @@ 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)
/* error is already populated */
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);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/mdraid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down