From cf3684cbb8ddb5727d63a9a52edea57700d413d7 Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Wed, 5 Nov 2025 15:12:08 +0100 Subject: [PATCH] md: Fix getting bitmap location on latest kernels The 'md/bitmap/location' file no longer exists in sysfs when the bitmap is not set. The location of the "internal" bitmap is also slightly differet now. --- src/plugins/mdraid.c | 20 +++++++++++--------- tests/mdraid_test.py | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/plugins/mdraid.c b/src/plugins/mdraid.c index 8e8a90aae..ee3aef1b4 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 af03e3051..b7f614713 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