From patchwork Mon Nov 14 12:44:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 125534 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 09D7DB71FE for ; Tue, 15 Nov 2011 00:37:05 +1100 (EST) Received: from localhost ([::1]:38853 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPvuj-0001Lt-9w for incoming@patchwork.ozlabs.org; Mon, 14 Nov 2011 07:45:29 -0500 Received: from eggs.gnu.org ([140.186.70.92]:54222) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPvu8-0008Ul-R8 for qemu-devel@nongnu.org; Mon, 14 Nov 2011 07:45:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RPvu4-00049n-F1 for qemu-devel@nongnu.org; Mon, 14 Nov 2011 07:44:52 -0500 Received: from mtagate1.uk.ibm.com ([194.196.100.161]:48116) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RPvu4-00048z-4O for qemu-devel@nongnu.org; Mon, 14 Nov 2011 07:44:48 -0500 Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate1.uk.ibm.com (8.13.1/8.13.1) with ESMTP id pAECilOO010940 for ; Mon, 14 Nov 2011 12:44:47 GMT Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id pAECilQh2412572 for ; Mon, 14 Nov 2011 12:44:47 GMT Received: from d06av05.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id pAECikXt017882 for ; Mon, 14 Nov 2011 05:44:47 -0700 Received: from localhost (stefanha-thinkpad.manchester-maybrook.uk.ibm.com [9.174.219.31]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id pAECikDq017877; Mon, 14 Nov 2011 05:44:46 -0700 From: Stefan Hajnoczi To: Date: Mon, 14 Nov 2011 12:44:24 +0000 Message-Id: <1321274666-14041-8-git-send-email-stefanha@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.7.1 In-Reply-To: <1321274666-14041-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1321274666-14041-1-git-send-email-stefanha@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 194.196.100.161 Cc: Kevin Wolf , Paolo Bonzini , Marcelo Tosatti , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v2 7/9] cow: convert to .bdrv_co_is_allocated() 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 The cow block driver does not keep internal state for cluster lookups. This means it is safe to perform cluster lookups in coroutine context without risk of race conditions that corrupt internal state. Signed-off-by: Stefan Hajnoczi --- block/cow.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/block/cow.c b/block/cow.c index 9858d71..7ae887b 100644 --- a/block/cow.c +++ b/block/cow.c @@ -132,8 +132,8 @@ static inline int is_bit_set(BlockDriverState *bs, int64_t bitnum) /* Return true if first block has been changed (ie. current version is * in COW file). Set the number of continuous blocks for which that * is true. */ -static int cow_is_allocated(BlockDriverState *bs, int64_t sector_num, - int nb_sectors, int *num_same) +static int coroutine_fn cow_co_is_allocated(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, int *num_same) { int changed; @@ -178,7 +178,7 @@ static int cow_read(BlockDriverState *bs, int64_t sector_num, int ret, n; while (nb_sectors > 0) { - if (cow_is_allocated(bs, sector_num, nb_sectors, &n)) { + if (bdrv_is_allocated(bs, sector_num, nb_sectors, &n)) { ret = bdrv_pread(bs->file, s->cow_sectors_offset + sector_num * 512, buf, n * 512); @@ -335,7 +335,7 @@ static BlockDriver bdrv_cow = { .bdrv_read = cow_co_read, .bdrv_write = cow_co_write, .bdrv_co_flush_to_disk = cow_co_flush, - .bdrv_is_allocated = cow_is_allocated, + .bdrv_co_is_allocated = cow_co_is_allocated, .create_options = cow_create_options, };