mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-27 07:22:07 +03:00
storage: Don't update pool available/allocation if buildVol fails
https://bugzilla.redhat.com/show_bug.cgi?id=1024159 If adding a volume to a storage pool fails during the CreateXML or CreateXMLFrom API's, we don't want to adjust the available and allocation values for the storage pool during storageVolDelete since we haven't adjusted the values for the create. Refactor storageVolDelete() a bit to create a storageVolDeleteInternal() which will handle the primary deletion activities. Add a parameter updateMeta which will signify whether to update the values or not. Adjust the calls from CreateXML and CreateXMLFrom to directly call the DeleteInternal with the pool lock held. This does bypass the call to virStorageVolDeleteEnsureACL().
This commit is contained in:
parent
a18c713013
commit
0c2305b31c
@ -1552,6 +1552,52 @@ storageVolLookupByPath(virConnectPtr conn,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
storageVolDeleteInternal(virStorageVolPtr obj,
|
||||||
|
virStorageBackendPtr backend,
|
||||||
|
virStoragePoolObjPtr pool,
|
||||||
|
virStorageVolDefPtr vol,
|
||||||
|
unsigned int flags,
|
||||||
|
bool updateMeta)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!backend->deleteVol) {
|
||||||
|
virReportError(VIR_ERR_NO_SUPPORT,
|
||||||
|
"%s", _("storage pool does not support vol deletion"));
|
||||||
|
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
/* Update pool metadata - don't update meta data from error paths
|
||||||
|
* in this module since the allocation/available weren't adjusted yet
|
||||||
|
*/
|
||||||
|
if (updateMeta) {
|
||||||
|
pool->def->allocation -= vol->target.allocation;
|
||||||
|
pool->def->available += vol->target.allocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < pool->volumes.count; i++) {
|
||||||
|
if (pool->volumes.objs[i] == vol) {
|
||||||
|
VIR_INFO("Deleting volume '%s' from storage pool '%s'",
|
||||||
|
vol->name, pool->def->name);
|
||||||
|
virStorageVolDefFree(vol);
|
||||||
|
|
||||||
|
VIR_DELETE_ELEMENT(pool->volumes.objs, i, pool->volumes.count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
storageVolDelete(virStorageVolPtr obj,
|
storageVolDelete(virStorageVolPtr obj,
|
||||||
unsigned int flags)
|
unsigned int flags)
|
||||||
@ -1560,7 +1606,6 @@ storageVolDelete(virStorageVolPtr obj,
|
|||||||
virStoragePoolObjPtr pool;
|
virStoragePoolObjPtr pool;
|
||||||
virStorageBackendPtr backend;
|
virStorageBackendPtr backend;
|
||||||
virStorageVolDefPtr vol = NULL;
|
virStorageVolDefPtr vol = NULL;
|
||||||
size_t i;
|
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
storageDriverLock(driver);
|
storageDriverLock(driver);
|
||||||
@ -1602,30 +1647,9 @@ storageVolDelete(virStorageVolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!backend->deleteVol) {
|
if (storageVolDeleteInternal(obj, backend, pool, vol, flags, true) < 0)
|
||||||
virReportError(VIR_ERR_NO_SUPPORT,
|
|
||||||
"%s", _("storage pool does not support vol deletion"));
|
|
||||||
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Update pool metadata */
|
|
||||||
pool->def->allocation -= vol->target.allocation;
|
|
||||||
pool->def->available += vol->target.allocation;
|
|
||||||
|
|
||||||
for (i = 0; i < pool->volumes.count; i++) {
|
|
||||||
if (pool->volumes.objs[i] == vol) {
|
|
||||||
VIR_INFO("Deleting volume '%s' from storage pool '%s'",
|
|
||||||
vol->name, pool->def->name);
|
|
||||||
virStorageVolDefFree(vol);
|
|
||||||
|
|
||||||
VIR_DELETE_ELEMENT(pool->volumes.objs, i, pool->volumes.count);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -1738,9 +1762,9 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
|||||||
voldef = NULL;
|
voldef = NULL;
|
||||||
|
|
||||||
if (buildret < 0) {
|
if (buildret < 0) {
|
||||||
virStoragePoolObjUnlock(pool);
|
storageVolDeleteInternal(volobj, backend, pool, buildvoldef,
|
||||||
storageVolDelete(volobj, 0);
|
0, false);
|
||||||
pool = NULL;
|
buildvoldef = NULL;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1908,7 +1932,6 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
|
|||||||
origvol->building = 0;
|
origvol->building = 0;
|
||||||
newvol->building = 0;
|
newvol->building = 0;
|
||||||
allocation = newvol->target.allocation;
|
allocation = newvol->target.allocation;
|
||||||
newvol = NULL;
|
|
||||||
pool->asyncjobs--;
|
pool->asyncjobs--;
|
||||||
|
|
||||||
if (origpool) {
|
if (origpool) {
|
||||||
@ -1918,11 +1941,11 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (buildret < 0) {
|
if (buildret < 0) {
|
||||||
virStoragePoolObjUnlock(pool);
|
storageVolDeleteInternal(volobj, backend, pool, newvol, 0, false);
|
||||||
storageVolDelete(volobj, 0);
|
newvol = NULL;
|
||||||
pool = NULL;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
newvol = NULL;
|
||||||
|
|
||||||
/* Updating pool metadata */
|
/* Updating pool metadata */
|
||||||
pool->def->allocation += allocation;
|
pool->def->allocation += allocation;
|
||||||
|
Loading…
Reference in New Issue
Block a user