Bug 1079625

Summary: virt-sparsify fails if a btrfs filesystem contains readonly snapshots
Product: [Community] Virtualization Tools Reporter: Richard W.M. Jones <rjones>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED UPSTREAM QA Contact:
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: jbastian, mbooth, ptoscano, rbalakri
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: 1064041 Environment:
Last Closed: 2015-02-02 14:06:01 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:    
Bug Blocks: 1064041    

Description Richard W.M. Jones 2014-03-22 07:40:12 UTC
+++ This bug was initially created as a clone of Bug #1064041 +++

Description of problem:

(Reported by Jeff Bastien here:
https://bugzilla.redhat.com/show_bug.cgi?id=1064008#c20 )

# virt-sparsify opensuse.img --convert qcow2 opensuse.qcow2qemu-img version 1.5
Create overlay file to protect source disk ...
Examine source disk ...
◓ 25% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒═════════════════════════════════════════════════⟧ --:--
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Fill free space in /dev/sda5 with zero ...
Clearing Linux swap on /dev/sda6 ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Fill free space in /dev/sda7 with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
Fill free space in /dev/sda8 with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:--
Fill free space in btrfsvol:/dev/sda7/.snapshots with zero ...
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:--
Fill free space in btrfsvol:/dev/sda7/.snapshots/1/snapshot with zero ...
Fatal error: exception Guestfs.Error("zero_free_space: open: /sysroot//qvm8re6w.spf: Read-only file system")

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

libguestfs 1.22.6-20.el7

--- Additional comment from RHEL Product and Program Management on 2014-02-11 16:20:29 EST ---

Since this bug report was entered in bugzilla, the release flag has been
set to ? to ensure that it is properly evaluated for this release.

--- Additional comment from Richard W.M. Jones on 2014-02-11 16:27:57 EST ---

Reproducer:

---------------------------------------------------------------
guestfish -x -N fs:btrfs -m /dev/sda1 <<EOF
btrfs-subvolume-create /vol1

# libguestfs has no API for this yet:
debug sh "btrfs subvolume snapshot -r /sysroot/vol1 /sysroot/snapshot"

# This will fail with the same error as virt-sparsify:
-zero-free-space /snapshot
EOF

virt-sparsify test1.img test1-out.img
---------------------------------------------------------------

The virt-sparsify command at the end will fail with:

Input disk virtual size = 104857600 bytes (100.0M)
Create overlay file in /tmp to protect source disk ...
Examine source disk ...
Fill free space in /dev/sda1 with zero ...
Fill free space in btrfsvol:/dev/sda1/snapshot with zero ...
Fatal error: exception Guestfs.Error("zero_free_space: open: /sysroot//idpr6elo.o7z: Read-only file system")

--- Additional comment from Richard W.M. Jones on 2014-02-11 16:31:01 EST ---

Virt-sparsify should generally avoid read-only filesystems.
The same thing would happen if, for example, there was an ISO9660
filesystem contained in any partition and you tried to sparsify
the disk image.

--- Additional comment from RHEL Product and Program Management on 2014-03-22 02:03:45 EDT ---

This request was not resolved in time for the current release.
Red Hat invites you to ask your support representative to
propose this request, if still desired, for consideration in
the next release of Red Hat Enterprise Linux.

Comment 1 Pino Toscano 2015-02-02 14:06:01 UTC
Fixed upstream with
https://github.com/libguestfs/libguestfs/commit/864c2ee371f65388b18e737136663986cfc9eb08

Also,
https://github.com/libguestfs/libguestfs/commit/4bb3c44a286beb0dd8cdf337d64d8ce71e361dd6
makes virt-sparsify ignore read-only filesystems.

Both available in libguestfs >= 1.29.24.