[libvirt] [PATCH] storage: resize vol against real allocated size

Martin Kletzander mkletzan at redhat.com
Mon Dec 16 15:45:06 UTC 2013


On Mon, Dec 16, 2013 at 02:29:15PM +0100, Michal Privoznik wrote:
> From: Wang Sen <wangsen at linux.vnet.ibm.com>
>
> Currently, 'vol-resize --allocate' allocates new space at the
> vol->capacity offset. But the vol->capacity is not necessarily the same
> as vol->allocation. For instance:.
>
> 	[root at localhost ~]# virsh vol-list --pool tmp-pool --details
> 	 Name      Path                   Type  Capacity  Allocation
> 	-------------------------------------------------------------
> 	 tmp-vol  /root/tmp-pool/tmp-vol  file  1.00 GiB  1.00 GiB
>
> 	[root at localhost ~]# virsh vol-resize tmp-vol --pool tmp-pool 2G
>
> 	[root at localhost ~]# virsh vol-list --pool tmp-pool --details
> 	 Name      Path                   Type  Capacity  Allocation
> 	-------------------------------------------------------------
> 	 tmp-vol  /root/tmp-pool/tmp-vol  file  2.00 GiB  1.00 GiB
>
> So, if we want to allocate more bytes, so the file is say 3G big, the
> real allocated size is 2G actually:
>
> 	[root at localhost ~]# virsh vol-resize tmp-vol --pool tmp-pool 3G --allocate
>
> 	[root at localhost ~]# virsh vol-list --pool tmp-pool --details
> 	 Name      Path                   Type  Capacity  Allocation
> 	-------------------------------------------------------------
> 	 tmp-vol  /root/tmp-pool/tmp-vol  file  3.00 GiB  2.00 GiB
>
> This commit uses the correct vol->allocation instead of incorrect
> vol->capacity, so the output of the commands above looks like this:
>
> 	[root at localhost ~]# virsh vol-resize tmp-vol --pool tmp-pool 3G --allocate
>
> 	[root at localhost ~]# virsh vol-list --pool tmp-pool --details
> 	 Name      Path                   Type  Capacity  Allocation
> 	-------------------------------------------------------------
> 	 tmp-vol  /root/tmp-pool/tmp-vol  file  3.00 GiB  3.00 GiB
>
> Moreover, if the '--alocate' flag was used, we must update the

s/alocate/allocate/

> vol->allocation member in storageVolResize API too, not just
> vol->capacity.
>
> Reported-by: Wang Sen <wangsen at linux.vnet.ibm.com>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/storage/storage_backend_fs.c | 2 +-
>  src/storage/storage_driver.c     | 2 ++
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
> index 11cf2df..95783be 100644
> --- a/src/storage/storage_backend_fs.c
> +++ b/src/storage/storage_backend_fs.c
> @@ -1267,7 +1267,7 @@ virStorageBackendFileSystemVolResize(virConnectPtr conn ATTRIBUTE_UNUSED,
>
>      if (vol->target.format == VIR_STORAGE_FILE_RAW) {
>          return virStorageFileResize(vol->target.path, capacity,
> -                                    vol->capacity, pre_allocate);
> +                                    vol->allocation, pre_allocate);
>      } else {
>          if (pre_allocate) {
>              virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
> index f08255e..816efda 100644
> --- a/src/storage/storage_driver.c
> +++ b/src/storage/storage_driver.c
> @@ -2029,6 +2029,8 @@ storageVolResize(virStorageVolPtr obj,
>          goto out;
>
>      vol->capacity = abs_capacity;
> +    if (flags & VIR_STORAGE_VOL_RESIZE_ALLOCATE)
> +        vol->allocation = abs_capacity;
>
>      /* Update pool metadata */
>      pool->def->allocation += (abs_capacity - vol->capacity);
> --
> 1.8.5.1
>

ACK,

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20131216/379bdfdd/attachment-0001.sig>


More information about the libvir-list mailing list