mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
storage: Add flags to allow building pool during create processing
https://bugzilla.redhat.com/show_bug.cgi?id=830056 Add flags handling to the virStoragePoolCreate and virStoragePoolCreateXML API's which will allow the caller to provide the capability for the storage pool create API's to also perform a pool build during creation rather than requiring the additional buildPool step. This will allow transient pools to be defined, built, and started. The new flags are: * VIR_STORAGE_POOL_CREATE_WITH_BUILD Perform buildPool without any flags passed. * VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE Perform buildPool using VIR_STORAGE_POOL_BUILD_OVERWRITE flag. * VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE Perform buildPool using VIR_STORAGE_POOL_BUILD_NO_OVERWRITE flag. It is up to the backend to handle the processing of build flags. The overwrite and no-overwrite flags are mutually exclusive. NB: This patch is loosely based upon code originally authored by Osier Yang that were not reviewed and pushed, see: https://www.redhat.com/archives/libvir-list/2012-July/msg01328.html
This commit is contained in:
parent
22f9754f1b
commit
aeb1078ab5
@ -57,7 +57,6 @@ typedef enum {
|
|||||||
# endif
|
# endif
|
||||||
} virStoragePoolState;
|
} virStoragePoolState;
|
||||||
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
VIR_STORAGE_POOL_BUILD_NEW = 0, /* Regular build from scratch */
|
VIR_STORAGE_POOL_BUILD_NEW = 0, /* Regular build from scratch */
|
||||||
VIR_STORAGE_POOL_BUILD_REPAIR = (1 << 0), /* Repair / reinitialize */
|
VIR_STORAGE_POOL_BUILD_REPAIR = (1 << 0), /* Repair / reinitialize */
|
||||||
@ -71,6 +70,23 @@ typedef enum {
|
|||||||
VIR_STORAGE_POOL_DELETE_ZEROED = 1 << 0, /* Clear all data to zeros (slow) */
|
VIR_STORAGE_POOL_DELETE_ZEROED = 1 << 0, /* Clear all data to zeros (slow) */
|
||||||
} virStoragePoolDeleteFlags;
|
} virStoragePoolDeleteFlags;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
VIR_STORAGE_POOL_CREATE_NORMAL = 0,
|
||||||
|
|
||||||
|
/* Create the pool and perform pool build without any flags */
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD = 1 << 0,
|
||||||
|
|
||||||
|
/* Create the pool and perform pool build using the
|
||||||
|
* VIR_STORAGE_POOL_BUILD_OVERWRITE flag. This is mutually
|
||||||
|
* exclusive to VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE */
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE = 1 << 1,
|
||||||
|
|
||||||
|
/* Create the pool and perform pool build using the
|
||||||
|
* VIR_STORAGE_POOL_BUILD_NO_OVERWRITE flag. This is mutually
|
||||||
|
* exclusive to VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE */
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE = 1 << 2,
|
||||||
|
} virStoragePoolCreateFlags;
|
||||||
|
|
||||||
typedef struct _virStoragePoolInfo virStoragePoolInfo;
|
typedef struct _virStoragePoolInfo virStoragePoolInfo;
|
||||||
|
|
||||||
struct _virStoragePoolInfo {
|
struct _virStoragePoolInfo {
|
||||||
|
@ -505,7 +505,7 @@ virStoragePoolLookupByVolume(virStorageVolPtr vol)
|
|||||||
* virStoragePoolCreateXML:
|
* virStoragePoolCreateXML:
|
||||||
* @conn: pointer to hypervisor connection
|
* @conn: pointer to hypervisor connection
|
||||||
* @xmlDesc: XML description for new pool
|
* @xmlDesc: XML description for new pool
|
||||||
* @flags: extra flags; not used yet, so callers should always pass 0
|
* @flags: bitwise-OR of virStoragePoolCreateFlags
|
||||||
*
|
*
|
||||||
* Create a new storage based on its XML description. The
|
* Create a new storage based on its XML description. The
|
||||||
* pool is not persistent, so its definition will disappear
|
* pool is not persistent, so its definition will disappear
|
||||||
@ -670,7 +670,7 @@ virStoragePoolUndefine(virStoragePoolPtr pool)
|
|||||||
/**
|
/**
|
||||||
* virStoragePoolCreate:
|
* virStoragePoolCreate:
|
||||||
* @pool: pointer to storage pool
|
* @pool: pointer to storage pool
|
||||||
* @flags: extra flags; not used yet, so callers should always pass 0
|
* @flags: bitwise-OR of virStoragePoolCreateFlags
|
||||||
*
|
*
|
||||||
* Starts an inactive storage pool
|
* Starts an inactive storage pool
|
||||||
*
|
*
|
||||||
|
@ -671,8 +671,14 @@ storagePoolCreateXML(virConnectPtr conn,
|
|||||||
virStoragePoolPtr ret = NULL;
|
virStoragePoolPtr ret = NULL;
|
||||||
virStorageBackendPtr backend;
|
virStorageBackendPtr backend;
|
||||||
char *stateFile = NULL;
|
char *stateFile = NULL;
|
||||||
|
unsigned int build_flags = 0;
|
||||||
|
|
||||||
virCheckFlags(0, NULL);
|
virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE, NULL);
|
||||||
|
|
||||||
|
VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE,
|
||||||
|
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, NULL);
|
||||||
|
|
||||||
storageDriverLock();
|
storageDriverLock();
|
||||||
if (!(def = virStoragePoolDefParseString(xml)))
|
if (!(def = virStoragePoolDefParseString(xml)))
|
||||||
@ -694,6 +700,22 @@ storagePoolCreateXML(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
|
||||||
|
if (backend->buildPool) {
|
||||||
|
if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
|
||||||
|
build_flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
|
||||||
|
else if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
|
||||||
|
build_flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
|
||||||
|
|
||||||
|
if (build_flags ||
|
||||||
|
(flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) {
|
||||||
|
if (backend->buildPool(conn, pool, build_flags) < 0) {
|
||||||
|
virStoragePoolObjRemove(&driver->pools, pool);
|
||||||
|
pool = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (backend->startPool &&
|
if (backend->startPool &&
|
||||||
backend->startPool(conn, pool) < 0) {
|
backend->startPool(conn, pool) < 0) {
|
||||||
virStoragePoolObjRemove(&driver->pools, pool);
|
virStoragePoolObjRemove(&driver->pools, pool);
|
||||||
@ -845,8 +867,14 @@ storagePoolCreate(virStoragePoolPtr obj,
|
|||||||
virStorageBackendPtr backend;
|
virStorageBackendPtr backend;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *stateFile = NULL;
|
char *stateFile = NULL;
|
||||||
|
unsigned int build_flags = 0;
|
||||||
|
|
||||||
virCheckFlags(0, -1);
|
virCheckFlags(VIR_STORAGE_POOL_CREATE_WITH_BUILD |
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE |
|
||||||
|
VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE, -1);
|
||||||
|
|
||||||
|
VIR_EXCLUSIVE_FLAGS_RET(VIR_STORAGE_POOL_BUILD_OVERWRITE,
|
||||||
|
VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, -1);
|
||||||
|
|
||||||
if (!(pool = virStoragePoolObjFromStoragePool(obj)))
|
if (!(pool = virStoragePoolObjFromStoragePool(obj)))
|
||||||
return -1;
|
return -1;
|
||||||
@ -864,6 +892,22 @@ storagePoolCreate(virStoragePoolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (backend->buildPool) {
|
||||||
|
if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_OVERWRITE)
|
||||||
|
build_flags |= VIR_STORAGE_POOL_BUILD_OVERWRITE;
|
||||||
|
else if (flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD_NO_OVERWRITE)
|
||||||
|
build_flags |= VIR_STORAGE_POOL_BUILD_NO_OVERWRITE;
|
||||||
|
|
||||||
|
if (build_flags ||
|
||||||
|
(flags & VIR_STORAGE_POOL_CREATE_WITH_BUILD)) {
|
||||||
|
if (backend->buildPool(obj->conn, pool, build_flags) < 0) {
|
||||||
|
virStoragePoolObjRemove(&driver->pools, pool);
|
||||||
|
pool = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
VIR_INFO("Starting up storage pool '%s'", pool->def->name);
|
VIR_INFO("Starting up storage pool '%s'", pool->def->name);
|
||||||
if (backend->startPool &&
|
if (backend->startPool &&
|
||||||
backend->startPool(obj->conn, pool) < 0)
|
backend->startPool(obj->conn, pool) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user