[dbus PATCH 8/9] domain: Introduce virtDBusDomainGVariantToCpumap helper

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

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/domain.c | 55 ++++++++++++++++++++++---------------------------------
 1 file changed, 22 insertions(+), 33 deletions(-)

diff --git a/src/domain.c b/src/domain.c
index c6dc744..2ba58e0 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -125,6 +125,25 @@ virtDBusDomainGVariantToMountpoints(GVariantIter *iter,
     }
 }
 
+static void
+virtDBusDomainGVariantToCpumap(GVariantIter *iter,
+                               guchar **cpumap,
+                               guint *cpumaplen)
+{
+    gboolean usable;
+    guint cpus = g_variant_iter_n_children(iter);
+    guint cnt = 0;
+
+    *cpumaplen = VIR_CPU_MAPLEN(cpus);
+    *cpumap = g_new0(guchar, cpumaplen);
+
+    while (g_variant_iter_loop(iter, "b", &usable)) {
+        if (usable)
+            VIR_USE_CPU(*cpumap, cnt);
+        cnt++;
+    }
+}
+
 static virDomainPtr
 virtDBusDomainGetVirDomain(virtDBusConnect *connect,
                            const gchar *objectPath,
@@ -1996,22 +2015,12 @@ virtDBusDomainPinEmulator(GVariant *inArgs,
     g_autoptr(virDomain) domain = NULL;
     g_autoptr(GVariantIter) iter = NULL;
     guint flags;
-    guint cpus;
     guint cpumaplen;
     g_autofree guchar *cpumap = NULL;
-    gboolean usable;
-    guint cnt = 0;
 
     g_variant_get(inArgs, "(abu)", &iter, &flags);
 
-    cpus = g_variant_iter_n_children(iter);
-    cpumaplen = VIR_CPU_MAPLEN(cpus);
-    cpumap = g_new0(guchar, cpumaplen);
-    while (g_variant_iter_loop(iter, "b", &usable)) {
-        if (usable)
-            VIR_USE_CPU(cpumap, cnt);
-        cnt++;
-    }
+    virtDBusDomainGVariantToCpumap(iter, &cpumap, &cpumaplen);
 
     domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
     if (!domain)
@@ -2036,22 +2045,12 @@ virtDBusDomainPinIOThread(GVariant *inArgs,
     guint iothreadId;
     g_autoptr(GVariantIter) iter = NULL;
     guint flags;
-    guint cpus;
     guint cpumaplen;
     g_autofree guchar *cpumap = NULL;
-    gboolean usable;
-    guint cnt = 0;
 
     g_variant_get(inArgs, "(uabu)", &iothreadId, &iter, &flags);
 
-    cpus = g_variant_iter_n_children(iter);
-    cpumaplen = VIR_CPU_MAPLEN(cpus);
-    cpumap = g_new0(guchar, cpumaplen);
-    while (g_variant_iter_loop(iter, "b", &usable)) {
-        if (usable)
-            VIR_USE_CPU(cpumap, cnt);
-        cnt++;
-    }
+    virtDBusDomainGVariantToCpumap(iter, &cpumap, &cpumaplen);
 
     domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
     if (!domain)
@@ -2076,22 +2075,12 @@ virtDBusDomainPinVcpu(GVariant *inArgs,
     guint vcpu;
     g_autoptr(GVariantIter) iter = NULL;
     guint flags;
-    guint cpus;
     guint cpumaplen;
     g_autofree guchar *cpumap = NULL;
-    gboolean usable;
-    guint cnt = 0;
 
     g_variant_get(inArgs, "(uabu)", &vcpu, &iter, &flags);
 
-    cpus = g_variant_iter_n_children(iter);
-    cpumaplen = VIR_CPU_MAPLEN(cpus);
-    cpumap = g_new0(guchar, cpumaplen);
-    while (g_variant_iter_loop(iter, "b", &usable)) {
-        if (usable)
-            VIR_USE_CPU(cpumap, cnt);
-        cnt++;
-    }
+    virtDBusDomainGVariantToCpumap(iter, &cpumap, &cpumaplen);
 
     domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
     if (!domain)
-- 
2.14.3

--
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