From patchwork Wed Jan 16 16:24:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 212892 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE3F12C0091 for ; Thu, 17 Jan 2013 04:52:52 +1100 (EST) Received: from localhost ([::1]:36948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVps-0003vn-0T for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 11:27:32 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41457) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVpR-00035v-FN for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:27:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvVpG-0007EB-0A for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:27:05 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:43252 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVpF-0007E7-ND for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:26:53 -0500 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 3D927874325; Wed, 16 Jan 2013 17:58:30 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id 1048C874331; Wed, 16 Jan 2013 17:56:05 +0100 (CET) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 17:24:45 +0100 Message-Id: <1358353497-5292-25-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358353497-5292-1-git-send-email-benoit@irqsave.net> References: <1358353497-5292-1-git-send-email-benoit@irqsave.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] [RFC V5 24/36] qcow2: Serialize write requests when deduplication is activated. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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;