On Wed, May 02, 2018 at 12:34:38PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou(a)redhat.com>
---
data/org.libvirt.Connect.xml | 7 +++++++
src/connect.c | 41 +++++++++++++++++++++++++++++++++++++++++
tests/test_connect.py | 4 ++++
3 files changed, 52 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml
index ee7bfdc..e5c18bd 100644
--- a/data/org.libvirt.Connect.xml
+++ b/data/org.libvirt.Connect.xml
@@ -166,6 +166,13 @@
<arg name="uuid" type="s" direction="in"/>
<arg name="network" type="o"
direction="out"/>
</method>
+ <method name="NodeGetCPUStats">
+ <annotation name="org.gtk.GDBus.DocString"
+ value="See
https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats&quo...
+ <arg name="cpuNum" type="i" direction="in"/>
+ <arg name="flags" type="u" direction="in"/>
+ <arg name="cpuStats" 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#virConnectDomainEven...
diff --git a/src/connect.c b/src/connect.c
index 5e577e4..6d0243f 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -842,6 +842,46 @@ virtDBusConnectNetworkLookupByUUID(GVariant *inArgs,
*outArgs = g_variant_new("(o)", path);
}
+static void
+virtDBusConnectNodeGetCPUStats(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;
+ gint cpuNum;
+ guint flags;
+ g_autofree virNodeCPUStatsPtr stats = NULL;
+ gint count = 0;
+ gint ret;
+ GVariant *gret;
+ GVariantBuilder builder;
+
+ g_variant_get(inArgs, "(iu)", &cpuNum, &flags);
+
+ if (!virtDBusConnectOpen(connect, error))
+ return;
+
+ ret = virNodeGetCPUStats(connect->connection, cpuNum, NULL, &count, flags);
This API can return -1 in case of error, we need to check it.
+ if (ret == 0 && count != 0) {
and the 'ret == 0' can be removed here.
Reviewed-by: Pavel Hrdina <phrdina(a)redhat.com>
with this diff applied:
diff --git a/src/connect.c b/src/connect.c
index 6d0243f..dd1d172 100644
--- a/src/connect.c
+++ b/src/connect.c
@@ -866,7 +866,10 @@ virtDBusConnectNodeGetCPUStats(GVariant *inArgs,
return;
ret = virNodeGetCPUStats(connect->connection, cpuNum, NULL, &count, flags);
- if (ret == 0 && count != 0) {
+ if (ret < 0)
+ return virtDBusUtilSetLastVirtError(error);
+
+ if (count != 0) {
stats = g_new0(virNodeCPUStats, count);
if (virNodeGetCPUStats(connect->connection, cpuNum, stats,
&count, flags) < 0) {