Move part, which deletes existing volume, to a new function parallelsStorageVolumeDefRemove so that we can use it later in parallels_driver.c Signed-off-by: Dmitry Guryanov <dguryanov@xxxxxxxxxxxxx> --- src/parallels/parallels_storage.c | 83 +++++++++++++++++++++--------------- src/parallels/parallels_utils.h | 2 + 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c index 1448a74..ad15687 100644 --- a/src/parallels/parallels_storage.c +++ b/src/parallels/parallels_storage.c @@ -1443,48 +1443,17 @@ cleanup: return ret; } -static int -parallelsStorageVolumeDelete(virStorageVolPtr vol, unsigned int flags) +int parallelsStorageVolumeDefRemove(virStoragePoolObjPtr privpool, + virStorageVolDefPtr privvol) { - parallelsConnPtr privconn = vol->conn->privateData; - virStoragePoolObjPtr privpool; - virStorageVolDefPtr privvol; - size_t i; int ret = -1; char *xml_path = NULL; - virCheckFlags(0, -1); - - parallelsDriverLock(privconn); - privpool = virStoragePoolObjFindByName(&privconn->pools, vol->pool); - parallelsDriverUnlock(privconn); - - if (privpool == NULL) { - parallelsPoolNotFoundError(vol->pool); - goto cleanup; - } - - - privvol = virStorageVolDefFindByName(privpool, vol->name); - - if (privvol == NULL) { - virReportError(VIR_ERR_NO_STORAGE_VOL, - _("no storage vol with matching name '%s'"), vol->name); - goto cleanup; - } - - if (!virStoragePoolObjIsActive(privpool)) { - virReportError(VIR_ERR_OPERATION_INVALID, - _("storage pool '%s' is not active"), vol->pool); - goto cleanup; - } - - privpool->def->allocation -= privvol->allocation; privpool->def->available = (privpool->def->capacity - privpool->def->allocation); - for (i = 0; i < privpool->volumes.count; i++) { + for (size_t i = 0; i < privpool->volumes.count; i++) { if (privpool->volumes.objs[i] == privvol) { xml_path = parallelsAddFileExt(privvol->target.path, ".xml"); if (!xml_path) @@ -1513,12 +1482,56 @@ parallelsStorageVolumeDelete(virStorageVolPtr vol, unsigned int flags) break; } } + + ret = 0; +cleanup: + VIR_FREE(xml_path); + return ret; +} + +static int +parallelsStorageVolumeDelete(virStorageVolPtr vol, unsigned int flags) +{ + parallelsConnPtr privconn = vol->conn->privateData; + virStoragePoolObjPtr privpool; + virStorageVolDefPtr privvol; + int ret = -1; + + virCheckFlags(0, -1); + + parallelsDriverLock(privconn); + privpool = virStoragePoolObjFindByName(&privconn->pools, vol->pool); + parallelsDriverUnlock(privconn); + + if (privpool == NULL) { + parallelsPoolNotFoundError(vol->pool); + goto cleanup; + } + + + privvol = virStorageVolDefFindByName(privpool, vol->name); + + if (privvol == NULL) { + virReportError(VIR_ERR_NO_STORAGE_VOL, + _("no storage vol with matching name '%s'"), vol->name); + goto cleanup; + } + + if (!virStoragePoolObjIsActive(privpool)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("storage pool '%s' is not active"), vol->pool); + goto cleanup; + } + + + if (parallelsStorageVolumeDefRemove(privpool, privvol)) + goto cleanup; + ret = 0; cleanup: if (privpool) virStoragePoolObjUnlock(privpool); - VIR_FREE(xml_path); return ret; } diff --git a/src/parallels/parallels_utils.h b/src/parallels/parallels_utils.h index fb759cf..e4b3f8b 100644 --- a/src/parallels/parallels_utils.h +++ b/src/parallels/parallels_utils.h @@ -62,5 +62,7 @@ void parallelsDriverLock(parallelsConnPtr driver); void parallelsDriverUnlock(parallelsConnPtr driver); virStorageVolPtr parallelsStorageVolumeLookupByPathLocked(virConnectPtr conn, const char *path); +int parallelsStorageVolumeDefRemove(virStoragePoolObjPtr privpool, + virStorageVolDefPtr privvol); #endif -- 1.7.7.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list