dusted off ANA code
Subsystems (2)
Christoph Hellwig
maintainerAs we had some ANA discussion I spent some hours over the weekend to dust off my old ANA code. It is mostly feature complete except for the lack of change state handling on the host, but only very lightly tested in this form. It also lacks proper changelogs and testing..
Christoph Hellwig
maintainerPATCH 1/11 nvme.h: untangle AEN notice definitions
Stop including the event type in the definitions for the notice type.
--- drivers/nvme/host/core.c | 30 ++++++++++++++++++------------ include/linux/nvme.h | 8 ++++++-- 2 files changed, 24 insertions(+), 14 deletions(-)
drivers/nvme/host/core.c +18 -12
@@ -3316,6 +3316,21 @@ static void nvme_fw_act_work(struct work_struct *work)nvme_get_fw_slot_info (ctrl); } +static void nvme_handle_aen_notice (struct nvme_ctrl *ctrl,u32 result) +{ +switch ((result &0xff00 ) >>8 ) { +case NVME_AER_NOTICE_NS_CHANGED : +dev_info (ctrl->device,"rescanning\n" ); +nvme_queue_scan (ctrl); +break ; +case NVME_AER_NOTICE_FW_ACT_STARTING : +queue_work (nvme_wq, &ctrl->fw_act_work); +break ; +default : +dev_warn (ctrl->device,"async event result %08x\n" , result); + } +} +void nvme_complete_async_event (struct nvme_ctrl *ctrl,__le16 status,union nvme_result *res) {
@@ -3325,6 +3340,9 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,return ;switch (result &0x7 ) { +case NVME_AER_NOTICE : +nvme_handle_aen_notice (ctrl, result); +break ;case NVME_AER_ERROR :case NVME_AER_SMART :case NVME_AER_CSS :
@@ -3334,18 +3352,6 @@ void nvme_complete_async_event(struct nvme_ctrl *ctrl, __le16 status,default :break ; } - -switch (result &0xff07 ) { -case NVME_AER_NOTICE_NS_CHANGED : -dev_info (ctrl->device,"rescanning\n" ); -nvme_queue_scan (ctrl); -break ; -case NVME_AER_NOTICE_FW_ACT_STARTING : -queue_work (nvme_wq, &ctrl->fw_act_work); -break ; -default : -dev_warn (ctrl->device,"async event result %08x\n" , result); - }queue_work (nvme_wq, &ctrl->async_event_work); }EXPORT_SYMBOL_GPL (nvme_complete_async_event);
include/linux/nvme.h +6 -2
@@ -436,10 +436,14 @@ enum {enum {NVME_AER_ERROR =0 ,NVME_AER_SMART =1 , +NVME_AER_NOTICE =2 ,NVME_AER_CSS =6 ,NVME_AER_VS =7 , -NVME_AER_NOTICE_NS_CHANGED =0x0002 , -NVME_AER_NOTICE_FW_ACT_STARTING =0x0102 , +}; + +enum { +NVME_AER_NOTICE_NS_CHANGED =0x00 , +NVME_AER_NOTICE_FW_ACT_STARTING =0x01 , };struct nvme_lba_range_type {
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 2/11 nvme.h: add ANA definitions
In reply to Christoph HellwigAdd various defintions from NVMe 1.3 TP 4004.
--- include/linux/nvme.h | 49 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-)
include/linux/nvme.h +46 -3
@@ -242,7 +242,12 @@ struct nvme_id_ctrl {__le32 sanicap;__le32 hmminds;__le16 hmmaxd; -__u8 rsvd338[174 ]; +__u8 rsvd338[4 ]; +__u8 anatt; +__u8 anacap; +__le32 anagrpmax; +__le32 nanagrpid; +__u8 rsvd352[160 ];__u8 sqes;__u8 cqes;__le16 maxcmd;
@@ -258,7 +263,8 @@ struct nvme_id_ctrl {__le16 acwu;__u8 rsvd534[2 ];__le32 sgls; -__u8 rsvd540[228 ]; +__le32 mnan; +__u8 rsvd544[224 ];char subnqn[256 ];__u8 rsvd1024[768 ];__le32 ioccsz;
@@ -312,7 +318,9 @@ struct nvme_id_ns {__le16 nabspf;__le16 noiob;__u8 nvmcap[16 ]; -__u8 rsvd64[40 ]; +__u8 rsvd64[28 ]; +__le32 anagrpid; +__u8 rsvd96[8 ];__u8 nguid[16 ];__u8 eui64[8 ];struct nvme_lbaf lbaf[16 ];
@@ -425,6 +433,32 @@ struct nvme_effects_log {__u8 resv[2048 ]; }; +enum nvme_ana_state { +NVME_ANA_OPTIMIZED =0x01 , +NVME_ANA_NONOPTIMIZED =0x02 , +NVME_ANA_INACCESSIBLE =0x03 , +NVME_ANA_PERSISTENT_LOSS =0x04 , +NVME_ANA_CHANGE =0x05 , +}; + +struct nvme_ana_group_desc { +__le32 grpid; +__le32 nnsids; +__le64 chgcnt; +__u8 state; +__u8 rsvd17[7 ]; +__le32 nsids[]; +}; + +/* flag for the log specific field of the ANA log */ +#define NVME_ANA_LOG_RGO (1 << 0) + +struct nvme_ana_rsp_hdr { +__le64 chgcnt; +__le16 ngrps; +__le16 rsvd10[3 ]; +}; +enum {NVME_SMART_CRIT_SPARE =1 <<0 ,NVME_SMART_CRIT_TEMPERATURE =1 <<1 ,
@@ -444,6 +478,7 @@ enum {enum {NVME_AER_NOTICE_NS_CHANGED =0x00 ,NVME_AER_NOTICE_FW_ACT_STARTING =0x01 , +NVME_AER_NOTICE_ANA =0x03 , };struct nvme_lba_range_type {
@@ -752,6 +787,7 @@ enum {NVME_LOG_SMART =0x02 ,NVME_LOG_FW_SLOT =0x03 ,NVME_LOG_CMD_EFFECTS =0x05 , +NVME_LOG_ANA =0x0c ,NVME_LOG_DISC =0x70 ,NVME_LOG_RESERVATION =0x80 , NVME_FWACT_REPL = (0 << 3),
@@ -1172,6 +1208,13 @@ enum {NVME_SC_ACCESS_DENIED =0x286 ,NVME_SC_UNWRITTEN_BLOCK =0x287 , +/* +* Path-related Errors: +*/ +NVME_SC_ANA_PERSISTENT_LOSS =0x301 , +NVME_SC_ANA_INACCESSIBLE =0x302 , +NVME_SC_ANA_TRANSITION =0x303 , + NVME_SC_DNR = 0x4000, };
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 3/11 nvme: add support for the log specific field
In reply to Christoph HellwigNVMe 1.3 added a new log specific field to the get log page CQ defintion. Add the field and support passing it to nvme_get_log_ext.
--- drivers/nvme/host/core.c | 6 +++--- drivers/nvme/host/lightnvm.c | 2 +- drivers/nvme/host/nvme.h | 2 +- include/linux/nvme.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-)
drivers/nvme/host/core.c +3 -3
@@ -2226,8 +2226,7 @@ static int nvme_init_subsystem(struct nvme_ctrl *ctrl, struct nvme_id_ctrl *id) }int nvme_get_log_ext (struct nvme_ctrl *ctrl,struct nvme_ns *ns, -u8 log_page,void *log, -size_t size,u64 offset) +u8 log_page,u8 lsp,void *log,size_t size,u64 offset) {struct nvme_command c = { };unsigned long dwlen = size /4 -1 ;
@@ -2240,6 +2239,7 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns, c.get_log_page.nsid =cpu_to_le32 (NVME_NSID_ALL ); c.get_log_page.lid = log_page; + c.get_log_page.lsp = lsp; c.get_log_page.numdl =cpu_to_le16 (dwlen & ((1 <<16 ) -1 )); c.get_log_page.numdu =cpu_to_le16 (dwlen >>16 ); c.get_log_page.lpol =cpu_to_le32 (lower_32_bits (offset));
@@ -2251,7 +2251,7 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,static int nvme_get_log (struct nvme_ctrl *ctrl,u8 log_page,void *log,size_t size) { -return nvme_get_log_ext (ctrl,NULL , log_page, log, size,0 ); +return nvme_get_log_ext (ctrl,NULL , log_page,0 , log, size,0 ); }static int nvme_get_effects_log (struct nvme_ctrl *ctrl)
drivers/nvme/host/lightnvm.c +1 -1
@@ -598,7 +598,7 @@ static int nvme_nvm_get_chk_meta(struct nvm_dev *ndev,while (left) { len = min_t(unsigned int, left, ctrl->max_hw_sectors << 9); - ret =nvme_get_log_ext (ctrl, ns,NVME_NVM_LOG_REPORT_CHUNK , + ret =nvme_get_log_ext (ctrl, ns,NVME_NVM_LOG_REPORT_CHUNK ,0 , dev_meta, len, offset);if (ret) {dev_err (ctrl->device,"Get REPORT CHUNK log error\n" );
drivers/nvme/host/nvme.h +1 -1
@@ -430,7 +430,7 @@ int nvme_delete_ctrl(struct nvme_ctrl *ctrl);int nvme_delete_ctrl_sync (struct nvme_ctrl *ctrl);int nvme_get_log_ext (struct nvme_ctrl *ctrl,struct nvme_ns *ns, -u8 log_page,void *log,size_t size,u64 offset); +u8 log_page,u8 lsp,void *log,size_t size,u64 offset);extern const struct attribute_group nvme_ns_id_attr_group;extern const struct block_device_operations nvme_ns_head_ops;
include/linux/nvme.h +1 -1
@@ -908,7 +908,7 @@ struct nvme_get_log_page_command {__u64 rsvd2[2 ];union nvme_data_ptr dptr;__u8 lid; -__u8 rsvd10; +__u8 lsp;/* upper 4 bits reserved */ __le16 numdl;__le16 numdu;__u16 rsvd11;
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 4/11 nvme: always failover on path or transport errors
In reply to Christoph HellwigNVMe 1.3 TP 4028 introduced a new status code type 3h for "Path Related Status". We should always retry on another path for this class of errors, without even trying to decode them.
--- drivers/nvme/host/multipath.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/nvme/host/multipath.c +2 -0
@@ -59,6 +59,8 @@ bool nvme_req_needs_failover(struct request *req, blk_status_t error) {if (!(req->cmd_flags &REQ_NVME_MPATH ))return false; +if (nvme_req (req)->status &0x300 ) +return true;return blk_path_error (error); }
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 5/11 nvme: add ANA support
In reply to Christoph Hellwig--- drivers/nvme/host/core.c | 28 +++++ drivers/nvme/host/multipath.c | 189 +++++++++++++++++++++++++++++++++- drivers/nvme/host/nvme.h | 27 +++++ 3 files changed, 239 insertions(+), 5 deletions(-)
drivers/nvme/host/core.c +28 -0
@@ -1443,6 +1443,7 @@ static void __nvme_revalidate_disk(struct gendisk *disk, struct nvme_id_ns *id) ns->lba_shift = id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ds;if (ns->lba_shift ==0 ) ns->lba_shift =9 ; + ns->anagrpid =le32_to_cpu (id->anagrpid); ns->noiob =le16_to_cpu (id->noiob); ns->ext = ns->ms && (id->flbas &NVME_NS_FLBAS_META_EXT ); ns->ms =le16_to_cpu (id->lbaf[id->flbas &NVME_NS_FLBAS_LBA_MASK ].ms);
@@ -2355,6 +2356,10 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)nvme_set_queue_limits (ctrl, ctrl->admin_q); ctrl->sgls =le32_to_cpu (id->sgls); ctrl->kas =le16_to_cpu (id->kas); + ctrl->max_namespaces =le32_to_cpu (id->mnan); + ctrl->anacap = id->anacap; + ctrl->nanagrpid =le32_to_cpu (id->nanagrpid); + ctrl->anagrpmax =le32_to_cpu (id->anagrpmax);if (id->rtd3e) {/* us -> s */
@@ -2433,6 +2438,10 @@ int nvme_init_identify(struct nvme_ctrl *ctrl)if (ret <0 )return ret; + ret =nvme_configure_ana (ctrl); +if (ret <0 ) +return ret; + ctrl->identified = true;return 0 ;
@@ -2634,6 +2643,10 @@ static struct attribute *nvme_ns_id_attrs[] = { &dev_attr_nguid.attr, &dev_attr_eui.attr, &dev_attr_nsid.attr, +#ifdef CONFIG_NVME_MULTIPATH + &dev_attr_ana_grpid.attr, + &dev_attr_ana_state.attr, +#endif NULL, };
@@ -2656,6 +2669,14 @@ static umode_t nvme_ns_id_attrs_are_visible(struct kobject *kobj,if (!memchr_inv (ids->eui64,0 ,sizeof (ids->eui64)))return 0 ; } +#ifdef CONFIG_NVME_MULTIPATH +if (a == &dev_attr_ana_grpid.attr || a == &dev_attr_ana_state.attr) { +if (dev_to_disk (dev)->fops != &nvme_fops)/* per-path attr */ +return 0 ; +if (!nvme_ctrl_has_ana (nvme_get_ns_from_dev (dev)->ctrl)) +return 0 ; + } +#endif return a->mode; }
@@ -3326,6 +3347,11 @@ static void nvme_handle_aen_notice(struct nvme_ctrl *ctrl, u32 result)case NVME_AER_NOTICE_FW_ACT_STARTING :queue_work (nvme_wq, &ctrl->fw_act_work);break ; +case NVME_AER_NOTICE_ANA : +if (WARN_ON_ONCE (!ctrl->ana_log_buf)) +break ; +queue_work (nvme_wq, &ctrl->ana_work); +break ;default :dev_warn (ctrl->device,"async event result %08x\n" , result); }
@@ -3361,6 +3387,7 @@ void nvme_stop_ctrl(struct nvme_ctrl *ctrl)nvme_stop_keep_alive (ctrl);flush_work (&ctrl->async_event_work);flush_work (&ctrl->scan_work); +cancel_work_sync (&ctrl->ana_work);cancel_work_sync (&ctrl->fw_act_work);if (ctrl->ops->stop_ctrl) ctrl->ops->stop_ctrl (ctrl);
@@ -3394,6 +3421,7 @@ static void nvme_free_ctrl(struct device *dev)ida_simple_remove (&nvme_instance_ida, ctrl->instance);kfree (ctrl->effects); +nvme_deconfigure_ana (ctrl);if (subsys) {mutex_lock (&subsys->lock);
drivers/nvme/host/multipath.c +184 -5
214 lines not on this page · raw message
drivers/nvme/host/nvme.h +27 -0
@@ -168,6 +168,7 @@ struct nvme_ctrl {u16 oacs;u16 nssa;u16 nr_streams; +u32 max_namespaces;atomic_t abort_limit;u8 vwc;u32 vs;
@@ -188,6 +189,15 @@ struct nvme_ctrl {struct nvme_command ka_cmd;struct work_struct fw_act_work; +/* asymmetric namespace access: */ +u8 anacap; +u32 anagrpmax; +u32 nanagrpid; +enum nvme_ana_state *ana_state; +size_t ana_log_size; +struct nvme_ana_rsp_hdr *ana_log_buf; +struct work_struct ana_work; +/* Power saving configuration */ u64 ps_max_latency_us;bool apst_enabled;
@@ -293,6 +303,7 @@ struct nvme_ns {#define NVME_NS_REMOVING 0#define NVME_NS_DEAD 1u16 noiob; +u32 anagrpid;#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS struct nvme_fault_inject fault_inject;
@@ -435,6 +446,11 @@ int nvme_get_log_ext(struct nvme_ctrl *ctrl, struct nvme_ns *ns,extern const struct attribute_group nvme_ns_id_attr_group;extern const struct block_device_operations nvme_ns_head_ops; +static inline bool nvme_ctrl_has_ana (struct nvme_ctrl *ctrl) +{ +return ctrl->subsys->cmic & (1 <<3 ); +} +#ifdef CONFIG_NVME_MULTIPATH void nvme_set_disk_name (char *disk_name,struct nvme_ns *ns,struct nvme_ctrl *ctrl,int *flags);
@@ -444,6 +460,8 @@ void nvme_kick_requeue_lists(struct nvme_ctrl *ctrl);int nvme_mpath_alloc_disk (struct nvme_ctrl *ctrl,struct nvme_ns_head *head);void nvme_mpath_add_disk (struct nvme_ns_head *head);void nvme_mpath_remove_disk (struct nvme_ns_head *head); +int nvme_configure_ana (struct nvme_ctrl *ctrl); +void nvme_deconfigure_ana (struct nvme_ctrl *ctrl);static inline void nvme_mpath_clear_current_path (struct nvme_ns *ns) {
@@ -462,6 +480,9 @@ static inline void nvme_mpath_check_last_path(struct nvme_ns *ns) kblockd_schedule_work(&head->requeue_work); } +extern struct device_attribute dev_attr_ana_grpid; +extern struct device_attribute dev_attr_ana_state; +#else /* * Without the multipath code enabled, multiple controller per subsystems are
@@ -501,6 +522,12 @@ static inline void nvme_mpath_clear_current_path(struct nvme_ns *ns)static inline void nvme_mpath_check_last_path (struct nvme_ns *ns) { } +static inline int nvme_configure_ana (struct nvme_ctrl *ctrl) +{ +} +static inline void nvme_deconfigure_ana (struct nvme_ctrl *ctrl) +{ +}#endif /* CONFIG_NVME_MULTIPATH */ #ifdef CONFIG_NVM
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 6/11 nvmet: refactor AER handling
In reply to Christoph HellwigCreate a helper to iterate all controlles in a subsystem instead of open coding the loop. Also use the NVME_AER_NOTICE_NS_CHANGED definition instead of plain 0.
--- drivers/nvme/target/core.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-)
drivers/nvme/target/core.c +15 -8
@@ -137,6 +137,19 @@ static void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,schedule_work (&ctrl->async_event_work); } +static void nvmet_send_ns_changed_event (struct nvmet_subsys *subsys) +{ +/* +* XXX: should also include the log id, but the changed namespace list +* log needs to be implemented first.. +*/ +struct nvmet_ctrl *ctrl; + +list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry) +nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE , +NVME_AER_NOTICE_NS_CHANGED ,0 ); +} +int nvmet_register_transport (const struct nvmet_fabrics_ops *ops) {int ret =0 ;
@@ -274,7 +287,6 @@ void nvmet_put_namespace(struct nvmet_ns *ns)int nvmet_ns_enable (struct nvmet_ns *ns) {struct nvmet_subsys *subsys = ns->subsys; -struct nvmet_ctrl *ctrl;int ret =0 ;mutex_lock (&subsys->lock);
@@ -320,9 +332,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)list_add_tail_rcu (&ns->dev_link, &old->dev_link); } -list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry) -nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE ,0 ,0 ); - +nvmet_send_ns_changed_event (subsys); ns->enabled = true; ret =0 ; out_unlock:
@@ -337,7 +347,6 @@ int nvmet_ns_enable(struct nvmet_ns *ns)void nvmet_ns_disable (struct nvmet_ns *ns) {struct nvmet_subsys *subsys = ns->subsys; -struct nvmet_ctrl *ctrl;mutex_lock (&subsys->lock);if (!ns->enabled)
@@ -363,9 +372,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns)percpu_ref_exit (&ns->ref);mutex_lock (&subsys->lock); -list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry) -nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE ,0 ,0 ); - +nvmet_send_ns_changed_event (subsys);if (ns->bdev)blkdev_put (ns->bdev,FMODE_WRITE |FMODE_READ ); out_unlock:
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 7/11 nvmet: add a new nvmet_zero_sgl helper
In reply to Christoph HellwigZeroes the SGL in the payload.
--- drivers/nvme/target/core.c | 7 +++++++ drivers/nvme/target/nvmet.h | 1 + 2 files changed, 8 insertions(+)
drivers/nvme/target/core.c +7 -0
@@ -57,6 +57,13 @@ u16 nvmet_copy_from_sgl(struct nvmet_req *req, off_t off, void *buf, size_t len)return 0 ; } +u16 nvmet_zero_sgl (struct nvmet_req *req,off_t off,size_t len) +{ +if (sg_zero_buffer (req->sg, req->sg_cnt, len, off) != len) +return NVME_SC_SGL_INVALID_DATA |NVME_SC_DNR ; +return 0 ; +} +static unsigned int nvmet_max_nsid (struct nvmet_subsys *subsys) {struct nvmet_ns *ns;
drivers/nvme/target/nvmet.h +1 -0
@@ -316,6 +316,7 @@ u16 nvmet_copy_to_sgl(struct nvmet_req *req, off_t off, const void *buf, size_t len);u16 nvmet_copy_from_sgl (struct nvmet_req *req,off_t off,void *buf,size_t len); +u16 nvmet_zero_sgl (struct nvmet_req *req,off_t off,size_t len);u32 nvmet_get_log_page_len (struct nvme_command *cmd);
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 8/11 nvmet: split log page implementation
In reply to Christoph HellwigRemove the common code to allocate a buffer and copy it into the SGL. Instead the two no-op implementations just zero the SGL directly, and the smart log allocates a buffer on its own. This prepares for the more elaborate ANA log page.
--- drivers/nvme/target/admin-cmd.c | 101 ++++++++++++-------------------- 1 file changed, 37 insertions(+), 64 deletions(-)
drivers/nvme/target/admin-cmd.c +37 -64
@@ -32,6 +32,11 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd)return len; } +static void nvmet_execute_get_log_page_noop (struct nvmet_req *req) +{ +nvmet_req_complete (req,nvmet_zero_sgl (req,0 , req->data_len)); +} +static u16 nvmet_get_smart_log_nsid (struct nvmet_req *req,struct nvme_smart_log *slog) {
@@ -89,74 +94,26 @@ static u16 nvmet_get_smart_log_all(struct nvmet_req *req,return NVME_SC_SUCCESS ; } -static u16 nvmet_get_smart_log (struct nvmet_req *req, -struct nvme_smart_log *slog) +static void nvmet_execute_get_log_page_smart (struct nvmet_req *req) { -u16 status; +struct nvme_smart_log *log; +u16 status =NVME_SC_INTERNAL ; -WARN_ON (req ==NULL || slog ==NULL ); -if (req->cmd->get_log_page.nsid ==cpu_to_le32 (NVME_NSID_ALL )) - status =nvmet_get_smart_log_all (req, slog); -else - status =nvmet_get_smart_log_nsid (req, slog); -return status; -} - -static void nvmet_execute_get_log_page (struct nvmet_req *req) -{ -struct nvme_smart_log *smart_log; -size_t data_len =nvmet_get_log_page_len (req->cmd); -void *buf; -u16 status =0 ; - - buf =kzalloc (data_len,GFP_KERNEL ); -if (!buf) { - status =NVME_SC_INTERNAL ; +if (req->data_len !=sizeof (*log)) goto out; - } -switch (req->cmd->get_log_page.lid) { -case NVME_LOG_ERROR : -/* -* We currently never set the More bit in the status field, -* so all error log entries are invalid and can be zeroed out. -* This is called a minum viable implementation (TM) of this -* mandatory log page. -*/ -break ; -case NVME_LOG_SMART : -/* -* XXX: fill out actual smart log -* -* We might have a hard time coming up with useful values for -* many of the fields, and even when we have useful data -* available (e.g. units or commands read/written) those aren't -* persistent over power loss. -*/ -if (data_len !=sizeof (*smart_log)) { - status =NVME_SC_INTERNAL ; - goto err; - } - smart_log = buf; - status =nvmet_get_smart_log (req, smart_log); -if (status) - goto err; -break ; -case NVME_LOG_FW_SLOT : -/* -* We only support a single firmware slot which always is -* active, so we can zero out the whole firmware slot log and -* still claim to fully implement this mandatory log page. -*/ -break ; -default : -BUG (); - } + log =kzalloc (sizeof (*log),GFP_KERNEL ); +if (!log) + goto out; - status =nvmet_copy_to_sgl (req,0 , buf, data_len); +if (req->cmd->get_log_page.nsid ==cpu_to_le32 (NVME_NSID_ALL )) + status =nvmet_get_smart_log_all (req, log); +else + status =nvmet_get_smart_log_nsid (req, log); +if (status) + goto out; -err: -kfree (buf); + status =nvmet_copy_to_sgl (req,0 , log,sizeof (*log)); out:nvmet_req_complete (req, status); }
@@ -560,9 +517,25 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)switch (cmd->get_log_page.lid) {case NVME_LOG_ERROR : -case NVME_LOG_SMART : +/* +* We currently never set the More bit in the status +* field, so all error log entries are invalid and can +* be zeroed out. This is called a minum viable +* implementation (TM) of this mandatory log page. +*/ + req->execute = nvmet_execute_get_log_page_noop; +return 0 ;case NVME_LOG_FW_SLOT : - req->execute = nvmet_execute_get_log_page; +/* +* We only support a single firmware slot which always +* is active, so we can zero out the whole firmware slot +* log and still claim to fully implement this mandatory +* log page. +*/ + req->execute = nvmet_execute_get_log_page_noop; +return 0 ; +case NVME_LOG_SMART : + req->execute = nvmet_execute_get_log_page_smart;return 0 ; }break ;
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 9/11 nvmet: track and limit the number of namespaces per subsystem
In reply to Christoph HellwigTP 4004 introduces a new 'Maximum Number of Allocated Namespaces' field in the Identify controller data to help the host size resources. Put an upper limit on the supported namespaces to be able to support this value as supporting 32-bits worth of namespaces would lead to very large buffers. The limit is completely arbitrary at this point.
--- drivers/nvme/target/admin-cmd.c | 1 + drivers/nvme/target/core.c | 8 +++++++- drivers/nvme/target/nvmet.h | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-)
drivers/nvme/target/admin-cmd.c +1 -0
@@ -188,6 +188,7 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) id->maxcmd =cpu_to_le16 (NVMET_MAX_CMD ); id->nn =cpu_to_le32 (ctrl->subsys->max_nsid); + id->mnan =cpu_to_le32 (NVMET_MAX_NAMESPACES ); id->oncs =cpu_to_le16 (NVME_CTRL_ONCS_DSM |NVME_CTRL_ONCS_WRITE_ZEROES );
drivers/nvme/target/core.c +7 -1
@@ -294,9 +294,13 @@ void nvmet_put_namespace(struct nvmet_ns *ns)int nvmet_ns_enable (struct nvmet_ns *ns) {struct nvmet_subsys *subsys = ns->subsys; -int ret =0 ; +int ret;mutex_lock (&subsys->lock); + ret = -EMFILE ; +if (subsys->nr_namespaces ==NVMET_MAX_NAMESPACES ) + goto out_unlock; + ret =0 ;if (ns->enabled) goto out_unlock;
@@ -338,6 +342,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)list_add_tail_rcu (&ns->dev_link, &old->dev_link); } + subsys->nr_namespaces++;nvmet_send_ns_changed_event (subsys); ns->enabled = true;
@@ -379,6 +384,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns)percpu_ref_exit (&ns->ref);mutex_lock (&subsys->lock); + subsys->nr_namespaces--;nvmet_send_ns_changed_event (subsys);if (ns->bdev)blkdev_put (ns->bdev,FMODE_WRITE |FMODE_READ );
drivers/nvme/target/nvmet.h +8 -0
@@ -143,6 +143,7 @@ struct nvmet_subsys {struct kref ref;struct list_head namespaces; +unsigned int nr_namespaces;unsigned int max_nsid;struct list_head ctrls;
@@ -323,6 +324,13 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd);#define NVMET_QUEUE_SIZE 1024#define NVMET_NR_QUEUES 128#define NVMET_MAX_CMD NVMET_QUEUE_SIZE + +/* +* Nice round number that makes a list of nsids fit into a page. +* Should become tunable at some point in the future. +*/ +#define NVMET_MAX_NAMESPACES 1024 +#define NVMET_KAS 10#define NVMET_DISC_KATO 120
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 10/11 nvmet: add minimal ANA support
In reply to Christoph HellwigJust add a default ANA group 1 that is optimized on all ports. This is (and will remain) the default assignment for any namespace not epxlicitly assigned to another ANA group.
--- drivers/nvme/target/admin-cmd.c | 80 ++++++++++++++++++++++++++++++++- drivers/nvme/target/configfs.c | 10 +++++ drivers/nvme/target/core.c | 17 +++++++ drivers/nvme/target/io-cmd.c | 17 +++++++ drivers/nvme/target/nvmet.h | 15 +++++++ 5 files changed, 137 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +78 -2
@@ -118,6 +118,73 @@ static void nvmet_execute_get_log_page_smart(struct nvmet_req *req)nvmet_req_complete (req, status); } +static u32 nvmet_format_ana_group (struct nvmet_req *req,u32 grpid, +struct nvme_ana_group_desc *desc) +{ +struct nvmet_ctrl *ctrl = req->sq->ctrl; +struct nvmet_ns *ns; +u32 count =0 ; + +if (!(req->cmd->get_log_page.lsp &NVME_ANA_LOG_RGO )) { +rcu_read_lock (); +list_for_each_entry_rcu (ns, &ctrl->subsys->namespaces, dev_link) +if (ns->anagrpid == grpid) + desc->nsids[count++] =cpu_to_le32 (ns->nsid); +rcu_read_unlock (); + } + + desc->grpid =cpu_to_le32 (grpid); + desc->nnsids =cpu_to_le32 (count); + desc->chgcnt =cpu_to_le64 (nvmet_ana_chgcnt); + desc->state = req->port->ana_state[grpid]; +memset (desc->rsvd17,0 ,sizeof (desc->rsvd17)); +memset (desc->nsids + count,0 , + (NVMET_MAX_NAMESPACES - count) *sizeof (__le32)); + +return sizeof (struct nvme_ana_group_desc ) + count *sizeof (__le32); +} + +static void nvmet_execute_get_log_page_ana (struct nvmet_req *req) +{ +struct nvme_ana_rsp_hdr hdr = {0 , }; +struct nvme_ana_group_desc *desc; +size_t offset =sizeof (struct nvme_ana_rsp_hdr );/* start beyond hdr */ +size_t len; +u32 grpid; +u16 ngrps =0 ; +u16 status; + + status =NVME_SC_INTERNAL ; + desc =kmalloc (sizeof (struct nvme_ana_group_desc ) + +NVMET_MAX_NAMESPACES *sizeof (__le32),GFP_KERNEL ); +if (!desc) + goto out; + +down_read (&nvmet_ana_sem); +for (grpid =1 ; grpid <=NVMET_MAX_ANAGRPS ; grpid++) { +if (!nvmet_ana_group_enabled[grpid]) +continue ; + + len =nvmet_format_ana_group (req, grpid, desc); + status =nvmet_copy_to_sgl (req, offset, desc, len); +if (status) +break ; + offset += len; + ngrps++; + } + + hdr.chgcnt =cpu_to_le64 (nvmet_ana_chgcnt); + hdr.ngrps =cpu_to_le16 (ngrps); +up_read (&nvmet_ana_sem); + +kfree (desc); + +/* copy the header last once we know the information */ + status =nvmet_copy_to_sgl (req,0 , &hdr,sizeof (hdr)); +out: +nvmet_req_complete (req, status); +} +static void nvmet_execute_identify_ctrl (struct nvmet_req *req) {struct nvmet_ctrl *ctrl = req->sq->ctrl;
@@ -149,8 +216,8 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)* the safest is to leave it as zeroes. */ -/* we support multiple ports and multiples hosts: */ - id->cmic = (1 <<0 ) | (1 <<1 ); +/* we support multiple ports, multiples hosts and ANA: */ + id->cmic = (1 <<0 ) | (1 <<1 ) | (1 <<3 );/* no limit on data transfer sizes for now */ id->mdts =0 ;
@@ -218,6 +285,11 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req) id->msdbd = ctrl->ops->msdbd; + id->anacap = (1 <<0 ) | (1 <<1 ) | (1 <<2 ) | (1 <<3 ) | (1 <<4 ); + id->anatt =10 ;/* random value */ + id->anagrpmax =cpu_to_le32 (NVMET_MAX_ANAGRPS ); + id->nanagrpid =cpu_to_le32 (NVMET_MAX_ANAGRPS ); +/* * Meh, we don't really support any power state. Fake up the same * values that qemu does.
@@ -270,6 +342,7 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)* controllers, but also with any other user of the block device. */ id->nmic = (1 <<0 ); + id->anagrpid =cpu_to_le32 (ns->anagrpid);memcpy (&id->nguid, &ns->nguid,sizeof (uuid_le));
@@ -538,6 +611,9 @@ u16 nvmet_parse_admin_cmd(struct nvmet_req *req)case NVME_LOG_SMART : req->execute = nvmet_execute_get_log_page_smart;return 0 ; +case NVME_LOG_ANA : + req->execute = nvmet_execute_get_log_page_ana; +return 0 ; }break ;case nvme_admin_identify:
drivers/nvme/target/configfs.c +10 -0
@@ -861,6 +861,7 @@ static void nvmet_port_release(struct config_item *item) {struct nvmet_port *port =to_nvmet_port (item); +kfree (port->ana_state);kfree (port); }
@@ -896,6 +897,15 @@ static struct config_group *nvmet_ports_make(struct config_group *group,if (!port)return ERR_PTR (-ENOMEM ); + port->ana_state =kcalloc (NVMET_MAX_ANAGRPS +1 , +sizeof (*port->ana_state),GFP_KERNEL ); +if (!port->ana_state) { +kfree (port); +return ERR_PTR (-ENOMEM ); + } + + port->ana_state[NVMET_DEFAULT_ANA_GRPID ] =NVME_ANA_OPTIMIZED ; +INIT_LIST_HEAD (&port->entry);INIT_LIST_HEAD (&port->subsystems);INIT_LIST_HEAD (&port->referrals);
drivers/nvme/target/core.c +17 -0
@@ -39,6 +39,10 @@ static DEFINE_IDA(cntlid_ida);*/ DECLARE_RWSEM (nvmet_config_sem); +u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS +1 ]; +u64 nvmet_ana_chgcnt; +DECLARE_RWSEM (nvmet_ana_sem); +static struct nvmet_subsys *nvmet_find_get_subsys (struct nvmet_port *port,const char *subsysnqn);
@@ -396,6 +400,10 @@ void nvmet_ns_free(struct nvmet_ns *ns) {nvmet_ns_disable (ns); +down_write (&nvmet_ana_sem); + nvmet_ana_group_enabled[ns->anagrpid]--; +up_write (&nvmet_ana_sem); +kfree (ns->device_path);kfree (ns); }
@@ -413,6 +421,12 @@ struct nvmet_ns *nvmet_ns_alloc(struct nvmet_subsys *subsys, u32 nsid) ns->nsid = nsid; ns->subsys = subsys; + +down_write (&nvmet_ana_sem); + ns->anagrpid =NVMET_DEFAULT_ANA_GRPID ; + nvmet_ana_group_enabled[ns->anagrpid]++; +up_write (&nvmet_ana_sem); +uuid_gen (&ns->uuid);return ns;
@@ -1051,6 +1065,8 @@ static int __init nvmet_init(void) {int error; + nvmet_ana_group_enabled[NVMET_DEFAULT_ANA_GRPID ] =1 ; + error =nvmet_init_discovery ();if (error) goto out;
@@ -1058,6 +1074,7 @@ static int __init nvmet_init(void) error =nvmet_init_configfs ();if (error) goto out_exit_discovery; +return 0 ; out_exit_discovery:
drivers/nvme/target/io-cmd.c +17 -0
@@ -189,6 +189,20 @@ static void nvmet_execute_write_zeroes(struct nvmet_req *req) } } +static u16 nvmet_check_ana_state (struct nvmet_port *port, +struct nvmet_ns *ns) +{ +enum nvme_ana_state state = port->ana_state[ns->anagrpid]; + +if (unlikely (state ==NVME_ANA_INACCESSIBLE )) +return NVME_SC_ANA_INACCESSIBLE ; +if (unlikely (state ==NVME_ANA_PERSISTENT_LOSS )) +return NVME_SC_ANA_PERSISTENT_LOSS ; +if (unlikely (state ==NVME_ANA_CHANGE )) +return NVME_SC_ANA_TRANSITION ; +return 0 ; +} +u16 nvmet_parse_io_cmd (struct nvmet_req *req) {struct nvme_command *cmd = req->cmd;
@@ -203,6 +217,9 @@ u16 nvmet_parse_io_cmd(struct nvmet_req *req) req->ns =nvmet_find_namespace (req->sq->ctrl, cmd->rw.nsid);if (unlikely (!req->ns))return NVME_SC_INVALID_NS |NVME_SC_DNR ; + ret =nvmet_check_ana_state (req->port, req->ns); +if (unlikely (ret)) +return ret;switch (cmd->common.opcode) {case nvme_cmd_read:
drivers/nvme/target/nvmet.h +15 -0
@@ -48,6 +48,7 @@ struct nvmet_ns {loff_t size;u8 nguid[16 ];uuid_t uuid; +u32 anagrpid;bool enabled;struct nvmet_subsys *subsys;
@@ -96,6 +97,7 @@ struct nvmet_port {struct list_head subsystems;struct config_group referrals_group;struct list_head referrals; +enum nvme_ana_state *ana_state;void *priv;bool enabled; };
@@ -331,6 +333,15 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd);*/ #define NVMET_MAX_NAMESPACES 1024 +/* +* 0 is not a valid ANA group ID, so we start numbering at 1. +* +* ANA Group 1 exists without manual intervention, has namespaces assigned to it +* by default, and is available in an optimized state through all ports. +*/ +#define NVMET_MAX_ANAGRPS 1 +#define NVMET_DEFAULT_ANA_GRPID 1 +#define NVMET_KAS 10#define NVMET_DISC_KATO 120
@@ -344,6 +355,10 @@ extern struct nvmet_subsys *nvmet_disc_subsys;extern u64 nvmet_genctr;extern struct rw_semaphore nvmet_config_sem; +extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS +1 ]; +extern u64 nvmet_ana_chgcnt; +extern struct rw_semaphore nvmet_ana_sem; +bool nvmet_host_allowed (struct nvmet_req *req,struct nvmet_subsys *subsys,const char *hostnqn);
Signature · 1 line
2.17.0
Christoph Hellwig
maintainerPATCH 11/11 nvmet: support configuring additional ANA groups
In reply to Christoph HellwigMostly configfs boilerplate.
--- drivers/nvme/target/configfs.c | 170 ++++++++++++++++++++++++++++++++- drivers/nvme/target/core.c | 21 ++++ drivers/nvme/target/nvmet.h | 26 ++++- 3 files changed, 215 insertions(+), 2 deletions(-)
drivers/nvme/target/configfs.c +169 -1
@@ -378,6 +378,39 @@ static ssize_t nvmet_ns_device_nguid_store(struct config_item *item,CONFIGFS_ATTR (nvmet_ns_, device_nguid); +static ssize_t nvmet_ns_ana_grpid_show (struct config_item *item,char *page) +{ +return sprintf (page,"%u\n" ,to_nvmet_ns (item)->anagrpid); +} + +static ssize_t nvmet_ns_ana_grpid_store (struct config_item *item, +const char *page,size_t count) +{ +struct nvmet_ns *ns =to_nvmet_ns (item); +u32 oldgrpid, newgrpid; +int ret; + + ret =kstrtou32 (page,0 , &newgrpid); +if (ret) +return ret; + +if (newgrpid <1 || newgrpid >NVMET_MAX_ANAGRPS ) +return -EINVAL ; + +down_write (&nvmet_ana_sem); + oldgrpid = ns->anagrpid; + nvmet_ana_group_enabled[newgrpid]++; + ns->anagrpid = newgrpid; + nvmet_ana_group_enabled[oldgrpid]--; + nvmet_ana_chgcnt++; +up_write (&nvmet_ana_sem); + +nvmet_send_ana_event (ns->subsys); +return count; +} + +CONFIGFS_ATTR (nvmet_ns_, ana_grpid); +static ssize_t nvmet_ns_enable_show (struct config_item *item,char *page) {return sprintf (page,"%d\n" ,to_nvmet_ns (item)->enabled);
@@ -407,6 +440,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = { &nvmet_ns_attr_device_path, &nvmet_ns_attr_device_nguid, &nvmet_ns_attr_device_uuid, + &nvmet_ns_attr_ana_grpid, &nvmet_ns_attr_enable, NULL, };
@@ -854,6 +888,131 @@ static const struct config_item_type nvmet_referrals_type = { .ct_group_ops = &nvmet_referral_group_ops, }; +static struct { +enum nvme_ana_state state; +const char *name; +} nvmet_ana_state_names[] = { + {NVME_ANA_OPTIMIZED ,"optimized" }, + {NVME_ANA_NONOPTIMIZED ,"non-optimized" }, + {NVME_ANA_INACCESSIBLE ,"inaccessible" }, + {NVME_ANA_PERSISTENT_LOSS ,"persistent-loss" }, + {NVME_ANA_CHANGE ,"change" }, +}; + +static ssize_t nvmet_ana_group_ana_state_show (struct config_item *item, +char *page) +{ +struct nvmet_ana_group *grp =to_ana_group (item); +enum nvme_ana_state state = grp->port->ana_state[grp->grpid]; +int i; + +for (i =0 ; i <ARRAY_SIZE (nvmet_ana_state_names); i++) { +if (state != nvmet_ana_state_names[i].state) +continue ; +return sprintf (page,"%s\n" , nvmet_ana_state_names[i].name); + } + +return sprintf (page,"\n" ); +} + +static ssize_t nvmet_ana_group_ana_state_store (struct config_item *item, +const char *page,size_t count) +{ +struct nvmet_ana_group *grp =to_ana_group (item); +int i; + +for (i =0 ; i <ARRAY_SIZE (nvmet_ana_state_names); i++) { +if (sysfs_streq (page, nvmet_ana_state_names[i].name)) + goto found; + } + +pr_err ("Invalid value '%s' for ana_state\n" , page); +return -EINVAL ; + +found: +down_write (&nvmet_ana_sem); + grp->port->ana_state[grp->grpid] = nvmet_ana_state_names[i].state; + nvmet_ana_chgcnt++; +up_write (&nvmet_ana_sem); + +nvmet_port_send_ana_event (grp->port); +return count; +} + +CONFIGFS_ATTR (nvmet_ana_group_, ana_state); + +static struct configfs_attribute *nvmet_ana_group_attrs[] = { + &nvmet_ana_group_attr_ana_state, +NULL , +}; + +static void nvmet_ana_group_release (struct config_item *item) +{ +struct nvmet_ana_group *grp =to_ana_group (item); + +down_write (&nvmet_ana_sem); + grp->port->ana_state[grp->grpid] =NVME_ANA_INACCESSIBLE ; + nvmet_ana_group_enabled[grp->grpid]--; +up_write (&nvmet_ana_sem); + +nvmet_port_send_ana_event (grp->port); +kfree (grp); +} + +static struct configfs_item_operations nvmet_ana_group_item_ops = { + .release = nvmet_ana_group_release, +}; + +static const struct config_item_type nvmet_ana_group_type = { + .ct_item_ops = &nvmet_ana_group_item_ops, + .ct_attrs = nvmet_ana_group_attrs, + .ct_owner =THIS_MODULE , +}; + +static struct config_group *nvmet_ana_groups_make_group ( +struct config_group *group,const char *name) +{ +struct nvmet_port *port =ana_groups_to_port (&group->cg_item); +struct nvmet_ana_group *grp; +u32 grpid; +int ret; + + ret =kstrtou32 (name,0 , &grpid); +if (ret) + goto out; + + ret = -EINVAL ; +if (grpid <=1 || grpid >NVMET_MAX_ANAGRPS ) + goto out; + + ret = -ENOMEM ; + grp =kzalloc (sizeof (*grp),GFP_KERNEL ); +if (!grp) + goto out; + grp->port = port; + grp->grpid = grpid; + +down_write (&nvmet_ana_sem); + nvmet_ana_group_enabled[grpid]++; +up_write (&nvmet_ana_sem); + +nvmet_port_send_ana_event (grp->port); + +config_group_init_type_name (&grp->group, name, &nvmet_ana_group_type); +return &grp->group; +out: +return ERR_PTR (ret); +} + +static struct configfs_group_operations nvmet_ana_groups_group_ops = { + .make_group = nvmet_ana_groups_make_group, +}; + +static const struct config_item_type nvmet_ana_groups_type = { + .ct_group_ops = &nvmet_ana_groups_group_ops, + .ct_owner =THIS_MODULE , +}; +/* * Ports definitions. */
@@ -889,6 +1048,7 @@ static struct config_group *nvmet_ports_make(struct config_group *group, {struct nvmet_port *port;u16 portid; +u32 i;if (kstrtou16 (name,0 , &portid))return ERR_PTR (-EINVAL );
@@ -904,7 +1064,12 @@ static struct config_group *nvmet_ports_make(struct config_group *group,return ERR_PTR (-ENOMEM ); } - port->ana_state[NVMET_DEFAULT_ANA_GRPID ] =NVME_ANA_OPTIMIZED ; +for (i =1 ; i <=NVMET_MAX_ANAGRPS ; i++) { +if (i ==NVMET_DEFAULT_ANA_GRPID ) + port->ana_state[1 ] =NVME_ANA_OPTIMIZED ; +else + port->ana_state[i] =NVME_ANA_INACCESSIBLE ; + }INIT_LIST_HEAD (&port->entry);INIT_LIST_HEAD (&port->subsystems);
@@ -921,6 +1086,9 @@ static struct config_group *nvmet_ports_make(struct config_group *group, "referrals", &nvmet_referrals_type);configfs_add_default_group (&port->referrals_group, &port->group); +config_group_init_type_name (&port->ana_groups_group, +"ana_groups" , &nvmet_ana_groups_type); +configfs_add_default_group (&port->ana_groups_group, &port->group);return &port->group; }
drivers/nvme/target/core.c +21 -0
@@ -161,6 +161,27 @@ static void nvmet_send_ns_changed_event(struct nvmet_subsys *subsys) NVME_AER_NOTICE_NS_CHANGED, 0); } +void nvmet_send_ana_event (struct nvmet_subsys *subsys) +{ +struct nvmet_ctrl *ctrl; + +mutex_lock (&subsys->lock); +list_for_each_entry (ctrl, &subsys->ctrls, subsys_entry) +nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE , +NVME_AER_NOTICE_ANA ,NVME_LOG_ANA ); +mutex_unlock (&subsys->lock); +} + +void nvmet_port_send_ana_event (struct nvmet_port *port) +{ +struct nvmet_subsys_link *p; + +down_read (&nvmet_config_sem); +list_for_each_entry (p, &port->subsystems, entry) +nvmet_send_ana_event (p->subsys); +up_read (&nvmet_config_sem); +} +int nvmet_register_transport (const struct nvmet_fabrics_ops *ops) {int ret =0 ;
drivers/nvme/target/nvmet.h +25 -1
@@ -24,6 +24,7 @@#include <linux/uuid.h> #include <linux/nvme.h> #include <linux/configfs.h> +#include <linux/refcount.h> #include <linux/rcupdate.h> #include <linux/blkdev.h>
@@ -97,6 +98,7 @@ struct nvmet_port {struct list_head subsystems;struct config_group referrals_group;struct list_head referrals; +struct config_group ana_groups_group;enum nvme_ana_state *ana_state;void *priv;bool enabled;
@@ -108,6 +110,13 @@ static inline struct nvmet_port *to_nvmet_port(struct config_item *item) group); } +static inline struct nvmet_port *ana_groups_to_port ( +struct config_item *item) +{ + return container_of(to_config_group(item), struct nvmet_port, + ana_groups_group); +} +struct nvmet_ctrl {struct nvmet_subsys *subsys;struct nvmet_cq **cqs;
@@ -191,6 +200,18 @@ static inline char *nvmet_host_name(struct nvmet_host *host)return config_item_name (&host->group.cg_item); } +struct nvmet_ana_group { +struct config_group group; +struct nvmet_port *port; +u32 grpid; +}; + +static inline struct nvmet_ana_group *to_ana_group (struct config_item *item) +{ + return container_of(to_config_group(item), struct nvmet_ana_group, + group); +} +struct nvmet_host_link {struct list_head entry;struct nvmet_host *host;
@@ -306,6 +327,9 @@ void nvmet_ns_disable(struct nvmet_ns *ns);struct nvmet_ns *nvmet_ns_alloc (struct nvmet_subsys *subsys,u32 nsid);void nvmet_ns_free (struct nvmet_ns *ns); +void nvmet_send_ana_event (struct nvmet_subsys *subsys); +void nvmet_port_send_ana_event (struct nvmet_port *port); +int nvmet_register_transport (const struct nvmet_fabrics_ops *ops);void nvmet_unregister_transport (const struct nvmet_fabrics_ops *ops);
@@ -339,7 +363,7 @@ u32 nvmet_get_log_page_len(struct nvme_command *cmd);* ANA Group 1 exists without manual intervention, has namespaces assigned to it * by default, and is available in an optimized state through all ports. */ -#define NVMET_MAX_ANAGRPS 1 +#define NVMET_MAX_ANAGRPS 128#define NVMET_DEFAULT_ANA_GRPID 1#define NVMET_KAS 10
Signature · 1 line
2.17.0
Quoted 5 lines · On Mon, 14 May 2018 09:56:35 +0200 Christoph Hellwig <[email protected]> wrote:
As we had some ANA discussion I spent some hours over the weekend to dust off my old ANA code. It is mostly feature complete except for the lack of change state handling on the host, but only very lightly tested in this form. It also lacks proper changelogs and testing..
Thanks for this.
I'll be working on integrating both codestreams and send a combined patchset for review.
Unless you want to do it yourself ...
Cheers,
Hannes
Quoted 5 lines · On Mon, 14 May 2018 09:56:35 +0200 Christoph Hellwig <[email protected]> wrote:
As we had some ANA discussion I spent some hours over the weekend to dust off my old ANA code. It is mostly feature complete except for the lack of change state handling on the host, but only very lightly tested in this form. It also lacks proper changelogs and testing..
Thanks for this.
I'll be working on integrating both codestreams and send a combined patchset for review.
Unless you want to do it yourself ...
Cheers,
Hannes
Christoph Hellwig
maintainerQuoted 4 lines · Hannes Reinecke
I'll be working on integrating both codestreams and send a combined patchset for review.
Unless you want to do it yourself ...
Please go ahead, I'm completely overloaded at the moment anyway.