Commit 31ff0cee authored by Matthew Wilcox's avatar Matthew Wilcox

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: default avatarMatthew Wilcox <willy@infradead.org>
parent 26abc916
...@@ -57,9 +57,8 @@ static DEFINE_SPINLOCK(tiqn_lock); ...@@ -57,9 +57,8 @@ static DEFINE_SPINLOCK(tiqn_lock);
static DEFINE_MUTEX(np_lock); static DEFINE_MUTEX(np_lock);
static struct idr tiqn_idr; static struct idr tiqn_idr;
struct idr sess_idr; DEFINE_IDA(sess_ida);
struct mutex auth_id_lock; struct mutex auth_id_lock;
spinlock_t sess_idr_lock;
struct iscsit_global *iscsit_global; struct iscsit_global *iscsit_global;
...@@ -700,9 +699,7 @@ static int __init iscsi_target_init_module(void) ...@@ -700,9 +699,7 @@ static int __init iscsi_target_init_module(void)
spin_lock_init(&iscsit_global->ts_bitmap_lock); spin_lock_init(&iscsit_global->ts_bitmap_lock);
mutex_init(&auth_id_lock); mutex_init(&auth_id_lock);
spin_lock_init(&sess_idr_lock);
idr_init(&tiqn_idr); idr_init(&tiqn_idr);
idr_init(&sess_idr);
ret = target_register_template(&iscsi_ops); ret = target_register_template(&iscsi_ops);
if (ret) if (ret)
...@@ -4375,10 +4372,7 @@ int iscsit_close_session(struct iscsi_session *sess) ...@@ -4375,10 +4372,7 @@ int iscsit_close_session(struct iscsi_session *sess)
pr_debug("Decremented number of active iSCSI Sessions on" pr_debug("Decremented number of active iSCSI Sessions on"
" iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions);
spin_lock(&sess_idr_lock); ida_free(&sess_ida, sess->session_index);
idr_remove(&sess_idr, sess->session_index);
spin_unlock(&sess_idr_lock);
kfree(sess->sess_ops); kfree(sess->sess_ops);
sess->sess_ops = NULL; sess->sess_ops = NULL;
spin_unlock_bh(&se_tpg->session_lock); spin_unlock_bh(&se_tpg->session_lock);
......
...@@ -55,9 +55,7 @@ extern struct kmem_cache *lio_ooo_cache; ...@@ -55,9 +55,7 @@ extern struct kmem_cache *lio_ooo_cache;
extern struct kmem_cache *lio_qr_cache; extern struct kmem_cache *lio_qr_cache;
extern struct kmem_cache *lio_r2t_cache; extern struct kmem_cache *lio_r2t_cache;
extern struct idr sess_idr; extern struct ida sess_ida;
extern struct mutex auth_id_lock; extern struct mutex auth_id_lock;
extern spinlock_t sess_idr_lock;
#endif /*** ISCSI_TARGET_H ***/ #endif /*** ISCSI_TARGET_H ***/
...@@ -336,21 +336,15 @@ static int iscsi_login_zero_tsih_s1( ...@@ -336,21 +336,15 @@ static int iscsi_login_zero_tsih_s1(
timer_setup(&sess->time2retain_timer, timer_setup(&sess->time2retain_timer,
iscsit_handle_time2retain_timeout, 0); iscsit_handle_time2retain_timeout, 0);
idr_preload(GFP_KERNEL); ret = ida_alloc(&sess_ida, GFP_KERNEL);
spin_lock_bh(&sess_idr_lock);
ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT);
if (ret >= 0)
sess->session_index = ret;
spin_unlock_bh(&sess_idr_lock);
idr_preload_end();
if (ret < 0) { if (ret < 0) {
pr_err("idr_alloc() for sess_idr failed\n"); pr_err("Session ID allocation failed %d\n", ret);
iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR,
ISCSI_LOGIN_STATUS_NO_RESOURCES); ISCSI_LOGIN_STATUS_NO_RESOURCES);
goto free_sess; goto free_sess;
} }
sess->session_index = ret;
sess->creation_time = get_jiffies_64(); sess->creation_time = get_jiffies_64();
/* /*
* The FFP CmdSN window values will be allocated from the TPG's * The FFP CmdSN window values will be allocated from the TPG's
...@@ -364,7 +358,7 @@ static int iscsi_login_zero_tsih_s1( ...@@ -364,7 +358,7 @@ static int iscsi_login_zero_tsih_s1(
ISCSI_LOGIN_STATUS_NO_RESOURCES); ISCSI_LOGIN_STATUS_NO_RESOURCES);
pr_err("Unable to allocate memory for" pr_err("Unable to allocate memory for"
" struct iscsi_sess_ops.\n"); " struct iscsi_sess_ops.\n");
goto remove_idr; goto free_id;
} }
sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); sess->se_sess = transport_init_session(TARGET_PROT_NORMAL);
...@@ -378,10 +372,8 @@ static int iscsi_login_zero_tsih_s1( ...@@ -378,10 +372,8 @@ static int iscsi_login_zero_tsih_s1(
free_ops: free_ops:
kfree(sess->sess_ops); kfree(sess->sess_ops);
remove_idr: free_id:
spin_lock_bh(&sess_idr_lock); ida_free(&sess_ida, sess->session_index);
idr_remove(&sess_idr, sess->session_index);
spin_unlock_bh(&sess_idr_lock);
free_sess: free_sess:
kfree(sess); kfree(sess);
conn->sess = NULL; conn->sess = NULL;
...@@ -1170,11 +1162,7 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn, ...@@ -1170,11 +1162,7 @@ void iscsi_target_login_sess_out(struct iscsi_conn *conn,
goto old_sess_out; goto old_sess_out;
transport_free_session(conn->sess->se_sess); transport_free_session(conn->sess->se_sess);
ida_free(&sess_ida, conn->sess->session_index);
spin_lock_bh(&sess_idr_lock);
idr_remove(&sess_idr, conn->sess->session_index);
spin_unlock_bh(&sess_idr_lock);
kfree(conn->sess->sess_ops); kfree(conn->sess->sess_ops);
kfree(conn->sess); kfree(conn->sess);
conn->sess = NULL; conn->sess = NULL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment