From: "Nicholas A. Bellinger" <nab@linux-iscsi.org>
To: linux-scsi <linux-scsi@vger.kernel.org>,
James Bottomley <James.Bottomley@suse.de>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Subject: [PATCH v2 02f/03] target: Add HBA core infrastructure
Date: Fri, 17 Dec 2010 13:11:22 -0800 [thread overview]
Message-ID: <1292620296-22822-8-git-send-email-nab@linux-iscsi.org> (raw)
In-Reply-To: <1292620296-22822-1-git-send-email-nab@linux-iscsi.org>
From: Nicholas Bellinger <nab@linux-iscsi.org>
This patch adds the core struct se_hba functionality that is used internally by
target_core_mod to group the same subsystem storage objects types until a single
/sys/kernel/config/target/core/$HBA directory. The HBA code supports boths
physical storage objects (from Linux/SCSI) and virtual storage objects (from Linux/BLOCK,
Linux/VFS, RAMDISK)
Signed-off-by: Nicholas A. Bellinger <nab@linux-iscsi.org>
---
drivers/target/target_core_hba.c | 185 ++++++++++++++++++++++++++++++++++++++
drivers/target/target_core_hba.h | 7 ++
2 files changed, 192 insertions(+), 0 deletions(-)
create mode 100644 drivers/target/target_core_hba.c
create mode 100644 drivers/target/target_core_hba.h
diff --git a/drivers/target/target_core_hba.c b/drivers/target/target_core_hba.c
new file mode 100644
index 0000000..4bbe820
--- /dev/null
+++ b/drivers/target/target_core_hba.c
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * Filename: target_core_hba.c
+ *
+ * This file copntains the iSCSI HBA Transport related functions.
+ *
+ * Copyright (c) 2003, 2004, 2005 PyX Technologies, Inc.
+ * Copyright (c) 2005, 2006, 2007 SBE, Inc.
+ * Copyright (c) 2007-2010 Rising Tide Systems
+ * Copyright (c) 2008-2010 Linux-iSCSI.org
+ *
+ * Nicholas A. Bellinger <nab@kernel.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ ******************************************************************************/
+
+#include <linux/net.h>
+#include <linux/string.h>
+#include <linux/timer.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/smp_lock.h>
+#include <linux/in.h>
+#include <net/sock.h>
+#include <net/tcp.h>
+
+#include <target/target_core_base.h>
+#include <target/target_core_device.h>
+#include <target/target_core_device.h>
+#include <target/target_core_tpg.h>
+#include <target/target_core_transport.h>
+
+#include "target_core_hba.h"
+
+static LIST_HEAD(subsystem_list);
+static DEFINE_MUTEX(subsystem_mutex);
+
+int transport_subsystem_register(struct se_subsystem_api *sub_api)
+{
+ struct se_subsystem_api *s;
+
+ INIT_LIST_HEAD(&sub_api->sub_api_list);
+
+ mutex_lock(&subsystem_mutex);
+ list_for_each_entry(s, &subsystem_list, sub_api_list) {
+ if (!(strcmp(s->name, sub_api->name))) {
+ printk(KERN_ERR "%p is already registered with"
+ " duplicate name %s, unable to process"
+ " request\n", s, s->name);
+ mutex_unlock(&subsystem_mutex);
+ return -EEXIST;
+ }
+ }
+ list_add_tail(&sub_api->sub_api_list, &subsystem_list);
+ mutex_unlock(&subsystem_mutex);
+
+ printk(KERN_INFO "TCM: Registered subsystem plugin: %s struct module:"
+ " %p\n", sub_api->name, sub_api->owner);
+ return 0;
+}
+EXPORT_SYMBOL(transport_subsystem_register);
+
+void transport_subsystem_release(struct se_subsystem_api *sub_api)
+{
+ mutex_lock(&subsystem_mutex);
+ list_del(&sub_api->sub_api_list);
+ mutex_unlock(&subsystem_mutex);
+}
+EXPORT_SYMBOL(transport_subsystem_release);
+
+static struct se_subsystem_api *core_get_backend(const char *sub_name)
+{
+ struct se_subsystem_api *s;
+
+ mutex_lock(&subsystem_mutex);
+ list_for_each_entry(s, &subsystem_list, sub_api_list) {
+ if (!strcmp(s->name, sub_name))
+ goto found;
+ }
+ mutex_unlock(&subsystem_mutex);
+ return NULL;
+found:
+ if (s->owner && !try_module_get(s->owner))
+ s = NULL;
+ mutex_unlock(&subsystem_mutex);
+ return s;
+}
+
+struct se_hba *
+core_alloc_hba(const char *plugin_name, u32 plugin_dep_id, u32 hba_flags)
+{
+ struct se_hba *hba;
+ int ret = 0;
+
+ hba = kzalloc(sizeof(*hba), GFP_KERNEL);
+ if (!hba) {
+ printk(KERN_ERR "Unable to allocate struct se_hba\n");
+ return ERR_PTR(-ENOMEM);
+ }
+
+ INIT_LIST_HEAD(&hba->hba_dev_list);
+ spin_lock_init(&hba->device_lock);
+ spin_lock_init(&hba->hba_queue_lock);
+ mutex_init(&hba->hba_access_mutex);
+
+ hba->hba_index = scsi_get_new_index(SCSI_INST_INDEX);
+ hba->hba_flags |= hba_flags;
+
+ atomic_set(&hba->max_queue_depth, 0);
+ atomic_set(&hba->left_queue_depth, 0);
+
+ hba->transport = core_get_backend(plugin_name);
+ if (!hba->transport) {
+ ret = -EINVAL;
+ goto out_free_hba;
+ }
+
+ ret = hba->transport->attach_hba(hba, plugin_dep_id);
+ if (ret < 0)
+ goto out_module_put;
+
+ spin_lock(&se_global->hba_lock);
+ hba->hba_id = se_global->g_hba_id_counter++;
+ list_add_tail(&hba->hba_list, &se_global->g_hba_list);
+ spin_unlock(&se_global->hba_lock);
+
+ printk(KERN_INFO "CORE_HBA[%d] - Attached HBA to Generic Target"
+ " Core\n", hba->hba_id);
+
+ return hba;
+
+out_module_put:
+ if (hba->transport->owner)
+ module_put(hba->transport->owner);
+ hba->transport = NULL;
+out_free_hba:
+ kfree(hba);
+ return ERR_PTR(ret);
+}
+
+int
+core_delete_hba(struct se_hba *hba)
+{
+ struct se_device *dev, *dev_tmp;
+
+ spin_lock(&hba->device_lock);
+ list_for_each_entry_safe(dev, dev_tmp, &hba->hba_dev_list, dev_list) {
+
+ se_clear_dev_ports(dev);
+ spin_unlock(&hba->device_lock);
+
+ se_release_device_for_hba(dev);
+
+ spin_lock(&hba->device_lock);
+ }
+ spin_unlock(&hba->device_lock);
+
+ hba->transport->detach_hba(hba);
+
+ spin_lock(&se_global->hba_lock);
+ list_del(&hba->hba_list);
+ spin_unlock(&se_global->hba_lock);
+
+ printk(KERN_INFO "CORE_HBA[%d] - Detached HBA from Generic Target"
+ " Core\n", hba->hba_id);
+
+ if (hba->transport->owner)
+ module_put(hba->transport->owner);
+
+ hba->transport = NULL;
+ kfree(hba);
+ return 0;
+}
diff --git a/drivers/target/target_core_hba.h b/drivers/target/target_core_hba.h
new file mode 100644
index 0000000..bb0fea5
--- /dev/null
+++ b/drivers/target/target_core_hba.h
@@ -0,0 +1,7 @@
+#ifndef TARGET_CORE_HBA_H
+#define TARGET_CORE_HBA_H
+
+extern struct se_hba *core_alloc_hba(const char *, u32, u32);
+extern int core_delete_hba(struct se_hba *);
+
+#endif /* TARGET_CORE_HBA_H */
--
1.7.3.4
next prev parent reply other threads:[~2010-12-17 21:12 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-17 21:11 [PATCH v2 00/03] target: Initial merge of v4.0.0-rc6 for .38 Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 01/03] scsi: Add missing SPC-4 CDB and MAINTENANCE_[IN,OUT] service action definitions Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02a/03] target: Add ConfigFS extended macro set Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02b/03] target: Add v4 base data structures and struct target_core_fabric_ops Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02c/03] target: Add SPC-4 explict and implict Asymmetric Logical Unit Access (ALUA) Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02d/03] target: Add ConfigFS subsystem backstore infrastructure Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02e/03] target: Add fabric and subsystem transport engine core Nicholas A. Bellinger
2010-12-17 21:11 ` Nicholas A. Bellinger [this message]
2010-12-17 21:11 ` [PATCH v2 02g/03] target: Add device core infrastructure Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02h/03] target: Add target portal group infrastructure Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02i/03] target: Add SPC-4 compliant Persistent Reservations (PR) Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02j/03] target: Add Task Management infrastructure Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02k/03] target: Add UNIT_ATTENTION infrastructure support Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02l/03] target: Add SCSI MIB statistics support Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02m/03] target: Add FILEIO subsystem plugin Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02n/03] target: Add IBLOCK " Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02o/03] target: Add PSCSI " Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02p/03] target: Add RAMDISK_DR and RAMDISK_MCP subsystem plugins Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02q/03] target: Add generic fabric independent ConfigFS infrastructure Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02r/03] target: Add generic ProtoID and TransportID fabric handlers for SAS, FC, and iSCSI Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 02s/03] target: Add Kbuild and Kconfig for drivers/target and Documentation/target/ Nicholas A. Bellinger
2010-12-17 21:11 ` [PATCH v2 03/03] tcm_loop: Add multi-fabric Linux/SCSI LLD fabric module Nicholas A. Bellinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1292620296-22822-8-git-send-email-nab@linux-iscsi.org \
--to=nab@linux-iscsi.org \
--cc=James.Bottomley@suse.de \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).