[PATCH 09/11] nvmet-fc: free pending reqs on tgtport unregister

Daniel Wagner posted 11 patches 11 months, 2 weeks ago
There is a newer version of this series
[PATCH 09/11] nvmet-fc: free pending reqs on tgtport unregister
Posted by Daniel Wagner 11 months, 2 weeks ago
When nvmet_fc_unregister_targetport is called by the LLDD, it's not
possible to communicate with the host, thus all pending request will not
be process. Thus explicitly free them.

Signed-off-by: Daniel Wagner <wagi@kernel.org>
---
 drivers/nvme/target/fc.c | 39 ++++++++++++++++++++++++++++++++-------
 1 file changed, 32 insertions(+), 7 deletions(-)

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 391917b4ce0115dbc0ad99d1fb363b1af6ee0685..a5f7cb18ac9f49e41626e1c9a031c3cc830af9ba 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1610,6 +1610,37 @@ nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl)
 	spin_unlock_irqrestore(&nvmet_fc_tgtlock, flags);
 }
 
+static void
+nvmet_fc_free_pending_reqs(struct nvmet_fc_tgtport *tgtport)
+{
+	struct nvmet_fc_ls_req_op *lsop;
+	struct nvmefc_ls_req *lsreq;
+
+	/*
+	 * After this point the connection is lost and thus any pending
+	 * request can't be processed by the normal completion path. This
+	 * is likely a request from nvmet_fc_send_ls_req_async.
+	 */
+	for (;;) {
+		lsop = list_first_entry_or_null(&tgtport->ls_req_list,
+						struct nvmet_fc_ls_req_op,
+						lsreq_list);
+		if (!lsop)
+			break;
+
+		list_del(&lsop->lsreq_list);
+
+		if (!lsop->req_queued)
+			continue;
+
+		lsreq = &lsop->ls_req;
+		fc_dma_unmap_single(tgtport->dev, lsreq->rqstdma,
+				    (lsreq->rqstlen + lsreq->rsplen),
+				    DMA_BIDIRECTIONAL);
+		nvmet_fc_tgtport_put(tgtport);
+	}
+}
+
 /**
  * nvmet_fc_unregister_targetport - transport entry point called by an
  *                              LLDD to deregister/remove a previously
@@ -1633,13 +1664,7 @@ nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *target_port)
 
 	flush_workqueue(nvmet_wq);
 
-	/*
-	 * should terminate LS's as well. However, LS's will be generated
-	 * at the tail end of association termination, so they likely don't
-	 * exist yet. And even if they did, it's worthwhile to just let
-	 * them finish and targetport ref counting will clean things up.
-	 */
-
+	nvmet_fc_free_pending_reqs(tgtport);
 	nvmet_fc_tgtport_put(tgtport);
 
 	return 0;

-- 
2.48.1
Re: [PATCH 09/11] nvmet-fc: free pending reqs on tgtport unregister
Posted by Hannes Reinecke 11 months, 2 weeks ago
On 2/26/25 19:46, Daniel Wagner wrote:
> When nvmet_fc_unregister_targetport is called by the LLDD, it's not
> possible to communicate with the host, thus all pending request will not
> be process. Thus explicitly free them.
> 
> Signed-off-by: Daniel Wagner <wagi@kernel.org>
> ---
>   drivers/nvme/target/fc.c | 39 ++++++++++++++++++++++++++++++++-------
>   1 file changed, 32 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
> index 391917b4ce0115dbc0ad99d1fb363b1af6ee0685..a5f7cb18ac9f49e41626e1c9a031c3cc830af9ba 100644
> --- a/drivers/nvme/target/fc.c
> +++ b/drivers/nvme/target/fc.c
> @@ -1610,6 +1610,37 @@ nvmet_fc_delete_ctrl(struct nvmet_ctrl *ctrl)
>   	spin_unlock_irqrestore(&nvmet_fc_tgtlock, flags);
>   }
>   
> +static void
> +nvmet_fc_free_pending_reqs(struct nvmet_fc_tgtport *tgtport)
> +{
> +	struct nvmet_fc_ls_req_op *lsop;
> +	struct nvmefc_ls_req *lsreq;
> +
> +	/*
> +	 * After this point the connection is lost and thus any pending
> +	 * request can't be processed by the normal completion path. This
> +	 * is likely a request from nvmet_fc_send_ls_req_async.
> +	 */
> +	for (;;) {
> +		lsop = list_first_entry_or_null(&tgtport->ls_req_list,
> +						struct nvmet_fc_ls_req_op,
> +						lsreq_list);
> +		if (!lsop)
> +			break;
> +
> +		list_del(&lsop->lsreq_list);
> +
> +		if (!lsop->req_queued)
> +			continue;
> +
> +		lsreq = &lsop->ls_req;
> +		fc_dma_unmap_single(tgtport->dev, lsreq->rqstdma,
> +				    (lsreq->rqstlen + lsreq->rsplen),
> +				    DMA_BIDIRECTIONAL);
> +		nvmet_fc_tgtport_put(tgtport);
> +	}
> +}
> +
>   /**
>    * nvmet_fc_unregister_targetport - transport entry point called by an
>    *                              LLDD to deregister/remove a previously
> @@ -1633,13 +1664,7 @@ nvmet_fc_unregister_targetport(struct nvmet_fc_target_port *target_port)
>   
>   	flush_workqueue(nvmet_wq);
>   
> -	/*
> -	 * should terminate LS's as well. However, LS's will be generated
> -	 * at the tail end of association termination, so they likely don't
> -	 * exist yet. And even if they did, it's worthwhile to just let
> -	 * them finish and targetport ref counting will clean things up.
> -	 */
> -
> +	nvmet_fc_free_pending_reqs(tgtport);
>   	nvmet_fc_tgtport_put(tgtport);
>   
>   	return 0;
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                  Kernel Storage Architect
hare@suse.de                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich