nvmet: Add traffic based keep alive support to configfs
Subsystems (2)
PATCH 1/1 nvmet: Add traffic based keep alive support to configfs
Add the ability to turn on and off tbkas (traffic based keep alive support) via configfs. This is useful for testing and debugging.
--- drivers/nvme/target/admin-cmd.c | 4 +++- drivers/nvme/target/configfs.c | 27 +++++++++++++++++++++++++++ drivers/nvme/target/core.c | 3 ++- drivers/nvme/target/nvmet.h | 1 + 4 files changed, 33 insertions(+), 2 deletions(-)
drivers/nvme/target/admin-cmd.c +3 -1
@@ -696,7 +696,9 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)/* XXX: figure out what to do about RTD3R/RTD3 */ id->oaes =cpu_to_le32 (NVMET_AEN_CFG_OPTIONAL ); - ctratt =NVME_CTRL_ATTR_HID_128_BIT |NVME_CTRL_ATTR_TBKAS ; + ctratt =NVME_CTRL_ATTR_HID_128_BIT ; +if (subsys->tbkas) + ctratt |=NVME_CTRL_ATTR_TBKAS ;if (nvmet_is_pci_ctrl (ctrl)) ctratt |=NVME_CTRL_ATTR_RHII ; id->ctratt =cpu_to_le32 (ctratt);
drivers/nvme/target/configfs.c +27 -0
@@ -1369,6 +1369,32 @@ static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item, }CONFIGFS_ATTR (nvmet_subsys_, attr_serial); +static ssize_t nvmet_subsys_attr_tbkas_show (struct config_item *item, +char *page) +{ +return snprintf (page,PAGE_SIZE ,"%d\n" ,to_subsys (item)->tbkas); +} + +static ssize_t nvmet_subsys_attr_tbkas_store (struct config_item *item, +const char *page,size_t count) +{ +struct nvmet_subsys *subsys =to_subsys (item); +bool tbkas; + +if (subsys->subsys_discovered) { +pr_err ("Can't set traffic based keep alive support. %d is already assigned\n" , + subsys->tbkas); +return -EINVAL ; + } + +if (kstrtobool (page, &tbkas)) +return -EINVAL ; + + subsys->tbkas = tbkas; +return count; +} +CONFIGFS_ATTR (nvmet_subsys_, attr_tbkas); +static ssize_t nvmet_subsys_attr_cntlid_min_show (struct config_item *item,char *page) {
@@ -1706,6 +1732,7 @@ static struct configfs_attribute *nvmet_subsys_attrs[] = { &nvmet_subsys_attr_attr_qid_max, &nvmet_subsys_attr_attr_ieee_oui, &nvmet_subsys_attr_attr_firmware, + &nvmet_subsys_attr_attr_tbkas, #ifdef CONFIG_BLK_DEV_INTEGRITY &nvmet_subsys_attr_attr_pi_enable, #endif
drivers/nvme/target/core.c +2 -1
@@ -1227,7 +1227,7 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_sq *sq, goto fail; } -if (sq->ctrl) +if (sq->ctrl && sq->ctrl->subsys->tbkas) sq->ctrl->reset_tbkas = true;return true;
@@ -1865,6 +1865,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, } subsys->ieee_oui =0 ; + subsys->tbkas = true; subsys->firmware_rev =kstrndup (UTS_RELEASE ,NVMET_FR_MAX_SIZE ,GFP_KERNEL );if (!subsys->firmware_rev) {
drivers/nvme/target/nvmet.h +1 -0
@@ -343,6 +343,7 @@ struct nvmet_subsys {bool subsys_discovered;char *subsysnqn;bool pi_support; +bool tbkas;struct config_group group;
Signature · 1 line
2.55.0
Quoted 2 lines · Jesse Taube
Add the ability to turn on and off tbkas (traffic based keep alive support) via configfs. This is useful for testing and debugging.
Yep, this is indeed useful.
Quoted 39 lines
Signed-off-by Jesse Taube <[email protected]>--- drivers/nvme/target/admin-cmd.c | 4 +++- drivers/nvme/target/configfs.c | 27 +++++++++++++++++++++++++++ drivers/nvme/target/core.c | 3 ++- drivers/nvme/target/nvmet.h | 1 + 4 files changed, 33 insertions(+), 2 deletions(-)drivers/nvme/target/admin-cmd.c +3
-1@@ -696,7 +696,9 @@ static void nvmet_execute_identify_ctrl(struct nvmet_req *req)/* XXX: figure out what to do about RTD3R/RTD3 */ id->oaes =cpu_to_le32 (NVMET_AEN_CFG_OPTIONAL ); - ctratt =NVME_CTRL_ATTR_HID_128_BIT |NVME_CTRL_ATTR_TBKAS ; + ctratt =NVME_CTRL_ATTR_HID_128_BIT ; +if (subsys->tbkas) + ctratt |=NVME_CTRL_ATTR_TBKAS ;if (nvmet_is_pci_ctrl (ctrl)) ctratt |=NVME_CTRL_ATTR_RHII ; id->ctratt =cpu_to_le32 (ctratt);drivers/nvme/target/configfs.c +7
-0@@ -1369,6 +1369,32 @@ static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item, }CONFIGFS_ATTR (nvmet_subsys_, attr_serial); +static ssize_t nvmet_subsys_attr_tbkas_show (struct config_item *item, +char *page) +{ +return snprintf (page,PAGE_SIZE ,"%d\n" ,to_subsys (item)->tbkas); +} + +static ssize_t nvmet_subsys_attr_tbkas_store(struct config_item *item,
drivers/nvme/target/configfs.c static ssize_t nvmet_subsys_attr_serial_store(struct config_item *item, · line 1388
Quoted 10 lines
drivers/nvme/target/configfs.c +10
-0+ const char *page, size_t count) +{ +struct nvmet_subsys *subsys =to_subsys (item); +bool tbkas; + +if (subsys->subsys_discovered) { +pr_err ("Can't set traffic based keep alive support. %d is already assigned\n" , + subsys->tbkas); +return -EINVAL ; + }
Would it be okay to fore reconnecting existing controllers when subsys->tbkas changes? Similar to what attr_qid_max does?
I think this will make testing more flexible by avoiding need to recreate the subsystem in order to test tkbas on/off. Also, you may consider adding ctrl->tkbas, again just like qid_max. It will be copied from subsys in nvmet_alloc_ctrl() under subsys->lock.
Quoted 25 lines
drivers/nvme/target/configfs.c +10
-0+ +if (kstrtobool (page, &tbkas)) +return -EINVAL ; + + subsys->tbkas = tbkas; +return count; +} +CONFIGFS_ATTR (nvmet_subsys_, attr_tbkas); +static ssize_t nvmet_subsys_attr_cntlid_min_show (struct config_item *item,char *page) {@@ -1706,6 +1732,7 @@ static struct configfs_attribute *nvmet_subsys_attrs[] = { &nvmet_subsys_attr_attr_qid_max, &nvmet_subsys_attr_attr_ieee_oui, &nvmet_subsys_attr_attr_firmware, + &nvmet_subsys_attr_attr_tbkas, #ifdef CONFIG_BLK_DEV_INTEGRITY &nvmet_subsys_attr_attr_pi_enable, #endifdrivers/nvme/target/core.c +0
-0
drivers/nvme/target/core.c bool nvmet_req_init(struct nvmet_req *req, struct nvmet_sq *sq, · line 1231
Quoted 6 lines
drivers/nvme/target/core.c +1
-1@@ -1227,7 +1227,7 @@ bool nvmet_req_init(struct nvmet_req *req, struct nvmet_sq *sq, goto fail; } -if (sq->ctrl) +if (sq->ctrl && sq->ctrl->subsys->tbkas) sq->ctrl->reset_tbkas = true;
If you add ctrl->tkbas, then this will be sq->ctrl->tkbas. It is guaranteed not to change during the lifetime of the controller.
Quoted 25 lines
drivers/nvme/target/core.c +1
-0return true;@@ -1865,6 +1865,7 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn, } subsys->ieee_oui =0 ; + subsys->tbkas = true; subsys->firmware_rev =kstrndup (UTS_RELEASE ,NVMET_FR_MAX_SIZE ,GFP_KERNEL );if (!subsys->firmware_rev) {drivers/nvme/target/nvmet.h +1
-0@@ -343,6 +343,7 @@ struct nvmet_subsys {bool subsys_discovered;char *subsysnqn;bool pi_support; +bool tbkas;struct config_group group;Signature · 1 line
2.55.0