* [PATCH] nvmet-fc: move RCU read lock to nvmet_fc_assoc_exists
@ 2024-02-12 10:29 Daniel Wagner
2024-02-21 13:11 ` Daniel Wagner
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Wagner @ 2024-02-12 10:29 UTC (permalink / raw)
To: James Smart
Cc: Keith Busch, Christoph Hellwig, Hannes Reinecke, linux-nvme,
linux-kernel, Daniel Wagner
The RCU lock is only needed for the lookup loop and not for
list_ad_tail_rcu call. Thus move it down the call chain into
nvmet_fc_assoc_exists.
While at it also fix the name typo of the function.
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
drivers/nvme/target/fc.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index fd229f310c93..337ee1cb09ae 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1115,16 +1115,21 @@ nvmet_fc_schedule_delete_assoc(struct nvmet_fc_tgt_assoc *assoc)
}
static bool
-nvmet_fc_assoc_exits(struct nvmet_fc_tgtport *tgtport, u64 association_id)
+nvmet_fc_assoc_exists(struct nvmet_fc_tgtport *tgtport, u64 association_id)
{
struct nvmet_fc_tgt_assoc *a;
+ bool found = false;
+ rcu_read_lock();
list_for_each_entry_rcu(a, &tgtport->assoc_list, a_list) {
- if (association_id == a->association_id)
- return true;
+ if (association_id == a->association_id) {
+ found = true;
+ break;
+ }
}
+ rcu_read_unlock();
- return false;
+ return found;
}
static struct nvmet_fc_tgt_assoc *
@@ -1164,13 +1169,11 @@ nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
ran = ran << BYTES_FOR_QID_SHIFT;
spin_lock_irqsave(&tgtport->lock, flags);
- rcu_read_lock();
- if (!nvmet_fc_assoc_exits(tgtport, ran)) {
+ if (!nvmet_fc_assoc_exists(tgtport, ran)) {
assoc->association_id = ran;
list_add_tail_rcu(&assoc->a_list, &tgtport->assoc_list);
done = true;
}
- rcu_read_unlock();
spin_unlock_irqrestore(&tgtport->lock, flags);
} while (!done);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] nvmet-fc: move RCU read lock to nvmet_fc_assoc_exists
2024-02-12 10:29 [PATCH] nvmet-fc: move RCU read lock to nvmet_fc_assoc_exists Daniel Wagner
@ 2024-02-21 13:11 ` Daniel Wagner
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Wagner @ 2024-02-21 13:11 UTC (permalink / raw)
To: James Smart
Cc: Keith Busch, Christoph Hellwig, Hannes Reinecke, linux-nvme,
linux-kernel
On Mon, Feb 12, 2024 at 11:29:40AM +0100, Daniel Wagner wrote:
> The RCU lock is only needed for the lookup loop and not for
> list_ad_tail_rcu call. Thus move it down the call chain into
> nvmet_fc_assoc_exists.
>
> While at it also fix the name typo of the function.
>
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
ping
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-21 13:11 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-12 10:29 [PATCH] nvmet-fc: move RCU read lock to nvmet_fc_assoc_exists Daniel Wagner
2024-02-21 13:11 ` Daniel Wagner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox