Received: from eggs.gnu.org ([208.118.235.92]:53642) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqR1T-0003nt-Gy for qemu-devel@nongnu.org; Wed, 02 Jan 2013 11:18:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TqR1G-0006Hs-8b for qemu-devel@nongnu.org; Wed, 02 Jan 2013 11:18:31 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:56261 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqR1G-0006Hm-0E for qemu-devel@nongnu.org; Wed, 02 Jan 2013 11:18:18 -0500 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Wed, 2 Jan 2013 17:16:23 +0100 Message-Id: <1357143393-29832-21-git-send-email-benoit@irqsave.net> In-Reply-To: <1357143393-29832-1-git-send-email-benoit@irqsave.net> References: <1357143393-29832-1-git-send-email-benoit@irqsave.net> Subject: [Qemu-devel] [RFC V4 20/30] qcow2: Serialize write requests when deduplication is activated. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com This fix the sub cluster sized writes race conditions while waiting for a more faster solution. Signed-off-by: Benoit Canet --- block/qcow2.c | 9 +++++++++ block/qcow2.h | 1 + 2 files changed, 10 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 54c8847..13f6a5c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -521,6 +521,7 @@ static int qcow2_open(BlockDriverState *bs, int flags) /* Initialise locks */ qemu_co_mutex_init(&s->lock); + qemu_co_mutex_init(&s->dedup_lock); /* Repair image if dirty */ if (!(flags & BDRV_O_CHECK) && !bs->read_only && @@ -810,6 +811,10 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, s->cluster_cache_offset = -1; /* disable compressed cache */ + if (s->has_dedup) { + qemu_co_mutex_lock(&s->dedup_lock); + } + qemu_co_mutex_lock(&s->lock); if (s->has_dedup) { @@ -978,6 +983,10 @@ fail: g_free(l2meta); } + if (s->has_dedup) { + qemu_co_mutex_unlock(&s->dedup_lock); + } + qemu_iovec_destroy(&hd_qiov); qemu_vfree(cluster_data); qemu_vfree(dedup_cluster_data); diff --git a/block/qcow2.h b/block/qcow2.h index f5576be..fd31f4f 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -224,6 +224,7 @@ typedef struct BDRVQcowState { GTree *dedup_tree_by_hash; GTree *dedup_tree_by_sect; CoMutex lock; + CoMutex dedup_lock; uint32_t crypt_method; /* current crypt method, 0 if no key yet */ uint32_t crypt_method_header; -- 1.7.10.4