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

Katerina Koukiou kkoukiou at redhat.com
Wed May 2 10:34:42 UTC 2018


Signed-off-by: Katerina Koukiou <kkoukiou at 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




More information about the libvir-list mailing list