From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:44758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRcO-00053l-DU for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RaRcG-0004J9-FV for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:38:00 -0500 Received: from mail-gy0-f173.google.com ([209.85.160.173]:48533) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RaRcG-0004FB-AM for qemu-devel@nongnu.org; Tue, 13 Dec 2011 07:37:52 -0500 Received: by mail-gy0-f173.google.com with SMTP id g19so382166ghb.4 for ; Tue, 13 Dec 2011 04:37:52 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Tue, 13 Dec 2011 13:37:15 +0100 Message-Id: <1323779840-4235-13-git-send-email-pbonzini@redhat.com> In-Reply-To: <1323779840-4235-1-git-send-email-pbonzini@redhat.com> References: <1323779840-4235-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 12/17] block: allow waiting only for overlapping writes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org To implement mismatching block size, we will reuse the request tracking mechanism that is used for copy-on-read. However, waiting for overlapping reads is not needed to protect against "torn reads", so add a flag to wait_for_overlapping_requests. Signed-off-by: Paolo Bonzini --- block.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 91622db..9a2ef83 100644 --- a/block.c +++ b/block.c @@ -1191,7 +1191,7 @@ static bool tracked_request_overlaps(BdrvTrackedRequest *req, } static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, - int64_t sector_num, int nb_sectors) + int64_t sector_num, int nb_sectors, bool writes_only) { BdrvTrackedRequest *req; int64_t cluster_sector_num; @@ -1207,9 +1207,16 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs, round_to_clusters(bs, sector_num, nb_sectors, &cluster_sector_num, &cluster_nb_sectors); + if (writes_only && !(bs->open_flags & BDRV_O_RDWR)) { + return; + } + do { retry = false; QLIST_FOREACH(req, &bs->tracked_requests, list) { + if (writes_only && !req->is_write) { + continue; + } if (tracked_request_overlaps(req, cluster_sector_num, cluster_nb_sectors)) { /* Hitting this means there was a reentrant request, for @@ -1576,7 +1583,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs, } if (bs->copy_on_read) { - wait_for_overlapping_requests(bs, sector_num, nb_sectors); + wait_for_overlapping_requests(bs, sector_num, nb_sectors, false); } tracked_request_begin(&req, bs, sector_num, nb_sectors, false); @@ -1636,7 +1643,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, } if (bs->copy_on_read) { - wait_for_overlapping_requests(bs, sector_num, nb_sectors); + wait_for_overlapping_requests(bs, sector_num, nb_sectors, false); } tracked_request_begin(&req, bs, sector_num, nb_sectors, true); -- 1.7.7.1