From nobody Mon Feb 9 09:29:44 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=1615210744; cv=none; d=zohomail.com; s=zohoarc; b=dk+vR5Q1QNXnjyHsWzSCfnd3F4mpPDUvcBBWJDBHMAv9jtkK/ghuYLuBZDgM3m8cm+zzVAFILmnfinDACFX+/22MJGpqhIJVL4U7Vllish/wU4V+z4stmNU6YPXuHt4UKAQTJVO7FkqvuXhZ41I31WhD2trO2zexykqtH+0LRqw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1615210744; 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=Q7itcGoTqmNSNMmSWuZjgBCbDtOz7K3OK9K5REGHCdo=; b=RnX2i/7mRmyula3rFpIJzCbhJ8OnSkfj7k8oPFEPj1HO+KWaDW9/nx34iRJgfFYVxvnKwIzzfDp87TnUzHF/IzOEaAbWARn524VGVTOecHOlz4IXnZ7ZnvpgnujDuz6lb9H/3rAZ39CWSx+Pe6tlGCrgiqa1ydO2pe8uoRcOfdU= 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 1615210744531748.3538640524347; Mon, 8 Mar 2021 05:39:04 -0800 (PST) Received: from localhost ([::1]:40166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lJG6B-0003SD-6t for importer@patchew.org; Mon, 08 Mar 2021 08:39:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:36554) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJEwJ-0003yC-Iw; Mon, 08 Mar 2021 07:24:47 -0500 Received: from wnew4-smtp.messagingengine.com ([64.147.123.18]:47463) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lJEwH-0007FY-LJ; Mon, 08 Mar 2021 07:24:47 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailnew.west.internal (Postfix) with ESMTP id E4AC536E3; Mon, 8 Mar 2021 07:24:09 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 08 Mar 2021 07:24:10 -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 2889B1080069; Mon, 8 Mar 2021 07:24:08 -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=Q7itcGoTqmNSN MmSWuZjgBCbDtOz7K3OK9K5REGHCdo=; b=VWmSgVjjJSODS3nPaPDaxuJDnQzIj p8d3HEF5onPT46C3O22Dy5fg30oF/3lg4NLSvWzdQAtmnI14qKutz7EPqXcPST+a Hv5M+BqTXo/dps5jLhgUZkbiBAVoy7ftH+vjrqx2aGGuKUhzWFspbPOTMJleuumT l2gkPLnvxub1cXAevCMLrk9OCymHysR3XciaK5EnUgjbLoZXf0I47OhXGrRHMdHy smzgpBXxHfZVBUMFBt3l32jYjfXTp1oOQqo2EFpgXF94ri8A2iCgkXBEpGl6BXsX FFrCVOXGWYcAldRJGKqceUAMzbPOS1wXy48Cc/KdYwtfphSy+BfiA04JQ== 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=Q7itcGoTqmNSNMmSWuZjgBCbDtOz7K3OK9K5REGHCdo=; b=I4W3W/VR ofetVjLAIzlA7W/mlmS+Ofs0LxIOowmed1gAA+8AOuLLibhqYtvxuS0cFjOUxEmr QBzmhTI6ce+T300djQD1ikeiaH7JvnXjqPw9lWLFsNf1Ub0VFfmhWyUF1FR+zXfk gbW4zbRwvpdFBgworwrFoaNYNplIfAYDF66Q8PB2jq+N+3JpZOjktCXLzbnTTFX/ RlsUHLTijF5Ikctuj/iQHvwO+kB0t0lXj7flKvcjYGYjSKl6JR/WsBtNY+6BH93G 3dBgcKJucxx5IAsKaOrB7Y3ujfww7tGzHszUkGfENYlICvXK9onrPXmIaw7Kjnfe 8l1K4cK1SGHH+A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudduvddgfedtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefmlhgruhhs ucflvghnshgvnhcuoehithhssehirhhrvghlvghvrghnthdrughkqeenucggtffrrghtth gvrhhnpeeuleetgeeiuefhgfekfefgveejiefgteekiedtgfdtieefhfdthfefueffvefg keenucfkphepkedtrdduieejrdelkedrudeltdenucevlhhushhtvghrufhiiigvpedvje enucfrrghrrghmpehmrghilhhfrhhomhepihhtshesihhrrhgvlhgvvhgrnhhtrdgukh X-ME-Proxy: From: Klaus Jensen To: Peter Maydell , qemu-devel@nongnu.org Subject: [PULL 34/38] hw/block/nvme: support allocated namespace type Date: Mon, 8 Mar 2021 13:23:09 +0100 Message-Id: <20210308122313.286938-35-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 From NVMe spec 1.4b "6.1.5. NSID and Namespace Relationships" defines valid namespace types: - Unallocated: Not exists in the NVMe subsystem - Allocated: Exists in the NVMe subsystem - Inactive: Not attached to the controller - Active: Attached to the controller This patch added support for allocated, but not attached namespace type: !nvme_ns(n, nsid) && nvme_subsys_ns(n->subsys, nsid) nvme_ns() returns attached namespace instance of the given controller and nvme_subsys_ns() returns allocated namespace instance in the subsystem. Signed-off-by: Minwoo Im Reviewed-by: Keith Busch Reviewed-by: Klaus Jensen Tested-by: Klaus Jensen Signed-off-by: Klaus Jensen --- hw/block/nvme-subsys.h | 13 +++++++++ hw/block/nvme.c | 63 +++++++++++++++++++++++++++++++----------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h index 8a0732b22316..14627f9ccb41 100644 --- a/hw/block/nvme-subsys.h +++ b/hw/block/nvme-subsys.h @@ -30,4 +30,17 @@ typedef struct NvmeSubsystem { int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp); int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp); =20 +/* + * Return allocated namespace of the specified nsid in the subsystem. + */ +static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys, + uint32_t nsid) +{ + if (!subsys) { + return NULL; + } + + return subsys->namespaces[nsid]; +} + #endif /* NVME_SUBSYS_H */ diff --git a/hw/block/nvme.c b/hw/block/nvme.c index bfbdc8213c2b..3bfe10f5b517 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -3253,7 +3253,7 @@ static uint16_t nvme_identify_ctrl_csi(NvmeCtrl *n, N= vmeRequest *req) return nvme_c2h(n, id, sizeof(id), req); } =20 -static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req, bool activ= e) { NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; @@ -3267,7 +3267,14 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRe= quest *req) =20 ns =3D nvme_ns(n, nsid); if (unlikely(!ns)) { - return nvme_rpt_empty_id_struct(n, req); + if (!active) { + ns =3D nvme_subsys_ns(n->subsys, nsid); + if (!ns) { + return nvme_rpt_empty_id_struct(n, req); + } + } else { + return nvme_rpt_empty_id_struct(n, req); + } } =20 if (c->csi =3D=3D NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) { @@ -3277,7 +3284,8 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeReq= uest *req) return NVME_INVALID_CMD_SET | NVME_DNR; } =20 -static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req, + bool active) { NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; @@ -3291,7 +3299,14 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, Nv= meRequest *req) =20 ns =3D nvme_ns(n, nsid); if (unlikely(!ns)) { - return nvme_rpt_empty_id_struct(n, req); + if (!active) { + ns =3D nvme_subsys_ns(n->subsys, nsid); + if (!ns) { + return nvme_rpt_empty_id_struct(n, req); + } + } else { + return nvme_rpt_empty_id_struct(n, req); + } } =20 if (c->csi =3D=3D NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) { @@ -3304,7 +3319,8 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, Nvm= eRequest *req) return NVME_INVALID_FIELD | NVME_DNR; } =20 -static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req, + bool active) { NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; @@ -3329,7 +3345,14 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, Nv= meRequest *req) for (i =3D 1; i <=3D n->num_namespaces; i++) { ns =3D nvme_ns(n, i); if (!ns) { - continue; + if (!active) { + ns =3D nvme_subsys_ns(n->subsys, i); + if (!ns) { + continue; + } + } else { + continue; + } } if (ns->params.nsid <=3D min_nsid) { continue; @@ -3343,7 +3366,8 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, Nvm= eRequest *req) return nvme_c2h(n, list, data_len, req); } =20 -static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req) +static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req, + bool active) { NvmeNamespace *ns; NvmeIdentify *c =3D (NvmeIdentify *)&req->cmd; @@ -3369,7 +3393,14 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n= , NvmeRequest *req) for (i =3D 1; i <=3D n->num_namespaces; i++) { ns =3D nvme_ns(n, i); if (!ns) { - continue; + if (!active) { + ns =3D nvme_subsys_ns(n->subsys, i); + if (!ns) { + continue; + } + } else { + continue; + } } if (ns->params.nsid <=3D min_nsid || c->csi !=3D ns->csi) { continue; @@ -3452,25 +3483,25 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequ= est *req) =20 switch (c->cns) { case NVME_ID_CNS_NS: - /* fall through */ + return nvme_identify_ns(n, req, true); case NVME_ID_CNS_NS_PRESENT: - return nvme_identify_ns(n, req); + return nvme_identify_ns(n, req, false); case NVME_ID_CNS_CS_NS: - /* fall through */ + return nvme_identify_ns_csi(n, req, true); case NVME_ID_CNS_CS_NS_PRESENT: - return nvme_identify_ns_csi(n, req); + return nvme_identify_ns_csi(n, req, false); case NVME_ID_CNS_CTRL: return nvme_identify_ctrl(n, req); case NVME_ID_CNS_CS_CTRL: return nvme_identify_ctrl_csi(n, req); case NVME_ID_CNS_NS_ACTIVE_LIST: - /* fall through */ + return nvme_identify_nslist(n, req, true); case NVME_ID_CNS_NS_PRESENT_LIST: - return nvme_identify_nslist(n, req); + return nvme_identify_nslist(n, req, false); case NVME_ID_CNS_CS_NS_ACTIVE_LIST: - /* fall through */ + return nvme_identify_nslist_csi(n, req, true); case NVME_ID_CNS_CS_NS_PRESENT_LIST: - return nvme_identify_nslist_csi(n, req); + return nvme_identify_nslist_csi(n, req, false); case NVME_ID_CNS_NS_DESCR_LIST: return nvme_identify_ns_descr_list(n, req); case NVME_ID_CNS_IO_COMMAND_SET: --=20 2.30.1