Bug 1298065 - The size of raw image is incorect after clone without --nonsparse
The size of raw image is incorect after clone without --nonsparse
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: libvirt (Show other bugs)
7.3
x86_64 Unspecified
medium Severity medium
: rc
: ---
Assigned To: Ján Tomko
Virtualization Bugs
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2016-01-13 01:25 EST by xiaodwan
Modified: 2016-11-03 14:36 EDT (History)
7 users (show)

See Also:
Fixed In Version: libvirt-1.3.1-1.el7
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2016-11-03 14:36:10 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description xiaodwan 2016-01-13 01:25:59 EST
Description of problem:
The size of raw image is incorect after clone without --nonsparse

Version-Release number of selected component (if applicable):
# rpm -q libvirt virt-install
libvirt-1.2.17-13.el7.x86_64
virt-install-1.2.1-8.el7.noarch

How reproducible:
100%

Steps to Reproduce:
Prepare a guest with raw image and clone it with sparse.

# qemu-img info demo.img 
image: demo.img
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 2.4G

# virt-clone -o demo -f /var/lib/libvirt/images/demo-clone -n demo-clone
Allocating 'demo-clone'                                                                                                                               | 5.0 GB  00:00:40     

Clone 'demo-clone' created successfully.
# ll
-rw-------.  1 root root  5368709120 Jan 13 14:10 demo-clone
-rw-------.  1 root root  5368709120 Dec 11 17:13 demo.img

# qemu-img info demo-clone
image: demo-clone
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 5.0G

Actual results:
The size of the image is incorrect.

Expected results:
The size of the image should not be 5G and should be sparse.

Additional info:
These is a bug on upstream (https://bugzilla.redhat.com/show_bug.cgi?id=1130739), This bug is reported for tracking the problem on downstream.
Comment 2 Ján Tomko 2016-01-22 03:34:49 EST
Fixed upstream by:
commit dd519a294b22646b8dab26627707a525556df4d4
Author:     Prerna Saxena <prerna@linux.vnet.ibm.com>
CommitDate: 2015-07-10 08:54:10 +0200

    Fix cloning of raw, sparse volumes
    
    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.
    This patch fixes the cloned disk to have same _allocated_size_ as
    the parent file from which it was cloned.
    
    Ref: http://www.redhat.com/archives/libvir-list/2015-May/msg00050.html
    
    Also fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1130739
    
    Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
    Signed-off-by: Ján Tomko <jtomko@redhat.com>

git describe: v1.2.17-74-gdd519a2 contains: v1.2.18-rc1~100
Comment 4 yisun 2016-02-23 05:05:53 EST
Verified and PASSED

versions:
qemu-kvm-rhev-2.3.0-31.el7_2.7.x86_64
libvirt-1.3.1-1.el7.x86_64
virt-install-1.2.1-8.el7.noarch


prepare disks
In host:
# qemu-img create -f qcow2 /var/lib/libvirt/images/qcow2  10G
# qemu-img create -f raw /var/lib/libvirt/images/raw  5G

# virsh dumpxml vm1 | grep var -a2
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/rhel7.qcow2'/>
      <target dev='hda' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
--
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='/var/lib/libvirt/images/qcow2'/>
      <target dev='hdb' bus='ide'/>
      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
--
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/raw'/>
      <target dev='hdc' bus='ide'/>
      <address type='drive' controller='0' bus='1' target='0' unit='0'/>

In guest:
#mkfs.xfs /dev/sdb; mkfs.xfs /dev/sdc
#mkdir /raw; mkdir /qcow2
#mount /dev/sdb /qcow2; mount /dev/sdc/raw
#dd if=/dev/urandom of=/raw/bigfile count=1000 bs=1M
#dd if=/dev/urandom of=/qcow2/bigfile count=2000 bs=1M

steps:
1. check original images' info 
# qemu-img info /var/lib/libvirt/images/qcow2 
image: /var/lib/libvirt/images/qcow2
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 2.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

# qemu-img info /var/lib/libvirt/images/raw 
image: /var/lib/libvirt/images/raw
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 1.0G

2. use virt-clone to do the clone and check the new images' info
# virt-clone -o vm1 -f /var/lib/libvirt/images/rhel7-clone -f /tmp/qcow2-clone  -f /tmp/raw-clone -n JustATest

# qemu-img info /tmp/qcow2-clone 
image: /tmp/qcow2-clone
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 2.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: true
    refcount bits: 16
    corrupt: false

# qemu-img info /tmp/raw-clone 
image: /tmp/raw-clone
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 1.0G

3. use virsh vol-clone to do the clone and check the new images' info
# virsh vol-clone --pool default --vol qcow2 qcow2-clone
Vol qcow2-clone cloned from qcow2

# virsh vol-clone --pool default --vol raw raw-clone
Vol raw-clone cloned from raw

# qemu-img info /var/lib/libvirt/images/qcow2-clone 
image: /var/lib/libvirt/images/qcow2-clone
file format: qcow2
virtual size: 10G (10737418240 bytes)
disk size: 2.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

# qemu-img info /var/lib/libvirt/images/raw-clone 
image: /var/lib/libvirt/images/raw-clone
file format: raw
virtual size: 5.0G (5368709120 bytes)
disk size: 1.0G
Comment 6 errata-xmlrpc 2016-11-03 14:36:10 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHSA-2016-2577.html

Note You need to log in before you can comment on or make changes to this bug.