[libvirt] [dbus PATCH 10/15] Implement StorageVolLookupByPath method for Connect Interface

Katerina Koukiou posted 15 patches 7 years, 6 months ago
There is a newer version of this series
[libvirt] [dbus PATCH 10/15] Implement StorageVolLookupByPath method for Connect Interface
Posted by Katerina Koukiou 7 years, 6 months ago
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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus PATCH 10/15] Implement StorageVolLookupByPath method for Connect Interface
Posted by Ján Tomko 7 years, 6 months ago
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);
>+
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list