From patchwork Wed Jan 16 15:48:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [RFC, V5, 24/62] qcow2: Serialize write requests when deduplication is activated. Date: Wed, 16 Jan 2013 05:48:03 -0000 From: =?utf-8?q?Beno=C3=AEt_Canet_=3Cbenoit=40irqsave=2Enet=3E?= X-Patchwork-Id: 212845 Message-Id: <1358351321-4891-25-git-send-email-benoit@irqsave.net> 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 | 14 +++++++++++++- block/qcow2.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 6b8f85f..4f8cf68 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -523,6 +523,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 && @@ -814,8 +815,15 @@ static coroutine_fn int qcow2_co_writev(BlockDriverState *bs, s->cluster_cache_offset = -1; /* disable compressed cache */ qemu_co_mutex_lock(&s->lock); - atomic_dedup_is_running = qcow2_dedup_is_running(bs); + qemu_co_mutex_unlock(&s->lock); + + if (atomic_dedup_is_running) { + qemu_co_mutex_lock(&s->dedup_lock); + } + + qemu_co_mutex_lock(&s->lock); + if (atomic_dedup_is_running) { QTAILQ_INIT(&ds.undedupables); ds.phash.reuse = false; @@ -982,6 +990,10 @@ fail: g_free(l2meta); } + if (atomic_dedup_is_running) { + 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 dc9f519..9f5d0f0 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -239,6 +239,7 @@ typedef struct BDRVQcowState { 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;