Skip to content

Commit

Permalink
Merge pull request #1079 from vojtechtrefny/master_lvm-dbus-lvrepair
Browse files Browse the repository at this point in the history
lvm-dbus: Add support for repairing RAID LVs
  • Loading branch information
vojtechtrefny authored Nov 26, 2024
2 parents a1534b1 + 6af0536 commit 2f5af57
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
32 changes: 28 additions & 4 deletions src/plugins/lvm-dbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -2706,10 +2706,34 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si
*
* Tech category: %BD_LVM_TECH_BASIC-%BD_LVM_TECH_MODE_MODIFY
*/
gboolean bd_lvm_lvrepair (const gchar *vg_name G_GNUC_UNUSED, const gchar *lv_name G_GNUC_UNUSED, const gchar **pv_list G_GNUC_UNUSED,
const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_TECH_UNAVAIL,
"lvrepair is not supported by this plugin implementation.");
gboolean bd_lvm_lvrepair (const gchar *vg_name, const gchar *lv_name, const gchar **pv_list,
const BDExtraArg **extra, GError **error) {
GVariantBuilder builder;
GVariant *params = NULL;
gchar *path = NULL;
const gchar **pv = NULL;
GVariant *pvs = NULL;

/* build the array of PVs (object paths) */
g_variant_builder_init (&builder, G_VARIANT_TYPE_OBJECT_PATH_ARRAY);
for (pv=pv_list; *pv; pv++) {
path = get_object_path (*pv, error);
if (!path) {
g_variant_builder_clear (&builder);
return FALSE;
}
g_variant_builder_add_value (&builder, g_variant_new ("o", path));
}
pvs = g_variant_builder_end (&builder);
g_variant_builder_clear (&builder);

g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
g_variant_builder_add_value (&builder, pvs);
params = g_variant_builder_end (&builder);
g_variant_builder_clear (&builder);

return call_lv_method_sync (vg_name, lv_name, "RepairRaidLv", params, NULL, extra, TRUE, error);

return FALSE;
}

Expand Down
29 changes: 27 additions & 2 deletions tests/lvm_dbus_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ def setUp(self):
self.addCleanup(self._clean_up)
self.dev_file = create_sparse_tempfile("lvm_test", self._sparse_size)
self.dev_file2 = create_sparse_tempfile("lvm_test", self._sparse_size)
self.dev_file3 = create_sparse_tempfile("lvm_test", self._sparse_size)
try:
self.loop_dev = create_lio_device(self.dev_file)
except RuntimeError as e:
Expand All @@ -359,9 +360,13 @@ def setUp(self):
self.loop_dev2 = create_lio_device(self.dev_file2)
except RuntimeError as e:
raise RuntimeError("Failed to setup loop device for testing: %s" % e)
try:
self.loop_dev3 = create_lio_device(self.dev_file3)
except RuntimeError as e:
raise RuntimeError("Failed to setup loop device for testing: %s" % e)

def _clean_up(self):
for dev in (self.loop_dev, self.loop_dev2):
for dev in (self.loop_dev, self.loop_dev2, self.loop_dev3):
try:
BlockDev.lvm_pvremove(dev)
except:
Expand All @@ -386,6 +391,13 @@ def _clean_up(self):
pass
os.unlink(self.dev_file2)

try:
delete_lio_device(self.loop_dev3)
except RuntimeError:
# just move on, we can do no better here
pass
os.unlink(self.dev_file3)

@unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
class LvmTestPVcreateRemove(LvmPVonlyTestCase):
@tag_test(TestTags.CORE)
Expand Down Expand Up @@ -1306,7 +1318,10 @@ def test_lvpartial(self):
succ = BlockDev.lvm_pvcreate(self.loop_dev2, 0, 0, None)
self.assertTrue(succ)

succ = BlockDev.lvm_vgcreate("testVG", [self.loop_dev, self.loop_dev2], 0, None)
succ = BlockDev.lvm_pvcreate(self.loop_dev3, 0, 0, None)
self.assertTrue(succ)

succ = BlockDev.lvm_vgcreate("testVG", [self.loop_dev, self.loop_dev2, self.loop_dev3], 0, None)
self.assertTrue(succ)

info = BlockDev.lvm_pvinfo(self.loop_dev2)
Expand Down Expand Up @@ -1390,6 +1405,16 @@ def assert_raid1_structure(pv1, pv2):
# lvs_tree should still report the second stripe to be missing
assert_raid1_structure(self.loop_dev, None)

# repair testLV with the third PV
with wait_for_sync("testVG", "testLV"):
succ = BlockDev.lvm_lvrepair("testVG", "testLV", [self.loop_dev3])
self.assertTrue(succ)

info = BlockDev.lvm_lvinfo("testVG", "testLV")
self.assertEqual(info.attr[8], "-")

assert_raid1_structure(self.loop_dev, self.loop_dev3)

@unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
class LvmTestLVsAll(LvmPVVGthpoolTestCase):
def test_lvs_all(self):
Expand Down
4 changes: 4 additions & 0 deletions tests/skip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@
- distro: "debian"
arch: "i686"
reason: "vdo userspace tools are not available on 32bit Debian"

- test: lvm_dbus_tests.LvmTestPartialLVs
skip_on:
- reason: "LVM DBus doesn't support LV repair yet"

0 comments on commit 2f5af57

Please sign in to comment.