[libvirt] [dbus PATCH v2 5/9] Implement NodeGetMemoryStats method for Connect Interface

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

diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index c62d107..4a1ee4a 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -189,6 +189,12 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="memoryParameters" type="a{sv}" direction="out"/>
     </method>
+    <method name="NodeGetMemoryStats">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryStats"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="stats" type="a{st}" 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 f2c6d45..0ecb333 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -966,6 +966,49 @@ virtDBusConnectNodeGetMemoryParameters(GVariant *inArgs,
     *outArgs = g_variant_new_tuple(&grecords, 1);
 }
 
+static void
+virtDBusConnectNodeGetMemoryStats(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_autofree virNodeMemoryStatsPtr params = NULL;
+    gint nparams = 0;
+    gint cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
+    guint flags;
+    gint ret;
+    GVariantBuilder builder;
+    GVariant *res;
+
+    g_variant_get(inArgs, "(u)", &flags);
+
+    if (!virtDBusConnectOpen(connect, error))
+        return;
+
+    ret = virNodeGetMemoryStats(connect->connection, cellNum, NULL,
+                                &nparams, flags);
+    if (ret < 0)
+        return virtDBusUtilSetLastVirtError(error);
+    if (nparams != 0) {
+        params = g_new0(virNodeMemoryStats, nparams);
+        if (virNodeGetMemoryStats(connect->connection, cellNum, params,
+                                  &nparams, flags) < 0) {
+            return virtDBusUtilSetLastVirtError(error);
+        }
+    }
+
+    g_variant_builder_init(&builder, G_VARIANT_TYPE("a{st}"));
+    for (gint i = 0; i < nparams; i++)
+        g_variant_builder_add(&builder, "{st}", params[i].field, params[i].value);
+    res = g_variant_builder_end(&builder);
+
+    *outArgs = g_variant_new_tuple(&res, 1);
+}
+
 static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = {
     { "Encrypted", virtDBusConnectGetEncrypted, NULL },
     { "Hostname", virtDBusConnectGetHostname, NULL },
@@ -1001,6 +1044,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = {
     { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory },
     { "NodeGetInfo", virtDBusConnectNodeGetInfo },
     { "NodeGetMemoryParameters", virtDBusConnectNodeGetMemoryParameters },
+    { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats },
     { 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 5/9] Implement NodeGetMemoryStats method for Connect Interface
Posted by Pavel Hrdina 7 years ago
On Wed, May 02, 2018 at 12:34:42PM +0200, Katerina Koukiou wrote:
> Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com>
> ---
>  data/org.libvirt.Connect.xml |  6 ++++++
>  src/connect.c                | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 50 insertions(+)
> 
> diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
> index c62d107..4a1ee4a 100644
> --- a/data/org.libvirt.Connect.xml
> +++ b/data/org.libvirt.Connect.xml
> @@ -189,6 +189,12 @@
>        <arg name="flags" type="u" direction="in"/>
>        <arg name="memoryParameters" type="a{sv}" direction="out"/>
>      </method>
> +    <method name="NodeGetMemoryStats">
> +      <annotation name="org.gtk.GDBus.DocString"
> +        value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryStats"/>
> +      <arg name="flags" type="u" direction="in"/>
> +      <arg name="stats" type="a{st}" direction="out"/>
> +    </method>

In the review of v1 I've stated that we should drop the cellNum
argument, that was wrong.  I thought that this API will report stats for
all numa nodes, but that's not true.  This is similar to the
NodeGetCPUStats API so it should be same.  Sorry about that.

>      <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 f2c6d45..0ecb333 100644
> --- a/src/connect.c
> +++ b/src/connect.c
> @@ -966,6 +966,49 @@ virtDBusConnectNodeGetMemoryParameters(GVariant *inArgs,
>      *outArgs = g_variant_new_tuple(&grecords, 1);
>  }
>  
> +static void
> +virtDBusConnectNodeGetMemoryStats(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_autofree virNodeMemoryStatsPtr params = NULL;
> +    gint nparams = 0;
> +    gint cellNum = VIR_NODE_MEMORY_STATS_ALL_CELLS;
> +    guint flags;
> +    gint ret;
> +    GVariantBuilder builder;
> +    GVariant *res;
> +
> +    g_variant_get(inArgs, "(u)", &flags);
> +
> +    if (!virtDBusConnectOpen(connect, error))
> +        return;
> +
> +    ret = virNodeGetMemoryStats(connect->connection, cellNum, NULL,
> +                                &nparams, flags);
> +    if (ret < 0)
> +        return virtDBusUtilSetLastVirtError(error);

I would put an empty line here.

> +    if (nparams != 0) {
> +        params = g_new0(virNodeMemoryStats, nparams);
> +        if (virNodeGetMemoryStats(connect->connection, cellNum, params,
> +                                  &nparams, flags) < 0) {
> +            return virtDBusUtilSetLastVirtError(error);
> +        }
> +    }

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

to the v1 patch with the error check fix as it was pointed out for the
v1 patch.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list