From nobody Tue Feb 10 12:46:00 2026 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1686232952; cv=none; d=zohomail.com; s=zohoarc; b=ddXEh8EVF0t5dNS7IQNlDosqmtJ/rjOiWuTFc3WlpXoMet/AlWkbmoZYppvT9FH2z7Q8A/pthJJqWZN9+kHCKGofFxiOn9RZ75UKY0G9p0VxY89RXhVXgp/MPiTPcGLHIYGR/nEgJ7k2ymrqgUntystkNxYzE7g78i68g7xYvPY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686232952; 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=/QnKxV2pN16lLcAjxkXlbh+ajdIrWM1LhBM7kNJsoY4=; b=cJ8jOQaEz0Wy/Kw3CP0iEV+qObZbiJQtrA5NvCvjhWZJoGVmrx/w6b4BXtkmk4gX1xLn2Btk5s9qC8F9Hzh6etpkNDvEif/OzMm0t9RjkuGu3KW7jGdLdj8LyejurT1dL8cFVR6b5ojicsjVVGSiD5g0AvRZ+YITS5Nxs+gXEi4= 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+importer2=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 1686232952046136.00483028445933; Thu, 8 Jun 2023 07:02:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7G8u-0004AB-Lt; Thu, 08 Jun 2023 09:57:36 -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 1q7G8j-00042h-NX for qemu-devel@nongnu.org; Thu, 08 Jun 2023 09:57:26 -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 1q7G8g-0004ko-Lw for qemu-devel@nongnu.org; Thu, 08 Jun 2023 09:57:25 -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-331-5wP7wlCEPHyhTaitPIesUQ-1; Thu, 08 Jun 2023 09:57:14 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6DD8C185A78B; Thu, 8 Jun 2023 13:57:14 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id DACB3492B00; Thu, 8 Jun 2023 13:57:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686232635; 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=/QnKxV2pN16lLcAjxkXlbh+ajdIrWM1LhBM7kNJsoY4=; b=N5cJvZ3iUN2LdWnFOnBoZYQi7pQbDfDu5+VTzLvdOx/PweKrf6cDYl0vEQ6uWDSSzZsBu+ qhO/cNymz5NN+GmbhQvkf5XgTDamF4fZC7LpHuvLIkZ1A6p099Fu8MGV98Lh6171XhPdu7 e13gr09P1+Dk2ppPmWPQq4qSBtDfHQ4= X-MC-Unique: 5wP7wlCEPHyhTaitPIesUQ-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, libguestfs@redhat.com, vsementsov@yandex-team.ru, Kevin Wolf , Hanna Reitz Subject: [PATCH v4 23/24] nbd/server: Prepare for per-request filtering of BLOCK_STATUS Date: Thu, 8 Jun 2023 08:56:52 -0500 Message-Id: <20230608135653.2918540-24-eblake@redhat.com> In-Reply-To: <20230608135653.2918540-1-eblake@redhat.com> References: <20230608135653.2918540-1-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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+importer2=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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1686232954031100001 Content-Type: text/plain; charset="utf-8" The next commit will add support for the optional extension NBD_CMD_FLAG_PAYLOAD during NBD_CMD_BLOCK_STATUS, where the client can request that the server only return a subset of negotiated contexts, rather than all contexts. To make that task easier, this patch populates the list of contexts to return on a per-command basis (for now, identical to the full set of negotiated contexts). Signed-off-by: Eric Blake --- v4: split out NBDMetaContexts refactoring to its own patch, track NBDRequests.contexts as a pointer rather than inline --- include/block/nbd.h | 1 + nbd/server.c | 22 +++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index f240707f646..47850be5a66 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -76,6 +76,7 @@ typedef struct NBDRequest { uint16_t flags; /* NBD_CMD_FLAG_* */ uint16_t type; /* NBD_CMD_* */ NBDMode mode; /* Determines which network representation to use */ + NBDMetaContexts *contexts; /* Used by NBD_CMD_BLOCK_STATUS */ } NBDRequest; typedef struct NBDSimpleReply { diff --git a/nbd/server.c b/nbd/server.c index 42a4300c95e..308846fe46b 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2491,6 +2491,8 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, NBDRequest * error_setg(errp, "No memory"); return -ENOMEM; } + } else if (request->type =3D=3D NBD_CMD_BLOCK_STATUS) { + request->contexts =3D &client->contexts; } if (payload_len) { @@ -2716,11 +2718,11 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, } assert(client->mode >=3D NBD_MODE_EXTENDED || request->len <=3D UINT32_MAX); - if (client->contexts.count) { + if (request->contexts->count) { bool dont_fragment =3D request->flags & NBD_CMD_FLAG_REQ_ONE; - int contexts_remaining =3D client->contexts.count; + int contexts_remaining =3D request->contexts->count; - if (client->contexts.base_allocation) { + if (request->contexts->base_allocation) { ret =3D nbd_co_send_block_status(client, request, exp->common.blk, request->from, @@ -2733,7 +2735,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, } } - if (client->contexts.allocation_depth) { + if (request->contexts->allocation_depth) { ret =3D nbd_co_send_block_status(client, request, exp->common.blk, request->from, request->len, @@ -2746,8 +2748,9 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, } } + assert(request->contexts->exp =3D=3D client->exp); for (i =3D 0; i < client->exp->nr_export_bitmaps; i++) { - if (!client->contexts.bitmaps[i]) { + if (!request->contexts->bitmaps[i]) { continue; } ret =3D nbd_co_send_bitmap(client, request, @@ -2763,6 +2766,10 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, assert(!contexts_remaining); return 0; + } else if (client->contexts.count) { + return nbd_send_generic_reply(client, request, -EINVAL, + "CMD_BLOCK_STATUS payload not va= lid", + errp); } else { return nbd_send_generic_reply(client, request, -EINVAL, "CMD_BLOCK_STATUS not negotiated= ", @@ -2841,6 +2848,11 @@ static coroutine_fn void nbd_trip(void *opaque) } else { ret =3D nbd_handle_request(client, &request, req->data, &local_err= ); } + if (request.type =3D=3D NBD_CMD_BLOCK_STATUS && + request.contexts !=3D &client->contexts) { + g_free(request.contexts->bitmaps); + g_free(request.contexts); + } if (ret < 0) { error_prepend(&local_err, "Failed to send reply: "); goto disconnect; --=20 2.40.1