From patchwork Fri Jun 23 09:10:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Christie X-Patchwork-Id: 9806025 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B21F160349 for ; Fri, 23 Jun 2017 09:10:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3BB228583 for ; Fri, 23 Jun 2017 09:10:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 98AF32861F; Fri, 23 Jun 2017 09:10:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 110542859E for ; Fri, 23 Jun 2017 09:10:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754352AbdFWJK1 (ORCPT ); Fri, 23 Jun 2017 05:10:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38650 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754346AbdFWJKW (ORCPT ); Fri, 23 Jun 2017 05:10:22 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C37018E239; Fri, 23 Jun 2017 09:10:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C37018E239 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=mchristi@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com C37018E239 Received: from rh2.redhat.com (ovpn-120-27.rdu2.redhat.com [10.10.120.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 079E918C69; Fri, 23 Jun 2017 09:10:20 +0000 (UTC) From: Mike Christie To: bart.vanassche@wdc.com, target-devel@vger.kernel.org, nab@linux-iscsi.org Cc: Mike Christie Subject: [RFC PATCH 2/4] target: merge hba_id and hba_index and use ida for the id Date: Fri, 23 Jun 2017 04:10:15 -0500 Message-Id: <1498209017-25110-3-git-send-email-mchristi@redhat.com> In-Reply-To: <1498209017-25110-1-git-send-email-mchristi@redhat.com> References: <1498209017-25110-1-git-send-email-mchristi@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 23 Jun 2017 09:10:21 +0000 (UTC) Sender: target-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: target-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;