Bug 1297424

Summary: Add warning about running qemu-img on active VMs to its manpage
Product: Red Hat Enterprise Linux 6 Reporter: Ademar Reis <areis>
Component: qemu-kvmAssignee: Kevin Wolf <kwolf>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: high Docs Contact: Jiri Herrmann <jherrman>
Priority: high    
Version: 6.7CC: ailan, chayang, ddu, fdelorey, jen, jherrman, juzhang, mkenneth, qizhu, rbalakri, virt-bugs, virt-maint, xfu
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Fixed In Version: qemu-kvm- Doc Type: Known Issue
Doc Text:
Using qemu-img to modify an image that is in use can corrupt the image Opening a QEMU disk image from multiple processes at the same time, for example by attempting to take a snapshot of a QEMU image while the guest is running, in some cases corrupts the image. To avoid this problem, never use the qemu-img utility to modify images in use by a running virtual machine or any other process. In addition, be aware that querying an image that is being modified by another process may trigger an inconsistent state error. This update also adds an admonition about the mentioned problem to the qemu-img(1) man page.
Story Points: ---
Clone Of: 1277167 Environment:
Last Closed: 2016-05-10 21:02:31 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:
Bug Depends On:    
Bug Blocks: 1277167    

Description Ademar Reis 2016-01-11 13:34:16 UTC
This should be a backport of 

commit 48467328c6dccc9c7be6628ed0ef0810f83be2a9
Author: Kevin Wolf <kwolf>
Date:   Thu Aug 16 10:56:35 2012 +0200

    Documentation: Warn against qemu-img on active image
    People have repeatedly expected that you can do things like snapshotting
    an image with qemu-img while a qemu instance is running. Maybe we need
    to consider locking the files while they are in use, but having a
    warning in the qemu-img manpage is doable for 1.2 and can't hurt anyway.
    Signed-off-by: Kevin Wolf <kwolf>

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

--- Additional comment from Ademar Reis on 2016-01-11 11:29:58 BRST ---

(In reply to Frank DeLorey from comment #0)
> Before this problem happened, customer took a snapshot when the vm was
> running:
> # /usr/bin/qemu-img snapshot -c snapshot-test-20151019
> /var/lib/libvirt/images/kpd-dbw.qcow2
> When trying to delete the snapshot, customer sees the same error message.
> # /usr/bin/qemu-img snapshot -l /var/lib/libvirt/images/kpd-dbw.qcow2
> Could not open '/var/lib/libvirt/images/kpd-dbw.qcow2': File too large
> # /usr/bin/qemu-img snapshot -d snapshot-test-20151029
> /var/lib/libvirt/images/kpd-dbw.qcow2
> Could not open '/var/lib/libvirt/images/kpd-dbw.qcow2': File too large

This will lead to image corruption for sure, so this is expected. One should never use qemu-img snapshot on a running VM. You can see a more complete explanation in the upstream bug you've mentioned (https://bugs.launchpad.net/qemu/+bug/1354167/comments/12):

"[...] it turned out that qemu-img snapshot was used on the image while the VM is running. This was likely the root cause of the corruption. So if you're reading this, it's probably already too late, but I want to spell it out anyway:

WARNING: Never open the same disk image from two processes at the same time, except if both are read-only! If your VM is running, use the qemu monitor of that VM (or libvirt functionality, which will do the same internally) to do operations on the image. Use qemu-img only for images of shut down VMs."

If the customer followed some of our documentation when doing it, then it should be fixed. There are recent and recurrent upstream discussions about adding some sort of locking to qemu and qemu-img, but there's no consensus, as this would add complexity and require cleanups in case of crashes.

You can see more details about a recent discussion here:

Anyway, we should at least backport to RHEL6 the warning which was added to qemu-img's manpage back in 2012. I'll open a new BZ to track that.

Comment 1 Jeff Nelson 2016-01-18 21:52:00 UTC
Fix included in qemu-kvm-

Comment 3 Qianqian Zhu 2016-01-27 08:45:52 UTC
Verified with:

Warning added to manpage in DESCRIPTION part.

# man qemu-img
QEMU-IMG(1)                                                        QEMU-IMG(1)

       qemu-img - QEMU disk image utility

       usage: qemu-img command [command options]

       qemu-img allows you to create, convert and modify images offline. It can handle all image formats supported by QEMU.

       Warning: Never use qemu-img to modify images in use by a running virtual machine or any other process; this may destroy the
       image. Also, be aware that querying an image that is being modified by another process may encounter inconsistent state.

Comment 6 errata-xmlrpc 2016-05-10 21:02:31 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.