[libvirt] [dbus PATCH v2 12/17] Implement StorageVolLookupByPath method for Connect Interface

Katerina Koukiou kkoukiou at redhat.com
Thu Jun 14 15:59:48 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at redhat.com>
Reviewed-by: Ján Tomko <jtomko at redhat.com>
---
 data/org.libvirt.Connect.xml |  6 ++++++
 src/connect.c                | 30 ++++++++++++++++++++++++++++++
 tests/test_connect.py        |  1 +
 3 files changed, 37 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 ff9d91a..4f2bdb6 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -1573,6 +1573,35 @@ 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;
+    const gchar *inPath;
+    g_autofree gchar *path = NULL;
+
+    g_variant_get(inArgs, "(&s)", &inPath);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    storageVol = virStorageVolLookupByPath(connect->connection, inPath);
+    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 +1656,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 5182769..57b385e 100755
--- a/tests/test_connect.py
+++ b/tests/test_connect.py
@@ -215,6 +215,7 @@ class TestConnect(libvirttest.BaseTestClass):
     @pytest.mark.usefixtures("storage_volume_create")
     @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




More information about the libvir-list mailing list