Bug 1122557

Summary: virt-sparsify overwrites block devices if used as output files
Product: Red Hat Enterprise Linux 6 Reporter: Federico Simoncelli <fsimonce>
Component: libguestfsAssignee: Pino Toscano <ptoscano>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.6CC: huzhan, jherrman, leiwang, mbooth, ptoscano, rbalakri, rjones, utkarshsins, wshi
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.20.11-13.el6 Doc Type: Bug Fix
Doc Text:
As a result of the fix for BZ#1056558, it was not possible to use a block device for output when using the virt-sparsify utility. This update re-enables block devices to be used as ouput in virt-sparsify.
Story Points: ---
Clone Of: 1056290 Environment:
Last Closed: 2015-07-22 05:55:25 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:
Bug Depends On: 1056290    
Bug Blocks: 1056556, 1056558    

Description Federico Simoncelli 2014-07-23 13:46:29 UTC
To implement virt-sparsify in oVirt we actually need the full support for block devices.

+++ This bug was initially created as a clone of Bug #1056290 +++

Description of problem:

(Reported by shawnjgoff on IRC)

If you do something like:

  virt-sparsify infile /dev/vg/lv

then virt-sparsify will overwrite /dev/vg/lv with a file, which
is not exactly as intended.

It should detect if the output is a block device and (probably)
reject the attempt, although there is a possible use case which
is writing a qcow2 file into an LV (as used by oVirt).

Version-Release number of selected component (if applicable):

virt-sparsify 1.20.11rhel=6,release=2.el6

--- Additional comment from Richard W.M. Jones on 2014-01-22 08:12:47 EST ---

Upstream fix is: 13bca32e4ec9213e69ea55e837dea846719fb67e
available in libguestfs >= 1.25.26 and >= 1.24.6.

Comment 2 Richard W.M. Jones 2014-07-23 14:09:30 UTC
Patch posted:

https://www.redhat.com/archives/libguestfs/2014-July/msg00073.html

Comment 3 Federico Simoncelli 2014-07-23 14:23:44 UTC
(In reply to Richard W.M. Jones from comment #2)
> Patch posted:
> 
> https://www.redhat.com/archives/libguestfs/2014-July/msg00073.html

Just for the record, we are not risking to hit bug 1056290 again? Thanks.

Comment 4 Richard W.M. Jones 2014-07-23 14:56:52 UTC
(In reply to Federico Simoncelli from comment #3)
> (In reply to Richard W.M. Jones from comment #2)
> > Patch posted:
> > 
> > https://www.redhat.com/archives/libguestfs/2014-July/msg00073.html
> 
> Just for the record, we are not risking to hit bug 1056290 again? Thanks.

It's a good question.  The code in virt-sparsify just runs:

  qemu-img convert overlay outdisk

The root cause of bug 1056290 was not in libguestfs, it was in
qemu-img, or more specifically in the block layer in qemu.

I have tested qemu-img convert in RHEL 6.5 against a loop device
and it correctly opens the block device.  It doesn't delete or
overwrite the device node.

I have also tested virt-sparsify against an LV on recent Fedora,
and that works.

So we may have just hit a transient bug in qemu-img.

Comment 6 Lingfei Kong 2014-08-28 10:55:57 UTC
Can reproduce with libguestfs-1.20.11-2.el6

Steps to reproduce:
#virt-sparsify rhel77.img  /dev/VolGroup/test 
qemu-img version 0.9
Create overlay file to protect source disk ...
Examine source disk ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:--
Fill free space in /dev/rhel/root with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Clearing Linux swap on /dev/rhel/swap ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Fill free space in /dev/sda1 with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Copy to destination and make sparse ...
......

Comment 8 Hu Zhang 2015-03-11 07:04:26 UTC
Verified with the package version:
libguestfs-1.20.11-14.el6.x86_64

Verify steps:
1. # virt-sparsify RHEL-Server-7.1-64-hvm-2.raw /dev/vg_ibmx3650m303/test
qemu-img version 0.9
Input disk virtual size = 10486808576 bytes (9.8G)
Create overlay file in /tmp to protect source disk ...
Examine source disk ...
Fill free space in /dev/rhel/root with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Clearing Linux swap on /dev/rhel/swap ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Fill free space in /dev/sda1 with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Fill free space in volgroup rhel with zero ...
Copy to destination and make sparse ...

Sparsify operation completed with no errors.  Before deleting the old 
disk, carefully check that the target disk boots and works correctly.
--------end--------

2. # virt-sparsify RHEL-Server-7.1-64-hvm-2.raw /dev/input/mouse0
virt-sparsify: error: output '/dev/vcs' cannot be a character device, 
it must be a regular file

virt-sparsify: If reporting bugs, run virt-sparsify with debugging 
enabled (-v) and include the complete output.
--------end--------

So the output can be a block device, but not a char device. Verified.

Comment 10 errata-xmlrpc 2015-07-22 05:55:25 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-1444.html