[dbus PATCH v2] Implement SetGuestVcpus method for Domain Interface

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Katerina Koukiou <kkoukiou@xxxxxxxxxx>
---
Fixed conditions since v1 was creating incorrect vcpumap.
If all vcpus will be passed False the API will not work, since '' is not
valid cpumap but this scenario should not be used.

 data/org.libvirt.Domain.xml |  7 +++++
 src/domain.c                | 62 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)

diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index db43b1c..eae6d97 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -463,6 +463,13 @@
       <arg name="params" type="a{sv}" direction="in"/>
       <arg name="flags" type="u" direction="in"/>
     </method>
+    <method name="SetGuestVcpus">
+      <annotation name="org.gtk.GDBus.DocString"
+          value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetGuestVcpus"/>
+      <arg name="vcpumap" type="ab" direction="in"/>
+      <arg name="state" type="i" direction="in"/>
+      <arg name="flags" type="u" direction="in"/>
+    </method>
     <method name="SetInterfaceParameters">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainSetInterfaceParameters"/>
diff --git a/src/domain.c b/src/domain.c
index e305fa3..28cbe76 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -72,6 +72,39 @@ VIRT_DBUS_ENUM_IMPL(virtDBusDomainMetadata,
                     "title",
                     "element")
 
+static gchar *
+virtDBusDomainConvertBoolArrayToGuestVcpumap(GVariantIter *iter)
+{
+    g_autoptr(GVariantIter) tmpIter = NULL;
+    gint intervalCnt = 0;
+    guint intervalStart = 0;
+    gboolean set;
+    gboolean setPrev = 0;
+    g_autofree GString *ret = NULL;
+
+    ret = g_string_new("");
+    for (guint i = 0; ; i++) {
+        gboolean next = g_variant_iter_loop(iter, "b", &set);
+
+        if (next && set && !setPrev)
+            intervalStart = i;
+        else if ((!next && setPrev) || (!set && setPrev)) {
+            if (intervalCnt > 0)
+                g_string_append_printf(ret, ",");
+            if (intervalStart != i - 1)
+                g_string_append_printf(ret, "%d-%d", intervalStart, i - 1);
+            else
+                g_string_append_printf(ret, "%d", intervalStart);
+            intervalCnt++;
+        }
+        setPrev = set;
+        if (!next)
+            break;
+    }
+
+    return ret->str;
+}
+
 struct _virtDBusDomainFSInfoList {
     virDomainFSInfoPtr *info;
     gint count;
@@ -2490,6 +2523,34 @@ virtDBusDomainSetBlockIOTune(GVariant *inArgs,
     }
 }
 
+static void
+virtDBusDomainSetGuestVcpus(GVariant *inArgs,
+                            GUnixFDList *inFDs G_GNUC_UNUSED,
+                            const gchar *objectPath,
+                            gpointer userData,
+                            GVariant **outArgs G_GNUC_UNUSED,
+                            GUnixFDList **outFDs G_GNUC_UNUSED,
+                            GError **error)
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virDomain) domain = NULL;
+    g_autoptr(GVariantIter) iter = NULL;
+    gint state;
+    guint flags;
+    g_autofree gchar *ret = NULL;
+
+    g_variant_get(inArgs, "(abiu)", &iter, &state, &flags);
+
+    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+    if (!domain)
+        return;
+
+    ret = virtDBusDomainConvertBoolArrayToGuestVcpumap(iter);
+
+    if (virDomainSetGuestVcpus(domain, ret, state, flags) < 0)
+        virtDBusUtilSetLastVirtError(error);
+}
+
 static void
 virtDBusDomainSetInterfaceParameters(GVariant *inArgs,
                                      GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -2988,6 +3049,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
     { "SendProcessSignal", virtDBusDomainSendProcessSignal },
     { "SetBlkioParameters", virtDBusDomainSetBlkioParameters },
     { "SetBlockIOTune", virtDBusDomainSetBlockIOTune },
+    { "SetGuestVcpus", virtDBusDomainSetGuestVcpus },
     { "SetInterfaceParameters", virtDBusDomainSetInterfaceParameters },
     { "SetVcpus", virtDBusDomainSetVcpus },
     { "SetMemory", virtDBusDomainSetMemory },
-- 
2.15.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux