[v4,12/12] nvmet-fc: use RCU list iterator for assoc_list

Message ID 20240130094938.1575-13-dwagner@suse.de
State New
Headers
Series enable nvmet-fc for blktests |

Commit Message

Daniel Wagner Jan. 30, 2024, 9:49 a.m. UTC
  The assoc_list is a RCU protected list, thus use the RCU flavor of list
functions.

Signed-off-by: Daniel Wagner <dwagner@suse.de>
---
 drivers/nvme/target/fc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Comments

Christoph Hellwig Jan. 31, 2024, 6:29 a.m. UTC | #1
> +		list_for_each_entry_rcu(tmpassoc, &tgtport->assoc_list, a_list) {

please avoid the overly long line.

Also in general the (rcu)lock, list walk to find something, return
patterns tend to benefit from being factored into a little helper.
Not sure if that really fits here, though.
  

Patch

diff --git a/drivers/nvme/target/fc.c b/drivers/nvme/target/fc.c
index 671d096745a5..b8d3e30f2ddb 100644
--- a/drivers/nvme/target/fc.c
+++ b/drivers/nvme/target/fc.c
@@ -1151,7 +1151,9 @@  nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
 
 		spin_lock_irqsave(&tgtport->lock, flags);
 		needrandom = false;
-		list_for_each_entry(tmpassoc, &tgtport->assoc_list, a_list) {
+		rcu_read_lock();
+		list_for_each_entry_rcu(tmpassoc, &tgtport->assoc_list, a_list) {
+
 			if (ran == tmpassoc->association_id) {
 				needrandom = true;
 				break;
@@ -1161,6 +1163,7 @@  nvmet_fc_alloc_target_assoc(struct nvmet_fc_tgtport *tgtport, void *hosthandle)
 			assoc->association_id = ran;
 			list_add_tail_rcu(&assoc->a_list, &tgtport->assoc_list);
 		}
+		rcu_read_unlock();
 		spin_unlock_irqrestore(&tgtport->lock, flags);
 	}