diff mbox

[RFC,3/4] target: use ida for acl index

Message ID 1498209017-25110-4-git-send-email-mchristi@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Mike Christie June 23, 2017, 9:10 a.m. UTC
This just uses a ida for the acl index, so we avoid collisions
if we ever rollover.

Signed-off-by: Mike Christie <mchristi@redhat.com>
---
 drivers/target/target_core_tpg.c  | 13 ++++++++++++-
 include/target/target_core_base.h |  1 -
 2 files changed, 12 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 1b2b60e..61d3f2b 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -47,6 +47,7 @@  extern struct se_device *g_lun0_dev;
 
 static DEFINE_SPINLOCK(tpg_lock);
 static LIST_HEAD(tpg_list);
+static DEFINE_IDA(acl_index_ida);
 
 /*	__core_tpg_get_initiator_node_acl():
  *
@@ -187,12 +188,18 @@  static struct se_node_acl *target_alloc_node_acl(struct se_portal_group *tpg,
 {
 	struct se_node_acl *acl;
 	u32 queue_depth;
+	int ret;
 
 	acl = kzalloc(max(sizeof(*acl), tpg->se_tpg_tfo->node_acl_size),
 			GFP_KERNEL);
 	if (!acl)
 		return NULL;
 
+	ret = ida_simple_get_cyclic(&acl_index_ida, 0, 0, GFP_KERNEL);
+	if (ret < 0)
+		goto free_acl;
+	acl->acl_index = ret;
+
 	INIT_LIST_HEAD(&acl->acl_list);
 	INIT_LIST_HEAD(&acl->acl_sess_list);
 	INIT_HLIST_HEAD(&acl->lun_entry_hlist);
@@ -210,11 +217,14 @@  static struct se_node_acl *target_alloc_node_acl(struct se_portal_group *tpg,
 
 	snprintf(acl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname);
 	acl->se_tpg = tpg;
-	acl->acl_index = scsi_get_new_index(SCSI_AUTH_INTR_INDEX);
 
 	tpg->se_tpg_tfo->set_default_node_attributes(acl);
 
 	return acl;
+
+free_acl:
+	kfree(acl);
+	return NULL;
 }
 
 static void target_add_node_acl(struct se_node_acl *acl)
@@ -382,6 +392,7 @@  void core_tpg_del_initiator_node_acl(struct se_node_acl *acl)
 
 	core_tpg_wait_for_nacl_pr_ref(acl);
 	core_free_device_list_for_node(acl, tpg);
+	ida_simple_remove(&acl_index_ida, acl->acl_index);
 
 	pr_debug("%s_TPG[%hu] - Deleted ACL with TCQ Depth: %d for %s"
 		" Initiator Node: %s\n", tpg->se_tpg_tfo->get_fabric_name(),
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 19ec189..d275a39 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -219,7 +219,6 @@  enum tcm_tmrsp_table {
  */
 typedef enum {
 	SCSI_INST_INDEX,
-	SCSI_AUTH_INTR_INDEX,
 	SCSI_INDEX_TYPE_MAX
 } scsi_index_t;