From nobody Mon Feb 9 16:12:55 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 ARC-Seal: i=1; a=rsa-sha256; t=1615206829; cv=none; d=zohomail.com; s=zohoarc; b=V6UveeQyZIsvpN+n4DhWGfbfKQLjsnS2zH0iciFH+3aWE80k81BqxretFx+tsgnimFpu4ndNd6fp5tVXRp51DImE5+YVgGhfA27nsGJ82EwybfPgzm+9/8b41Hb3xa1TtK42QB9cSettbRxiwu5WKf/hfi0r+cgTGYaMqYZpig8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615206829; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=62hI8Sl1+AOh0EDJGsNyANbqeAo7S+ls4HuSt2updQY=; b=ZDu4w5yoyuGdkuPh4HUBk4C9vw6nl8DSDjxUI33/GLc9mD8Mf3R5/abo/uFM2M0brh9GhCKXG2UngBiQ7jnBn8xa5GSPfqfobwX1rdBMjx+5wU22gW+5dIxOv2R8dm+unge08u7FsxQ3vWvbOZ0RlKRbN44BvWddRV975hSf4Y4= ARC-Authentication-Results: i=1; mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1615206829099552.1806709454859; Mon, 8 Mar 2021 04:33:49 -0800 (PST) Received: from localhost ([::1]:54026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJF51-0000fd-Jj for importer@patchew.org; Mon, 08 Mar 2021 07:33:47 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36050) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJEv9-00032M-0b; Mon, 08 Mar 2021 07:23:35 -0500 Received: from wnew4-smtp.messagingengine.com ([64.147.123.18]:58359) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJEv2-0006ux-L4; Mon, 08 Mar 2021 07:23:34 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id 40A8C36C8; Mon, 8 Mar 2021 07:23:26 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 08 Mar 2021 07:23:27 -0500 Received: from apples.local (80-167-98-190-cable.dk.customer.tdc.net [80.167.98.190]) by mail.messagingengine.com (Postfix) with ESMTPA id 6598E108005C; Mon, 8 Mar 2021 07:23:24 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irrelevant.dk; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=fm2; bh=62hI8Sl1+AOh0 EDJGsNyANbqeAo7S+ls4HuSt2updQY=; b=fsLSJHL31kYq9oyMP4AqTu8YJug84 MVX/b7/ssVWC62KCrh7Dn89kumWGE1lznCK3RRi9yADT3QvIP5ugyPcmzJnrlSE2 nPCc3xz7DtLjylvETzt9StKJkMab6rXmRYSSFvPcCv3gzflM+HjaasIAy9i+Dzii eN3gYH1Z1FbjiQ8aJWhG0ZYXi1Ql83fXTK2hR/d1jiGzopk4KDiy9Bo/nBSSD3xd 03yAnuyIFqUUDAn7vC9EHQWIy2b1cxIxPJjGY5OvwvXVOLM672Y75/MBj8koRZ22 CUflJNAGEV3PHOC1ZKmd2Q9cKrIDwdSzIpkj6rK/lnov4uG3vxX3p46xA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=62hI8Sl1+AOh0EDJGsNyANbqeAo7S+ls4HuSt2updQY=; b=eCfgJe59 /oyyclGfDHrEQs5y9FDVZiBYvnvAORa4G13jnhoXohRNTljTWrFkFzPeup8YbW1Y R3zeZy5cLG1PwgJKh9HgyuWmiggoCpw0i6Tx2ZpVecuKcF4LAnbGBEGAMTI3HZpe eEYCBsqc0aBzxlDvIdx/OoEyJvFLBxq6bp4xi5iDdDR29+LGjwFI1v+sc74363Sr B27BgJzFETAmFMbcxMQiISTyVtI95ndoBEYRac2z1xs4wBoSLhVD/IxmDR3fP0BE hiJMplg602UsD6YWkyKj8gaZPJdqbUwgdJwswtXDWD+UjLjDWEfRQx0t1ukZ2wgU ct6l/TxSKGE62A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudduvddgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucfkphepkedtrdduieejrdelkedrudeltdenucevlhhushhtvghrufhiiigvpedune curfgrrhgrmhepmhgrihhlfhhrohhmpehithhssehirhhrvghlvghvrghnthdrughk X-ME-Proxy: From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 06/38] hw/block/nvme: support for shared namespace in subsystem Date: Mon, 8 Mar 2021 13:22:41 +0100 Message-Id: <20210308122313.286938-7-its@irrelevant.dk> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210308122313.286938-1-its@irrelevant.dk> References: <20210308122313.286938-1-its@irrelevant.dk> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=64.147.123.18; envelope-from=its@irrelevant.dk; helo=wnew4-smtp.messagingengine.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Klaus Jensen , Max Reitz , Keith Busch , Minwoo Im , Stefan Hajnoczi , Klaus Jensen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Minwoo Im nvme-ns device is registered to a nvme controller device during the initialization in nvme_register_namespace() in case that 'bus' property is given which means it's mapped to a single controller. This patch introduced a new property 'subsys' just like the controller device instance did to map a namespace to a NVMe subsystem. If 'subsys' property is given to the nvme-ns device, it will belong to the specified subsystem and will be attached to all controllers in that subsystem by enabling shared namespace capability in NMIC(Namespace Multi-path I/O and Namespace Capabilities) in Identify Namespace. Usage: -device nvme-subsys,id=3Dsubsys0 -device nvme,serial=3Dfoo,id=3Dnvme0,subsys=3Dsubsys0 -device nvme,serial=3Dbar,id=3Dnvme1,subsys=3Dsubsys0 -device nvme,serial=3Dbaz,id=3Dnvme2,subsys=3Dsubsys0 -device nvme-ns,id=3Dns1,drive=3D,nsid=3D1,subsys=3Dsubsys0 # Shared -device nvme-ns,id=3Dns2,drive=3D,nsid=3D2,bus=3Dnvme2 # Non-s= hared In the above example, 'ns1' will be shared to 'nvme0' and 'nvme1' in the same subsystem. On the other hand, 'ns2' will be attached to the 'nvme2' only as a private namespace in that subsystem. All the namespace with 'subsys' parameter will attach all controllers in the subsystem to the namespace by default. Signed-off-by: Minwoo Im Tested-by: Klaus Jensen Reviewed-by: Klaus Jensen Reviewed-by: Keith Busch Signed-off-by: Klaus Jensen --- hw/block/nvme-ns.h | 7 +++++++ hw/block/nvme-subsys.h | 3 +++ hw/block/nvme-ns.c | 17 ++++++++++++++--- hw/block/nvme-subsys.c | 25 +++++++++++++++++++++++++ hw/block/nvme.c | 10 +++++++++- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/hw/block/nvme-ns.h b/hw/block/nvme-ns.h index 293ac990e3f6..929e78861903 100644 --- a/hw/block/nvme-ns.h +++ b/hw/block/nvme-ns.h @@ -47,6 +47,8 @@ typedef struct NvmeNamespace { const uint32_t *iocs; uint8_t csi; =20 + NvmeSubsystem *subsys; + NvmeIdNsZoned *id_ns_zoned; NvmeZone *zone_array; QTAILQ_HEAD(, NvmeZone) exp_open_zones; @@ -77,6 +79,11 @@ static inline uint32_t nvme_nsid(NvmeNamespace *ns) return -1; } =20 +static inline bool nvme_ns_shared(NvmeNamespace *ns) +{ + return !!ns->subsys; +} + static inline NvmeLBAF *nvme_ns_lbaf(NvmeNamespace *ns) { NvmeIdNs *id_ns =3D &ns->id_ns; diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 4eba50d96a1d..ccf6a71398d3 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -14,6 +14,7 @@ OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS) =20 #define NVME_SUBSYS_MAX_CTRLS 32 +#define NVME_SUBSYS_MAX_NAMESPACES 32 =20 typedef struct NvmeCtrl NvmeCtrl; typedef struct NvmeNamespace NvmeNamespace; @@ -22,8 +23,10 @@ typedef struct NvmeSubsystem { uint8_t subnqn[256]; =20 NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS]; + NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES]; } NvmeSubsystem; =20 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); +int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp); =20 #endif /* NVME_SUBSYS_H */ diff --git a/hw/block/nvme-ns.c b/hw/block/nvme-ns.c index 93ac6e107a09..64b6a491adc3 100644 --- a/hw/block/nvme-ns.c +++ b/hw/block/nvme-ns.c @@ -63,6 +63,10 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp) =20 id_ns->npda =3D id_ns->npdg =3D npdg - 1; =20 + if (nvme_ns_shared(ns)) { + id_ns->nmic |=3D NVME_NMIC_NS_SHARED; + } + return 0; } =20 @@ -363,14 +367,21 @@ static void nvme_ns_realize(DeviceState *dev, Error *= *errp) return; } =20 - if (nvme_register_namespace(n, ns, errp)) { - return; + if (ns->subsys) { + if (nvme_subsys_register_ns(ns, errp)) { + return; + } + } else { + if (nvme_register_namespace(n, ns, errp)) { + return; + } } - } =20 static Property nvme_ns_props[] =3D { DEFINE_BLOCK_PROPERTIES(NvmeNamespace, blkconf), + DEFINE_PROP_LINK("subsys", NvmeNamespace, subsys, TYPE_NVME_SUBSYS, + NvmeSubsystem *), DEFINE_PROP_UINT32("nsid", NvmeNamespace, params.nsid, 0), DEFINE_PROP_UUID("uuid", NvmeNamespace, params.uuid), DEFINE_PROP_BOOL("zoned", NvmeNamespace, params.zoned, false), diff --git a/hw/block/nvme-subsys.c b/hw/block/nvme-subsys.c index e9d61c993c90..641de33e99fc 100644 --- a/hw/block/nvme-subsys.c +++ b/hw/block/nvme-subsys.c @@ -43,6 +43,31 @@ int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp) return cntlid; } =20 +int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp) +{ + NvmeSubsystem *subsys =3D ns->subsys; + NvmeCtrl *n; + int i; + + if (subsys->namespaces[nvme_nsid(ns)]) { + error_setg(errp, "namespace %d already registerd to subsy %s", + nvme_nsid(ns), subsys->parent_obj.id); + return -1; + } + + subsys->namespaces[nvme_nsid(ns)] =3D ns; + + for (i =3D 0; i < ARRAY_SIZE(subsys->ctrls); i++) { + n =3D subsys->ctrls[i]; + + if (n && nvme_register_namespace(n, ns, errp)) { + return -1; + } + } + + return 0; +} + static void nvme_subsys_setup(NvmeSubsystem *subsys) { snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn), diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 4e8e15a82da0..34f9be0199d5 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -25,7 +25,8 @@ * mdts=3D,zoned.append_size_limit=3D, \ * subsys=3D \ * -device nvme-ns,drive=3D,bus=3D,nsid=3D,\ - * zoned=3D + * zoned=3D, \ + * subsys=3D * -device nvme-subsys,id=3D * * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at @@ -70,6 +71,13 @@ * data size being in effect. By setting this property to 0, users can m= ake * ZASL to be equal to MDTS. This property only affects zoned namespaces. * + * nvme namespace device parameters + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * - `subsys` + * NVM Subsystem device. If given, this namespace will be attached to a= ll + * controllers in the subsystem. Otherwise, `bus` must be given to attach + * this namespace to a specified single controller as a non-shared names= pace. + * * Setting `zoned` to true selects Zoned Command Set at the namespace. * In this case, the following namespace properties are available to confi= gure * zoned operation: --=20 2.30.1