The volume object list is also directly manipulated in the storage
driver, test storage driver, and parallels storage driver (this should
probably be consolidated).
---
src/conf/interface_conf.c | 13 ++-----------
src/conf/interface_conf.h | 4 ++--
src/conf/network_conf.c | 11 +----------
src/conf/network_conf.h | 2 +-
src/conf/node_device_conf.c | 11 +----------
src/conf/node_device_conf.h | 4 ++--
src/conf/nwfilter_conf.c | 11 +----------
src/conf/nwfilter_conf.h | 2 +-
src/conf/storage_conf.c | 11 +----------
src/conf/storage_conf.h | 4 ++--
src/parallels/parallels_storage.c | 14 +-------------
src/storage/storage_backend_rbd.c | 2 +-
src/storage/storage_driver.c | 12 +-----------
src/test/test_driver.c | 14 +-------------
14 files changed, 18 insertions(+), 97 deletions(-)
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index fc3602a..078f2ca 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -1,7 +1,7 @@
/*
* interface_conf.c: interfaces XML handling
*
- * Copyright (C) 2006-2010 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -1313,16 +1313,7 @@ void virInterfaceRemove(virInterfaceObjListPtr interfaces,
if (interfaces->objs[i] == iface) {
virInterfaceObjUnlock(interfaces->objs[i]);
virInterfaceObjFree(interfaces->objs[i]);
-
- if (i < (interfaces->count - 1))
- memmove(interfaces->objs + i, interfaces->objs + i + 1,
- sizeof(*(interfaces->objs)) * (interfaces->count - (i +
1)));
-
- if (VIR_REALLOC_N(interfaces->objs, interfaces->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- interfaces->count--;
-
+ VIR_DELETE_ELEMENT(interfaces->objs, i, interfaces->count);
break;
}
virInterfaceObjUnlock(interfaces->objs[i]);
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index 1749629..bcfca62 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -1,7 +1,7 @@
/*
* interface_conf.h: interface XML handling entry points
*
- * Copyright (C) 2006-2009 Red Hat, Inc.
+ * Copyright (C) 2006-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -171,7 +171,7 @@ struct _virInterfaceObj {
typedef struct _virInterfaceObjList virInterfaceObjList;
typedef virInterfaceObjList *virInterfaceObjListPtr;
struct _virInterfaceObjList {
- unsigned int count;
+ size_t count;
virInterfaceObjPtr *objs;
};
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 777b89f..c36bdd3 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -495,16 +495,7 @@ void virNetworkRemoveInactive(virNetworkObjListPtr nets,
if (nets->objs[i] == net) {
virNetworkObjUnlock(nets->objs[i]);
virNetworkObjFree(nets->objs[i]);
-
- if (i < (nets->count - 1))
- memmove(nets->objs + i, nets->objs + i + 1,
- sizeof(*(nets->objs)) * (nets->count - (i + 1)));
-
- if (VIR_REALLOC_N(nets->objs, nets->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- nets->count--;
-
+ VIR_DELETE_ELEMENT(nets->objs, i, nets->count);
break;
}
virNetworkObjUnlock(nets->objs[i]);
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 87d7746..d4dc214 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -231,7 +231,7 @@ struct _virNetworkObj {
typedef struct _virNetworkObjList virNetworkObjList;
typedef virNetworkObjList *virNetworkObjListPtr;
struct _virNetworkObjList {
- unsigned int count;
+ size_t count;
virNetworkObjPtr *objs;
};
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 41fa8e4..66a446c 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -218,16 +218,7 @@ void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs,
if (devs->objs[i] == dev) {
virNodeDeviceObjUnlock(dev);
virNodeDeviceObjFree(devs->objs[i]);
-
- if (i < (devs->count - 1))
- memmove(devs->objs + i, devs->objs + i + 1,
- sizeof(*(devs->objs)) * (devs->count - (i + 1)));
-
- if (VIR_REALLOC_N(devs->objs, devs->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- devs->count--;
-
+ VIR_DELETE_ELEMENT(devs->objs, i, devs->count);
break;
}
virNodeDeviceObjUnlock(dev);
diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h
index e394042..ee02991 100644
--- a/src/conf/node_device_conf.h
+++ b/src/conf/node_device_conf.h
@@ -1,7 +1,7 @@
/*
* node_device_conf.h: config handling for node devices
*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
* Copyright (C) 2008 Virtual Iron Software, Inc.
* Copyright (C) 2008 David F. Lively
*
@@ -199,7 +199,7 @@ struct _virNodeDeviceObj {
typedef struct _virNodeDeviceObjList virNodeDeviceObjList;
typedef virNodeDeviceObjList *virNodeDeviceObjListPtr;
struct _virNodeDeviceObjList {
- unsigned int count;
+ size_t count;
virNodeDeviceObjPtr *objs;
};
diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c
index 46580e9..2d32bd3 100644
--- a/src/conf/nwfilter_conf.c
+++ b/src/conf/nwfilter_conf.c
@@ -426,16 +426,7 @@ virNWFilterObjRemove(virNWFilterObjListPtr nwfilters,
if (nwfilters->objs[i] == nwfilter) {
virNWFilterObjUnlock(nwfilters->objs[i]);
virNWFilterObjFree(nwfilters->objs[i]);
-
- if (i < (nwfilters->count - 1))
- memmove(nwfilters->objs + i, nwfilters->objs + i + 1,
- sizeof(*(nwfilters->objs)) * (nwfilters->count - (i +
1)));
-
- if (VIR_REALLOC_N(nwfilters->objs, nwfilters->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- nwfilters->count--;
-
+ VIR_DELETE_ELEMENT(nwfilters->objs, i, nwfilters->count);
break;
}
virNWFilterObjUnlock(nwfilters->objs[i]);
diff --git a/src/conf/nwfilter_conf.h b/src/conf/nwfilter_conf.h
index 805fbe7..4a2a9f3 100644
--- a/src/conf/nwfilter_conf.h
+++ b/src/conf/nwfilter_conf.h
@@ -547,7 +547,7 @@ struct _virNWFilterObj {
typedef struct _virNWFilterObjList virNWFilterObjList;
typedef virNWFilterObjList *virNWFilterObjListPtr;
struct _virNWFilterObjList {
- unsigned int count;
+ size_t count;
virNWFilterObjPtr *objs;
};
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index ad0f0c1..164eea0 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -402,16 +402,7 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
if (pools->objs[i] == pool) {
virStoragePoolObjUnlock(pools->objs[i]);
virStoragePoolObjFree(pools->objs[i]);
-
- if (i < (pools->count - 1))
- memmove(pools->objs + i, pools->objs + i + 1,
- sizeof(*(pools->objs)) * (pools->count - (i + 1)));
-
- if (VIR_REALLOC_N(pools->objs, pools->count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- pools->count--;
-
+ VIR_DELETE_ELEMENT(pools->objs, i, pools->count);
break;
}
virStoragePoolObjUnlock(pools->objs[i]);
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 743b768..e42e4c3 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -116,7 +116,7 @@ struct _virStorageVolDef {
typedef struct _virStorageVolDefList virStorageVolDefList;
typedef virStorageVolDefList *virStorageVolDefListPtr;
struct _virStorageVolDefList {
- unsigned int count;
+ size_t count;
virStorageVolDefPtr *objs;
};
@@ -319,7 +319,7 @@ struct _virStoragePoolObj {
typedef struct _virStoragePoolObjList virStoragePoolObjList;
typedef virStoragePoolObjList *virStoragePoolObjListPtr;
struct _virStoragePoolObjList {
- unsigned int count;
+ size_t count;
virStoragePoolObjPtr *objs;
};
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index 9075dfd..2b5b9ba 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -1187,19 +1187,7 @@ parallelsStorageVolumeDelete(virStorageVolPtr vol, unsigned int
flags)
}
virStorageVolDefFree(privvol);
-
- if (i < (privpool->volumes.count - 1))
- memmove(privpool->volumes.objs + i,
- privpool->volumes.objs + i + 1,
- sizeof(*(privpool->volumes.objs)) *
- (privpool->volumes.count - (i + 1)));
-
- if (VIR_REALLOC_N(privpool->volumes.objs,
- privpool->volumes.count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- privpool->volumes.count--;
-
+ VIR_DELETE_ELEMENT(privpool->volumes.objs, i,
privpool->volumes.count);
break;
}
}
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index bc61cf7..b9212fe 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -343,7 +343,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn
ATTRIBUTE_UNUSED,
pool->volumes.objs[pool->volumes.count++] = vol;
}
- VIR_DEBUG("Found %d images in RBD pool %s",
+ VIR_DEBUG("Found %zu images in RBD pool %s",
pool->volumes.count, pool->def->source.name);
ret = 0;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index c567fff..d7a71e8 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2177,17 +2177,7 @@ storageVolumeDelete(virStorageVolPtr obj,
VIR_INFO("Deleting volume '%s' from storage pool
'%s'",
vol->name, pool->def->name);
virStorageVolDefFree(vol);
- vol = NULL;
-
- if (i < (pool->volumes.count - 1))
- memmove(pool->volumes.objs + i, pool->volumes.objs + i + 1,
- sizeof(*(pool->volumes.objs)) * (pool->volumes.count - (i +
1)));
-
- if (VIR_REALLOC_N(pool->volumes.objs, pool->volumes.count - 1) < 0)
{
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- pool->volumes.count--;
-
+ VIR_DELETE_ELEMENT(pool->volumes.objs, i, pool->volumes.count);
break;
}
}
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 6ca59e2..a33841f 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -5035,19 +5035,7 @@ testStorageVolumeDelete(virStorageVolPtr vol,
for (i = 0 ; i < privpool->volumes.count ; i++) {
if (privpool->volumes.objs[i] == privvol) {
virStorageVolDefFree(privvol);
-
- if (i < (privpool->volumes.count - 1))
- memmove(privpool->volumes.objs + i,
- privpool->volumes.objs + i + 1,
- sizeof(*(privpool->volumes.objs)) *
- (privpool->volumes.count - (i + 1)));
-
- if (VIR_REALLOC_N(privpool->volumes.objs,
- privpool->volumes.count - 1) < 0) {
- ; /* Failure to reduce memory allocation isn't fatal */
- }
- privpool->volumes.count--;
-
+ VIR_DELETE_ELEMENT(privpool->volumes.objs, i,
privpool->volumes.count);
break;
}
}
--
1.7.11.7