From patchwork Tue Dec 30 09:28:18 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 424591 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 2C83A1400DD for ; Tue, 30 Dec 2014 20:32:50 +1100 (AEDT) Received: from localhost ([::1]:36215 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5tAW-0002fP-8r for incoming@patchwork.ozlabs.org; Tue, 30 Dec 2014 04:32:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48224) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5t67-0003b7-TX for qemu-devel@nongnu.org; Tue, 30 Dec 2014 04:28:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y5t5x-0006ii-Vz for qemu-devel@nongnu.org; Tue, 30 Dec 2014 04:28:15 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:19713 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y5t5x-0006ep-22 for qemu-devel@nongnu.org; Tue, 30 Dec 2014 04:28:05 -0500 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id sBU9Roa0000315; Tue, 30 Dec 2014 12:27:59 +0300 (MSK) From: "Denis V. Lunev" To: Date: Tue, 30 Dec 2014 12:28:18 +0300 Message-Id: <1419931701-19362-7-git-send-email-den@openvz.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1419931701-19362-1-git-send-email-den@openvz.org> References: <1419931701-19362-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Kevin Wolf , "Denis V. Lunev" , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 06/19] block/parallels: provide _co_readv routine for parallels format driver 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 Main approach is taken from qcow2_co_readv. The patch drops coroutine lock for the duration of IO operation and peforms normal scatter-gather IO using standard QEMU backend. Signed-off-by: Denis V. Lunev Acked-by: Roman Kagan CC: Kevin Wolf CC: Stefan Hajnoczi --- block/parallels.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/block/parallels.c b/block/parallels.c index b469984..64b169b 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -186,37 +186,45 @@ static int64_t coroutine_fn parallels_co_get_block_status(BlockDriverState *bs, BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } -static int parallels_read(BlockDriverState *bs, int64_t sector_num, - uint8_t *buf, int nb_sectors) +static coroutine_fn int parallels_co_readv(BlockDriverState *bs, + int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { BDRVParallelsState *s = bs->opaque; + uint64_t bytes_done = 0; + QEMUIOVector hd_qiov; + int ret = 0; + qemu_iovec_init(&hd_qiov, qiov->niov); + + qemu_co_mutex_lock(&s->lock); while (nb_sectors > 0) { int64_t position = seek_to_sector(s, sector_num); int n = cluster_remainder(s, sector_num, nb_sectors); - if (position >= 0) { - int ret = bdrv_read(bs->file, position, buf, n); + int nbytes = n << BDRV_SECTOR_BITS; + + if (position < 0) { + qemu_iovec_memset(qiov, bytes_done, 0, nbytes); + } else { + qemu_iovec_reset(&hd_qiov); + qemu_iovec_concat(&hd_qiov, qiov, bytes_done, nbytes); + + qemu_co_mutex_unlock(&s->lock); + ret = bdrv_co_readv(bs->file, position, n, &hd_qiov); + qemu_co_mutex_lock(&s->lock); + if (ret < 0) { - return ret; + goto fail; } - } else { - memset(buf, 0, n << BDRV_SECTOR_BITS); } + nb_sectors -= n; sector_num += n; - buf += n << BDRV_SECTOR_BITS; + bytes_done += nbytes; } - return 0; -} - -static coroutine_fn int parallels_co_read(BlockDriverState *bs, int64_t sector_num, - uint8_t *buf, int nb_sectors) -{ - int ret; - BDRVParallelsState *s = bs->opaque; - qemu_co_mutex_lock(&s->lock); - ret = parallels_read(bs, sector_num, buf, nb_sectors); qemu_co_mutex_unlock(&s->lock); + +fail: + qemu_iovec_destroy(&hd_qiov); return ret; } @@ -231,9 +239,9 @@ static BlockDriver bdrv_parallels = { .instance_size = sizeof(BDRVParallelsState), .bdrv_probe = parallels_probe, .bdrv_open = parallels_open, - .bdrv_read = parallels_co_read, .bdrv_close = parallels_close, .bdrv_co_get_block_status = parallels_co_get_block_status, + .bdrv_co_readv = parallels_co_readv, }; static void bdrv_parallels_init(void)