From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGqB6-0006i1-Fz for qemu-devel@nongnu.org; Wed, 06 Jan 2016 10:39:13 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aGqB1-00044c-GB for qemu-devel@nongnu.org; Wed, 06 Jan 2016 10:39:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36901) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aGqB1-00044Y-8y for qemu-devel@nongnu.org; Wed, 06 Jan 2016 10:39:07 -0500 References: <568AAFC4.6060009@redhat.com> From: Max Reitz Message-ID: <568D3517.7030401@redhat.com> Date: Wed, 6 Jan 2016 16:39:03 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="rN1NcDSfnM9k0nNGDjhAPkgOT5C1aXWSx" Subject: Re: [Qemu-devel] could i using qemu-img covert && rebase -u to do qcow2 rollback? List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Huan Zhang Cc: "qemu-devel@nongnu.org" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --rN1NcDSfnM9k0nNGDjhAPkgOT5C1aXWSx Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 05.01.2016 04:52, Huan Zhang wrote: > Hi Max, > "rollback" means revert user data to snap1 state, and for some reason, > we want to > keep snap2 and 'rollbacked' qocw2 file in a single backing file chain.= > After rollback, looks like: > snap0.qcow2 -> snap1.qcow2 ->snap2.qcow2 -> rollbacked-snap1.qcow2 > =20 > In my immature opinion, > 'qemu-img convert -O qcow2 snap1.qcow2 rollback.qcow2' get snap1 sate d= ata, > 'qemu-img rebase -u -b snap2.qcow2 rollback.qcow2' just changes > rollback.qcow2 backing file to snap2.qcow2, > will NOT change the data from user perspective(data reading from backin= g > file (snap2.qcow2 e.g.) which not in rollback.qcow2 is meaningless to u= ser]. > Is that right? OK. The problem with this is that qemu-img convert will not write unallocated clusters. For instance, assume we have the following configuration: # An empty snap0.qcow2 $ qemu-img create -f qcow2 snap0.qcow2 64M # snap1.qcow2 contains some 64k data block at offset 0 $ qemu-img create -f qcow2 -b snap0.qcow2 -F qcow2 snap1.qcow2 $ qemu-io -c 'write -P 1 0 64k' snap1.qcow2 # snap2.qcow2 contains some other 64k data block at offset 64k $ qemu-img create -f qcow2 -b snap1.qcow2 -F qcow2 snap2.qcow2 $ qemu-io -c 'write -P 2 64k 64k' snap2.qcow2 # Now you want to rollback to snap1 $ qemu-img convert -O qcow2 snap1.qcow2 rollback.qcow2 $ qemu-img rebase -u -b snap2.qcow2 rollback.qcow2 # Now let's compare snap1.qcow2 and rollback.qcow2 $ qemu-img compare snap1.qcow2 rollback.qcow2 Content mismatch at offset 65536! So what went wrong? qemu-img convert does not write unallocated sectors to the output; therefore, the block starting from offset 64k is unallocated in rollback.qcow2 (just as it is in snap1.qcow2), however, in rollback.qcow2, this will not return 0, but whatever is in snap2.qcow2 (which snap1.qcow2 does not have as a backing file). Therefore, when read from snap1.qcow2, that range is 0; but from rollback.qcow2, it returns 2s (what we wrote to snap2.qcow2). How to fix it? Drop the -u for rebase. However, qemu-img will not let us do this because without -u it wants the image to have a backing file already. So let's make rollback.qcow2's backing file snap0.qcow2 (the backing file snap1.qcow2 has): $ qemu-img convert -O qcow2 \ -o backing_file=3Dsnap0.qcow2,backing_fmt=3Dqcow2 \ snap1.qcow2 rollback.qcow2 (So in the general case, the backing_file option should be set to whatever backing file snap1.qcow2 has.) Alternatively, since you will actually be doing a rebase after this, you can also simply do: $ cp snap1.qcow2 rollback.qcow2 Whatever you choose (the second may actually be the better choice), the rebase can be done using: $ qemu-img rebase -b snap2.qcow2 -F qcow2 rollback.qcow2 Now let's check: $ qemu-img compare snap1.qcow2 rollback.qcow2 Images are identical. That looks better! So, conclusion, the following will probably generally do: $ cp snap1.qcow2 rollback.qcow2 $ qemu-img rebase -b snap2.qcow2 -F qcow2 rollback.qcow2 Where snap1.qcow2 is the state you want to roll back to, and snap2.qcow2 is the last image you want to be in the backing chain under rollback.qcow= 2. Hope that helps (and that I'm actually correct), Max --rN1NcDSfnM9k0nNGDjhAPkgOT5C1aXWSx Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQEcBAEBCAAGBQJWjTUXAAoJEDuxQgLoOKytT9MH/AgAe4k0xhUu9kXVQ5PIqNVD ELrZS2tiZdHUX0dND2+znLfLb4A+NCafDU/Unh71h2a29jW6N6+9wLXkDpW/XQem B+reIfiPg352ezo7eF5M/mK/yC67xZoXJQsUnVa2mB6mbJwFAAvB/lLpMLNm1FNA UBDuPT8ss2x9FR6Z7AzEMmG+fjtDAuZy0VqOj7Eujnr5a/pPBIxOqVGscRJZBPTw D7K2YhHl2tW1k1pIZiKNV/4ywGjkThm+0No1hwPBTJ2bNgyWcUjrhdJTO3bg8gTL cZ2XDi9NogPrKyPsOO0eVJE6pUy19LdnMCptPiIs2nf3l7yx3bmo76k65WSUXGQ= =sN71 -----END PGP SIGNATURE----- --rN1NcDSfnM9k0nNGDjhAPkgOT5C1aXWSx--