diff options
author | Konstantin Neumoin <kneumoin@virtuozzo.com> | 2016-11-03 20:05:51 +0300 |
---|---|---|
committer | Peter Krempa <pkrempa@redhat.com> | 2016-11-11 13:44:44 +0100 |
commit | a03d782b3e19cb9b4681783ec1f6c88615128627 (patch) | |
tree | b2afc851dba75bd729c0e5dacaec70cc31cf1473 /libvirt-override.c | |
parent | 653ca92463788c0f1873f53b81c6d5f5a37784c1 (diff) | |
download | libvirt-python-a03d782b3e19cb9b4681783ec1f6c88615128627.tar.gz |
move cpumap conversion code to a common helper
All libvirt_virDomainPin* functions do the same thing for convert
pycpumap to cpumap, so this patch moves all common logic to new
helper - virPyCpumapConvert.
Signed-off-by: Konstantin Neumoin <kneumoin@virtuozzo.com>
Diffstat (limited to 'libvirt-override.c')
-rw-r--r-- | libvirt-override.c | 131 |
1 files changed, 11 insertions, 120 deletions
diff --git a/libvirt-override.c b/libvirt-override.c index fa3e2ca..be299d4 100644 --- a/libvirt-override.c +++ b/libvirt-override.c @@ -1302,8 +1302,7 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, PyObject *pyobj_domain, *pycpumap; PyObject *ret = NULL; unsigned char *cpumap; - int cpumaplen, vcpu, tuple_size, cpunum; - size_t i; + int cpumaplen, vcpu, cpunum; int i_retval; if (!PyArg_ParseTuple(args, (char *)"OiO:virDomainPinVcpu", @@ -1314,34 +1313,8 @@ libvirt_virDomainPinVcpu(PyObject *self ATTRIBUTE_UNUSED, if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0) return VIR_PY_INT_FAIL; - if (PyTuple_Check(pycpumap)) { - tuple_size = PyTuple_Size(pycpumap); - if (tuple_size == -1) - return ret; - } else { - PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required"); - return ret; - } - - cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) - return PyErr_NoMemory(); - - for (i = 0; i < tuple_size; i++) { - PyObject *flag = PyTuple_GetItem(pycpumap, i); - bool b; - - if (!flag || libvirt_boolUnwrap(flag, &b) < 0) - goto cleanup; - - if (b) - VIR_USE_CPU(cpumap, i); - else - VIR_UNUSE_CPU(cpumap, i); - } - - for (; i < cpunum; i++) - VIR_UNUSE_CPU(cpumap, i); + if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0) + return NULL; LIBVIRT_BEGIN_ALLOW_THREADS; i_retval = virDomainPinVcpu(domain, vcpu, cpumap, cpumaplen); @@ -1366,8 +1339,7 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, PyObject *pyobj_domain, *pycpumap; PyObject *ret = NULL; unsigned char *cpumap; - int cpumaplen, vcpu, tuple_size, cpunum; - size_t i; + int cpumaplen, vcpu, cpunum; unsigned int flags; int i_retval; @@ -1379,34 +1351,8 @@ libvirt_virDomainPinVcpuFlags(PyObject *self ATTRIBUTE_UNUSED, if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0) return VIR_PY_INT_FAIL; - if (PyTuple_Check(pycpumap)) { - tuple_size = PyTuple_Size(pycpumap); - if (tuple_size == -1) - return ret; - } else { - PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required"); - return ret; - } - - cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) - return PyErr_NoMemory(); - - for (i = 0; i < tuple_size; i++) { - PyObject *flag = PyTuple_GetItem(pycpumap, i); - bool b; - - if (!flag || libvirt_boolUnwrap(flag, &b) < 0) - goto cleanup; - - if (b) - VIR_USE_CPU(cpumap, i); - else - VIR_UNUSE_CPU(cpumap, i); - } - - for (; i < cpunum; i++) - VIR_UNUSE_CPU(cpumap, i); + if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0) + return NULL; LIBVIRT_BEGIN_ALLOW_THREADS; i_retval = virDomainPinVcpuFlags(domain, vcpu, cpumap, cpumaplen, flags); @@ -1505,8 +1451,7 @@ libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, virDomainPtr domain; PyObject *pyobj_domain, *pycpumap; unsigned char *cpumap = NULL; - int cpumaplen, tuple_size, cpunum; - size_t i; + int cpumaplen, cpunum; int i_retval; unsigned int flags; @@ -1519,37 +1464,9 @@ libvirt_virDomainPinEmulator(PyObject *self ATTRIBUTE_UNUSED, if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0) return VIR_PY_INT_FAIL; - cpumaplen = VIR_CPU_MAPLEN(cpunum); - - if (!PyTuple_Check(pycpumap)) { - PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required"); - return NULL; - } - - if ((tuple_size = PyTuple_Size(pycpumap)) == -1) + if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0) return NULL; - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) - return PyErr_NoMemory(); - - for (i = 0; i < tuple_size; i++) { - PyObject *flag = PyTuple_GetItem(pycpumap, i); - bool b; - - if (!flag || libvirt_boolUnwrap(flag, &b) < 0) { - VIR_FREE(cpumap); - return NULL; - } - - if (b) - VIR_USE_CPU(cpumap, i); - else - VIR_UNUSE_CPU(cpumap, i); - } - - for (; i < cpunum; i++) - VIR_UNUSE_CPU(cpumap, i); - LIBVIRT_BEGIN_ALLOW_THREADS; i_retval = virDomainPinEmulator(domain, cpumap, cpumaplen, flags); LIBVIRT_END_ALLOW_THREADS; @@ -1713,8 +1630,7 @@ libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED, PyObject *pyobj_domain, *pycpumap; PyObject *ret = NULL; unsigned char *cpumap; - int cpumaplen, iothread_val, tuple_size, cpunum; - size_t i; + int cpumaplen, iothread_val, cpunum; unsigned int flags; int i_retval; @@ -1726,33 +1642,8 @@ libvirt_virDomainPinIOThread(PyObject *self ATTRIBUTE_UNUSED, if ((cpunum = getPyNodeCPUCount(virDomainGetConnect(domain))) < 0) return VIR_PY_INT_FAIL; - if (PyTuple_Check(pycpumap)) { - if ((tuple_size = PyTuple_Size(pycpumap)) == -1) - return ret; - } else { - PyErr_SetString(PyExc_TypeError, "Unexpected type, tuple is required"); - return ret; - } - - cpumaplen = VIR_CPU_MAPLEN(cpunum); - if (VIR_ALLOC_N(cpumap, cpumaplen) < 0) - return PyErr_NoMemory(); - - for (i = 0; i < tuple_size; i++) { - PyObject *flag = PyTuple_GetItem(pycpumap, i); - bool b; - - if (!flag || libvirt_boolUnwrap(flag, &b) < 0) - goto cleanup; - - if (b) - VIR_USE_CPU(cpumap, i); - else - VIR_UNUSE_CPU(cpumap, i); - } - - for (; i < cpunum; i++) - VIR_UNUSE_CPU(cpumap, i); + if (virPyCpumapConvert(cpunum, pycpumap, &cpumap, &cpumaplen) < 0) + return NULL; LIBVIRT_BEGIN_ALLOW_THREADS; i_retval = virDomainPinIOThread(domain, iothread_val, |