Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 62a65ae..abb2dbc 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -196,6 +196,13 @@ <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="cellNum" type="i" direction="in"/> + <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 8a168f4..27355d3 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1003,6 +1003,47 @@ 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; + guint flags; + gint ret; + GVariantBuilder builder; + GVariant *res; + + g_variant_get(inArgs, "(iu)", &cellNum, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + ret = virNodeGetMemoryStats(connect->connection, cellNum, NULL, + &nparams, flags); + if (ret == 0 && 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 }, @@ -1039,6 +1080,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory }, { "NodeGetInfo", virtDBusConnectNodeGetInfo }, { "NodeGetMemoryParameters", virtDBusConnectNodeGetMemoryParameters }, + { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats }, { 0 } }; -- 2.15.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list