From nobody Sun Oct 5 19:22:52 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524599590279797.7434685160324; Tue, 24 Apr 2018 12:53:10 -0700 (PDT) Received: from localhost ([::1]:60589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB3zx-0004O0-KD for importer@patchew.org; Tue, 24 Apr 2018 15:53:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58527) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fB3d2-00029E-Vn for qemu-devel@nongnu.org; Tue, 24 Apr 2018 15:29:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fB3d1-00061A-SR for qemu-devel@nongnu.org; Tue, 24 Apr 2018 15:29:28 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:38504 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fB3cy-0005yl-Ja; Tue, 24 Apr 2018 15:29:24 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 348F581A88B6; Tue, 24 Apr 2018 19:29:24 +0000 (UTC) Received: from red.redhat.com (ovpn-122-114.rdu2.redhat.com [10.10.122.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AE3D2023239; Tue, 24 Apr 2018 19:29:23 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 24 Apr 2018 14:25:03 -0500 Message-Id: <20180424192506.149089-4-eblake@redhat.com> In-Reply-To: <20180424192506.149089-1-eblake@redhat.com> References: <20180424192506.149089-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 24 Apr 2018 19:29:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Tue, 24 Apr 2018 19:29:24 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 3/6] null: Switch to byte-based read/write X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Fam Zheng , jsnow@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We are gradually moving away from sector-based interfaces, towards byte-based. Make the change for the last few sector-based callbacks in the null-co and null-aio drivers. Note that since the null driver does nothing on writes, it trivially supports the BDRV_REQ_FUA flag (all writes have already landed to the same bit-bucket without needing an extra flush call). Also, since the null driver does just as well with byte-based requests, we can now avoid cycles wasted on read-modify-write by taking advantage of the block layer now defaulting the alignment to 1 instead of 512. Signed-off-by: Eric Blake --- v2: rely on new block layer default alignment [Kevin] --- block/null.c | 59 ++++++++++++++++++++++++++++++--------------------------= --- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/block/null.c b/block/null.c index 806a8631e4d..8fbbda52ea1 100644 --- a/block/null.c +++ b/block/null.c @@ -93,6 +93,7 @@ static int null_file_open(BlockDriverState *bs, QDict *op= tions, int flags, } s->read_zeroes =3D qemu_opt_get_bool(opts, NULL_OPT_ZEROES, false); qemu_opts_del(opts); + bs->supported_write_flags =3D BDRV_REQ_FUA; return ret; } @@ -116,22 +117,22 @@ static coroutine_fn int null_co_common(BlockDriverSta= te *bs) return 0; } -static coroutine_fn int null_co_readv(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - QEMUIOVector *qiov) +static coroutine_fn int null_co_preadv(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags) { BDRVNullState *s =3D bs->opaque; if (s->read_zeroes) { - qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE); + qemu_iovec_memset(qiov, 0, 0, bytes); } return null_co_common(bs); } -static coroutine_fn int null_co_writev(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, - QEMUIOVector *qiov) +static coroutine_fn int null_co_pwritev(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags) { return null_co_common(bs); } @@ -186,26 +187,26 @@ static inline BlockAIOCB *null_aio_common(BlockDriver= State *bs, return &acb->common; } -static BlockAIOCB *null_aio_readv(BlockDriverState *bs, - int64_t sector_num, QEMUIOVector *qiov, - int nb_sectors, - BlockCompletionFunc *cb, - void *opaque) -{ - BDRVNullState *s =3D bs->opaque; - - if (s->read_zeroes) { - qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE); - } - - return null_aio_common(bs, cb, opaque); -} - -static BlockAIOCB *null_aio_writev(BlockDriverState *bs, - int64_t sector_num, QEMUIOVector *qiov, - int nb_sectors, +static BlockAIOCB *null_aio_preadv(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags, BlockCompletionFunc *cb, void *opaque) +{ + BDRVNullState *s =3D bs->opaque; + + if (s->read_zeroes) { + qemu_iovec_memset(qiov, 0, 0, bytes); + } + + return null_aio_common(bs, cb, opaque); +} + +static BlockAIOCB *null_aio_pwritev(BlockDriverState *bs, + uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, int flags, + BlockCompletionFunc *cb, + void *opaque) { return null_aio_common(bs, cb, opaque); } @@ -266,8 +267,8 @@ static BlockDriver bdrv_null_co =3D { .bdrv_close =3D null_close, .bdrv_getlength =3D null_getlength, - .bdrv_co_readv =3D null_co_readv, - .bdrv_co_writev =3D null_co_writev, + .bdrv_co_preadv =3D null_co_preadv, + .bdrv_co_pwritev =3D null_co_pwritev, .bdrv_co_flush_to_disk =3D null_co_flush, .bdrv_reopen_prepare =3D null_reopen_prepare, @@ -286,8 +287,8 @@ static BlockDriver bdrv_null_aio =3D { .bdrv_close =3D null_close, .bdrv_getlength =3D null_getlength, - .bdrv_aio_readv =3D null_aio_readv, - .bdrv_aio_writev =3D null_aio_writev, + .bdrv_aio_preadv =3D null_aio_preadv, + .bdrv_aio_pwritev =3D null_aio_pwritev, .bdrv_aio_flush =3D null_aio_flush, .bdrv_reopen_prepare =3D null_reopen_prepare, --=20 2.14.3