From nobody Wed Feb 11 01:09:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1691689513; cv=none; d=zohomail.com; s=zohoarc; b=Pbrf14HtAxeqDv6S1Ph3cZUHy7U3dUlJUVG+cc1hGBBcZ8dXFT/iHhq9cqz58ePtEm0L9hqmiACtRtm2dlPNsC3qcoX/K5c2XaYqzalCFHtd/GxFGNdFfXLo18Fyni+YymzF8zW8wpM7Bk3EUU3apqr/5Zk37ueOywFC/IUQsI4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691689513; h=Content-Type: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; bh=QHWVZIHcN+/7rfuhrD6+hjs10SsK8o54ib/jDyxF9aM=; b=ewjWwQD6IsLcem9VP7ZTZLEXqmi1LEasHIMqFl7HE5WQdnc6QCu8mQtLCrsAXqdZhowmGWwQJ/gHkgExJE0qf1cC6tjl7FBKKabT3v0nN9tMoI2TtEO2Q4ekIIlq7ym2JRIjd8FpDP6MuzJ4FKMtsGT5l4Tml8QuVyk6SsaNvok= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1691689513646280.54699743746005; Thu, 10 Aug 2023 10:45:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qU9g4-0003uH-5z; Thu, 10 Aug 2023 13:42:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qU9g3-0003tA-G2 for qemu-devel@nongnu.org; Thu, 10 Aug 2023 13:42:27 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qU9g1-0004xv-5E for qemu-devel@nongnu.org; Thu, 10 Aug 2023 13:42:27 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-QSGM9jS9OGyORmYzEDYlWw-1; Thu, 10 Aug 2023 13:42:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6D7758DC66D; Thu, 10 Aug 2023 17:42:22 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.169]) by smtp.corp.redhat.com (Postfix) with ESMTP id 196A21121314; Thu, 10 Aug 2023 17:42:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1691689344; 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=QHWVZIHcN+/7rfuhrD6+hjs10SsK8o54ib/jDyxF9aM=; b=M36hmoYEObit8M7vdeZ9MPJSva48HJmlkN2CMWiSKBkNHfr6+6GzGuEa/k8i6z22Ho7WOR ZWOH68lHXPHT8V0V0Nu+rXCEDf742yVFqMmRC1Qsrz7UwJ2zzHMeucUs7BafrGA1qASF29 eHAhN0M+DBYnJ1dG3Ewtw1cbe/oxFcM= X-MC-Unique: QSGM9jS9OGyORmYzEDYlWw-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, vsementsov@yandex-team.ru Subject: [PATCH v5 06/17] nbd/server: Support a request payload Date: Thu, 10 Aug 2023 12:36:53 -0500 Message-ID: <20230810173646.17695-25-eblake@redhat.com> In-Reply-To: <20230810173646.17695-19-eblake@redhat.com> References: <20230810173646.17695-19-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1691689515803100003 Content-Type: text/plain; charset="utf-8" Upcoming additions to support NBD 64-bit effect lengths allow for the possibility to distinguish between payload length (capped at 32M) and effect length (64 bits, although we generally assume 63 bits because of off_t limitations). Without that extension, only the NBD_CMD_WRITE request has a payload; but with the extension, it makes sense to allow at least NBD_CMD_BLOCK_STATUS to have both a payload and effect length in a future patch (where the payload is a limited-size struct that in turn gives the real effect length as well as a subset of known ids for which status is requested). Other future NBD commands may also have a request payload, so the 64-bit extension introduces a new NBD_CMD_FLAG_PAYLOAD_LEN that distinguishes between whether the header length is a payload length or an effect length, rather than hard-coding the decision based on the command; although a client should never send a command with a payload without the negotiation phase proving such extension is available, we are now able to gracefully fail unexpected client payloads while keeping the connection alive. Note that we do not support the payload version of BLOCK_STATUS yet. Signed-off-by: Eric Blake --- v5: retitled from v4 13/24, rewrite on top of previous patch's switch statement [Vladimir] v4: less indentation on several 'if's [Vladimir] --- nbd/server.c | 33 ++++++++++++++++++++++++++++----- nbd/trace-events | 1 + 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 795f7c86781..9b7fb3c55ae 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2334,7 +2334,8 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, Error **errp) { NBDClient *client =3D req->client; - bool check_length =3D false; + bool extended_with_payload; + bool check_length; bool check_rofs =3D false; bool allocate_buffer =3D false; unsigned payload_len =3D 0; @@ -2350,6 +2351,9 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, trace_nbd_co_receive_request_decode_type(request->cookie, request->typ= e, nbd_cmd_lookup(request->type)= ); + check_length =3D extended_with_payload =3D client->mode >=3D NBD_MODE_= EXTENDED && + request->flags & NBD_CMD_FLAG_PAYLOAD_LEN; + switch (request->type) { case NBD_CMD_DISC: /* Special case: we're going to disconnect without a reply, @@ -2366,6 +2370,14 @@ static int coroutine_fn nbd_co_receive_request(NBDRe= questData *req, break; case NBD_CMD_WRITE: + if (client->mode >=3D NBD_MODE_EXTENDED) { + if (!extended_with_payload) { + /* The client is noncompliant. Trace it, but proceed. */ + trace_nbd_co_receive_ext_payload_compliance(request->from, + request->len); + } + valid_flags |=3D NBD_CMD_FLAG_PAYLOAD_LEN; + } payload_len =3D request->len; check_length =3D true; allocate_buffer =3D true; @@ -2407,6 +2419,15 @@ static int coroutine_fn nbd_co_receive_request(NBDRe= questData *req, request->len, NBD_MAX_BUFFER_SIZE); return -EINVAL; } + if (extended_with_payload && !allocate_buffer) { + /* + * For now, we don't support payloads on other commands; but + * we can keep the connection alive by ignoring the payload. + */ + assert(request->type !=3D NBD_CMD_WRITE); + payload_len =3D request->len; + request->len =3D 0; + } if (allocate_buffer) { /* READ, WRITE */ req->data =3D blk_try_blockalign(client->exp->common.blk, @@ -2417,10 +2438,12 @@ static int coroutine_fn nbd_co_receive_request(NBDR= equestData *req, } } if (payload_len) { - /* WRITE */ - assert(req->data); - ret =3D nbd_read(client->ioc, req->data, payload_len, - "CMD_WRITE data", errp); + if (req->data) { + ret =3D nbd_read(client->ioc, req->data, payload_len, + "CMD_WRITE data", errp); + } else { + ret =3D nbd_drop(client->ioc, payload_len, errp); + } if (ret < 0) { return -EIO; } diff --git a/nbd/trace-events b/nbd/trace-events index f9dccfcfb44..c1a3227613f 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -71,6 +71,7 @@ nbd_co_send_extents(uint64_t cookie, unsigned int extents= , uint32_t id, uint64_t nbd_co_send_chunk_error(uint64_t cookie, int err, const char *errname, con= st char *msg) "Send structured error reply: cookie =3D %" PRIu64 ", error = =3D %d (%s), msg =3D '%s'" nbd_co_receive_request_decode_type(uint64_t cookie, uint16_t type, const c= har *name) "Decoding type: cookie =3D %" PRIu64 ", type =3D %" PRIu16 " (%s= )" nbd_co_receive_request_payload_received(uint64_t cookie, uint64_t len) "Pa= yload received: cookie =3D %" PRIu64 ", len =3D %" PRIu64 +nbd_co_receive_ext_payload_compliance(uint64_t from, uint64_t len) "client= sent non-compliant write without payload flag: from=3D0x%" PRIx64 ", len= =3D0x%" PRIx64 nbd_co_receive_align_compliance(const char *op, uint64_t from, uint64_t le= n, uint32_t align) "client sent non-compliant unaligned %s request: from=3D= 0x%" PRIx64 ", len=3D0x%" PRIx64 ", align=3D0x%" PRIx32 nbd_trip(void) "Reading request" --=20 2.41.0