diff options
author | Matthew Wilcox <willy@infradead.org> | 2018-06-19 01:23:04 -0400 |
---|---|---|
committer | Matthew Wilcox <willy@infradead.org> | 2018-08-21 23:54:19 -0400 |
commit | 31ff0ceeb266a4ac96f3fc8cebb85df862a22f92 (patch) | |
tree | 0b5d49f8c334d178b63b4bcc11e668f6d964f91d | |
parent | 26abc916a898d34c5ad159315a2f683def3c5555 (diff) |
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>
-rw-r--r-- | drivers/target/iscsi/iscsi_target.c | 10 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target.h | 4 | ||||
-rw-r--r-- | drivers/target/iscsi/iscsi_target_login.c | 26 |
3 files changed, 10 insertions, 30 deletions
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c index 8e223799347a..94bad43c41ff 100644 --- a/drivers/target/iscsi/iscsi_target.c +++ b/drivers/target/iscsi/iscsi_target.c | |||
@@ -57,9 +57,8 @@ static DEFINE_SPINLOCK(tiqn_lock); | |||
57 | static DEFINE_MUTEX(np_lock); | 57 | static DEFINE_MUTEX(np_lock); |
58 | 58 | ||
59 | static struct idr tiqn_idr; | 59 | static struct idr tiqn_idr; |
60 | struct idr sess_idr; | 60 | DEFINE_IDA(sess_ida); |
61 | struct mutex auth_id_lock; | 61 | struct mutex auth_id_lock; |
62 | spinlock_t sess_idr_lock; | ||
63 | 62 | ||
64 | struct iscsit_global *iscsit_global; | 63 | struct iscsit_global *iscsit_global; |
65 | 64 | ||
@@ -700,9 +699,7 @@ static int __init iscsi_target_init_module(void) | |||
700 | 699 | ||
701 | spin_lock_init(&iscsit_global->ts_bitmap_lock); | 700 | spin_lock_init(&iscsit_global->ts_bitmap_lock); |
702 | mutex_init(&auth_id_lock); | 701 | mutex_init(&auth_id_lock); |
703 | spin_lock_init(&sess_idr_lock); | ||
704 | idr_init(&tiqn_idr); | 702 | idr_init(&tiqn_idr); |
705 | idr_init(&sess_idr); | ||
706 | 703 | ||
707 | ret = target_register_template(&iscsi_ops); | 704 | ret = target_register_template(&iscsi_ops); |
708 | if (ret) | 705 | if (ret) |
@@ -4375,10 +4372,7 @@ int iscsit_close_session(struct iscsi_session *sess) | |||
4375 | pr_debug("Decremented number of active iSCSI Sessions on" | 4372 | pr_debug("Decremented number of active iSCSI Sessions on" |
4376 | " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); | 4373 | " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); |
4377 | 4374 | ||
4378 | spin_lock(&sess_idr_lock); | 4375 | ida_free(&sess_ida, sess->session_index); |
4379 | idr_remove(&sess_idr, sess->session_index); | ||
4380 | spin_unlock(&sess_idr_lock); | ||
4381 | |||
4382 | kfree(sess->sess_ops); | 4376 | kfree(sess->sess_ops); |
4383 | sess->sess_ops = NULL; | 4377 | sess->sess_ops = NULL; |
4384 | spin_unlock_bh(&se_tpg->session_lock); | 4378 | spin_unlock_bh(&se_tpg->session_lock); |
diff --git a/drivers/target/iscsi/iscsi_target.h b/drivers/target/iscsi/iscsi_target.h index 42de1843aa40..48bac0acf8c7 100644 --- a/drivers/target/iscsi/iscsi_target.h +++ b/drivers/target/iscsi/iscsi_target.h | |||
@@ -55,9 +55,7 @@ extern struct kmem_cache *lio_ooo_cache; | |||
55 | extern struct kmem_cache *lio_qr_cache; | 55 | extern struct kmem_cache *lio_qr_cache; |
56 | extern struct kmem_cache *lio_r2t_cache; | 56 | extern struct kmem_cache *lio_r2t_cache; |
57 | 57 | ||
58 | extern struct idr sess_idr; | 58 | extern struct ida sess_ida; |
59 | extern struct mutex auth_id_lock; | 59 | extern struct mutex auth_id_lock; |
60 | extern spinlock_t sess_idr_lock; | ||
61 | |||
62 | 60 | ||
63 | #endif /*** ISCSI_TARGET_H ***/ | 61 | #endif /*** ISCSI_TARGET_H ***/ |
diff --git a/drivers/target/iscsi/iscsi_target_login.c b/drivers/target/iscsi/iscsi_target_login.c index 68b3eb00a9d0..b75a8b283581 100644 --- a/drivers/target/iscsi/iscsi_target_login.c +++ b/drivers/target/iscsi/iscsi_target_login.c | |||
@@ -336,21 +336,15 @@ static int iscsi_login_zero_tsih_s1( | |||
336 | timer_setup(&sess->time2retain_timer, | 336 | timer_setup(&sess->time2retain_timer, |
337 | iscsit_handle_time2retain_timeout, 0); | 337 | iscsit_handle_time2retain_timeout, 0); |
338 | 338 | ||
339 | idr_preload(GFP_KERNEL); | 339 | ret = ida_alloc(&sess_ida, 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 | |||
347 | if (ret < 0) { | 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 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, | 342 | iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, |
350 | ISCSI_LOGIN_STATUS_NO_RESOURCES); | 343 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
351 | goto free_sess; | 344 | goto free_sess; |
352 | } | 345 | } |
353 | 346 | ||
347 | sess->session_index = ret; | ||
354 | sess->creation_time = get_jiffies_64(); | 348 | sess->creation_time = get_jiffies_64(); |
355 | /* | 349 | /* |
356 | * The FFP CmdSN window values will be allocated from the TPG's | 350 | * The FFP CmdSN window values will be allocated from the TPG's |
@@ -364,7 +358,7 @@ static int iscsi_login_zero_tsih_s1( | |||
364 | ISCSI_LOGIN_STATUS_NO_RESOURCES); | 358 | ISCSI_LOGIN_STATUS_NO_RESOURCES); |
365 | pr_err("Unable to allocate memory for" | 359 | pr_err("Unable to allocate memory for" |
366 | " struct iscsi_sess_ops.\n"); | 360 | " struct iscsi_sess_ops.\n"); |
367 | goto remove_idr; | 361 | goto free_id; |
368 | } | 362 | } |
369 | 363 | ||
370 | sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); | 364 | sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); |
@@ -378,10 +372,8 @@ static int iscsi_login_zero_tsih_s1( | |||
378 | 372 | ||
379 | free_ops: | 373 | free_ops: |
380 | kfree(sess->sess_ops); | 374 | kfree(sess->sess_ops); |
381 | remove_idr: | 375 | free_id: |
382 | spin_lock_bh(&sess_idr_lock); | 376 | ida_free(&sess_ida, sess->session_index); |
383 | idr_remove(&sess_idr, sess->session_index); | ||
384 | spin_unlock_bh(&sess_idr_lock); | ||
385 | free_sess: | 377 | free_sess: |
386 | kfree(sess); | 378 | kfree(sess); |
387 | conn->sess = NULL; | 379 | conn->sess = NULL; |
@@ -1170,11 +1162,7 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn, | |||
1170 | goto old_sess_out; | 1162 | goto old_sess_out; |
1171 | 1163 | ||
1172 | transport_free_session(conn->sess->se_sess); | 1164 | transport_free_session(conn->sess->se_sess); |
1173 | 1165 | ida_free(&sess_ida, conn->sess->session_index); | |
1174 | spin_lock_bh(&sess_idr_lock); | ||
1175 | idr_remove(&sess_idr, conn->sess->session_index); | ||
1176 | spin_unlock_bh(&sess_idr_lock); | ||
1177 | |||
1178 | kfree(conn->sess->sess_ops); | 1166 | kfree(conn->sess->sess_ops); |
1179 | kfree(conn->sess); | 1167 | kfree(conn->sess); |
1180 | conn->sess = NULL; | 1168 | conn->sess = NULL; |