#include <target/iscsi/iscsi_transport.h>
-static LIST_HEAD(g_tiqn_list);
static LIST_HEAD(g_np_list);
-static DEFINE_SPINLOCK(tiqn_lock);
static DEFINE_MUTEX(np_lock);
-static struct idr tiqn_idr;
+static DEFINE_XARRAY_ALLOC(tiqns);
DEFINE_IDA(sess_ida);
struct mutex auth_id_lock;
struct iscsi_tiqn *iscsit_get_tiqn_for_login(unsigned char *buf)
{
- struct iscsi_tiqn *tiqn = NULL;
+ struct iscsi_tiqn *tiqn;
+ unsigned long index;
- spin_lock(&tiqn_lock);
- list_for_each_entry(tiqn, &g_tiqn_list, tiqn_list) {
+ xa_lock(&tiqns);
+ xa_for_each(&tiqns, index, tiqn) {
if (!strcmp(tiqn->tiqn, buf)) {
-
spin_lock(&tiqn->tiqn_state_lock);
if (tiqn->tiqn_state == TIQN_STATE_ACTIVE) {
tiqn->tiqn_access_count++;
spin_unlock(&tiqn->tiqn_state_lock);
- spin_unlock(&tiqn_lock);
- return tiqn;
+ break;
}
spin_unlock(&tiqn->tiqn_state_lock);
}
}
- spin_unlock(&tiqn_lock);
+ xa_unlock(&tiqns);
- return NULL;
+ return tiqn;
}
static int iscsit_set_tiqn_shutdown(struct iscsi_tiqn *tiqn)
return ERR_PTR(-ENOMEM);
sprintf(tiqn->tiqn, "%s", buf);
- INIT_LIST_HEAD(&tiqn->tiqn_list);
INIT_LIST_HEAD(&tiqn->tiqn_tpg_list);
spin_lock_init(&tiqn->tiqn_state_lock);
spin_lock_init(&tiqn->tiqn_tpg_lock);
tiqn->tiqn_state = TIQN_STATE_ACTIVE;
- idr_preload(GFP_KERNEL);
- spin_lock(&tiqn_lock);
-
- ret = idr_alloc(&tiqn_idr, NULL, 0, 0, GFP_NOWAIT);
+ ret = xa_alloc(&tiqns, &tiqn->tiqn_index, tiqn, xa_limit_32b,
+ GFP_KERNEL);
if (ret < 0) {
- pr_err("idr_alloc() failed for tiqn->tiqn_index\n");
- spin_unlock(&tiqn_lock);
- idr_preload_end();
+ pr_err("tiqn ID allocation failed\n");
kfree(tiqn);
return ERR_PTR(ret);
}
- tiqn->tiqn_index = ret;
- list_add_tail(&tiqn->tiqn_list, &g_tiqn_list);
-
- spin_unlock(&tiqn_lock);
- idr_preload_end();
pr_debug("CORE[0] - Added iSCSI Target IQN: %s\n", tiqn->tiqn);
return tiqn;
-
}
static void iscsit_wait_for_tiqn(struct iscsi_tiqn *tiqn)
iscsit_wait_for_tiqn(tiqn);
- spin_lock(&tiqn_lock);
- list_del(&tiqn->tiqn_list);
- idr_remove(&tiqn_idr, tiqn->tiqn_index);
- spin_unlock(&tiqn_lock);
+ xa_erase(&tiqns, tiqn->tiqn_index);
pr_debug("CORE[0] - Deleted iSCSI Target IQN: %s\n",
tiqn->tiqn);
spin_lock_init(&iscsit_global->ts_bitmap_lock);
mutex_init(&auth_id_lock);
- idr_init(&tiqn_idr);
ret = target_register_template(&iscsi_ops);
if (ret)
struct iscsi_conn *conn = cmd->conn;
struct iscsi_portal_group *tpg;
struct iscsi_tiqn *tiqn;
+ unsigned long index;
struct iscsi_tpg_np *tpg_np;
int buffer_len, end_of_buf = 0, len = 0, payload_len = 0;
int target_name_printed;
text_ptr += 1;
}
- spin_lock(&tiqn_lock);
- list_for_each_entry(tiqn, &g_tiqn_list, tiqn_list) {
+ xa_lock(&tiqns);
+ xa_for_each(&tiqns, index, tiqn) {
if ((cmd->cmd_flags & ICF_SENDTARGETS_SINGLE) &&
strcmp(tiqn->tiqn, text_ptr)) {
continue;
if (cmd->cmd_flags & ICF_SENDTARGETS_SINGLE)
break;
}
- spin_unlock(&tiqn_lock);
+ xa_unlock(&tiqns);
cmd->buf_ptr = payload;