All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 2/4] block/null-{co, aio}: Allow reading zeroes
Date: Fri, 25 Mar 2016 10:01:15 +0800	[thread overview]
Message-ID: <20160325020115.GA29171@ad.usersys.redhat.com> (raw)
In-Reply-To: <1458858840-3859-3-git-send-email-mreitz@redhat.com>

On Thu, 03/24 23:33, Max Reitz wrote:
> 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 <mreitz@redhat.com>
> ---
>  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);
>  }
>  
> -- 
> 2.7.4
> 

Acked-by: Fam Zheng <famz@redhat.com>

  parent reply	other threads:[~2016-03-25  2:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-24 22:33 [Qemu-devel] [PATCH v2 0/4] qemu-img: Fix preallocation with -S 0 for convert Max Reitz
2016-03-24 22:33 ` [Qemu-devel] [PATCH v2 1/4] " Max Reitz
2016-03-25  6:36   ` Fam Zheng
2016-03-24 22:33 ` [Qemu-devel] [PATCH v2 2/4] block/null-{co, aio}: Allow reading zeroes Max Reitz
2016-03-24 22:55   ` Eric Blake
2016-03-25  2:01   ` Fam Zheng [this message]
2016-03-24 22:33 ` [Qemu-devel] [PATCH v2 3/4] block/null-{co, aio}: Implement get_block_status() Max Reitz
2016-03-25  2:02   ` Fam Zheng
2016-03-24 22:34 ` [Qemu-devel] [PATCH v2 4/4] iotests: Test qemu-img convert -S 0 behavior Max Reitz
2016-03-25  6:43   ` Fam Zheng
2016-03-29 16:16 ` [Qemu-devel] [PATCH v2 0/4] qemu-img: Fix preallocation with -S 0 for convert Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160325020115.GA29171@ad.usersys.redhat.com \
    --to=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.