From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35802) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2MSY-0002ue-Pi for qemu-devel@nongnu.org; Thu, 25 Jul 2013 10:24:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V2MSX-0007sd-4D for qemu-devel@nongnu.org; Thu, 25 Jul 2013 10:24:02 -0400 Received: from mail-yh0-x230.google.com ([2607:f8b0:4002:c01::230]:40933) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V2MSW-0007sZ-Vi for qemu-devel@nongnu.org; Thu, 25 Jul 2013 10:24:01 -0400 Received: by mail-yh0-f48.google.com with SMTP id b20so568283yha.7 for ; Thu, 25 Jul 2013 07:24:00 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Thu, 25 Jul 2013 16:23:03 +0200 Message-Id: <1374762197-7261-6-git-send-email-pbonzini@redhat.com> In-Reply-To: <1374762197-7261-1-git-send-email-pbonzini@redhat.com> References: <1374762197-7261-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH v3 05/19] block: make bdrv_co_is_allocated static List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pl@kamp.de, stefanha@redhat.com 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/raw.c | 2 +- block/stream.c | 4 ++-- include/block/block.h | 2 -- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index ebac2fa..dd4c570 100644 --- a/block.c +++ b/block.c @@ -2527,7 +2527,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; } @@ -2981,8 +2981,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; @@ -3032,10 +3033,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; } @@ -3063,8 +3069,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/raw.c b/block/raw.c index f1682d4..4517a81 100644 --- a/block/raw.c +++ b/block/raw.c @@ -39,7 +39,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, -- 1.8.3.1