[libvirt] [dbus PATCH 01/25] Implement GetControlInfo method for Domain Interface

Katerina Koukiou posted 25 patches 7 years, 8 months ago
There is a newer version of this series
[libvirt] [dbus PATCH 01/25] Implement GetControlInfo method for Domain Interface
Posted by Katerina Koukiou 7 years, 8 months ago
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
---
 data/org.libvirt.Domain.xml |  6 +++++
 src/domain.c                | 54 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index 98e2873..74b0a62 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -76,6 +76,12 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="BlkioParameters" type="a{sv}" direction="out"/>
     </method>
+    <method name="GetControlInfo">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetControlInfo"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="jobInfo" type="(sst)" direction="out"/>
+    </method>
     <method name="GetJobInfo">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo"/>
diff --git a/src/domain.c b/src/domain.c
index 8a25ae1..5ec7686 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -3,6 +3,22 @@
 
 #include <libvirt/libvirt.h>
 
+VIRT_DBUS_ENUM_DECL(virtDBusDomainControlState)
+VIRT_DBUS_ENUM_IMPL(virtDBusDomainControlState,
+                    VIR_DOMAIN_CONTROL_LAST,
+                    "ok",
+                    "job",
+                    "occupied",
+                    "error")
+
+VIRT_DBUS_ENUM_DECL(virtDBusDomainControlErrorReason)
+VIRT_DBUS_ENUM_IMPL(virtDBusDomainControlErrorReason,
+                    VIR_DOMAIN_CONTROL_ERROR_REASON_LAST,
+                    "none",
+                    "unknown",
+                    "monitor",
+                    "internal")
+
 VIRT_DBUS_ENUM_DECL(virtDBusDomainJob)
 VIRT_DBUS_ENUM_IMPL(virtDBusDomainJob,
                     VIR_DOMAIN_JOB_LAST,
@@ -472,6 +488,43 @@ virtDBusDomainGetBlkioParameters(GVariant *inArgs,
     *outArgs = g_variant_new_tuple(&grecords, 1);
 }
 
+static void
+virtDBusDomainGetControlInfo(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(virDomain) domain = NULL;
+    g_autofree virDomainControlInfoPtr controlInfo = NULL;
+    const gchar *stateStr;
+    const gchar *errorReasonStr;
+    guint flags;
+
+    g_variant_get(inArgs, "(u)", &flags);
+
+    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+    if (!domain)
+        return;
+
+    controlInfo = g_new0(virDomainControlInfo, 1);
+    if (virDomainGetControlInfo(domain, controlInfo, flags) == -1)
+        return virtDBusUtilSetLastVirtError(error);
+
+    stateStr = virtDBusDomainControlStateTypeToString(controlInfo->state);
+    if (!stateStr)
+        return;
+    errorReasonStr = virtDBusDomainControlErrorReasonTypeToString(controlInfo->details);
+    if (!errorReasonStr)
+        return;
+
+    *outArgs = g_variant_new("((sst))", stateStr,
+                             errorReasonStr, controlInfo->stateTime);
+}
+
 static void
 virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUSED,
                          GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -1086,6 +1139,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
     { "Destroy", virtDBusDomainDestroy },
     { "DetachDevice", virtDBusDomainDetachDevice },
     { "GetBlkioParameters", virtDBusDomainGetBlkioParameters },
+    { "GetControlInfo", virtDBusDomainGetControlInfo },
     { "GetJobInfo", virtDBusDomainGetJobInfo },
     { "GetMemoryParameters", virtDBusDomainGetMemoryParameters },
     { "GetSchedulerParameters", virtDBusDomainGetSchedulerParameters },
-- 
2.15.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus PATCH 01/25] Implement GetControlInfo method for Domain Interface
Posted by Ján Tomko 7 years, 8 months ago
On Tue, Apr 17, 2018 at 02:04:20PM +0200, Katerina Koukiou wrote:
>Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
>---
> data/org.libvirt.Domain.xml |  6 +++++
> src/domain.c                | 54 +++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 60 insertions(+)
>
>diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
>index 98e2873..74b0a62 100644
>--- a/data/org.libvirt.Domain.xml
>+++ b/data/org.libvirt.Domain.xml
>@@ -76,6 +76,12 @@
>       <arg name="flags" type="u" direction="in"/>
>       <arg name="BlkioParameters" type="a{sv}" direction="out"/>
>     </method>
>+    <method name="GetControlInfo">
>+      <annotation name="org.gtk.GDBus.DocString"
>+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetControlInfo"/>
>+      <arg name="flags" type="u" direction="in"/>
>+      <arg name="jobInfo" type="(sst)" direction="out"/>

s/jobInfo/controlInfo/

>+    </method>
>     <method name="GetJobInfo">
>       <annotation name="org.gtk.GDBus.DocString"
>         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetJobInfo"/>
>diff --git a/src/domain.c b/src/domain.c
>index 8a25ae1..5ec7686 100644
>--- a/src/domain.c
>+++ b/src/domain.c
>@@ -3,6 +3,22 @@
>
> #include <libvirt/libvirt.h>
>
>+VIRT_DBUS_ENUM_DECL(virtDBusDomainControlState)
>+VIRT_DBUS_ENUM_IMPL(virtDBusDomainControlState,
>+                    VIR_DOMAIN_CONTROL_LAST,
>+                    "ok",
>+                    "job",
>+                    "occupied",
>+                    "error")
>+
>+VIRT_DBUS_ENUM_DECL(virtDBusDomainControlErrorReason)
>+VIRT_DBUS_ENUM_IMPL(virtDBusDomainControlErrorReason,
>+                    VIR_DOMAIN_CONTROL_ERROR_REASON_LAST,
>+                    "none",
>+                    "unknown",
>+                    "monitor",
>+                    "internal")
>+

Any plans to keep these alphabetically sorted?

> VIRT_DBUS_ENUM_DECL(virtDBusDomainJob)
> VIRT_DBUS_ENUM_IMPL(virtDBusDomainJob,
>                     VIR_DOMAIN_JOB_LAST,
>@@ -472,6 +488,43 @@ virtDBusDomainGetBlkioParameters(GVariant *inArgs,
>     *outArgs = g_variant_new_tuple(&grecords, 1);
> }
>
>+static void
>+virtDBusDomainGetControlInfo(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(virDomain) domain = NULL;
>+    g_autofree virDomainControlInfoPtr controlInfo = NULL;
>+    const gchar *stateStr;
>+    const gchar *errorReasonStr;
>+    guint flags;
>+
>+    g_variant_get(inArgs, "(u)", &flags);
>+
>+    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
>+    if (!domain)
>+        return;
>+
>+    controlInfo = g_new0(virDomainControlInfo, 1);
>+    if (virDomainGetControlInfo(domain, controlInfo, flags) == -1)

s/== -1/< 0/

>+        return virtDBusUtilSetLastVirtError(error);
>+
>+    stateStr = virtDBusDomainControlStateTypeToString(controlInfo->state);
>+    if (!stateStr)
>+        return;
>+    errorReasonStr = virtDBusDomainControlErrorReasonTypeToString(controlInfo->details);
>+    if (!errorReasonStr)
>+        return;

Two returns without an error reported. Is that the policy?
virtDBusDomainGetJobInfo does report an error when it fails to convert an enum.

Jano

>+
>+    *outArgs = g_variant_new("((sst))", stateStr,
>+                             errorReasonStr, controlInfo->stateTime);
>+}
>+
> static void
> virtDBusDomainGetJobInfo(GVariant *inArgs G_GNUC_UNUSED,
>                          GUnixFDList *inFDs G_GNUC_UNUSED,
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list