}
+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
storageVolDelete(virStorageVolPtr obj,
unsigned int flags)
virStoragePoolObjPtr pool;
virStorageBackendPtr backend;
virStorageVolDefPtr vol = NULL;
- size_t i;
int ret = -1;
storageDriverLock(driver);
goto cleanup;
}
- 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)
+ if (storageVolDeleteInternal(obj, backend, pool, vol, flags, true) < 0)
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;
cleanup:
voldef = NULL;
if (buildret < 0) {
- virStoragePoolObjUnlock(pool);
- storageVolDelete(volobj, 0);
- pool = NULL;
+ storageVolDeleteInternal(volobj, backend, pool, buildvoldef,
+ 0, false);
+ buildvoldef = NULL;
goto cleanup;
}
origvol->building = 0;
newvol->building = 0;
allocation = newvol->target.allocation;
- newvol = NULL;
pool->asyncjobs--;
if (origpool) {
}
if (buildret < 0) {
- virStoragePoolObjUnlock(pool);
- storageVolDelete(volobj, 0);
- pool = NULL;
+ storageVolDeleteInternal(volobj, backend, pool, newvol, 0, false);
+ newvol = NULL;
goto cleanup;
}
+ newvol = NULL;
/* Updating pool metadata */
pool->def->allocation += allocation;