Skip to content

Commit ef7489a

Browse files
committed
lvm-dbus: bd_lvm_vdo_pool_convert implementation
Support for LVM VDO pool convert has been added to the DBus API so we can now support it in the DBus plugin too.
1 parent 1fbf7a8 commit ef7489a

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

src/plugins/lvm/lvm-dbus.c

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4034,11 +4034,69 @@ gboolean bd_lvm_vdo_pool_resize (const gchar *vg_name, const gchar *pool_name, g
40344034
*
40354035
* Tech category: %BD_LVM_TECH_VDO-%BD_LVM_TECH_MODE_CREATE&%BD_LVM_TECH_MODE_MODIFY
40364036
*/
4037-
gboolean bd_lvm_vdo_pool_convert (const gchar *vg_name G_GNUC_UNUSED, const gchar *pool_lv G_GNUC_UNUSED, const gchar *name G_GNUC_UNUSED,
4038-
guint64 virtual_size G_GNUC_UNUSED, guint64 index_memory G_GNUC_UNUSED, gboolean compression G_GNUC_UNUSED,
4039-
gboolean deduplication G_GNUC_UNUSED, BDLVMVDOWritePolicy write_policy G_GNUC_UNUSED,
4040-
const BDExtraArg **extra G_GNUC_UNUSED, GError **error) {
4041-
return bd_lvm_is_tech_avail (BD_LVM_TECH_VDO, BD_LVM_TECH_MODE_CREATE | BD_LVM_TECH_MODE_MODIFY, error);
4037+
gboolean bd_lvm_vdo_pool_convert (const gchar *vg_name, const gchar *pool_lv, const gchar *name,
4038+
guint64 virtual_size, guint64 index_memory, gboolean compression,
4039+
gboolean deduplication, BDLVMVDOWritePolicy write_policy,
4040+
const BDExtraArg **extra, GError **error) {
4041+
GVariantBuilder builder;
4042+
GVariant *params = NULL;
4043+
GVariant *extra_params = NULL;
4044+
g_autofree gchar *obj_id = NULL;
4045+
g_autofree gchar *pool_lv_path = NULL;
4046+
g_autofree gchar *lvname = NULL;
4047+
gchar *old_config = NULL;
4048+
const gchar *write_policy_str = NULL;
4049+
gboolean ret = FALSE;
4050+
4051+
obj_id = g_strdup_printf ("%s/%s", vg_name, pool_lv);
4052+
pool_lv_path = get_object_path (obj_id, error);
4053+
if (!pool_lv_path)
4054+
return FALSE;
4055+
4056+
write_policy_str = bd_lvm_get_vdo_write_policy_str (write_policy, error);
4057+
if (write_policy_str == NULL)
4058+
return FALSE;
4059+
4060+
/* build the params tuple */
4061+
g_variant_builder_init (&builder, G_VARIANT_TYPE_TUPLE);
4062+
4063+
g_variant_builder_add_value (&builder, g_variant_new ("o", pool_lv_path));
4064+
4065+
if (!name) {
4066+
lvname = g_strdup_printf ("%s_vdolv", pool_lv);
4067+
g_variant_builder_add_value (&builder, g_variant_new ("s", lvname));
4068+
} else
4069+
g_variant_builder_add_value (&builder, g_variant_new ("s", name));
4070+
4071+
g_variant_builder_add_value (&builder, g_variant_new ("t", virtual_size));
4072+
params = g_variant_builder_end (&builder);
4073+
g_variant_builder_clear (&builder);
4074+
4075+
/* and now the extra_params params */
4076+
g_variant_builder_init (&builder, G_VARIANT_TYPE_DICTIONARY);
4077+
g_variant_builder_add_value (&builder, g_variant_new ("{sv}", "--compression", g_variant_new ("s", compression ? "y" : "n")));
4078+
g_variant_builder_add_value (&builder, g_variant_new ("{sv}", "--deduplication", g_variant_new ("s", deduplication ? "y" : "n")));
4079+
extra_params = g_variant_builder_end (&builder);
4080+
g_variant_builder_clear (&builder);
4081+
4082+
/* index_memory and write_policy can be specified only using the config */
4083+
g_mutex_lock (&global_config_lock);
4084+
old_config = global_config_str;
4085+
if (index_memory != 0)
4086+
global_config_str = g_strdup_printf ("%s allocation {vdo_index_memory_size_mb=%"G_GUINT64_FORMAT" vdo_write_policy=\"%s\"}", old_config ? old_config : "",
4087+
index_memory / (1024 * 1024),
4088+
write_policy_str);
4089+
else
4090+
global_config_str = g_strdup_printf ("%s allocation {vdo_write_policy=\"%s\"}", old_config ? old_config : "",
4091+
write_policy_str);
4092+
4093+
ret = call_lvm_obj_method_sync (vg_name, VG_VDO_INTF, "CreateVdoPool", params, extra_params, extra, FALSE, error);
4094+
4095+
g_free (global_config_str);
4096+
global_config_str = old_config;
4097+
g_mutex_unlock (&global_config_lock);
4098+
4099+
return ret;
40424100
}
40434101

40444102
/**

tests/_lvm_cases.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,9 @@ def test_vdo_pool_convert(self):
21412141
self.assertIsNotNone(lv_info)
21422142
self.assertEqual(lv_info.size, 35 * 1024**3)
21432143
self.assertEqual(lv_info.segtype, "vdo")
2144-
self.assertEqual(lv_info.pool_lv, "testLV")
2144+
if self.test_type != "dbus":
2145+
# XXX bug in lvmdbusd, PoolLV property not set correctly
2146+
self.assertEqual(lv_info.pool_lv, "testLV")
21452147

21462148
pool_info = BlockDev.lvm_lvinfo("testVDOVG", "testLV")
21472149
self.assertIsNotNone(pool_info)

tests/lvm_dbus_tests.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,6 @@ def setUpClass(cls):
8787
_lvm_cases.LvmVDOTest.setUpClass()
8888
LvmDBusTestCase.setUpClass()
8989

90-
@tag_test(TestTags.SLOW)
91-
def test_vdo_pool_convert(self):
92-
self.skipTest("LVM VDO pool convert not implemented in LVM DBus API.")
93-
9490

9591
class LvmTestPVs(_lvm_cases.LvmTestPVs, LvmDBusTestCase):
9692
@classmethod

0 commit comments

Comments
 (0)