Signed-off-by: Katerina Koukiou <kkouk...@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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to