Bug 1241454

Summary: Underlying file was not removed when volume create/build fails
Product: Red Hat Enterprise Linux 7 Reporter: Yang Yang <yanyang>
Component: libvirtAssignee: Erik Skultety <eskultet>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2CC: dyuan, eskultet, mzhan, rbalakri, xuzhang, yisun
Target Milestone: rcKeywords: Regression
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: libvirt-1.2.17-2.el7 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-11-19 06:48:35 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Yang Yang 2015-07-09 09:20:25 UTC
Description of problem:
commit 4749d82a8bb92b908fe7f30038d8b1ea3390384d introduces a regression. When I tried to create a huge volume, the volume created failed as expect, but the underlying file was not removed. I think we should delete underlying file when buildret failed.

Version-Release number of selected component (if applicable):
libvirt-1.2.17-1.el7.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Make sure haha.img does not exist
# virsh vol-list default| grep haha.img
# ll /var/lib/libvirt/images/haha.img
ls: cannot access /var/lib/libvirt/images/haha.img: No such file or directory

2. create haha.img in default pool with huge size
# virsh vol-create-as default haha.img 100000G
error: Failed to create vol haha.img
error: cannot allocate 107374182400000 bytes in file '/var/lib/libvirt/images/haha.img': No space left on device

3. check if haha.img file exists
# virsh vol-list default| grep haha.img
# ll /var/lib/libvirt/images/haha.img
-rw-------. 1 root root 107374182400000 Jul  6 16:35 /var/lib/libvirt/images/haha.img

Actual results:


Expected results:
Underlying file should be removed when volume create/build fails

Additional info:

Comment 2 Erik Skultety 2015-07-09 12:48:56 UTC
Fixed upstream:

commit b5637871920c88d88a32343a13c6c1476062a6bb
Author: Erik Skultety <eskultet>
Date:   Thu Jul 9 11:17:12 2015 +0200

    storage: Revert volume obj list updating after volume creation (4749d82a)
    
    This patch reverts commit 4749d82a which tried to tweak the logic in
    volume creation. We did realloc and update our object list before we executed
    volume building within a specific storage backend. If that failed, we
    had to update (again) our object list to the original state as it was before the
    build and delete the volume from the pool (even though it didn't exist - this
    truly depends on the backend).
    I misunderstood the base idea to be able to poll the status of the volume
    creation using vol-info. After commit 4749d82a this wasn't possible
    anymore, although no BZ has been reported yet.
    
    Commit 4749d82a also claimed to fix
    https://bugzilla.redhat.com/show_bug.cgi?id=1223177, but commit c8be606b of the
    same series as 4749d82ad (which was more of a refactor than a fix)
    fixes the same issue so the revert should be pretty straightforward.
    Further more, BZ https://bugzilla.redhat.com/show_bug.cgi?id=1241454 can be
    fixed with this revert.

v1.2.17-58-gb563787

Comment 6 yisun 2015-07-14 05:48:27 UTC
Verified on:
libvirt-1.2.17-2.el7.x86_64
qemu-kvm-rhev-2.3.0-9.el7.x86_64
kernel-3.10.0-290.el7.x86_64


1. Prepared a pool
# virsh pool-dumpxml default
<pool type='dir'>
  <name>default</name>
  <uuid>3fb748f5-8b63-4aad-bd76-908b5434e4af</uuid>
  <capacity unit='bytes'>214643507200</capacity>
  <allocation unit='bytes'>30016999424</allocation>
  <available unit='bytes'>184626507776</available>
  <source>
  </source>
  <target>
    <path>/home/pool</path>
    <permissions>
      <mode>0755</mode>
      <owner>0</owner>
      <group>0</group>
      <label>unconfined_u:object_r:home_root_t:s0</label>
    </permissions>
  </target>
</pool>

2. create a volume with size exceeding disk left space
# virsh vol-create-as default big.img  10000G
error: Failed to create vol big.img
error: cannot allocate 10737418240000 bytes in file '/home/pool/big.img': No space left on device

3. check the pool's directory
# ll /home/pool/ -a
total 4
drwxr-xr-x. 2 root root    6 Jul 14 13:31 .
drwxr-xr-x. 6 root root 4096 Jul 13 18:14 ..
<==== vol file not created as expect.

[root@localhost ~]# virsh vol-list default
 Name                 Path                                   
------------------------------------------------------------------------------
<===== no vol listed as expect.

4. create a volume with reasonable size
# virsh vol-create-as default big.img  1G
Vol big.img created

5. check the vol-info works well against the volume
# virsh vol-info big.img --pool default
Name:           big.img
Type:           file
Capacity:       1.00 GiB
Allocation:     1.00 GiB

Comment 8 errata-xmlrpc 2015-11-19 06:48:35 UTC
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/RHBA-2015-2202.html