From patchwork Mon Feb 10 21:41:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 11374149 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3EE86138D for ; Mon, 10 Feb 2020 21:42:53 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 166872082F for ; Mon, 10 Feb 2020 21:42:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="SdV2nHc7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 166872082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40042 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1GpQ-0007yy-1U for patchwork-qemu-devel@patchwork.kernel.org; Mon, 10 Feb 2020 16:42:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47077) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1Gnt-0006EX-RC for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1Gns-0001V5-EO for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:17 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:22225 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j1Gns-0001Te-9S for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:16 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581370876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=slx1Uc5NT50d59xWG/Bx+qVq3cAWVxFBYvTlyL2cQy8=; b=SdV2nHc7M1Hfj/jKFU7BJW09JXTxsYVmkmWPaL99XT/7xrq//oiZsS2iIK0DVNxtuQt6xF 5rpfpQTxyec3lhvKPyum4vbPJoy82FGtQgu4S4n22t2zZb2XrszXCGzjL2PMod9ozF4lGg cOLgz1ueeu+xN9FKUzzTHV1NnhRPr1M= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-KOGYvyi-Oomm6Vhjv__WFw-1; Mon, 10 Feb 2020 16:41:13 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F86418FF665; Mon, 10 Feb 2020 21:41:12 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D2285D9CA; Mon, 10 Feb 2020 21:41:12 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH 1/3] nbd: Preparation for NBD_INFO_INIT_STATE Date: Mon, 10 Feb 2020 15:41:07 -0600 Message-Id: <20200210214109.751734-2-eblake@redhat.com> In-Reply-To: <20200210214109.751734-1-eblake@redhat.com> References: <20200210214109.751734-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: KOGYvyi-Oomm6Vhjv__WFw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, rjones@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Declare the constants being proposed for an NBD extension, which will let qemu advertise/learn if an image began life with all zeroes. Signed-off-by: Eric Blake --- docs/interop/nbd.txt | 1 + include/block/nbd.h | 9 +++++++++ nbd/common.c | 2 ++ 3 files changed, 12 insertions(+) diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt index 45118809618e..35ba85367153 100644 --- a/docs/interop/nbd.txt +++ b/docs/interop/nbd.txt @@ -55,3 +55,4 @@ the operation of that feature. NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE * 4.2: NBD_FLAG_CAN_MULTI_CONN for sharable read-only exports, NBD_CMD_FLAG_FAST_ZERO +* 5.0: NBD_INFO_INIT_STATE diff --git a/include/block/nbd.h b/include/block/nbd.h index 7f46932d80f1..0de020904a37 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -200,6 +200,15 @@ enum { #define NBD_INFO_NAME 1 #define NBD_INFO_DESCRIPTION 2 #define NBD_INFO_BLOCK_SIZE 3 +#define NBD_INFO_INIT_STATE 4 + +/* Initial state bits, when replying to NBD_INFO_INIT_STATE */ +enum { + NBD_INIT_SPARSE_BIT = 0, + NBD_INIT_ZERO_BIT = 1, +}; +#define NBD_INIT_SPARSE (1 << NBD_INIT_SPARSE_BIT) +#define NBD_INIT_ZERO (1 << NBD_INIT_ZERO_BIT) /* Request flags, sent from client to server during transmission phase */ #define NBD_CMD_FLAG_FUA (1 << 0) /* 'force unit access' during write */ diff --git a/nbd/common.c b/nbd/common.c index ddfe7d118371..3e24feb0d502 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -129,6 +129,8 @@ const char *nbd_info_lookup(uint16_t info) return "description"; case NBD_INFO_BLOCK_SIZE: return "block size"; + case NBD_INFO_INIT_STATE: + return "init state"; default: return ""; } From patchwork Mon Feb 10 21:41:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 11374145 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A659192A for ; Mon, 10 Feb 2020 21:42:48 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7CB422082F for ; Mon, 10 Feb 2020 21:42:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ZTzaeOQc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CB422082F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1GpL-0007t6-IL for patchwork-qemu-devel@patchwork.kernel.org; Mon, 10 Feb 2020 16:42:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47217) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1Gnv-0006Gf-S7 for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1Gnt-0001ZT-HR for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:19 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:50717 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j1Gnt-0001W4-9I for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581370876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qduzxPa1kIn6JbRnxdn2A3uEmQeavXD90D62k3y40+Y=; b=ZTzaeOQcYNuRx74tNFxpNb7QCGq50l9lCmJkT9CUNyCsIvwghRHnkzUm5v5X6sLFMFalmn 078z5l0W4ra4pz/E+jkn5BSqpv9HLgCGhIOucVbnelh7B0Lh5b+oDa0ZjGchWi1hnLzfDU Y5xE0ONyAL/dWBxpbRI1zkyQHeB2t2U= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-186-mlpLeAe1NjqvvZKYxnhUBw-1; Mon, 10 Feb 2020 16:41:14 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73B91100550E; Mon, 10 Feb 2020 21:41:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id D867E5D9CA; Mon, 10 Feb 2020 21:41:12 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH 2/3] nbd: Add .bdrv_known_zeroes() client support Date: Mon, 10 Feb 2020 15:41:08 -0600 Message-Id: <20200210214109.751734-3-eblake@redhat.com> In-Reply-To: <20200210214109.751734-1-eblake@redhat.com> References: <20200210214109.751734-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: mlpLeAe1NjqvvZKYxnhUBw-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, rjones@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Using the new NBD extension of NBD_INFO_INIT_STATE, we can pass on the information when a server reports that an image initially reads as all zeroes. The server information is treated as stale the moment we request a write operation, even across reconnections to the server, which is fine since our intended usage of BDRV_ZERO_OPEN is to optimize qemu-img at startup, and not something relied on during later image use. Update iotests to reflect improved output of 'qemu-nbd --list'. As NBD still cannot create or resize images, we don't need to worry about BDRV_ZERO_CREATE or BDRV_ZERO_TRUNCATE. Signed-off-by: Eric Blake --- block/nbd.c | 15 +++++++++++++++ include/block/nbd.h | 4 ++++ nbd/client.c | 24 ++++++++++++++++++++---- nbd/trace-events | 1 + qemu-nbd.c | 13 +++++++++++++ tests/qemu-iotests/223.out | 4 ++++ tests/qemu-iotests/233.out | 1 + 7 files changed, 58 insertions(+), 4 deletions(-) diff --git a/block/nbd.c b/block/nbd.c index d085554f21ea..2e1fbd6152f6 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1204,6 +1204,7 @@ static int nbd_client_co_pwritev(BlockDriverState *bs, uint64_t offset, }; assert(!(s->info.flags & NBD_FLAG_READ_ONLY)); + s->info.modified = true; if (flags & BDRV_REQ_FUA) { assert(s->info.flags & NBD_FLAG_SEND_FUA); request.flags |= NBD_CMD_FLAG_FUA; @@ -1276,6 +1277,7 @@ static int nbd_client_co_pdiscard(BlockDriverState *bs, int64_t offset, }; assert(!(s->info.flags & NBD_FLAG_READ_ONLY)); + s->info.modified = true; if (!(s->info.flags & NBD_FLAG_SEND_TRIM) || !bytes) { return 0; } @@ -1909,6 +1911,16 @@ static int nbd_co_flush(BlockDriverState *bs) return nbd_client_co_flush(bs); } +static int nbd_known_zeroes(BlockDriverState *bs) +{ + BDRVNBDState *s = bs->opaque; + + if (!s->info.modified && s->info.init_state & NBD_INIT_ZERO) { + return BDRV_ZERO_OPEN; + } + return 0; +} + static void nbd_refresh_limits(BlockDriverState *bs, Error **errp) { BDRVNBDState *s = (BDRVNBDState *)bs->opaque; @@ -2027,6 +2039,7 @@ static BlockDriver bdrv_nbd = { .bdrv_close = nbd_close, .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_pdiscard = nbd_client_co_pdiscard, + .bdrv_known_zeroes = nbd_known_zeroes, .bdrv_refresh_limits = nbd_refresh_limits, .bdrv_getlength = nbd_getlength, .bdrv_detach_aio_context = nbd_client_detach_aio_context, @@ -2052,6 +2065,7 @@ static BlockDriver bdrv_nbd_tcp = { .bdrv_close = nbd_close, .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_pdiscard = nbd_client_co_pdiscard, + .bdrv_known_zeroes = nbd_known_zeroes, .bdrv_refresh_limits = nbd_refresh_limits, .bdrv_getlength = nbd_getlength, .bdrv_detach_aio_context = nbd_client_detach_aio_context, @@ -2077,6 +2091,7 @@ static BlockDriver bdrv_nbd_unix = { .bdrv_close = nbd_close, .bdrv_co_flush_to_os = nbd_co_flush, .bdrv_co_pdiscard = nbd_client_co_pdiscard, + .bdrv_known_zeroes = nbd_known_zeroes, .bdrv_refresh_limits = nbd_refresh_limits, .bdrv_getlength = nbd_getlength, .bdrv_detach_aio_context = nbd_client_detach_aio_context, diff --git a/include/block/nbd.h b/include/block/nbd.h index 0de020904a37..5103053bed49 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -307,6 +307,7 @@ struct NBDExportInfo { uint32_t min_block; uint32_t opt_block; uint32_t max_block; + uint16_t init_state; uint32_t context_id; @@ -314,6 +315,9 @@ struct NBDExportInfo { char *description; int n_contexts; char **contexts; + + /* Set during runtime to track if init_state is still trustworthy. */ + bool modified; }; typedef struct NBDExportInfo NBDExportInfo; diff --git a/nbd/client.c b/nbd/client.c index ba173108baab..199a8a2bc49e 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -350,16 +350,17 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt, assert(opt == NBD_OPT_GO || opt == NBD_OPT_INFO); trace_nbd_opt_info_go_start(nbd_opt_lookup(opt), info->name); - buf = g_malloc(4 + len + 2 + 2 * info->request_sizes + 1); + buf = g_malloc(4 + len + 2 + 2 * (info->request_sizes + 1) + 1); stl_be_p(buf, len); memcpy(buf + 4, info->name, len); - /* At most one request, everything else up to server */ - stw_be_p(buf + 4 + len, info->request_sizes); + /* One or two requests, everything else up to server */ + stw_be_p(buf + 4 + len, info->request_sizes + 1); if (info->request_sizes) { stw_be_p(buf + 4 + len + 2, NBD_INFO_BLOCK_SIZE); } + stw_be_p(buf + 4 + len + 2 + 2 * info->request_sizes, NBD_INFO_INIT_STATE); error = nbd_send_option_request(ioc, opt, - 4 + len + 2 + 2 * info->request_sizes, + 4 + len + 2 + 2 * (info->request_sizes + 1), buf, errp); g_free(buf); if (error < 0) { @@ -484,6 +485,21 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt, info->max_block); break; + case NBD_INFO_INIT_STATE: + if (len != sizeof(info->init_state)) { + error_setg(errp, "remaining export info len %" PRIu32 + " is unexpected size", len); + nbd_send_opt_abort(ioc); + return -1; + } + if (nbd_read16(ioc, &info->init_state, "info init state", + errp) < 0) { + nbd_send_opt_abort(ioc); + return -1; + } + trace_nbd_opt_info_init_state(info->init_state); + break; + default: /* * Not worth the bother to check if NBD_INFO_NAME or diff --git a/nbd/trace-events b/nbd/trace-events index a955918e9707..12589b2afb84 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -10,6 +10,7 @@ nbd_opt_info_go_start(const char *opt, const char *name) "Attempting %s for expo nbd_opt_info_go_success(const char *opt) "Export is ready after %s request" nbd_opt_info_unknown(int info, const char *name) "Ignoring unknown info %d (%s)" nbd_opt_info_block_size(uint32_t minimum, uint32_t preferred, uint32_t maximum) "Block sizes are 0x%" PRIx32 ", 0x%" PRIx32 ", 0x%" PRIx32 +nbd_opt_info_init_state(unsigned int flags) "Initial state flags 0x%x" nbd_receive_query_exports_start(const char *wantname) "Querying export list for '%s'" nbd_receive_query_exports_success(const char *wantname) "Found desired export name '%s'" nbd_receive_starttls_new_client(void) "Setting up TLS" diff --git a/qemu-nbd.c b/qemu-nbd.c index 4aa005004ebd..856df85823bc 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -220,6 +220,19 @@ static int qemu_nbd_client_list(SocketAddress *saddr, QCryptoTLSCreds *tls, printf(" opt block: %u\n", list[i].opt_block); printf(" max block: %u\n", list[i].max_block); } + { + static const char *const init_names[] = { + [NBD_INIT_SPARSE_BIT] = "sparse", + [NBD_INIT_ZERO_BIT] = "zero", + }; + printf(" init state: 0x%x (", list[i].init_state); + for (size_t bit = 0; bit < ARRAY_SIZE(init_names); bit++) { + if (init_names[bit] && (list[i].init_state & (1 << bit))) { + printf(" %s", init_names[bit]); + } + } + printf(" )\n"); + } if (list[i].n_contexts) { printf(" available meta contexts: %d\n", list[i].n_contexts); for (j = 0; j < list[i].n_contexts; j++) { diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out index 80c0cf65095b..ce7945aa7cf6 100644 --- a/tests/qemu-iotests/223.out +++ b/tests/qemu-iotests/223.out @@ -59,6 +59,7 @@ exports available: 2 min block: 1 opt block: 4096 max block: 33554432 + init state: 0x0 ( ) available meta contexts: 2 base:allocation qemu:dirty-bitmap:b @@ -69,6 +70,7 @@ exports available: 2 min block: 1 opt block: 4096 max block: 33554432 + init state: 0x0 ( ) available meta contexts: 2 base:allocation qemu:dirty-bitmap:b2 @@ -140,6 +142,7 @@ exports available: 2 min block: 1 opt block: 4096 max block: 33554432 + init state: 0x0 ( ) available meta contexts: 2 base:allocation qemu:dirty-bitmap:b @@ -150,6 +153,7 @@ exports available: 2 min block: 1 opt block: 4096 max block: 33554432 + init state: 0x0 ( ) available meta contexts: 2 base:allocation qemu:dirty-bitmap:b2 diff --git a/tests/qemu-iotests/233.out b/tests/qemu-iotests/233.out index c3c344811b2b..5be30d6b7c9c 100644 --- a/tests/qemu-iotests/233.out +++ b/tests/qemu-iotests/233.out @@ -43,6 +43,7 @@ exports available: 1 min block: 1 opt block: 4096 max block: 33554432 + init state: 0x0 ( ) available meta contexts: 1 base:allocation From patchwork Mon Feb 10 21:41:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 11374159 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 09313138D for ; Mon, 10 Feb 2020 21:44:58 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D4B7620733 for ; Mon, 10 Feb 2020 21:44:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Toti2cG6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D4B7620733 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40060 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1GrQ-0001Uc-Ur for patchwork-qemu-devel@patchwork.kernel.org; Mon, 10 Feb 2020 16:44:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:47312) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j1Gnx-0006IZ-4g for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j1Gnv-0001fk-HN for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:20 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:20459 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j1Gnv-0001dQ-4Q for qemu-devel@nongnu.org; Mon, 10 Feb 2020 16:41:19 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581370878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IoXaWJQ9EJkF7ysR6MzOzTgFk+SloGOrcr166f0CBhM=; b=Toti2cG6vjViMlLTzhY1xY7egFRTuVNJwR4qRPNEQ0fc5kK+oatYLX0YdDa/a5aVwTNEn+ n6bdgJeJJtUe/o9r45iniR9Ci2ZIFXnpm/iWVRinxJ2pIrgO0ckTW3sxd/IJ1rgZdd3ing BUjgtiEHuGbb8DHn6xATnscJyKpP3/4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-424-UkTC_Q1ZPL6xLVWz4A1lmQ-1; Mon, 10 Feb 2020 16:41:15 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 30F21DB61; Mon, 10 Feb 2020 21:41:14 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-180.phx2.redhat.com [10.3.116.180]) by smtp.corp.redhat.com (Postfix) with ESMTP id A52BB5D9CA; Mon, 10 Feb 2020 21:41:13 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH 3/3] nbd: Add .bdrv_known_zeroes() server support Date: Mon, 10 Feb 2020 15:41:09 -0600 Message-Id: <20200210214109.751734-4-eblake@redhat.com> In-Reply-To: <20200210214109.751734-1-eblake@redhat.com> References: <20200210214109.751734-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: UkTC_Q1ZPL6xLVWz4A1lmQ-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.61 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , vsementsov@virtuozzo.com, rjones@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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