Bug 1056558

Summary: virt-sparsify overwrites block devices if used as output files
Product: Red Hat Enterprise Linux 6 Reporter: Richard W.M. Jones <rjones>
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, lkong, mbooth, ptoscano, rbalakri, wshi, yuliu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.20.11-4.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: 2014-10-14 06:35:04 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, 1122557    
Bug Blocks:    

Description Richard W.M. Jones 2014-01-22 13:11:43 UTC
+++ 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

Comment 1 Richard W.M. Jones 2014-01-22 13:12:35 UTC
Upstream fix is: 13bca32e4ec9213e69ea55e837dea846719fb67e
available in libguestfs >= 1.25.26 and >= 1.24.6.

Comment 2 Richard W.M. Jones 2014-01-22 13:21:17 UTC
A test of this is:

# Create an empty file to sparsify:
guestfish -N fs exit

# Create block & char device nodes in the filesystem:
mknod /tmp/block b 0 0
mknod /tmp/char c 0 0

You should have two dummy device nodes in /tmp:

$ ll /tmp/block /tmp/char
brw-r--r--. 1 root root 0, 0 Jan 22 13:16 /tmp/block
crw-r--r--. 1 root root 0, 0 Jan 22 13:16 /tmp/char

Run virt-sparsify like this:

virt-sparsify test1.img /tmp/block

and:

virt-sparsify test1.img /tmp/char

If these two commands run, and you see an error like:

qemu-img: /tmp/block: error while converting qcow2: No such device or address
virt-sparsify: error: external command failed: qemu-img convert -f 
qcow2 -O 'qcow2' '/tmp/sparsify011645.qcow2' '/tmp/block'

then that's bad (demonstrating the bug).

If the commands show a clean error like:

virt-sparsify: error: output '/tmp/block' cannot be a block device, it 
must be a regular file

then that's good (showing the bug is fixed).

Comment 4 bfan 2014-07-02 05:53:35 UTC
Verified with libguestfs-1.20.11-8.el6.x86_64

# guestfish -N fs exit
# mknod /tmp/block b 0 0
# mknod /tmp/char c 0 0
# ll /tmp/block /tmp/char
brw-r--r--. 1 root root 0, 0 Jul  2 13:42 /tmp/block
crw-r--r--. 1 root root 0, 0 Jul  2 13:42 /tmp/char

# virt-sparsify test1.img /tmp/block
virt-sparsify: error: output '/tmp/block' cannot be a block device, it 
must be a regular file

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

# virt-sparsify test1.img /tmp/char
virt-sparsify: error: output '/tmp/char' 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.


Got the clean error message

Comment 5 errata-xmlrpc 2014-10-14 06:35:04 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.

http://rhn.redhat.com/errata/RHBA-2014-1458.html