In preparation for privatizing the object, use the accessor.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/test/test_driver.c | 162 +++++++++++++++++++++++++++----------------------
1 file changed, 91 insertions(+), 71 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 7ddff053b..5e68b03e5 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1046,6 +1046,7 @@ testOpenVolumesForPool(const char *file,
virStoragePoolObjPtr obj,
int objidx)
{
+ virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
char *vol_xpath;
size_t i;
int num, ret = -1;
@@ -1067,12 +1068,12 @@ testOpenVolumesForPool(const char *file,
if (!node)
goto error;
- if (!(volDef = virStorageVolDefParseNode(obj->def, ctxt->doc, node, 0)))
+ if (!(volDef = virStorageVolDefParseNode(def, ctxt->doc, node, 0)))
goto error;
if (!volDef->target.path) {
if (virAsprintf(&volDef->target.path, "%s/%s",
- obj->def->target.path, volDef->name) < 0)
+ def->target.path, volDef->name) < 0)
goto error;
}
@@ -1082,8 +1083,8 @@ testOpenVolumesForPool(const char *file,
if (virStoragePoolObjAddVol(obj, volDef) < 0)
goto error;
- obj->def->allocation += volDef->target.allocation;
- obj->def->available = (obj->def->capacity -
obj->def->allocation);
+ def->allocation += volDef->target.allocation;
+ def->available = (def->capacity - def->allocation);
volDef = NULL;
}
@@ -4072,10 +4073,11 @@ static int
testStoragePoolObjSetDefaults(virStoragePoolObjPtr obj)
{
char *configFile;
+ virStoragePoolDefPtr def = virStoragePoolObjGetDef(obj);
- obj->def->capacity = defaultPoolCap;
- obj->def->allocation = defaultPoolAlloc;
- obj->def->available = defaultPoolCap - defaultPoolAlloc;
+ def->capacity = defaultPoolCap;
+ def->allocation = defaultPoolAlloc;
+ def->available = defaultPoolCap - defaultPoolAlloc;
if (VIR_STRDUP(configFile, "") < 0)
return -1;
@@ -4172,13 +4174,14 @@ testStoragePoolLookupByUUID(virConnectPtr conn,
{
testDriverPtr privconn = conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
if (!(obj = testStoragePoolObjFindByUUID(privconn, uuid)))
return NULL;
+ def = virStoragePoolObjGetDef(obj);
- pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
- NULL, NULL);
+ pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
virStoragePoolObjUnlock(obj);
return pool;
@@ -4191,13 +4194,14 @@ testStoragePoolLookupByName(virConnectPtr conn,
{
testDriverPtr privconn = conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
if (!(obj = testStoragePoolObjFindByName(privconn, name)))
return NULL;
+ def = virStoragePoolObjGetDef(obj);
- pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid,
- NULL, NULL);
+ pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
virStoragePoolObjUnlock(obj);
return pool;
@@ -4442,38 +4446,40 @@ testStoragePoolCreateXML(virConnectPtr conn,
unsigned int flags)
{
testDriverPtr privconn = conn->privateData;
- virStoragePoolDefPtr def;
+ virStoragePoolDefPtr newDef;
virStoragePoolObjPtr obj = NULL;
+ virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
virObjectEventPtr event = NULL;
virCheckFlags(0, NULL);
testDriverLock(privconn);
- if (!(def = virStoragePoolDefParseString(xml)))
+ if (!(newDef = virStoragePoolDefParseString(xml)))
goto cleanup;
- obj = virStoragePoolObjFindByUUID(&privconn->pools, def->uuid);
+ obj = virStoragePoolObjFindByUUID(&privconn->pools, newDef->uuid);
if (!obj)
- obj = virStoragePoolObjFindByName(&privconn->pools, def->name);
+ obj = virStoragePoolObjFindByName(&privconn->pools, newDef->name);
if (obj) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("storage pool already exists"));
goto cleanup;
}
- if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def)))
+ if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, newDef)))
goto cleanup;
- def = NULL;
+ newDef = NULL;
+ def = virStoragePoolObjGetDef(obj);
- if (obj->def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
+ if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
/* In the real code, we'd call virVHBAManageVport followed by
* find_new_device, but we cannot do that here since we're not
* mocking udev. The mock routine will copy an existing vHBA and
* rename a few fields to mock that. */
if (testCreateVport(privconn,
- obj->def->source.adapter.data.fchost.wwnn,
- obj->def->source.adapter.data.fchost.wwpn) < 0) {
+ def->source.adapter.data.fchost.wwnn,
+ def->source.adapter.data.fchost.wwpn) < 0) {
virStoragePoolObjRemove(&privconn->pools, obj);
obj = NULL;
goto cleanup;
@@ -4493,14 +4499,14 @@ testStoragePoolCreateXML(virConnectPtr conn,
virStoragePoolObjSetActive(obj, true);
- event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid,
+ event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
VIR_STORAGE_POOL_EVENT_STARTED,
0);
- pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL,
NULL);
+ pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
cleanup:
- virStoragePoolDefFree(def);
+ virStoragePoolDefFree(newDef);
testObjectEventQueue(privconn, event);
if (obj)
virStoragePoolObjUnlock(obj);
@@ -4515,26 +4521,28 @@ testStoragePoolDefineXML(virConnectPtr conn,
unsigned int flags)
{
testDriverPtr privconn = conn->privateData;
- virStoragePoolDefPtr def;
+ virStoragePoolDefPtr newDef;
virStoragePoolObjPtr obj = NULL;
+ virStoragePoolDefPtr def;
virStoragePoolPtr pool = NULL;
virObjectEventPtr event = NULL;
virCheckFlags(0, NULL);
testDriverLock(privconn);
- if (!(def = virStoragePoolDefParseString(xml)))
+ if (!(newDef = virStoragePoolDefParseString(xml)))
goto cleanup;
- def->capacity = defaultPoolCap;
- def->allocation = defaultPoolAlloc;
- def->available = defaultPoolCap - defaultPoolAlloc;
+ newDef->capacity = defaultPoolCap;
+ newDef->allocation = defaultPoolAlloc;
+ newDef->available = defaultPoolCap - defaultPoolAlloc;
- if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, def)))
+ if (!(obj = virStoragePoolObjAssignDef(&privconn->pools, newDef)))
goto cleanup;
- def = NULL;
+ newDef = NULL;
+ def = virStoragePoolObjGetDef(obj);
- event = virStoragePoolEventLifecycleNew(obj->def->name, obj->def->uuid,
+ event = virStoragePoolEventLifecycleNew(def->name, def->uuid,
VIR_STORAGE_POOL_EVENT_DEFINED,
0);
@@ -4544,10 +4552,10 @@ testStoragePoolDefineXML(virConnectPtr conn,
goto cleanup;
}
- pool = virGetStoragePool(conn, obj->def->name, obj->def->uuid, NULL,
NULL);
+ pool = virGetStoragePool(conn, def->name, def->uuid, NULL, NULL);
cleanup:
- virStoragePoolDefFree(def);
+ virStoragePoolDefFree(newDef);
testObjectEventQueue(privconn, event);
if (obj)
virStoragePoolObjUnlock(obj);
@@ -4633,24 +4641,25 @@ testStoragePoolDestroy(virStoragePoolPtr pool)
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
int ret = -1;
virObjectEventPtr event = NULL;
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
return -1;
+ def = virStoragePoolObjGetDef(obj);
virStoragePoolObjSetActive(obj, false);
- if (obj->def->source.adapter.type ==
- VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
+ if (def->source.adapter.type == VIR_STORAGE_ADAPTER_TYPE_FC_HOST) {
if (testDestroyVport(privconn,
- obj->def->source.adapter.data.fchost.wwnn,
- obj->def->source.adapter.data.fchost.wwpn) < 0)
+ def->source.adapter.data.fchost.wwnn,
+ def->source.adapter.data.fchost.wwpn) < 0)
goto cleanup;
}
- event = virStoragePoolEventLifecycleNew(obj->def->name,
- obj->def->uuid,
+ event = virStoragePoolEventLifecycleNew(def->name,
+ def->uuid,
VIR_STORAGE_POOL_EVENT_STOPPED,
0);
@@ -4712,18 +4721,20 @@ testStoragePoolGetInfo(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
return -1;
+ def = virStoragePoolObjGetDef(obj);
memset(info, 0, sizeof(virStoragePoolInfo));
if (virStoragePoolObjIsActive(obj))
info->state = VIR_STORAGE_POOL_RUNNING;
else
info->state = VIR_STORAGE_POOL_INACTIVE;
- info->capacity = obj->def->capacity;
- info->allocation = obj->def->allocation;
- info->available = obj->def->available;
+ info->capacity = def->capacity;
+ info->allocation = def->allocation;
+ info->available = def->available;
virStoragePoolObjUnlock(obj);
return 0;
@@ -4743,7 +4754,7 @@ testStoragePoolGetXMLDesc(virStoragePoolPtr pool,
if (!(obj = testStoragePoolObjFindByName(privconn, pool->name)))
return NULL;
- ret = virStoragePoolDefFormat(obj->def);
+ ret = virStoragePoolDefFormat(virStoragePoolObjGetDef(obj));
virStoragePoolObjUnlock(obj);
return ret;
@@ -4883,16 +4894,18 @@ testStorageVolLookupByName(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStorageVolDefPtr privvol;
virStorageVolPtr ret = NULL;
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
return NULL;
+ def = virStoragePoolObjGetDef(obj);
if (!(privvol = testStorageVolDefFindByName(obj, name)))
goto cleanup;
- ret = virGetStorageVol(pool->conn, obj->def->name,
+ ret = virGetStorageVol(pool->conn, def->name,
privvol->name, privvol->key,
NULL, NULL);
@@ -4908,6 +4921,7 @@ testStorageVolLookupByKey(virConnectPtr conn,
{
testDriverPtr privconn = conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
size_t i;
virStorageVolPtr ret = NULL;
@@ -4915,14 +4929,13 @@ testStorageVolLookupByKey(virConnectPtr conn,
for (i = 0; i < privconn->pools.count; i++) {
obj = privconn->pools.objs[i];
virStoragePoolObjLock(obj);
+ def = virStoragePoolObjGetDef(obj);
if (virStoragePoolObjIsActive(obj)) {
virStorageVolDefPtr privvol = virStorageVolDefFindByKey(obj, key);
if (privvol) {
- ret = virGetStorageVol(conn,
- obj->def->name,
- privvol->name,
- privvol->key,
+ ret = virGetStorageVol(conn, def->name,
+ privvol->name, privvol->key,
NULL, NULL);
virStoragePoolObjUnlock(obj);
break;
@@ -4946,6 +4959,7 @@ testStorageVolLookupByPath(virConnectPtr conn,
{
testDriverPtr privconn = conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
size_t i;
virStorageVolPtr ret = NULL;
@@ -4953,14 +4967,13 @@ testStorageVolLookupByPath(virConnectPtr conn,
for (i = 0; i < privconn->pools.count; i++) {
obj = privconn->pools.objs[i];
virStoragePoolObjLock(obj);
+ def = virStoragePoolObjGetDef(obj);
if (virStoragePoolObjIsActive(obj)) {
virStorageVolDefPtr privvol = virStorageVolDefFindByPath(obj, path);
if (privvol) {
- ret = virGetStorageVol(conn,
- obj->def->name,
- privvol->name,
- privvol->key,
+ ret = virGetStorageVol(conn, def->name,
+ privvol->name, privvol->key,
NULL, NULL);
virStoragePoolObjUnlock(obj);
break;
@@ -4985,6 +4998,7 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStorageVolDefPtr privvol = NULL;
virStorageVolPtr ret = NULL;
@@ -4992,8 +5006,9 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
return NULL;
+ def = virStoragePoolObjGetDef(obj);
- privvol = virStorageVolDefParseString(obj->def, xmldesc, 0);
+ privvol = virStorageVolDefParseString(def, xmldesc, 0);
if (privvol == NULL)
goto cleanup;
@@ -5004,8 +5019,8 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
}
/* Make sure enough space */
- if ((obj->def->allocation + privvol->target.allocation) >
- obj->def->capacity) {
+ if ((def->allocation + privvol->target.allocation) >
+ def->capacity) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not enough free space in pool for volume
'%s'"),
privvol->name);
@@ -5013,17 +5028,17 @@ testStorageVolCreateXML(virStoragePoolPtr pool,
}
if (virAsprintf(&privvol->target.path, "%s/%s",
- obj->def->target.path, privvol->name) < 0)
+ def->target.path, privvol->name) < 0)
goto cleanup;
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
virStoragePoolObjAddVol(obj, privvol) < 0)
goto cleanup;
- obj->def->allocation += privvol->target.allocation;
- obj->def->available = (obj->def->capacity - obj->def->allocation);
+ def->allocation += privvol->target.allocation;
+ def->available = (def->capacity - def->allocation);
- ret = virGetStorageVol(pool->conn, obj->def->name,
+ ret = virGetStorageVol(pool->conn, def->name,
privvol->name, privvol->key,
NULL, NULL);
privvol = NULL;
@@ -5043,6 +5058,7 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
{
testDriverPtr privconn = pool->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStorageVolDefPtr privvol = NULL, origvol = NULL;
virStorageVolPtr ret = NULL;
@@ -5050,8 +5066,9 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
if (!(obj = testStoragePoolObjFindActiveByName(privconn, pool->name)))
return NULL;
+ def = virStoragePoolObjGetDef(obj);
- privvol = virStorageVolDefParseString(obj->def, xmldesc, 0);
+ privvol = virStorageVolDefParseString(def, xmldesc, 0);
if (privvol == NULL)
goto cleanup;
@@ -5070,27 +5087,26 @@ testStorageVolCreateXMLFrom(virStoragePoolPtr pool,
}
/* Make sure enough space */
- if ((obj->def->allocation + privvol->target.allocation) >
- obj->def->capacity) {
+ if ((def->allocation + privvol->target.allocation) > def->capacity) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Not enough free space in pool for volume
'%s'"),
privvol->name);
goto cleanup;
}
- obj->def->available = (obj->def->capacity - obj->def->allocation);
+ def->available = (def->capacity - def->allocation);
if (virAsprintf(&privvol->target.path, "%s/%s",
- obj->def->target.path, privvol->name) < 0)
+ def->target.path, privvol->name) < 0)
goto cleanup;
if (VIR_STRDUP(privvol->key, privvol->target.path) < 0 ||
virStoragePoolObjAddVol(obj, privvol) < 0)
goto cleanup;
- obj->def->allocation += privvol->target.allocation;
- obj->def->available = (obj->def->capacity - obj->def->allocation);
+ def->allocation += privvol->target.allocation;
+ def->available = (def->capacity - def->allocation);
- ret = virGetStorageVol(pool->conn, obj->def->name,
+ ret = virGetStorageVol(pool->conn, def->name,
privvol->name, privvol->key,
NULL, NULL);
privvol = NULL;
@@ -5108,6 +5124,7 @@ testStorageVolDelete(virStorageVolPtr vol,
{
testDriverPtr privconn = vol->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStorageVolDefPtr privvol;
int ret = -1;
@@ -5115,12 +5132,13 @@ testStorageVolDelete(virStorageVolPtr vol,
if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
return -1;
+ def = virStoragePoolObjGetDef(obj);
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
goto cleanup;
- obj->def->allocation -= privvol->target.allocation;
- obj->def->available = (obj->def->capacity - obj->def->allocation);
+ def->allocation -= privvol->target.allocation;
+ def->available = (def->capacity - def->allocation);
virStoragePoolObjRemoveVol(obj, privvol);
@@ -5153,17 +5171,19 @@ testStorageVolGetInfo(virStorageVolPtr vol,
{
testDriverPtr privconn = vol->conn->privateData;
virStoragePoolObjPtr obj;
+ virStoragePoolDefPtr def;
virStorageVolDefPtr privvol;
int ret = -1;
if (!(obj = testStoragePoolObjFindActiveByName(privconn, vol->pool)))
return -1;
+ def = virStoragePoolObjGetDef(obj);
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
goto cleanup;
memset(info, 0, sizeof(*info));
- info->type = testStorageVolumeTypeForPool(obj->def->type);
+ info->type = testStorageVolumeTypeForPool(def->type);
info->capacity = privvol->target.capacity;
info->allocation = privvol->target.allocation;
ret = 0;
@@ -5191,7 +5211,7 @@ testStorageVolGetXMLDesc(virStorageVolPtr vol,
if (!(privvol = testStorageVolDefFindByName(obj, vol->name)))
goto cleanup;
- ret = virStorageVolDefFormat(obj->def, privvol);
+ ret = virStorageVolDefFormat(virStoragePoolObjGetDef(obj), privvol);
cleanup:
virStoragePoolObjUnlock(obj);
--
2.13.5