[libvirt] [PATCH] python: prefer PyList_SET_ITEM to PyList_SetItem
by Giuseppe Scrivano
The PyList_SET_ITEM macro, differently from PyList_SetItem, doesn't do
any error checking and overwrites anything that was previously stored
in the list at the chosen destination position.
PyList_SET_ITEM is usually faster than PyList_SetItem, and since it is
used only to fill freshly created lists, it is safe to be used here.
Signed-off-by: Giuseppe Scrivano <gscrivan(a)redhat.com>
---
python/libvirt-override.c | 197 +++++++++++++++++++++-------------------------
1 file changed, 90 insertions(+), 107 deletions(-)
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 2e58bf9..1e1a2ee 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -1588,8 +1588,7 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
PyTuple_SetItem(info, 3, item) < 0)
goto itemError;
- if (PyList_SetItem(pycpuinfo, i, info) < 0)
- goto itemError;
+ PyList_SET_ITEM(pycpuinfo, i, info);
continue;
itemError:
@@ -1611,10 +1610,7 @@ libvirt_virDomainGetVcpus(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
}
}
- if (PyList_SetItem(pycpumap, i, info) < 0) {
- Py_DECREF(info);
- goto cleanup;
- }
+ PyList_SET_ITEM(pycpumap, i, info);
}
if (PyTuple_SetItem(pyretval, 0, pycpuinfo) < 0 ||
PyTuple_SetItem(pyretval, 1, pycpumap) < 0)
@@ -1812,7 +1808,7 @@ libvirt_virDomainGetVcpuPinInfo(PyObject *self ATTRIBUTE_UNUSED,
PyTuple_SetItem(mapinfo, pcpu,
PyBool_FromLong(VIR_CPU_USABLE(cpumaps, cpumaplen, vcpu, pcpu)));
}
- PyList_SetItem(pycpumaps, vcpu, mapinfo);
+ PyList_SET_ITEM(pycpumaps, vcpu, mapinfo);
}
VIR_FREE(cpumaps);
@@ -2115,21 +2111,21 @@ static int virConnectCredCallbackWrapper(virConnectCredentialPtr cred,
pycreditem = PyList_New(5);
Py_INCREF(Py_None);
PyTuple_SetItem(pycred, i, pycreditem);
- PyList_SetItem(pycreditem, 0, PyInt_FromLong((long) cred[i].type));
- PyList_SetItem(pycreditem, 1, PyString_FromString(cred[i].prompt));
+ PyList_SET_ITEM(pycreditem, 0, PyInt_FromLong((long) cred[i].type));
+ PyList_SET_ITEM(pycreditem, 1, PyString_FromString(cred[i].prompt));
if (cred[i].challenge) {
- PyList_SetItem(pycreditem, 2, PyString_FromString(cred[i].challenge));
+ PyList_SET_ITEM(pycreditem, 2, PyString_FromString(cred[i].challenge));
} else {
Py_INCREF(Py_None);
- PyList_SetItem(pycreditem, 2, Py_None);
+ PyList_SET_ITEM(pycreditem, 2, Py_None);
}
if (cred[i].defresult) {
- PyList_SetItem(pycreditem, 3, PyString_FromString(cred[i].defresult));
+ PyList_SET_ITEM(pycreditem, 3, PyString_FromString(cred[i].defresult));
} else {
Py_INCREF(Py_None);
- PyList_SetItem(pycreditem, 3, Py_None);
+ PyList_SET_ITEM(pycreditem, 3, Py_None);
}
- PyList_SetItem(pycreditem, 4, Py_None);
+ PyList_SET_ITEM(pycreditem, 4, Py_None);
}
PyTuple_SetItem(list, 0, pycred);
@@ -2390,7 +2386,7 @@ libvirt_virConnectListDomainsID(PyObject *self ATTRIBUTE_UNUSED,
if (ids) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_intWrap(ids[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_intWrap(ids[i]));
}
VIR_FREE(ids);
}
@@ -2426,13 +2422,12 @@ libvirt_virConnectListAllDomains(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virDomainPtrWrap(doms[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virDomainPtrWrap(doms[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
doms[i] = NULL;
}
@@ -2481,7 +2476,7 @@ libvirt_virConnectListDefinedDomains(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -2530,13 +2525,12 @@ libvirt_virDomainSnapshotListNames(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
- PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
- Py_XDECREF(pyobj_snap);
+ if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, pyobj_snap);
VIR_FREE(names[i]);
}
@@ -2575,13 +2569,12 @@ libvirt_virDomainListAllSnapshots(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
- PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
- Py_XDECREF(pyobj_snap);
+ if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, pyobj_snap);
snaps[i] = NULL;
}
@@ -2631,13 +2624,12 @@ libvirt_virDomainSnapshotListChildrenNames(PyObject *self ATTRIBUTE_UNUSED,
py_retval = PyList_New(c_retval);
for (i = 0; i < c_retval; i++) {
- if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL ||
- PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
- Py_XDECREF(pyobj_snap);
+ if ((pyobj_snap = libvirt_constcharPtrWrap(names[i])) == NULL) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, pyobj_snap);
VIR_FREE(names[i]);
}
@@ -2676,13 +2668,12 @@ libvirt_virDomainSnapshotListAllChildren(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL ||
- PyList_SetItem(py_retval, i, pyobj_snap) < 0) {
- Py_XDECREF(pyobj_snap);
+ if ((pyobj_snap = libvirt_virDomainSnapshotPtrWrap(snaps[i])) == NULL) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, pyobj_snap);
snaps[i] = NULL;
}
@@ -2734,11 +2725,11 @@ libvirt_virDomainGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (c_retval < 0)
return VIR_PY_NONE;
py_retval = PyList_New(5);
- PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
- PyList_SetItem(py_retval, 1, libvirt_ulongWrap(info.maxMem));
- PyList_SetItem(py_retval, 2, libvirt_ulongWrap(info.memory));
- PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
- PyList_SetItem(py_retval, 4,
+ PyList_SET_ITEM(py_retval, 0, libvirt_intWrap((int) info.state));
+ PyList_SET_ITEM(py_retval, 1, libvirt_ulongWrap(info.maxMem));
+ PyList_SET_ITEM(py_retval, 2, libvirt_ulongWrap(info.memory));
+ PyList_SET_ITEM(py_retval, 3, libvirt_intWrap((int) info.nrVirtCpu));
+ PyList_SET_ITEM(py_retval, 4,
libvirt_longlongWrap((unsigned long long) info.cpuTime));
return py_retval;
}
@@ -2767,8 +2758,8 @@ libvirt_virDomainGetState(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
return VIR_PY_NONE;
py_retval = PyList_New(2);
- PyList_SetItem(py_retval, 0, libvirt_intWrap(state));
- PyList_SetItem(py_retval, 1, libvirt_intWrap(reason));
+ PyList_SET_ITEM(py_retval, 0, libvirt_intWrap(state));
+ PyList_SET_ITEM(py_retval, 1, libvirt_intWrap(reason));
return py_retval;
}
@@ -2792,9 +2783,9 @@ libvirt_virDomainGetControlInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args)
if (c_retval < 0)
return VIR_PY_NONE;
py_retval = PyList_New(3);
- PyList_SetItem(py_retval, 0, libvirt_intWrap(info.state));
- PyList_SetItem(py_retval, 1, libvirt_intWrap(info.details));
- PyList_SetItem(py_retval, 2, libvirt_longlongWrap(info.stateTime));
+ PyList_SET_ITEM(py_retval, 0, libvirt_intWrap(info.state));
+ PyList_SET_ITEM(py_retval, 1, libvirt_intWrap(info.details));
+ PyList_SET_ITEM(py_retval, 2, libvirt_longlongWrap(info.stateTime));
return py_retval;
}
@@ -2818,9 +2809,9 @@ libvirt_virDomainGetBlockInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (c_retval < 0)
return VIR_PY_NONE;
py_retval = PyList_New(3);
- PyList_SetItem(py_retval, 0, libvirt_ulonglongWrap(info.capacity));
- PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.allocation));
- PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.physical));
+ PyList_SET_ITEM(py_retval, 0, libvirt_ulonglongWrap(info.capacity));
+ PyList_SET_ITEM(py_retval, 1, libvirt_ulonglongWrap(info.allocation));
+ PyList_SET_ITEM(py_retval, 2, libvirt_ulonglongWrap(info.physical));
return py_retval;
}
@@ -2842,14 +2833,14 @@ libvirt_virNodeGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (c_retval < 0)
return VIR_PY_NONE;
py_retval = PyList_New(8);
- PyList_SetItem(py_retval, 0, libvirt_constcharPtrWrap(&info.model[0]));
- PyList_SetItem(py_retval, 1, libvirt_longWrap((long) info.memory >> 10));
- PyList_SetItem(py_retval, 2, libvirt_intWrap((int) info.cpus));
- PyList_SetItem(py_retval, 3, libvirt_intWrap((int) info.mhz));
- PyList_SetItem(py_retval, 4, libvirt_intWrap((int) info.nodes));
- PyList_SetItem(py_retval, 5, libvirt_intWrap((int) info.sockets));
- PyList_SetItem(py_retval, 6, libvirt_intWrap((int) info.cores));
- PyList_SetItem(py_retval, 7, libvirt_intWrap((int) info.threads));
+ PyList_SET_ITEM(py_retval, 0, libvirt_constcharPtrWrap(&info.model[0]));
+ PyList_SET_ITEM(py_retval, 1, libvirt_longWrap((long) info.memory >> 10));
+ PyList_SET_ITEM(py_retval, 2, libvirt_intWrap((int) info.cpus));
+ PyList_SET_ITEM(py_retval, 3, libvirt_intWrap((int) info.mhz));
+ PyList_SET_ITEM(py_retval, 4, libvirt_intWrap((int) info.nodes));
+ PyList_SET_ITEM(py_retval, 5, libvirt_intWrap((int) info.sockets));
+ PyList_SET_ITEM(py_retval, 6, libvirt_intWrap((int) info.cores));
+ PyList_SET_ITEM(py_retval, 7, libvirt_intWrap((int) info.threads));
return py_retval;
}
@@ -2965,7 +2956,7 @@ libvirt_virConnectListNetworks(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -3011,7 +3002,7 @@ libvirt_virConnectListDefinedNetworks(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -3048,13 +3039,12 @@ libvirt_virConnectListAllNetworks(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virNetworkPtrWrap(nets[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virNetworkPtrWrap(nets[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
nets[i] = NULL;
}
@@ -3219,7 +3209,7 @@ libvirt_virNodeGetCellsFreeMemory(PyObject *self ATTRIBUTE_UNUSED, PyObject *arg
}
py_retval = PyList_New(c_retval);
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i,
+ PyList_SET_ITEM(py_retval, i,
libvirt_longlongWrap((long long) freeMems[i]));
}
VIR_FREE(freeMems);
@@ -3398,7 +3388,7 @@ libvirt_virConnectListStoragePools(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -3452,7 +3442,7 @@ libvirt_virConnectListDefinedStoragePools(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -3489,13 +3479,12 @@ libvirt_virConnectListAllStoragePools(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virStoragePoolPtrWrap(pools[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
pools[i] = NULL;
}
@@ -3552,7 +3541,7 @@ libvirt_virStoragePoolListVolumes(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -3590,13 +3579,12 @@ libvirt_virStoragePoolListAllVolumes(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virStorageVolPtrWrap(vols[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
vols[i] = NULL;
}
@@ -3654,12 +3642,12 @@ libvirt_virStoragePoolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if ((py_retval = PyList_New(4)) == NULL)
return VIR_PY_NONE;
- PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.state));
- PyList_SetItem(py_retval, 1,
+ PyList_SET_ITEM(py_retval, 0, libvirt_intWrap((int) info.state));
+ PyList_SET_ITEM(py_retval, 1,
libvirt_longlongWrap((unsigned long long) info.capacity));
- PyList_SetItem(py_retval, 2,
+ PyList_SET_ITEM(py_retval, 2,
libvirt_longlongWrap((unsigned long long) info.allocation));
- PyList_SetItem(py_retval, 3,
+ PyList_SET_ITEM(py_retval, 3,
libvirt_longlongWrap((unsigned long long) info.available));
return py_retval;
}
@@ -3685,10 +3673,10 @@ libvirt_virStorageVolGetInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if ((py_retval = PyList_New(3)) == NULL)
return VIR_PY_NONE;
- PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
- PyList_SetItem(py_retval, 1,
+ PyList_SET_ITEM(py_retval, 0, libvirt_intWrap((int) info.type));
+ PyList_SET_ITEM(py_retval, 1,
libvirt_longlongWrap((unsigned long long) info.capacity));
- PyList_SetItem(py_retval, 2,
+ PyList_SET_ITEM(py_retval, 2,
libvirt_longlongWrap((unsigned long long) info.allocation));
return py_retval;
}
@@ -3806,7 +3794,7 @@ libvirt_virNodeListDevices(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -3843,13 +3831,12 @@ libvirt_virConnectListAllNodeDevices(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virNodeDevicePtrWrap(devices[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
devices[i] = NULL;
}
@@ -3897,7 +3884,7 @@ libvirt_virNodeDeviceListCaps(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -4017,7 +4004,7 @@ libvirt_virConnectListSecrets(PyObject *self ATTRIBUTE_UNUSED,
if (uuids) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
VIR_FREE(uuids[i]);
}
VIR_FREE(uuids);
@@ -4054,13 +4041,12 @@ libvirt_virConnectListAllSecrets(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virSecretPtrWrap(secrets[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virSecretPtrWrap(secrets[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
secrets[i] = NULL;
}
@@ -4237,7 +4223,7 @@ libvirt_virConnectListNWFilters(PyObject *self ATTRIBUTE_UNUSED,
if (uuids) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(uuids[i]));
VIR_FREE(uuids[i]);
}
VIR_FREE(uuids);
@@ -4274,13 +4260,12 @@ libvirt_virConnectListAllNWFilters(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virNWFilterPtrWrap(filters[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virNWFilterPtrWrap(filters[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
filters[i] = NULL;
}
@@ -4337,7 +4322,7 @@ libvirt_virConnectListInterfaces(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -4392,7 +4377,7 @@ libvirt_virConnectListDefinedInterfaces(PyObject *self ATTRIBUTE_UNUSED,
if (names) {
for (i = 0; i < c_retval; i++) {
- PyList_SetItem(py_retval, i, libvirt_constcharPtrWrap(names[i]));
+ PyList_SET_ITEM(py_retval, i, libvirt_constcharPtrWrap(names[i]));
VIR_FREE(names[i]);
}
VIR_FREE(names);
@@ -4430,13 +4415,12 @@ libvirt_virConnectListAllInterfaces(PyObject *self ATTRIBUTE_UNUSED,
goto cleanup;
for (i = 0; i < c_retval; i++) {
- if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i])) ||
- PyList_SetItem(py_retval, i, tmp) < 0) {
- Py_XDECREF(tmp);
+ if (!(tmp = libvirt_virInterfacePtrWrap(ifaces[i]))) {
Py_DECREF(py_retval);
py_retval = NULL;
goto cleanup;
}
+ PyList_SET_ITEM(py_retval, i, tmp);
/* python steals the pointer */
ifaces[i] = NULL;
}
@@ -4519,18 +4503,18 @@ libvirt_virDomainGetJobInfo(PyObject *self ATTRIBUTE_UNUSED, PyObject *args) {
if (c_retval < 0)
return VIR_PY_NONE;
py_retval = PyList_New(12);
- PyList_SetItem(py_retval, 0, libvirt_intWrap((int) info.type));
- PyList_SetItem(py_retval, 1, libvirt_ulonglongWrap(info.timeElapsed));
- PyList_SetItem(py_retval, 2, libvirt_ulonglongWrap(info.timeRemaining));
- PyList_SetItem(py_retval, 3, libvirt_ulonglongWrap(info.dataTotal));
- PyList_SetItem(py_retval, 4, libvirt_ulonglongWrap(info.dataProcessed));
- PyList_SetItem(py_retval, 5, libvirt_ulonglongWrap(info.dataRemaining));
- PyList_SetItem(py_retval, 6, libvirt_ulonglongWrap(info.memTotal));
- PyList_SetItem(py_retval, 7, libvirt_ulonglongWrap(info.memProcessed));
- PyList_SetItem(py_retval, 8, libvirt_ulonglongWrap(info.memRemaining));
- PyList_SetItem(py_retval, 9, libvirt_ulonglongWrap(info.fileTotal));
- PyList_SetItem(py_retval, 10, libvirt_ulonglongWrap(info.fileProcessed));
- PyList_SetItem(py_retval, 11, libvirt_ulonglongWrap(info.fileRemaining));
+ PyList_SET_ITEM(py_retval, 0, libvirt_intWrap((int) info.type));
+ PyList_SET_ITEM(py_retval, 1, libvirt_ulonglongWrap(info.timeElapsed));
+ PyList_SET_ITEM(py_retval, 2, libvirt_ulonglongWrap(info.timeRemaining));
+ PyList_SET_ITEM(py_retval, 3, libvirt_ulonglongWrap(info.dataTotal));
+ PyList_SET_ITEM(py_retval, 4, libvirt_ulonglongWrap(info.dataProcessed));
+ PyList_SET_ITEM(py_retval, 5, libvirt_ulonglongWrap(info.dataRemaining));
+ PyList_SET_ITEM(py_retval, 6, libvirt_ulonglongWrap(info.memTotal));
+ PyList_SET_ITEM(py_retval, 7, libvirt_ulonglongWrap(info.memProcessed));
+ PyList_SET_ITEM(py_retval, 8, libvirt_ulonglongWrap(info.memRemaining));
+ PyList_SET_ITEM(py_retval, 9, libvirt_ulonglongWrap(info.fileTotal));
+ PyList_SET_ITEM(py_retval, 10, libvirt_ulonglongWrap(info.fileProcessed));
+ PyList_SET_ITEM(py_retval, 11, libvirt_ulonglongWrap(info.fileRemaining));
return py_retval;
}
@@ -5916,7 +5900,7 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE
PyTuple_SetItem(pair, 0, libvirt_constcharPtrWrap(subject->identities[i].type));
PyTuple_SetItem(pair, 1, libvirt_constcharPtrWrap(subject->identities[i].name));
- PyList_SetItem(pyobj_subject, i, pair);
+ PyList_SET_ITEM(pyobj_subject, i, pair);
}
/* Call the Callback Dispatcher */
@@ -7101,8 +7085,7 @@ libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
for (i = 0; i < i_retval; i++) {
if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL)
goto error;
- if (PyList_SetItem(pycpumap, i, pyused) < 0)
- goto error;
+ PyList_SET_ITEM(pycpumap, i, pyused);
}
if (PyTuple_SetItem(ret, 1, pycpumap) < 0)
--
1.8.3.1
11 years
[libvirt] [PATCH] qemuMigrationBeginPhase: Check for 'drive-mirror' for NBD
by Michal Privoznik
So far we are checking if qemu supports 'nbd-server-start'. This,
however, makes no sense on the source as nbd-server-* is used on the
destination. On the source the 'drive-mirror' is used instead.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_migration.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 7d8b727..166fbb9 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1987,7 +1987,7 @@ static char
goto cleanup;
if (flags & (VIR_MIGRATE_NON_SHARED_DISK | VIR_MIGRATE_NON_SHARED_INC) &&
- virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_SERVER)) {
+ virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DRIVE_MIRROR)) {
/* TODO support NBD for TUNNELLED migration */
if (flags & VIR_MIGRATE_TUNNELLED) {
VIR_WARN("NBD in tunnelled migration is currently not supported");
--
1.8.1.5
11 years
[libvirt] rpmbuild problem for 1.1.4
by Franky Van Liedekerke
Hi,
using the latest 1.1.4, I'm having issues to get the rpm build to
complete. I'm always getting this error:
==================
Wrote: /root/rpmbuild/RPMS/x86_64/libvirt-1.1.4-1.el6.x86_64.rpm
error: create archive failed on file
/root/rpmbuild/BUILDROOT/libvirt-1.1.4-1.el6.x86_64/usr/share/doc/libvirt-docs-1.1.4/html/32favicon.png:
cpio: Bad magic
RPM build errors:
File listed twice: /usr/share/doc/libvirt-docs-1.1.4
create archive failed on file
/root/rpmbuild/BUILDROOT/libvirt-1.1.4-1.el6.x86_64/usr/share/doc/libvirt-docs-1.1.4/html/32favicon.png:
cpio: Bad magic
==================
Using 1.1.3-1 results in the same error, while 1.1.2 builds without
problems (all 3 tried today).
The command is just "rpmbuild -tb libvirt-xxx.tgz" on a patched CentOS
6 system.
I also did a diff on the favicon file and it is the same in 1.1.2 and
1.1.3-1.
Any hints on how the get the build to work on a CentOS 6 system? The
spec file has changed quite a bit between 1.1.2 and 1.1.3 ...
Franky
11 years
[libvirt] [PATCH]conf: fix incorrect error log in virCPUDefIsEqual
by Chen Hanxiao
From: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
A copy-paste error.
s/model/vendor id
Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
src/conf/cpu_conf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 5deb325..c4917b8 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -767,7 +767,7 @@ virCPUDefIsEqual(virCPUDefPtr src,
if (STRNEQ_NULLABLE(src->vendor_id, dst->vendor_id)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Target CPU model %s does not match source %s"),
+ _("Target CPU vendor id %s does not match source %s"),
NULLSTR(dst->vendor_id), NULLSTR(src->vendor_id));
goto cleanup;
}
--
1.8.2.1
11 years
[libvirt] [PATCH] tests: Distribute virpcitestdata
by Michal Privoznik
Since 21685c955e5466 we have tests/virpcitestdata dir containing the PCI
config files for some dummy PCI devices that are used int virpcitest.
However, the directory containing the config files is not distributed
making 'make rpm' fail.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
Pushed under build breaker rule.
tests/Makefile.am | 1 +
1 file changed, 1 insertion(+)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2c2e5a9..70b5f61 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -107,6 +107,7 @@ EXTRA_DIST = \
sysinfodata \
test-lib.sh \
virsh-uriprecedence \
+ virpcitestdata \
vmx2xmldata \
xencapsdata \
xmconfigdata \
--
1.8.1.5
11 years
[libvirt] [PATCH] tests: Fix virtpcitest in VPATH
by Jiri Denemark
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
tests/virpcimock.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/tests/virpcimock.c b/tests/virpcimock.c
index 9d5c079..19062c3 100644
--- a/tests/virpcimock.c
+++ b/tests/virpcimock.c
@@ -305,9 +305,14 @@ pci_device_new_from_stub(const struct pciDevice *data)
char *configSrc, *configDst;
char tmp[32];
struct stat sb;
+ char *abs_srcdir;
+
+ abs_srcdir = getenv("abs_srcdir");
+ if (!abs_srcdir)
+ abs_srcdir = getcwd(NULL, 0);
if (VIR_ALLOC_QUIET(dev) < 0 ||
- virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", abs_builddir, data->id) < 0 ||
+ virAsprintfQuiet(&configSrc, "%s/virpcitestdata/%s.config", abs_srcdir, data->id) < 0 ||
virAsprintfQuiet(&devpath, "%s/devices/%s", fakesysfsdir, data->id) < 0)
ABORT_OOM();
--
1.8.4.2
11 years
[libvirt] [PATCH 0/4] Split out disk source parsing code
by Peter Krempa
To avoid code duplication when I'll later attempt to add
support for snapshots on gluster I'll need to split out
the parsing code for disk source.
Peter Krempa (4):
conf: Refactor virDomainDiskSourcePoolDefParse
conf: Split out code to parse the source of a disk definition
conf: Rename virDomainDiskHostDefFree to virDomainDiskHostDefClear
conf: Refactor virDomainDiskSourceDefParse
src/conf/domain_conf.c | 297 +++++++++++++++++++++++++----------------------
src/conf/domain_conf.h | 2 +-
src/libvirt_private.syms | 2 +-
src/qemu/qemu_command.c | 4 +-
4 files changed, 165 insertions(+), 140 deletions(-)
--
1.8.4.2
11 years
[libvirt] When vm's status file being left over, some persistent but inactive vms will be lost by libvirtd after libvirtd rebooting.
by Wangyufei (A)
Hello,
I found a problem that:
vm's status file may be left over in the path /var/run/libvirt/qemu under some situation, such as host reboot. When vm's status file is left over, some
persistent but inactive vms will be lost by libvirtd after it is rebooted. And you can do as follows to reproduce the problem:
1、Create a vm and start it by the commands: virsh define vm-xml and virsh start vm-name.
2、Stop the libvirtd by the command: service libvirtd stop.
3、Kill the qemu process related to the vm, and make the vm's status file left over.
4、Start libvirtd.
After starting the libvirtd service, we find that the vm has been lost by libvirtd with command"virsh list --all".
What we expect is that the vm is shown with shutoff status, should we?
The reason for the problem is that:
During libvirtd startup, it first loads status files of vms under the path /var/run/libvirt/qemu, creates virDomainObj for each vm and adds it to
driver->domains list.
Then it creates a thread to connect related qemu process for each virDomainObj in the domains list.Because the qemu process has been killed, so connecting to
qemu will be failed. When connecting to qemu failed, connection-thread will do the follows:
1、Check if vm->persistent is 1.
2、If vm->persistent is not 1, then qemuDomainRemoveInactive() is called to remove the virDomainObj.
3、Then the following calling sequence will occur:qemuDomainRemoveInactive() -->virDomainObjListRemove()-->virHashRemoveEntry(). Around virHashRemoveEntry(),
domlist and dom will be locked and unlocked sequencely.
The problem of the above steps is that vm->persistent maybe has been set to 1 by libvirtd main-thread when connection-thread calling virHashRemoveEntry() to
remove the dom. That is a persistent virDomainObj is removed during libvirtd startup.
Two ways can resolve the above problem:
1、expending the range of locking virDomainObj and virDomainObjList, lock the object of virDomainObj and virDomainObjList in connection-thread before checking vm->persistent.
2、checking vm->persistent again before calling virHashRemoveEntry().
Do you think it is a problem described above and which way listed above is more suitable to resolve the problem, or is there any other better idea? Any suggestions?
Best Regards,
-WangYufei
11 years
[libvirt] [PATCH] qemu: clean up migration ports when migration cancelled
by Wangyufei (A)
>From bfb2dafa8ea183781446c7cbe0376e1a2d41a5ae Mon Sep 17 00:00:00 2001
From: Zeng Junliang <zengjunliang(a)huawei.com>
Date: Wed, 6 Nov 2013 11:36:57 +0800
Subject: [PATCH] qemu: clean up migration ports when migration cancelled
If there's a migration cancelled, the bitmap of migration port should be cleaned up too.
Signed-off-by: Zeng Junliang <zengjunliang(a)huawei.com>
---
src/qemu/qemu_migration.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 4f35a7a..594d1cd 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -4387,12 +4387,16 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
virCapsPtr caps = NULL;
+ unsigned short port = 0;
VIR_DEBUG("driver=%p, dconn=%p, vm=%p, cookiein=%s, cookieinlen=%d, "
"cookieout=%p, cookieoutlen=%p, flags=%lx, retcode=%d",
driver, dconn, vm, NULLSTR(cookiein), cookieinlen,
cookieout, cookieoutlen, flags, retcode);
+ port = priv->migrationPort;
+ priv->migrationPort = 0;
+
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
@@ -4439,8 +4443,6 @@ qemuMigrationFinish(virQEMUDriverPtr driver,
}
qemuMigrationStopNBDServer(driver, vm, mig);
- virPortAllocatorRelease(driver->migrationPorts, priv->migrationPort);
- priv->migrationPort = 0;
if (flags & VIR_MIGRATE_PERSIST_DEST) {
virDomainDefPtr vmdef;
@@ -4573,6 +4575,7 @@ endjob:
}
cleanup:
+ virPortAllocatorRelease(driver->migrationPorts, port);
if (vm) {
VIR_FREE(priv->origname);
virObjectUnlock(vm);
--
1.7.3.1.msysgit.0
Best Regards,
-WangYufei
11 years
[libvirt] [PATCH 0/3] more storage cleanups
by Eric Blake
I'm still plugging away at getting gluster backing chains to work;
here's a couple of independent cleanups that can be applied first.
Eric Blake (3):
storage: use simpler 'char *'
storage: avoid short reads while chasing backing chain
storage: reduce number of stat calls
src/libvirt_private.syms | 1 +
src/storage/storage_backend.c | 62 +++++++++++++++++--------------------
src/storage/storage_backend.h | 10 ++++--
src/storage/storage_backend_fs.c | 5 +--
src/storage/storage_backend_mpath.c | 7 +++--
src/storage/storage_backend_scsi.c | 7 +++--
src/util/virfile.c | 21 +++++++++++++
src/util/virfile.h | 9 ++++--
src/util/virstoragefile.c | 52 ++++++++++++++-----------------
9 files changed, 100 insertions(+), 74 deletions(-)
--
1.8.3.1
11 years