@@ -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)) {
@@ -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);
@@ -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
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(+)