[dbus PATCH 4/5] domain: Implement GetVcpuPinInfo method

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

 



Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 data/org.libvirt.Domain.xml |  6 ++++
 src/domain.c                | 59 +++++++++++++++++++++++++++++++++++++
 tests/test_domain.py        |  9 ++++++
 3 files changed, 74 insertions(+)

diff --git a/data/org.libvirt.Domain.xml b/data/org.libvirt.Domain.xml
index 6c48e9d..3f6e8d8 100644
--- a/data/org.libvirt.Domain.xml
+++ b/data/org.libvirt.Domain.xml
@@ -312,6 +312,12 @@
       <arg name="flags" type="u" direction="in"/>
       <arg name="time" type="(tu)" direction="out"/>
     </method>
+    <method name="GetVcpuPinInfo">
+      <annotation name="org.gtk.GDBus.DocString"
+        value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpuPinInfo"/>
+      <arg name="flags" type="u" direction="in"/>
+      <arg name="vcpuPinInfo" type="aab" direction="out"/>
+    </method>
     <method name="GetVcpus">
       <annotation name="org.gtk.GDBus.DocString"
         value="See https://libvirt.org/html/libvirt-libvirt-domain.html#virDomainGetVcpusFlags"/>
diff --git a/src/domain.c b/src/domain.c
index d07e0a7..274d385 100644
--- a/src/domain.c
+++ b/src/domain.c
@@ -1686,6 +1686,64 @@ virtDBusDomainGetTime(GVariant *inArgs,
     *outArgs = g_variant_new("((tu))", seconds, nseconds);
 }
 
+static void
+virtDBusDomainGetVcpuPinInfo(GVariant *inArgs,
+                             GUnixFDList *inFDs G_GNUC_UNUSED,
+                             const gchar *objectPath,
+                             gpointer userData,
+                             GVariant **outArgs,
+                             GUnixFDList **outFDs G_GNUC_UNUSED,
+                             GError **error)
+
+{
+    virtDBusConnect *connect = userData;
+    g_autoptr(virDomain) domain = NULL;
+    guint flags;
+    virDomainInfo domInfo;
+    gint vcpuCount;
+    gint cpuCount;
+    g_autofree guchar *cpumaps = NULL;
+    gint cpumaplen;
+    GVariantBuilder builder;
+    GVariant *gret;
+
+    g_variant_get(inArgs, "(u)", &flags);
+
+    domain = virtDBusDomainGetVirDomain(connect, objectPath, error);
+    if (!domain)
+        return;
+
+    if (virDomainGetInfo(domain, &domInfo) < 0)
+        return virtDBusUtilSetLastVirtError(error);
+
+    vcpuCount = domInfo.nrVirtCpu;
+
+    cpuCount = virNodeGetCPUMap(connect->connection, NULL, NULL, 0);
+    if (cpuCount < 0)
+        return virtDBusUtilSetLastVirtError(error);
+
+    cpumaplen = VIR_CPU_MAPLEN(cpuCount);
+    cpumaps = g_new0(guchar, cpumaplen * vcpuCount);
+
+    if (virDomainGetVcpuPinInfo(domain, vcpuCount, cpumaps,
+                                cpumaplen, flags) < 0) {
+        return virtDBusUtilSetLastVirtError(error);
+    }
+
+    g_variant_builder_init(&builder, G_VARIANT_TYPE("aab"));
+    for (gint i = 0; i < vcpuCount; i++) {
+        g_variant_builder_open(&builder, G_VARIANT_TYPE("ab"));
+        for (gint j = 0; j < cpuCount; j++) {
+            g_variant_builder_add(&builder, "b",
+                                  VIR_CPU_USABLE(cpumaps, cpumaplen, i, j));
+        }
+        g_variant_builder_close(&builder);
+    }
+    gret = g_variant_builder_end(&builder);
+
+    *outArgs = g_variant_new_tuple(&gret, 1);
+}
+
 static void
 virtDBusDomainGetVcpus(GVariant *inArgs,
                        GUnixFDList *inFDs G_GNUC_UNUSED,
@@ -3024,6 +3082,7 @@ static virtDBusGDBusMethodTable virtDBusDomainMethodTable[] = {
     { "GetSecurityLabelList", virtDBusDomainGetSecurityLabelList },
     { "GetStats", virtDBusDomainGetStats },
     { "GetTime", virtDBusDomainGetTime },
+    { "GetVcpuPinInfo", virtDBusDomainGetVcpuPinInfo },
     { "GetVcpus", virtDBusDomainGetVcpus },
     { "GetXMLDesc", virtDBusDomainGetXMLDesc },
     { "HasManagedSaveImage", virtDBusDomainHasManagedSaveImage },
diff --git a/tests/test_domain.py b/tests/test_domain.py
index dfa19ed..00f282f 100755
--- a/tests/test_domain.py
+++ b/tests/test_domain.py
@@ -151,6 +151,15 @@ class TestDomain(libvirttest.BaseTestClass):
         domain.SetVcpus(vcpus_expected, 0)
         assert domain.GetVcpus(0) == dbus.Int32(vcpus_expected)
 
+    def test_domain_vcpu_pin_info(self):
+        obj, domain = self.domain()
+        pinInfo_expected = [
+                [ True, True, True, True, True, True, True, True ],
+                [ True, True, True, True, True, True, True, True ]
+        ]
+        pinInfo = domain.GetVcpuPinInfo(0)
+        assert pinInfo == pinInfo_expected
+
 
 if __name__ == '__main__':
     libvirttest.run()
-- 
2.17.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