From patchwork Tue Mar 8 12:47:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8533681 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CBABE9F46A for ; Tue, 8 Mar 2016 12:52:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2D0CD20165 for ; Tue, 8 Mar 2016 12:52:29 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6AE4F20123 for ; Tue, 8 Mar 2016 12:52:28 +0000 (UTC) Received: from localhost ([::1]:34212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adH7j-0003wT-R2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 08 Mar 2016 07:52:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40467) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adH3f-0005QV-5j for qemu-devel@nongnu.org; Tue, 08 Mar 2016 07:48:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1adH3e-0005UF-9d for qemu-devel@nongnu.org; Tue, 08 Mar 2016 07:48:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46715) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1adH3V-0005RO-Jr; Tue, 08 Mar 2016 07:48:05 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 37DDFC0A1B16; Tue, 8 Mar 2016 12:48:05 +0000 (UTC) Received: from noname.str.redhat.com. (dhcp-192-197.str.redhat.com [10.33.192.197]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u28CltVx024869; Tue, 8 Mar 2016 07:48:03 -0500 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 8 Mar 2016 13:47:51 +0100 Message-Id: <1457441273-29821-7-git-send-email-kwolf@redhat.com> In-Reply-To: <1457441273-29821-1-git-send-email-kwolf@redhat.com> References: <1457441273-29821-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com Subject: [Qemu-devel] [PATCH 6/8] block: Use blk_prw() in blk_pread()/blk_pwrite() 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Kevin Wolf --- block/block-backend.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 5b9d387..579cc09 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -747,9 +747,9 @@ static void blk_write_entry(void *opaque) rwco->qiov, rwco->flags); } -static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf, - int nb_sectors, CoroutineEntry co_entry, - BdrvRequestFlags flags) +static int blk_prw(BlockBackend *blk, int64_t offset, uint8_t *buf, + int64_t bytes, CoroutineEntry co_entry, + BdrvRequestFlags flags) { AioContext *aio_context; QEMUIOVector qiov; @@ -757,19 +757,15 @@ static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf, Coroutine *co; BlkRwCo rwco; - if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { - return -EINVAL; - } - iov = (struct iovec) { .iov_base = buf, - .iov_len = nb_sectors * BDRV_SECTOR_SIZE, + .iov_len = bytes, }; qemu_iovec_init_external(&qiov, &iov, 1); rwco = (BlkRwCo) { .blk = blk, - .offset = sector_num << BDRV_SECTOR_BITS, + .offset = offset, .qiov = &qiov, .flags = flags, .ret = NOT_DONE, @@ -786,6 +782,18 @@ static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf, return rwco.ret; } +static int blk_rw(BlockBackend *blk, int64_t sector_num, uint8_t *buf, + int nb_sectors, CoroutineEntry co_entry, + BdrvRequestFlags flags) +{ + if (nb_sectors < 0 || nb_sectors > BDRV_REQUEST_MAX_SECTORS) { + return -EINVAL; + } + + return blk_prw(blk, sector_num << BDRV_SECTOR_BITS, buf, + nb_sectors << BDRV_SECTOR_BITS, co_entry, flags); +} + int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf, int nb_sectors) { @@ -866,22 +874,20 @@ BlockAIOCB *blk_aio_write_zeroes(BlockBackend *blk, int64_t sector_num, int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count) { - int ret = blk_check_byte_request(blk, offset, count); + int ret = blk_prw(blk, offset, buf, count, blk_read_entry, 0); if (ret < 0) { return ret; } - - return bdrv_pread(blk_bs(blk), offset, buf, count); + return count; } int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count) { - int ret = blk_check_byte_request(blk, offset, count); + int ret = blk_prw(blk, offset, (void*) buf, count, blk_write_entry, 0); if (ret < 0) { return ret; } - - return bdrv_pwrite(blk_bs(blk), offset, buf, count); + return count; } int64_t blk_getlength(BlockBackend *blk)