Received: from eggs.gnu.org ([2001:4830:134:3::10]:56678) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlDJL-0002IN-9l for qemu-devel@nongnu.org; Thu, 23 Apr 2015 05:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YlDJF-0004Oc-7q for qemu-devel@nongnu.org; Thu, 23 Apr 2015 05:20:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57657) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YlDJE-0004OG-Ri for qemu-devel@nongnu.org; Thu, 23 Apr 2015 05:20:37 -0400 Date: Thu, 23 Apr 2015 10:20:31 +0100 From: Stefan Hajnoczi Message-ID: <20150423092031.GC8811@stefanha-thinkpad.redhat.com> References: <1426069701-1405-1-git-send-email-den@openvz.org> <1426069701-1405-9-git-send-email-den@openvz.org> <20150422130855.GI27617@stefanha-thinkpad.redhat.com> <55379F36.3060906@openvz.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="4ZLFUWh1odzi/v6L" Content-Disposition: inline In-Reply-To: <55379F36.3060906@openvz.org> Subject: Re: [Qemu-devel] [PATCH 08/27] block/parallels: _co_writev callback for Parallels format List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Denis V. Lunev" Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org --4ZLFUWh1odzi/v6L Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 22, 2015 at 04:16:38PM +0300, Denis V. Lunev wrote: > On 22/04/15 16:08, Stefan Hajnoczi wrote: > >On Wed, Mar 11, 2015 at 01:28:02PM +0300, Denis V. Lunev wrote: > >>+static int64_t allocate_cluster(BlockDriverState *bs, int64_t sector_num) > >>+{ > >>+ BDRVParallelsState *s = bs->opaque; > >>+ uint32_t idx, offset, tmp; > >>+ int64_t pos; > >>+ int ret; > >>+ > >>+ idx = sector_num / s->tracks; > >>+ offset = sector_num % s->tracks; > >>+ > >>+ if (idx >= s->catalog_size) { > >>+ return -EINVAL; > >>+ } > >>+ if (s->catalog_bitmap[idx] != 0) { > >>+ return (uint64_t)s->catalog_bitmap[idx] * s->off_multiplier + offset; > >>+ } > >>+ > >>+ pos = bdrv_getlength(bs->file) >> BDRV_SECTOR_BITS; > >>+ bdrv_truncate(bs->file, (pos + s->tracks) << BDRV_SECTOR_BITS); > >>+ s->catalog_bitmap[idx] = pos / s->off_multiplier; > >>+ > >>+ tmp = cpu_to_le32(s->catalog_bitmap[idx]); > >>+ > >>+ ret = bdrv_pwrite_sync(bs->file, > >>+ sizeof(ParallelsHeader) + idx * sizeof(tmp), &tmp, sizeof(tmp)); > >What is the purpose of the sync? > This is necessary to preserve image consistency on crash from > my point of view. There is no check consistency at the moment. > The sync will be removed later when proper crash detection > code will be added (patches 19, 20, 21) Let's look at possible orderings in case of failure: A. BAT update B. Data write This sync enforces A, B ordering. If we can see B, then A must also have happened thanks to the sync. But A, B ordering is too conservative. Imagine B, A ordering and the failure where we crash before A. It means we wrote the data but never linked it into the BAT. What happens in that case? We've leaked a cluster in the underlying image file but it doesn't corrupt the visible disk from the guest point-of-view. Because your implementation uses truncate to extend the file size before A, even the A, B failure case results in a leaked cluster. So the B, A case is not worse in any way. Why do other image formats sync cluster allocation updates? Because they support backing files and in that case an A, B ordering results in data corruption so they enforce B, A ordering (the opposite of what you're trying to do!). The reason why A, B ordering results in data corruption when backing files are in use is because the guest's write request might touch only a subset of the cluster (a couple of sectors out of the whole cluster). So the guest needs to copy the remaining sectors from the backing file. If there is a dangling BAT entry like in the A, B failure case, then the guest will see a zeroed cluster instead of the contents of the backing file. This is a data corruption, but only if a backing file is being used! So the sync is not necessary, both A, B and B, A ordering work for block/parallels.c. Stefan --4ZLFUWh1odzi/v6L Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVOLlfAAoJEJykq7OBq3PIUT4H/3T8kDi28rgI2fxPsZTQZjbp oLDfrSAZRBH23f+k7gqbf5i16BfJ6OoyFOv8mtoPh24KigzNPIRz+Pm0KTF48af0 SoXTXYOe2HOO5h60NMjtCrFlnWURLvjuY9+hE2+uDHtul0wD91+MX3aV1ib+oLMc J+SPevGKXvJ37Nvp0/jY8KV5lFP37NRQ8x4jlLT8LNsnbYMdqAq8c5Ta2DFu+8mC Ezu/burmNYn3LLGFf8/wjpZzXzTKI8Mk+gPz67GSTOfbfeCA9nca76zQ6KMphIaD kJE6V8O/Ot0Q+pk/ROrpyoXbJtM+hQWVkCxIfRXp+7UDnmrSe1SwXBlRMvCIzuk= =PDPM -----END PGP SIGNATURE----- --4ZLFUWh1odzi/v6L--