From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:52602) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqT2y-0004xr-LZ for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqT2p-0003RF-0U for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:40 -0500 Received: from mail-gx0-f173.google.com ([209.85.161.173]:59379) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqT2o-0003Mz-Tx for qemu-devel@nongnu.org; Thu, 26 Jan 2012 12:23:30 -0500 Received: by mail-gx0-f173.google.com with SMTP id h1so470472ggn.4 for ; Thu, 26 Jan 2012 09:23:30 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 26 Jan 2012 18:22:43 +0100 Message-Id: <1327598569-5199-13-git-send-email-pbonzini@redhat.com> In-Reply-To: <1327598569-5199-1-git-send-email-pbonzini@redhat.com> References: <1327598569-5199-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v2 12/18] block: allow waiting only for overlapping writes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com 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 af41fb3..76e1c6a 100644 --- a/block.c +++ b/block.c @@ -1198,7 +1198,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; @@ -1214,9 +1214,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 @@ -1591,7 +1598,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs, } if (bs->copy_on_read_in_flight) { - 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); @@ -1665,7 +1672,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs, } if (bs->copy_on_read_in_flight) { - 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.6