All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pavel Borzenkov <pborzenkov@virtuozzo.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	alex@alex.org.uk, qemu-block@nongnu.org,
	Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 41/44] nbd: Implement NBD_CMD_WRITE_ZEROES on server
Date: Sat, 23 Apr 2016 12:00:13 +0300	[thread overview]
Message-ID: <20160423090013.GB3985@phobos> (raw)
In-Reply-To: <1461368452-10389-42-git-send-email-eblake@redhat.com>

On Fri, Apr 22, 2016 at 05:40:49PM -0600, Eric Blake wrote:
> Upstream NBD protocol recently added the ability to efficiently
> write zeroes without having to send the zeroes over the wire,
> along with a flag to control whether the client wants a hole.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> 
> ---
> v3: abandon NBD_CMD_CLOSE extension, rebase to use blk_pwrite_zeroes
> ---
>  include/block/nbd.h |  7 +++++--
>  nbd/server.c        | 42 ++++++++++++++++++++++++++++++++++++++++--
>  2 files changed, 45 insertions(+), 4 deletions(-)
> 
> diff --git a/include/block/nbd.h b/include/block/nbd.h
> index 05c0e48..1072d9e 100644
> --- a/include/block/nbd.h
> +++ b/include/block/nbd.h
> @@ -70,6 +70,7 @@ typedef struct nbd_reply nbd_reply;
>  #define NBD_FLAG_SEND_FUA       (1 << 3)        /* Send FUA (Force Unit Access) */
>  #define NBD_FLAG_ROTATIONAL     (1 << 4)        /* Use elevator algorithm - rotational media */
>  #define NBD_FLAG_SEND_TRIM      (1 << 5)        /* Send TRIM (discard) */
> +#define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6)     /* Send WRITE_ZEROES */
> 
>  /* New-style handshake (global) flags, sent from server to client, and
>     control what will happen during handshake phase. */
> @@ -102,7 +103,8 @@ typedef struct nbd_reply nbd_reply;
>  #define NBD_INFO_DESCRIPTION    2
> 
>  /* Request flags, sent from client to server during transmission phase */
> -#define NBD_CMD_FLAG_FUA        (1 << 0)
> +#define NBD_CMD_FLAG_FUA        (1 << 0) /* 'force unit access' during write */
> +#define NBD_CMD_FLAG_NO_HOLE    (1 << 1) /* don't punch hole on zero run */
> 
>  /* Supported request types */
>  enum {
> @@ -110,7 +112,8 @@ enum {
>      NBD_CMD_WRITE = 1,
>      NBD_CMD_DISC = 2,
>      NBD_CMD_FLUSH = 3,
> -    NBD_CMD_TRIM = 4
> +    NBD_CMD_TRIM = 4,
> +    NBD_CMD_WRITE_ZEROES = 5,

It's defined to 6 by the spec.

>  };
> 
>  #define NBD_DEFAULT_PORT	10809
> diff --git a/nbd/server.c b/nbd/server.c
> index 1edb5f3..563afb2 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -689,7 +689,8 @@ static coroutine_fn int nbd_negotiate(NBDClientNewData *data)
>      char buf[8 + 8 + 8 + 128];
>      int rc;
>      const uint16_t myflags = (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM |
> -                              NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA);
> +                              NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA |
> +                              NBD_FLAG_SEND_WRITE_ZEROES);
>      bool oldStyle;
>      size_t len;
> 
> @@ -1199,11 +1200,17 @@ static ssize_t nbd_co_receive_request(NBDRequest *req,
>          rc = -EINVAL;
>          goto out;
>      }
> -    if (request->flags & ~NBD_CMD_FLAG_FUA) {
> +    if (request->flags & ~(NBD_CMD_FLAG_FUA | NBD_CMD_FLAG_NO_HOLE)) {
>          LOG("unsupported flags (got 0x%x)", request->flags);
>          rc = -EINVAL;
>          goto out;
>      }
> +    if (request->type != NBD_CMD_WRITE_ZEROES &&
> +        (request->flags & NBD_CMD_FLAG_NO_HOLE)) {
> +        LOG("unexpected flags (got 0x%x)", request->flags);
> +        rc = -EINVAL;
> +        goto out;
> +    }
> 
>      rc = 0;
> 
> @@ -1308,6 +1315,37 @@ static void nbd_trip(void *opaque)
>          }
>          break;
> 
> +    case NBD_CMD_WRITE_ZEROES:
> +        TRACE("Request type is WRITE_ZEROES");
> +
> +        if (exp->nbdflags & NBD_FLAG_READ_ONLY) {
> +            TRACE("Server is read-only, return error");
> +            reply.error = EROFS;
> +            goto error_reply;
> +        }
> +
> +        TRACE("Writing to device");
> +
> +        flags = 0;
> +        if (request.flags & NBD_CMD_FLAG_FUA) {
> +            flags |= BDRV_REQ_FUA;
> +        }
> +        if (!(request.flags & NBD_CMD_FLAG_NO_HOLE)) {
> +            flags |= BDRV_REQ_MAY_UNMAP;
> +        }
> +        ret = blk_pwrite_zeroes(exp->blk, request.from + exp->dev_offset,
> +                                request.len, flags);
> +        if (ret < 0) {
> +            LOG("writing to file failed");
> +            reply.error = -ret;
> +            goto error_reply;
> +        }
> +
> +        if (nbd_co_send_reply(req, &reply, 0) < 0) {
> +            goto out;
> +        }
> +        break;
> +
>      case NBD_CMD_DISC:
>          /* unreachable, thanks to special case in nbd_co_receive_request() */
>          abort();
> -- 
> 2.5.5
> 
> 

  reply	other threads:[~2016-04-23 10:33 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-22 23:40 [Qemu-devel] [PATCH v3 00/44] NBD protocol additions Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 01/44] nbd: More debug typo fixes, use correct formats Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 02/44] nbd: Quit server after any write error Eric Blake
2016-04-25  9:21   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 03/44] nbd: Improve server handling of bogus commands Eric Blake
2016-04-25  9:29   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 04/44] nbd: Reject unknown request flags Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 05/44] nbd: Group all Linux-specific ioctl code in one place Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 06/44] nbd: Clean up ioctl handling of qemu-nbd -c Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 07/44] nbd: Limit nbdflags to 16 bits Eric Blake
2016-04-25  9:24   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 08/44] nbd: Add qemu-nbd -D for human-readable description Eric Blake
2016-04-25  9:25   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 09/44] block: Allow BDRV_REQ_FUA through blk_pwrite() Eric Blake
2016-04-23  8:12   ` Denis V. Lunev
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 10/44] fdc: Switch to byte-based block access Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 11/44] nand: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 12/44] onenand: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 13/44] pflash: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 14/44] sd: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 15/44] m25p80: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 16/44] atapi: " Eric Blake
2016-04-25 21:36   ` John Snow
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 17/44] nbd: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 18/44] qemu-img: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 19/44] qemu-io: " Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 20/44] block: Switch blk_read_unthrottled() to byte interface Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 21/44] block: Switch blk_write_zeroes() " Eric Blake
2016-04-23  8:12   ` Denis V. Lunev
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 22/44] block: Kill blk_write(), blk_read() Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 23/44] qemu-io: Add missing option documentation Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 24/44] qemu-io: Add 'write -f' to test FUA flag Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 25/44] qemu-io: Add 'open -u' to set BDRV_O_UNMAP after the fact Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 26/44] qemu-io: Add 'write -z -u' to test MAY_UNMAP flag Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 27/44] nbd: Use BDRV_REQ_FUA for better FUA where supported Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 28/44] nbd: Detect servers that send unexpected error values Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 29/44] nbd: Avoid magic number for NBD max name size Eric Blake
2016-04-25  9:32   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 30/44] nbd: Treat flags vs. command type as separate fields Eric Blake
2016-04-25  9:34   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 31/44] nbd: Share common reply-sending code in server Eric Blake
2016-04-25  9:34   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 32/44] nbd: Share common option-sending code in client Eric Blake
2016-04-25  9:37   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 33/44] nbd: Let client skip portions of server reply Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 34/44] nbd: Less allocation during NBD_OPT_LIST Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 35/44] nbd: Support shorter handshake Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 36/44] nbd: Improve handling of shutdown requests Eric Blake
2016-04-25  9:47   ` Alex Bligh
2016-04-25 19:20     ` Eric Blake
2016-04-25 19:40       ` Alex Bligh
2016-04-25 19:48         ` Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 37/44] nbd: Create struct for tracking export info Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 38/44] block: Add blk_get_opt_transfer_length() Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 39/44] nbd: Implement NBD_OPT_GO on server Eric Blake
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 40/44] nbd: Implement NBD_OPT_GO on client Eric Blake
2016-04-25 10:31   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 41/44] nbd: Implement NBD_CMD_WRITE_ZEROES on server Eric Blake
2016-04-23  9:00   ` Pavel Borzenkov [this message]
2016-04-25 12:11   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 42/44] nbd: Implement NBD_CMD_WRITE_ZEROES on client Eric Blake
2016-04-25 12:12   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 43/44] nbd: Implement NBD_OPT_BLOCK_SIZE on server Eric Blake
2016-04-25 12:16   ` Alex Bligh
2016-04-22 23:40 ` [Qemu-devel] [PATCH v3 44/44] nbd: Implement NBD_OPT_BLOCK_SIZE on client Eric Blake
2016-04-25 12:19   ` Alex Bligh
2016-04-25 19:16     ` Eric Blake

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=20160423090013.GB3985@phobos \
    --to=pborzenkov@virtuozzo.com \
    --cc=alex@alex.org.uk \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@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.