From nobody Sun May 19 01:15:05 2024 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=1695668598; cv=none; d=zohomail.com; s=zohoarc; b=VOuMpxExmlrakLz1HP/IdWlBu3EypKCpknINYnTK/nY6q6CufYDI7Ce/eDu6zX53K+KvFJIk8gLMySBPU8Z45nTZeyw17BfgHP4F61Y32g10OBWC4vUvXGyNGQmZYvfVMek5DmX+cDxbdbug11SI1F/WaBmfsqnwuTBfLp9kQSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668598; 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=4lXYcXWo8hCeTUShIT4/UbAPm7PFlODCxerMxYzeMy4=; b=VDDlVBpfgK+V9yKo0lHW0kXe+8dwMka/ClqQ3xCvnwk7udkW1wGUa3LAJW85XXjaYPaY31qN/nVjA559DTKTr/iDYM4TUOhEyMqa4AGX6V1Ifnbd282NYE0vhy6ibe14JHpkT8nIyDwmzVcJaZaCptxIh7KJn+mGXzEHBQwjfNw= 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 1695668598928897.0856118231309; Mon, 25 Sep 2023 12:03:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqqn-0002pn-Ac; Mon, 25 Sep 2023 15:02:33 -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 1qkqql-0002p8-Vf for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:32 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkqqh-0005WW-19 for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:31 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-356-jkKW60HNMxiF5ZFz2gRI5g-1; Mon, 25 Sep 2023 15:02:23 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30EB21C06500; Mon, 25 Sep 2023 19:02:23 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 344C6C15BB8; Mon, 25 Sep 2023 19:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668545; 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=4lXYcXWo8hCeTUShIT4/UbAPm7PFlODCxerMxYzeMy4=; b=HIwq4zhdtHlZgDOXjPC62ByBXkoRP+rXVo+czEF2MR5ihYA7qMvrL9AMvTUEUK1Fu+qvhV 8EYcAgNEVYdf9fKDhNn6xG+Eso3shyWfVkzHllhpIVf81rglIRNgMGbp2FrLVj9OD8IVlB 7BHKDnORh0X4Q5E389m7Xu7Yarrovhw= X-MC-Unique: jkKW60HNMxiF5ZFz2gRI5g-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Block layer core) Subject: [PULL 1/7] iotests: use TEST_IMG_FILE instead of TEST_IMG in _require_large_file Date: Mon, 25 Sep 2023 14:01:16 -0500 Message-ID: <20230925190114.3163545-10-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 16 X-Spam_score: 1.6 X-Spam_bar: + X-Spam_report: (1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1695668601114100003 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" We need to check that we are able to create large enough file which is used as an export base rather than connection URL. Unfortunately, there are cases when the TEST_IMG_FILE is not defined. We should fallback to TEST_IMG in that case. This problem has been detected when running ./check -nbd 5 The test should be able to run while it does not. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906140917.559129-2-den@openvz.org> Tested-by: Eric Blake Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- tests/qemu-iotests/common.rc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index d145f08201c..95c12577dd4 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -979,10 +979,15 @@ _require_drivers() # _require_large_file() { - if ! truncate --size=3D"$1" "$TEST_IMG"; then + if [ -z "$TEST_IMG_FILE" ]; then + FILENAME=3D"$TEST_IMG" + else + FILENAME=3D"$TEST_IMG_FILE" + fi + if ! truncate --size=3D"$1" "$FILENAME"; then _notrun "file system on $TEST_DIR does not support large enough fi= les" fi - rm "$TEST_IMG" + rm "$FILENAME" } # Check that a set of devices is available in the QEMU binary --=20 2.41.0 From nobody Sun May 19 01:15:05 2024 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=1695668619; cv=none; d=zohomail.com; s=zohoarc; b=COjTkPMReyJ8QEq1NMnT9fCG0oUWMcpZ4XkyTH9EGAHq2fx4HClz14ZRuX8h+IJwTISFYI9WswQGpDY5k3MllRDqt7a13cJCj9u54MkCxmixnbGjxTq3w/xnfJ15kQSGYpbGcqFkGNY9Gghvog/boaU6I7EouoY075fxJqv0Lfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668619; 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=yEeMFLbrmNmBCHU0FTQYOXc+3AuIf7EJXCmvyAlbPmw=; b=P11A28cxoY8pNcdQD942veTOBbrAfA+qmuHer3xYBnQUj/vWFZW+WJ+aws1ml700R+bw2FZWM/xyYsoDzI7ocJvtRfGftHtaLzKdQLAFlRyhJJ55260sSETpWA4DfzQAqxrB3CqiOjOtnK3az/WF201AYwmqmMqtZ4DADr9G3JU= 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 169566861959286.9896481734337; Mon, 25 Sep 2023 12:03:39 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqr5-0002vb-VC; Mon, 25 Sep 2023 15:02:51 -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 1qkqqz-0002tN-FP for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:46 -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 1qkqqi-0005X5-Vm for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:45 -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-695-KtjG1qf6MUONFL3zg-oU1Q-1; Mon, 25 Sep 2023 15:02:24 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DFF87185A790; Mon, 25 Sep 2023 19:02:23 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5FB52C15BB8; Mon, 25 Sep 2023 19:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668548; 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=yEeMFLbrmNmBCHU0FTQYOXc+3AuIf7EJXCmvyAlbPmw=; b=dygbxUJHWghuljf7avcCVxrzF/goul0apneKdRwVIk+pEPqNfeBSiendphlYC+T+Rb4m7+ 0t5IiWSputgrcF+mH9IUYN9exPVcYlFVLr3oDbx72x9xjvrkShNcpkYUPx22c6ITLSRs6L VSEXRb2Jby6PpWhUVvfDf/7UK9a8LFg= X-MC-Unique: KtjG1qf6MUONFL3zg-oU1Q-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Kevin Wolf , Hanna Reitz , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 2/7] iotests: improve 'not run' message for nbd-multiconn test Date: Mon, 25 Sep 2023 14:01:17 -0500 Message-ID: <20230925190114.3163545-11-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable 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: 1695668621870100003 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" The test actually requires Python bindings to libnbd rather than libnbd itself. Clarify that inside the message. Signed-off-by: Denis V. Lunev CC: Kevin Wolf CC: Hanna Reitz CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy Message-ID: <20230906140917.559129-3-den@openvz.org> Reviewed-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- tests/qemu-iotests/tests/nbd-multiconn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/qemu-iotests/tests/nbd-multiconn b/tests/qemu-iotests/te= sts/nbd-multiconn index b121f2e363d..478a1eaba27 100755 --- a/tests/qemu-iotests/tests/nbd-multiconn +++ b/tests/qemu-iotests/tests/nbd-multiconn @@ -142,4 +142,4 @@ if __name__ =3D=3D '__main__': iotests.main(supported_fmts=3D['qcow2']) except ImportError: - iotests.notrun('libnbd not installed') + iotests.notrun('Python bindings to libnbd are not installed') --=20 2.41.0 From nobody Sun May 19 01:15:05 2024 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=1695668639; cv=none; d=zohomail.com; s=zohoarc; b=P/esZkqLcmPCwvei+iLD/QO5ElzqweFSuRe6j8yObODZxZL3KRAyN4Y7ACVGLGlLZE8Wr02u4oC8Qp0v3N4GOkWJYo1Aw6B5YNPYELn715nrGQo9jDkx1fu4CD0wvwqxRuOubnOvwzk2J+mUcCdzUIFu+tUlSc2NFsw6QAuzbA8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668639; 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=teA9tMr7PV0hHVrfLUY1BUr2aVzkx5D3kF19N81N4Ag=; b=n4junzXFUasXOGbQordh3mCZJhkMsRERXuR/89eL0iFblfCRJP3FvCu2r6vDIHJsbp6TXhwzI7Vk5K2pXa2L3wgUZEHIi5VQ7SfKVsenlpJNPq1w4715HpSvKZCNzj9TSVq+Zi5mGMNG+okdl2urDJdzKg+dNeLugIHU0wjRMGA= 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 1695668639849119.81885149427114; Mon, 25 Sep 2023 12:03:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqr6-0002vc-67; Mon, 25 Sep 2023 15:02:52 -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 1qkqr2-0002u9-Ci for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:48 -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 1qkqql-0005XW-3t for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:48 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-201-ZkIWlPjlNkmuZjAvDZWYFA-1; Mon, 25 Sep 2023 15:02:25 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A17FF3800E94; Mon, 25 Sep 2023 19:02:24 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21400C15BB8; Mon, 25 Sep 2023 19:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668549; 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=teA9tMr7PV0hHVrfLUY1BUr2aVzkx5D3kF19N81N4Ag=; b=TaElqZmGwr0goo8HwKY7C5IkTptFQtuil8NLM5uz7Bow8cFoAw3A4IecPpZwitM6+5p52L QazUK91EPY7gfjsNhPf1bE6ufjOAArNJuXEA8wTOK3FkmLBuvdr8qCK8rasU0kfN/1rH/q rHcshmiP3QMkUtlmmpnwWqgNrZcH+Ns= X-MC-Unique: ZkIWlPjlNkmuZjAvDZWYFA-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 3/7] nbd: Replace bool structured_reply with mode enum Date: Mon, 25 Sep 2023 14:01:18 -0500 Message-ID: <20230925190114.3163545-12-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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, 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: 1695668641305100001 Content-Type: text/plain; charset="utf-8" The upcoming patches for 64-bit extensions requires various points in the protocol to make decisions based on what was negotiated. While we could easily add a 'bool extended_headers' alongside the existing 'bool structured_reply', this does not scale well if more modes are added in the future. Better is to expose the mode enum added in the recent commit bfe04d0a7d out to a wider use in the code base. Where the code previously checked for structured_reply being set or clear, it now prefers checking for an inequality; this works because the nodes are in a continuum of increasing abilities, and allows us to touch fewer places if we ever insert other modes in the middle of the enum. There should be no semantic change in this patch. Signed-off-by: Eric Blake Message-ID: <20230829175826.377251-20-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/nbd.h | 2 +- block/nbd.c | 8 +++++--- nbd/client-connection.c | 4 ++-- nbd/client.c | 18 +++++++++--------- nbd/server.c | 31 ++++++++++++++++++------------- qemu-nbd.c | 4 +++- 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index f672b76173b..53226764574 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -305,7 +305,7 @@ typedef struct NBDExportInfo { /* In-out fields, set by client before nbd_receive_negotiate() and * updated by server results during nbd_receive_negotiate() */ - bool structured_reply; + NBDMode mode; /* input maximum mode tolerated; output actual mode chos= en */ bool base_allocation; /* base:allocation context for NBD_CMD_BLOCK_STA= TUS */ /* Set by server results during nbd_receive_negotiate() and diff --git a/block/nbd.c b/block/nbd.c index cc48580df70..676b755d79f 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -463,7 +463,8 @@ static coroutine_fn int nbd_receive_replies(BDRVNBDStat= e *s, uint64_t cookie) nbd_channel_error(s, ret); return ret; } - if (nbd_reply_is_structured(&s->reply) && !s->info.structured_repl= y) { + if (nbd_reply_is_structured(&s->reply) && + s->info.mode < NBD_MODE_STRUCTURED) { nbd_channel_error(s, -EINVAL); return -EINVAL; } @@ -866,7 +867,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( } /* handle structured reply chunk */ - assert(s->info.structured_reply); + assert(s->info.mode >=3D NBD_MODE_STRUCTURED); chunk =3D &s->reply.structured; if (chunk->type =3D=3D NBD_REPLY_TYPE_NONE) { @@ -1070,7 +1071,8 @@ nbd_co_receive_cmdread_reply(BDRVNBDState *s, uint64_= t cookie, void *payload =3D NULL; Error *local_err =3D NULL; - NBD_FOREACH_REPLY_CHUNK(s, iter, cookie, s->info.structured_reply, + NBD_FOREACH_REPLY_CHUNK(s, iter, cookie, + s->info.mode >=3D NBD_MODE_STRUCTURED, qiov, &reply, &payload) { int ret; diff --git a/nbd/client-connection.c b/nbd/client-connection.c index 53a6549914c..aa0201b7107 100644 --- a/nbd/client-connection.c +++ b/nbd/client-connection.c @@ -1,5 +1,5 @@ /* - * QEMU Block driver for NBD + * QEMU Block driver for NBD * * Copyright (c) 2021 Virtuozzo International GmbH. * @@ -93,7 +93,7 @@ NBDClientConnection *nbd_client_connection_new(const Sock= etAddress *saddr, .do_negotiation =3D do_negotiation, .initial_info.request_sizes =3D true, - .initial_info.structured_reply =3D true, + .initial_info.mode =3D NBD_MODE_STRUCTURED, .initial_info.base_allocation =3D true, .initial_info.x_dirty_bitmap =3D g_strdup(x_dirty_bitmap), .initial_info.name =3D g_strdup(export_name ?: "") diff --git a/nbd/client.c b/nbd/client.c index bd7e2001366..844be42181a 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -879,7 +879,7 @@ static int nbd_list_meta_contexts(QIOChannel *ioc, */ static int nbd_start_negotiate(QIOChannel *ioc, QCryptoTLSCreds *tlscreds, const char *hostname, QIOChannel **outioc, - bool structured_reply, bool *zeroes, + NBDMode max_mode, bool *zeroes, Error **errp) { ERRP_GUARD(); @@ -953,7 +953,7 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypto= TLSCreds *tlscreds, if (fixedNewStyle) { int result =3D 0; - if (structured_reply) { + if (max_mode >=3D NBD_MODE_STRUCTURED) { result =3D nbd_request_simple_option(ioc, NBD_OPT_STRUCTURED_REPL= Y, false, errp); @@ -1022,20 +1022,19 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, trace_nbd_receive_negotiate_name(info->name); result =3D nbd_start_negotiate(ioc, tlscreds, hostname, outioc, - info->structured_reply, &zeroes, errp); + info->mode, &zeroes, errp); if (result < 0) { return result; } - info->structured_reply =3D false; + info->mode =3D result; info->base_allocation =3D false; if (tlscreds && *outioc) { ioc =3D *outioc; } - switch ((NBDMode)result) { + switch (info->mode) { case NBD_MODE_STRUCTURED: - info->structured_reply =3D true; if (base_allocation) { result =3D nbd_negotiate_simple_meta_context(ioc, info, errp); if (result < 0) { @@ -1144,8 +1143,8 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, QIOChannel *sioc =3D NULL; *info =3D NULL; - result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, true, - NULL, errp); + result =3D nbd_start_negotiate(ioc, tlscreds, hostname, &sioc, + NBD_MODE_STRUCTURED, NULL, errp); if (tlscreds && sioc) { ioc =3D sioc; } @@ -1176,7 +1175,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, memset(&array[count - 1], 0, sizeof(*array)); array[count - 1].name =3D name; array[count - 1].description =3D desc; - array[count - 1].structured_reply =3D result =3D=3D NBD_MODE_S= TRUCTURED; + array[count - 1].mode =3D result; } for (i =3D 0; i < count; i++) { @@ -1209,6 +1208,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, /* Lone export name is implied, but we can parse length and flags = */ array =3D g_new0(NBDExportInfo, 1); array->name =3D g_strdup(""); + array->mode =3D NBD_MODE_OLDSTYLE; count =3D 1; if (nbd_negotiate_finish_oldstyle(ioc, array, errp) < 0) { diff --git a/nbd/server.c b/nbd/server.c index b5f93a20c9c..936c35e55c6 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -143,7 +143,7 @@ struct NBDClient { uint32_t check_align; /* If non-zero, check for aligned client request= s */ - bool structured_reply; + NBDMode mode; NBDExportMetaContexts export_meta; uint32_t opt; /* Current option being negotiated */ @@ -502,7 +502,7 @@ static int nbd_negotiate_handle_export_name(NBDClient *= client, bool no_zeroes, } myflags =3D client->exp->nbdflags; - if (client->structured_reply) { + if (client->mode >=3D NBD_MODE_STRUCTURED) { myflags |=3D NBD_FLAG_SEND_DF; } trace_nbd_negotiate_new_style_size_flags(client->exp->size, myflags); @@ -687,7 +687,7 @@ static int nbd_negotiate_handle_info(NBDClient *client,= Error **errp) /* Send NBD_INFO_EXPORT always */ myflags =3D exp->nbdflags; - if (client->structured_reply) { + if (client->mode >=3D NBD_MODE_STRUCTURED) { myflags |=3D NBD_FLAG_SEND_DF; } trace_nbd_negotiate_new_style_size_flags(exp->size, myflags); @@ -985,7 +985,8 @@ static int nbd_negotiate_meta_queries(NBDClient *client, size_t i; size_t count =3D 0; - if (client->opt =3D=3D NBD_OPT_SET_META_CONTEXT && !client->structured= _reply) { + if (client->opt =3D=3D NBD_OPT_SET_META_CONTEXT && + client->mode < NBD_MODE_STRUCTURED) { return nbd_opt_invalid(client, errp, "request option '%s' when structured reply " "is not negotiated", @@ -1122,10 +1123,12 @@ static int nbd_negotiate_options(NBDClient *client,= Error **errp) if (nbd_read32(client->ioc, &flags, "flags", errp) < 0) { return -EIO; } + client->mode =3D NBD_MODE_EXPORT_NAME; trace_nbd_negotiate_options_flags(flags); if (flags & NBD_FLAG_C_FIXED_NEWSTYLE) { fixedNewstyle =3D true; flags &=3D ~NBD_FLAG_C_FIXED_NEWSTYLE; + client->mode =3D NBD_MODE_SIMPLE; } if (flags & NBD_FLAG_C_NO_ZEROES) { no_zeroes =3D true; @@ -1261,13 +1264,13 @@ static int nbd_negotiate_options(NBDClient *client,= Error **errp) case NBD_OPT_STRUCTURED_REPLY: if (length) { ret =3D nbd_reject_length(client, false, errp); - } else if (client->structured_reply) { + } else if (client->mode >=3D NBD_MODE_STRUCTURED) { ret =3D nbd_negotiate_send_rep_err( client, NBD_REP_ERR_INVALID, errp, "structured reply already negotiated"); } else { ret =3D nbd_negotiate_send_rep(client, NBD_REP_ACK, er= rp); - client->structured_reply =3D true; + client->mode =3D NBD_MODE_STRUCTURED; } break; @@ -1895,7 +1898,9 @@ static int coroutine_fn nbd_co_send_simple_reply(NBDC= lient *client, }; assert(!len || !nbd_err); - assert(!client->structured_reply || request->type !=3D NBD_CMD_READ); + assert(client->mode < NBD_MODE_STRUCTURED || + (client->mode =3D=3D NBD_MODE_STRUCTURED && + request->type !=3D NBD_CMD_READ)); trace_nbd_co_send_simple_reply(request->cookie, nbd_err, nbd_err_lookup(nbd_err), len); set_be_simple_reply(&reply, nbd_err, request->cookie); @@ -1971,7 +1976,7 @@ static int coroutine_fn nbd_co_send_chunk_read(NBDCli= ent *client, return nbd_co_send_iov(client, iov, 3, errp); } -/*ebb*/ + static int coroutine_fn nbd_co_send_chunk_error(NBDClient *client, NBDRequest *request, uint32_t error, @@ -2397,7 +2402,7 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, NBDRequest * client->check_align); } valid_flags =3D NBD_CMD_FLAG_FUA; - if (request->type =3D=3D NBD_CMD_READ && client->structured_reply) { + if (request->type =3D=3D NBD_CMD_READ && client->mode >=3D NBD_MODE_ST= RUCTURED) { 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 | NBD_CMD_FLAG_FAST_ZERO; @@ -2423,7 +2428,7 @@ static coroutine_fn int nbd_send_generic_reply(NBDCli= ent *client, const char *error_msg, Error **errp) { - if (client->structured_reply && ret < 0) { + if (client->mode >=3D NBD_MODE_STRUCTURED && ret < 0) { return nbd_co_send_chunk_error(client, request, -ret, error_msg, e= rrp); } else { return nbd_co_send_simple_reply(client, request, ret < 0 ? -ret : = 0, @@ -2451,8 +2456,8 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, } } - if (client->structured_reply && !(request->flags & NBD_CMD_FLAG_DF) && - request->len) + if (client->mode >=3D NBD_MODE_STRUCTURED && + !(request->flags & NBD_CMD_FLAG_DF) && request->len) { return nbd_co_send_sparse_read(client, request, request->from, data, request->len, errp); @@ -2464,7 +2469,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, "reading from file failed", errp); } - if (client->structured_reply) { + if (client->mode >=3D NBD_MODE_STRUCTURED) { if (request->len) { return nbd_co_send_chunk_read(client, request, request->from, = data, request->len, true, errp); diff --git a/qemu-nbd.c b/qemu-nbd.c index 30eeb6f3c75..70aa3c487a0 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -295,7 +295,9 @@ static void *show_parts(void *arg) static void *nbd_client_thread(void *arg) { struct NbdClientOpts *opts =3D arg; - NBDExportInfo info =3D { .request_sizes =3D false, .name =3D g_strdup(= "") }; + /* TODO: Revisit this if nbd.ko ever gains support for structured repl= y */ + NBDExportInfo info =3D { .request_sizes =3D false, .name =3D g_strdup(= ""), + .mode =3D NBD_MODE_SIMPLE }; QIOChannelSocket *sioc; int fd =3D -1; int ret =3D EXIT_FAILURE; --=20 2.41.0 From nobody Sun May 19 01:15:05 2024 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=1695668630; cv=none; d=zohomail.com; s=zohoarc; b=PufL/AQUmAwUwc4JTw82HOq8kwre+zessP3iHaYVr5NGVvzeazxONusflHr8ayd1ffkp0skvbi1UCxTPNOetIf/Dk27DaINe+q+sZOqlb+OQ6R/yQvhXNy6X83wZtKFcN5pDo3INaJKcXbfTLKOde11KmynmHExr0ptttDh7PME= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668630; 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=AWTGopw2Z/nyfjx0J1OHtw1KKgfeUR28/hboQdVW0gE=; b=IkNaWtw+gOv0MDZQFb5BVjLJN/VU5HKYzPYanmsbuBqjSyIA+B28ZmJE9/kp/2IH5JKe6/Kq7p5IbjWkNfCKbG/zDvsec6bLfLmAvksO79/UIrcTn4FfyoAWi8PJLLQjJyfSslhN+w2z6gYedq46pv3thWRdI8aSajONYmWoe0o= 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 1695668630138913.5273702919219; Mon, 25 Sep 2023 12:03:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqqt-0002ru-3H; Mon, 25 Sep 2023 15:02:39 -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 1qkqqo-0002qJ-Ew for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkqqk-0005Xl-AR for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:34 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-148-F0p2YizXPCy4aGgQ9bIZRQ-1; Mon, 25 Sep 2023 15:02:25 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4FE7D29AB410; Mon, 25 Sep 2023 19:02:25 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id D0866C15BB8; Mon, 25 Sep 2023 19:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668549; 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=AWTGopw2Z/nyfjx0J1OHtw1KKgfeUR28/hboQdVW0gE=; b=bW7rOMeA3Bg+8t1ZHVxRIgXOaW/PjXol59f27wb6WGHQ0h5iCyVdsODDaVH/uTyH6KTCeh hmvWVDIXrHJkye9KvZYjciuLkjBCEyDrs9EfNuNa9NkCEcio4BigE9rQRCpwNRObDvEe9p TUY4XcFm2hMKiFcvexP1CCZVRycoPTU= X-MC-Unique: F0p2YizXPCy4aGgQ9bIZRQ-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 4/7] nbd/client: Pass mode through to nbd_send_request Date: Mon, 25 Sep 2023 14:01:19 -0500 Message-ID: <20230925190114.3163545-13-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1695668630377100001 Content-Type: text/plain; charset="utf-8" Once the 64-bit headers extension is enabled, the data layout we send over the wire for a client request depends on the mode negotiated with the server. Rather than adding a parameter to nbd_send_request, we can add a member to struct NBDRequest, since it already does not reflect on-wire format. Some callers initialize it directly; many others rely on a common initialization point during nbd_co_send_request(). At this point, there is no semantic change. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-ID: <20230829175826.377251-21-eblake@redhat.com> --- include/block/nbd.h | 12 +++++++----- block/nbd.c | 5 +++-- nbd/client.c | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 53226764574..e07b9f9bff7 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -63,17 +63,19 @@ typedef enum NBDMode { /* TODO add NBD_MODE_EXTENDED */ } NBDMode; -/* Transmission phase structs - * - * Note: these are _NOT_ the same as the network representation of an NBD - * request and reply! +/* Transmission phase structs */ + +/* + * Note: NBDRequest is _NOT_ the same as the network representation of an = NBD + * request! */ typedef struct NBDRequest { uint64_t cookie; uint64_t from; uint32_t len; uint16_t flags; /* NBD_CMD_FLAG_* */ - uint16_t type; /* NBD_CMD_* */ + uint16_t type; /* NBD_CMD_* */ + NBDMode mode; /* Determines which network representation to use */ } NBDRequest; typedef struct NBDSimpleReply { diff --git a/block/nbd.c b/block/nbd.c index 676b755d79f..24f50b79e47 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -339,7 +339,7 @@ int coroutine_fn nbd_co_do_establish_connection(BlockDr= iverState *bs, * We have connected, but must fail for other reasons. * Send NBD_CMD_DISC as a courtesy to the server. */ - NBDRequest request =3D { .type =3D NBD_CMD_DISC }; + NBDRequest request =3D { .type =3D NBD_CMD_DISC, .mode =3D s->info= .mode }; nbd_send_request(s->ioc, &request); @@ -520,6 +520,7 @@ nbd_co_send_request(BlockDriverState *bs, NBDRequest *r= equest, qemu_co_mutex_lock(&s->send_mutex); request->cookie =3D INDEX_TO_COOKIE(i); + request->mode =3D s->info.mode; assert(s->ioc); @@ -1465,7 +1466,7 @@ static void nbd_yank(void *opaque) static void nbd_client_close(BlockDriverState *bs) { BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; - NBDRequest request =3D { .type =3D NBD_CMD_DISC }; + NBDRequest request =3D { .type =3D NBD_CMD_DISC, .mode =3D s->info.mod= e }; if (s->ioc) { nbd_send_request(s->ioc, &request); diff --git a/nbd/client.c b/nbd/client.c index 844be42181a..345f1c0f2d0 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1218,7 +1218,7 @@ int nbd_receive_export_list(QIOChannel *ioc, QCryptoT= LSCreds *tlscreds, /* Send NBD_CMD_DISC as a courtesy to the server, but ignore all * errors now that we have the information we wanted. */ if (nbd_drop(ioc, 124, NULL) =3D=3D 0) { - NBDRequest request =3D { .type =3D NBD_CMD_DISC }; + NBDRequest request =3D { .type =3D NBD_CMD_DISC, .mode =3D res= ult }; nbd_send_request(ioc, &request); } @@ -1348,6 +1348,7 @@ int nbd_send_request(QIOChannel *ioc, NBDRequest *req= uest) { uint8_t buf[NBD_REQUEST_SIZE]; + assert(request->mode <=3D NBD_MODE_STRUCTURED); /* TODO handle extende= d */ trace_nbd_send_request(request->from, request->len, request->cookie, request->flags, request->type, nbd_cmd_lookup(request->type)); --=20 2.41.0 From nobody Sun May 19 01:15:05 2024 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=1695668612; cv=none; d=zohomail.com; s=zohoarc; b=YzBB7OJjSCu6aIBFn0RfGvKjkq4aNkVbkLR+tKMTqEzucbwVlRpGJVG8WBGtLO9ebEYjUtxU35GHegHEKZhFvfuPu+BYZlSen6a6v0cC9wSXar4bKBoSzjsTna6g4H7cuLJkk0HUs95eF/Z+E5ZuGNbu2QHfhHdltUEueXl1+Sk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668612; 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=RnCLMNI8G+fwHV6suCgpyCXaJAhIZ9b4QbGRyXBfKTo=; b=Ii4JNUfu4ls1sEubNtGRdnEYp6yqH37OtbieMiAEgkYp4W1ntLVLBlBXG8L8BuIlWmpZUgEOpUNl9zuviniSjsg6/MKBv5/c7XbHjb8Y3eNsyvZ5bfumjWkA89+ZwwK+QJ+GIWv43637ZLHhDQJDbOpve4mA6pYJHSarXBGmwB4= 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 1695668612003665.8071952422371; Mon, 25 Sep 2023 12:03:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqr4-0002uX-9J; Mon, 25 Sep 2023 15:02:50 -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 1qkqqr-0002ra-IS for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qkqql-0005Xu-KJ for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:37 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-472-pgOsW4IVMZaQgEJlJBqs3w-1; Mon, 25 Sep 2023 15:02:26 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2B0C73800E9B; Mon, 25 Sep 2023 19:02:26 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B797C15BB8; Mon, 25 Sep 2023 19:02:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668550; 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=RnCLMNI8G+fwHV6suCgpyCXaJAhIZ9b4QbGRyXBfKTo=; b=TMQ2WCQnMQTpKIYtyuDsMgENJd05o+UH1q3uuXWtp3b1wCqcY5sT8h8gjNB4FqRP/ACnu8 RKJyfL5TWw1QgS/InRY0pVtKgLeQm9elwdKMg8uPeoXiFPmonm/FKTBs0Ahog9HjnBYggI RQ0mDrLraunntiLZlOyLDv3Uf5DP9nA= X-MC-Unique: pgOsW4IVMZaQgEJlJBqs3w-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 5/7] nbd: Add types for extended headers Date: Mon, 25 Sep 2023 14:01:20 -0500 Message-ID: <20230925190114.3163545-14-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1695668612409100001 Content-Type: text/plain; charset="utf-8" Add the constants and structs necessary for later patches to start implementing the NBD_OPT_EXTENDED_HEADERS extension in both the client and server, matching recent upstream nbd.git (through commit e6f3b94a934). This patch does not change any existing behavior, but merely sets the stage for upcoming patches. This patch does not change the status quo that neither the client nor server use a packed-struct representation for the request header. While most of the patch adds new types, there is also some churn for renaming the existing NBDExtent to NBDExtent32 to contrast it with NBDExtent64, which I thought was a nicer name than NBDExtentExt. Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy Message-ID: <20230829175826.377251-22-eblake@redhat.com> --- include/block/nbd.h | 124 +++++++++++++++++++++++++++++++------------- nbd/nbd-internal.h | 3 +- block/nbd.c | 6 +-- nbd/common.c | 12 ++++- nbd/server.c | 6 +-- 5 files changed, 106 insertions(+), 45 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index e07b9f9bff7..22a9b5d10e0 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -60,7 +60,7 @@ typedef enum NBDMode { NBD_MODE_EXPORT_NAME, /* newstyle but only OPT_EXPORT_NAME safe */ NBD_MODE_SIMPLE, /* newstyle but only simple replies */ NBD_MODE_STRUCTURED, /* newstyle, structured replies enabled */ - /* TODO add NBD_MODE_EXTENDED */ + NBD_MODE_EXTENDED, /* newstyle, extended headers enabled */ } NBDMode; /* Transmission phase structs */ @@ -93,20 +93,36 @@ typedef struct NBDStructuredReplyChunk { uint32_t length; /* length of payload */ } QEMU_PACKED NBDStructuredReplyChunk; +typedef struct NBDExtendedReplyChunk { + uint32_t magic; /* NBD_EXTENDED_REPLY_MAGIC */ + uint16_t flags; /* combination of NBD_REPLY_FLAG_* */ + uint16_t type; /* NBD_REPLY_TYPE_* */ + uint64_t cookie; /* request handle */ + uint64_t offset; /* request offset */ + uint64_t length; /* length of payload */ +} QEMU_PACKED NBDExtendedReplyChunk; + typedef union NBDReply { NBDSimpleReply simple; NBDStructuredReplyChunk structured; + NBDExtendedReplyChunk extended; struct { /* - * @magic and @cookie fields have the same offset and size both in - * simple reply and structured reply chunk, so let them be accessi= ble - * without ".simple." or ".structured." specification + * @magic and @cookie fields have the same offset and size in all + * forms of replies, so let them be accessible without ".simple.", + * ".structured.", or ".extended." specifications. */ uint32_t magic; uint32_t _skip; uint64_t cookie; - } QEMU_PACKED; + }; } NBDReply; +QEMU_BUILD_BUG_ON(offsetof(NBDReply, simple.cookie) !=3D + offsetof(NBDReply, cookie)); +QEMU_BUILD_BUG_ON(offsetof(NBDReply, structured.cookie) !=3D + offsetof(NBDReply, cookie)); +QEMU_BUILD_BUG_ON(offsetof(NBDReply, extended.cookie) !=3D + offsetof(NBDReply, cookie)); /* Header of chunk for NBD_REPLY_TYPE_OFFSET_DATA */ typedef struct NBDStructuredReadData { @@ -133,14 +149,34 @@ typedef struct NBDStructuredError { typedef struct NBDStructuredMeta { /* header's length >=3D 12 (at least one extent) */ uint32_t context_id; - /* extents follows */ + /* NBDExtent32 extents[] follows, array length implied by header */ } QEMU_PACKED NBDStructuredMeta; -/* Extent chunk for NBD_REPLY_TYPE_BLOCK_STATUS */ -typedef struct NBDExtent { +/* Extent array element for NBD_REPLY_TYPE_BLOCK_STATUS */ +typedef struct NBDExtent32 { uint32_t length; uint32_t flags; /* NBD_STATE_* */ -} QEMU_PACKED NBDExtent; +} QEMU_PACKED NBDExtent32; + +/* Header of NBD_REPLY_TYPE_BLOCK_STATUS_EXT */ +typedef struct NBDExtendedMeta { + /* header's length >=3D 24 (at least one extent) */ + uint32_t context_id; + uint32_t count; /* header length must be count * 16 + 8 */ + /* NBDExtent64 extents[count] follows */ +} QEMU_PACKED NBDExtendedMeta; + +/* Extent array element for NBD_REPLY_TYPE_BLOCK_STATUS_EXT */ +typedef struct NBDExtent64 { + uint64_t length; + uint64_t flags; /* NBD_STATE_* */ +} QEMU_PACKED NBDExtent64; + +/* Client payload for limiting NBD_CMD_BLOCK_STATUS reply */ +typedef struct NBDBlockStatusPayload { + uint64_t effect_length; + /* uint32_t ids[] follows, array length implied by header */ +} QEMU_PACKED NBDBlockStatusPayload; /* Transmission (export) flags: sent from server to client during handshak= e, but describe what will happen during transmission */ @@ -158,20 +194,22 @@ enum { 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 */ + NBD_FLAG_BLOCK_STAT_PAYLOAD_BIT =3D 12, /* PAYLOAD flag for BLOCK_STAT= US */ }; -#define NBD_FLAG_HAS_FLAGS (1 << NBD_FLAG_HAS_FLAGS_BIT) -#define NBD_FLAG_READ_ONLY (1 << NBD_FLAG_READ_ONLY_BIT) -#define NBD_FLAG_SEND_FLUSH (1 << NBD_FLAG_SEND_FLUSH_BIT) -#define NBD_FLAG_SEND_FUA (1 << NBD_FLAG_SEND_FUA_BIT) -#define NBD_FLAG_ROTATIONAL (1 << NBD_FLAG_ROTATIONAL_BIT) -#define NBD_FLAG_SEND_TRIM (1 << NBD_FLAG_SEND_TRIM_BIT) -#define NBD_FLAG_SEND_WRITE_ZEROES (1 << NBD_FLAG_SEND_WRITE_ZEROES_BIT) -#define NBD_FLAG_SEND_DF (1 << NBD_FLAG_SEND_DF_BIT) -#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) +#define NBD_FLAG_HAS_FLAGS (1 << NBD_FLAG_HAS_FLAGS_BIT) +#define NBD_FLAG_READ_ONLY (1 << NBD_FLAG_READ_ONLY_BIT) +#define NBD_FLAG_SEND_FLUSH (1 << NBD_FLAG_SEND_FLUSH_BIT) +#define NBD_FLAG_SEND_FUA (1 << NBD_FLAG_SEND_FUA_BIT) +#define NBD_FLAG_ROTATIONAL (1 << NBD_FLAG_ROTATIONAL_BIT) +#define NBD_FLAG_SEND_TRIM (1 << NBD_FLAG_SEND_TRIM_BIT) +#define NBD_FLAG_SEND_WRITE_ZEROES (1 << NBD_FLAG_SEND_WRITE_ZEROES_BIT) +#define NBD_FLAG_SEND_DF (1 << NBD_FLAG_SEND_DF_BIT) +#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) +#define NBD_FLAG_BLOCK_STAT_PAYLOAD (1 << NBD_FLAG_BLOCK_STAT_PAYLOAD_BIT) /* New-style handshake (global) flags, sent from server to client, and control what will happen during handshake phase. */ @@ -194,6 +232,7 @@ enum { #define NBD_OPT_STRUCTURED_REPLY (8) #define NBD_OPT_LIST_META_CONTEXT (9) #define NBD_OPT_SET_META_CONTEXT (10) +#define NBD_OPT_EXTENDED_HEADERS (11) /* Option reply types. */ #define NBD_REP_ERR(value) ((UINT32_C(1) << 31) | (value)) @@ -211,6 +250,8 @@ enum { #define NBD_REP_ERR_UNKNOWN NBD_REP_ERR(6) /* Export unknown */ #define NBD_REP_ERR_SHUTDOWN NBD_REP_ERR(7) /* Server shutting dow= n */ #define NBD_REP_ERR_BLOCK_SIZE_REQD NBD_REP_ERR(8) /* Need INFO_BLOCK_SIZ= E */ +#define NBD_REP_ERR_TOO_BIG NBD_REP_ERR(9) /* Payload size overfl= ow */ +#define NBD_REP_ERR_EXT_HEADER_REQD NBD_REP_ERR(10) /* Need extended heade= rs */ /* Info types, used during NBD_REP_INFO */ #define NBD_INFO_EXPORT 0 @@ -219,12 +260,14 @@ enum { #define NBD_INFO_BLOCK_SIZE 3 /* Request flags, sent from client to server during transmission phase */ -#define NBD_CMD_FLAG_FUA (1 << 0) /* 'force unit access' during wri= te */ -#define NBD_CMD_FLAG_NO_HOLE (1 << 1) /* don't punch hole on zero run */ -#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 */ +#define NBD_CMD_FLAG_FUA (1 << 0) /* 'force unit access' during wr= ite */ +#define NBD_CMD_FLAG_NO_HOLE (1 << 1) /* don't punch hole on zero run = */ +#define NBD_CMD_FLAG_DF (1 << 2) /* don't fragment structured rea= d */ +#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 f= ast */ +#define NBD_CMD_FLAG_PAYLOAD_LEN (1 << 5) \ + /* length describes payload, not effect; only with ext header */ /* Supported request types */ enum { @@ -250,22 +293,31 @@ enum { */ #define NBD_MAX_STRING_SIZE 4096 -/* Two types of reply structures */ +/* Two types of request structures, a given client will only use 1 */ +#define NBD_REQUEST_MAGIC 0x25609513 +#define NBD_EXTENDED_REQUEST_MAGIC 0x21e41c71 + +/* + * Three types of reply structures, but what a client expects depends + * on NBD_OPT_STRUCTURED_REPLY and NBD_OPT_EXTENDED_HEADERS. + */ #define NBD_SIMPLE_REPLY_MAGIC 0x67446698 #define NBD_STRUCTURED_REPLY_MAGIC 0x668e33ef +#define NBD_EXTENDED_REPLY_MAGIC 0x6e8a278c -/* Structured reply flags */ +/* Chunk reply flags (for structured and extended replies) */ #define NBD_REPLY_FLAG_DONE (1 << 0) /* This reply-chunk is last = */ -/* Structured reply types */ +/* Chunk reply types */ #define NBD_REPLY_ERR(value) ((1 << 15) | (value)) -#define NBD_REPLY_TYPE_NONE 0 -#define NBD_REPLY_TYPE_OFFSET_DATA 1 -#define NBD_REPLY_TYPE_OFFSET_HOLE 2 -#define NBD_REPLY_TYPE_BLOCK_STATUS 5 -#define NBD_REPLY_TYPE_ERROR NBD_REPLY_ERR(1) -#define NBD_REPLY_TYPE_ERROR_OFFSET NBD_REPLY_ERR(2) +#define NBD_REPLY_TYPE_NONE 0 +#define NBD_REPLY_TYPE_OFFSET_DATA 1 +#define NBD_REPLY_TYPE_OFFSET_HOLE 2 +#define NBD_REPLY_TYPE_BLOCK_STATUS 5 +#define NBD_REPLY_TYPE_BLOCK_STATUS_EXT 6 +#define NBD_REPLY_TYPE_ERROR NBD_REPLY_ERR(1) +#define NBD_REPLY_TYPE_ERROR_OFFSET NBD_REPLY_ERR(2) /* Extent flags for base:allocation in NBD_REPLY_TYPE_BLOCK_STATUS */ #define NBD_STATE_HOLE (1 << 0) diff --git a/nbd/nbd-internal.h b/nbd/nbd-internal.h index df42fef7066..133b1d94b50 100644 --- a/nbd/nbd-internal.h +++ b/nbd/nbd-internal.h @@ -1,7 +1,7 @@ /* * NBD Internal Declarations * - * Copyright (C) 2016 Red Hat, Inc. + * Copyright Red Hat * * This work is licensed under the terms of the GNU GPL, version 2 or late= r. * See the COPYING file in the top-level directory. @@ -44,7 +44,6 @@ #define NBD_OLDSTYLE_NEGOTIATE_SIZE (8 + 8 + 8 + 4 + 124) #define NBD_INIT_MAGIC 0x4e42444d41474943LL /* ASCII "NBDMAGI= C" */ -#define NBD_REQUEST_MAGIC 0x25609513 #define NBD_OPTS_MAGIC 0x49484156454F5054LL /* ASCII "IHAVEOP= T" */ #define NBD_CLIENT_MAGIC 0x0000420281861253LL #define NBD_REP_MAGIC 0x0003e889045565a9LL diff --git a/block/nbd.c b/block/nbd.c index 24f50b79e47..9e99a4ddb52 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -610,7 +610,7 @@ static int nbd_parse_offset_hole_payload(BDRVNBDState *= s, static int nbd_parse_blockstatus_payload(BDRVNBDState *s, NBDStructuredReplyChunk *chunk, uint8_t *payload, uint64_t orig_l= ength, - NBDExtent *extent, Error **errp) + NBDExtent32 *extent, Error **errp) { uint32_t context_id; @@ -1118,7 +1118,7 @@ nbd_co_receive_cmdread_reply(BDRVNBDState *s, uint64_= t cookie, static int coroutine_fn nbd_co_receive_blockstatus_reply(BDRVNBDState *s, uint64_t cookie, - uint64_t length, NBDExtent *extent, + uint64_t length, NBDExtent32 *extent, int *request_ret, Error **errp) { NBDReplyChunkIter iter; @@ -1373,7 +1373,7 @@ static int coroutine_fn GRAPH_RDLOCK nbd_client_co_bl= ock_status( int64_t *pnum, int64_t *map, BlockDriverState **file) { int ret, request_ret; - NBDExtent extent =3D { 0 }; + NBDExtent32 extent =3D { 0 }; BDRVNBDState *s =3D (BDRVNBDState *)bs->opaque; Error *local_err =3D NULL; diff --git a/nbd/common.c b/nbd/common.c index 989fbe54a19..3247c1d618a 100644 --- a/nbd/common.c +++ b/nbd/common.c @@ -79,6 +79,8 @@ const char *nbd_opt_lookup(uint32_t opt) return "list meta context"; case NBD_OPT_SET_META_CONTEXT: return "set meta context"; + case NBD_OPT_EXTENDED_HEADERS: + return "extended headers"; default: return ""; } @@ -112,6 +114,10 @@ const char *nbd_rep_lookup(uint32_t rep) return "server shutting down"; case NBD_REP_ERR_BLOCK_SIZE_REQD: return "block size required"; + case NBD_REP_ERR_TOO_BIG: + return "option payload too big"; + case NBD_REP_ERR_EXT_HEADER_REQD: + return "extended headers required"; default: return ""; } @@ -170,7 +176,9 @@ const char *nbd_reply_type_lookup(uint16_t type) case NBD_REPLY_TYPE_OFFSET_HOLE: return "hole"; case NBD_REPLY_TYPE_BLOCK_STATUS: - return "block status"; + return "block status (32-bit)"; + case NBD_REPLY_TYPE_BLOCK_STATUS_EXT: + return "block status (64-bit)"; case NBD_REPLY_TYPE_ERROR: return "generic error"; case NBD_REPLY_TYPE_ERROR_OFFSET: @@ -261,6 +269,8 @@ const char *nbd_mode_lookup(NBDMode mode) return "simple headers"; case NBD_MODE_STRUCTURED: return "structured replies"; + case NBD_MODE_EXTENDED: + return "extended headers"; default: return ""; } diff --git a/nbd/server.c b/nbd/server.c index 936c35e55c6..35fcd9fdbc9 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2072,7 +2072,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, } typedef struct NBDExtentArray { - NBDExtent *extents; + NBDExtent32 *extents; unsigned int nb_alloc; unsigned int count; uint64_t total_length; @@ -2085,7 +2085,7 @@ static NBDExtentArray *nbd_extent_array_new(unsigned = int nb_alloc) NBDExtentArray *ea =3D g_new0(NBDExtentArray, 1); ea->nb_alloc =3D nb_alloc; - ea->extents =3D g_new(NBDExtent, nb_alloc); + ea->extents =3D g_new(NBDExtent32, nb_alloc); ea->can_add =3D true; return ea; @@ -2148,7 +2148,7 @@ static int nbd_extent_array_add(NBDExtentArray *ea, } ea->total_length +=3D length; - ea->extents[ea->count] =3D (NBDExtent) {.length =3D length, .flags =3D= flags}; + ea->extents[ea->count] =3D (NBDExtent32) {.length =3D length, .flags = =3D flags}; ea->count++; return 0; --=20 2.41.0 From nobody Sun May 19 01:15:05 2024 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=1695668586; cv=none; d=zohomail.com; s=zohoarc; b=oHdLIm61CeiBwkvXRe2XHkywkyFekH1c9PwnQghp31/mTR/rr2QY+SbOBxMyzNRA1pVnhkdVntGo1YxWjboGvJPTZMJzwjj8+3DTUjGvzJ+5wObakdcXYaajDNHaIzL1NiINSU9rzyK7W2q9sI2odraVKnxwnKUGGOO6wZ9v4VY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668586; 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=dDvsHkAsTZQVDMoV7RNUkHXj5CX094pkquz1q+xLeVs=; b=j0NAw5/KVQ6N0oAvYibS6FJwSX+9gNExYV1+TUQsVt9IzIKKeXwJYZuLSBp4apxjbjA6Pxb23uKO3AikRbTzT0a9OwZqQx7qI7d8lwJ/9uN/yYLinYWTyevPVqaoSXg4i1X0ru/B5Gm5aC1rQilFwYI+WRerx4w8ORCWl1XyNmQ= 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 1695668586794959.5022209934452; Mon, 25 Sep 2023 12:03:06 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqr2-0002tM-Fj; Mon, 25 Sep 2023 15:02:49 -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 1qkqqq-0002qV-AW for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:36 -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 1qkqql-0005Y9-Jb for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:36 -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-523-WNHchn3YOMOU3AttOMWn6A-1; Mon, 25 Sep 2023 15:02:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9A9C18312C5; Mon, 25 Sep 2023 19:02:26 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 673ECC15BB8; Mon, 25 Sep 2023 19:02:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668550; 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=dDvsHkAsTZQVDMoV7RNUkHXj5CX094pkquz1q+xLeVs=; b=VY2TUeT4/jTJ7UDoZ0o0a3l3IxVj6vOceeqzhNR94fR4khBoF80elGROh7n+sskO+X2sDT HMxTICvjhG6cCPjFeb/x+F3z/KaLbK4mjC8DH07pVaZX3ee7YuAX/YyiVRY9+49O2iCqr1 WgHZBWbCCtKzORH39FzvmSTfivCHgFI= X-MC-Unique: WNHchn3YOMOU3AttOMWn6A-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , Kevin Wolf , Hanna Reitz , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 6/7] nbd: Prepare for 64-bit request effect lengths Date: Mon, 25 Sep 2023 14:01:21 -0500 Message-ID: <20230925190114.3163545-15-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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=unavailable 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: 1695668587417100003 Content-Type: text/plain; charset="utf-8" Widen the length field of NBDRequest to 64-bits, although we can assert that all current uses are still under 32 bits: either because of NBD_MAX_BUFFER_SIZE which is even smaller (and where size_t can still be appropriate, even on 32-bit platforms), or because nothing ever puts us into NBD_MODE_EXTENDED yet (and while future patches will allow larger transactions, the lengths in play here are still capped at 32-bit). There are no semantic changes, other than a typo fix in a couple of error messages. Signed-off-by: Eric Blake Message-ID: <20230829175826.377251-23-eblake@redhat.com> [eblake: fix assertion bug in nbd_co_send_simple_reply] Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/nbd.h | 4 ++-- block/nbd.c | 25 +++++++++++++++++++------ nbd/client.c | 1 + nbd/server.c | 23 +++++++++++++++-------- block/trace-events | 2 +- nbd/trace-events | 14 +++++++------- 6 files changed, 45 insertions(+), 24 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 22a9b5d10e0..8a765e78dfb 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -71,8 +71,8 @@ typedef enum NBDMode { */ typedef struct NBDRequest { uint64_t cookie; - uint64_t from; - uint32_t len; + uint64_t from; /* Offset touched by the command */ + uint64_t len; /* Effect length; 32 bit limit without extended header= s */ uint16_t flags; /* NBD_CMD_FLAG_* */ uint16_t type; /* NBD_CMD_* */ NBDMode mode; /* Determines which network representation to use */ diff --git a/block/nbd.c b/block/nbd.c index 9e99a4ddb52..4a7f37da1c6 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1305,10 +1305,11 @@ nbd_client_co_pwrite_zeroes(BlockDriverState *bs, i= nt64_t offset, int64_t bytes, NBDRequest request =3D { .type =3D NBD_CMD_WRITE_ZEROES, .from =3D offset, - .len =3D bytes, /* .len is uint32_t actually */ + .len =3D bytes, }; - assert(bytes <=3D UINT32_MAX); /* rely on max_pwrite_zeroes */ + /* rely on max_pwrite_zeroes */ + assert(bytes <=3D UINT32_MAX || s->info.mode >=3D NBD_MODE_EXTENDED); assert(!(s->info.flags & NBD_FLAG_READ_ONLY)); if (!(s->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) { @@ -1355,10 +1356,11 @@ nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int64_t bytes) NBDRequest request =3D { .type =3D NBD_CMD_TRIM, .from =3D offset, - .len =3D bytes, /* len is uint32_t */ + .len =3D bytes, }; - assert(bytes <=3D UINT32_MAX); /* rely on max_pdiscard */ + /* rely on max_pdiscard */ + assert(bytes <=3D UINT32_MAX || s->info.mode >=3D NBD_MODE_EXTENDED); assert(!(s->info.flags & NBD_FLAG_READ_ONLY)); if (!(s->info.flags & NBD_FLAG_SEND_TRIM) || !bytes) { @@ -1380,8 +1382,7 @@ static int coroutine_fn GRAPH_RDLOCK nbd_client_co_bl= ock_status( NBDRequest request =3D { .type =3D NBD_CMD_BLOCK_STATUS, .from =3D offset, - .len =3D MIN(QEMU_ALIGN_DOWN(INT_MAX, bs->bl.request_alignment), - MIN(bytes, s->info.size - offset)), + .len =3D MIN(bytes, s->info.size - offset), .flags =3D NBD_CMD_FLAG_REQ_ONE, }; @@ -1391,6 +1392,10 @@ static int coroutine_fn GRAPH_RDLOCK nbd_client_co_b= lock_status( *file =3D bs; return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } + if (s->info.mode < NBD_MODE_EXTENDED) { + request.len =3D MIN(QEMU_ALIGN_DOWN(INT_MAX, bs->bl.request_alignm= ent), + request.len); + } /* * Work around the fact that the block layer doesn't do @@ -1955,6 +1960,14 @@ static void nbd_refresh_limits(BlockDriverState *bs,= Error **errp) bs->bl.max_pwrite_zeroes =3D max; bs->bl.max_transfer =3D max; + /* + * Assume that if the server supports extended headers, it also + * supports unlimited size zero and trim commands. + */ + if (s->info.mode >=3D NBD_MODE_EXTENDED) { + bs->bl.max_pdiscard =3D bs->bl.max_pwrite_zeroes =3D 0; + } + if (s->info.opt_block && s->info.opt_block > bs->bl.opt_transfer) { bs->bl.opt_transfer =3D s->info.opt_block; diff --git a/nbd/client.c b/nbd/client.c index 345f1c0f2d0..cecb0f04377 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1349,6 +1349,7 @@ int nbd_send_request(QIOChannel *ioc, NBDRequest *req= uest) uint8_t buf[NBD_REQUEST_SIZE]; assert(request->mode <=3D NBD_MODE_STRUCTURED); /* TODO handle extende= d */ + assert(request->len <=3D UINT32_MAX); trace_nbd_send_request(request->from, request->len, request->cookie, request->flags, request->type, nbd_cmd_lookup(request->type)); diff --git a/nbd/server.c b/nbd/server.c index 35fcd9fdbc9..0ca0a4c5c25 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1165,7 +1165,7 @@ static int nbd_negotiate_options(NBDClient *client, E= rror **errp) client->optlen =3D length; if (length > NBD_MAX_BUFFER_SIZE) { - error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u= )", + error_setg(errp, "len (%" PRIu32 ") is larger than max len (%u= )", length, NBD_MAX_BUFFER_SIZE); return -EINVAL; } @@ -1437,7 +1437,7 @@ static int coroutine_fn nbd_receive_request(NBDClient= *client, NBDRequest *reque request->type =3D lduw_be_p(buf + 6); request->cookie =3D ldq_be_p(buf + 8); request->from =3D ldq_be_p(buf + 16); - request->len =3D ldl_be_p(buf + 24); + request->len =3D (uint32_t)ldl_be_p(buf + 24); /* widen 32 to 64 bi= ts */ trace_nbd_receive_request(magic, request->flags, request->type, request->from, request->len); @@ -1887,7 +1887,7 @@ static int coroutine_fn nbd_co_send_simple_reply(NBDC= lient *client, NBDRequest *request, uint32_t error, void *data, - size_t len, + uint64_t len, Error **errp) { NBDSimpleReply reply; @@ -1898,6 +1898,7 @@ static int coroutine_fn nbd_co_send_simple_reply(NBDC= lient *client, }; assert(!len || !nbd_err); + assert(len <=3D NBD_MAX_BUFFER_SIZE); assert(client->mode < NBD_MODE_STRUCTURED || (client->mode =3D=3D NBD_MODE_STRUCTURED && request->type !=3D NBD_CMD_READ)); @@ -1956,7 +1957,7 @@ static int coroutine_fn nbd_co_send_chunk_read(NBDCli= ent *client, NBDRequest *request, uint64_t offset, void *data, - size_t size, + uint64_t size, bool final, Error **errp) { @@ -1968,7 +1969,7 @@ static int coroutine_fn nbd_co_send_chunk_read(NBDCli= ent *client, {.iov_base =3D data, .iov_len =3D size} }; - assert(size); + assert(size && size <=3D NBD_MAX_BUFFER_SIZE); trace_nbd_co_send_chunk_read(request->cookie, offset, data, size); set_be_chunk(client, iov, 3, final ? NBD_REPLY_FLAG_DONE : 0, NBD_REPLY_TYPE_OFFSET_DATA, request); @@ -2011,13 +2012,14 @@ static int coroutine_fn nbd_co_send_sparse_read(NBD= Client *client, NBDRequest *request, uint64_t offset, uint8_t *data, - size_t size, + uint64_t size, Error **errp) { int ret =3D 0; NBDExport *exp =3D client->exp; size_t progress =3D 0; + assert(size <=3D NBD_MAX_BUFFER_SIZE); while (progress < size) { int64_t pnum; int status =3D blk_co_block_status_above(exp->common.blk, NULL, @@ -2347,7 +2349,7 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, NBDRequest * request->type =3D=3D NBD_CMD_CACHE) { if (request->len > NBD_MAX_BUFFER_SIZE) { - error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u= )", + error_setg(errp, "len (%" PRIu64 ") is larger than max len (%u= )", request->len, NBD_MAX_BUFFER_SIZE); return -EINVAL; } @@ -2363,6 +2365,7 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, NBDRequest * } if (request->type =3D=3D NBD_CMD_WRITE) { + assert(request->len <=3D NBD_MAX_BUFFER_SIZE); if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data= ", errp) < 0) { @@ -2384,7 +2387,7 @@ static int coroutine_fn nbd_co_receive_request(NBDReq= uestData *req, NBDRequest * } if (request->from > client->exp->size || request->len > client->exp->size - request->from) { - error_setg(errp, "operation past EOF; From: %" PRIu64 ", Len: %" P= RIu32 + error_setg(errp, "operation past EOF; From: %" PRIu64 ", Len: %" P= RIu64 ", Size: %" PRIu64, request->from, request->len, client->exp->size); return (request->type =3D=3D NBD_CMD_WRITE || @@ -2446,6 +2449,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, NBDExport *exp =3D client->exp; assert(request->type =3D=3D NBD_CMD_READ); + assert(request->len <=3D NBD_MAX_BUFFER_SIZE); /* XXX: NBD Protocol only documents use of FUA with WRITE */ if (request->flags & NBD_CMD_FLAG_FUA) { @@ -2496,6 +2500,7 @@ static coroutine_fn int nbd_do_cmd_cache(NBDClient *c= lient, NBDRequest *request, NBDExport *exp =3D client->exp; assert(request->type =3D=3D NBD_CMD_CACHE); + assert(request->len <=3D NBD_MAX_BUFFER_SIZE); ret =3D blk_co_preadv(exp->common.blk, request->from, request->len, NULL, BDRV_REQ_COPY_ON_READ | BDRV_REQ_PREFETCH); @@ -2529,6 +2534,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, if (request->flags & NBD_CMD_FLAG_FUA) { flags |=3D BDRV_REQ_FUA; } + assert(request->len <=3D NBD_MAX_BUFFER_SIZE); ret =3D blk_co_pwrite(exp->common.blk, request->from, request->len= , data, flags); return nbd_send_generic_reply(client, request, ret, @@ -2572,6 +2578,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, return nbd_send_generic_reply(client, request, -EINVAL, "need non-zero length", errp); } + assert(request->len <=3D UINT32_MAX); if (client->export_meta.count) { bool dont_fragment =3D request->flags & NBD_CMD_FLAG_REQ_ONE; int contexts_remaining =3D client->export_meta.count; diff --git a/block/trace-events b/block/trace-events index 6f121b76365..925aa554bbf 100644 --- a/block/trace-events +++ b/block/trace-events @@ -167,7 +167,7 @@ iscsi_xcopy(void *src_lun, uint64_t src_off, void *dst_= lun, uint64_t dst_off, ui nbd_parse_blockstatus_compliance(const char *err) "ignoring extra data fro= m non-compliant server: %s" nbd_structured_read_compliance(const char *type) "server sent non-complian= t unaligned read %s chunk" nbd_read_reply_entry_fail(int ret, const char *err) "ret =3D %d, err: %s" -nbd_co_request_fail(uint64_t from, uint32_t len, uint64_t handle, uint16_t= flags, uint16_t type, const char *name, int ret, const char *err) "Request= failed { .from =3D %" PRIu64", .len =3D %" PRIu32 ", .handle =3D %" PRIu64= ", .flags =3D 0x%" PRIx16 ", .type =3D %" PRIu16 " (%s) } ret =3D %d, err:= %s" +nbd_co_request_fail(uint64_t from, uint64_t len, uint64_t handle, uint16_t= flags, uint16_t type, const char *name, int ret, const char *err) "Request= failed { .from =3D %" PRIu64", .len =3D %" PRIu64 ", .handle =3D %" PRIu64= ", .flags =3D 0x%" PRIx16 ", .type =3D %" PRIu16 " (%s) } ret =3D %d, err:= %s" nbd_client_handshake(const char *export_name) "export '%s'" nbd_client_handshake_success(const char *export_name) "export '%s'" nbd_reconnect_attempt(unsigned in_flight) "in_flight %u" diff --git a/nbd/trace-events b/nbd/trace-events index f19a4d0db39..f9dccfcfb44 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -31,7 +31,7 @@ nbd_client_loop(void) "Doing NBD loop" nbd_client_loop_ret(int ret, const char *error) "NBD loop returned %d: %s" nbd_client_clear_queue(void) "Clearing NBD queue" nbd_client_clear_socket(void) "Clearing NBD socket" -nbd_send_request(uint64_t from, uint32_t len, uint64_t cookie, uint16_t fl= ags, uint16_t type, const char *name) "Sending request to server: { .from = =3D %" PRIu64", .len =3D %" PRIu32 ", .cookie =3D %" PRIu64 ", .flags =3D 0= x%" PRIx16 ", .type =3D %" PRIu16 " (%s) }" +nbd_send_request(uint64_t from, uint64_t len, uint64_t cookie, uint16_t fl= ags, uint16_t type, const char *name) "Sending request to server: { .from = =3D %" PRIu64", .len =3D %" PRIu64 ", .cookie =3D %" PRIu64 ", .flags =3D 0= x%" PRIx16 ", .type =3D %" PRIu16 " (%s) }" nbd_receive_simple_reply(int32_t error, const char *errname, uint64_t cook= ie) "Got simple reply: { .error =3D %" PRId32 " (%s), cookie =3D %" PRIu64"= }" nbd_receive_structured_reply_chunk(uint16_t flags, uint16_t type, const ch= ar *name, uint64_t cookie, uint32_t length) "Got structured reply chunk: { = flags =3D 0x%" PRIx16 ", type =3D %d (%s), cookie =3D %" PRIu64 ", length = =3D %" PRIu32 " }" @@ -60,18 +60,18 @@ nbd_negotiate_options_check_option(uint32_t option, con= st char *name) "Checking nbd_negotiate_begin(void) "Beginning negotiation" nbd_negotiate_new_style_size_flags(uint64_t size, unsigned flags) "adverti= sing size %" PRIu64 " and flags 0x%x" nbd_negotiate_success(void) "Negotiation succeeded" -nbd_receive_request(uint32_t magic, uint16_t flags, uint16_t type, uint64_= t from, uint32_t len) "Got request: { magic =3D 0x%" PRIx32 ", .flags =3D 0= x%" PRIx16 ", .type =3D 0x%" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRI= u32 " }" +nbd_receive_request(uint32_t magic, uint16_t flags, uint16_t type, uint64_= t from, uint64_t len) "Got request: { magic =3D 0x%" PRIx32 ", .flags =3D 0= x%" PRIx16 ", .type =3D 0x%" PRIx16 ", from =3D %" PRIu64 ", len =3D %" PRI= u64 " }" nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p" nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p" -nbd_co_send_simple_reply(uint64_t cookie, uint32_t error, const char *errn= ame, int len) "Send simple reply: cookie =3D %" PRIu64 ", error =3D %" PRIu= 32 " (%s), len =3D %d" +nbd_co_send_simple_reply(uint64_t cookie, uint32_t error, const char *errn= ame, uint64_t len) "Send simple reply: cookie =3D %" PRIu64 ", error =3D %"= PRIu32 " (%s), len =3D %" PRIu64 nbd_co_send_chunk_done(uint64_t cookie) "Send structured reply done: cooki= e =3D %" PRIu64 -nbd_co_send_chunk_read(uint64_t cookie, uint64_t offset, void *data, size_= t size) "Send structured read data reply: cookie =3D %" PRIu64 ", offset = =3D %" PRIu64 ", data =3D %p, len =3D %zu" -nbd_co_send_chunk_read_hole(uint64_t cookie, uint64_t offset, size_t size)= "Send structured read hole reply: cookie =3D %" PRIu64 ", offset =3D %" PR= Iu64 ", len =3D %zu" +nbd_co_send_chunk_read(uint64_t cookie, uint64_t offset, void *data, uint6= 4_t size) "Send structured read data reply: cookie =3D %" PRIu64 ", offset = =3D %" PRIu64 ", data =3D %p, len =3D %" PRIu64 +nbd_co_send_chunk_read_hole(uint64_t cookie, uint64_t offset, uint64_t siz= e) "Send structured read hole reply: cookie =3D %" PRIu64 ", offset =3D %" = PRIu64 ", len =3D %" PRIu64 nbd_co_send_extents(uint64_t cookie, unsigned int extents, uint32_t id, ui= nt64_t length, int last) "Send block status reply: cookie =3D %" PRIu64 ", = extents =3D %u, context =3D %d (extents cover %" PRIu64 " bytes, last chunk= =3D %d)" 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, uint32_t len) "Pa= yload received: cookie =3D %" PRIu64 ", len =3D %" PRIu32 -nbd_co_receive_align_compliance(const char *op, uint64_t from, uint32_t le= n, uint32_t align) "client sent non-compliant unaligned %s request: from=3D= 0x%" PRIx64 ", len=3D0x%" PRIx32 ", align=3D0x%" PRIx32 +nbd_co_receive_request_payload_received(uint64_t cookie, uint64_t len) "Pa= yload received: cookie =3D %" PRIu64 ", len =3D %" PRIu64 +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" # client-connection.c --=20 2.41.0 From nobody Sun May 19 01:15:05 2024 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=1695668681; cv=none; d=zohomail.com; s=zohoarc; b=QsycVxD5YGBq6nycg6R7tUMxH2gqxfM/MnuG6WEHxmN5lfF1/BnasI8RxXiuCQFWvnmwaTAWeZeaJNgYff2kkUuIp0yDc8aIWN1wb2z/CpYvuoO53Lfum17e2fWyUDHlPmrPOcYvWq6knYxxb5fEiS68Co2cPBr0dTLFxYPWgfk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1695668681; 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=3WtU/wxbnIFHSOQudlz+eJvKqNN/TkZju0/TeOBbOhA=; b=YjLmZabSpsLHOqboep/dxtTwFnK+/iNxSL6WG+uepkGJQQtZNQH8nsr00YTwlVWyqIuRlKpCYonOYsU1achHJrvAUh5VShMO1fIbI4bJ6rIsDgIiIE1f7PmeMWl6WKmXUKofeNAp3T2Ym7xS14Pphci71rXfh69Ju1kxdibYz5Q= 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 1695668681447284.4537051049191; Mon, 25 Sep 2023 12:04:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qkqr4-0002ur-Ju; Mon, 25 Sep 2023 15:02:50 -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 1qkqqr-0002rb-Nr for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:38 -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 1qkqqm-0005YQ-3s for qemu-devel@nongnu.org; Mon, 25 Sep 2023 15:02:37 -0400 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-b-ULmEU1N9Cp88PvcfR1sg-1; Mon, 25 Sep 2023 15:02:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 701A81C06501; Mon, 25 Sep 2023 19:02:27 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E977C15BB8; Mon, 25 Sep 2023 19:02:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695668551; 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=3WtU/wxbnIFHSOQudlz+eJvKqNN/TkZju0/TeOBbOhA=; b=J/uYg5PlKTh78C7GgTzZ4wogVQCcsK8Q6kfiBScHK1dVl5JnPbIAFqpsh7so4gv612wB8L 7PF8/aXdnPFQ1c1T8mbXjDM30AobzW39cW2OsaMgB81PaCHZHW0E5JauiBVIB1Jxfcnen0 qJCrjmhwUWsBbnpP2bWL/eNAUpGBomo= X-MC-Unique: b-ULmEU1N9Cp88PvcfR1sg-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 7/7] nbd/server: Refactor handling of command sanity checks Date: Mon, 25 Sep 2023 14:01:22 -0500 Message-ID: <20230925190114.3163545-16-eblake@redhat.com> In-Reply-To: <20230925190114.3163545-9-eblake@redhat.com> References: <20230925190114.3163545-9-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 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: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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: 1695668683419100003 Content-Type: text/plain; charset="utf-8" Upcoming additions to support NBD 64-bit effect lengths will add a new command flag NBD_CMD_FLAG_PAYLOAD_LEN that needs to be considered in our sanity checks of the client's messages (that is, more than just CMD_WRITE have the potential to carry a client payload when extended headers are in effect). But before we can start to support that, it is easier to first refactor the existing set of various if statements over open-coded combinations of request->type to instead be a single switch statement over all command types that sets witnesses, then straight-line processing based on the witnesses. No semantic change is intended. Signed-off-by: Eric Blake Message-ID: <20230829175826.377251-24-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 118 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 74 insertions(+), 44 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 0ca0a4c5c25..7a6f95071f8 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2317,11 +2317,16 @@ static int coroutine_fn nbd_co_send_bitmap(NBDClien= t *client, * to the client (although the caller may still need to disconnect after * reporting the error). */ -static int coroutine_fn nbd_co_receive_request(NBDRequestData *req, NBDReq= uest *request, +static int coroutine_fn nbd_co_receive_request(NBDRequestData *req, + NBDRequest *request, Error **errp) { NBDClient *client =3D req->client; - int valid_flags; + bool check_length =3D false; + bool check_rofs =3D false; + bool allocate_buffer =3D false; + unsigned payload_len =3D 0; + int valid_flags =3D NBD_CMD_FLAG_FUA; int ret; g_assert(qemu_in_coroutine()); @@ -2333,55 +2338,88 @@ static int coroutine_fn nbd_co_receive_request(NBDR= equestData *req, NBDRequest * trace_nbd_co_receive_request_decode_type(request->cookie, request->typ= e, nbd_cmd_lookup(request->type)= ); - - if (request->type !=3D NBD_CMD_WRITE) { - /* No payload, we are ready to read the next request. */ - req->complete =3D true; - } - - if (request->type =3D=3D NBD_CMD_DISC) { + switch (request->type) { + case NBD_CMD_DISC: /* Special case: we're going to disconnect without a reply, * whether or not flags, from, or len are bogus */ + req->complete =3D true; return -EIO; - } - if (request->type =3D=3D NBD_CMD_READ || request->type =3D=3D NBD_CMD_= WRITE || - request->type =3D=3D NBD_CMD_CACHE) - { - if (request->len > NBD_MAX_BUFFER_SIZE) { - error_setg(errp, "len (%" PRIu64 ") is larger than max len (%u= )", - request->len, NBD_MAX_BUFFER_SIZE); - return -EINVAL; + case NBD_CMD_READ: + if (client->mode >=3D NBD_MODE_STRUCTURED) { + valid_flags |=3D NBD_CMD_FLAG_DF; } + check_length =3D true; + allocate_buffer =3D true; + break; - if (request->type !=3D NBD_CMD_CACHE) { - req->data =3D blk_try_blockalign(client->exp->common.blk, - request->len); - if (req->data =3D=3D NULL) { - error_setg(errp, "No memory"); - return -ENOMEM; - } - } + case NBD_CMD_WRITE: + payload_len =3D request->len; + check_length =3D true; + allocate_buffer =3D true; + check_rofs =3D true; + break; + + case NBD_CMD_FLUSH: + break; + + case NBD_CMD_TRIM: + check_rofs =3D true; + break; + + case NBD_CMD_CACHE: + check_length =3D true; + break; + + case NBD_CMD_WRITE_ZEROES: + valid_flags |=3D NBD_CMD_FLAG_NO_HOLE | NBD_CMD_FLAG_FAST_ZERO; + check_rofs =3D true; + break; + + case NBD_CMD_BLOCK_STATUS: + valid_flags |=3D NBD_CMD_FLAG_REQ_ONE; + break; + + default: + /* Unrecognized, will fail later */ + ; } - if (request->type =3D=3D NBD_CMD_WRITE) { - assert(request->len <=3D NBD_MAX_BUFFER_SIZE); - if (nbd_read(client->ioc, req->data, request->len, "CMD_WRITE data= ", - errp) < 0) - { + /* Payload and buffer handling. */ + if (!payload_len) { + req->complete =3D true; + } + if (check_length && request->len > NBD_MAX_BUFFER_SIZE) { + /* READ, WRITE, CACHE */ + error_setg(errp, "len (%" PRIu64 ") is larger than max len (%u)", + request->len, NBD_MAX_BUFFER_SIZE); + return -EINVAL; + } + if (allocate_buffer) { + /* READ, WRITE */ + req->data =3D blk_try_blockalign(client->exp->common.blk, + request->len); + if (req->data =3D=3D NULL) { + error_setg(errp, "No memory"); + return -ENOMEM; + } + } + if (payload_len) { + /* WRITE */ + assert(req->data); + ret =3D nbd_read(client->ioc, req->data, payload_len, + "CMD_WRITE data", errp); + if (ret < 0) { return -EIO; } req->complete =3D true; - trace_nbd_co_receive_request_payload_received(request->cookie, - request->len); + payload_len); } /* Sanity checks. */ - if (client->exp->nbdflags & NBD_FLAG_READ_ONLY && - (request->type =3D=3D NBD_CMD_WRITE || - request->type =3D=3D NBD_CMD_WRITE_ZEROES || - request->type =3D=3D NBD_CMD_TRIM)) { + if (client->exp->nbdflags & NBD_FLAG_READ_ONLY && check_rofs) { + /* WRITE, TRIM, WRITE_ZEROES */ error_setg(errp, "Export is read-only"); return -EROFS; } @@ -2404,14 +2442,6 @@ static int coroutine_fn nbd_co_receive_request(NBDRe= questData *req, NBDRequest * request->len, client->check_align); } - valid_flags =3D NBD_CMD_FLAG_FUA; - if (request->type =3D=3D NBD_CMD_READ && client->mode >=3D NBD_MODE_ST= RUCTURED) { - 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 | NBD_CMD_FLAG_FAST_ZERO; - } else if (request->type =3D=3D NBD_CMD_BLOCK_STATUS) { - valid_flags |=3D NBD_CMD_FLAG_REQ_ONE; - } if (request->flags & ~valid_flags) { error_setg(errp, "unsupported flags for command %s (got 0x%x)", nbd_cmd_lookup(request->type), request->flags); --=20 2.41.0