[libvirt] [dbus PATCH 00/10] NodeAPIs for Connect Interface

Katerina Koukiou (10): Implement NodeGetCellsFreeMemory method for Connect Interface Implement NodeGetCPUStats method for Connect Interface Implement NodeGetFreeMemory method for Connect Interface Implement NodeGetInfo method for Connect Interface Implement NodeGetMemoryParameters method in Connect Interface Implement NodeGetMemoryStats method for Connect Interface Implement NodeGetSecurityModel method for Domain Interface Implement NodeSetMemoryParameters method for Connect Interface Implement NodeSuspendForDuration method for Connect Interface Implement NodeGetCPUMap method for Connect Interface data/org.libvirt.Connect.xml | 63 ++++++++ src/connect.c | 342 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 405 insertions(+) -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index ee7bfdc..1502849 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="NodeGetCellsFreeMemory"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCellsFreeMemory"/> + <arg name="startCell" type="i" direction="in"/> + <arg name="maxCells" type="i" direction="in"/> + <arg name="freeMems" type="at" 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 5e577e4..78b438e 100644 --- a/src/connect.c +++ b/src/connect.c @@ -842,6 +842,44 @@ virtDBusConnectNetworkLookupByUUID(GVariant *inArgs, *outArgs = g_variant_new("(o)", path); } +static void +virtDBusConnectNodeGetCellsFreeMemory(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 startCell; + gint maxCells; + g_autofree guint64 *freeMems = NULL; + gint ret; + GVariantBuilder builder; + GVariant *res; + + g_variant_get(inArgs, "(ii)", &startCell, &maxCells); + + if (!virtDBusConnectOpen(connect, error)) + return; + + freeMems = g_new0(guint64, maxCells); + + ret = virNodeGetCellsFreeMemory(connect->connection, + (unsigned long long *)freeMems, + startCell, maxCells); + if (ret < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("at")); + for (gint i = 0; i < ret; i++) + g_variant_builder_add(&builder, "t", freeMems[i]); + res = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&res, 1); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -873,6 +911,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkDefineXML", virtDBusConnectNetworkDefineXML }, { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, + { "NodeGetCellsFreeMemory", virtDBusConnectNodeGetCellsFreeMemory }, { 0 } }; -- 2.15.0

On Thu, Apr 26, 2018 at 04:54:08PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 7 +++++++ src/connect.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index ee7bfdc..1502849 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="NodeGetCellsFreeMemory"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCellsFreeMemory"/> + <arg name="startCell" type="i" direction="in"/> + <arg name="maxCells" type="i" direction="in"/> + <arg name="freeMems" type="at" direction="out"/> + </method>
Another example of bad design of libvirt API. We can do a better job in libvirt-dbus to always return an array of free memory for all NUMA nodes. However, there is no other way how to get the number of NUMA nodes except for parsing XML output of virConnectGetCapabilities() API. That means that we need to use libxml2 library to parse the XML. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- 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 1502849..0dcc6e8 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -173,6 +173,13 @@ <arg name="maxCells" type="i" direction="in"/> <arg name="freeMems" type="at" direction="out"/> </method> + <method name="NodeGetCPUStats"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats"/> + <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#virConnectDomainEventCallback"/> diff --git a/src/connect.c b/src/connect.c index 78b438e..80b5c67 100644 --- a/src/connect.c +++ b/src/connect.c @@ -880,6 +880,47 @@ virtDBusConnectNodeGetCellsFreeMemory(GVariant *inArgs, *outArgs = g_variant_new_tuple(&res, 1); } +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); + if (ret == 0 && count != 0) { + stats = g_new0(virNodeCPUStats, count); + if (virNodeGetCPUStats(connect->connection, cpuNum, stats, + &count, flags) < 0) { + return virtDBusUtilSetLastVirtError(error); + } + } + + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{st}")); + for (gint i = 0; i < count; i++) + g_variant_builder_add(&builder, "{st}", stats[i].field, stats[i].value); + gret = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&gret, 1); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -912,6 +953,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, { "NodeGetCellsFreeMemory", virtDBusConnectNodeGetCellsFreeMemory }, + { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats }, { 0 } }; -- 2.15.0

On Thu, Apr 26, 2018 at 04:54:09PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- 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 1502849..0dcc6e8 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -173,6 +173,13 @@ <arg name="maxCells" type="i" direction="in"/> <arg name="freeMems" type="at" direction="out"/> </method> + <method name="NodeGetCPUStats"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats"/> + <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#virConnectDomainEventCallback"/> diff --git a/src/connect.c b/src/connect.c index 78b438e..80b5c67 100644 --- a/src/connect.c +++ b/src/connect.c @@ -880,6 +880,47 @@ virtDBusConnectNodeGetCellsFreeMemory(GVariant *inArgs, *outArgs = g_variant_new_tuple(&res, 1); }
+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; +
No need for the empty line. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 5 +++++ src/connect.c | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 0dcc6e8..f0a7738 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -180,6 +180,11 @@ <arg name="flags" type="u" direction="in"/> <arg name="cpuStats" type="a{st}" direction="out"/> </method> + <method name="NodeGetFreeMemory"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreeMemory"/> + <arg name="freemem" type="t" 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 80b5c67..60fcaa5 100644 --- a/src/connect.c +++ b/src/connect.c @@ -921,6 +921,29 @@ virtDBusConnectNodeGetCPUStats(GVariant *inArgs, *outArgs = g_variant_new_tuple(&gret, 1); } +static void +virtDBusConnectNodeGetFreeMemory(GVariant *inArgs G_GNUC_UNUSED, + 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; + guint64 freemem; + + if (!virtDBusConnectOpen(connect, error)) + return; + + freemem = virNodeGetFreeMemory(connect->connection); + if (freemem == 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("(t)", freemem); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -954,6 +977,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, { "NodeGetCellsFreeMemory", virtDBusConnectNodeGetCellsFreeMemory }, { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats }, + { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 5 +++++ src/connect.c | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index f0a7738..2e65f8b 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -185,6 +185,11 @@ value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetFreeMemory"/> <arg name="freemem" type="t" direction="out"/> </method> + <method name="NodeGetInfo"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo"/> + <arg name="info" type="(stuuuuuu)" 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 60fcaa5..bb9bd46 100644 --- a/src/connect.c +++ b/src/connect.c @@ -944,6 +944,30 @@ virtDBusConnectNodeGetFreeMemory(GVariant *inArgs G_GNUC_UNUSED, *outArgs = g_variant_new("(t)", freemem); } +static void +virtDBusConnectNodeGetInfo(GVariant *inArgs G_GNUC_UNUSED, + 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; + virNodeInfo info; + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virNodeGetInfo(connect->connection, &info) < 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("((stuuuuuu))", info.model, info.memory, + info.cpus, info.mhz, info.nodes, info.sockets, + info.cores, info.threads); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -978,6 +1002,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetCellsFreeMemory", virtDBusConnectNodeGetCellsFreeMemory }, { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats }, { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory }, + { "NodeGetInfo", virtDBusConnectNodeGetInfo }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 2e65f8b..62a65ae 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -190,6 +190,12 @@ value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo"/> <arg name="info" type="(stuuuuuu)" direction="out"/> </method> + <method name="NodeGetMemoryParameters"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryParameters"/> + <arg name="flags" type="u" direction="in"/> + <arg name="memoryParameters" type="a{sv}" 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 bb9bd46..8a168f4 100644 --- a/src/connect.c +++ b/src/connect.c @@ -968,6 +968,41 @@ virtDBusConnectNodeGetInfo(GVariant *inArgs G_GNUC_UNUSED, info.cores, info.threads); } +static void +virtDBusConnectNodeGetMemoryParameters(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_auto(virtDBusUtilTypedParams) params = { 0 }; + guint flags; + gint ret; + GVariant *grecords; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + ret = virNodeGetMemoryParameters(connect->connection, NULL, + ¶ms.nparams, flags); + if (ret == 0 && params.nparams != 0) { + params.params = g_new0(virTypedParameter, params.nparams); + if (virNodeGetMemoryParameters(connect->connection, params.params, + ¶ms.nparams, flags) < 0) { + return virtDBusUtilSetLastVirtError(error); + } + } + + grecords = virtDBusUtilTypedParamsToGVariant(params.params, params.nparams); + + *outArgs = g_variant_new_tuple(&grecords, 1); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -1003,6 +1038,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats }, { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory }, { "NodeGetInfo", virtDBusConnectNodeGetInfo }, + { "NodeGetMemoryParameters", virtDBusConnectNodeGetMemoryParameters }, { 0 } }; -- 2.15.0

On Thu, Apr 26, 2018 at 04:54:12PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 2e65f8b..62a65ae 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -190,6 +190,12 @@ value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetInfo"/> <arg name="info" type="(stuuuuuu)" direction="out"/> </method> + <method name="NodeGetMemoryParameters"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetMemoryParameters"/> + <arg name="flags" type="u" direction="in"/> + <arg name="memoryParameters" type="a{sv}" 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 bb9bd46..8a168f4 100644 --- a/src/connect.c +++ b/src/connect.c @@ -968,6 +968,41 @@ virtDBusConnectNodeGetInfo(GVariant *inArgs G_GNUC_UNUSED, info.cores, info.threads); }
+static void +virtDBusConnectNodeGetMemoryParameters(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_auto(virtDBusUtilTypedParams) params = { 0 }; + guint flags; + gint ret; + GVariant *grecords; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + ret = virNodeGetMemoryParameters(connect->connection, NULL, + ¶ms.nparams, flags);
This can fail so we should check for 'ret < 0' and set an error.
+ if (ret == 0 && params.nparams != 0) {
and in that case there is no need to check ret here. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- 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

On Thu, Apr 26, 2018 at 04:54:13PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- 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"/>
I think we don't have to export this argument and instead always return all stats, so we will call virNodeGetMemoryStats with VIR_NODE_MEMORY_STATS_ALL_CELLS as cellNum.
+ <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);
We should check the return value and set an error if the API fails. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index abb2dbc..fc306be 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -203,6 +203,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="stats" type="a{st}" direction="out"/> </method> + <method name="NodeGetSecurityModel"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetSecurityModel"/> + <arg name="flags" type="u" direction="in"/> + <arg name="secModel" type="(ss)" 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 27355d3..32aa07d 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1044,6 +1044,28 @@ virtDBusConnectNodeGetMemoryStats(GVariant *inArgs, *outArgs = g_variant_new_tuple(&res, 1); } +static void +virtDBusConnectNodeGetSecurityModel(GVariant *inArgs G_GNUC_UNUSED, + 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; + virSecurityModel secmodel; + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (virNodeGetSecurityModel(connect->connection, &secmodel) < 0) + return virtDBusUtilSetLastVirtError(error); + + *outArgs = g_variant_new("((ss))", secmodel.model, secmodel.doi); +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -1081,6 +1103,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetInfo", virtDBusConnectNodeGetInfo }, { "NodeGetMemoryParameters", virtDBusConnectNodeGetMemoryParameters }, { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats }, + { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, { 0 } }; -- 2.15.0

On Thu, Apr 26, 2018 at 04:54:14PM +0200, Katerina Koukiou wrote:
Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+)
diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index abb2dbc..fc306be 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -203,6 +203,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="stats" type="a{st}" direction="out"/> </method> + <method name="NodeGetSecurityModel"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetSecurityModel"/> + <arg name="flags" type="u" direction="in"/>
There is no argument flags for this API. Pavel

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index fc306be..a929802 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -209,6 +209,12 @@ <arg name="flags" type="u" direction="in"/> <arg name="secModel" type="(ss)" direction="out"/> </method> + <method name="NodeSetMemoryParameters"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeSetMemoryParameters"/> + <arg name="params" type="a{sv}" 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 32aa07d..3b7d8a3 100644 --- a/src/connect.c +++ b/src/connect.c @@ -1066,6 +1066,36 @@ virtDBusConnectNodeGetSecurityModel(GVariant *inArgs G_GNUC_UNUSED, *outArgs = g_variant_new("((ss))", secmodel.model, secmodel.doi); } +static void +virtDBusConnectNodeSetMemoryParameters(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; + g_autoptr(GVariantIter) iter = NULL; + g_auto(virtDBusUtilTypedParams) params = { 0 }; + guint flags; + + g_variant_get(inArgs, "(a{sv}u)", &iter, &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + if (!virtDBusUtilGVariantToTypedParams(iter, ¶ms.params, + ¶ms.nparams, error)) { + return; + } + + if (virNodeSetMemoryParameters(connect->connection, params.params, + params.nparams, flags) < 0) { + virtDBusUtilSetLastVirtError(error); + } +} + static virtDBusGDBusPropertyTable virtDBusConnectPropertyTable[] = { { "Encrypted", virtDBusConnectGetEncrypted, NULL }, { "Hostname", virtDBusConnectGetHostname, NULL }, @@ -1104,6 +1134,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetMemoryParameters", virtDBusConnectNodeGetMemoryParameters }, { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats }, { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, + { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters }, { 0 } }; -- 2.15.0

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 a929802..9358040 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -215,6 +215,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 3b7d8a3..7d7c7c0 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, @@ -1096,6 +1103,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 }, @@ -1135,6 +1176,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NodeGetMemoryStats", virtDBusConnectNodeGetMemoryStats }, { "NodeGetSecurityModel", virtDBusConnectNodeGetSecurityModel }, { "NodeSetMemoryParameters", virtDBusConnectNodeSetMemoryParameters }, + { "NodeSuspendForDuration", virtDBusConnectNodeSuspendForDuration }, { 0 } }; -- 2.15.0

Signed-off-by: Katerina Koukiou <kkoukiou@redhat.com> --- data/org.libvirt.Connect.xml | 6 ++++++ src/connect.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/data/org.libvirt.Connect.xml b/data/org.libvirt.Connect.xml index 9358040..dfb8cc3 100644 --- a/data/org.libvirt.Connect.xml +++ b/data/org.libvirt.Connect.xml @@ -173,6 +173,12 @@ <arg name="maxCells" type="i" direction="in"/> <arg name="freeMems" type="at" direction="out"/> </method> + <method name="NodeGetCPUMap"> + <annotation name="org.gtk.GDBus.DocString" + value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUMap"/> + <arg name="flags" type="u" direction="in"/> + <arg name="res" type="ab" direction="out"/> + </method> <method name="NodeGetCPUStats"> <annotation name="org.gtk.GDBus.DocString" value="See https://libvirt.org/html/libvirt-libvirt-host.html#virNodeGetCPUStats"/> diff --git a/src/connect.c b/src/connect.c index 7d7c7c0..64e8e53 100644 --- a/src/connect.c +++ b/src/connect.c @@ -887,6 +887,40 @@ virtDBusConnectNodeGetCellsFreeMemory(GVariant *inArgs, *outArgs = g_variant_new_tuple(&res, 1); } +static void +virtDBusConnectNodeGetCPUMap(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 guchar *cpumap = NULL; + guint online = 0; + guint flags; + gint ret; + GVariant *gret; + GVariantBuilder builder; + + g_variant_get(inArgs, "(u)", &flags); + + if (!virtDBusConnectOpen(connect, error)) + return; + + ret = virNodeGetCPUMap(connect->connection, &cpumap, &online, flags); + if (ret < 0) + return virtDBusUtilSetLastVirtError(error); + + g_variant_builder_init(&builder, G_VARIANT_TYPE("ab")); + for (gint i = 0; i < ret; i++) + g_variant_builder_add(&builder, "b", VIR_CPU_USED(cpumap, i)); + gret = g_variant_builder_end(&builder); + + *outArgs = g_variant_new_tuple(&gret, 1); +} + static void virtDBusConnectNodeGetCPUStats(GVariant *inArgs, GUnixFDList *inFDs G_GNUC_UNUSED, @@ -1169,6 +1203,7 @@ static virtDBusGDBusMethodTable virtDBusConnectMethodTable[] = { { "NetworkLookupByName", virtDBusConnectNetworkLookupByName }, { "NetworkLookupByUUID", virtDBusConnectNetworkLookupByUUID }, { "NodeGetCellsFreeMemory", virtDBusConnectNodeGetCellsFreeMemory }, + { "NodeGetCPUMap", virtDBusConnectNodeGetCPUMap }, { "NodeGetCPUStats", virtDBusConnectNodeGetCPUStats }, { "NodeGetFreeMemory", virtDBusConnectNodeGetFreeMemory }, { "NodeGetInfo", virtDBusConnectNodeGetInfo }, -- 2.15.0

On Thu, Apr 26, 2018 at 04:54:07PM +0200, Katerina Koukiou wrote:
Katerina Koukiou (10): Implement NodeGetCellsFreeMemory method for Connect Interface Implement NodeGetCPUStats method for Connect Interface Implement NodeGetFreeMemory method for Connect Interface Implement NodeGetInfo method for Connect Interface Implement NodeGetMemoryParameters method in Connect Interface Implement NodeGetMemoryStats method for Connect Interface Implement NodeGetSecurityModel method for Domain Interface Implement NodeSetMemoryParameters method for Connect Interface Implement NodeSuspendForDuration method for Connect Interface Implement NodeGetCPUMap method for Connect Interface
All the patches are missing tests so there is need for v2 anyway. Some patches have few nits pointed out, otherwise looks good. Pavel
participants (2)
-
Katerina Koukiou
-
Pavel Hrdina