From: Michal Privoznik Date: Fri, 24 May 2019 14:35:42 +0000 (+0200) Subject: virStoragePoolObjListAdd: Turn boolean arg into flags X-Git-Tag: v5.7.0-rc1~109 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c04707058e9c7cc0ca1c1f23468df916caf6520;p=thirdparty%2Flibvirt.git virStoragePoolObjListAdd: Turn boolean arg into flags 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 Reviewed-by: Ján Tomko --- diff --git a/src/conf/virstorageobj.c b/src/conf/virstorageobj.c index cb9bac08f1..7c86ec529f 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 9738ee57e6..ef4a6bf408 100644 --- a/src/conf/virstorageobj.h +++ b/src/conf/virstorageobj.h @@ -194,10 +194,14 @@ virStoragePoolObjVolumeListExport(virConnectPtr conn, virStorageVolPtr **vols, virStoragePoolVolumeACLFilter filter); +typedef enum { + VIR_STORAGE_POOL_OBJ_LIST_ADD_CHECK_LIVE = (1 << 1), +} virStoragePoolObjListFlags; + 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 a62df0f091..f2ecabc70f 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -754,7 +754,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); @@ -829,7 +830,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 edd1e1ff40..9df7840390 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1140,7 +1140,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; } @@ -6436,7 +6436,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); @@ -6502,7 +6503,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);