[libvirt] [dbus PATCH 00/15] StorageVolume APIs

StorageVols logically should be nested under StoragePools, however this implementation does not nest the StorageVol interface under StorageVols. Reason is that the current gdbus.c implementation would not allow nesting of objects. Phrdina checked the posibility of rewritting the gdbus.c to support such requirements, but the effort stopped, since such implentation would interfere with the current lazy loading of objects. Thus, this solution appears to be the only viable. Katerina Koukiou (15): Introduce StorageVol Interface Implement ListStorageVolumes for StoragePool Interface Implement StorageVolCreateXML method for StoragePool Interface Implement Name property for StorageVol Interface Implement Key property for StorageVol Interface Implement Path property for StorageVol Interface Implement GetXMLDesc method for StorageVol Interface Implement StorageVolLookupByKey method for Connect Interface Implement StorageVolLookupByName method for StoragePool Interface Implement StorageVolLookupByPath method for Connect Interface Implement Resize method for StorageVol Interface Implement Wipe method for StorageVol Interface Implement GetInfo method for StorageVol Interface Implement Delete method for StorageVol Interface Implement StorageVolCreateXMLFrom method for StoragePool Interface data/Makefile.am | 3 +- data/org.libvirt.Connect.xml | 12 ++ data/org.libvirt.StoragePool.xml | 28 ++++ data/org.libvirt.StorageVol.xml | 51 +++++++ src/Makefile.am | 3 +- src/connect.c | 65 ++++++++ src/connect.h | 1 + src/storagepool.c | 153 +++++++++++++++++++ src/storagevol.c | 321 +++++++++++++++++++++++++++++++++++++++ src/storagevol.h | 9 ++ src/util.c | 35 +++++ src/util.h | 16 ++ tests/libvirttest.py | 17 +++ tests/test_connect.py | 15 ++ tests/test_storage.py | 57 +++++++ 15 files changed, 784 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StorageVol.xml create mode 100644 src/storagevol.c create mode 100644 src/storagevol.h -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/Makefile.am | 3 +- data/org.libvirt.StorageVol.xml | 7 +++ src/Makefile.am | 3 +- src/connect.c | 6 +++ src/connect.h | 1 + src/storagevol.c | 96 +++++++++++++++++++++++++++++++++++++++++ src/storagevol.h | 9 ++++ src/util.c | 35 +++++++++++++++ src/util.h | 16 +++++++ 9 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StorageVol.xml create mode 100644 src/storagevol.c create mode 100644 src/storagevol.h diff --git a/data/Makefile.am b/data/Makefile.am index fdec857..5688cab 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -24,7 +24,8 @@ interfaces_files = \ org.libvirt.Network.xml \ org.libvirt.NWFilter.xml \ org.libvirt.Secret.xml \ - org.libvirt.StoragePool.xml + org.libvirt.StoragePool.xml \ + org.libvirt.StorageVol.xml interfacesdir = $(DBUS_INTERFACES_DIR) interfaces_DATA = $(interfaces_files) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml new file mode 100644 index 0000000..c72c847 --- /dev/null +++ b/data/org.libvirt.StorageVol.xml @@ -0,0 +1,7 @@ +<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" +"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> + +<node name="/org/libvirt/storagevol"> + <interface name="org.libvirt.StorageVol"> + </interface> +</node> diff --git a/src/Makefile.am b/src/Makefile.am index 22128c2..539e722 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,8 @@ DAEMON_SOURCES = \ network.c network.h \ nwfilter.c nwfilter.h \ secret.c secret.h \ - storagepool.c storagepool.h + storagepool.c storagepool.h \ + storagevol.c storagevol.h EXTRA_DIST = \ $(DAEMON_SOURCES) diff --git a/src/connect.c b/src/connect.c index 75ae1cd..1090e3e 100644 --- a/src/connect.c +++ b/src/connect.c @@ -5,6 +5,7 @@ #include "nwfilter.h" #include "secret.h" #include "storagepool.h" +#include "storagevol.h" #include "util.h" #include <gio/gunixfdlist.h> @@ -1612,6 +1613,7 @@ virtDBusConnectFree(virtDBusConnect *connect) g_free(connect->nwfilterPath); g_free(connect->secretPath); g_free(connect->storagePoolPath); + g_free(connect->storageVolPath); g_free(connect); } G_DEFINE_AUTOPTR_CLEANUP_FUNC(virtDBusConnect, virtDBusConnectFree); @@ -1679,6 +1681,10 @@ virtDBusConnectNew(virtDBusConnect **connectp, if (error && *error) return; + virtDBusStorageVolRegister(connect, error); + if (error && *error) + return; + *connectp = connect; connect = NULL; } diff --git a/src/connect.h b/src/connect.h index fe672ed..341dfc4 100644 --- a/src/connect.h +++ b/src/connect.h @@ -17,6 +17,7 @@ struct virtDBusConnect { gchar *nwfilterPath; gchar *secretPath; gchar *storagePoolPath; + gchar *storageVolPath; virConnectPtr connection; GMutex lock; diff --git a/src/storagevol.c b/src/storagevol.c new file mode 100644 index 0000000..dad7d11 --- /dev/null +++ b/src/storagevol.c @@ -0,0 +1,96 @@ +#include "storagevol.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusStorageVolEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePoolPtr) storagePools = NULL; + gint numPools = 0; + gint numVols = 0; + gint numVolsTotal = 0; + gint offset = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + numPools = virConnectListAllStoragePools(connect->connection, + &storagePools, 0); + if (numPools < 0) + return NULL; + + if (numPools == 0) + return NULL; + + for (gint i = 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols = NULL; + + numVols = virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols < 0) + return NULL; + + if (numVols == 0) + return NULL; + + numVolsTotal += numVols; + } + + ret = g_new0(gchar *, numVolsTotal + 1); + + for (gint i = 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols = NULL; + + numVols = virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols < 0) + return NULL; + + if (numVols == 0) + return NULL; + + for (gint j = 0; j < numVols; j++) { + ret[offset] = virtDBusUtilBusPathForVirStorageVol(storageVols[j], + connect->storageVolPath); + offset++; + } + } + + return ret; +} + +static GDBusInterfaceInfo *interfaceInfo; + +void +virtDBusStorageVolRegister(virtDBusConnect *connect, + GError **error) +{ + connect->storageVolPath = g_strdup_printf("%s/storagevol", + connect->connectPath); + + if (!interfaceInfo) { + interfaceInfo = virtDBusGDBusLoadIntrospectData(VIRT_DBUS_STORAGEVOL_INTERFACE, + error); + if (!interfaceInfo) + return; + } + + virtDBusGDBusRegisterSubtree(connect->bus, + connect->storageVolPath, + interfaceInfo, + virtDBusStorageVolEnumerate, + virtDBusStorageVolMethodTable, + virtDBusStorageVolPropertyTable, + connect); +} diff --git a/src/storagevol.h b/src/storagevol.h new file mode 100644 index 0000000..e2a893b --- /dev/null +++ b/src/storagevol.h @@ -0,0 +1,9 @@ +#pragma once + +#include "connect.h" + +#define VIRT_DBUS_STORAGEVOL_INTERFACE "org.libvirt.StorageVol" + +void +virtDBusStorageVolRegister(virtDBusConnect *connect, + GError **error); diff --git a/src/util.c b/src/util.c index 1268736..1d11ce6 100644 --- a/src/util.c +++ b/src/util.c @@ -417,3 +417,38 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools) g_free(storagePools); } + +virStorageVolPtr +virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storageVolPath) +{ + g_autofree gchar *key = NULL; + gsize prefixLen = strlen(storageVolPath); + + key = virtDBusUtilDecodeStr(path + prefixLen + 1); + + return virStorageVolLookupByKey(connection, key); +} + +gchar * +virtDBusUtilBusPathForVirStorageVol(virStorageVolPtr storageVol, + const gchar *storageVolPath) +{ + const gchar *key = NULL; + g_autofree const gchar *encodedKey = NULL; + + key = virStorageVolGetKey(storageVol); + encodedKey = virtDBusUtilEncodeStr(key); + + return g_strdup_printf("%s/%s", storageVolPath, encodedKey); +} + +void +virtDBusUtilVirStorageVolListFree(virStorageVolPtr *storageVols) +{ + for (gint i = 0; storageVols[i] != NULL; i++) + virStorageVolFree(storageVols[i]); + + g_free(storageVols); +} diff --git a/src/util.h b/src/util.h index 56e0409..bf08d5d 100644 --- a/src/util.h +++ b/src/util.h @@ -133,3 +133,19 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePool, virStoragePoolFree); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStoragePoolPtr, virtDBusUtilVirStoragePoolListFree); + +virStorageVolPtr +virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storageVolPath); + +gchar * +virtDBusUtilBusPathForVirStorageVol(virStorageVolPtr storageVol, + const gchar *storageVolPath); + +void +virtDBusUtilVirStorageVolListFree(virStorageVolPtr *storageVols); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVol, virStorageVolFree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virStorageVolPtr, + virtDBusUtilVirStorageVolListFree); -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:14AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/Makefile.am | 3 +- data/org.libvirt.StorageVol.xml | 7 +++ src/Makefile.am | 3 +- src/connect.c | 6 +++ src/connect.h | 1 + src/storagevol.c | 96 +++++++++++++++++++++++++++++++++++++++++ src/storagevol.h | 9 ++++ src/util.c | 35 +++++++++++++++ src/util.h | 16 +++++++ 9 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StorageVol.xml create mode 100644 src/storagevol.c create mode 100644 src/storagevol.h
diff --git a/data/Makefile.am b/data/Makefile.am index fdec857..5688cab 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -24,7 +24,8 @@ interfaces_files = \ org.libvirt.Network.xml \ org.libvirt.NWFilter.xml \ org.libvirt.Secret.xml \ - org.libvirt.StoragePool.xml + org.libvirt.StoragePool.xml \ + org.libvirt.StorageVol.xml
org.libvirt.StorageVol.xml \ $(NULL) That way all the future additions can include the trailing slash, making for nicer diffs.
interfacesdir = $(DBUS_INTERFACES_DIR) interfaces_DATA = $(interfaces_files)
diff --git a/src/Makefile.am b/src/Makefile.am index 22128c2..539e722 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -12,7 +12,8 @@ DAEMON_SOURCES = \ network.c network.h \ nwfilter.c nwfilter.h \ secret.c secret.h \ - storagepool.c storagepool.h + storagepool.c storagepool.h \ + storagevol.c storagevol.h
$(NULL) here as well
EXTRA_DIST = \ $(DAEMON_SOURCES)
diff --git a/src/storagevol.c b/src/storagevol.c new file mode 100644 index 0000000..dad7d11 --- /dev/null +++ b/src/storagevol.c @@ -0,0 +1,96 @@ +#include "storagevol.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusStorageVolEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePoolPtr) storagePools = NULL; + gint numPools = 0; + gint numVols = 0; + gint numVolsTotal = 0; + gint offset = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + numPools = virConnectListAllStoragePools(connect->connection, + &storagePools, 0); + if (numPools < 0) + return NULL; + + if (numPools == 0) + return NULL; + + for (gint i = 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols = NULL; + + numVols = virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols < 0) + return NULL; + + if (numVols == 0) + return NULL; + + numVolsTotal += numVols; + } + + ret = g_new0(gchar *, numVolsTotal + 1); + + for (gint i = 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols = NULL; + + numVols = virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0);
We don't need to list the volumes twice, not only it seems inefficient, the number of volumes can change in the meantime, leading to possible invalid memory access. Possibly an APPEND_ELEMENT macro similar to what we have in libvirt, so that we can test it separately in test_util.c.
+ if (numVols < 0) + return NULL;
This would leak ret.
+ + if (numVols == 0) + return NULL; + + for (gint j = 0; j < numVols; j++) { + ret[offset] = virtDBusUtilBusPathForVirStorageVol(storageVols[j], + connect->storageVolPath); + offset++; + } + } + + return ret; +} +
diff --git a/src/util.c b/src/util.c index 1268736..1d11ce6 100644 --- a/src/util.c +++ b/src/util.c @@ -417,3 +417,38 @@ virtDBusUtilVirStoragePoolListFree(virStoragePoolPtr *storagePools)
g_free(storagePools); } + +virStorageVolPtr +virtDBusUtilVirStorageVolFromBusPath(virConnectPtr connection, + const gchar *path, + const gchar *storageVolPath) +{ + g_autofree gchar *key = NULL; + gsize prefixLen = strlen(storageVolPath); + + key = virtDBusUtilDecodeStr(path + prefixLen + 1);
In other cases, the + 1 is a part of the prefixLen.
+ + return virStorageVolLookupByKey(connection, key); +} +
Jano

On Wed, Jun 13, 2018 at 04:21:33PM +0200, Ján Tomko wrote:
On Tue, Jun 12, 2018 at 11:00:14AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/Makefile.am | 3 +- data/org.libvirt.StorageVol.xml | 7 +++ src/Makefile.am | 3 +- src/connect.c | 6 +++ src/connect.h | 1 + src/storagevol.c | 96 +++++++++++++++++++++++++++++++++++++++++ src/storagevol.h | 9 ++++ src/util.c | 35 +++++++++++++++ src/util.h | 16 +++++++ 9 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 data/org.libvirt.StorageVol.xml create mode 100644 src/storagevol.c create mode 100644 src/storagevol.h
[...]
diff --git a/src/storagevol.c b/src/storagevol.c new file mode 100644 index 0000000..dad7d11 --- /dev/null +++ b/src/storagevol.c @@ -0,0 +1,96 @@ +#include "storagevol.h" +#include "util.h" + +#include <libvirt/libvirt.h> + +static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { + { 0 } +}; + +static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { + { 0 } +}; + +static gchar ** +virtDBusStorageVolEnumerate(gpointer userData) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePoolPtr) storagePools = NULL; + gint numPools = 0; + gint numVols = 0; + gint numVolsTotal = 0; + gint offset = 0; + gchar **ret = NULL; + + if (!virtDBusConnectOpen(connect, NULL)) + return NULL; + + numPools = virConnectListAllStoragePools(connect->connection, + &storagePools, 0); + if (numPools < 0) + return NULL; + + if (numPools == 0) + return NULL; + + for (gint i = 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols = NULL; + + numVols = virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0); + if (numVols < 0) + return NULL; + + if (numVols == 0) + return NULL; + + numVolsTotal += numVols; + } + + ret = g_new0(gchar *, numVolsTotal + 1); + + for (gint i = 0; i < numPools; i++) { + g_autoptr(virStorageVolPtr) storageVols = NULL; + + numVols = virStoragePoolListAllVolumes(storagePools[i], + &storageVols, 0);
We don't need to list the volumes twice, not only it seems inefficient, the number of volumes can change in the meantime, leading to possible invalid memory access.
Possibly an APPEND_ELEMENT macro similar to what we have in libvirt, so that we can test it separately in test_util.c.
Or we can use GPtrArray.
+ if (numVols < 0) + return NULL;
This would leak ret.
+ + if (numVols == 0) + return NULL;
I thing that in both cases we should call 'continue' instead to use best-effort approach. The loop can look like this: list = g_ptr_array_new(); for (gint i = 0; i < numPools; i++) { g_autoptr(virStorageVolPtr) storageVols = NULL; gint numVols; numVols = virStoragePoolListAllVolumes(storagePools[i], &storageVols, 0); if (numVols <= 0) continue; for (gint j = 0; j < numVols; j++) { gchar *volPath = virtDBusUtilBusPathForVirStorageVol(storageVols[j], connect->storageVolPath); g_ptr_array_add(list, volPath); } } if (list->len > 0) g_ptr_array_add(list, NULL); return (gchar **)g_ptr_array_free(list, FALSE); Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 6 ++++++ src/storagepool.c | 44 ++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 8 ++++++++ 3 files changed, 58 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..11e356c 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -301,6 +301,49 @@ virtDBusStoragePoolGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusStoragePoolListAllVolumes(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; + g_autofree gchar *xml = 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 +406,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "Destroy", virtDBusStoragePoolDestroy }, { "GetInfo", virtDBusStoragePoolGetInfo }, { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, + { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes }, { "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

On Tue, Jun 12, 2018 at 11:00:15AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 6 ++++++ src/storagepool.c | 44 ++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 8 ++++++++ 3 files changed, 58 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..11e356c 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -301,6 +301,49 @@ virtDBusStoragePoolGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); }
+static void +virtDBusStoragePoolListAllVolumes(GVariant *inArgs,
s/ListAll/List/ The other DBus wrappers around *ListAll APIs do not include All in their names.
+ 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; + g_autofree gchar *xml = NULL;
My CLang complains: storagepool.c:316:23: error: unused variable 'xml' [-Werror,-Wunused-variable] g_autofree gchar *xml = 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++) {
Missing space before <.
+ 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);
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 7 +++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ tests/libvirttest.py | 17 +++++++++++++++++ tests/test_storage.py | 4 ++++ 4 files changed, 62 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 764c9c1..51d65ab 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -68,6 +68,13 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="StorageVolCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/> diff --git a/src/storagepool.c b/src/storagepool.c index 11e356c..c3fd0bf 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -368,6 +368,39 @@ virtDBusStoragePoolRefresh(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStoragePoolStorageVolCreateXML(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(virStorageVol) storageVol = NULL; + gchar *xml; + guint flags; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + storageVol = virStorageVolCreateXML(storagePool, xml, flags); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusStoragePoolUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -408,6 +441,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, + { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } }; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 3cd02ef..f65251a 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -100,6 +100,23 @@ class BaseTestClass(): obj = self.bus.get_object('org.libvirt', path) return path, obj + def test_storage_vol(self): + minimal_storage_vol_xml = ''' + <volume> + <name>sparse.img</name> + <capacity unit="G">2</capacity> + <target> + <path>/var/lib/virt/images/sparse.img</path> + </target> + </volume> + ''' + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + path = interface_obj.StorageVolCreateXML(minimal_storage_vol_xml, 0) + obj = self.bus.get_object('org.libvirt', path) + return path, obj + class DomainEvent(IntEnum): DEFINED = 0 diff --git a/tests/test_storage.py b/tests/test_storage.py index 79e0c16..1cd1249 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -126,6 +126,10 @@ class TestStoragePool(libvirttest.BaseTestClass): self.main_loop() + def test_storage_pool_volume_create(self): + path, _ = self.test_storage_vol() + assert isinstance(path, dbus.ObjectPath) + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:16AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 7 +++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ tests/libvirttest.py | 17 +++++++++++++++++ tests/test_storage.py | 4 ++++ 4 files changed, 62 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On Tue, Jun 12, 2018 at 11:00:16AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 7 +++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ tests/libvirttest.py | 17 +++++++++++++++++ tests/test_storage.py | 4 ++++ 4 files changed, 62 insertions(+)
diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 764c9c1..51d65ab 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -68,6 +68,13 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolRefresh"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="StorageVolCreateXML"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML"/> + <arg name="xml" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/> diff --git a/src/storagepool.c b/src/storagepool.c index 11e356c..c3fd0bf 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -368,6 +368,39 @@ virtDBusStoragePoolRefresh(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); }
+static void +virtDBusStoragePoolStorageVolCreateXML(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(virStorageVol) storageVol = NULL; + gchar *xml; + guint flags; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(&su)", &xml, &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + storageVol = virStorageVolCreateXML(storagePool, xml, flags); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusStoragePoolUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -408,6 +441,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "GetXMLDesc", virtDBusStoragePoolGetXMLDesc }, { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, + { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } }; diff --git a/tests/libvirttest.py b/tests/libvirttest.py index 3cd02ef..f65251a 100644 --- a/tests/libvirttest.py +++ b/tests/libvirttest.py @@ -100,6 +100,23 @@ class BaseTestClass(): obj = self.bus.get_object('org.libvirt', path) return path, obj
+ def test_storage_vol(self): + minimal_storage_vol_xml = ''' + <volume> + <name>sparse.img</name> + <capacity unit="G">2</capacity> + <target> + <path>/var/lib/virt/images/sparse.img</path> + </target> + </volume> + ''' + _, test_storage_pool = self.test_storage_pool() + interface_obj = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + path = interface_obj.StorageVolCreateXML(minimal_storage_vol_xml, 0) + obj = self.bus.get_object('org.libvirt', path) + return path, obj
Right, so there is no default volume defined for the test driver so we cannot use the same approach as for other object types. However, the XML of the new storage volume should be in the storage_pool test file as we have new domain XML in the connect test file. Or we can move all the XMLs into specific file and include it.
+
class DomainEvent(IntEnum): DEFINED = 0 diff --git a/tests/test_storage.py b/tests/test_storage.py index 79e0c16..1cd1249 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -126,6 +126,10 @@ class TestStoragePool(libvirttest.BaseTestClass):
self.main_loop()
+ def test_storage_pool_volume_create(self): + path, _ = self.test_storage_vol() + assert isinstance(path, dbus.ObjectPath) +
The test_storage_vol hides the actual StorageVolCreateXML call. I understand the we need to create the storage volume for every single test-case because the libvirt-dbus deamon is restarted every time. It would be nice to do it differently, for example to have some method that would precreate the storage volume and this one would do the same as for other objects. Otherwise looks good. If it turn out to be difficult to make it work that way we can use this current solution for tests. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 44 +++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 9 +++++++++ 3 files changed, 58 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index c72c847..3110b4f 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -3,5 +3,10 @@ <node name="/org/libvirt/storagevol"> <interface name="org.libvirt.StorageVol"> + <property name="Name" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetName"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index dad7d11..70bc2bc 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -3,7 +3,51 @@ #include <libvirt/libvirt.h> +static virStorageVolPtr +virtDBusStorageVolGetVirStorageVol(virtDBusConnect *connect, + const gchar *objectPath, + GError **error) +{ + virStorageVolPtr storageVol; + + if (virtDBusConnectOpen(connect, error) < 0) + return NULL; + + storageVol = virtDBusUtilVirStorageVolFromBusPath(connect->connection, + objectPath, + connect->storageVolPath); + if (!storageVol) { + virtDBusUtilSetLastVirtError(error); + return NULL; + } + + return storageVol; +} + +static void +virtDBusStorageVolGetName(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + const gchar *name; + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + name = virStorageVolGetName(storageVol); + if (!name) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", name); +} + static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { + { "Name", virtDBusStorageVolGetName, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 1cd1249..bfdd084 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -131,5 +131,14 @@ class TestStoragePool(libvirttest.BaseTestClass): assert isinstance(path, dbus.ObjectPath) +class TestStorageVolume(libvirttest.BaseTestClass): + def test_storage_vol_properties_type(self): + _, obj = self.test_storage_vol() + + props = obj.GetAll('org.libvirt.StorageVol', + dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Name'], dbus.String) + + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:17AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 44 +++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 9 +++++++++ 3 files changed, 58 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 29 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index 3110b4f..3b36f3b 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -8,5 +8,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetName"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="Key" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetKey"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index 70bc2bc..82d81ab 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -46,8 +46,31 @@ virtDBusStorageVolGetName(const gchar *objectPath, *value = g_variant_new("s", name); } +static void +virtDBusStorageVolGetKey(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + const gchar *key; + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + key = virStorageVolGetKey(storageVol); + if (!key) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", key); +} + static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { { "Name", virtDBusStorageVolGetName, NULL }, + { "Key", virtDBusStorageVolGetKey, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index bfdd084..7aa887d 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -137,6 +137,7 @@ class TestStorageVolume(libvirttest.BaseTestClass): props = obj.GetAll('org.libvirt.StorageVol', dbus_interface=dbus.PROPERTIES_IFACE) + assert isinstance(props['Key'], dbus.String) assert isinstance(props['Name'], dbus.String) -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:18AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 29 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 29 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index 3b36f3b..03c15c2 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -13,5 +13,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetKey"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="Path" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index 82d81ab..c65e11a 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -68,9 +68,32 @@ virtDBusStorageVolGetKey(const gchar *objectPath, *value = g_variant_new("s", key); } +static void +virtDBusStorageVolGetPath(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + const gchar *key; + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + key = virStorageVolGetPath(storageVol); + if (!key) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", key); +} + static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { { "Name", virtDBusStorageVolGetName, NULL }, { "Key", virtDBusStorageVolGetKey, NULL }, + { "Path", virtDBusStorageVolGetPath, NULL }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index 7aa887d..a430808 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -139,6 +139,7 @@ class TestStorageVolume(libvirttest.BaseTestClass): dbus_interface=dbus.PROPERTIES_IFACE) assert isinstance(props['Key'], dbus.String) assert isinstance(props['Name'], dbus.String) + assert isinstance(props['Path'], dbus.String) if __name__ == '__main__': -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:19AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 29 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On Tue, Jun 12, 2018 at 11:00:19AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 23 +++++++++++++++++++++++ tests/test_storage.py | 1 + 3 files changed, 29 insertions(+)
diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index 3b36f3b..03c15c2 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -13,5 +13,10 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetKey"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <property name="Path" type="s" access="read"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath"/> + <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> + </property> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index 82d81ab..c65e11a 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -68,9 +68,32 @@ virtDBusStorageVolGetKey(const gchar *objectPath, *value = g_variant_new("s", key); }
+static void +virtDBusStorageVolGetPath(const gchar *objectPath, + gpointer userData, + GVariant **value, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + const gchar *key; +
g_autofree gchar *path; virStorageVolGetPath returns a strdup'd string, unlike virStorageVolGetKey Jano
+ storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + key = virStorageVolGetPath(storageVol); + if (!key) + return virtDBusUtilSetLastVirtError(error); + + *value = g_variant_new("s", key); +}

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 29 +++++++++++++++++++++++++++++ tests/test_storage.py | 7 +++++++ 3 files changed, 42 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index 03c15c2..c1fecf3 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -18,5 +18,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <method name="GetXMLDesc"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetXMLDesc"/> + <arg name="flags" type="u" direction="in"/> + <arg name="xml" type="s" direction="out"/> + </method> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index c65e11a..efe88d3 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -90,6 +90,34 @@ virtDBusStorageVolGetPath(const gchar *objectPath, *value = g_variant_new("s", key); } +static void +virtDBusStorageVolGetXMLDesc(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(virStorageVol) storageVol = NULL; + g_autofree gchar *xml = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + xml = virStorageVolGetXMLDesc(storageVol, flags); + if (!xml) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(s)", xml); +} + static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { { "Name", virtDBusStorageVolGetName, NULL }, { "Key", virtDBusStorageVolGetKey, NULL }, @@ -98,6 +126,7 @@ static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { + { "GetXMLDesc", virtDBusStorageVolGetXMLDesc }, { 0 } }; diff --git a/tests/test_storage.py b/tests/test_storage.py index a430808..1d0afe0 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -141,6 +141,13 @@ class TestStorageVolume(libvirttest.BaseTestClass): assert isinstance(props['Name'], dbus.String) assert isinstance(props['Path'], dbus.String) + def test_storage_vol_get_xml_description(self): + _, test_storage_vol = self.test_storage_vol() + interface_obj = dbus.Interface(test_storage_vol, + 'org.libvirt.StorageVol') + xml = interface_obj.GetXMLDesc(0) + assert isinstance(xml, dbus.String) + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:20AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 29 +++++++++++++++++++++++++++++ tests/test_storage.py | 7 +++++++ 3 files changed, 42 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ tests/test_connect.py | 14 ++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f41acd2..d3871b3 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -308,6 +308,12 @@ <arg name="uuid" type="s" direction="in"/> <arg name="storagePool" type="o" direction="out"/> </method> + <method name="StorageVolLookupByKey"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByKey"/> + <arg name="key" type="s" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <signal name="DomainEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/> diff --git a/src/connect.c b/src/connect.c index 1090e3e..c526808 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1544,6 +1544,35 @@ virtDBusConnectStoragePoolLookupByUUID(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectStorageVolLookupByKey(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + g_autofree gchar *path = NULL; + const gchar *key; + + g_variant_get(inArgs, "(s)", &key); + + if (!virtDBusConnectOpen(connect, error)) + return; + + storageVol = virStorageVolLookupByKey(connect->connection, key); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -1597,6 +1626,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "StoragePoolDefineXML", virtDBusConnectStoragePoolDefineXML }, { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName }, { "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID }, + { "StorageVolLookupByKey", virtDBusConnectStorageVolLookupByKey }, { 0 } }; diff --git a/tests/test_connect.py b/tests/test_connect.py index da146a4..fc4ca78 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -245,6 +245,20 @@ class TestConnect(libvirttest.BaseTestClass): path = getattr(self.connect, lookup_method_name)(prop) assert original_path == path + @pytest.mark.parametrize("lookup_method_name,lookup_item", [ + ("StorageVolLookupByKey", 'Key'), + ]) + def test_connect_storage_vol_lookup_by_property(self, + lookup_method_name, + lookup_item): + """Parameterized test for all StorageVolLookupBy* API calls of Connect interface + """ + original_path, obj = self.test_storage_vol() + prop = obj.Get('org.libvirt.StorageVol', lookup_item, + dbus_interface=dbus.PROPERTIES_IFACE) + path = getattr(self.connect, lookup_method_name)(prop) + assert original_path == path + if __name__ == '__main__': libvirttest.run() -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:21AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ tests/test_connect.py | 14 ++++++++++++++ 3 files changed, 50 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On Tue, Jun 12, 2018 at 11:00:21AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 30 ++++++++++++++++++++++++++++++ tests/test_connect.py | 14 ++++++++++++++ 3 files changed, 50 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f41acd2..d3871b3 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -308,6 +308,12 @@ <arg name="uuid" type="s" direction="in"/> <arg name="storagePool" type="o" direction="out"/> </method> + <method name="StorageVolLookupByKey"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByKey"/> + <arg name="key" type="s" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <signal name="DomainEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/> diff --git a/src/connect.c b/src/connect.c index 1090e3e..c526808 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1544,6 +1544,35 @@ virtDBusConnectStoragePoolLookupByUUID(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusConnectStorageVolLookupByKey(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + g_autofree gchar *path = NULL; + const gchar *key; + + g_variant_get(inArgs, "(s)", &key);
&s Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 6 ++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 51d65ab..161ade5 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -75,6 +75,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="storageVol" type="o" direction="out"/> </method> + <method name="StorageVolLookupByName"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByName"/> + <arg name="name" type="s" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="Undefine"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStoragePoolUndefine"/> diff --git a/src/storagepool.c b/src/storagepool.c index c3fd0bf..55077ed 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -401,6 +401,39 @@ virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusStoragePoolStorageVolLookupByName(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + g_autoptr(virStorageVol) storageVol = NULL; + g_autofree gchar *path = NULL; + const gchar *name; + + g_variant_get(inArgs, "(&s)", &name); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + storageVol = virStorageVolLookupByName(storagePool, name); + + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusStoragePoolUndefine(GVariant *inArgs G_GNUC_UNUSED, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -442,6 +475,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML }, + { "StorageVolLookupByName", virtDBusStoragePoolStorageVolLookupByName }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } }; -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:22AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 6 ++++++ src/storagepool.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+)
diff --git a/src/storagepool.c b/src/storagepool.c index c3fd0bf..55077ed 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -401,6 +401,39 @@ virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusStoragePoolStorageVolLookupByName(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED,
objectPath is actually used.
+ gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStoragePool) storagePool = NULL; + g_autoptr(virStorageVol) storageVol = NULL; + g_autofree gchar *path = NULL; + const gchar *name; +
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ tests/test_connect.py | 1 + 3 files changed, 36 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index d3871b3..37daed0 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -314,6 +314,12 @@ <arg name="key" type="s" direction="in"/> <arg name="storageVol" type="o" direction="out"/> </method> + <method name="StorageVolLookupByPath"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByPath"/> + <arg name="path" type="s" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <signal name="DomainEvent"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virConnectDomainEventCallback"/> diff --git a/src/connect.c b/src/connect.c index c526808..157cdb3 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1573,6 +1573,34 @@ virtDBusConnectStorageVolLookupByKey(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectStorageVolLookupByPath(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(s)", &path); + + if (!virtDBusConnectOpen(connect, error)) + return; + + storageVol = virStorageVolLookupByPath(connect->connection, path); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -1627,6 +1655,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "StoragePoolLookupByName", virtDBusConnectStoragePoolLookupByName }, { "StoragePoolLookupByUUID", virtDBusConnectStoragePoolLookupByUUID }, { "StorageVolLookupByKey", virtDBusConnectStorageVolLookupByKey }, + { "StorageVolLookupByPath", virtDBusConnectStorageVolLookupByPath }, { 0 } }; diff --git a/tests/test_connect.py b/tests/test_connect.py index fc4ca78..80bb50b 100755 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -247,6 +247,7 @@ class TestConnect(libvirttest.BaseTestClass): @pytest.mark.parametrize("lookup_method_name,lookup_item", [ ("StorageVolLookupByKey", 'Key'), + ("StorageVolLookupByPath", 'Path'), ]) def test_connect_storage_vol_lookup_by_property(self, lookup_method_name, -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:23AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 29 +++++++++++++++++++++++++++++ tests/test_connect.py | 1 + 3 files changed, 36 insertions(+)
diff --git a/src/connect.c b/src/connect.c index c526808..157cdb3 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1573,6 +1573,34 @@ virtDBusConnectStorageVolLookupByKey(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusConnectStorageVolLookupByPath(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath G_GNUC_UNUSED, + gpointer userData, + GVariant **outArgs, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(s)", &path);
I'd suggest using a different variable for the input parameter, e.g. const gchar *inPath and "(&s)" here, to save g_variant_get the trouble of strdup-ing the path and us the trouble of freeing it before reusing the variable for the storage volume object path. Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
+ + if (!virtDBusConnectOpen(connect, error)) + return; + + storageVol = virStorageVolLookupByPath(connect->connection, path); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); +

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index c1fecf3..fdde430 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -24,5 +24,11 @@ <arg name="flags" type="u" direction="in"/> <arg name="xml" type="s" direction="out"/> </method> + <method name="Resize"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolResize"/> + <arg name="capacity" type="t" direction="in"/> + <arg name="flags" type="u" direction="in"/> + </method> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index efe88d3..66f7c86 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -118,6 +118,31 @@ virtDBusStorageVolGetXMLDesc(GVariant *inArgs, *outArgs = g_variant_new("(s)", xml); } +static void +virtDBusStorageVolResize(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + guint64 capacity; + guint flags; + + g_variant_get(inArgs, "(tu)", &capacity, &flags); + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + if (virStorageVolResize(storageVol, capacity, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { { "Name", virtDBusStorageVolGetName, NULL }, { "Key", virtDBusStorageVolGetKey, NULL }, @@ -127,6 +152,7 @@ static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { { "GetXMLDesc", virtDBusStorageVolGetXMLDesc }, + { "Resize", virtDBusStorageVolResize }, { 0 } }; -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:24AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index fdde430..aed3f7a 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -30,5 +30,11 @@ <arg name="capacity" type="t" direction="in"/> <arg name="flags" type="u" direction="in"/> </method> + <method name="Wipe"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolWipePattern"/> + <arg name="pattern" type="u" direction="in"/> + <arg name="flags" type="u" direction="in"/> + </method> </interface> </node> diff --git a/src/storagevol.c b/src/storagevol.c index 66f7c86..91d99e7 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -143,6 +143,31 @@ virtDBusStorageVolResize(GVariant *inArgs, virtDBusUtilSetLastVirtError(error); } +static void +virtDBusStorageVolWipe(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + guint pattern; + guint flags; + + g_variant_get(inArgs, "(uu)", &pattern, &flags); + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + if (virStorageVolWipePattern(storageVol, pattern, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { { "Name", virtDBusStorageVolGetName, NULL }, { "Key", virtDBusStorageVolGetKey, NULL }, @@ -153,6 +178,7 @@ static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { { "GetXMLDesc", virtDBusStorageVolGetXMLDesc }, { "Resize", virtDBusStorageVolResize }, + { "Wipe", virtDBusStorageVolWipe }, { 0 } }; -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:25AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On Tue, Jun 12, 2018 at 11:00:25AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+)
+ if (!storageVol) + return; + + if (virStorageVolWipePattern(storageVol, pattern, flags) < 0)
Also, double space ----------------------------^ Jano
+ virtDBusUtilSetLastVirtError(error); +} +

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index aed3f7a..8a4eab2 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -18,6 +18,12 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <method name="GetInfo"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetInfoFlags"/> + <arg name="flags" type="u" direction="in"/> + <arg name="info" type="(itt)" direction="out"/> + </method> <method name="GetXMLDesc"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetXMLDesc"/> diff --git a/src/storagevol.c b/src/storagevol.c index 91d99e7..dc05dc4 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -90,6 +90,34 @@ virtDBusStorageVolGetPath(const gchar *objectPath, *value = g_variant_new("s", key); } +static void +virtDBusStorageVolGetInfo(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(virStorageVol) storageVol = NULL; + virStorageVolInfo info; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + if (virStorageVolGetInfoFlags(storageVol, &info, flags) < 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("((itt))", info.type, info.capacity, + info.allocation); +} + static void virtDBusStorageVolGetXMLDesc(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -176,6 +204,7 @@ static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { + { "GetInfo", virtDBusStorageVolGetInfo }, { "GetXMLDesc", virtDBusStorageVolGetXMLDesc }, { "Resize", virtDBusStorageVolResize }, { "Wipe", virtDBusStorageVolWipe }, -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:26AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 6 ++++++ src/storagevol.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 25 +++++++++++++++++++++++++ tests/test_storage.py | 6 ++++++ 3 files changed, 36 insertions(+) diff --git a/data/org.libvirt.StorageVol.xml b/data/org.libvirt.StorageVol.xml index 8a4eab2..7ad9459 100644 --- a/data/org.libvirt.StorageVol.xml +++ b/data/org.libvirt.StorageVol.xml @@ -18,6 +18,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetPath"/> <annotation name="org.freedesktop.DBus.Property.EmitsChangedSignal" value="const"/> </property> + <method name="Delete"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolDelete"/> + <arg name="flags" type="u" direction="in"/> + </method> <method name="GetInfo"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolGetInfoFlags"/> diff --git a/src/storagevol.c b/src/storagevol.c index dc05dc4..c574be9 100644 --- a/src/storagevol.c +++ b/src/storagevol.c @@ -90,6 +90,30 @@ virtDBusStorageVolGetPath(const gchar *objectPath, *value = g_variant_new("s", key); } +static void +virtDBusStorageVolDelete(GVariant *inArgs, + GUnixFDList *inFDs G_GNUC_UNUSED, + const gchar *objectPath, + gpointer userData, + GVariant **outArgs G_GNUC_UNUSED, + GUnixFDList **outFDs G_GNUC_UNUSED, + GError **error) +{ + virtDBusConnect *connect = userData; + g_autoptr(virStorageVol) storageVol = NULL; + guint flags; + + g_variant_get(inArgs, "(u)", &flags); + + storageVol = virtDBusStorageVolGetVirStorageVol(connect, objectPath, + error); + if (!storageVol) + return; + + if (virStorageVolDelete(storageVol, flags) < 0) + virtDBusUtilSetLastVirtError(error); +} + static void virtDBusStorageVolGetInfo(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -204,6 +228,7 @@ static virtDBusGDBusPropertyTable virtDBusStorageVolPropertyTable[] = { }; static virtDBusGDBusMethodTable virtDBusStorageVolMethodTable[] = { + { "Delete", virtDBusStorageVolDelete }, { "GetInfo", virtDBusStorageVolGetInfo }, { "GetXMLDesc", virtDBusStorageVolGetXMLDesc }, { "Resize", virtDBusStorageVolResize }, diff --git a/tests/test_storage.py b/tests/test_storage.py index 1d0afe0..f342e77 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -132,6 +132,12 @@ class TestStoragePool(libvirttest.BaseTestClass): class TestStorageVolume(libvirttest.BaseTestClass): + def test_storage_vol_delete(self): + test_storage_vol_path, test_storage_vol = self.test_storage_vol() + interface_obj = dbus.Interface(test_storage_vol, + 'org.libvirt.StorageVol') + interface_obj.Delete(0) + def test_storage_vol_properties_type(self): _, obj = self.test_storage_vol() -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:27AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StorageVol.xml | 5 +++++ src/storagevol.c | 25 +++++++++++++++++++++++++ tests/test_storage.py | 6 ++++++ 3 files changed, 36 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 9 +++++++++ src/storagepool.c | 41 ++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 21 ++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 161ade5..0a324e6 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -75,6 +75,15 @@ <arg name="flags" type="u" direction="in"/> <arg name="storageVol" type="o" direction="out"/> </method> + <method name="StorageVolCreateXMLFrom"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML... + Call with @key argument set to the key of the storage volume to be cloned."/> + <arg name="xml" type="s" direction="in"/> + <arg name="key" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="StorageVolLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByName"/> diff --git a/src/storagepool.c b/src/storagepool.c index 55077ed..854ca7d 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -401,6 +401,46 @@ virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusStoragePoolStorageVolCreateXMLFrom(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(virStorageVol) storageVol = NULL; + g_autoptr(virStorageVol) storageVolOld = NULL; + gchar *key; + gchar *xml; + guint flags; + g_autofree gchar *path = NULL; + + g_variant_get(inArgs, "(&s&su)", &xml, &key, &flags); + + storagePool = virtDBusStoragePoolGetVirStoragePool(connect, objectPath, + error); + if (!storagePool) + return; + + storageVolOld = virStorageVolLookupByKey(connect->connection, key); + if (!storageVolOld) + return virtDBusUtilSetLastVirtError(error); + + storageVol = virStorageVolCreateXMLFrom(storagePool, xml, storageVolOld, + flags); + if (!storageVol) + return virtDBusUtilSetLastVirtError(error); + + path = virtDBusUtilBusPathForVirStorageVol(storageVol, + connect->storageVolPath); + + *outArgs = g_variant_new("(o)", path); +} + static void virtDBusStoragePoolStorageVolLookupByName(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -475,6 +515,7 @@ static virtDBusGDBusMethodTable virtDBusStoragePoolMethodTable[] = { { "ListStorageVolumes", virtDBusStoragePoolListAllVolumes }, { "Refresh", virtDBusStoragePoolRefresh }, { "StorageVolCreateXML", virtDBusStoragePoolStorageVolCreateXML }, + { "StorageVolCreateXMLFrom", virtDBusStoragePoolStorageVolCreateXMLFrom }, { "StorageVolLookupByName", virtDBusStoragePoolStorageVolLookupByName }, { "Undefine", virtDBusStoragePoolUndefine }, { 0 } diff --git a/tests/test_storage.py b/tests/test_storage.py index f342e77..8a0c4f6 100755 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -130,6 +130,27 @@ class TestStoragePool(libvirttest.BaseTestClass): path, _ = self.test_storage_vol() assert isinstance(path, dbus.ObjectPath) + def test_storage_pool_volume_create_xml_from(self): + minimal_storage_vol_clone_xml = ''' + <volume> + <name>clone.img</name> + <capacity unit="G">1</capacity> + </volume> + ''' + _, test_storage_vol = self.test_storage_vol() + props = test_storage_vol.GetAll('org.libvirt.StorageVol', + dbus_interface=dbus.PROPERTIES_IFACE) + test_storage_vol_key = str(props['Key']) + + _, test_storage_pool = self.test_storage_pool() + storage_pool_iface = dbus.Interface(test_storage_pool, + 'org.libvirt.StoragePool') + + new_vol_path = storage_pool_iface.StorageVolCreateXMLFrom(minimal_storage_vol_clone_xml, + test_storage_vol_key, + 0) + assert isinstance(new_vol_path, dbus.ObjectPath) + class TestStorageVolume(libvirttest.BaseTestClass): def test_storage_vol_delete(self): -- 2.15.0

On Tue, Jun 12, 2018 at 11:00:28AM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.StoragePool.xml | 9 +++++++++ src/storagepool.c | 41 ++++++++++++++++++++++++++++++++++++++++ tests/test_storage.py | 21 ++++++++++++++++++++ 3 files changed, 71 insertions(+)
diff --git a/data/org.libvirt.StoragePool.xml b/data/org.libvirt.StoragePool.xml index 161ade5..0a324e6 100644 --- a/data/org.libvirt.StoragePool.xml +++ b/data/org.libvirt.StoragePool.xml @@ -75,6 +75,15 @@ <arg name="flags" type="u" direction="in"/> <arg name="storageVol" type="o" direction="out"/> </method> + <method name="StorageVolCreateXMLFrom"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolCreateXML... + Call with @key argument set to the key of the storage volume to be cloned."/> + <arg name="xml" type="s" direction="in"/> + <arg name="key" type="s" direction="in"/> + <arg name="flags" type="u" direction="in"/> + <arg name="storageVol" type="o" direction="out"/> + </method> <method name="StorageVolLookupByName"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-storage.html#virStorageVolLookupByName"/> diff --git a/src/storagepool.c b/src/storagepool.c index 55077ed..854ca7d 100644 --- a/src/storagepool.c +++ b/src/storagepool.c @@ -401,6 +401,46 @@ virtDBusStoragePoolStorageVolCreateXML(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); }
+static void +virtDBusStoragePoolStorageVolCreateXMLFrom(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(virStorageVol) storageVol = NULL; + g_autoptr(virStorageVol) storageVolOld = NULL; + gchar *key;
const
+ gchar *xml;
const
+ guint flags; + g_autofree gchar *path = NULL; +
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (3)
-
Ján Tomko
-
Katerina Koukiou
-
Pavel Hrdina