Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target/iscsi: Allocate session IDs from an IDA

Since the session is never looked up by ID, we can use the more
space-efficient IDA instead of the IDR.

Signed-off-by: Matthew Wilcox <willy@infradead.org>

+10 -30
+2 -8
drivers/target/iscsi/iscsi_target.c
··· 57 57 static DEFINE_MUTEX(np_lock); 58 58 59 59 static struct idr tiqn_idr; 60 - struct idr sess_idr; 60 + DEFINE_IDA(sess_ida); 61 61 struct mutex auth_id_lock; 62 - spinlock_t sess_idr_lock; 63 62 64 63 struct iscsit_global *iscsit_global; 65 64 ··· 699 700 700 701 spin_lock_init(&iscsit_global->ts_bitmap_lock); 701 702 mutex_init(&auth_id_lock); 702 - spin_lock_init(&sess_idr_lock); 703 703 idr_init(&tiqn_idr); 704 - idr_init(&sess_idr); 705 704 706 705 ret = target_register_template(&iscsi_ops); 707 706 if (ret) ··· 4372 4375 pr_debug("Decremented number of active iSCSI Sessions on" 4373 4376 " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); 4374 4377 4375 - spin_lock(&sess_idr_lock); 4376 - idr_remove(&sess_idr, sess->session_index); 4377 - spin_unlock(&sess_idr_lock); 4378 - 4378 + ida_free(&sess_ida, sess->session_index); 4379 4379 kfree(sess->sess_ops); 4380 4380 sess->sess_ops = NULL; 4381 4381 spin_unlock_bh(&se_tpg->session_lock);
+1 -3
drivers/target/iscsi/iscsi_target.h
··· 55 55 extern struct kmem_cache *lio_qr_cache; 56 56 extern struct kmem_cache *lio_r2t_cache; 57 57 58 - extern struct idr sess_idr; 58 + extern struct ida sess_ida; 59 59 extern struct mutex auth_id_lock; 60 - extern spinlock_t sess_idr_lock; 61 - 62 60 63 61 #endif /*** ISCSI_TARGET_H ***/
+7 -19
drivers/target/iscsi/iscsi_target_login.c
··· 336 336 timer_setup(&sess->time2retain_timer, 337 337 iscsit_handle_time2retain_timeout, 0); 338 338 339 - idr_preload(GFP_KERNEL); 340 - spin_lock_bh(&sess_idr_lock); 341 - ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT); 342 - if (ret >= 0) 343 - sess->session_index = ret; 344 - spin_unlock_bh(&sess_idr_lock); 345 - idr_preload_end(); 346 - 339 + ret = ida_alloc(&sess_ida, GFP_KERNEL); 347 340 if (ret < 0) { 348 - pr_err("idr_alloc() for sess_idr failed\n"); 341 + pr_err("Session ID allocation failed %d\n", ret); 349 342 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 350 343 ISCSI_LOGIN_STATUS_NO_RESOURCES); 351 344 goto free_sess; 352 345 } 353 346 347 + sess->session_index = ret; 354 348 sess->creation_time = get_jiffies_64(); 355 349 /* 356 350 * The FFP CmdSN window values will be allocated from the TPG's ··· 358 364 ISCSI_LOGIN_STATUS_NO_RESOURCES); 359 365 pr_err("Unable to allocate memory for" 360 366 " struct iscsi_sess_ops.\n"); 361 - goto remove_idr; 367 + goto free_id; 362 368 } 363 369 364 370 sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); ··· 372 378 373 379 free_ops: 374 380 kfree(sess->sess_ops); 375 - remove_idr: 376 - spin_lock_bh(&sess_idr_lock); 377 - idr_remove(&sess_idr, sess->session_index); 378 - spin_unlock_bh(&sess_idr_lock); 381 + free_id: 382 + ida_free(&sess_ida, sess->session_index); 379 383 free_sess: 380 384 kfree(sess); 381 385 conn->sess = NULL; ··· 1162 1170 goto old_sess_out; 1163 1171 1164 1172 transport_free_session(conn->sess->se_sess); 1165 - 1166 - spin_lock_bh(&sess_idr_lock); 1167 - idr_remove(&sess_idr, conn->sess->session_index); 1168 - spin_unlock_bh(&sess_idr_lock); 1169 - 1173 + ida_free(&sess_ida, conn->sess->session_index); 1170 1174 kfree(conn->sess->sess_ops); 1171 1175 kfree(conn->sess); 1172 1176 conn->sess = NULL;