Skip to content

Commit a6c09ea

Browse files
Merge pull request #1143 from vojtechtrefny/main_md-bitmap-location-fix
md: Fix getting bitmap location on latest kernels
2 parents 49608e3 + cf3684c commit a6c09ea

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/plugins/mdraid.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1476,28 +1476,30 @@ gboolean bd_md_set_bitmap_location (const gchar *raid_spec, const gchar *locatio
14761476
* Tech category: %BD_MD_TECH_MDRAID-%BD_MD_TECH_MODE_QUERY
14771477
*/
14781478
gchar* bd_md_get_bitmap_location (const gchar *raid_spec, GError **error) {
1479-
gchar *raid_node = NULL;
1480-
gchar *sys_path = NULL;
1479+
g_autofree gchar *raid_node = NULL;
1480+
g_autofree gchar *sys_path = NULL;
14811481
gchar *ret = NULL;
14821482
gboolean success = FALSE;
1483+
GError *l_error = NULL;
14831484

14841485
raid_node = get_sysfs_name_from_input (raid_spec, error);
14851486
if (!raid_node)
14861487
/* error is already populated */
14871488
return NULL;
14881489

14891490
sys_path = g_strdup_printf ("/sys/class/block/%s/md/bitmap/location", raid_node);
1490-
g_free (raid_node);
14911491

1492-
success = g_file_get_contents (sys_path, &ret, NULL, error);
1492+
success = g_file_get_contents (sys_path, &ret, NULL, &l_error);
14931493
if (!success) {
1494-
/* error is already populated */
1495-
g_free (sys_path);
1496-
return NULL;
1494+
if (g_error_matches (l_error, G_FILE_ERROR, G_FILE_ERROR_NOENT)) {
1495+
g_clear_error (&l_error);
1496+
return g_strdup ("none");
1497+
} else {
1498+
g_propagate_prefixed_error (error, l_error, "Failed to get bitmap location: ");
1499+
return NULL;
1500+
}
14971501
}
14981502

1499-
g_free (sys_path);
1500-
15011503
return g_strstrip (ret);
15021504
}
15031505

tests/mdraid_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ def test_set_bitmap_location(self):
476476
self.assertTrue(succ)
477477

478478
loc = BlockDev.md_get_bitmap_location("bd_test_md")
479-
self.assertEqual(loc, "+8")
479+
self.assertIn(loc, ("+8", "+2"))
480480

481481
succ = BlockDev.md_set_bitmap_location("bd_test_md", "none")
482482
self.assertTrue(succ)
@@ -488,7 +488,7 @@ def test_set_bitmap_location(self):
488488
self.assertTrue(succ)
489489

490490
loc = BlockDev.md_get_bitmap_location("bd_test_md")
491-
self.assertEqual(loc, "+8")
491+
self.assertIn(loc, ("+8", "+2"))
492492

493493
# test some different name specifications
494494
# (need to switch between internal and none because setting the same

0 commit comments

Comments
 (0)