hba_index and hba_id seem to both be a int that is just incremented. This patch converts us to use the cyclic ida alloctor for both. Signed-off-by: Mike Christie <mchristi@xxxxxxxxxx> --- drivers/target/target_core_device.c | 2 +- drivers/target/target_core_hba.c | 16 ++++++++++------ drivers/target/target_core_stat.c | 12 ++++++------ include/target/target_core_base.h | 3 +-- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c index 3ae8fbf..05f1454 100644 --- a/drivers/target/target_core_device.c +++ b/drivers/target/target_core_device.c @@ -766,7 +766,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name) dev->se_hba = hba; dev->transport = hba->backend->ops; dev->prot_length = sizeof(struct t10_pi_tuple); - dev->hba_index = hba->hba_index; + dev->hba_id = hba->hba_id; INIT_LIST_HEAD(&dev->dev_sep_list); INIT_LIST_HEAD(&dev->dev_tmr_list); diff --git a/drivers/target/target_core_hba.c b/drivers/target/target_core_hba.c index 22390e0..375f70f 100644 --- a/drivers/target/target_core_hba.c +++ b/drivers/target/target_core_hba.c @@ -42,11 +42,9 @@ static LIST_HEAD(backend_list); static DEFINE_MUTEX(backend_mutex); -static u32 hba_id_counter; - static DEFINE_SPINLOCK(hba_lock); static LIST_HEAD(hba_list); - +static DEFINE_IDA(hba_id_ida); int transport_backend_register(const struct target_backend_ops *ops) { @@ -133,13 +131,16 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags) spin_lock_init(&hba->device_lock); mutex_init(&hba->hba_access_mutex); - hba->hba_index = scsi_get_new_index(SCSI_INST_INDEX); + ret = ida_simple_get_cyclic(&hba_id_ida, 0, 0, GFP_KERNEL); + if (ret < 0) + goto out_free_hba; + hba->hba_id = ret; hba->hba_flags |= hba_flags; hba->backend = core_get_backend(plugin_name); if (!hba->backend) { ret = -EINVAL; - goto out_free_hba; + goto out_free_ida; } ret = hba->backend->ops->attach_hba(hba, plugin_dep_id); @@ -147,7 +148,6 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags) goto out_module_put; spin_lock(&hba_lock); - hba->hba_id = hba_id_counter++; list_add_tail(&hba->hba_node, &hba_list); spin_unlock(&hba_lock); @@ -159,6 +159,8 @@ core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags) out_module_put: module_put(hba->backend->ops->owner); hba->backend = NULL; +out_free_ida: + ida_simple_remove(&hba_id_ida, hba->hba_id); out_free_hba: kfree(hba); return ERR_PTR(ret); @@ -175,6 +177,8 @@ core_delete_hba(struct se_hba *hba) list_del(&hba->hba_node); spin_unlock(&hba_lock); + ida_simple_remove(&hba_id_ida, hba->hba_id); + pr_debug("CORE_HBA[%d] - Detached HBA from Generic Target" " Core\n", hba->hba_id); diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c index 8038255..b042d5f 100644 --- a/drivers/target/target_core_stat.c +++ b/drivers/target/target_core_stat.c @@ -65,7 +65,7 @@ static ssize_t target_stat_inst_show(struct config_item *item, char *page) { struct se_hba *hba = to_stat_dev(item)->se_hba; - return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); + return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_id); } static ssize_t target_stat_indx_show(struct config_item *item, char *page) @@ -115,7 +115,7 @@ static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page) { struct se_hba *hba = to_stat_tgt_dev(item)->se_hba; - return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); + return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_id); } static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page) @@ -213,7 +213,7 @@ static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page) { struct se_hba *hba = to_stat_lu_dev(item)->se_hba; - return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); + return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_id); } static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page) @@ -461,7 +461,7 @@ static ssize_t target_stat_port_inst_show(struct config_item *item, char *page) rcu_read_lock(); dev = rcu_dereference(lun->lun_se_dev); if (dev) - ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_id); rcu_read_unlock(); return ret; } @@ -565,7 +565,7 @@ static ssize_t target_stat_tgt_port_inst_show(struct config_item *item, rcu_read_lock(); dev = rcu_dereference(lun->lun_se_dev); if (dev) - ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_id); rcu_read_unlock(); return ret; } @@ -749,7 +749,7 @@ static ssize_t target_stat_transport_inst_show(struct config_item *item, rcu_read_lock(); dev = rcu_dereference(lun->lun_se_dev); if (dev) - ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_id); rcu_read_unlock(); return ret; } diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 516764f..19ec189 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -818,7 +818,7 @@ struct se_device { /* Protection Information */ int prot_length; /* For se_lun->lun_se_dev RCU read-side critical access */ - u32 hba_index; + u32 hba_id; struct rcu_head rcu_head; }; @@ -829,7 +829,6 @@ struct se_hba { u32 hba_flags; /* Virtual iSCSI devices attached. */ u32 dev_count; - u32 hba_index; /* Pointer to transport specific host structure. */ void *hba_ptr; struct list_head hba_node; -- 2.7.2 -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html