From patchwork Thu Aug 29 14:00:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 270836 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 459FC2C00B6 for ; Fri, 30 Aug 2013 00:03:24 +1000 (EST) Received: from localhost ([::1]:43557 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2ok-0001WF-6U for incoming@patchwork.ozlabs.org; Thu, 29 Aug 2013 10:03:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53923) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2mK-0006ZH-Lx for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:01:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VF2mC-00085A-7z for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:00:52 -0400 Received: from mail-ea0-x22a.google.com ([2a00:1450:4013:c01::22a]:54341) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VF2mB-00084a-HH for qemu-devel@nongnu.org; Thu, 29 Aug 2013 10:00:43 -0400 Received: by mail-ea0-f170.google.com with SMTP id h14so266295eak.15 for ; Thu, 29 Aug 2013 07:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=z6O7jsbTjSq/OpSos/Uo3qk9Phc1QXeVu+3RGrZJFFA=; b=UZ2BJNcE94r0pmNr30aIb7THkVyKdfOzkAHkjLKp5GecTCBHPztyIdVPHU1dXsW5nG YfHqh+V663UhZ8udxc92R03tEUsTXxAztnyxljT7rrBp574uWmJbdRmQRpQFEF3J2M/I x4jj19YZ6OXSEtGCuKVUQpDLgRKG+LOBDao5GIUjmN7H52XDvgZJkbDUtYm1o/MNv/re s0fuX/IjWp4gnOShxbEDq+DmJQuXTbycno0DOuLOwkArWcSH4mZug9qCxhBkfNnsLn4w HNKfMFcfF9vkDVtkmqjPvAP/ddDHV8AqM52a1XSC4cYRbNA7BGWDxu5E3y5rYIhUrugo jpnw== X-Received: by 10.15.101.195 with SMTP id bp43mr3522881eeb.70.1377784842603; Thu, 29 Aug 2013 07:00:42 -0700 (PDT) Received: from yakj.usersys.redhat.com (nat-pool-mxp-t.redhat.com. [209.132.186.18]) by mx.google.com with ESMTPSA id p5sm46359028eeg.5.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 29 Aug 2013 07:00:41 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 29 Aug 2013 16:00:05 +0200 Message-Id: <1377784821-29561-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> References: <1377784821-29561-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22a Cc: kwolf@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v4 05/21] block: make bdrv_co_is_allocated static 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 bdrv_is_allocated can detect coroutine context and go through a fast path, similar to other block layer functions. Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- block.c | 24 +++++++++++++++--------- block/backup.c | 4 ++-- block/raw.c | 2 +- block/stream.c | 4 ++-- include/block/block.h | 2 -- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index b11254a..fc5ea56 100644 --- a/block.c +++ b/block.c @@ -2533,7 +2533,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs, if (flags & BDRV_REQ_COPY_ON_READ) { int pnum; - ret = bdrv_co_is_allocated(bs, sector_num, nb_sectors, &pnum); + ret = bdrv_is_allocated(bs, sector_num, nb_sectors, &pnum); if (ret < 0) { goto out; } @@ -2987,8 +2987,9 @@ typedef struct BdrvCoIsAllocatedData { * 'nb_sectors' is the max value 'pnum' should be set to. If nb_sectors goes * beyond the end of the disk image it will be clamped. */ -int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum) +static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, + int nb_sectors, int *pnum) { int64_t n; @@ -3038,10 +3039,15 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, .done = false, }; - co = qemu_coroutine_create(bdrv_is_allocated_co_entry); - qemu_coroutine_enter(co, &data); - while (!data.done) { - qemu_aio_wait(); + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + bdrv_is_allocated_co_entry(&data); + } else { + co = qemu_coroutine_create(bdrv_is_allocated_co_entry); + qemu_coroutine_enter(co, &data); + while (!data.done) { + qemu_aio_wait(); + } } return data.ret; } @@ -3069,8 +3075,8 @@ int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, intermediate = top; while (intermediate && intermediate != base) { int pnum_inter; - ret = bdrv_co_is_allocated(intermediate, sector_num, nb_sectors, - &pnum_inter); + ret = bdrv_is_allocated(intermediate, sector_num, nb_sectors, + &pnum_inter); if (ret < 0) { return ret; } else if (ret) { diff --git a/block/backup.c b/block/backup.c index 6ae8a05..9931bb9 100644 --- a/block/backup.c +++ b/block/backup.c @@ -289,14 +289,14 @@ static void coroutine_fn backup_run(void *opaque) * backing file. */ for (i = 0; i < BACKUP_SECTORS_PER_CLUSTER;) { - /* bdrv_co_is_allocated() only returns true/false based + /* bdrv_is_allocated() only returns true/false based * on the first set of sectors it comes accross that * are are all in the same state. * For that reason we must verify each sector in the * backup cluster length. We end up copying more than * needed but at some point that is always the case. */ alloced = - bdrv_co_is_allocated(bs, + bdrv_is_allocated(bs, start * BACKUP_SECTORS_PER_CLUSTER + i, BACKUP_SECTORS_PER_CLUSTER - i, &n); i += n; diff --git a/block/raw.c b/block/raw.c index 4751825..1467d75 100644 --- a/block/raw.c +++ b/block/raw.c @@ -62,7 +62,7 @@ static int coroutine_fn raw_co_is_allocated(BlockDriverState *bs, int64_t sector_num, int nb_sectors, int *pnum) { - return bdrv_co_is_allocated(bs->file, sector_num, nb_sectors, pnum); + return bdrv_is_allocated(bs->file, sector_num, nb_sectors, pnum); } static int coroutine_fn raw_co_write_zeroes(BlockDriverState *bs, diff --git a/block/stream.c b/block/stream.c index 7fe9e48..fb1f9c3 100644 --- a/block/stream.c +++ b/block/stream.c @@ -115,8 +115,8 @@ wait: break; } - ret = bdrv_co_is_allocated(bs, sector_num, - STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); + ret = bdrv_is_allocated(bs, sector_num, + STREAM_BUFFER_SIZE / BDRV_SECTOR_SIZE, &n); if (ret == 1) { /* Allocated in the top, no need to copy. */ copy = false; diff --git a/include/block/block.h b/include/block/block.h index 742fce5..dde745f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -181,8 +181,6 @@ int coroutine_fn bdrv_co_writev(BlockDriverState *bs, int64_t sector_num, */ int coroutine_fn bdrv_co_write_zeroes(BlockDriverState *bs, int64_t sector_num, int nb_sectors); -int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *pnum); int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, BlockDriverState *base, int64_t sector_num,