[libvirt] [dbus PATCH v2 8/9] Implement NodeSuspendForDuration method for Connect Interface

Katerina Koukiou posted 9 patches 7 years ago
[libvirt] [dbus PATCH v2 8/9] Implement NodeSuspendForDuration method for Connect Interface
Posted by Katerina Koukiou 7 years ago
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
---
 data/org.libvirt.Connect.xml |  8 ++++++++
 src/connect.c                | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+)

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index e46d28d..eb4990e 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -206,6 +206,14 @@
       <arg name="params" type="a{sv}" direction="in"/>
       <arg name="flags" type="u" direction="in"/>
     </method>
+    <method name="NodeSuspendForDuration">
+      <annotation name="org.gtk.GDBus.DocString"
+          value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSuspendForDuration
+                 @target argument should be one of 'mem', 'disk' or 'hybrid'."/>
+      <arg name="target" type="s" direction="in"/>
+      <arg name="duration" type="t" direction="in"/>
+      <arg name="flags" type="u" direction="in"/>
+    </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 cea64cb..4035853 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -13,6 +13,13 @@ VIRT_DBUS_ENUM_IMPL(virtDBusConnectCPUCompareResult,
                     "identical",
                     "superset")
 
+VIRT_DBUS_ENUM_DECL(virtDBusConnectNodeSuspendTarget)
+VIRT_DBUS_ENUM_IMPL(virtDBusConnectNodeSuspendTarget,
+                    VIR_NODE_SUSPEND_TARGET_LAST,
+                    "mem",
+                    "disk",
+                    "hybrid")
+
 static gint virtDBusConnectCredType[] = {
     VIR_CRED_AUTHNAME,
     VIR_CRED_ECHOPROMPT,
@@ -1061,6 +1068,40 @@ virtDBusConnectNodeSetMemoryParameters(GVariant *inArgs,
     }
 }
 
+static void
+virtDBusConnectNodeSuspendForDuration(GVariant *inArgs,
+                                      GUnixFDList *inFDs G_GNUC_UNUSED,
+                                      const gchar *objectPath G_GNUC_UNUSED,
+                                      gpointer userData,
+                                      GVariant **outArgs G_GNUC_UNUSED,
+                                      GUnixFDList **outFDs G_GNUC_UNUSED,
+                                      GError **error)
+{
+    virtDBusConnect *connect = userData;
+    const gchar *targetStr;
+    gint target;
+    guint64 duration;
+    guint flags;
+
+    g_variant_get(inArgs, "(&stu)", &targetStr, &duration, &flags);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    target = virtDBusConnectNodeSuspendTargetTypeFromString(targetStr);
+    if (target < 0) {
+        g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
+                    "Can't get valid virNodeSuspendTarget from string '%s'.",
+                    targetStr);
+        return;
+    }
+
+    if (virNodeSuspendForDuration(connect->connection, target,
+                                  duration, flags) < 0) {
+        virtDBusUtilSetLastVirtError(error);
+    }
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
     { "Encrypted", virtDBusConnectGetEncrypted, NULL },
     { "Hostname", virtDBusConnectGetHostname, NULL },
@@ -1099,6 +1140,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats },
     { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel },
     { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters },
+    { "NodeSuspendForDuration", virtDBusConnectNodeSuspendForDuration },
     { 0 }
 };
 
-- 
2.15.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [dbus PATCH v2 8/9] Implement NodeSuspendForDuration method for Connect Interface
Posted by Pavel Hrdina 7 years ago
On Wed, May 02, 2018 at 12:34:45PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
> ---
>  data/org.libvirt.Connect.xml |  8 ++++++++
>  src/connect.c                | 42 ++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 50 insertions(+)
> 
> diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
> index e46d28d..eb4990e 100644
> --- a/data/org.libvirt.Connect.xml
> +++ b/data/org.libvirt.Connect.xml
> @@ -206,6 +206,14 @@
>        <arg name="params" type="a{sv}" direction="in"/>
>        <arg name="flags" type="u" direction="in"/>
>      </method>
> +    <method name="NodeSuspendForDuration">
> +      <annotation name="org.gtk.GDBus.DocString"
> +          value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSuspendForDuration
> +                 @target argument should be one of 'mem', 'disk' or 'hybrid'."/>

We will probably remove the string->enum translation so I would wait to
get that pushed before pushing this patch.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list