Bug 1277122

Summary: RFE: virt-sparsify: make '--in-place' sparsification safe to abort (gracefully or ungracefully)
Product: Red Hat Enterprise Linux 7 Reporter: Yaniv Kaul <ykaul>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 7.3CC: leiwang, linl, ptoscano, sherold, xchen
Target Milestone: rcKeywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libguestfs-1.32.0-2.el7 Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2016-11-03 17:56:26 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: 1218766    
Bug Blocks: 1288337, 1301891    

Description Yaniv Kaul 2015-11-02 12:24:02 UTC
Description of problem:
I'd be happy if there will be a possibility to use virt-sparsify in '--in-place' mode (where sparsification is not happening on a copy of the disk, but in place) and if a user stops gracefully the process or the process gets killed abruptly, the disk is still safe from corruption.

TIA,
Y.

Comment 2 Richard W.M. Jones 2015-11-03 13:12:19 UTC
I posted a thread upstream about this:

https://lists.nongnu.org/archive/html/qemu-devel/2015-11/threads.html#00402

Paolo's reply hasn't appeared in that archive yet, but he agrees
with me that this should be safe.

However it would be nice for virt-sparsify to handle ^C
gracefully, so I'm going to try to implement that.

Comment 3 Richard W.M. Jones 2015-11-04 12:39:23 UTC
Patch posted:
https://www.redhat.com/archives/libguestfs/2015-November/thread.html#00032

Comment 4 Richard W.M. Jones 2015-11-04 17:47:14 UTC
This is upstream now:
https://github.com/libguestfs/libguestfs/commit/8e3920a334d8d2b3c0a2be8ca84f8f935c41b106

We'll pick this change up in the rebase (bug 1218766).

Comment 5 Richard W.M. Jones 2015-11-04 17:50:16 UTC
From an oVirt operational point of view, you just need to send
the virt-sparsify process either SIGINT or SIGQUIT (once).  It
will shut down gracefully (which may take some time), and then
exit with an error code.

If you send a second signal before virt-sparsify exits, then
virt-sparsify will exit immediately (and *un*gracefully), so I
don't recommend doing that.

Comment 7 Xianghua Chen 2016-07-28 11:54:33 UTC
Verified with packages:
libguestfs-1.32.6-1.el7.x86_64

Steps:
1. Prepare a RHEL7 guest image: RHEL-Server-7.2-64-hvm.raw
#  qemu-img  info RHEL-Server-7.2-64-hvm.raw
image: RHEL-Server-7.2-64-hvm.raw
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 8.0G
# virt-filesystems -a RHEL-Server-7.2-64-hvm.raw -l
Name                      Type       VFS Label Size       Parent
/dev/sda1                 filesystem xfs -     524288000  -
/dev/rhel_dhcp-10-28/root filesystem xfs -     7159676928 -

2. # virt-sparsify --in-place RHEL-Server-7.2-64-hvm.raw

3. #  qemu-img  info RHEL-Server-7.2-64-hvm.raw
image: RHEL-Server-7.2-64-hvm.raw
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 2.2G
# virt-filesystems -a RHEL-Server-7.2-64-hvm.raw -l
Name                      Type       VFS Label Size       Parent
/dev/sda1                 filesystem xfs -     524288000  -
/dev/rhel_dhcp-10-28/root filesystem xfs -     7159676928 -

4. Execute step 1-3 again, but use ctrl+c to stop it during the process in step 2.

All commands finished successfully, and the guest images is shrinked and can be boot normally after execute virt-sparsify.

Comment 9 errata-xmlrpc 2016-11-03 17:56:26 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/RHSA-2016-2576.html