qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	vsementsov@virtuozzo.com, rjones@redhat.com,
	qemu-block@nongnu.org, mreitz@redhat.com
Subject: [PATCH 3/3] nbd: Add .bdrv_known_zeroes() server support
Date: Mon, 10 Feb 2020 15:41:09 -0600	[thread overview]
Message-ID: <20200210214109.751734-4-eblake@redhat.com> (raw)
In-Reply-To: <20200210214109.751734-1-eblake@redhat.com>

Using the new NBD extension of NBD_INFO_INIT_STATE, we can advertise
at least the NBD_INIT_ZERO bit based on what the block layer already
knows.  Advertising NBD_INIT_SPARSE might also be possible by
inspecting blk_probe_blocksizes, but as the block layer does not
consume that information at present, the effort of advertising it for
a third party is less important.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 block/block-backend.c          |  9 +++++++++
 include/sysemu/block-backend.h |  1 +
 nbd/server.c                   | 11 +++++++++++
 3 files changed, 21 insertions(+)

diff --git a/block/block-backend.c b/block/block-backend.c
index 8b8f2a80a0d5..d7e01f2e67de 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2127,6 +2127,15 @@ int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size)
     return bdrv_load_vmstate(blk_bs(blk), buf, pos, size);
 }

+int blk_known_zeroes(BlockBackend *blk)
+{
+    if (!blk_is_available(blk)) {
+        return 0;
+    }
+
+    return bdrv_known_zeroes(blk_bs(blk));
+}
+
 int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz)
 {
     if (!blk_is_available(blk)) {
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index b198deca0b24..2a9b750bb775 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -245,6 +245,7 @@ int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,
 int blk_load_vmstate(BlockBackend *blk, uint8_t *buf, int64_t pos, int size);
 int blk_probe_blocksizes(BlockBackend *blk, BlockSizes *bsz);
 int blk_probe_geometry(BlockBackend *blk, HDGeometry *geo);
+int blk_known_zeroes(BlockBackend *blk);
 BlockAIOCB *blk_abort_aio_request(BlockBackend *blk,
                                   BlockCompletionFunc *cb,
                                   void *opaque, int ret);
diff --git a/nbd/server.c b/nbd/server.c
index 11a31094ff83..f6bb7d944daa 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -661,6 +661,17 @@ static int nbd_negotiate_handle_info(NBDClient *client, Error **errp)
         return rc;
     }

+    /* Send NBD_INFO_INIT_STATE always */
+    trace_nbd_negotiate_new_style_size_flags(exp->size, myflags);
+    /* Is it worth using blk_probe_blocksizes for setting NBD_INIT_SPARSE? */
+    stw_be_p(buf, ((blk_known_zeroes(exp->blk) & BDRV_ZERO_OPEN)
+                   ? NBD_INIT_ZERO : 0));
+    rc = nbd_negotiate_send_info(client, NBD_INFO_INIT_STATE,
+                                 sizeof(uint16_t), buf, errp);
+    if (rc < 0) {
+        return rc;
+    }
+
     /*
      * If the client is just asking for NBD_OPT_INFO, but forgot to
      * request block sizes in a situation that would impact
-- 
2.24.1



  parent reply	other threads:[~2020-02-10 21:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-10 21:37 Cross-project NBD extension proposal: NBD_INFO_INIT_STATE Eric Blake
2020-02-10 21:41 ` [qemu PATCH 0/3] NBD_INFO_INIT_STATE extension Eric Blake
2020-02-10 21:41   ` [PATCH 1/3] nbd: Preparation for NBD_INFO_INIT_STATE Eric Blake
2020-02-10 21:41   ` [PATCH 2/3] nbd: Add .bdrv_known_zeroes() client support Eric Blake
2020-02-10 21:41   ` Eric Blake [this message]
2020-02-10 21:51   ` [qemu PATCH 0/3] NBD_INFO_INIT_STATE extension no-reply
2020-02-10 21:54     ` Eric Blake
2020-02-10 21:53   ` no-reply
2020-02-10 22:12 ` Cross-project NBD extension proposal: NBD_INFO_INIT_STATE Richard W.M. Jones
2020-02-10 22:29   ` Eric Blake
2020-02-10 22:52     ` Richard W.M. Jones
2020-02-11 14:33       ` Eric Blake
2020-02-12  7:27       ` Wouter Verhelst
2020-02-12 12:09         ` Eric Blake
2020-02-12 12:36           ` Richard W.M. Jones
2020-02-12 12:47             ` Eric Blake
2020-02-17 15:13 ` Max Reitz
2020-02-18 20:55   ` Eric Blake
2020-02-19 11:10     ` Max Reitz

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=20200210214109.751734-4-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rjones@redhat.com \
    --cc=vsementsov@virtuozzo.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).