Bug 1056556

Summary: virt-sparsify overwrites block devices if used as output files
Product: Red Hat Enterprise Linux 7 Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED CURRENTRELEASE QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 7.0CC: acathrow, bfan, jherrman, leiwang, mbooth, ptoscano, wshi
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.22.6-19.el7 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-06-13 11:53:15 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, 1062533, 1062890, 1122557    
Bug Blocks:    

Description Richard W.M. Jones 2014-01-22 13:11:41 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:43 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:13 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 3 bfan 2014-02-06 02:43:33 UTC
Reproduced with libguestfs-1.22.6-18.el7.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 Feb  6 10:39 /tmp/block
crw-r--r--. 1 root root 0, 0 Feb  6 10:39 /tmp/char

# virt-sparsify test1.img /tmp/block
qemu-img version 1.5
Create overlay file to protect source disk ...
Examine source disk ...
Fill free space in /dev/sda1 with zero ...
Copy to destination and make sparse ...
qemu-img: /tmp/block: error while converting raw: Could not open device: No such device or address
virt-resize: error: external command failed: qemu-img convert -f qcow2 
-O 'raw' '/tmp/sparsify892f5e.qcow2' '/tmp/block'

If reporting bugs, run virt-resize with the '-d' option and include the 
complete output.

# virt-sparsify test1.img /tmp/char
qemu-img version 1.5
Create overlay file to protect source disk ...
Examine source disk ...
Fill free space in /dev/sda1 with zero ...
Copy to destination and make sparse ...
qemu-img: /tmp/char: error while converting raw: Could not open device: No such device or address
virt-resize: error: external command failed: qemu-img convert -f qcow2 
-O 'raw' '/tmp/sparsify6c2b0d.qcow2' '/tmp/char'

If reporting bugs, run virt-resize with the '-d' option and include the 
complete output.

Comment 5 bfan 2014-02-10 08:10:51 UTC
Verified with libguestfs-1.22.6-19.el7.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 Feb 10 16:08 /tmp/block
crw-r--r--. 1 root root 0, 0 Feb 10 16:08 /tmp/char
# virt-sparsify test1.img /tmp/block
virt-resize: error: output '/tmp/block' cannot be a block device, it 
must be a regular file

If reporting bugs, run virt-resize with the '-d' option and include the 
complete output.


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

If reporting bugs, run virt-resize with the '-d' option and include the 
complete output.

Comment 6 Ludek Smid 2014-06-13 11:53:15 UTC
This request was resolved in Red Hat Enterprise Linux 7.0.

Contact your manager or support representative in case you have further questions about the request.