[PATCH 4/4] python: add Python binding for virDomainGetVcpuPinInfo API

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

 



This patch adds the Python bindings for virDomainGetVcpuPinInfo API.

Signed-off-by: Taku Izumi <izumi.taku@xxxxxxxxxxxxxx>
---
 python/generator.py             |    1 
 python/libvirt-override-api.xml |    6 +++
 python/libvirt-override.c       |   69 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 76 insertions(+)

Index: libvirt/python/generator.py
===================================================================
--- libvirt.orig/python/generator.py
+++ libvirt/python/generator.py
@@ -344,6 +344,7 @@ skip_impl = (
     'virDomainGetVcpus',
     'virDomainPinVcpu',
     'virDomainPinVcpuFlags',
+    'virDomainGetVcpuPinInfo',
     'virSecretGetValue',
     'virSecretSetValue',
     'virSecretGetUUID',
Index: libvirt/python/libvirt-override.c
===================================================================
--- libvirt.orig/python/libvirt-override.c
+++ libvirt/python/libvirt-override.c
@@ -784,6 +784,74 @@ libvirt_virDomainPinVcpuFlags(PyObject *
     return VIR_PY_INT_SUCCESS;
 }
 
+static PyObject *
+libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
+                                PyObject *args) {
+    virDomainPtr domain;
+    PyObject *pyobj_domain, *pycpumaps = NULL;
+    virNodeInfo nodeinfo;
+    virDomainInfo dominfo;
+    unsigned char *cpumaps;
+    int cpumaplen, vcpu, pcpu;
+    int flags;
+    int i_retval;
+
+    if (!PyArg_ParseTuple(args, (char *)"Oi:virDomainGetVcpuPinInfo",
+                          &pyobj_domain, &flags))
+        return(NULL);
+    domain = (virDomainPtr) PyvirDomain_Get(pyobj_domain);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virNodeGetInfo(virDomainGetConnect(domain), &nodeinfo);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (i_retval < 0)
+        return VIR_PY_NONE;
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virDomainGetInfo(domain, &dominfo);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (i_retval < 0)
+        return VIR_PY_NONE;
+
+    cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
+    if ((cpumaps = malloc(dominfo.nrVirtCpu * cpumaplen)) == NULL)
+        goto cleanup;
+    memset(cpumaps, 0, dominfo.nrVirtCpu * cpumaplen);
+
+    LIBVIRT_BEGIN_ALLOW_THREADS;
+    i_retval = virDomainGetVcpuPinInfo(domain, dominfo.nrVirtCpu,
+                                       cpumaps, cpumaplen, flags);
+    LIBVIRT_END_ALLOW_THREADS;
+    if (i_retval < 0)
+        goto cleanup;
+
+    if ((pycpumaps = PyList_New(dominfo.nrVirtCpu)) == NULL)
+        goto cleanup;
+
+    for (vcpu = 0; vcpu < dominfo.nrVirtCpu; vcpu++) {
+        PyObject *mapinfo = PyTuple_New(VIR_NODEINFO_MAXCPUS(nodeinfo));
+        if (mapinfo == NULL)
+            goto cleanup;
+
+        for (pcpu = 0; pcpu < VIR_NODEINFO_MAXCPUS(nodeinfo); pcpu++) {
+            PyTuple_SetItem(mapinfo, pcpu,
+                            PyBool_FromLong(VIR_CPU_USABLE(cpumaps, cpumaplen, vcpu, pcpu)));
+        }
+        PyList_SetItem(pycpumaps, vcpu, mapinfo);
+    }
+
+    free(cpumaps);
+
+    return pycpumaps;
+
+cleanup:
+    free(cpumaps);
+
+    if (pycpumaps) { Py_DECREF(pycpumaps);}
+
+    return VIR_PY_NONE;
+}
+
 /************************************************************************
  *									*
  *		Global error handler at the Python level		*
@@ -4067,6 +4135,7 @@ static PyMethodDef libvirtMethods[] = {
     {(char *) "virDomainGetVcpus", libvirt_virDomainGetVcpus, METH_VARARGS, NULL},
     {(char *) "virDomainPinVcpu", libvirt_virDomainPinVcpu, METH_VARARGS, NULL},
     {(char *) "virDomainPinVcpuFlags", libvirt_virDomainPinVcpuFlags, METH_VARARGS, NULL},
+    {(char *) "virDomainGetVcpuPinInfo", libvirt_virDomainGetVcpuPinInfo, METH_VARARGS, NULL},
     {(char *) "virConnectListStoragePools", libvirt_virConnectListStoragePools, METH_VARARGS, NULL},
     {(char *) "virConnectListDefinedStoragePools", libvirt_virConnectListDefinedStoragePools, METH_VARARGS, NULL},
     {(char *) "virStoragePoolGetAutostart", libvirt_virStoragePoolGetAutostart, METH_VARARGS, NULL},
Index: libvirt/python/libvirt-override-api.xml
===================================================================
--- libvirt.orig/python/libvirt-override-api.xml
+++ libvirt/python/libvirt-override-api.xml
@@ -182,6 +182,12 @@
       <arg name='cpumap' type='unsigned char *' info='pointer to a bit map of real CPUs (in 8-bit bytes) (IN) Each bit set to 1 means that corresponding CPU is usable. Bytes are stored in little-endian order: CPU0-7, 8-15... In each byte, lowest CPU number is least significant bit.'/>
       <arg name='flags' type='int' info='an OR&apos;ed set of virDomainModificationImpact'/>
     </function>
+    <function name='virDomainGetVcpuPinInfo' file='python'>
+      <info>Query the CPU affinity setting of all virtual CPUs of domain</info>
+      <return type='unsigned char *' info='the array of cpumap'/>
+      <arg name='domain' type='virDomainPtr' info='pointer to domain object, or NULL for Domain0'/>
+      <arg name='flags'  type='int' info='an OR&apos;ed set of virDomainModificationImpact'/>
+    </function>
     <function name='virDomainSetSchedulerParameters' file='python'>
       <info>Change the scheduler parameters</info>
       <return type='int' info='-1 in case of error, 0 in case of success.'/>

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