nvme: dead code cleanups
Subsystems (4)
v2 cover nvme: dead code cleanups
A round of dead code removals in the nvme host and target drivers, all found by code inspection. Every patch stands on its own and can be picked individually:
- the NVMEQ_DELETE_ERROR flag lost its only reader in 2020 and is now write-only; dropping it also removes the nvme_del_cq_end() wrapper, which degenerates to nvme_del_queue_end() without it
- struct fields never referenced since they were introduced:
nvme_fc_queue.seqno, nvme_dhchap_queue_context.entry, nvmet_fc_ls_iod.fcpreq and nvmet_fc_tgt_queue.ninetypercent
- a hostnqn already-assigned check that can never fire because opts->host is only set after the option parsing loop
- the reconnect_delay "off" case, copied from fast_io_fail_tmo but unreachable for an unsigned value the parser bounds to positive values, along with its sentence in the ABI documentation
- an address family map entry that both show and store skip, an unreachable break in the passthru feature handling, and a drain of an SQ list that is never populated
Compile tested only.
Changes since v1:
- fold the Documentation/ABI/stable/sysfs-nvme update into patch 5, whose show function no longer returns "off" (reported by Sashiko)
Guixin Liu (9):
nvme-pci: remove write-only NVMEQ_DELETE_ERROR flag
nvme-fc: remove dead seqno field in nvme_fc_queue
nvme-auth: remove dead entry field in nvme_dhchap_queue_context
nvme-fabrics: remove dead hostnqn already-assigned check
nvme: drop unreachable "off" case in reconnect_delay_show()
nvmet-fc: remove dead fields in nvmet_fc_ls_iod and nvmet_fc_tgt_queue
nvmet: remove unreachable "pcie" entry from the address family map
nvmet: passthru: remove unreachable break statements
nvmet-pci-epf: don't drain the never-populated SQ list
Documentation/ABI/stable/sysfs-nvme | 3 +-- drivers/nvme/host/auth.c | 1 - drivers/nvme/host/fabrics.c | 6 ------ drivers/nvme/host/fc.c | 1 - drivers/nvme/host/pci.c | 20 +------------------- drivers/nvme/host/sysfs.c | 2 -- drivers/nvme/target/configfs.c | 5 ++--- drivers/nvme/target/fc.c | 3 --- drivers/nvme/target/passthru.c | 2 -- drivers/nvme/target/pci-epf.c | 2 -- 10 files changed, 4 insertions(+), 41 deletions(-)
Signature · 1 line
2.43.7
PATCH v2 1/9 nvme-pci: remove write-only NVMEQ_DELETE_ERROR flag
Commit fa46c6fb5d61b ("nvme/pci: move cqe check after device shutdown") removed the only reader of the NVMEQ_DELETE_ERROR flag, but left the flag and its two writes behind. Without a reader the flag carries no state, and nvme_del_cq_end() degenerates to a plain wrapper around nvme_del_queue_end(), which the SQ deletion path already uses directly.
Remove the flag, its writes, and the now redundant wrapper.
--- drivers/nvme/host/pci.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-)
drivers/nvme/host/pci.c +1 -19
@@ -388,7 +388,6 @@ struct nvme_queue {unsigned long flags;#define NVMEQ_ENABLED 0#define NVMEQ_SQ_CMB 1 -#define NVMEQ_DELETE_ERROR 2#define NVMEQ_POLLED 3__le32 *dbbuf_sq_db;__le32 *dbbuf_cq_db;
@@ -2238,8 +2237,6 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid, bool polled)int result;u16 vector =0 ; -clear_bit (NVMEQ_DELETE_ERROR , &nvmeq->flags); -/* * A queue's vector matches the queue identifier unless the controller * has only one vector available.
@@ -3101,18 +3098,6 @@ static enum rq_end_io_ret nvme_del_queue_end(struct request *req,return RQ_END_IO_NONE ; } -static enum rq_end_io_ret nvme_del_cq_end (struct request *req, -blk_status_t error, -const struct io_comp_batch *iob) -{ -struct nvme_queue *nvmeq = req->end_io_data; - -if (error) -set_bit (NVMEQ_DELETE_ERROR , &nvmeq->flags); - -return nvme_del_queue_end (req, error, iob); -} -static int nvme_delete_queue (struct nvme_queue *nvmeq,u8 opcode) {struct request_queue *q = nvmeq->dev->ctrl.admin_q;
@@ -3127,10 +3112,7 @@ static int nvme_delete_queue(struct nvme_queue *nvmeq, u8 opcode)return PTR_ERR (req);nvme_init_request (req, &cmd); -if (opcode == nvme_admin_delete_cq) - req->end_io = nvme_del_cq_end; -else - req->end_io = nvme_del_queue_end; + req->end_io = nvme_del_queue_end; req->end_io_data = nvmeq;init_completion (&nvmeq->delete_done);
Signature · 1 line
2.43.7
Re: [PATCH v2 1/9] nvme-pci: remove write-only NVMEQ_DELETE_ERROR flag
Quoted 7 lines · Guixin Liu
Commit
fa46c6fb5d61b("nvme/pci: move cqe check after device shutdown") removed the only reader of theNVMEQ_DELETE_ERRORflag, but left the flag and its two writes behind. Without a reader the flag carries no state, andnvme_del_cq_end()degenerates to a plain wrapper aroundnvme_del_queue_end(), which the SQ deletion path already uses directly.Remove the flag, its writes, and the now redundant wrapper.
Looks good:
Re: [PATCH v2 1/9] nvme-pci: remove write-only NVMEQ_DELETE_ERROR flag
In reply to Guixin LiuQuoted 9 lines · Guixin Liu
Commit
fa46c6fb5d61b("nvme/pci: move cqe check after device shutdown") removed the only reader of theNVMEQ_DELETE_ERRORflag, but left the flag and its two writes behind. Without a reader the flag carries no state, andnvme_del_cq_end()degenerates to a plain wrapper aroundnvme_del_queue_end(), which the SQ deletion path already uses directly.Remove the flag, its writes, and the now redundant wrapper.
Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 2/9 nvme-fc: remove dead seqno field in nvme_fc_queue
In reply to Guixin LiuThe seqno field of struct nvme_fc_queue has never been referenced since it was introduced in commit e399441de9115 ("nvme-fabrics: Add host support for FC transport"). Drop it.
--- drivers/nvme/host/fc.c | 1 - 1 file changed, 1 deletion(-)
drivers/nvme/host/fc.c +0 -1
@@ -39,7 +39,6 @@ struct nvme_fc_queue {size_t cmnd_capsule_len;u32 qnum;u32 rqcnt; -u32 seqno;u64 connection_id;atomic_t csn;
Signature · 1 line
2.43.7
Re: [PATCH v2 2/9] nvme-fc: remove dead seqno field in nvme_fc_queue
Quoted 3 lines · Guixin Liu
The seqno field of struct
nvme_fc_queuehas never been referenced since it was introduced in commite399441de9115("nvme-fabrics: Add host support for FC transport"). Drop it.
Looks good:
Re: [PATCH v2 2/9] nvme-fc: remove dead seqno field in nvme_fc_queue
In reply to Guixin LiuQuoted 5 lines · Guixin Liu
The seqno field of struct
nvme_fc_queuehas never been referenced since it was introduced in commite399441de9115("nvme-fabrics: Add host support for FC transport"). Drop it.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 3/9 nvme-auth: remove dead entry field in nvme_dhchap_queue_context
In reply to Guixin LiuThe entry list_head of struct nvme_dhchap_queue_context has never been used since it was introduced in commit f50fff73d620c ("nvme: implement In-Band authentication"). Drop it.
--- drivers/nvme/host/auth.c | 1 - 1 file changed, 1 deletion(-)
drivers/nvme/host/auth.c +0 -1
@@ -19,7 +19,6 @@ static struct kmem_cache *nvme_chap_buf_cache;static mempool_t *nvme_chap_buf_pool;struct nvme_dhchap_queue_context { -struct list_head entry;struct work_struct auth_work;struct nvme_ctrl *ctrl;struct crypto_kpp *dh_tfm;
Signature · 1 line
2.43.7
Re: [PATCH v2 3/9] nvme-auth: remove dead entry field in nvme_dhchap_queue_context
Quoted 3 lines · Guixin Liu
The entry
list_headof structnvme_dhchap_queue_contexthas never been used since it was introduced in commitf50fff73d620c("nvme: implement In-Band authentication"). Drop it.
Looks good:
Re: [PATCH v2 3/9] nvme-auth: remove dead entry field in nvme_dhchap_queue_context
In reply to Guixin LiuQuoted 5 lines · Guixin Liu
The entry
list_headof structnvme_dhchap_queue_contexthas never been used since it was introduced in commitf50fff73d620c("nvme: implement In-Band authentication"). Drop it.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 4/9 nvme-fabrics: remove dead hostnqn already-assigned check
In reply to Guixin LiuThe opts->host check in the NVMF_OPT_HOSTNQN handler can never fire:
options are parsed into a freshly allocated struct, and opts->host is only assigned after the parsing loop completes. A duplicate hostnqn option is already silently overridden by the strscpy() into the local buffer. Remove the dead check.
--- drivers/nvme/host/fabrics.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/nvme/host/fabrics.c +0 -6
@@ -872,12 +872,6 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, opts->fast_io_fail_tmo = token;break ;case NVMF_OPT_HOSTNQN : -if (opts->host) { -pr_err ("hostnqn already user-assigned: %s\n" , - opts->host->nqn); - ret = -EADDRINUSE ; - goto out; - } p =match_strdup (args);if (!p) { ret = -ENOMEM ;
Signature · 1 line
2.43.7
Re: [PATCH v2 4/9] nvme-fabrics: remove dead hostnqn already-assigned check
Quoted 5 lines · Guixin Liu
The
opts->hostcheck in theNVMF_OPT_HOSTNQNhandler can never fire:
options are parsed into a freshly allocated struct, andopts->hostis only assigned after the parsing loop completes. A duplicate hostnqn option is already silently overridden by thestrscpy()into the local buffer. Remove the dead check.
Looks good:
Re: [PATCH v2 4/9] nvme-fabrics: remove dead hostnqn already-assigned check
In reply to Guixin LiuQuoted 7 lines · Guixin Liu
The
opts->hostcheck in theNVMF_OPT_HOSTNQNhandler can never fire:
options are parsed into a freshly allocated struct, andopts->hostis only assigned after the parsing loop completes. A duplicate hostnqn option is already silently overridden by thestrscpy()into the local buffer. Remove the dead check.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 5/9 nvme: drop unreachable "off" case in reconnect_delay_show()
In reply to Guixin LiuThe "off" case was copied from fast_io_fail_tmo_show(), but unlike fast_io_fail_tmo, reconnect_delay is an unsigned int that the option parser bounds to positive values and that has no off state. The comparison can only trigger when the raw value 4294967295 is written through sysfs, which is not a meaningful delay. Drop the case and the matching sentence in the ABI documentation.
--- Documentation/ABI/stable/sysfs-nvme | 3 +-- drivers/nvme/host/sysfs.c | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-)
Documentation/ABI/stable/sysfs-nvme +1 -2
@@ -70,8 +70,7 @@ Description: fabrics controller. reconnect_delay: Shows or sets the reconnect delay in - seconds. Reading returns the delay value, or "off" if - disabled. + seconds. Reading returns the delay value. ctrl_loss_tmo: Shows or sets the controller loss timeout in seconds. Reading returns the timeout value, or "off" if
drivers/nvme/host/sysfs.c +0 -2
@@ -618,8 +618,6 @@ static ssize_t nvme_ctrl_reconnect_delay_show(struct device *dev, {struct nvme_ctrl *ctrl =dev_get_drvdata (dev); -if (ctrl->opts->reconnect_delay ==-1 ) -return sysfs_emit (buf,"off\n" );return sysfs_emit (buf,"%d\n" , ctrl->opts->reconnect_delay); }
Signature · 1 line
2.43.7
Re: [PATCH v2 5/9] nvme: drop unreachable "off" case in reconnect_delay_show()
Looks good:
Re: [PATCH v2 5/9] nvme: drop unreachable "off" case in reconnect_delay_show()
In reply to Guixin LiuQuoted 8 lines · Guixin Liu
The "off" case was copied from
fast_io_fail_tmo_show(), but unlikefast_io_fail_tmo,reconnect_delayis an unsigned int that the option parser bounds to positive values and that has no off state. The comparison can only trigger when the raw value 4294967295 is written through sysfs, which is not a meaningful delay. Drop the case and the matching sentence in the ABI documentation.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 6/9 nvmet-fc: remove dead fields in nvmet_fc_ls_iod and nvmet_fc_tgt_queue
In reply to Guixin LiuThe fcpreq field of struct nvmet_fc_ls_iod is only ever assigned NULL and never read, and the ninetypercent field of struct nvmet_fc_tgt_queue is never referenced as the 90% queue state is recomputed on demand. Drop both.
--- drivers/nvme/target/fc.c | 3 --- 1 file changed, 3 deletions(-)
drivers/nvme/target/fc.c +0 -3
@@ -27,7 +27,6 @@ struct nvmet_fc_tgt_assoc;struct nvmet_fc_ls_iod {/* for an LS RQST RCV */ struct nvmefc_ls_rsp *lsrsp; -struct nvmefc_tgt_fcp_req *fcpreq;/* only if RS */ struct list_head ls_rcv_list;/* tgtport->ls_rcv_list */
@@ -129,7 +128,6 @@ struct nvmet_fc_defer_fcp_req { };struct nvmet_fc_tgt_queue { -bool ninetypercent;u16 qid;u16 sqsize;u16 ersp_ratio;
@@ -2076,7 +2074,6 @@ nvmet_fc_rcv_ls_req(struct nvmet_fc_target_port *target_port, } iod->lsrsp = lsrsp; - iod->fcpreq =NULL ;memcpy (iod->rqstbuf, lsreqbuf, lsreqbuf_len); iod->rqstdatalen = lsreqbuf_len; iod->hosthandle = hosthandle;
Signature · 1 line
2.43.7
Re: [PATCH v2 6/9] nvmet-fc: remove dead fields in nvmet_fc_ls_iod and nvmet_fc_tgt_queue
Looks good:
Re: [PATCH v2 6/9] nvmet-fc: remove dead fields in nvmet_fc_ls_iod and nvmet_fc_tgt_queue
In reply to Guixin LiuQuoted 6 lines · Guixin Liu
The fcpreq field of struct
nvmet_fc_ls_iodis only ever assigned NULL and never read, and the ninetypercent field of structnvmet_fc_tgt_queueis never referenced as the 90% queue state is recomputed on demand. Drop both.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 7/9 nvmet: remove unreachable "pcie" entry from the address family map
In reply to Guixin LiuThe first entry of nvmet_addr_family[] is never matched: both the adrfam show and store handlers skip index 0, and the NVMF_ADDR_FAMILY_PCI type is matched by the "pci" entry further down the array. Drop the entry and start the iteration at index 0 so the map no longer needs an explanation for the skipped element.
--- drivers/nvme/target/configfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/nvme/target/configfs.c +2 -3
@@ -42,7 +42,6 @@ static struct nvmet_type_name_map nvmet_transport[] = { };static const struct nvmet_type_name_map nvmet_addr_family[] = { - {NVMF_ADDR_FAMILY_PCI ,"pcie" }, {NVMF_ADDR_FAMILY_IP4 ,"ipv4" }, {NVMF_ADDR_FAMILY_IP6 ,"ipv6" }, {NVMF_ADDR_FAMILY_IB ,"ib" },
@@ -68,7 +67,7 @@ static ssize_t nvmet_addr_adrfam_show(struct config_item *item, char *page)u8 adrfam =to_nvmet_port (item)->disc_addr.adrfam;int i; -for (i =1 ; i <ARRAY_SIZE (nvmet_addr_family); i++) { +for (i =0 ; i <ARRAY_SIZE (nvmet_addr_family); i++) {if (nvmet_addr_family[i].type == adrfam)return snprintf (page,PAGE_SIZE ,"%s\n" , nvmet_addr_family[i].name);
@@ -86,7 +85,7 @@ static ssize_t nvmet_addr_adrfam_store(struct config_item *item,if (nvmet_is_port_enabled (port, __func__))return -EACCES ; -for (i =1 ; i <ARRAY_SIZE (nvmet_addr_family); i++) { +for (i =0 ; i <ARRAY_SIZE (nvmet_addr_family); i++) {if (sysfs_streq (page, nvmet_addr_family[i].name)) goto found; }
Signature · 1 line
2.43.7
Re: [PATCH v2 7/9] nvmet: remove unreachable "pcie" entry from the address family map
Quoted 5 lines · Guixin Liu
The first entry of nvmet_addr_family[] is never matched: both the adrfam show and store handlers skip index 0, and the
NVMF_ADDR_FAMILY_PCItype is matched by the "pci" entry further down the array. Drop the entry and start the iteration at index 0 so the map no longer needs an explanation for the skipped element.
Looks good:
Re: [PATCH v2 7/9] nvmet: remove unreachable "pcie" entry from the address family map
In reply to Guixin LiuQuoted 7 lines · Guixin Liu
The first entry of nvmet_addr_family[] is never matched: both the adrfam show and store handlers skip index 0, and the
NVMF_ADDR_FAMILY_PCItype is matched by the "pci" entry further down the array. Drop the entry and start the iteration at index 0 so the map no longer needs an explanation for the skipped element.Signed-off-by Guixin Liu<[email protected]>
Wonder why does at first place, we added the duplicate entries for NVMF_ADDR_FAMILY_PCI in nvmet_addr_family[]. May be some history which I don't know...
Anyways, Looks good to me:
PATCH v2 8/9 nvmet: passthru: remove unreachable break statements
In reply to Guixin LiuIn the nvme_admin_set_features and nvme_admin_get_features handlers of nvmet_passthru_parse_cmd(), every path of the inner switch over the feature id returns, so the break statement following the switch can never be reached. Remove them.
--- drivers/nvme/target/passthru.c | 2 -- 1 file changed, 2 deletions(-)
drivers/nvme/target/passthru.c +0 -2
@@ -550,7 +550,6 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req)default :return nvmet_passthru_get_set_features (req); } -break ;case nvme_admin_get_features:switch (le32_to_cpu (req->cmd->features.fid)) {case NVME_FEAT_ASYNC_EVENT :
@@ -564,7 +563,6 @@ u16 nvmet_parse_passthru_admin_cmd(struct nvmet_req *req)default :return nvmet_passthru_get_set_features (req); } -break ;case nvme_admin_identify:switch (req->cmd->identify.cns) {case NVME_ID_CNS_CS_CTRL :
Signature · 1 line
2.43.7
Re: [PATCH v2 8/9] nvmet: passthru: remove unreachable break statements
Looks good:
Re: [PATCH v2 8/9] nvmet: passthru: remove unreachable break statements
In reply to Guixin LiuQuoted 6 lines · Guixin Liu
In the
nvme_admin_set_featuresandnvme_admin_get_featureshandlers ofnvmet_passthru_parse_cmd(), every path of the inner switch over the feature id returns, so the break statement following the switch can never be reached. Remove them.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
PATCH v2 9/9 nvmet-pci-epf: don't drain the never-populated SQ list
In reply to Guixin Liunvmet_pci_epf_delete_sq() calls nvmet_pci_epf_drain_queue() on the submission queue, but IOD links are only ever added to the completion queue list, so the SQ list is always empty and the call is a no-op. Remove it.
--- drivers/nvme/target/pci-epf.c | 2 -- 1 file changed, 2 deletions(-)
drivers/nvme/target/pci-epf.c +0 -2
@@ -1432,8 +1432,6 @@ static u16 nvmet_pci_epf_delete_sq(struct nvmet_ctrl *tctrl, u16 sqid)destroy_workqueue (sq->iod_wq); sq->iod_wq =NULL ; -nvmet_pci_epf_drain_queue (sq); -if (sq->nvme_sq.ctrl)nvmet_sq_destroy (&sq->nvme_sq);
Signature · 1 line
2.43.7
Re: [PATCH v2 9/9] nvmet-pci-epf: don't drain the never-populated SQ list
Quoted 4 lines · Guixin Liu
nvmet_pci_epf_delete_sq()callsnvmet_pci_epf_drain_queue()on the submission queue, but IOD links are only ever added to the completion queue list, so the SQ list is always empty and the call is a no-op. Remove it.
Looks good:
Re: [PATCH v2 9/9] nvmet-pci-epf: don't drain the never-populated SQ list
In reply to Guixin LiuQuoted 6 lines · Guixin Liu
nvmet_pci_epf_delete_sq()callsnvmet_pci_epf_drain_queue()on the submission queue, but IOD links are only ever added to the completion queue list, so the SQ list is always empty and the call is a no-op. Remove it.Signed-off-by Guixin Liu<[email protected]>
Looks good to me:
Quoted 19 lines · Guixin Liu
A round of dead code removals in the nvme host and target drivers, all found by code inspection. Every patch stands on its own and can be picked individually:
- the
NVMEQ_DELETE_ERRORflag lost its only reader in 2020 and is now write-only; dropping it also removes thenvme_del_cq_end()wrapper, which degenerates tonvme_del_queue_end()without it
- struct fields never referenced since they were introduced:
nvme_fc_queue.seqno, nvme_dhchap_queue_context.entry, nvmet_fc_ls_iod.fcpreq and nvmet_fc_tgt_queue.ninetypercent
- a hostnqn already-assigned check that can never fire becauseopts->hostis only set after the option parsing loop
- thereconnect_delay"off" case, copied fromfast_io_fail_tmobut unreachable for an unsigned value the parser bounds to positive values, along with its sentence in the ABI documentation
- an address family map entry that both show and store skip, an unreachable break in the passthru feature handling, and a drain of an SQ list that is never populated
Quoted 1 line
[...]
Thanks, applied to nvme-7.4.
[1/9] nvme-pci: remove write-only NVMEQ_DELETE_ERROR flag
commit: 51a08d499c3a2e69ff2509a8c67249b51a52f0c2
[2/9] nvme-fc: remove dead seqno field in nvme_fc_queue
commit: 21e384dfa497f5bdb987e104652e3a11cda80e75
[3/9] nvme-auth: remove dead entry field in nvme_dhchap_queue_context
commit: 6e31e030e2004b94f663f7a8bef54e4db79d6db6
[4/9] nvme-fabrics: remove dead hostnqn already-assigned check
commit: c621d47b7a454a105e7b873d61cd69dcf84d0451
[5/9] nvme: drop unreachable "off" case in reconnect_delay_show()
commit: 9762c7ae1ee709f6dc3823d151391f89457b5492
[6/9] nvmet-fc: remove dead fields in nvmet_fc_ls_iod and nvmet_fc_tgt_queue
commit: f7a3f5f72b8b8c53972a6848290e8121e786b4c4
[7/9] nvmet: remove unreachable "pcie" entry from the address family map
commit: 16fc085d86144c7f6e1c9b70e9d9fe562f8d611e
[8/9] nvmet: passthru: remove unreachable break statements
commit: 2b7982b06cc877584942d82d071a28a2a9e83603
[9/9] nvmet-pci-epf: don't drain the never-populated SQ list
commit: 66e3ef5dad6d22a79cb32b614d2a37a166a5437b--
Keith Busch <[email protected]>