Skip to content

Commit 2f5af57

Browse files
Merge pull request #1079 from vojtechtrefny/master_lvm-dbus-lvrepair
lvm-dbus: Add support for repairing RAID LVs
2 parents a1534b1 + 6af0536 commit 2f5af57

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

src/plugins/lvm-dbus.c

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2706,10 +2706,34 @@ gboolean bd_lvm_lvresize (const gchar *vg_name, const gchar *lv_name, guint64 si
27062706
*
27072707
* Tech category: %BD_LVM_TECH_BASIC-%BD_LVM_TECH_MODE_MODIFY
27082708
*/
2709-
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,
2710-
const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
2711-
g_set_error (error, BD_LVM_ERROR, BD_LVM_ERROR_TECH_UNAVAIL,
2712-
"lvrepair is not supported by this plugin implementation.");
2709+
gboolean bd_lvm_lvrepair (const gchar *vg_name, const gchar *lv_name, const gchar **pv_list,
2710+
const BDExtraArg **extra, GError **error) {
2711+
GVariantBuilder builder;
2712+
GVariant *params = NULL;
2713+
gchar *path = NULL;
2714+
const gchar **pv = NULL;
2715+
GVariant *pvs = NULL;
2716+
2717+
/* build the array of PVs (object paths) */
2718+
g_variant_builder_init (&builder, G_VARIANT_TYPE_OBJECT_PATH_ARRAY);
2719+
for (pv=pv_list; *pv; pv++) {
2720+
path = get_object_path (*pv, error);
2721+
if (!path) {
2722+
g_variant_builder_clear (&builder);
2723+
return FALSE;
2724+
}
2725+
g_variant_builder_add_value (&builder, g_variant_new ("o", path));
2726+
}
2727+
pvs = g_variant_builder_end (&builder);
2728+
g_variant_builder_clear (&builder);
2729+
2730+
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
2731+
g_variant_builder_add_value (&builder, pvs);
2732+
params = g_variant_builder_end (&builder);
2733+
g_variant_builder_clear (&builder);
2734+
2735+
return call_lv_method_sync (vg_name, lv_name, "RepairRaidLv", params, NULL, extra, TRUE, error);
2736+
27132737
return FALSE;
27142738
}
27152739

tests/lvm_dbus_tests.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ def setUp(self):
351351
self.addCleanup(self._clean_up)
352352
self.dev_file = create_sparse_tempfile("lvm_test", self._sparse_size)
353353
self.dev_file2 = create_sparse_tempfile("lvm_test", self._sparse_size)
354+
self.dev_file3 = create_sparse_tempfile("lvm_test", self._sparse_size)
354355
try:
355356
self.loop_dev = create_lio_device(self.dev_file)
356357
except RuntimeError as e:
@@ -359,9 +360,13 @@ def setUp(self):
359360
self.loop_dev2 = create_lio_device(self.dev_file2)
360361
except RuntimeError as e:
361362
raise RuntimeError("Failed to setup loop device for testing: %s" % e)
363+
try:
364+
self.loop_dev3 = create_lio_device(self.dev_file3)
365+
except RuntimeError as e:
366+
raise RuntimeError("Failed to setup loop device for testing: %s" % e)
362367

363368
def _clean_up(self):
364-
for dev in (self.loop_dev, self.loop_dev2):
369+
for dev in (self.loop_dev, self.loop_dev2, self.loop_dev3):
365370
try:
366371
BlockDev.lvm_pvremove(dev)
367372
except:
@@ -386,6 +391,13 @@ def _clean_up(self):
386391
pass
387392
os.unlink(self.dev_file2)
388393

394+
try:
395+
delete_lio_device(self.loop_dev3)
396+
except RuntimeError:
397+
# just move on, we can do no better here
398+
pass
399+
os.unlink(self.dev_file3)
400+
389401
@unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
390402
class LvmTestPVcreateRemove(LvmPVonlyTestCase):
391403
@tag_test(TestTags.CORE)
@@ -1306,7 +1318,10 @@ def test_lvpartial(self):
13061318
succ = BlockDev.lvm_pvcreate(self.loop_dev2, 0, 0, None)
13071319
self.assertTrue(succ)
13081320

1309-
succ = BlockDev.lvm_vgcreate("testVG", [self.loop_dev, self.loop_dev2], 0, None)
1321+
succ = BlockDev.lvm_pvcreate(self.loop_dev3, 0, 0, None)
1322+
self.assertTrue(succ)
1323+
1324+
succ = BlockDev.lvm_vgcreate("testVG", [self.loop_dev, self.loop_dev2, self.loop_dev3], 0, None)
13101325
self.assertTrue(succ)
13111326

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

1408+
# repair testLV with the third PV
1409+
with wait_for_sync("testVG", "testLV"):
1410+
succ = BlockDev.lvm_lvrepair("testVG", "testLV", [self.loop_dev3])
1411+
self.assertTrue(succ)
1412+
1413+
info = BlockDev.lvm_lvinfo("testVG", "testLV")
1414+
self.assertEqual(info.attr[8], "-")
1415+
1416+
assert_raid1_structure(self.loop_dev, self.loop_dev3)
1417+
13931418
@unittest.skipUnless(lvm_dbus_running, "LVM DBus not running")
13941419
class LvmTestLVsAll(LvmPVVGthpoolTestCase):
13951420
def test_lvs_all(self):

tests/skip.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,7 @@
5555
- distro: "debian"
5656
arch: "i686"
5757
reason: "vdo userspace tools are not available on 32bit Debian"
58+
59+
- test: lvm_dbus_tests.LvmTestPartialLVs
60+
skip_on:
61+
- reason: "LVM DBus doesn't support LV repair yet"

0 commit comments

Comments
 (0)