hw/block/nvme: support namespace attachment
v3 cover hw/block/nvme: support namespace attachment
Hello,
This series supports namespace attachment: attach and detach. This is the third version of series with fixing command events and asynchronous events based on Keith's review.
Since command effects for the namespace attachment command is added in this version, we no longer need to rescan controller after namespace attachment command. Kernel will rescan the controller namespaces after the command successfully done through passthru.
Please review.
Thanks,
Since V2:
- Added command effects (namespace inventory changed) for namespace attach command. (Keith)
- Added [7/8] patch to support asynchronus event when namespace inventory is updated. (Keith)
- Added review and tested tag from Klaus to all the patches, but [6/8]
and [7/8].
Since V1:
- Fix to take 'ctrl' which is given from the command rather than 'n'.
(Klaus)
- Add a [7/7] patch to support CNS 12h Identify command (Namespace Attached Controller list).
Minwoo Im (8):
hw/block/nvme: support namespace detach hw/block/nvme: fix namespaces array to 1-based hw/block/nvme: fix allocated namespace list to 256 hw/block/nvme: support allocated namespace type hw/block/nvme: refactor nvme_select_ns_iocs hw/block/nvme: support namespace attachment command hw/block/nvme: support changed namespace asyncrohous event hw/block/nvme: support Identify NS Attached Controller List
hw/block/nvme-ns.c | 1 + hw/block/nvme-ns.h | 1 + hw/block/nvme-subsys.h | 28 +++- hw/block/nvme.c | 287 ++++++++++++++++++++++++++++++++++++----- hw/block/nvme.h | 40 ++++++ hw/block/trace-events | 3 + include/block/nvme.h | 14 ++ 7 files changed, 338 insertions(+), 36 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/8 hw/block/nvme: support namespace detach
Given that now we have nvme-subsys device supported, we can manage namespace allocated, but not attached: detached. This patch introduced a parameter for nvme-ns device named 'detached'. This parameter indicates whether the given namespace device is detached from a entire NVMe subsystem('subsys' given case, shared namespace) or a controller('bus' given case, private namespace).
- Allocated namespace
1) Shared ns in the subsystem 'subsys0':
-device nvme-ns,id=ns1,drive=blknvme0,nsid=1,subsys=subsys0,detached=true
2) Private ns for the controller 'nvme0' of the subsystem 'subsys0':
-device nvme-subsys,id=subsys0
-device nvme,serial=foo,id=nvme0,subsys=subsys0
-device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true
3) (Invalid case) Controller 'nvme0' has no subsystem to manage ns:
-device nvme,serial=foo,id=nvme0
-device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true
--- hw/block/nvme-ns.c | 1 + hw/block/nvme-ns.h | 1 + hw/block/nvme-subsys.h | 1 + hw/block/nvme.c | 41 +++++++++++++++++++++++++++++++++++++++-- hw/block/nvme.h | 22 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-)
hw/block/nvme-ns.c +1 -0
@@ -399,6 +399,7 @@ static Property nvme_ns_props[] = {DEFINE_BLOCK_PROPERTIES (NvmeNamespace, blkconf),DEFINE_PROP_LINK ("subsys" , NvmeNamespace, subsys,TYPE_NVME_SUBSYS , NvmeSubsystem *), +DEFINE_PROP_BOOL ("detached" , NvmeNamespace, params.detached, false),DEFINE_PROP_UINT32 ("nsid" , NvmeNamespace, params.nsid,0 ),DEFINE_PROP_UUID ("uuid" , NvmeNamespace, params.uuid), DEFINE_PROP_UINT16("mssrl", NvmeNamespace, params.mssrl, 128),
hw/block/nvme-ns.h +1 -0
@@ -26,6 +26,7 @@ typedef struct NvmeZone { } NvmeZone; typedef struct NvmeNamespaceParams { + bool detached; uint32_t nsid; QemuUUID uuid;
hw/block/nvme-subsys.h +1 -0
@@ -23,6 +23,7 @@ typedef struct NvmeSubsystem {uint8_t subnqn[256 ];NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS ]; +/* Allocated namespaces for this subsystem */ NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES ]; } NvmeSubsystem;
hw/block/nvme.c +39 -2
65 lines not on this page · raw message
hw/block/nvme.h +22 -0
@@ -174,6 +174,10 @@ typedef struct NvmeCtrl {NvmeSubsystem *subsys;NvmeNamespace namespace; +/* +* Attached namespaces to this controller. If subsys is not given, all +* namespaces in this list will always be attached. +*/ NvmeNamespace *namespaces[NVME_MAX_NAMESPACES ];NvmeSQueue **sq;NvmeCQueue **cq;
@@ -192,6 +196,24 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)return n->namespaces[nsid -1 ]; } +static inline bool nvme_ns_is_attached (NvmeCtrl *n,NvmeNamespace *ns) +{ +int nsid; + +for (nsid =1 ; nsid <= n->num_namespaces; nsid++) { +if (nvme_ns (n, nsid) == ns) { +return true; + } + } + +return false; +} + +static inline void nvme_ns_attach (NvmeCtrl *n,NvmeNamespace *ns) +{ + n->namespaces[nvme_nsid (ns) -1 ] = ns; +} +static inline NvmeCQueue *nvme_cq (NvmeRequest *req) {NvmeSQueue *sq = req->sq;
Signature · 1 line
2.25.1
Re: [PATCH V3 1/8] hw/block/nvme: support namespace detach
Hi,
I don't dig into code logic, just some nit below.
Quoted 2 lines · Minwoo Im
Given that now we have nvme-subsys device supported, we can manage namespace allocated, but not attached: detached. This patch introduced
s/introduced/introduces
Quoted 83 lines
a parameter for nvme-ns device named 'detached'. This parameter indicates whether the given namespace device is detached from a entire NVMe
subsystem('subsys' given case, shared namespace)or acontroller('bus' given case, private namespace).- Allocated namespace
1) Shared ns in the subsystem 'subsys0':
-device nvme-ns,id=ns1,drive=blknvme0,nsid=1,subsys=subsys0,detached=true
2) Private ns for the controller 'nvme0' of the subsystem 'subsys0':
-device nvme-subsys,id=subsys0
-device nvme,serial=foo,id=nvme0,subsys=subsys0
-device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=true3) (Invalid case) Controller 'nvme0' has no subsystem to manage ns:
-device nvme,serial=foo,id=nvme0
-device nvme-ns,id=ns1,drive=blknvme0,nsid=1,bus=nvme0,detached=trueSigned-off-by Minwoo Im <[email protected]>Tested-by Klaus Jensen <[email protected]>Reviewed-by Klaus Jensen <[email protected]>--- hw/block/nvme-ns.c | 1 + hw/block/nvme-ns.h | 1 + hw/block/nvme-subsys.h | 1 + hw/block/nvme.c | 41 +++++++++++++++++++++++++++++++++++++++-- hw/block/nvme.h | 22 ++++++++++++++++++++++ 5 files changed, 64 insertions(+), 2 deletions(-)hw/block/nvme-ns.c +1
-0@@ -399,6 +399,7 @@ static Property nvme_ns_props[] = {DEFINE_BLOCK_PROPERTIES (NvmeNamespace, blkconf),DEFINE_PROP_LINK ("subsys" , NvmeNamespace, subsys,TYPE_NVME_SUBSYS , NvmeSubsystem *), +DEFINE_PROP_BOOL ("detached" , NvmeNamespace, params.detached, false),DEFINE_PROP_UINT32 ("nsid" , NvmeNamespace, params.nsid,0 ),DEFINE_PROP_UUID ("uuid" , NvmeNamespace, params.uuid), DEFINE_PROP_UINT16("mssrl", NvmeNamespace, params.mssrl, 128),hw/block/nvme-ns.h +1
-0@@ -26,6 +26,7 @@ typedef struct NvmeZone { } NvmeZone; typedef struct NvmeNamespaceParams { + bool detached; uint32_t nsid; QemuUUID uuid;hw/block/nvme-subsys.h +1
-0@@ -23,6 +23,7 @@ typedef struct NvmeSubsystem {uint8_t subnqn[256 ];NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS ]; +/* Allocated namespaces for this subsystem */ NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES ]; } NvmeSubsystem;hw/block/nvme.c +1
-1@@ -23,7 +23,7 @@* max_ioqpairs=<N[optional]>, \ * aerl=<N[optional]>, aer_max_queued=<N[optional]>, \ * mdts=<N[optional]>,zoned.append_size_limit=<N[optional]>, \ -* subsys=<subsys_id> \ +* subsys=<subsys_id>,detached=<true|false[optional]> * -device nvme-ns,drive=<drive_id>,bus=<bus_name>,nsid=<nsid>,\ * zoned=<true|false[optional]>, \ * subsys=<subsys_id>
hw/block/nvme.c line 87
Quoted 6 lines
hw/block/nvme.c +3
-0@@ -82,6 +82,13 @@* controllers in the subsystem. Otherwise, `bus` must be given to attach * this namespace to a specified single controller as a non-shared namespace. * +* - `detached` +* Not to attach the namespace device to controllers in the NVMe subsystem +* during boot-up. If not given, namespaces are all attahced to all
s/attahced/attached
Quoted 29 lines
hw/block/nvme.c +18
-0+* controllers in the subsystem by default. +* It's mutual exclusive with 'bus' parameter. It's only valid in case +* `subsys` is provided. +* * Setting `zoned` to true selects Zoned Command Set at the namespace. * In this case, the following namespace properties are available to configure * zoned operation: @@ -4613,6 +4620,20 @@ static void nvme_init_state(NvmeCtrl *n) n->aer_reqs = g_new0(NvmeRequest *, n->params.aerl + 1); } +static int nvme_attach_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp) +{ +if (nvme_ns_is_attached (n, ns)) { +error_setg (errp, +"namespace %d is already attached to controller %d" , +nvme_nsid (ns), n->cntlid); +return -1 ; + } + +nvme_ns_attach (n, ns); + +return 0 ; +} +int nvme_register_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp) {uint32_t nsid =nvme_nsid (ns);
hw/block/nvme.c int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp) · line 4669
Quoted 6 lines
hw/block/nvme.c +2
-1@@ -4644,7 +4665,23 @@ int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)trace_pci_nvme_register_namespace (nsid); - n->namespaces[nsid -1 ] = ns; +/* +* If subsys is not given, namespae is always attached to the controller
s/namespae/namespace
Quoted 59 lines
hw/block/nvme.c +15
-0+* because there's no subsystem to manage namespace allocation. +*/ +if (!n->subsys) { +if (ns->params.detached) { +error_setg (errp, +"detached needs nvme-subsys specified nvme or nvme-ns" ); +return -1 ; + } + +return nvme_attach_namespace (n, ns, errp); + }else { +if (!ns->params.detached) { +return nvme_attach_namespace (n, ns, errp); + } + }return 0 ; }hw/block/nvme.h +22
-0@@ -174,6 +174,10 @@ typedef struct NvmeCtrl {NvmeSubsystem *subsys;NvmeNamespace namespace; +/* +* Attached namespaces to this controller. If subsys is not given, all +* namespaces in this list will always be attached. +*/ NvmeNamespace *namespaces[NVME_MAX_NAMESPACES ];NvmeSQueue **sq;NvmeCQueue **cq;@@ -192,6 +196,24 @@ static inline NvmeNamespace *nvme_ns(NvmeCtrl *n, uint32_t nsid)return n->namespaces[nsid -1 ]; } +static inline bool nvme_ns_is_attached (NvmeCtrl *n,NvmeNamespace *ns) +{ +int nsid; + +for (nsid =1 ; nsid <= n->num_namespaces; nsid++) { +if (nvme_ns (n, nsid) == ns) { +return true; + } + } + +return false; +} + +static inline void nvme_ns_attach (NvmeCtrl *n,NvmeNamespace *ns) +{ + n->namespaces[nvme_nsid (ns) -1 ] = ns; +} +static inline NvmeCQueue *nvme_cq (NvmeRequest *req) {NvmeSQueue *sq = req->sq;
Re: [PATCH V3 1/8] hw/block/nvme: support namespace detach
Quoted 4 lines · Keqian Zhu
Hi,
I don't dig into code logic, just some nit below.
Thanks! I'll cook up a fix with some corrections on these typos.
PATCH v3 2/8 hw/block/nvme: fix namespaces array to 1-based
In reply to Minwoo Imsubsys->namespaces array used to be sized to NVME_SUBSYS_MAX_NAMESPACES. But subsys->namespaces are being accessed with 1-based namespace id which means the very first array entry will always be empty(NULL).
--- hw/block/nvme-subsys.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/block/nvme-subsys.h +1 -1
@@ -24,7 +24,7 @@ typedef struct NvmeSubsystem {NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS ];/* Allocated namespaces for this subsystem */ -NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES ]; +NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES +1 ]; } NvmeSubsystem;int nvme_subsys_register_ctrl (NvmeCtrl *n,Error **errp);
Signature · 1 line
2.25.1
PATCH v3 3/8 hw/block/nvme: fix allocated namespace list to 256
In reply to Minwoo ImExpand allocated namespace list (subsys->namespaces) to have 256 entries which is a value lager than at least NVME_MAX_NAMESPACES which is for attached namespace list in a controller.
Allocated namespace list should at least larger than attached namespace list.
n->num_namespaces = NVME_MAX_NAMESPACES;
The above line will set the NN field by id->nn so that the subsystem should also prepare at least this number of namespace list entries.
--- hw/block/nvme-subsys.h | 2 +- hw/block/nvme.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
hw/block/nvme-subsys.h +1 -1
@@ -14,7 +14,7 @@ OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS)#define NVME_SUBSYS_MAX_CTRLS 32 -#define NVME_SUBSYS_MAX_NAMESPACES 32 +#define NVME_SUBSYS_MAX_NAMESPACES 256typedef struct NvmeCtrl NvmeCtrl ;typedef struct NvmeNamespace NvmeNamespace ;
hw/block/nvme.h +6 -0
@@ -10,6 +10,12 @@#define NVME_DEFAULT_ZONE_SIZE (128 * MiB)#define NVME_DEFAULT_MAX_ZA_SIZE (128 * KiB) +/* +* Subsystem namespace list for allocated namespaces should be larger than +* attached namespace list in a controller. +*/ +QEMU_BUILD_BUG_ON (NVME_MAX_NAMESPACES >NVME_SUBSYS_MAX_NAMESPACES ); + typedef struct NvmeParams { char *serial; uint32_t num_queues; /* deprecated since 5.1 */
Signature · 1 line
2.25.1
PATCH v3 4/8 hw/block/nvme: support allocated namespace type
In reply to Minwoo ImFrom 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.
--- hw/block/nvme-subsys.h | 13 +++++++++ hw/block/nvme.c | 63 +++++++++++++++++++++++++++++++----------- 2 files changed, 60 insertions(+), 16 deletions(-)
hw/block/nvme-subsys.h +13 -0
@@ -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 */
hw/block/nvme.c +47 -16
128 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 5/8 hw/block/nvme: refactor nvme_select_ns_iocs
In reply to Minwoo ImThis patch has no functional changes. This patch just refactored nvme_select_ns_iocs() to iterate the attached namespaces of the controlller and make it invoke __nvme_select_ns_iocs().
--- hw/block/nvme.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
hw/block/nvme.c +21 -15
@@ -4000,6 +4000,25 @@ static void nvme_ctrl_shutdown(NvmeCtrl *n) } } +static void __nvme_select_ns_iocs (NvmeCtrl *n,NvmeNamespace *ns) +{ + ns->iocs = nvme_cse_iocs_none; +switch (ns->csi) { +case NVME_CSI_NVM : +if (NVME_CC_CSS (n->bar.cc) !=NVME_CC_CSS_ADMIN_ONLY ) { + ns->iocs = nvme_cse_iocs_nvm; + } +break ; +case NVME_CSI_ZONED : +if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_CSI ) { + ns->iocs = nvme_cse_iocs_zoned; + }else if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_NVM ) { + ns->iocs = nvme_cse_iocs_nvm; + } +break ; + } +} +static void nvme_select_ns_iocs (NvmeCtrl *n) {NvmeNamespace *ns;
@@ -4010,21 +4029,8 @@ static void nvme_select_ns_iocs(NvmeCtrl *n)if (!ns) {continue ; } - ns->iocs = nvme_cse_iocs_none; -switch (ns->csi) { -case NVME_CSI_NVM : -if (NVME_CC_CSS (n->bar.cc) !=NVME_CC_CSS_ADMIN_ONLY ) { - ns->iocs = nvme_cse_iocs_nvm; - } -break ; -case NVME_CSI_ZONED : -if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_CSI ) { - ns->iocs = nvme_cse_iocs_zoned; - }else if (NVME_CC_CSS (n->bar.cc) ==NVME_CC_CSS_NVM ) { - ns->iocs = nvme_cse_iocs_nvm; - } -break ; - } + +__nvme_select_ns_iocs (n, ns); } }
Signature · 1 line
2.25.1
PATCH v3 6/8 hw/block/nvme: support namespace attachment command
In reply to Minwoo ImThis patch supports Namespace Attachment command for the pre-defined nvme-ns device nodes. Of course, attach/detach namespace should only be supported in case 'subsys' is given. This is because if we detach a namespace from a controller, somebody needs to manage the detached, but allocated namespace in the NVMe subsystem.
As command effect for the namespace attachment command is registered, the host will be notified that namespace inventory is changed so that host will rescan the namespace inventory after this command. For example, kernel driver manages this command effect via passthru IOCTL.
--- hw/block/nvme-subsys.h | 10 +++++++ hw/block/nvme.c | 61 +++++++++++++++++++++++++++++++++++++++++- hw/block/nvme.h | 5 ++++ hw/block/trace-events | 2 ++ include/block/nvme.h | 6 +++++ 5 files changed, 83 insertions(+), 1 deletion(-)
hw/block/nvme-subsys.h +10 -0
@@ -30,6 +30,16 @@ typedef struct NvmeSubsystem {int nvme_subsys_register_ctrl (NvmeCtrl *n,Error **errp);int nvme_subsys_register_ns (NvmeNamespace *ns,Error **errp); +static inline NvmeCtrl *nvme_subsys_ctrl (NvmeSubsystem *subsys, +uint32_t cntlid) +{ +if (!subsys) { +return NULL ; + } + +return subsys->ctrls[cntlid]; +} +/* * Return allocated namespace of the specified nsid in the subsystem. */
hw/block/nvme.c +60 -1
85 lines not on this page · raw message
hw/block/nvme.h +5 -0
@@ -220,6 +220,11 @@ static inline void nvme_ns_attach(NvmeCtrl *n, NvmeNamespace *ns) n->namespaces[nvme_nsid (ns) -1 ] = ns; } +static inline void nvme_ns_detach (NvmeCtrl *n,NvmeNamespace *ns) +{ + n->namespaces[nvme_nsid (ns) -1 ] =NULL ; +} +static inline NvmeCQueue *nvme_cq (NvmeRequest *req) {NvmeSQueue *sq = req->sq;
hw/block/trace-events +2 -0
@@ -82,6 +82,8 @@ pci_nvme_aer(uint16_t cid) "cid %"PRIu16"" pci_nvme_aer_aerl_exceeded(void) "aerl exceeded" pci_nvme_aer_masked(uint8_t type, uint8_t mask) "type 0x%"PRIx8" mask 0x%"PRIx8"" pci_nvme_aer_post_cqe(uint8_t typ, uint8_t info, uint8_t log_page) "type 0x%"PRIx8" info 0x%"PRIx8" lid 0x%"PRIx8"" +pci_nvme_ns_attachment(uint16_t cid, uint8_t sel) "cid %"PRIu16", sel=0x%"PRIx8"" +pci_nvme_ns_attachment_attach(uint16_t cntlid, uint32_t nsid) "cntlid=0x%"PRIx16", nsid=0x%"PRIx32"" pci_nvme_enqueue_event(uint8_t typ, uint8_t info, uint8_t log_page) "type 0x%"PRIx8" info 0x%"PRIx8" lid 0x%"PRIx8"" pci_nvme_enqueue_event_noqueue(int queued) "queued %d" pci_nvme_enqueue_event_masked(uint8_t typ) "type 0x%"PRIx8""
include/block/nvme.h +6 -0
@@ -566,6 +566,7 @@ enum NvmeAdminCommands {NVME_ADM_CMD_ASYNC_EV_REQ =0x0c ,NVME_ADM_CMD_ACTIVATE_FW =0x10 ,NVME_ADM_CMD_DOWNLOAD_FW =0x11 , +NVME_ADM_CMD_NS_ATTACHMENT =0x15 ,NVME_ADM_CMD_FORMAT_NVM =0x80 ,NVME_ADM_CMD_SECURITY_SEND =0x81 , NVME_ADM_CMD_SECURITY_RECV = 0x82,
@@ -836,6 +837,9 @@ enum NvmeStatusCodes {NVME_FEAT_NOT_CHANGEABLE =0x010e ,NVME_FEAT_NOT_NS_SPEC =0x010f ,NVME_FW_REQ_SUSYSTEM_RESET =0x0110 , +NVME_NS_ALREADY_ATTACHED =0x0118 , +NVME_NS_NOT_ATTACHED =0x011A , +NVME_NS_CTRL_LIST_INVALID =0x011C ,NVME_CONFLICTING_ATTRS =0x0180 ,NVME_INVALID_PROT_INFO =0x0181 , NVME_WRITE_TO_RO = 0x0182,
@@ -951,6 +955,7 @@ typedef struct QEMU_PACKED NvmePSD {uint8_t resv[16 ]; } NvmePSD; +#define NVME_CONTROLLER_LIST_SIZE 2048#define NVME_IDENTIFY_DATA_SIZE 4096enum NvmeIdCns {
@@ -1045,6 +1050,7 @@ enum NvmeIdCtrlOacs {NVME_OACS_SECURITY =1 <<0 ,NVME_OACS_FORMAT =1 <<1 ,NVME_OACS_FW =1 <<2 , + NVME_OACS_NS_MGMT = 1 << 3, }; enum NvmeIdCtrlOncs {
Signature · 1 line
2.25.1
PATCH v3 7/8 hw/block/nvme: support changed namespace asyncrohous event
In reply to Minwoo ImIf namespace inventory is changed due to some reasons (e.g., namespace attachment/detachment), controller can send out event notifier to the host to manage namespaces.
This patch sends out the AEN to the host after either attach or detach namespaces from controllers. To support clear of the event from the controller, this patch also implemented Get Log Page command for Changed Namespace List log type. To return namespace id list through the command, when namespace inventory is updated, id is added to the per-controller list (changed_ns_list).
To indicate the support of this async event, this patch set OAES(Optional Asynchronous Events Supported) in Identify Controller data structure.
--- hw/block/nvme.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/block/nvme.h | 7 +++++++ include/block/nvme.h | 7 +++++++ 3 files changed, 58 insertions(+)
hw/block/nvme.c +44 -0
@@ -2980,6 +2980,32 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } +static uint16_t nvme_changed_nslist (NvmeCtrl *n,uint8_t rae,uint32_t buf_len, +uint64_t off,NvmeRequest *req) +{ +uint32_t nslist[1024 ]; +uint32_t trans_len; +NvmeChangedNs *ns, *next; +int i =0 ; + +memset (nslist,0x0 ,sizeof (nslist)); + trans_len =MIN (sizeof (nslist) - off, buf_len); + + QTAILQ_FOREACH_SAFE(ns, &n->changed_ns_list, entry, next) { + nslist[i++] = ns->nsid; + +QTAILQ_REMOVE (&n->changed_ns_list, ns, entry); +g_free (ns); + } + +if (!rae) { +nvme_clear_events (n,NVME_AER_TYPE_NOTICE ); + } + +return nvme_dma (n, ((uint8_t *)nslist) + off, trans_len, +DMA_DIRECTION_FROM_DEVICE , req); +} +static uint16_t nvme_cmd_effects (NvmeCtrl *n,uint8_t csi,uint32_t buf_len,uint64_t off,NvmeRequest *req) {
@@ -3064,6 +3090,8 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest *req)return nvme_smart_info (n, rae, len, off, req);case NVME_LOG_FW_SLOT_INFO :return nvme_fw_log_info (n, len, off, req); +case NVME_LOG_CHANGED_NSLIST : +return nvme_changed_nslist (n, rae, len, off, req);case NVME_LOG_CMD_EFFECTS :return nvme_cmd_effects (n, csi, len, off, req);default :
@@ -3882,6 +3910,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)uint16_t *ids = &list[1 ];uint16_t ret;int i; +NvmeChangedNs *changed_nsid;trace_pci_nvme_ns_attachment (nvme_cid (req), dw10 &0xf );
@@ -3920,6 +3949,18 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)nvme_ns_detach (ctrl, ns); } + +/* +* Add namespace id to the changed namespace id list for event clearing +* via Get Log Page command. +*/ + changed_nsid =g_new (NvmeChangedNs,1 ); + changed_nsid->nsid = nsid; +QTAILQ_INSERT_TAIL (&ctrl->changed_ns_list, changed_nsid, entry); + +nvme_enqueue_event (ctrl,NVME_AER_TYPE_NOTICE , +NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED , +NVME_LOG_CHANGED_NSLIST ); }return NVME_SUCCESS ;
@@ -4714,6 +4755,7 @@ static void nvme_init_state(NvmeCtrl *n) n->features.temp_thresh_hi =NVME_TEMPERATURE_WARNING ; n->starttime_ms =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ); n->aer_reqs = g_new0(NvmeRequest *, n->params.aerl + 1); +QTAILQ_INIT (&n->changed_ns_list); }static int nvme_attach_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp)
@@ -4910,6 +4952,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->cntlid =cpu_to_le16 (n->cntlid); + id->oaes =cpu_to_le32 (NVME_OAES_NS_ATTR ); + id->rab =6 ;if (n->params.use_intel_id) {
hw/block/nvme.h +7 -0
@@ -132,6 +132,11 @@ typedef struct NvmeFeatureVal {uint32_t async_config; } NvmeFeatureVal; +typedef struct NvmeChangedNs { +uint32_t nsid; +QTAILQ_ENTRY (NvmeChangedNs) entry; +}NvmeChangedNs ; + typedef struct NvmeCtrl { PCIDevice parent_obj; MemoryRegion bar0;
@@ -177,6 +182,8 @@ typedef struct NvmeCtrl { QTAILQ_HEAD(, NvmeAsyncEvent) aer_queue;int aer_queued; + QTAILQ_HEAD(, NvmeChangedNs) changed_ns_list; /* Changed NS list log */ +NvmeSubsystem *subsys;NvmeNamespace namespace;
include/block/nvme.h +7 -0
@@ -760,6 +760,7 @@ typedef struct QEMU_PACKED NvmeCopySourceRange {enum NvmeAsyncEventRequest {NVME_AER_TYPE_ERROR =0 ,NVME_AER_TYPE_SMART =1 , +NVME_AER_TYPE_NOTICE =2 ,NVME_AER_TYPE_IO_SPECIFIC =6 ,NVME_AER_TYPE_VENDOR_SPECIFIC =7 ,NVME_AER_INFO_ERR_INVALID_DB_REGISTER =0 ,
@@ -771,6 +772,7 @@ enum NvmeAsyncEventRequest {NVME_AER_INFO_SMART_RELIABILITY =0 ,NVME_AER_INFO_SMART_TEMP_THRESH =1 ,NVME_AER_INFO_SMART_SPARE_THRESH =2 , + NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED = 0, }; typedef struct QEMU_PACKED NvmeAerResult {
@@ -940,6 +942,7 @@ enum NvmeLogIdentifier {NVME_LOG_ERROR_INFO =0x01 ,NVME_LOG_SMART_INFO =0x02 ,NVME_LOG_FW_SLOT_INFO =0x03 , +NVME_LOG_CHANGED_NSLIST =0x04 , NVME_LOG_CMD_EFFECTS = 0x05, };
@@ -1046,6 +1049,10 @@ typedef struct NvmeIdCtrlZoned {uint8_t rsvd1[4095 ]; } NvmeIdCtrlZoned; +enum NvmeIdCtrlOaes { +NVME_OAES_NS_ATTR =1 <<8 , +}; +enum NvmeIdCtrlOacs {NVME_OACS_SECURITY =1 <<0 ,NVME_OACS_FORMAT =1 <<1 ,
Signature · 1 line
2.25.1
Re: [PATCH V3 7/8] hw/block/nvme: support changed namespace asyncrohous event
Quoted 83 lines · Minwoo Im
If namespace inventory is changed due to some reasons (e.g., namespace attachment/detachment), controller can send out event notifier to the host to manage namespaces.
This patch sends out the AEN to the host after either attach or detach namespaces from controllers. To support clear of the event from the controller, this patch also implemented Get Log Page command for Changed Namespace List log type. To return namespace id list through the command, when namespace inventory is updated, id is added to the per-controller list (
changed_ns_list).To indicate the support of this async event, this patch set OAES(Optional Asynchronous Events Supported) in Identify Controller data structure.
Signed-off-by Minwoo Im <[email protected]>--- hw/block/nvme.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/block/nvme.h | 7 +++++++ include/block/nvme.h | 7 +++++++ 3 files changed, 58 insertions(+)hw/block/nvme.c +32
-0@@ -2980,6 +2980,32 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } +static uint16_t nvme_changed_nslist (NvmeCtrl *n,uint8_t rae,uint32_t buf_len, +uint64_t off,NvmeRequest *req) +{ +uint32_t nslist[1024 ]; +uint32_t trans_len; +NvmeChangedNs *ns, *next; +int i =0 ; + +memset (nslist,0x0 ,sizeof (nslist)); + trans_len =MIN (sizeof (nslist) - off, buf_len); + + QTAILQ_FOREACH_SAFE(ns, &n->changed_ns_list, entry, next) { + nslist[i++] = ns->nsid; + +QTAILQ_REMOVE (&n->changed_ns_list, ns, entry); +g_free (ns); + } + +if (!rae) { +nvme_clear_events (n,NVME_AER_TYPE_NOTICE ); + } + +return nvme_dma (n, ((uint8_t *)nslist) + off, trans_len, +DMA_DIRECTION_FROM_DEVICE , req); +} +static uint16_t nvme_cmd_effects (NvmeCtrl *n,uint8_t csi,uint32_t buf_len,uint64_t off,NvmeRequest *req) {@@ -3064,6 +3090,8 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest *req)return nvme_smart_info (n, rae, len, off, req);case NVME_LOG_FW_SLOT_INFO :return nvme_fw_log_info (n, len, off, req); +case NVME_LOG_CHANGED_NSLIST : +return nvme_changed_nslist (n, rae, len, off, req);case NVME_LOG_CMD_EFFECTS :return nvme_cmd_effects (n, csi, len, off, req);default :@@ -3882,6 +3910,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)uint16_t *ids = &list[1 ];uint16_t ret;int i; +NvmeChangedNs *changed_nsid;trace_pci_nvme_ns_attachment (nvme_cid (req), dw10 &0xf );@@ -3920,6 +3949,18 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)nvme_ns_detach (ctrl, ns); } + +/* +* Add namespace id to the changed namespace id list for event clearing
hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 3964
Quoted 10 lines
hw/block/nvme.c +9
-0+* via Get Log Page command. +*/ + changed_nsid =g_new (NvmeChangedNs,1 ); + changed_nsid->nsid = nsid; +QTAILQ_INSERT_TAIL (&ctrl->changed_ns_list, changed_nsid, entry); + +nvme_enqueue_event (ctrl,NVME_AER_TYPE_NOTICE , +NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED , +NVME_LOG_CHANGED_NSLIST ); }
If one just keeps attaching/detaching we end up with more than 1024 entries here and go out of bounds in nvme_changed_nslist.
How about having the QTAILQ_ENTRY directly on the NvmeNamespace struct and use QTAILQ_IN_USE to check if the namespace is already in the list?
Quoted 86 lines
hw/block/nvme.c +3
-0return NVME_SUCCESS ;@@ -4714,6 +4755,7 @@ static void nvme_init_state(NvmeCtrl *n) n->features.temp_thresh_hi =NVME_TEMPERATURE_WARNING ; n->starttime_ms =qemu_clock_get_ms (QEMU_CLOCK_VIRTUAL ); n->aer_reqs = g_new0(NvmeRequest *, n->params.aerl + 1); +QTAILQ_INIT (&n->changed_ns_list); }static int nvme_attach_namespace (NvmeCtrl *n,NvmeNamespace *ns,Error **errp)@@ -4910,6 +4952,8 @@ static void nvme_init_ctrl(NvmeCtrl *n, PCIDevice *pci_dev) id->cntlid =cpu_to_le16 (n->cntlid); + id->oaes =cpu_to_le32 (NVME_OAES_NS_ATTR ); + id->rab =6 ;if (n->params.use_intel_id) {hw/block/nvme.h +7
-0@@ -132,6 +132,11 @@ typedef struct NvmeFeatureVal {uint32_t async_config; } NvmeFeatureVal; +typedef struct NvmeChangedNs { +uint32_t nsid; +QTAILQ_ENTRY (NvmeChangedNs) entry; +}NvmeChangedNs ; + typedef struct NvmeCtrl { PCIDevice parent_obj; MemoryRegion bar0;@@ -177,6 +182,8 @@ typedef struct NvmeCtrl { QTAILQ_HEAD(, NvmeAsyncEvent) aer_queue;int aer_queued; + QTAILQ_HEAD(, NvmeChangedNs) changed_ns_list; /* Changed NS list log */ +NvmeSubsystem *subsys;NvmeNamespace namespace;include/block/nvme.h +7
-0@@ -760,6 +760,7 @@ typedef struct QEMU_PACKED NvmeCopySourceRange {enum NvmeAsyncEventRequest {NVME_AER_TYPE_ERROR =0 ,NVME_AER_TYPE_SMART =1 , +NVME_AER_TYPE_NOTICE =2 ,NVME_AER_TYPE_IO_SPECIFIC =6 ,NVME_AER_TYPE_VENDOR_SPECIFIC =7 ,NVME_AER_INFO_ERR_INVALID_DB_REGISTER =0 ,@@ -771,6 +772,7 @@ enum NvmeAsyncEventRequest {NVME_AER_INFO_SMART_RELIABILITY =0 ,NVME_AER_INFO_SMART_TEMP_THRESH =1 ,NVME_AER_INFO_SMART_SPARE_THRESH =2 , + NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED = 0, }; typedef struct QEMU_PACKED NvmeAerResult {@@ -940,6 +942,7 @@ enum NvmeLogIdentifier {NVME_LOG_ERROR_INFO =0x01 ,NVME_LOG_SMART_INFO =0x02 ,NVME_LOG_FW_SLOT_INFO =0x03 , +NVME_LOG_CHANGED_NSLIST =0x04 , NVME_LOG_CMD_EFFECTS = 0x05, };@@ -1046,6 +1049,10 @@ typedef struct NvmeIdCtrlZoned {uint8_t rsvd1[4095 ]; } NvmeIdCtrlZoned; +enum NvmeIdCtrlOaes { +NVME_OAES_NS_ATTR =1 <<8 , +}; +enum NvmeIdCtrlOacs {NVME_OACS_SECURITY =1 <<0 ,NVME_OACS_FORMAT =1 <<1 ,Signature · 1 line
2.25.1
Signature · 1 line
One of us - No more doubt, silence or taboo about mental illness.
Re: [PATCH V3 7/8] hw/block/nvme: support changed namespace asyncrohous event
Quoted 98 lines · Klaus Jensen
Quoted 83 lines · Minwoo Im
If namespace inventory is changed due to some reasons (e.g., namespace attachment/detachment), controller can send out event notifier to the host to manage namespaces.
This patch sends out the AEN to the host after either attach or detach namespaces from controllers. To support clear of the event from the controller, this patch also implemented Get Log Page command for Changed Namespace List log type. To return namespace id list through the command, when namespace inventory is updated, id is added to the per-controller list (
changed_ns_list).To indicate the support of this async event, this patch set OAES(Optional Asynchronous Events Supported) in Identify Controller data structure.
Signed-off-by Minwoo Im <[email protected]>--- hw/block/nvme.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/block/nvme.h | 7 +++++++ include/block/nvme.h | 7 +++++++ 3 files changed, 58 insertions(+)hw/block/nvme.c +32
-0@@ -2980,6 +2980,32 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } +static uint16_t nvme_changed_nslist (NvmeCtrl *n,uint8_t rae,uint32_t buf_len, +uint64_t off,NvmeRequest *req) +{ +uint32_t nslist[1024 ]; +uint32_t trans_len; +NvmeChangedNs *ns, *next; +int i =0 ; + +memset (nslist,0x0 ,sizeof (nslist)); + trans_len =MIN (sizeof (nslist) - off, buf_len); + + QTAILQ_FOREACH_SAFE(ns, &n->changed_ns_list, entry, next) { + nslist[i++] = ns->nsid; + +QTAILQ_REMOVE (&n->changed_ns_list, ns, entry); +g_free (ns); + } + +if (!rae) { +nvme_clear_events (n,NVME_AER_TYPE_NOTICE ); + } + +return nvme_dma (n, ((uint8_t *)nslist) + off, trans_len, +DMA_DIRECTION_FROM_DEVICE , req); +} +static uint16_t nvme_cmd_effects (NvmeCtrl *n,uint8_t csi,uint32_t buf_len,uint64_t off,NvmeRequest *req) {@@ -3064,6 +3090,8 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest *req)return nvme_smart_info (n, rae, len, off, req);case NVME_LOG_FW_SLOT_INFO :return nvme_fw_log_info (n, len, off, req); +case NVME_LOG_CHANGED_NSLIST : +return nvme_changed_nslist (n, rae, len, off, req);case NVME_LOG_CMD_EFFECTS :return nvme_cmd_effects (n, csi, len, off, req);default :@@ -3882,6 +3910,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)uint16_t *ids = &list[1 ];uint16_t ret;int i; +NvmeChangedNs *changed_nsid;trace_pci_nvme_ns_attachment (nvme_cid (req), dw10 &0xf );@@ -3920,6 +3949,18 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)nvme_ns_detach (ctrl, ns); } + +/* +* Add namespace id to the changed namespace id list for event clearing hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 3964
Quoted 10 lines
hw/block/nvme.c +9
-0+* via Get Log Page command. +*/ + changed_nsid =g_new (NvmeChangedNs,1 ); + changed_nsid->nsid = nsid; +QTAILQ_INSERT_TAIL (&ctrl->changed_ns_list, changed_nsid, entry); + +nvme_enqueue_event (ctrl,NVME_AER_TYPE_NOTICE , +NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED , +NVME_LOG_CHANGED_NSLIST ); }If one just keeps attaching/detaching we end up with more than 1024 entries here and go out of bounds in
nvme_changed_nslist.
Quoted 2 lines
How about having the
QTAILQ_ENTRYdirectly on the NvmeNamespace struct and useQTAILQ_IN_USEto check if the namespace is already in the list?
QTAILQ_IN_USE might be tough to represent relationship between controller and namespace itself. So, I will work on this with standard bitmap rather than the list. I think bitmap will be easier to represent the relationship.
Re: [PATCH V3 7/8] hw/block/nvme: support changed namespace asyncrohous event
Quoted 99 lines · Minwoo Im
Quoted 98 lines · Klaus Jensen
Quoted 83 lines · Minwoo Im
If namespace inventory is changed due to some reasons (e.g., namespace attachment/detachment), controller can send out event notifier to the host to manage namespaces.
This patch sends out the AEN to the host after either attach or detach namespaces from controllers. To support clear of the event from the controller, this patch also implemented Get Log Page command for Changed Namespace List log type. To return namespace id list through the command, when namespace inventory is updated, id is added to the per-controller list (
changed_ns_list).To indicate the support of this async event, this patch set OAES(Optional Asynchronous Events Supported) in Identify Controller data structure.
Signed-off-by Minwoo Im <[email protected]>--- hw/block/nvme.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ hw/block/nvme.h | 7 +++++++ include/block/nvme.h | 7 +++++++ 3 files changed, 58 insertions(+)hw/block/nvme.c +32
-0@@ -2980,6 +2980,32 @@ static uint16_t nvme_error_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, DMA_DIRECTION_FROM_DEVICE, req); } +static uint16_t nvme_changed_nslist (NvmeCtrl *n,uint8_t rae,uint32_t buf_len, +uint64_t off,NvmeRequest *req) +{ +uint32_t nslist[1024 ]; +uint32_t trans_len; +NvmeChangedNs *ns, *next; +int i =0 ; + +memset (nslist,0x0 ,sizeof (nslist)); + trans_len =MIN (sizeof (nslist) - off, buf_len); + + QTAILQ_FOREACH_SAFE(ns, &n->changed_ns_list, entry, next) { + nslist[i++] = ns->nsid; + +QTAILQ_REMOVE (&n->changed_ns_list, ns, entry); +g_free (ns); + } + +if (!rae) { +nvme_clear_events (n,NVME_AER_TYPE_NOTICE ); + } + +return nvme_dma (n, ((uint8_t *)nslist) + off, trans_len, +DMA_DIRECTION_FROM_DEVICE , req); +} +static uint16_t nvme_cmd_effects (NvmeCtrl *n,uint8_t csi,uint32_t buf_len,uint64_t off,NvmeRequest *req) {@@ -3064,6 +3090,8 @@ static uint16_t nvme_get_log(NvmeCtrl *n, NvmeRequest *req)return nvme_smart_info (n, rae, len, off, req);case NVME_LOG_FW_SLOT_INFO :return nvme_fw_log_info (n, len, off, req); +case NVME_LOG_CHANGED_NSLIST : +return nvme_changed_nslist (n, rae, len, off, req);case NVME_LOG_CMD_EFFECTS :return nvme_cmd_effects (n, csi, len, off, req);default :@@ -3882,6 +3910,7 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)uint16_t *ids = &list[1 ];uint16_t ret;int i; +NvmeChangedNs *changed_nsid;trace_pci_nvme_ns_attachment (nvme_cid (req), dw10 &0xf );@@ -3920,6 +3949,18 @@ static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req)nvme_ns_detach (ctrl, ns); } + +/* +* Add namespace id to the changed namespace id list for event clearing hw/block/nvme.c static uint16_t nvme_ns_attachment(NvmeCtrl *n, NvmeRequest *req) · line 3964
Quoted 10 lines
hw/block/nvme.c +9
-0+* via Get Log Page command. +*/ + changed_nsid =g_new (NvmeChangedNs,1 ); + changed_nsid->nsid = nsid; +QTAILQ_INSERT_TAIL (&ctrl->changed_ns_list, changed_nsid, entry); + +nvme_enqueue_event (ctrl,NVME_AER_TYPE_NOTICE , +NVME_AER_INFO_NOTICE_NS_ATTR_CHANGED , +NVME_LOG_CHANGED_NSLIST ); }If one just keeps attaching/detaching we end up with more than 1024 entries here and go out of bounds in
nvme_changed_nslist.
Quoted 7 lines
Quoted 2 lines
How about having the
QTAILQ_ENTRYdirectly on the NvmeNamespace struct and useQTAILQ_IN_USEto check if the namespace is already in the list?
QTAILQ_IN_USEmight be tough to represent relationship between controller and namespace itself. So, I will work on this with standard bitmap rather than the list. I think bitmap will be easier to represent the relationship.
OK, sounds reasonable!
PATCH v3 8/8 hw/block/nvme: support Identify NS Attached Controller List
In reply to Minwoo ImSupport Identify command for Namespace attached controller list. This command handler will traverse the controller instances in the given subsystem to figure out whether the specified nsid is attached to the controllers or not.
The 4096bytes Identify data will return with the first entry (16bits) indicating the number of the controller id entries. So, the data can hold up to 2047 entries for the controller ids.
--- hw/block/nvme.c | 42 ++++++++++++++++++++++++++++++++++++++++++ hw/block/trace-events | 1 + include/block/nvme.h | 1 + 3 files changed, 44 insertions(+)
hw/block/nvme.c +42 -0
@@ -3286,6 +3286,46 @@ static uint16_t nvme_identify_ns(NvmeCtrl *n, NvmeRequest *req, bool active)return NVME_INVALID_CMD_SET |NVME_DNR ; } +static uint16_t nvme_identify_ns_attached_list (NvmeCtrl *n,NvmeRequest *req) +{ +NvmeIdentify *c = (NvmeIdentify *)&req->cmd; +uint16_t min_id =le16_to_cpu (c->ctrlid); +uint16_t list[NVME_CONTROLLER_LIST_SIZE ] = {}; +uint16_t *ids = &list[1 ]; +NvmeNamespace *ns; +NvmeCtrl *ctrl; +int cntlid, nr_ids =0 ; + +trace_pci_nvme_identify_ns_attached_list (min_id); + +if (c->nsid ==NVME_NSID_BROADCAST ) { +return NVME_INVALID_FIELD |NVME_DNR ; + } + + ns =nvme_subsys_ns (n->subsys, c->nsid); +if (!ns) { +return NVME_INVALID_FIELD |NVME_DNR ; + } + +for (cntlid = min_id; cntlid <ARRAY_SIZE (n->subsys->ctrls); cntlid++) { + ctrl =nvme_subsys_ctrl (n->subsys, cntlid); +if (!ctrl) { +continue ; + } + +if (!nvme_ns_is_attached (ctrl, ns)) { +continue ; + } + + ids[nr_ids++] = cntlid; + } + + list[0 ] = nr_ids; + +return nvme_dma (n, (uint8_t *)list,sizeof (list), +DMA_DIRECTION_FROM_DEVICE , req); +} +static uint16_t nvme_identify_ns_csi (NvmeCtrl *n,NvmeRequest *req,bool active) {
@@ -3485,6 +3525,8 @@ static uint16_t nvme_identify(NvmeCtrl *n, NvmeRequest *req)return nvme_identify_ns (n, req, true);case NVME_ID_CNS_NS_PRESENT :return nvme_identify_ns (n, req, false); +case NVME_ID_CNS_NS_ATTACHED_CTRL_LIST : +return nvme_identify_ns_attached_list (n, req);case NVME_ID_CNS_CS_NS :return nvme_identify_ns_csi (n, req, true);case NVME_ID_CNS_CS_NS_PRESENT :
hw/block/trace-events +1 -0
@@ -64,6 +64,7 @@ pci_nvme_del_cq(uint16_t cqid) "deleted completion queue, cqid=%"PRIu16"" pci_nvme_identify_ctrl(void) "identify controller" pci_nvme_identify_ctrl_csi(uint8_t csi) "identify controller, csi=0x%"PRIx8"" pci_nvme_identify_ns(uint32_t ns) "nsid %"PRIu32"" +pci_nvme_identify_ns_attached_list(uint16_t cntid) "cntid=%"PRIu16"" pci_nvme_identify_ns_csi(uint32_t ns, uint8_t csi) "nsid=%"PRIu32", csi=0x%"PRIx8"" pci_nvme_identify_nslist(uint32_t ns) "nsid %"PRIu32"" pci_nvme_identify_nslist_csi(uint16_t ns, uint8_t csi) "nsid=%"PRIu16", csi=0x%"PRIx8""
include/block/nvme.h +1 -0
@@ -971,6 +971,7 @@ enum NvmeIdCns {NVME_ID_CNS_CS_NS_ACTIVE_LIST =0x07 ,NVME_ID_CNS_NS_PRESENT_LIST =0x10 ,NVME_ID_CNS_NS_PRESENT =0x11 , +NVME_ID_CNS_NS_ATTACHED_CTRL_LIST =0x12 ,NVME_ID_CNS_CS_NS_PRESENT_LIST =0x1a ,NVME_ID_CNS_CS_NS_PRESENT =0x1b , NVME_ID_CNS_IO_COMMAND_SET = 0x1c,
Signature · 1 line
2.25.1