From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kevin Wolf Subject: Re: [RFC/PATCH] kvm tools, qcow: Add support for writing to zero refcount clusters Date: Mon, 25 Jul 2011 10:11:46 +0200 Message-ID: <4E2D2542.8040009@redhat.com> References: <1311536709-25976-1-git-send-email-penberg@kernel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, Asias He , Cyrill Gorcunov , Ingo Molnar , Prasad Joshi , Sasha Levin To: Pekka Enberg Return-path: Received: from mx1.redhat.com ([209.132.183.28]:13409 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750830Ab1GYII7 (ORCPT ); Mon, 25 Jul 2011 04:08:59 -0400 In-Reply-To: <1311536709-25976-1-git-send-email-penberg@kernel.org> Sender: kvm-owner@vger.kernel.org List-ID: Am 24.07.2011 21:45, schrieb Pekka Enberg: > This patch adds support for writing to zero refcount clusters. Refcount blocks > are cached in like L2 tables and flushed upon VIRTIO_BLK_T_FLUSH and when > evicted from the LRU cache. > > With this patch applied, 'qemu-img check' no longer complains about referenced > clusters with zero reference count after > > dd if=/dev/zero of=/mnt/tmp > > where '/mnt' is freshly generated QCOW2 image. > > Cc: Asias He > Cc: Cyrill Gorcunov > Cc: Ingo Molnar > Cc: Kevin Wolf > Cc: Prasad Joshi > Cc: Sasha Levin > Signed-off-by: Pekka Enberg Looks okay, except that in case of a crash you'll most likely corrupt the image because the order in which refcounts and mapping are written out is completely undefined. For a reliable implementation you need to make sure that for cluster allocation you first write out the refcount update, then fsync, then write out the mapping. Otherwise if the mapping is written out first and then a crash happens, you'll have clusters that are used, but marked free, so that in the next run a second cluster can be mapped to the same location. Kevin