[libvirt] [PATCH 0/2] Update pool allocation with new values on volume creation

https://bugzilla.redhat.com/show_bug.cgi?id=1163091 Ján Tomko (2): Update pool allocation with new values on volume creation Create a shallow copy for volume building only if supported src/storage/storage_driver.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) -- 2.4.6

Since commit e0139e3, we update the pool allocation with the user-provided allocation values. For qcow2, the allocation is ignored for volume building, but we still subtracted it from pool's allocation. This can result in interesting values if the user-provided allocation is large enough: Capacity: 104.71 GiB Allocation: 109.13 GiB Available: 16.00 EiB We already do a VolRefresh on volume creation. Also refresh the volume after creating and use the new value to update the pool. https://bugzilla.redhat.com/show_bug.cgi?id=1163091 --- src/storage/storage_driver.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 0494e5d..16d0b6c 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1878,8 +1878,8 @@ storageVolCreateXML(virStoragePoolPtr obj, * it updates the pool values. */ if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation += buildvoldef->target.allocation; - pool->def->available -= buildvoldef->target.allocation; + pool->def->allocation += voldef->target.allocation; + pool->def->available -= voldef->target.allocation; } VIR_INFO("Creating volume '%s' in storage pool '%s'", @@ -2057,25 +2057,27 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj, origpool = NULL; } - if (buildret < 0) { + if (buildret < 0 || + (backend->refreshVol && + backend->refreshVol(obj->conn, pool, newvol) < 0)) { storageVolDeleteInternal(volobj, backend, pool, newvol, 0, false); newvol = NULL; goto cleanup; } - newvol = NULL; /* Updating pool metadata ignoring the disk backend since * it updates the pool values */ if (pool->def->type != VIR_STORAGE_POOL_DISK) { - pool->def->allocation += shadowvol->target.allocation; - pool->def->available -= shadowvol->target.allocation; + pool->def->allocation += newvol->target.allocation; + pool->def->available -= newvol->target.allocation; } VIR_INFO("Creating volume '%s' in storage pool '%s'", volobj->name, pool->def->name); ret = volobj; volobj = NULL; + newvol = NULL; cleanup: virObjectUnref(volobj); -- 2.4.6

Since the previous commit, the shallow copy is only used inside the if (backend->buildVol) if. --- src/storage/storage_driver.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c index 16d0b6c..7aaa060 100644 --- a/src/storage/storage_driver.c +++ b/src/storage/storage_driver.c @@ -1766,7 +1766,6 @@ storageVolCreateXML(virStoragePoolPtr obj, virStorageBackendPtr backend; virStorageVolDefPtr voldef = NULL; virStorageVolPtr ret = NULL, volobj = NULL; - virStorageVolDefPtr buildvoldef = NULL; virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, NULL); @@ -1828,19 +1827,21 @@ storageVolCreateXML(virStoragePoolPtr obj, 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) { 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 */ pool->asyncjobs++; @@ -1891,7 +1892,6 @@ storageVolCreateXML(virStoragePoolPtr obj, cleanup: virObjectUnref(volobj); virStorageVolDefFree(voldef); - VIR_FREE(buildvoldef); if (pool) virStoragePoolObjUnlock(pool); return ret; -- 2.4.6

On 09/24/2015 11:15 AM, Ján Tomko wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1163091
Ján Tomko (2): Update pool allocation with new values on volume creation Create a shallow copy for volume building only if supported
src/storage/storage_driver.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
ACK series, John
participants (2)
-
John Ferlan
-
Ján Tomko