mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
storage: Update pool metadata after adding/removing/resizing volume
One has to refresh the pool to get the correct pool info after adding/removing/resizing a volume, this updates the pool metadata (allocation, available) after those operation are done.
This commit is contained in:
parent
e7c7e32200
commit
e0139e3044
@ -1507,6 +1507,7 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
|||||||
virStorageBackendPtr backend;
|
virStorageBackendPtr backend;
|
||||||
virStorageVolDefPtr voldef = NULL;
|
virStorageVolDefPtr voldef = NULL;
|
||||||
virStorageVolPtr ret = NULL, volobj = NULL;
|
virStorageVolPtr ret = NULL, volobj = NULL;
|
||||||
|
virStorageVolDefPtr buildvoldef = NULL;
|
||||||
|
|
||||||
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
|
virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL);
|
||||||
|
|
||||||
@ -1565,20 +1566,19 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (VIR_ALLOC(buildvoldef) < 0) {
|
||||||
|
voldef = NULL;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Make a shallow copy of the 'defined' volume definition, since the
|
||||||
|
* original allocation value will change as the user polls 'info',
|
||||||
|
* but we only need the initial requested values
|
||||||
|
*/
|
||||||
|
memcpy(buildvoldef, voldef, sizeof(*voldef));
|
||||||
|
|
||||||
if (backend->buildVol) {
|
if (backend->buildVol) {
|
||||||
int buildret;
|
int buildret;
|
||||||
virStorageVolDefPtr buildvoldef = NULL;
|
|
||||||
|
|
||||||
if (VIR_ALLOC(buildvoldef) < 0) {
|
|
||||||
voldef = NULL;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Make a shallow copy of the 'defined' volume definition, since the
|
|
||||||
* original allocation value will change as the user polls 'info',
|
|
||||||
* but we only need the initial requested values
|
|
||||||
*/
|
|
||||||
memcpy(buildvoldef, voldef, sizeof(*voldef));
|
|
||||||
|
|
||||||
/* Drop the pool lock during volume allocation */
|
/* Drop the pool lock during volume allocation */
|
||||||
pool->asyncjobs++;
|
pool->asyncjobs++;
|
||||||
@ -1595,7 +1595,6 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
|||||||
pool->asyncjobs--;
|
pool->asyncjobs--;
|
||||||
|
|
||||||
voldef = NULL;
|
voldef = NULL;
|
||||||
VIR_FREE(buildvoldef);
|
|
||||||
|
|
||||||
if (buildret < 0) {
|
if (buildret < 0) {
|
||||||
virStoragePoolObjUnlock(pool);
|
virStoragePoolObjUnlock(pool);
|
||||||
@ -1606,6 +1605,10 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Update pool metadata */
|
||||||
|
pool->def->allocation += buildvoldef->allocation;
|
||||||
|
pool->def->available -= buildvoldef->allocation;
|
||||||
|
|
||||||
VIR_INFO("Creating volume '%s' in storage pool '%s'",
|
VIR_INFO("Creating volume '%s' in storage pool '%s'",
|
||||||
volobj->name, pool->def->name);
|
volobj->name, pool->def->name);
|
||||||
ret = volobj;
|
ret = volobj;
|
||||||
@ -1615,6 +1618,7 @@ storageVolCreateXML(virStoragePoolPtr obj,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virObjectUnref(volobj);
|
virObjectUnref(volobj);
|
||||||
virStorageVolDefFree(voldef);
|
virStorageVolDefFree(voldef);
|
||||||
|
virStorageVolDefFree(buildvoldef);
|
||||||
if (pool)
|
if (pool)
|
||||||
virStoragePoolObjUnlock(pool);
|
virStoragePoolObjUnlock(pool);
|
||||||
return ret;
|
return ret;
|
||||||
@ -1770,6 +1774,10 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Updating pool metadata */
|
||||||
|
pool->def->allocation += newvol->allocation;
|
||||||
|
pool->def->available -= newvol->allocation;
|
||||||
|
|
||||||
VIR_INFO("Creating volume '%s' in storage pool '%s'",
|
VIR_INFO("Creating volume '%s' in storage pool '%s'",
|
||||||
volobj->name, pool->def->name);
|
volobj->name, pool->def->name);
|
||||||
ret = volobj;
|
ret = volobj;
|
||||||
@ -2013,6 +2021,11 @@ storageVolResize(virStorageVolPtr obj,
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
vol->capacity = abs_capacity;
|
vol->capacity = abs_capacity;
|
||||||
|
|
||||||
|
/* Update pool metadata */
|
||||||
|
pool->def->allocation += (abs_capacity - vol->capacity);
|
||||||
|
pool->def->available -= (abs_capacity - vol->capacity);
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
@ -2356,6 +2369,10 @@ storageVolDelete(virStorageVolPtr obj,
|
|||||||
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
|
if (backend->deleteVol(obj->conn, pool, vol, flags) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
/* Update pool metadata */
|
||||||
|
pool->def->allocation -= vol->allocation;
|
||||||
|
pool->def->available += vol->allocation;
|
||||||
|
|
||||||
for (i = 0; i < pool->volumes.count; i++) {
|
for (i = 0; i < pool->volumes.count; i++) {
|
||||||
if (pool->volumes.objs[i] == vol) {
|
if (pool->volumes.objs[i] == vol) {
|
||||||
VIR_INFO("Deleting volume '%s' from storage pool '%s'",
|
VIR_INFO("Deleting volume '%s' from storage pool '%s'",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user