[libvirt] [PATCH] Storage: Fix allocation for raw files.

Prerna Saxena prerna at linux.vnet.ibm.com
Tue Sep 2 10:04:47 UTC 2014


When virsh vol-clone is attempted on a raw file where capacity > allocation,
the resulting cloned volume has a size that matches the virtual-size of
the parent; in place of matching its actual, disk size.
For example : Given this image:
[root at localhost]# qemu-img info /var/lib/libvirt/images/f20.raw
image: /var/lib/libvirt/images/f20.raw
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 617M

When this disk is copied using virsh vol-clone :
[root at localhost~] vol-clone --vol f20.raw --newname f20-copy.raw
--pool default
Vol f20-copy.raw cloned from f20.raw
[root at localhost~]

The characteristics of the cloned disk differ in "disk size".
Its allocated disk size is more than the allocated size of parent file;
which is an anomaly. It has picked up an allocated size matching
the parent's virtual size.

[root at localhost~] qemu-img info /var/lib/libvirt/images/f20-copy.raw
image: /var/lib/libvirt/images/f20-copy.raw
file format: raw
virtual size: 2.0G (2147483648 bytes)
disk size: 2.0G

This patch fixes the cloned disk to have same _allocated_size_ as
the parent file from which it was cloned.

Signed-off-by: Prerna Saxena <prerna at linux.vnet.ibm.com>
---
 src/storage/storage_driver.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 433d7b7..930b45a 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -1821,11 +1821,6 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
     if (newvol->target.capacity < origvol->target.capacity)
         newvol->target.capacity = origvol->target.capacity;
 
-    /* Make sure allocation is at least as large as the destination cap,
-     * to make absolutely sure we copy all possible contents */
-    if (newvol->target.allocation < origvol->target.capacity)
-        newvol->target.allocation = origvol->target.capacity;
-
     if (!backend->buildVolFrom) {
         virReportError(VIR_ERR_NO_SUPPORT,
                        "%s", _("storage pool does not support volume creation from an existing volume"));
-- 
1.9.3

-- 
Prerna Saxena

Linux Technology Centre,
IBM Systems and Technology Lab,
Bangalore, India




More information about the libvir-list mailing list