From nobody Tue Feb 10 07:40:53 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1638574919706530.7759835998487; Fri, 3 Dec 2021 15:41:59 -0800 (PST) Received: from localhost ([::1]:38288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mtIBi-0001lM-O0 for importer@patchew.org; Fri, 03 Dec 2021 18:41:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mtHoa-0002IX-HJ for qemu-devel@nongnu.org; Fri, 03 Dec 2021 18:18:04 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:25573) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mtHoX-0003Jc-Gu for qemu-devel@nongnu.org; Fri, 03 Dec 2021 18:18:04 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-wf9M9K8FNV6NjBdTz1VFkw-1; Fri, 03 Dec 2021 18:17:58 -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 CA0DA801B26; Fri, 3 Dec 2021 23:17:56 +0000 (UTC) Received: from blue.redhat.com (unknown [10.2.16.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id E932EADD5; Fri, 3 Dec 2021 23:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638573481; 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=68wLFDmhwgI93GM09cg1fWteej9OMa60cYVzyX0BSaI=; b=Ur881y4bIbBTrbxAmoVr8n+jXn/YYYabVj3kZQjY/rBMtbWmkB/UQLqxJaR+lrqsu6izEf qArPQZhPDG0Z7XhJoos6qftCoBEaO8gADHJzgWtBnvAgFupP3vita6yT4ndwcXCujzKTR/ iWoi3u6gwWBPVZ/sZXjrUOs7h0Z6/8Q= X-MC-Unique: wf9M9K8FNV6NjBdTz1VFkw-1 From: Eric Blake To: libguestfs@redhat.com Subject: [libnbd PATCH 04/13] protocol: Prepare to send 64-bit requests Date: Fri, 3 Dec 2021 17:17:32 -0600 Message-Id: <20211203231741.3901263-5-eblake@redhat.com> In-Reply-To: <20211203231741.3901263-1-eblake@redhat.com> References: <20211203231307.wmtbw7r72tyzkkax@redhat.com> <20211203231741.3901263-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.717, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=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: , Cc: nsoffer@redhat.com, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, qemu-block@nongnu.org, nbd@other.debian.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1638574921933100001 Content-Type: text/plain; charset="utf-8" Support sending 64-bit requests if extended headers were negotiated. At this point, h->extended_headers is permanently false (we can't enable it until all other aspects of the protocol have likewise been converted). --- lib/internal.h | 12 ++++++++--- generator/states-issue-command.c | 31 +++++++++++++++++++---------- generator/states-reply-structured.c | 2 +- lib/rw.c | 10 ++++------ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lib/internal.h b/lib/internal.h index 7e96e8e9..07378588 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -1,5 +1,5 @@ /* nbd client library in userspace: internal definitions - * Copyright (C) 2013-2020 Red Hat Inc. + * Copyright (C) 2013-2021 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -106,6 +106,9 @@ struct nbd_handle { char *tls_username; /* Username, NULL =3D use current username= */ char *tls_psk_file; /* PSK filename, NULL =3D no PSK */ + /* Extended headers. */ + bool extended_headers; /* If we negotiated NBD_OPT_EXTENDED_HEADE= RS */ + /* Desired metadata contexts. */ bool request_sr; string_vector request_meta_contexts; @@ -242,7 +245,10 @@ struct nbd_handle { /* Issuing a command must use a buffer separate from sbuf, for the * case when we interrupt a request to service a reply. */ - struct nbd_request request; + union { + struct nbd_request request; + struct nbd_request_ext request_ext; + } req; bool in_write_payload; bool in_write_shutdown; @@ -347,7 +353,7 @@ struct command { uint16_t type; uint64_t cookie; uint64_t offset; - uint32_t count; + uint64_t count; void *data; /* Buffer for read/write */ struct command_cb cb; enum state state; /* State to resume with on next POLLIN */ diff --git a/generator/states-issue-command.c b/generator/states-issue-comm= and.c index a8101144..7b1d6dc7 100644 --- a/generator/states-issue-command.c +++ b/generator/states-issue-command.c @@ -1,5 +1,5 @@ /* nbd client library in userspace: state machine - * Copyright (C) 2013-2020 Red Hat Inc. + * Copyright (C) 2013-2021 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -41,14 +41,23 @@ STATE_MACHINE { return 0; } - h->request.magic =3D htobe32 (NBD_REQUEST_MAGIC); - h->request.flags =3D htobe16 (cmd->flags); - h->request.type =3D htobe16 (cmd->type); - h->request.handle =3D htobe64 (cmd->cookie); - h->request.offset =3D htobe64 (cmd->offset); - h->request.count =3D htobe32 ((uint32_t) cmd->count); - h->wbuf =3D &h->request; - h->wlen =3D sizeof (h->request); + /* These fields are coincident between req.request and req.request_ext */ + h->req.request.flags =3D htobe16 (cmd->flags); + h->req.request.type =3D htobe16 (cmd->type); + h->req.request.handle =3D htobe64 (cmd->cookie); + h->req.request.offset =3D htobe64 (cmd->offset); + if (h->extended_headers) { + h->req.request_ext.magic =3D htobe32 (NBD_REQUEST_EXT_MAGIC); + h->req.request_ext.count =3D htobe64 (cmd->count); + h->wlen =3D sizeof (h->req.request_ext); + } + else { + assert (cmd->count <=3D UINT32_MAX); + h->req.request.magic =3D htobe32 (NBD_REQUEST_MAGIC); + h->req.request.count =3D htobe32 (cmd->count); + h->wlen =3D sizeof (h->req.request); + } + h->wbuf =3D &h->req; if (cmd->type =3D=3D NBD_CMD_WRITE || cmd->next) h->wflags =3D MSG_MORE; SET_NEXT_STATE (%SEND_REQUEST); @@ -73,7 +82,7 @@ STATE_MACHINE { assert (h->cmds_to_issue !=3D NULL); cmd =3D h->cmds_to_issue; - assert (cmd->cookie =3D=3D be64toh (h->request.handle)); + assert (cmd->cookie =3D=3D be64toh (h->req.request.handle)); if (cmd->type =3D=3D NBD_CMD_WRITE) { h->wbuf =3D cmd->data; h->wlen =3D cmd->count; @@ -119,7 +128,7 @@ STATE_MACHINE { assert (!h->wlen); assert (h->cmds_to_issue !=3D NULL); cmd =3D h->cmds_to_issue; - assert (cmd->cookie =3D=3D be64toh (h->request.handle)); + assert (cmd->cookie =3D=3D be64toh (h->req.request.handle)); h->cmds_to_issue =3D cmd->next; if (h->cmds_to_issue_tail =3D=3D cmd) h->cmds_to_issue_tail =3D NULL; diff --git a/generator/states-reply-structured.c b/generator/states-reply-s= tructured.c index e1da850d..5524e000 100644 --- a/generator/states-reply-structured.c +++ b/generator/states-reply-structured.c @@ -34,7 +34,7 @@ structured_reply_in_bounds (uint64_t offset, uint32_t len= gth, offset + length > cmd->offset + cmd->count) { set_error (0, "range of structured reply is out of bounds, " "offset=3D%" PRIu64 ", cmd->offset=3D%" PRIu64 ", " - "length=3D%" PRIu32 ", cmd->count=3D%" PRIu32 ": " + "length=3D%" PRIu32 ", cmd->count=3D%" PRIu64 ": " "this is likely to be a bug in the NBD server", offset, cmd->offset, length, cmd->count); return false; diff --git a/lib/rw.c b/lib/rw.c index 4ade7508..16c2e848 100644 --- a/lib/rw.c +++ b/lib/rw.c @@ -1,5 +1,5 @@ /* NBD client library in userspace - * Copyright (C) 2013-2020 Red Hat Inc. + * Copyright (C) 2013-2021 Red Hat Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -216,13 +216,11 @@ nbd_internal_command_common (struct nbd_handle *h, } break; - /* Other commands are currently limited by the 32 bit field in the - * command structure on the wire, but in future we hope to support - * 64 bit values here with a change to the NBD protocol which is - * being discussed upstream. + /* Other commands are limited by the 32 bit field in the command + * structure on the wire, unless extended headers were negotiated. */ default: - if (count > UINT32_MAX) { + if (!h->extended_headers && count > UINT32_MAX) { set_error (ERANGE, "request too large: maximum request size is %" PR= Iu32, UINT32_MAX); goto err; --=20 2.33.1