[libvirt] [dbus PATCH v3 06/20] Implement GetJobInfo method for Domain interface

Katerina Koukiou posted 20 patches 7 years, 1 month ago
[libvirt] [dbus PATCH v3 06/20] Implement GetJobInfo method for Domain interface
Posted by Katerina Koukiou 7 years, 1 month ago
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
---
 data/org.libvirt.Domain.xml |  5 +++++
 src/domain.c                | 49 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index 5c310ad..c672053 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -62,6 +62,11 @@
       <arg name="xml" type="s" direction="in"/>
       <arg name="flags" type="u" direction="in"/>
     </method>
+    <method name="GetJobInfo">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo"/>
+      <arg name="jobInfo" type="(sttttttttttt)" direction="out"/>
+    </method>
     <method name="GetStats">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListGetStats"/>
diff --git a/src/domain.c b/src/domain.c
index 2c3174b..47bd585 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -3,6 +3,16 @@
 
 #include <libvirt/libvirt.h>
 
+VIRT_DBUS_ENUM_DECL(virtDBusDomainJob)
+VIRT_DBUS_ENUM_IMPL(virtDBusDomainJob,
+                    VIR_DOMAIN_JOB_LAST,
+                    "none",
+                    "bounded",
+                    "unbounded",
+                    "completed",
+                    "failed",
+                    "canceled")
+
 VIRT_DBUS_ENUM_DECL(virtDBusDomainMemoryStat)
 VIRT_DBUS_ENUM_IMPL(virtDBusDomainMemoryStat,
                     VIR_DOMAIN_MEMORY_STAT_LAST,
@@ -390,6 +400,44 @@ virtDBusDomainDetachDevice(GVariant *inArgs,
         virtDBusUtilSetLastVirtError(error);
 }
 
+static void
+virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUSED,
+                         GUnixFDList *inFDs G_GNUC_UNUSED,
+                         const gchar *objectPath,
+                         gpointer userData,
+                         GVariant **outArgs,
+                         GUnixFDList **outFDs G_GNUC_UNUSED,
+                         GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virDomain) domain = NULL;
+    g_autofree virDomainJobInfoPtr jobInfo = NULL;
+    const gchar *jobTypeStr;
+
+    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+    if (!domain)
+        return;
+
+    jobInfo = g_new0(virDomainJobInfo, 1);
+    if (virDomainGetJobInfo(domain, jobInfo) < 0)
+        return virtDBusUtilSetLastVirtError(error);
+
+    jobTypeStr = virtDBusDomainJobTypeToString(jobInfo->type);
+    if (!jobTypeStr) {
+        g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
+                    "Can't translate virDomainJobType to string.");
+        virtDBusUtilSetLastVirtError(error);
+        return;
+    }
+    *outArgs = g_variant_new("((sttttttttttt))", jobTypeStr,
+                             jobInfo->timeElapsed, jobInfo->timeRemaining,
+                             jobInfo->dataTotal, jobInfo->dataProcessed,
+                             jobInfo->dataRemaining, jobInfo->memTotal,
+                             jobInfo->memProcessed, jobInfo->memRemaining,
+                             jobInfo->fileTotal, jobInfo->fileProcessed,
+                             jobInfo->fileRemaining);
+}
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainStatsRecordPtr, virDomainStatsRecordListFree);
 
 static void
@@ -669,6 +717,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
     { "Create", virtDBusDomainCreate },
     { "Destroy", virtDBusDomainDestroy },
     { "DetachDevice", virtDBusDomainDetachDevice },
+    { "GetJobInfo", virtDBusDomainGetJobInfo },
     { "GetStats", virtDBusDomainGetStats },
     { "GetVcpus", virtDBusDomainGetVcpus },
     { "GetXMLDesc", virtDBusDomainGetXMLDesc },
-- 
2.15.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus PATCH v3 06/20] Implement GetJobInfo method for Domain interface
Posted by Pavel Hrdina 7 years, 1 month ago
On Fri, Apr 13, 2018 at 01:15:17PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
> ---
>  data/org.libvirt.Domain.xml |  5 +++++
>  src/domain.c                | 49 +++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 54 insertions(+)
> 
> diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
> index 5c310ad..c672053 100644
> --- a/data/org.libvirt.Domain.xml
> +++ b/data/org.libvirt.Domain.xml
> @@ -62,6 +62,11 @@
>        <arg name="xml" type="s" direction="in"/>
>        <arg name="flags" type="u" direction="in"/>
>      </method>
> +    <method name="GetJobInfo">
> +      <annotation name="org.gtk.GDBus.DocString"
> +        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo"/>
> +      <arg name="jobInfo" type="(sttttttttttt)" direction="out"/>
> +    </method>
>      <method name="GetStats">
>        <annotation name="org.gtk.GDBus.DocString"
>          value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainListGetStats"/>
> diff --git a/src/domain.c b/src/domain.c
> index 2c3174b..47bd585 100644
> --- a/src/domain.c
> +++ b/src/domain.c
> @@ -3,6 +3,16 @@
>  
>  #include <libvirt/libvirt.h>
>  
> +VIRT_DBUS_ENUM_DECL(virtDBusDomainJob)
> +VIRT_DBUS_ENUM_IMPL(virtDBusDomainJob,
> +                    VIR_DOMAIN_JOB_LAST,
> +                    "none",
> +                    "bounded",
> +                    "unbounded",
> +                    "completed",
> +                    "failed",
> +                    "canceled")
> +
>  VIRT_DBUS_ENUM_DECL(virtDBusDomainMemoryStat)
>  VIRT_DBUS_ENUM_IMPL(virtDBusDomainMemoryStat,
>                      VIR_DOMAIN_MEMORY_STAT_LAST,
> @@ -390,6 +400,44 @@ virtDBusDomainDetachDevice(GVariant *inArgs,
>          virtDBusUtilSetLastVirtError(error);
>  }
>  
> +static void
> +virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUSED,
> +                         GUnixFDList *inFDs G_GNUC_UNUSED,
> +                         const gchar *objectPath,
> +                         gpointer userData,
> +                         GVariant **outArgs,
> +                         GUnixFDList **outFDs G_GNUC_UNUSED,
> +                         GError **error)
> +{
> +    virtDBusConnect *connect = userData;
> +    g_autoptr(virDomain) domain = NULL;
> +    g_autofree virDomainJobInfoPtr jobInfo = NULL;
> +    const gchar *jobTypeStr;
> +
> +    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
> +    if (!domain)
> +        return;
> +
> +    jobInfo = g_new0(virDomainJobInfo, 1);
> +    if (virDomainGetJobInfo(domain, jobInfo) < 0)
> +        return virtDBusUtilSetLastVirtError(error);
> +
> +    jobTypeStr = virtDBusDomainJobTypeToString(jobInfo->type);
> +    if (!jobTypeStr) {
> +        g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
> +                    "Can't translate virDomainJobType to string.");

In this case setting the error makes sense since the other two options
are not to translate the type to string or returning job type 'none'
with all values as 0.

How about this error message:

"Can't format virDomainJobType '%d' to string.", jobInfo->type ?

> +        virtDBusUtilSetLastVirtError(error);

This would overwrite the previous error so it should not be used here.
The purpose of this function is to get an libvirt error if some libvirt
API fails.

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