From patchwork Tue Mar 29 15:08:46 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 8688501 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 0E3649FC5B for ; Tue, 29 Mar 2016 15:36:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 72C57202FE for ; Tue, 29 Mar 2016 15:36:51 +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 AA5A82034E for ; Tue, 29 Mar 2016 15:36:50 +0000 (UTC) Received: from localhost ([::1]:48019 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akvhK-0006Vn-4C for patchwork-qemu-devel@patchwork.kernel.org; Tue, 29 Mar 2016 11:36:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41006) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akvIM-0005UV-Ey for qemu-devel@nongnu.org; Tue, 29 Mar 2016 11:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1akvIL-0006iD-Fd for qemu-devel@nongnu.org; Tue, 29 Mar 2016 11:11:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38110) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1akvI8-0006eL-Sy; Tue, 29 Mar 2016 11:10:48 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 9C7107F0B4; Tue, 29 Mar 2016 15:10:48 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-120.ams2.redhat.com [10.36.116.120]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2TF913N011786; Tue, 29 Mar 2016 11:10:47 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Tue, 29 Mar 2016 17:08:46 +0200 Message-Id: <1459264128-12761-47-git-send-email-kwolf@redhat.com> In-Reply-To: <1459264128-12761-1-git-send-email-kwolf@redhat.com> References: <1459264128-12761-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 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 Subject: [Qemu-devel] [PULL 46/48] block/null-{co, aio}: Allow reading zeroes 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 From: Max Reitz This is optional so that it does not impede the null block driver's performance unless this behavior is desired. Signed-off-by: Max Reitz Reviewed-by: Eric Blake Acked-by: Fam Zheng Signed-off-by: Kevin Wolf --- block/null.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/block/null.c b/block/null.c index d90165d..a7df386 100644 --- a/block/null.c +++ b/block/null.c @@ -14,10 +14,12 @@ #include "block/block_int.h" #define NULL_OPT_LATENCY "latency-ns" +#define NULL_OPT_ZEROES "read-zeroes" typedef struct { int64_t length; int64_t latency_ns; + bool read_zeroes; } BDRVNullState; static QemuOptsList runtime_opts = { @@ -40,6 +42,11 @@ static QemuOptsList runtime_opts = { .help = "nanoseconds (approximated) to wait " "before completing request", }, + { + .name = NULL_OPT_ZEROES, + .type = QEMU_OPT_BOOL, + .help = "return zeroes when read", + }, { /* end of list */ } }, }; @@ -61,6 +68,7 @@ static int null_file_open(BlockDriverState *bs, QDict *options, int flags, error_setg(errp, "latency-ns is invalid"); ret = -EINVAL; } + s->read_zeroes = qemu_opt_get_bool(opts, NULL_OPT_ZEROES, false); qemu_opts_del(opts); return ret; } @@ -90,6 +98,12 @@ static coroutine_fn int null_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) { + BDRVNullState *s = bs->opaque; + + if (s->read_zeroes) { + qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE); + } + return null_co_common(bs); } @@ -159,6 +173,12 @@ static BlockAIOCB *null_aio_readv(BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque) { + BDRVNullState *s = bs->opaque; + + if (s->read_zeroes) { + qemu_iovec_memset(qiov, 0, 0, nb_sectors * BDRV_SECTOR_SIZE); + } + return null_aio_common(bs, cb, opaque); }