*** Implement the NVMe reservation feature ***
Subsystems (2)
v2 cover *** Implement the NVMe reservation feature ***
Hi guys,
I've implemented the NVMe reservation feature. Please review it, all
comments are welcome as usual.
Changes from v2 to v3:
- Use rcu instead of rwlock to make IO path run faster, and put the rtype into the struct nvmet_pr_registrant.
- Limit the resv_log_list to 128.
- Change generation to atomic64.
- Put register rkey check to a warpper.
- Change nr_avl_pages to nr_pages.
- Use NVME_SC_SUCCESS instead of 0.
- Change kmalloc param to let it not sleep in mutex lock.
Changes from v1 to v2:
- Implement the reservation notification report, includes registration preempted, reservation released and reservation preempted. And also handle the reservation log page avaliable event and send get
reservation log page command to clear log page at host.
- Put the reservation check access after validate opcode. And remove opcodes which nvmet not implement yet check.
Now there is no admin opcode nvmet implemented needs reservation check,
so I dont add reservation check to admin command path.
Next we need to do reservation check includes the situation of nsid is0xffffffff at each admin command path, if it is needed.
- Add reservation commands support in nvmet_get_cmd_effects_nvm().
- From Chaitanya, change the local variable tree style to make it cleaner, and add some comments about NVMe spec.
And also change others advice from chaitanya.
- Put the nvmet_pr_check_cmd_access and nvmet_parse_pr_cmd into reservation enable check warp.
- Remove kmem_cache instead to use kmalloc and kfree.
- Change others advice from Sagi.
- Add a blktest test case, this patch will be sent before these series of pathes.
Guixin Liu (2):
nvmet: support reservation feature
nvmet: unify aer type enum
drivers/nvme/target/Makefile | 2 +- drivers/nvme/target/admin-cmd.c | 14 +- drivers/nvme/target/configfs.c | 27 + drivers/nvme/target/core.c | 53 +- drivers/nvme/target/discovery.c | 2 +- drivers/nvme/target/nvmet.h | 33 ++ drivers/nvme/target/pr.c | 979 ++++++++++++++++++++++++++++++++ include/linux/nvme.h | 54 +- 8 files changed, 1148 insertions(+), 16 deletions(-) create mode 100644 drivers/nvme/target/pr.c
Signature · 1 line
2.43.0
PATCH v2 1/2 nvmet: support reservation feature
This patch implements the reservation feature, includes:
1. reservation register(register, unregister and replace).
2. reservation acquire(acquire, preempt, preempt and abort).
3. reservation release(release and clear).
4. reservation report.
And also make reservation configurable, one can set ns to support reservation before enable ns. The default of resv_enable is false.
--- drivers/nvme/target/Makefile | 2 +- drivers/nvme/target/admin-cmd.c | 14 +- drivers/nvme/target/configfs.c | 27 + drivers/nvme/target/core.c | 49 +- drivers/nvme/target/nvmet.h | 33 ++ drivers/nvme/target/pr.c | 979 ++++++++++++++++++++++++++++++++ include/linux/nvme.h | 48 ++ 7 files changed, 1145 insertions(+), 7 deletions(-) create mode 100644 drivers/nvme/target/pr.c
drivers/nvme/target/Makefile +1 -1
@@ -10,7 +10,7 @@ obj-$(CONFIG_NVME_TARGET_FCLOOP) += nvme-fcloop.o obj-$(CONFIG_NVME_TARGET_TCP) += nvmet-tcp.o nvmet-y += core.o configfs.o admin-cmd.o fabrics-cmd.o \ - discovery.o io-cmd-file.o io-cmd-bdev.o + discovery.o io-cmd-file.o io-cmd-bdev.o pr.o nvmet-$(CONFIG_NVME_TARGET_PASSTHRU) += passthru.o nvmet-$(CONFIG_BLK_DEV_ZONED) += zns.o nvmet-$(CONFIG_NVME_TARGET_AUTH) += fabrics-cmd-auth.o auth.o
drivers/nvme/target/admin-cmd.c +13 -1
@@ -176,6 +176,10 @@ static void nvmet_get_cmd_effects_nvm(struct nvme_effects_log *log) log->iocs[nvme_cmd_read] = log->iocs[nvme_cmd_flush] = log->iocs[nvme_cmd_dsm] = + log->iocs[nvme_cmd_resv_acquire] = + log->iocs[nvme_cmd_resv_register] = + log->iocs[nvme_cmd_resv_release] = + log->iocs[nvme_cmd_resv_report] =cpu_to_le32 (NVME_CMD_EFFECTS_CSUPP ); log->iocs[nvme_cmd_write] = log->iocs[nvme_cmd_write_zeroes] =
@@ -340,6 +344,8 @@ static void nvmet_execute_get_log_page(struct nvmet_req *req)return nvmet_execute_get_log_cmd_effects_ns (req);case NVME_LOG_ANA :return nvmet_execute_get_log_page_ana (req); +case NVME_LOG_RESERVATION : +return nvmet_execute_get_log_page_resv (req); }pr_debug ("unhandled lid %d on qid %d\n" , req->cmd->get_log_page.lid, req->sq->qid);
@@ -550,7 +556,13 @@ static void nvmet_execute_identify_ns(struct nvmet_req *req)*/ id->nmic =NVME_NS_NMIC_SHARED ; id->anagrpid =cpu_to_le32 (req->ns->anagrpid); - + id->rescap =NVME_PR_SUPPORT_WRITE_EXCLUSIVE | +NVME_PR_SUPPORT_EXCLUSIVE_ACCESS | +NVME_PR_SUPPORT_WRITE_EXCLUSIVE_REG_ONLY | +NVME_PR_SUPPORT_EXCLUSIVE_ACCESS_REG_ONLY | +NVME_PR_SUPPORT_WRITE_EXCLUSIVE_ALL_REGS | +NVME_PR_SUPPORT_EXCLUSIVE_ACCESS_ALL_REGS | +NVME_PR_SUPPORT_IEKEY_VER_1_3_DEF ;memcpy (&id->nguid, &req->ns->nguid,sizeof (id->nguid)); id->lbaf[0 ].ds = req->ns->blksize_shift;
drivers/nvme/target/configfs.c +27 -0
@@ -714,6 +714,32 @@ static ssize_t nvmet_ns_revalidate_size_store(struct config_item *item,CONFIGFS_ATTR_WO (nvmet_ns_, revalidate_size); +static ssize_t nvmet_ns_resv_enable_show (struct config_item *item,char *page) +{ +return sprintf (page,"%d\n" ,to_nvmet_ns (item)->pr.enable); +} + +static ssize_t nvmet_ns_resv_enable_store (struct config_item *item, +const char *page,size_t count) +{ +struct nvmet_ns *ns =to_nvmet_ns (item); +bool val; + +if (kstrtobool (page, &val)) +return -EINVAL ; + +mutex_lock (&ns->subsys->lock); +if (ns->enabled) { +pr_err ("the ns:%d is already enabled.\n" , ns->nsid); +mutex_unlock (&ns->subsys->lock); +return -EINVAL ; + } + ns->pr.enable = val; +mutex_unlock (&ns->subsys->lock); +return count; +} +CONFIGFS_ATTR (nvmet_ns_, resv_enable); +static struct configfs_attribute *nvmet_ns_attrs[] = { &nvmet_ns_attr_device_path, &nvmet_ns_attr_device_nguid,
@@ -722,6 +748,7 @@ static struct configfs_attribute *nvmet_ns_attrs[] = { &nvmet_ns_attr_enable, &nvmet_ns_attr_buffered_io, &nvmet_ns_attr_revalidate_size, + &nvmet_ns_attr_resv_enable, #ifdef CONFIG_PCI_P2PDMA &nvmet_ns_attr_p2pmem, #endif
drivers/nvme/target/core.c +44 -5
92 lines not on this page · raw message
drivers/nvme/target/nvmet.h +33 -0
@@ -56,6 +56,22 @@#define IPO_IATTR_CONNECT_SQE (x) \ (cpu_to_le32(offsetof(struct nvmf_connect_command, x))) +struct nvmet_pr_registrant { +u64 rkey; +uuid_t hostid; +enum nvme_pr_type rtype; +struct list_head entry; +struct rcu_head rcu; +}; + +struct nvmet_pr { +bool enable; +atomic64_t generation; +struct nvmet_pr_registrant __rcu *holder; +struct mutex pr_lock; +struct list_head registrant_list; +}; +struct nvmet_ns {struct percpu_ref ref;struct bdev_handle *bdev_handle;
@@ -85,6 +101,7 @@ struct nvmet_ns {int pi_type;int metadata_size;u8 csi; +struct nvmet_pr pr; };static inline struct nvmet_ns *to_nvmet_ns (struct config_item *item)
@@ -190,6 +207,11 @@ static inline bool nvmet_port_secure_channel_required(struct nvmet_port *port)return nvmet_port_disc_addr_treq_secure_channel (port) ==NVMF_TREQ_REQUIRED ; } +struct nvmet_pr_log_entry { +struct nvme_pr_log log; +struct list_head entry; +}; +struct nvmet_ctrl {struct nvmet_subsys *subsys;struct nvmet_sq **sqs;
@@ -243,6 +265,9 @@ struct nvmet_ctrl {u8 *dh_key;size_t dh_keysize;#endif +struct mutex resv_log_lock; +u64 resv_log_counter; +struct list_head resv_log_list; };struct nvmet_subsys {
@@ -750,4 +775,12 @@ static inline bool nvmet_has_auth(struct nvmet_ctrl *ctrl)static inline const char *nvmet_dhchap_dhgroup_name (u8 dhgid) {return NULL ; }#endif +void nvmet_pr_init_ns (struct nvmet_ns *ns); +u16 nvmet_parse_pr_cmd (struct nvmet_req *req); +u16 nvmet_pr_check_cmd_access (struct nvmet_req *req); +void nvmet_ctrl_destroy_pr (struct nvmet_ctrl *ctrl); +void nvmet_pr_exit_ns (struct nvmet_ns *ns); +bool nvmet_is_host_still_connected (uuid_t *hostid,struct nvmet_subsys *subsys); +void nvmet_execute_get_log_page_resv (struct nvmet_req *req); +#endif /* _NVMET_H */
drivers/nvme/target/pr.c new file +979 -0
979 lines not on this page · raw message
include/linux/nvme.h +48 -0
66 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 2/2 nvmet: unify aer type enum
In reply to Guixin LiuThe host and target use two definition of aer type, unify them into a single one.
--- drivers/nvme/target/core.c | 4 ++-- drivers/nvme/target/discovery.c | 2 +- include/linux/nvme.h | 6 ------ 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/nvme/target/core.c +2 -2
@@ -248,7 +248,7 @@ void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid)nvmet_add_to_changed_ns_log (ctrl,cpu_to_le32 (nsid));if (nvmet_aen_bit_disabled (ctrl,NVME_AEN_BIT_NS_ATTR ))continue ; -nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE , +nvmet_add_async_event (ctrl,NVME_AER_NOTICE ,NVME_AER_NOTICE_NS_CHANGED ,NVME_LOG_CHANGED_NS ); }
@@ -265,7 +265,7 @@ void nvmet_send_ana_event(struct nvmet_subsys *subsys,continue ;if (nvmet_aen_bit_disabled (ctrl,NVME_AEN_BIT_ANA_CHANGE ))continue ; -nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE , +nvmet_add_async_event (ctrl,NVME_AER_NOTICE ,NVME_AER_NOTICE_ANA ,NVME_LOG_ANA ); }mutex_unlock (&subsys->lock);
drivers/nvme/target/discovery.c +1 -1
@@ -21,7 +21,7 @@ static void __nvmet_disc_changed(struct nvmet_port *port,if (nvmet_aen_bit_disabled (ctrl,NVME_AEN_BIT_DISC_CHANGE ))return ; -nvmet_add_async_event (ctrl,NVME_AER_TYPE_NOTICE , +nvmet_add_async_event (ctrl,NVME_AER_NOTICE ,NVME_AER_NOTICE_DISC_CHANGED ,NVME_LOG_DISC ); }
include/linux/nvme.h +0 -6
@@ -865,12 +865,6 @@ struct nvme_reservation_status_ext {struct nvme_registered_ctrl_ext regctl_eds[]; }; -enum nvme_async_event_type { -NVME_AER_TYPE_ERROR =0 , -NVME_AER_TYPE_SMART =1 , -NVME_AER_TYPE_NOTICE =2 , -}; -/* I/O commands */ enum nvme_opcode {
Signature · 1 line
2.43.0
The version is wrong, please ignore this.
Best regards,
Guixin Liu
Quoted 65 lines · Guixin Liu
Hi guys,
I've implemented the NVMe reservation feature. Please review it, all
comments are welcome as usual.Changes from v2 to v3:
- Use rcu instead of rwlock to make IO path run faster, and put the rtype into the structnvmet_pr_registrant.- Limit the
resv_log_listto 128.- Change generation to atomic64.
- Put register rkey check to a warpper.
- Change
nr_avl_pagestonr_pages.- Use
NVME_SC_SUCCESSinstead of 0.- Change kmalloc param to let it not sleep in mutex lock.
Changes from v1 to v2:
- Implement the reservation notification report, includes registration preempted, reservation released and reservation preempted. And also handle the reservation log page avaliable event and send get
reservation log page command to clear log page at host.- Put the reservation check access after validate opcode. And remove opcodes which nvmet not implement yet check.
Now there is no admin opcode nvmet implemented needs reservation check,
so I dont add reservation check to admin command path.
Next we need to do reservation check includes the situation of nsid is0xffffffffat each admin command path, if it is needed.- Add reservation commands support in
nvmet_get_cmd_effects_nvm().- From Chaitanya, change the local variable tree style to make it cleaner, and add some comments about NVMe spec.
And also change others advice from chaitanya.- Put the
nvmet_pr_check_cmd_accessandnvmet_parse_pr_cmdinto reservation enable check warp.- Remove
kmem_cacheinstead to use kmalloc and kfree.- Change others advice from Sagi.
- Add a blktest test case, this patch will be sent before these series of pathes.
Guixin Liu (2):
nvmet: support reservation feature
nvmet: unify aer type enumdrivers/nvme/target/Makefile | 2 +- drivers/nvme/target/admin-cmd.c | 14 +- drivers/nvme/target/configfs.c | 27 + drivers/nvme/target/core.c | 53 +- drivers/nvme/target/discovery.c | 2 +- drivers/nvme/target/nvmet.h | 33 ++ drivers/nvme/target/pr.c | 979 ++++++++++++++++++++++++++++++++ include/linux/nvme.h | 54 +- 8 files changed, 1148 insertions(+), 16 deletions(-)create mode 100644
drivers/nvme/target/pr.c