Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> Reviewed-by: Ján Tomko <jtomko@xxxxxxxxxx> --- data/org.libvirt.StoragePool.xml | 6 ++++++ src/storagepool.c | 43 ++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 8 ++++++++ 3 files changed, 57 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index e9d6b0e..764c9c1 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -57,6 +57,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="ListStorageVolumes"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolListAllVolumes"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVols" type="ao" direction="out"/> + </method> <method name="Refresh"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> diff --git a/src/storagepool.c b/src/storagepool.c index 0da732f..4f83ee2 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -301,6 +301,48 @@ virtDBusStoragePoolGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusStoragePoolListStorageVolumes(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + g_autoptr(virStorageVolPtr) storageVols = NULL; + guint flags; + gint nVols; + GVariantBuilder builder; + GVariant *gstorageVols; + + g_variant_get(inArgs, "(u)", &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + nVols = virStoragePoolListAllVolumes(storagePool, &storageVols, flags); + if (nVols < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ao")); + + for (gint i = 0; i < nVols; i++) { + g_autofree gchar *path = NULL; + path = virtDBusUtilBusPathForVirStorageVol(storageVols[i], + connect->storageVolPath); + + g_variant_builder_add(&builder, "o", path); + } + + gstorageVols = g_variant_builder_end(&builder); + *outArgs = g_variant_new_tuple(&gstorageVols, 1); +} + static void virtDBusStoragePoolRefresh(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -363,6 +405,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Destroy", virtDBusStoragePoolDestroy }, { "GetInfo", virtDBusStoragePoolGetInfo }, { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, + { "ListStorageVolumes", virtDBusStoragePoolListStorageVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } diff --git a/tests/test_storage.py b/tests/test_storage.py index b9e7090..79e0c16 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -79,6 +79,14 @@ class TestStoragePool(libvirttest.BaseTestClass): info = interface_obj.GetXMLDesc(0) assert isinstance(info, dbus.String) + def test_storage_pool_list_storage_volumes(self): + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + storage_vols = interface_obj.ListStorageVolumes(0) + assert isinstance(storage_vols, dbus.Array) + assert len(storage_vols) == 0 + def test_storage_pool_properties_type(self): _, obj = self.test_storage_pool() -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list