*** Implement the NVMe reservation feature ***
Subsystems (2)
v5 cover *** Implement the NVMe reservation feature ***
Hi guys,
I've implemented the NVMe reservation feature. Please review it, all
comments are welcome as usual.
Hi Sagi,
I have not receive your reply yet, so I put my reply of v4 here:
- About adding synchronize_rcu after rcu_assign_pointer, rcu_assign_pointer ensures that all reads after it will see the new value, we only need to ensure that there are no reads before the old value free, the kfree_rcu can make sure that.
And using synchronize_rcu and free is same as kfree_rcu, could you plz explain
detailly why should we use synchronize_rcu after rcu_assign_pointer?
- About the lock I use, I use pr->pr_lock to protect pr->registrant_list and pr->holder writing, and both of holder and registrant_list are rcu protected, so they can be read lightly in nvmet_pr_check_cmd_access.
I was misled by the __dev_exception_clean() into thinking that if I added
a mutex lock, I wouldn't have to use the rculist marcros anymore, I will change this in v5, sorry for the trouble...
Changes from v4 to v5:
- Use rculist macros to handle registration_list instead of list macros regardless of in mutex lock or not.
- Use goto statement instead of return in nvmet_is_host_still_connected and __nvmet_pr_unregister_one.
- Add lockdep_assert_held and rcu_read_lock_held assert to many functions, if it's necessary.
- Add a comment to nvmet_execute_get_log_page_resv to explain how lost_count works.
- In nvmet_pr_clear, we should set holder to NULL first, I fixed this.
- Unify nvmet_pr_update_holder_rtype and __nvmet_pr_do_replace to nvmet_pr_update_reg_attr.
- Fix wrong nr_pages in nvmet_execute_get_log_page_resv.
- Fix the deadlock issue of nvmet_pr_exit_ns, put it out of the subsys lock.
Changes from v3 to v4:
- Use kfifo to handle resv log page instead of list, and also limit the resv log queue to 64.
- Change the function calling aligment style to:
nvmet_pr_send_event_by_hostid(pr, hostid,
NVME_PR_LOG_RESERVATOPM_PREEMPTED); - Put kmalloc out of rcu_read_lock in nvmet_execute_pr_report().
- Remove the goto in __nvmet_pr_unregister_one().
- Change generation to atomic_t, and remove nvmet_pr_inc_generation().
- In addtion, the number2 patch "nvmet: unify aer type enum" is not relate with this patch, so I will send it separately.
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 (1):
nvmet: support reservation feature
drivers/nvme/target/Makefile | 2 +- drivers/nvme/target/admin-cmd.c | 14 +- drivers/nvme/target/configfs.c | 27 + drivers/nvme/target/core.c | 51 +- drivers/nvme/target/nvmet.h | 35 ++ drivers/nvme/target/pr.c | 968 ++++++++++++++++++++++++++++++++ include/linux/nvme.h | 48 ++ 7 files changed, 1138 insertions(+), 7 deletions(-) create mode 100644 drivers/nvme/target/pr.c
Signature · 1 line
2.43.0
PATCH v5 1/1 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 | 51 +- drivers/nvme/target/nvmet.h | 35 ++ drivers/nvme/target/pr.c | 968 ++++++++++++++++++++++++++++++++ include/linux/nvme.h | 48 ++ 7 files changed, 1138 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 +46 -5
94 lines not on this page · raw message
drivers/nvme/target/nvmet.h +35 -0
@@ -20,6 +20,7 @@#include <linux/blkdev.h> #include <linux/radix-tree.h> #include <linux/t10-pi.h> +#include <linux/kfifo.h> #define NVMET_DEFAULT_VS NVME_VS(1, 3, 0)
@@ -30,6 +31,7 @@#define NVMET_MN_MAX_SIZE 40#define NVMET_SN_MAX_SIZE 20#define NVMET_FR_MAX_SIZE 8 +#define NVMET_PR_LOG_QUEUE_SIZE 64/* * Supported optional AENs:
@@ -56,6 +58,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; +atomic_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 +103,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 +209,13 @@ 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_mgr { +struct mutex lock; +u64 lost_count; +u64 counter; + DECLARE_KFIFO(log_queue, struct nvme_pr_log, NVMET_PR_LOG_QUEUE_SIZE); +}; +struct nvmet_ctrl {struct nvmet_subsys *subsys;struct nvmet_sq **sqs;
@@ -243,6 +269,7 @@ struct nvmet_ctrl {u8 *dh_key;size_t dh_keysize;#endif +struct nvmet_pr_log_mgr pr_log_mgr; };struct nvmet_subsys {
@@ -750,4 +777,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 +968 -0
968 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