There will be more boolean information that we want to pass to
this function. Instead of having them in separate arguments per
each one, use @flags.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/virstorageobj.c | 16 +++++++++++-----
src/conf/virstorageobj.h | 6 +++++-
src/storage/storage_driver.c | 5 +++--
src/test/test_driver.c | 7 ++++---
4 files changed, 23 insertions(+), 11 deletions(-)
diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c
index 7f25931d05..7515b5d107 100644
--- a/src/conf/virstorageobj.c
+++ b/src/conf/virstorageobj.c
@@ -1509,17 +1509,20 @@ virStoragePoolObjSourceFindDuplicate(virStoragePoolObjListPtr
pools,
* virStoragePoolObjListAdd:
* @pools: Storage Pool object list pointer
* @def: Storage pool definition to add or update
- * @check_active: If true, ensure that pool is not active
+ * @flags: bitwise-OR of VIR_STORAGE_POOL_OBJ_LIST_* flags
*
* Lookup the @def to see if it already exists in the @pools in order
* to either update or add if it does not exist.
*
+ * If VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE is set in @flags
+ * then this will fail if the pool exists and is active.
+ *
* Returns locked and reffed object pointer or NULL on error
*/
virStoragePoolObjPtr
virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def,
- bool check_active)
+ unsigned int flags)
{
virStoragePoolObjPtr obj = NULL;
char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -1530,7 +1533,9 @@ virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
if (virStoragePoolObjSourceFindDuplicate(pools, def) < 0)
goto error;
- rc = virStoragePoolObjIsDuplicate(pools, def, check_active, &obj);
+ rc = virStoragePoolObjIsDuplicate(pools, def,
+ !!(flags &
VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE),
+ &obj);
if (rc < 0)
goto error;
@@ -1590,7 +1595,7 @@ virStoragePoolObjLoad(virStoragePoolObjListPtr pools,
return NULL;
}
- if (!(obj = virStoragePoolObjListAdd(pools, def, false)))
+ if (!(obj = virStoragePoolObjListAdd(pools, def, 0)))
return NULL;
def = NULL;
@@ -1651,7 +1656,8 @@ virStoragePoolObjLoadState(virStoragePoolObjListPtr pools,
}
/* create the object */
- if (!(obj = virStoragePoolObjListAdd(pools, def, true)))
+ if (!(obj = virStoragePoolObjListAdd(pools, def,
+ VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
goto cleanup;
def = NULL;
diff --git a/src/conf/virstorageobj.h b/src/conf/virstorageobj.h
index 090dd6a7e6..fe62515b50 100644
--- a/src/conf/virstorageobj.h
+++ b/src/conf/virstorageobj.h
@@ -192,10 +192,14 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn,
virStorageVolPtr **vols,
virStoragePoolVolumeACLFilter filter);
+enum {
+ VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1),
+};
+
virStoragePoolObjPtr
virStoragePoolObjListAdd(virStoragePoolObjListPtr pools,
virStoragePoolDefPtr def,
- bool check_active);
+ unsigned int flags);
int
virStoragePoolObjSaveDef(virStorageDriverStatePtr driver,
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index b4a56e54bb..38b83a77b7 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -743,7 +743,8 @@ storagePoolCreateXML(virConnectPtr conn,
if ((backend = virStorageBackendForType(newDef->type)) == NULL)
goto cleanup;
- if (!(obj = virStoragePoolObjListAdd(driver->pools, newDef, true)))
+ if (!(obj = virStoragePoolObjListAdd(driver->pools, newDef,
+ VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
goto cleanup;
newDef = NULL;
def = virStoragePoolObjGetDef(obj);
@@ -818,7 +819,7 @@ storagePoolDefineXML(virConnectPtr conn,
if (virStorageBackendForType(newDef->type) == NULL)
goto cleanup;
- if (!(obj = virStoragePoolObjListAdd(driver->pools, newDef, false)))
+ if (!(obj = virStoragePoolObjListAdd(driver->pools, newDef, 0)))
goto cleanup;
newDef = virStoragePoolObjGetNewDef(obj);
def = virStoragePoolObjGetDef(obj);
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 832943c1fb..39f5557fe1 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -1095,7 +1095,7 @@ testParseStorage(testDriverPtr privconn,
if (!def)
return -1;
- if (!(obj = virStoragePoolObjListAdd(privconn->pools, def, false))) {
+ if (!(obj = virStoragePoolObjListAdd(privconn->pools, def, 0))) {
virStoragePoolDefFree(def);
return -1;
}
@@ -4581,7 +4581,8 @@ testStoragePoolCreateXML(virConnectPtr conn,
if (!(newDef = virStoragePoolDefParseString(xml)))
goto cleanup;
- if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef, true)))
+ if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef,
+ VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE)))
goto cleanup;
newDef = NULL;
def = virStoragePoolObjGetDef(obj);
@@ -4647,7 +4648,7 @@ testStoragePoolDefineXML(virConnectPtr conn,
newDef->allocation = defaultPoolAlloc;
newDef->available = defaultPoolCap - defaultPoolAlloc;
- if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef, false)))
+ if (!(obj = virStoragePoolObjListAdd(privconn->pools, newDef, 0)))
goto cleanup;
newDef = NULL;
def = virStoragePoolObjGetDef(obj);
--
2.21.0