From nobody Sat Apr 27 22:14:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566572016; cv=none; d=zoho.com; s=zohoarc; b=A1OPVLNZU4QYxY/2csTARhlXnTJfSxv/504inPEIONadw74YsaS8yPT5CB/FvdVfwrYB+qF1PTGG1Tpwrv1XOLin33ZyDVKYnarfsgt8+UZQeWoPmiTnstJ562dTWmIvJgictBIlXzmdoE92UhN7NmQuAmWSwEkthBWJveOb90E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566572016; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=XtI5gdP54PlDwGYrhtpG7b+ZV5eIKxP7Hp2JmQckZSo=; b=W1CVJ7S0/VqxEZiVJnjAIKWhKrmibyAUm8lkm2Rz13oLsKqCc4JbDnvy6tHkFl1VlZkhQWlzNdS5uDL6Xqur07Ef8RebALwXtpssmNWQkzRuOys1VBQNLM3TfwktWA1/Shh9ZUHCD17XPRvezH710FR/t4A7cwKi560U/OYTMgc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566572016938403.8468463088343; Fri, 23 Aug 2019 07:53:36 -0700 (PDT) Received: from localhost ([::1]:57362 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AwU-0004RJ-IW for importer@patchew.org; Fri, 23 Aug 2019 10:53:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51364) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AhB-00041p-QK for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1Ah9-0004fc-1I for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40946) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1Ah3-0004at-SQ; Fri, 23 Aug 2019 10:37:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D76D081F0F; Fri, 23 Aug 2019 14:37:32 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-234.phx2.redhat.com [10.3.116.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB27D6CE60; Fri, 23 Aug 2019 14:37:31 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 23 Aug 2019 09:37:22 -0500 Message-Id: <20190823143726.27062-2-eblake@redhat.com> In-Reply-To: <20190823143726.27062-1-eblake@redhat.com> References: <25ead363-4f37-5450-b985-1876374e314d@redhat.com> <20190823143726.27062-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 23 Aug 2019 14:37:32 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/5] nbd: Improve per-export flag handling in server 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 , Max Reitz , "open list:Network Block Dev..." , libguestfs@redhat.com, nbd@other.debian.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When creating a read-only image, we are still advertising support for TRIM and WRITE_ZEROES to the client, even though the client should not be issuing those commands. But seeing this requires looking across multiple functions: All callers to nbd_export_new() passed a single flag based solely on whether the export allows writes. Later, we then pass a constant set of flags to nbd_negotiate_options() (namely, the set of flags which we always support, at least for writable images), which is then further dynamically modified based on client requests for structured options. Finally, when processing NBD_OPT_EXPORT_NAME or NBD_OPT_EXPORT_GO we bitwise-or the original caller's flag with the runtime set of flags we've built up over several functions. Let's refactor things to instead compute a baseline of flags as soon as possible, in nbd_export_new(), and changing the signature for the callers to pass in a simpler bool rather than having to figure out flags. We can then get rid of the 'myflags' parameter to various functions, and instead refer to client for everything we need (we still have to perform a bitwise-OR during NBD_OPT_EXPORT_NAME and NBD_OPT_EXPORT_GO, but it's easier to see what is being computed). This lets us quit advertising senseless flags for read-only images, as well as making the next patch for exposing FAST_ZERO support easier to write. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/nbd.h | 2 +- blockdev-nbd.c | 3 +-- nbd/server.c | 62 +++++++++++++++++++++++++-------------------- qemu-nbd.c | 6 ++--- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 991fd52a5134..2c87b42dfd48 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -326,7 +326,7 @@ typedef struct NBDClient NBDClient; NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, uint64_t size, const char *name, const char *des= c, - const char *bitmap, uint16_t nbdflags, bool shar= ed, + const char *bitmap, bool readonly, bool shared, void (*close)(NBDExport *), bool writethrough, BlockBackend *on_eject_blk, Error **errp); void nbd_export_close(NBDExport *exp); diff --git a/blockdev-nbd.c b/blockdev-nbd.c index ecfa2ef0adb5..1cdffab4fce1 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -187,8 +187,7 @@ void qmp_nbd_server_add(const char *device, bool has_na= me, const char *name, writable =3D false; } - exp =3D nbd_export_new(bs, 0, len, name, NULL, bitmap, - writable ? 0 : NBD_FLAG_READ_ONLY, !writable, + exp =3D nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !wri= table, NULL, false, on_eject_blk, errp); if (!exp) { return; diff --git a/nbd/server.c b/nbd/server.c index 0fb41c6c50ea..b5577828aa44 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -423,14 +423,14 @@ static void nbd_check_meta_export(NBDClient *client) /* Send a reply to NBD_OPT_EXPORT_NAME. * Return -errno on error, 0 on success. */ -static int nbd_negotiate_handle_export_name(NBDClient *client, - uint16_t myflags, bool no_zero= es, +static int nbd_negotiate_handle_export_name(NBDClient *client, bool no_zer= oes, Error **errp) { char name[NBD_MAX_NAME_SIZE + 1]; char buf[NBD_REPLY_EXPORT_NAME_SIZE] =3D ""; size_t len; int ret; + uint16_t myflags; /* Client sends: [20 .. xx] export name (length bytes) @@ -458,10 +458,13 @@ static int nbd_negotiate_handle_export_name(NBDClient= *client, return -EINVAL; } - trace_nbd_negotiate_new_style_size_flags(client->exp->size, - client->exp->nbdflags | myfla= gs); + myflags =3D client->exp->nbdflags; + if (client->structured_reply) { + myflags |=3D NBD_FLAG_SEND_DF; + } + trace_nbd_negotiate_new_style_size_flags(client->exp->size, myflags); stq_be_p(buf, client->exp->size); - stw_be_p(buf + 8, client->exp->nbdflags | myflags); + stw_be_p(buf + 8, myflags); len =3D no_zeroes ? 10 : sizeof(buf); ret =3D nbd_write(client->ioc, buf, len, errp); if (ret < 0) { @@ -526,8 +529,7 @@ static int nbd_reject_length(NBDClient *client, bool fa= tal, Error **errp) /* Handle NBD_OPT_INFO and NBD_OPT_GO. * Return -errno on error, 0 if ready for next option, and 1 to move * into transmission phase. */ -static int nbd_negotiate_handle_info(NBDClient *client, uint16_t myflags, - Error **errp) +static int nbd_negotiate_handle_info(NBDClient *client, Error **errp) { int rc; char name[NBD_MAX_NAME_SIZE + 1]; @@ -540,6 +542,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= uint16_t myflags, uint32_t sizes[3]; char buf[sizeof(uint64_t) + sizeof(uint16_t)]; uint32_t check_align =3D 0; + uint16_t myflags; /* Client sends: 4 bytes: L, name length (can be 0) @@ -637,10 +640,13 @@ static int nbd_negotiate_handle_info(NBDClient *clien= t, uint16_t myflags, } /* Send NBD_INFO_EXPORT always */ - trace_nbd_negotiate_new_style_size_flags(exp->size, - exp->nbdflags | myflags); + myflags =3D exp->nbdflags; + if (client->structured_reply) { + myflags |=3D NBD_FLAG_SEND_DF; + } + trace_nbd_negotiate_new_style_size_flags(exp->size, myflags); stq_be_p(buf, exp->size); - stw_be_p(buf + 8, exp->nbdflags | myflags); + stw_be_p(buf + 8, myflags); rc =3D nbd_negotiate_send_info(client, NBD_INFO_EXPORT, sizeof(buf), buf, errp); if (rc < 0) { @@ -1037,8 +1043,7 @@ static int nbd_negotiate_meta_queries(NBDClient *clie= nt, * 1 if client sent NBD_OPT_ABORT, i.e. on valid disconnect, * errp is not set */ -static int nbd_negotiate_options(NBDClient *client, uint16_t myflags, - Error **errp) +static int nbd_negotiate_options(NBDClient *client, Error **errp) { uint32_t flags; bool fixedNewstyle =3D false; @@ -1172,13 +1177,12 @@ static int nbd_negotiate_options(NBDClient *client,= uint16_t myflags, return 1; case NBD_OPT_EXPORT_NAME: - return nbd_negotiate_handle_export_name(client, - myflags, no_zeroes, + return nbd_negotiate_handle_export_name(client, no_zeroes, errp); case NBD_OPT_INFO: case NBD_OPT_GO: - ret =3D nbd_negotiate_handle_info(client, myflags, errp); + ret =3D nbd_negotiate_handle_info(client, errp); if (ret =3D=3D 1) { assert(option =3D=3D NBD_OPT_GO); return 0; @@ -1209,7 +1213,6 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, } else { ret =3D nbd_negotiate_send_rep(client, NBD_REP_ACK, er= rp); client->structured_reply =3D true; - myflags |=3D NBD_FLAG_SEND_DF; } break; @@ -1232,8 +1235,7 @@ static int nbd_negotiate_options(NBDClient *client, u= int16_t myflags, */ switch (option) { case NBD_OPT_EXPORT_NAME: - return nbd_negotiate_handle_export_name(client, - myflags, no_zeroes, + return nbd_negotiate_handle_export_name(client, no_zeroes, errp); default: @@ -1259,9 +1261,6 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) { char buf[NBD_OLDSTYLE_NEGOTIATE_SIZE] =3D ""; int ret; - const uint16_t myflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM | - NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA | - NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_C= ACHE); /* Old style negotiation header, no room for options [ 0 .. 7] passwd ("NBDMAGIC") @@ -1289,7 +1288,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *clie= nt, Error **errp) error_prepend(errp, "write failed: "); return -EINVAL; } - ret =3D nbd_negotiate_options(client, myflags, errp); + ret =3D nbd_negotiate_options(client, errp); if (ret !=3D 0) { if (ret < 0) { error_prepend(errp, "option negotiation failed: "); @@ -1461,7 +1460,7 @@ static void nbd_eject_notifier(Notifier *n, void *dat= a) NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset, uint64_t size, const char *name, const char *des= c, - const char *bitmap, uint16_t nbdflags, bool shar= ed, + const char *bitmap, bool readonly, bool shared, void (*close)(NBDExport *), bool writethrough, BlockBackend *on_eject_blk, Error **errp) { @@ -1485,10 +1484,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint= 64_t dev_offset, /* Don't allow resize while the NBD server is running, otherwise we do= n't * care what happens with the node. */ perm =3D BLK_PERM_CONSISTENT_READ; - if ((nbdflags & NBD_FLAG_READ_ONLY) =3D=3D 0) { + if (!readonly) { perm |=3D BLK_PERM_WRITE; - } else if (shared) { - nbdflags |=3D NBD_FLAG_CAN_MULTI_CONN; } blk =3D blk_new(bdrv_get_aio_context(bs), perm, BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED | @@ -1507,7 +1504,16 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint= 64_t dev_offset, exp->dev_offset =3D dev_offset; exp->name =3D g_strdup(name); exp->description =3D g_strdup(desc); - exp->nbdflags =3D nbdflags; + exp->nbdflags =3D (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_FLUSH | + NBD_FLAG_SEND_FUA | NBD_FLAG_SEND_CACHE); + if (readonly) { + exp->nbdflags |=3D NBD_FLAG_READ_ONLY; + if (shared) { + exp->nbdflags |=3D NBD_FLAG_CAN_MULTI_CONN; + } + } else { + exp->nbdflags |=3D NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROES; + } assert(size <=3D INT64_MAX - dev_offset); exp->size =3D QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); @@ -1532,7 +1538,7 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint6= 4_t dev_offset, goto fail; } - if ((nbdflags & NBD_FLAG_READ_ONLY) && bdrv_is_writable(bs) && + if (readonly && bdrv_is_writable(bs) && bdrv_dirty_bitmap_enabled(bm)) { error_setg(errp, "Enabled bitmap '%s' incompatible with readonly exp= ort", diff --git a/qemu-nbd.c b/qemu-nbd.c index 55f5ceaf5c92..079702bb837f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -600,7 +600,7 @@ int main(int argc, char **argv) BlockBackend *blk; BlockDriverState *bs; uint64_t dev_offset =3D 0; - uint16_t nbdflags =3D 0; + bool readonly =3D false; bool disconnect =3D false; const char *bindto =3D NULL; const char *port =3D NULL; @@ -782,7 +782,7 @@ int main(int argc, char **argv) } /* fall through */ case 'r': - nbdflags |=3D NBD_FLAG_READ_ONLY; + readonly =3D true; flags &=3D ~BDRV_O_RDWR; break; case 'P': @@ -1173,7 +1173,7 @@ int main(int argc, char **argv) } export =3D nbd_export_new(bs, dev_offset, fd_size, export_name, - export_description, bitmap, nbdflags, shared >= 1, + export_description, bitmap, readonly, shared >= 1, nbd_export_closed, writethrough, NULL, &error_fatal); --=20 2.21.0 From nobody Sat Apr 27 22:14:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566571952; cv=none; d=zoho.com; s=zohoarc; b=CdQjuQGQhVrQuOzbpAOBqx4HlQotmsCQ2NcCzdRImar2ZKdTrj6EqMAYyhN1E+W7EVMscJA2hmKSLZBZGYcZcFltDwFV+QD13AaTZOAJAYhBhctWx9QoDMA9O2QluxVIZIVC0ARS1D7gh1mXx/AuFju/2AsFgnDk0tt/dY8XYbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566571952; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9htmioNWA3yQFnkDT0sT3llhQIMwlpPbj0ePAHahyJg=; b=KH6jfWo9D+cedvfARbBGUIAb+fbqhGnn8OSks1cQHWcsPXwwDWllDTIvYZdhVNiIa1LDus7gQNvXiL7Dl/oQKxC7ECSJY6yfHEkcu/azlOnIC0QwOS9Egq9bAYKOekLMYPyXIlyrzAclRa1RMQGi6shZtfkl/RMlMGDpsgFxqtc= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566571952697123.11234393906363; Fri, 23 Aug 2019 07:52:32 -0700 (PDT) Received: from localhost ([::1]:57342 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AvX-00033T-6j for importer@patchew.org; Fri, 23 Aug 2019 10:52:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51430) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AhE-00045S-QP for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1AhD-0004i4-Ce for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57886) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1Ah4-0004bU-Ft; Fri, 23 Aug 2019 10:37:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 91B882A09D4; Fri, 23 Aug 2019 14:37:33 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-234.phx2.redhat.com [10.3.116.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14EA66CE58; Fri, 23 Aug 2019 14:37:33 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 23 Aug 2019 09:37:23 -0500 Message-Id: <20190823143726.27062-3-eblake@redhat.com> In-Reply-To: <20190823143726.27062-1-eblake@redhat.com> References: <25ead363-4f37-5450-b985-1876374e314d@redhat.com> <20190823143726.27062-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 23 Aug 2019 14:37:33 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/5] nbd: Prepare for NBD_CMD_FLAG_FAST_ZERO 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 , Max Reitz , "open list:Network Block Dev..." , libguestfs@redhat.com, nbd@other.debian.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Commit fe0480d6 and friends added BDRV_REQ_NO_FALLBACK as a way to avoid wasting time on a preliminary write-zero request that will later be rewritten by actual data, if it is known that the write-zero request will use a slow fallback; but in doing so, could not optimize for NBD. The NBD specification is now considering an extension that will allow passing on those semantics; this patch updates the new protocol bits and 'qemu-nbd --list' output to recognize the bit, as well as the new errno value possible when using the new flag; while upcoming patches will improve the client to use the feature when present, and the server to advertise support for it. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/interop/nbd.txt | 3 ++- include/block/nbd.h | 4 ++++ nbd/common.c | 5 +++++ nbd/server.c | 2 ++ qemu-nbd.c | 1 + 5 files changed, 14 insertions(+), 1 deletion(-) diff --git a/docs/interop/nbd.txt b/docs/interop/nbd.txt index 6dfec7f47647..45118809618e 100644 --- a/docs/interop/nbd.txt +++ b/docs/interop/nbd.txt @@ -53,4 +53,5 @@ the operation of that feature. * 2.12: NBD_CMD_BLOCK_STATUS for "base:allocation" * 3.0: NBD_OPT_STARTTLS with TLS Pre-Shared Keys (PSK), NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE -* 4.2: NBD_FLAG_CAN_MULTI_CONN for sharable read-only exports +* 4.2: NBD_FLAG_CAN_MULTI_CONN for sharable read-only exports, +NBD_CMD_FLAG_FAST_ZERO diff --git a/include/block/nbd.h b/include/block/nbd.h index 2c87b42dfd48..21550747cf35 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -140,6 +140,7 @@ enum { NBD_FLAG_CAN_MULTI_CONN_BIT =3D 8, /* Multi-client cache consiste= nt */ NBD_FLAG_SEND_RESIZE_BIT =3D 9, /* Send resize */ NBD_FLAG_SEND_CACHE_BIT =3D 10, /* Send CACHE (prefetch) */ + NBD_FLAG_SEND_FAST_ZERO_BIT =3D 11, /* FAST_ZERO flag for WRITE_ZE= ROES */ }; #define NBD_FLAG_HAS_FLAGS (1 << NBD_FLAG_HAS_FLAGS_BIT) @@ -153,6 +154,7 @@ enum { #define NBD_FLAG_CAN_MULTI_CONN (1 << NBD_FLAG_CAN_MULTI_CONN_BIT) #define NBD_FLAG_SEND_RESIZE (1 << NBD_FLAG_SEND_RESIZE_BIT) #define NBD_FLAG_SEND_CACHE (1 << NBD_FLAG_SEND_CACHE_BIT) +#define NBD_FLAG_SEND_FAST_ZERO (1 << NBD_FLAG_SEND_FAST_ZERO_BIT) /* New-style handshake (global) flags, sent from server to client, and control what will happen during handshake phase. */ @@ -205,6 +207,7 @@ enum { #define NBD_CMD_FLAG_DF (1 << 2) /* don't fragment structured read= */ #define NBD_CMD_FLAG_REQ_ONE (1 << 3) /* only one extent in BLOCK_STATUS * reply chunk */ +#define NBD_CMD_FLAG_FAST_ZERO (1 << 4) /* fail if WRITE_ZEROES is not fa= st */ /* Supported request types */ enum { @@ -270,6 +273,7 @@ static inline bool nbd_reply_type_is_error(int type) #define NBD_EINVAL 22 #define NBD_ENOSPC 28 #define NBD_EOVERFLOW 75 +#define NBD_ENOTSUP 95 #define NBD_ESHUTDOWN 108 /* Details collected by NBD_OPT_EXPORT_NAME and NBD_OPT_GO */ diff --git a/nbd/common.c b/nbd/common.c index cc8b278e541d..ddfe7d118371 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -201,6 +201,8 @@ const char *nbd_err_lookup(int err) return "ENOSPC"; case NBD_EOVERFLOW: return "EOVERFLOW"; + case NBD_ENOTSUP: + return "ENOTSUP"; case NBD_ESHUTDOWN: return "ESHUTDOWN"; default: @@ -231,6 +233,9 @@ int nbd_errno_to_system_errno(int err) case NBD_EOVERFLOW: ret =3D EOVERFLOW; break; + case NBD_ENOTSUP: + ret =3D ENOTSUP; + break; case NBD_ESHUTDOWN: ret =3D ESHUTDOWN; break; diff --git a/nbd/server.c b/nbd/server.c index b5577828aa44..981bc3cb1151 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -55,6 +55,8 @@ static int system_errno_to_nbd_errno(int err) return NBD_ENOSPC; case EOVERFLOW: return NBD_EOVERFLOW; + case ENOTSUP: + return NBD_ENOTSUP; case ESHUTDOWN: return NBD_ESHUTDOWN; case EINVAL: diff --git a/qemu-nbd.c b/qemu-nbd.c index 079702bb837f..dce52f564b5a 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -294,6 +294,7 @@ static int qemu_nbd_client_list(SocketAddress *saddr, Q= CryptoTLSCreds *tls, [NBD_FLAG_CAN_MULTI_CONN_BIT] =3D "multi", [NBD_FLAG_SEND_RESIZE_BIT] =3D "resize", [NBD_FLAG_SEND_CACHE_BIT] =3D "cache", + [NBD_FLAG_SEND_FAST_ZERO_BIT] =3D "fast-zero", }; printf(" size: %" PRIu64 "\n", list[i].size); --=20 2.21.0 From nobody Sat Apr 27 22:14:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566571793; cv=none; d=zoho.com; s=zohoarc; b=CuFRAu1C5ewaaIUHMTHMRbaBQMzVtALeuBDhzQtoRtwOjGNto0L2yFbm9+8pCTu/JGpSxqT9hx3zhFV+f7yWc3EdvCER+gN6cVe0JSQvHWHxSfTsMu2OO2KKiCWcnxic1QTNqmcuLUJ9gajtWi1vC+wQFxX84PhpbBSLbWZBtEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566571793; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=14DuT2U3s5EJez8YgqrkKLnSxjYB0AR3PzsF78nHOiM=; b=fw3MlojIVCLlFuKfKRu7SpmYI+0ddx217tLcxYDXpGs9uXcO9gE4RZt63maow3FdtLW/T4uhUNK21gPf1C5jNgYRiNrjxxrHXtJTQkanRP/8vp+O289DiQ/OG1q5L6boWbhAQMecOvQracFhrxFU1Qk1lqcd+50bOjgFZzzOYj4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156657179345456.93463922399451; Fri, 23 Aug 2019 07:49:53 -0700 (PDT) Received: from localhost ([::1]:57278 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1Asx-00088F-B6 for importer@patchew.org; Fri, 23 Aug 2019 10:49:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51386) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AhD-00043I-0T for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1AhB-0004gt-Vx for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44266) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1Ah6-0004dc-S6; Fri, 23 Aug 2019 10:37:36 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 462F989AC9; Fri, 23 Aug 2019 14:37:36 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-234.phx2.redhat.com [10.3.116.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id BC1856CE58; Fri, 23 Aug 2019 14:37:33 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 23 Aug 2019 09:37:24 -0500 Message-Id: <20190823143726.27062-4-eblake@redhat.com> In-Reply-To: <20190823143726.27062-1-eblake@redhat.com> References: <25ead363-4f37-5450-b985-1876374e314d@redhat.com> <20190823143726.27062-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 23 Aug 2019 14:37:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/5] nbd: Implement client use of NBD FAST_ZERO 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 , Max Reitz , "open list:Network Block Dev..." , libguestfs@redhat.com, nbd@other.debian.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The client side is fairly straightforward: if the server advertised fast zero support, then we can map that to BDRV_REQ_NO_FALLBACK support. A server that advertises FAST_ZERO but not WRITE_ZEROES is technically broken, but we can ignore that situation as it does not change our behavior. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- Perhaps this is worth merging with the previous patch. --- block/nbd.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/nbd.c b/block/nbd.c index beed46fb3414..8339d7106366 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1044,6 +1044,10 @@ static int nbd_client_co_pwrite_zeroes(BlockDriverSt= ate *bs, int64_t offset, if (!(flags & BDRV_REQ_MAY_UNMAP)) { request.flags |=3D NBD_CMD_FLAG_NO_HOLE; } + if (flags & BDRV_REQ_NO_FALLBACK) { + assert(s->info.flags & NBD_FLAG_SEND_FAST_ZERO); + request.flags |=3D NBD_CMD_FLAG_FAST_ZERO; + } if (!bytes) { return 0; @@ -1239,6 +1243,9 @@ static int nbd_client_connect(BlockDriverState *bs, E= rror **errp) } if (s->info.flags & NBD_FLAG_SEND_WRITE_ZEROES) { bs->supported_zero_flags |=3D BDRV_REQ_MAY_UNMAP; + if (s->info.flags & NBD_FLAG_SEND_FAST_ZERO) { + bs->supported_zero_flags |=3D BDRV_REQ_NO_FALLBACK; + } } s->sioc =3D sioc; --=20 2.21.0 From nobody Sat Apr 27 22:14:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566571744; cv=none; d=zoho.com; s=zohoarc; b=IGIhIHMYHBRdsq+Twi3UJ0da+ZfbqLrIvd/TDPSFgV53fsu0iCJx5uIqxE+AYTMkVTu6tj11VhIUM8g6zLce4kCmnOBtgh5f6xjsTunnXVoPyBoleQeBQvyFKHL1bm+FOSQUNfArPpszp2K8EQQJHNpp0VPtv2LMqB4se9quivI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566571744; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=NTROhoa7E27VS9ABE0Odo4PMn0Tr2Hc2Wurp15+qwN0=; b=BkotjxI2cMGJ83UPV3wyFw1bD8CZ0R7E5CZQ9fyXkunYvZGOVVSMSXwJUKTZi8jWXFI+F6rJ2WY38vKGfwzvGHCJ09ZzFUc9nHjiLzsHstZrWr45LnlRYPIegM1por/3wzu2j5bJye36gFLbHN6ATU0sAa/mNDqCmN7dTjTKEO8= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566571744519498.83660946792577; Fri, 23 Aug 2019 07:49:04 -0700 (PDT) Received: from localhost ([::1]:57270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AsA-00075q-LI for importer@patchew.org; Fri, 23 Aug 2019 10:49:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51454) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AhG-00046Z-1X for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1AhE-0004jc-RL for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54338) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1AhB-0004eH-Un; Fri, 23 Aug 2019 10:37:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CFDC718C8910; Fri, 23 Aug 2019 14:37:36 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-234.phx2.redhat.com [10.3.116.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6FB126CE58; Fri, 23 Aug 2019 14:37:36 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 23 Aug 2019 09:37:25 -0500 Message-Id: <20190823143726.27062-5-eblake@redhat.com> In-Reply-To: <20190823143726.27062-1-eblake@redhat.com> References: <25ead363-4f37-5450-b985-1876374e314d@redhat.com> <20190823143726.27062-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.70]); Fri, 23 Aug 2019 14:37:36 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/5] nbd: Implement server use of NBD FAST_ZERO 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: "open list:Network Block Dev..." , libguestfs@redhat.com, nbd@other.debian.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The server side is fairly straightforward: we can always advertise support for detection of fast zero, and implement it by mapping the request to the block layer BDRV_REQ_NO_FALLBACK. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- Again, this may be worth merging with the previous patch. --- nbd/server.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 981bc3cb1151..3c0799eda87f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1514,7 +1514,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint6= 4_t dev_offset, exp->nbdflags |=3D NBD_FLAG_CAN_MULTI_CONN; } } else { - exp->nbdflags |=3D NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROES; + exp->nbdflags |=3D (NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROE= S | + NBD_FLAG_SEND_FAST_ZERO); } assert(size <=3D INT64_MAX - dev_offset); exp->size =3D QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE); @@ -2167,7 +2168,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, if (request->type =3D=3D NBD_CMD_READ && client->structured_reply) { valid_flags |=3D NBD_CMD_FLAG_DF; } else if (request->type =3D=3D NBD_CMD_WRITE_ZEROES) { - valid_flags |=3D NBD_CMD_FLAG_NO_HOLE; + valid_flags |=3D NBD_CMD_FLAG_NO_HOLE | NBD_CMD_FLAG_FAST_ZERO; } else if (request->type =3D=3D NBD_CMD_BLOCK_STATUS) { valid_flags |=3D NBD_CMD_FLAG_REQ_ONE; } @@ -2306,6 +2307,9 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, if (!(request->flags & NBD_CMD_FLAG_NO_HOLE)) { flags |=3D BDRV_REQ_MAY_UNMAP; } + if (request->flags & NBD_CMD_FLAG_FAST_ZERO) { + flags |=3D BDRV_REQ_NO_FALLBACK; + } ret =3D blk_pwrite_zeroes(exp->blk, request->from + exp->dev_offse= t, request->len, flags); return nbd_send_generic_reply(client, request->handle, ret, --=20 2.21.0 From nobody Sat Apr 27 22:14:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566571916; cv=none; d=zoho.com; s=zohoarc; b=jja2vKIV71zNDlPP5PIgIRpiTqlMcq6nzr5GgD6XbwmDV1fUfC0lkiE7PQqGbmwvzljGXNJ3jbmMolsdHUHiDybmvba2OYxUSNMXMX6ZE9vBxhSSwcWIYVSnnt5Tt89dwV0u1GIs3WWOiQFgNvhycGjRKhcws6E8oINnkTLbfQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566571916; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Izkje2QhqJedy3yTOle9tuEelOyabZIYDB6MJ/nphg4=; b=OokNkBUZv8bFmdQX8UsVjm/8WQ52qwkINfx4us4tBigcTif0hr3CJTVsAy/aIFxf8vuQcNQW3XtvXDj31FlByt3bmFTGMaSxJYjNp0hLPfeM93LVc0GE21gbI49Aa67cvzshf5mL0U74FGO14UyeQo1y0PgrZOv4bPgmZ7B18oI= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566571916783981.2655660391036; Fri, 23 Aug 2019 07:51:56 -0700 (PDT) Received: from localhost ([::1]:57336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1Aux-0002Lj-E1 for importer@patchew.org; Fri, 23 Aug 2019 10:51:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51472) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i1AhG-00047Q-RK for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i1AhF-0004k2-AZ for qemu-devel@nongnu.org; Fri, 23 Aug 2019 10:37:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42308) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i1AhB-0004ek-Vs; Fri, 23 Aug 2019 10:37:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B74E106E289; Fri, 23 Aug 2019 14:37:37 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-234.phx2.redhat.com [10.3.116.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 079B16CE5B; Fri, 23 Aug 2019 14:37:36 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 23 Aug 2019 09:37:26 -0500 Message-Id: <20190823143726.27062-6-eblake@redhat.com> In-Reply-To: <20190823143726.27062-1-eblake@redhat.com> References: <25ead363-4f37-5450-b985-1876374e314d@redhat.com> <20190823143726.27062-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Fri, 23 Aug 2019 14:37:37 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/5] nbd: Tolerate more errors to structured reply request 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: "open list:Network Block Dev..." , libguestfs@redhat.com, nbd@other.debian.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A server may have a reason to reject a request for structured replies, beyond just not recognizing them as a valid request. It doesn't hurt us to continue talking to such a server; otherwise 'qemu-nbd --list' of such a server fails to display all possible details about the export. Encountered when temporarily tweaking nbdkit to reply with NBD_REP_ERR_POLICY. Present since structured reply support was first added (commit d795299b reused starttls handling, but starttls has to reject all errors). Signed-off-by: Eric Blake --- nbd/client.c | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 49bf9906f94b..92444f5e9a62 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2018 Red Hat, Inc. + * Copyright (C) 2016-2019 Red Hat, Inc. * Copyright (C) 2005 Anthony Liguori * * Network Block Device Client Side @@ -142,17 +142,19 @@ static int nbd_receive_option_reply(QIOChannel *ioc, = uint32_t opt, return 0; } -/* If reply represents success, return 1 without further action. - * If reply represents an error, consume the optional payload of - * the packet on ioc. Then return 0 for unsupported (so the client - * can fall back to other approaches), or -1 with errp set for other - * errors. +/* + * If reply represents success, return 1 without further action. If + * reply represents an error, consume the optional payload of the + * packet on ioc. Then return 0 for unsupported (so the client can + * fall back to other approaches), where @strict determines if only + * ERR_UNSUP or all errors fit that category, or -1 with errp set for + * other errors. */ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply, - Error **errp) + bool strict, Error **errp) { char *msg =3D NULL; - int result =3D -1; + int result =3D strict ? -1 : 0; if (!(reply->type & (1 << 31))) { return 1; @@ -163,6 +165,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOpt= ionReply *reply, error_setg(errp, "server error %" PRIu32 " (%s) message is too long", reply->type, nbd_rep_lookup(reply->type)); + result =3D -1; goto cleanup; } msg =3D g_malloc(reply->length + 1); @@ -170,6 +173,7 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOpt= ionReply *reply, error_prepend(errp, "Failed to read option error %" PRIu32 " (%s) message: ", reply->type, nbd_rep_lookup(reply->type)); + result =3D -1; goto cleanup; } msg[reply->length] =3D '\0'; @@ -258,7 +262,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **nam= e, char **description, if (nbd_receive_option_reply(ioc, NBD_OPT_LIST, &reply, errp) < 0) { return -1; } - error =3D nbd_handle_reply_err(ioc, &reply, errp); + error =3D nbd_handle_reply_err(ioc, &reply, true, errp); if (error <=3D 0) { return error; } @@ -371,7 +375,7 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t= opt, if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) { return -1; } - error =3D nbd_handle_reply_err(ioc, &reply, errp); + error =3D nbd_handle_reply_err(ioc, &reply, true, errp); if (error <=3D 0) { return error; } @@ -546,12 +550,15 @@ static int nbd_receive_query_exports(QIOChannel *ioc, } } -/* nbd_request_simple_option: Send an option request, and parse the reply +/* + * nbd_request_simple_option: Send an option request, and parse the reply. + * @strict controls whether ERR_UNSUP or all errors produce 0 status. * return 1 for successful negotiation, * 0 if operation is unsupported, * -1 with errp set for any other error */ -static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **err= p) +static int nbd_request_simple_option(QIOChannel *ioc, int opt, bool strict, + Error **errp) { NBDOptionReply reply; int error; @@ -563,7 +570,7 @@ static int nbd_request_simple_option(QIOChannel *ioc, i= nt opt, Error **errp) if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) { return -1; } - error =3D nbd_handle_reply_err(ioc, &reply, errp); + error =3D nbd_handle_reply_err(ioc, &reply, strict, errp); if (error <=3D 0) { return error; } @@ -595,7 +602,7 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc, QIOChannelTLS *tioc; struct NBDTLSHandshakeData data =3D { 0 }; - ret =3D nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp); + ret =3D nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, true, errp); if (ret <=3D 0) { if (ret =3D=3D 0) { error_setg(errp, "Server don't support STARTTLS option"); @@ -695,7 +702,7 @@ static int nbd_receive_one_meta_context(QIOChannel *ioc, return -1; } - ret =3D nbd_handle_reply_err(ioc, &reply, errp); + ret =3D nbd_handle_reply_err(ioc, &reply, true, errp); if (ret <=3D 0) { return ret; } @@ -951,7 +958,7 @@ static int nbd_start_negotiate(AioContext *aio_context,= QIOChannel *ioc, if (structured_reply) { result =3D nbd_request_simple_option(ioc, NBD_OPT_STRUCTURED_REPL= Y, - errp); + false, errp); if (result < 0) { return -EINVAL; } --=20 2.21.0