All of lore.kernel.org
 help / color / mirror / Atom feed
From: Klaus Jensen <its@irrelevant.dk>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Fam Zheng <fam@euphon.net>, Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org, Klaus Jensen <k.jensen@samsung.com>,
	Max Reitz <mreitz@redhat.com>, Keith Busch <kbusch@kernel.org>,
	Minwoo Im <minwoo.im.dev@gmail.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Klaus Jensen <its@irrelevant.dk>
Subject: [PULL 34/38] hw/block/nvme: support allocated namespace type
Date: Mon,  8 Mar 2021 13:23:09 +0100	[thread overview]
Message-ID: <20210308122313.286938-35-its@irrelevant.dk> (raw)
In-Reply-To: <20210308122313.286938-1-its@irrelevant.dk>

From: Minwoo Im <minwoo.im.dev@gmail.com>

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 <minwoo.im.dev@gmail.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Tested-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 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);
 
+/*
+ * 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, NvmeRequest *req)
     return nvme_c2h(n, id, sizeof(id), req);
 }
 
-static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req)
+static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req, bool active)
 {
     NvmeNamespace *ns;
     NvmeIdentify *c = (NvmeIdentify *)&req->cmd;
@@ -3267,7 +3267,14 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req)
 
     ns = nvme_ns(n, nsid);
     if (unlikely(!ns)) {
-        return nvme_rpt_empty_id_struct(n, req);
+        if (!active) {
+            ns = 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);
+        }
     }
 
     if (c->csi == NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) {
@@ -3277,7 +3284,8 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req)
     return NVME_INVALID_CMD_SET | NVME_DNR;
 }
 
-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 = (NvmeIdentify *)&req->cmd;
@@ -3291,7 +3299,14 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req)
 
     ns = nvme_ns(n, nsid);
     if (unlikely(!ns)) {
-        return nvme_rpt_empty_id_struct(n, req);
+        if (!active) {
+            ns = 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);
+        }
     }
 
     if (c->csi == NVME_CSI_NVM && nvme_csi_has_nvm_support(ns)) {
@@ -3304,7 +3319,8 @@ static uint16_t nvme_identify_ns_csi(NvmeCtrl *n, NvmeRequest *req)
     return NVME_INVALID_FIELD | NVME_DNR;
 }
 
-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 = (NvmeIdentify *)&req->cmd;
@@ -3329,7 +3345,14 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req)
     for (i = 1; i <= n->num_namespaces; i++) {
         ns = nvme_ns(n, i);
         if (!ns) {
-            continue;
+            if (!active) {
+                ns = nvme_subsys_ns(n->subsys, i);
+                if (!ns) {
+                    continue;
+                }
+            } else {
+                continue;
+            }
         }
         if (ns->params.nsid <= min_nsid) {
             continue;
@@ -3343,7 +3366,8 @@ static uint16_t nvme_identify_nslist(NvmeCtrl *n, NvmeRequest *req)
     return nvme_c2h(n, list, data_len, req);
 }
 
-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 = (NvmeIdentify *)&req->cmd;
@@ -3369,7 +3393,14 @@ static uint16_t nvme_identify_nslist_csi(NvmeCtrl *n, NvmeRequest *req)
     for (i = 1; i <= n->num_namespaces; i++) {
         ns = nvme_ns(n, i);
         if (!ns) {
-            continue;
+            if (!active) {
+                ns = nvme_subsys_ns(n->subsys, i);
+                if (!ns) {
+                    continue;
+                }
+            } else {
+                continue;
+            }
         }
         if (ns->params.nsid <= min_nsid || c->csi != ns->csi) {
             continue;
@@ -3452,25 +3483,25 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest *req)
 
     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:
-- 
2.30.1



  parent reply	other threads:[~2021-03-08 13:38 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-08 12:22 [PULL 00/38] emulated nvme device updates Klaus Jensen
2021-03-08 12:22 ` [PULL 01/38] hw/block/nvme: introduce nvme-subsys device Klaus Jensen
2021-03-08 18:32   ` Paolo Bonzini
2021-03-08 18:46     ` Klaus Jensen
2021-03-08 18:53       ` Peter Maydell
2021-03-08 18:55         ` Klaus Jensen
2021-03-08 12:22 ` [PULL 02/38] hw/block/nvme: support to map controller to a subsystem Klaus Jensen
2021-03-08 12:22 ` [PULL 03/38] hw/block/nvme: add CMIC enum value for Identify Controller Klaus Jensen
2021-03-08 12:22 ` [PULL 04/38] hw/block/nvme: support for multi-controller in subsystem Klaus Jensen
2021-03-08 12:22 ` [PULL 05/38] hw/block/nvme: add NMIC enum value for Identify Namespace Klaus Jensen
2021-03-08 12:22 ` [PULL 06/38] hw/block/nvme: support for shared namespace in subsystem Klaus Jensen
2021-03-08 12:22 ` [PULL 07/38] hw/block/nvme: remove unused parameter in check zone write Klaus Jensen
2021-03-08 12:22 ` [PULL 08/38] hw/block/nvme: refactor zone resource management Klaus Jensen
2021-03-08 12:22 ` [PULL 09/38] hw/block/nvme: pull write pointer advancement to separate function Klaus Jensen
2021-03-08 12:22 ` [PULL 10/38] nvme: updated shared header for copy command Klaus Jensen
2021-03-08 12:22 ` [PULL 11/38] hw/block/nvme: add simple " Klaus Jensen
2021-03-08 12:22 ` [PULL 12/38] hw/block/nvme: fix Close Zone Klaus Jensen
2021-03-08 12:22 ` [PULL 13/38] hw/block/nvme: add missing mor/mar constraint checks Klaus Jensen
2021-03-08 12:22 ` [PULL 14/38] hw/block/nvme: improve invalid zasl value reporting Klaus Jensen
2021-03-08 12:22 ` [PULL 15/38] hw/block/nvme: use locally assigned QEMU IEEE OUI Klaus Jensen
2021-03-08 12:22 ` [PULL 16/38] hw/block/nvme: add broadcast nsid support flush command Klaus Jensen
2021-03-08 12:22 ` [PULL 17/38] hw/block/nvme: document 'mdts' nvme device parameter Klaus Jensen
2021-03-08 12:22 ` [PULL 18/38] hw/block/nvme: deduplicate bad mdts trace event Klaus Jensen
2021-03-08 12:22 ` [PULL 19/38] hw/block/nvme: align zoned.zasl with mdts Klaus Jensen
2021-03-08 12:22 ` [PULL 20/38] hw/block/nvme: remove unnecessary endian conversion Klaus Jensen
2021-03-08 12:22 ` [PULL 21/38] hw/block/nvme: add identify trace event Klaus Jensen
2021-03-08 12:22 ` [PULL 22/38] hw/block/nvme: fix potential compilation error Klaus Jensen
2021-03-08 12:22 ` [PULL 23/38] hw/block/nvme: add trace event for zone read check Klaus Jensen
2021-03-08 12:22 ` [PULL 24/38] hw/block/nvme: report non-mdts command size limit for dsm Klaus Jensen
2021-03-08 12:23 ` [PULL 25/38] hw/block/nvme: remove redundant len member in compare context Klaus Jensen
2021-03-08 12:23 ` [PULL 26/38] hw/block/nvme: remove block accounting for write zeroes Klaus Jensen
2021-03-08 12:23 ` [PULL 27/38] hw/block/nvme: fix strerror printing Klaus Jensen
2021-03-08 12:23 ` [PULL 28/38] hw/block/nvme: try to deal with the iov/qsg duality Klaus Jensen
2021-03-08 12:23 ` [PULL 29/38] hw/block/nvme: remove the req dependency in map functions Klaus Jensen
2021-03-08 12:23 ` [PULL 30/38] hw/block/nvme: refactor nvme_dma Klaus Jensen
2021-03-08 12:23 ` [PULL 31/38] hw/block/nvme: support namespace detach Klaus Jensen
2021-03-08 12:23 ` [PULL 32/38] hw/block/nvme: fix namespaces array to 1-based Klaus Jensen
2021-03-08 12:23 ` [PULL 33/38] hw/block/nvme: fix allocated namespace list to 256 Klaus Jensen
2021-03-08 12:23 ` Klaus Jensen [this message]
2021-03-08 12:23 ` [PULL 35/38] hw/block/nvme: refactor nvme_select_ns_iocs Klaus Jensen
2021-03-08 12:23 ` [PULL 36/38] hw/block/nvme: support namespace attachment command Klaus Jensen
2021-03-08 12:23 ` [PULL 37/38] hw/block/nvme: support changed namespace asynchronous event Klaus Jensen
2021-03-08 12:23 ` [PULL 38/38] hw/block/nvme: support Identify NS Attached Controller List Klaus Jensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210308122313.286938-35-its@irrelevant.dk \
    --to=its@irrelevant.dk \
    --cc=fam@euphon.net \
    --cc=k.jensen@samsung.com \
    --cc=kbusch@kernel.org \
    --cc=kwolf@redhat.com \
    --cc=minwoo.im.dev@gmail.com \
    --cc=mreitz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.