summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Grover <agrover@redhat.com>2013-01-02 16:04:24 -0800
committerAndy Grover <agrover@redhat.com>2013-01-02 16:04:24 -0800
commit185717da3ac3b6b404eb7797651794cebacf3f94 (patch)
treefe0a30b2c3051f54b0464328e3b3920c6de54adc
parent6052874d15aa01538e552d1028fbeb4d92aa3b5a (diff)
downloadrtslib-fb-185717da3ac3b6b404eb7797651794cebacf3f94.tar.gz
Replace specs/ with fabrics.pyv2.1.fb27
.spec files contain relatively little. Consolidate all of them to a single .py file (easy since specs are already in Python). This should make spec maintenance and distribution easier. Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r--rtslib/fabrics.py203
-rw-r--r--rtslib/target.py44
-rw-r--r--specs/README78
-rw-r--r--specs/example.spec.txt29
-rw-r--r--specs/ib_srpt.spec32
-rw-r--r--specs/iscsi.spec29
-rw-r--r--specs/loopback.spec28
-rw-r--r--specs/qla2xxx.spec26
-rw-r--r--specs/sbp.spec21
-rw-r--r--specs/tcm_fc.spec30
-rw-r--r--specs/usb_gadget.spec21
11 files changed, 207 insertions, 334 deletions
diff --git a/rtslib/fabrics.py b/rtslib/fabrics.py
new file mode 100644
index 0000000..69ec376
--- /dev/null
+++ b/rtslib/fabrics.py
@@ -0,0 +1,203 @@
+'''
+Copyright (c) 2011 by RisingTide Systems LLC
+Copyright (c) 2013 by Andy Grover
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, version 3 (AGPLv3).
+
+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 Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+
+Description
+-----------
+
+Instead of having a class to handle each fabric type, rtslib uses a
+single FabricModule class. An instance of FabricModule changes its
+behavior depending on parameters it picks up from here. These used to
+be listed in "spec" files, but are now here.
+
+
+Available parameters
+--------------------
+
+* features
+Lists the target fabric available features. Default value:
+("discovery_auth", "acls", "acls_auth", "nps")
+example: features = ("discovery_auth", "acls", "acls_auth")
+example: features = () # no features supported
+
+Detail of features:
+
+ * tpgts
+ The target fabric module is using iSCSI-style target portal group tags.
+
+ * discovery_auth
+ The target fabric module supports a fabric-wide authentication for
+ discovery.
+
+ * acls
+ The target's TPGTs support explicit initiator ACLs.
+
+ * acls_auth
+ The target's TPGT's ACLs support per-ACL initiator authentication.
+
+ * nps
+ The TPGTs support iSCSI-like IPv4/IPv6 network portals, using IP:PORT
+ group names.
+
+ * nexus
+ The TPGTs have a 'nexus' attribute that contains the local initiator
+ serial unit. This attribute must be set before being able to create any
+ LUNs.
+
+* wwn_type
+Sets the type of WWN expected by the target fabric. Defaults to 'free'.
+Example: wwn_type = "iqn"
+Current valid types are:
+
+ * free
+ Freeform WWN.
+
+ * iqn
+ The fabric module targets are using iSCSI-type IQNs.
+
+ * naa
+ NAA SAS address type WWN.
+
+ * unit_serial
+ Disk-type unit serial.
+
+* wwns()
+This function returns an iterable (either generator or list) of valid
+target WWNs for the fabric, if WWNs should be chosen from existing
+fabric interfaces. The most common case for this is hardware-set
+WWNs. This function should return a string with the WWN formatted for
+what the fabric module expects.
+
+* kernel_module
+Sets the name of the kernel module implementing the fabric modules. If not
+specified, it will be assumed to be MODNAME_target_mod, where MODNAME is the
+name of the fabric module, as used to name the spec file. Note that you must
+not specify any .ko or such extension here.
+Example: kernel_module = "my_module"
+
+* configfs_group
+Sets the name of the configfs group used by the fabric module. Defaults to the
+name of the module as used to name the spec file.
+Example: configfs_group = "iscsi"
+
+'''
+
+import os
+from glob import iglob as glob
+from utils import fread
+
+def _colonize(str):
+ '''
+ helper function for the specfiles to add colons every 2 chars
+ '''
+ new_str = ""
+ while str:
+ new_str += str[:2] + ":"
+ str = str[2:]
+ return new_str[:-1]
+
+# ---- Fabric override definitions ----
+
+# Transform 'fe80:0000:0000:0000:0002:1903:000e:8acd' WWN notation to
+# '0xfe8000000000000000021903000e8acd'
+def _srpt_wwns():
+ for wwn_file in glob("/sys/class/infiniband/*/ports/*/gids/0"):
+ yield "0x" + fread(wwn_file).strip(":")
+
+_ib_srpt = dict(features = ("acls",),
+ kernel_module="ib_srpt",
+ configfs_group="srpt",
+ wwns=_srpt_wwns)
+
+
+_iscsi = dict(wwn_type="iqn")
+
+
+_loopback = dict(features=("nexus",),
+ wwn_type = "naa",
+ kernel_module = "tcm_loop")
+
+
+def _qla_wwns():
+ for wwn_file in glob("/sys/class/fc_host/host*/port_name"):
+ yield _colonize(fread(wwn_file)[2:])
+
+_qla2xxx = dict(features=("acls",),
+ kernel_module="tcm_qla2xxx",
+ wwns=_qla_wwns)
+
+
+# We need a single unique value to create the target.
+# Return the first local 1394 device's guid.
+def _sbp_wwns():
+ for fname in glob("/sys/bus/firewire/devices/fw*/is_local"):
+ if bool(int(fread(fname))):
+ guid_path = os.path.dirname(fname) + "/guid"
+ yield fread(guid_path)[2:].strip()
+ break
+
+_sbp = dict(features=(),
+ kernel_module="sbp_target",
+ wwns=_sbp_wwns)
+
+
+# Transform '0x1234567812345678' WWN notation to '12:34:56:78:12:34:56:78'
+def _fc_wwns():
+ for wwn_file in glob("/sys/class/fc_host/host*/port_name"):
+ yield _colonize(fread(wwn_file)[2:])
+
+_tcm_fc = dict(features = ("acls",),
+ kernel_module = "tcm_fc",
+ configfs_group = "fc",
+ wwns=_fc_wwns)
+
+
+_usb_gadget = dict(features=("nexus",),
+ wwn_type="naa",
+ kernel_module="tcm_usb_gadget")
+
+
+# ---- Putting it all together ----
+
+
+# list of tuples containing fabric name and spec overrides, if any
+fabrics = [
+ ("ib_srpt", _ib_srpt),
+ ("iscsi", _iscsi),
+ ("loopback", _loopback),
+ ("qla2xxxx", _qla2xxx),
+ ("sbp", _sbp),
+ ("tcm_fc", _tcm_fc),
+ ("usb_gadget", _usb_gadget),
+ ]
+
+_default_features = ('discovery_auth', 'acls', 'acls_auth', 'nps', 'tpgts')
+_default_wwn_type = 'free'
+
+# Merge defaults and overrides to create actual specfile dict
+specs = {}
+for f_name, f_ovr in fabrics:
+ fabric = {}
+ fabric['features'] = f_ovr.get("features", _default_features)
+ fabric['kernel_module'] = f_ovr.get("kernel_module", "%s_target_mod" % f_name)
+ fabric['configfs_group'] = f_ovr.get("configfs_group", f_name)
+ fabric['wwn_type'] = f_ovr.get("wwn_type", _default_wwn_type)
+ if 'wwns' in f_ovr:
+ fabric['wwn_list'] = list(f_ovr['wwns']())
+ else:
+ fabric['wwn_list'] = None
+
+ specs[f_name] = fabric
diff --git a/rtslib/target.py b/rtslib/target.py
index 01c305a..02f09fd 100644
--- a/rtslib/target.py
+++ b/rtslib/target.py
@@ -30,6 +30,7 @@ from doctest import testmod
from utils import RTSLibError, RTSLibBrokenLink, modprobe
from utils import fread, fwrite, generate_wwn, is_valid_wwn
from utils import dict_remove, set_attributes, set_parameters
+import fabrics
# Where do we store the fabric modules spec files ?
spec_dir = "/var/lib/target/fabric"
@@ -51,9 +52,7 @@ class FabricModule(CFSNode):
@classmethod
def all(cls):
- mod_names = [mod_name[:-5] for mod_name in os.listdir(spec_dir)
- if mod_name.endswith('.spec')]
- for name in mod_names:
+ for name, unused in fabrics.fabrics:
yield FabricModule(name)
@@ -67,7 +66,8 @@ class FabricModule(CFSNode):
'''
super(FabricModule, self).__init__()
self.name = str(name)
- self.spec = self._parse_spec(spec_dir+"/"+name+".spec")
+ self.spec = fabrics.specs[self.name]
+ self.spec_file = "N/A"
self._path = "%s/%s" % (self.configfs_dir,
self.spec['configfs_group'])
# FabricModule public stuff
@@ -87,42 +87,6 @@ class FabricModule(CFSNode):
else:
return False
- def _parse_spec(self, spec_file):
- '''
- Parses the fabric module spec file.
- spec files are in Python, and may use functions defined for
- convenience in 'specfile_funcs' below
- '''
-
- def colonize(str):
- '''
- helper function for the specfiles to add colons every 2 chars
- '''
- new_str = ""
- while str:
- new_str += str[:2] + ":"
- str = str[2:]
- return new_str[:-1]
-
- specfile_funcs = dict(glob=glob.iglob, fread=fread, colonize=colonize)
-
- spec = dict(features=('discovery_auth', 'acls', 'acls_auth', 'nps',
- 'tpgts'),
- kernel_module="%s_target_mod" % self.name,
- configfs_group=self.name,
- wwn_type='free',
- wwn_list=None,
- )
-
- execfile(spec_file, specfile_funcs, spec)
-
- self.spec_file = spec_file
- wwns = spec.get('wwns', None)
- if wwns:
- spec['wwn_list'] = list(wwns())
-
- return spec
-
def _list_targets(self):
if self.exists:
for wwn in os.listdir(self.path):
diff --git a/specs/README b/specs/README
deleted file mode 100644
index aa2c00c..0000000
--- a/specs/README
+++ /dev/null
@@ -1,78 +0,0 @@
-This directory (normally /var/lib/target/fabric) contains the spec files for
-RisingTide Systems's LIO SCSI target subsystem fabric modules.
-
-Each spec file should be named MODULE.spec, where MODULE is the name the fabric
-module is to be referred as.
-
-The spec file is in Python. It defines parameters for rtslib to access the
-fabric if they differ from the defaults.
-
-Available parameters
---------------------
-
-* features
-Lists the target fabric available features. Default value:
-("discovery_auth", "acls", "acls_auth", "nps")
-example: features = ("discovery_auth", "acls", "acls_auth")
-example: features = () # no features supported
-
-Detail of features:
-
- * tpgts
- The target fabric module is using iSCSI-style target portal group tags.
-
- * discovery_auth
- The target fabric module supports a fabric-wide authentication for
- discovery.
-
- * acls
- The target's TPGTs support explicit initiator ACLs.
-
- * acls_auth
- The target's TPGT's ACLs support per-ACL initiator authentication.
-
- * nps
- The TPGTs support iSCSI-like IPv4/IPv6 network portals, using IP:PORT
- group names.
-
- * nexus
- The TPGTs have a 'nexus' attribute that contains the local initiator
- serial unit. This attribute must be set before being able to create any
- LUNs.
-
-* wwn_type
-Sets the type of WWN expected by the target fabric. Defaults to 'free'.
-Example: wwn_type = "iqn"
-Current valid types are:
-
- * free
- Freeform WWN.
-
- * iqn
- The fabric module targets are using iSCSI-type IQNs.
-
- * naa
- NAA SAS address type WWN.
-
- * unit_serial
- Disk-type unit serial.
-
-* wwns()
-This generator function returns valid target WWNs for the fabric, if WWNs
-should be chosen from existing fabric interfaces. The most common case for
-this is hardware-set WWNs. This function should return a string with the
-WWN formatted for what the fabric module expects.
-
-See existing spec files for examples of generator functions.
-
-* kernel_module
-Sets the name of the kernel module implementing the fabric modules. If not
-specified, it will be assumed to be MODULE_target_mod, where MODNAME is the
-name of the fabric module, as used to name the spec file. Note that you must
-not specify any .ko or such extension here.
-Example: kernel_module = "my_module"
-
-* configfs_group
-Sets the name of the configfs group used by the fabric module. Defaults to the
-name of the module as used to name the spec file.
-Example: configfs_group = "iscsi"
diff --git a/specs/example.spec.txt b/specs/example.spec.txt
deleted file mode 100644
index acaca08..0000000
--- a/specs/example.spec.txt
+++ /dev/null
@@ -1,29 +0,0 @@
-# Example LIO target fabric module.
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# The example fabric module uses the default feature set.
-# features = discovery_auth, acls, acls_auth, nps
-
-# This module uses anything as WWNs.
-wwn_type = free
-
-# Convoluted kernel module name. Default would be example_target_mod
-kernel_module = my_complex_kernel_module_name
-
-# The configfs group name. Default would be "example"
-configfs_group = "example_group"
-
diff --git a/specs/ib_srpt.spec b/specs/ib_srpt.spec
deleted file mode 100644
index da80581..0000000
--- a/specs/ib_srpt.spec
+++ /dev/null
@@ -1,32 +0,0 @@
-# The ib_srpt fabric module specfile.
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# The fabric module feature set
-features = ("acls",)
-
-# Non-standard module naming scheme
-kernel_module = "ib_srpt"
-
-# Transform 'fe80:0000:0000:0000:0002:1903:000e:8acd' WWN notation to
-# '0xfe8000000000000000021903000e8acd'
-def wwns():
- for wwn_file in glob("/sys/class/infiniband/*/ports/*/gids/0"):
- yield "0x" + fread(wwn_file).strip(":")
-
-# The configfs group
-configfs_group = "srpt"
-
diff --git a/specs/iscsi.spec b/specs/iscsi.spec
deleted file mode 100644
index 94657b6..0000000
--- a/specs/iscsi.spec
+++ /dev/null
@@ -1,29 +0,0 @@
-# The iscsi fabric module specfile.
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# The iscsi fabric module features set.
-features = ("discovery_auth", "acls", "acls_auth", "nps", "tpgts")
-
-# Obviously, this module uses IQN strings as WWNs.
-wwn_type = "iqn"
-
-# This is default too
-# kernel_module = iscsi_target_mod
-
-# The configfs group name, default too
-# configfs_group = iscsi
-
diff --git a/specs/loopback.spec b/specs/loopback.spec
deleted file mode 100644
index 233ce9c..0000000
--- a/specs/loopback.spec
+++ /dev/null
@@ -1,28 +0,0 @@
-# The tcm_loop fabric module specfile.
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# The fabric module feature set
-features = ("nexus",)
-
-# Use naa WWNs.
-wwn_type = "naa"
-
-# Non-standard module naming scheme
-kernel_module = "tcm_loop"
-
-# The configfs group
-configfs_group = "loopback"
diff --git a/specs/qla2xxx.spec b/specs/qla2xxx.spec
deleted file mode 100644
index afb15ff..0000000
--- a/specs/qla2xxx.spec
+++ /dev/null
@@ -1,26 +0,0 @@
-# The qla2xxx fabric module specfile.
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# The qla2xxx fabric module feature set
-features = ("acls",)
-
-# Non-standard module naming scheme
-kernel_module = "tcm_qla2xxx"
-
-def wwns():
- for wwn_file in glob("/sys/class/fc_host/host*/port_name"):
- yield colonize(fread(wwn_file)[2:])
diff --git a/specs/sbp.spec b/specs/sbp.spec
deleted file mode 100644
index 4ce5846..0000000
--- a/specs/sbp.spec
+++ /dev/null
@@ -1,21 +0,0 @@
-# See README for details on this file's format
-
-# The fabric module feature set
-features = ()
-
-# Non-standard module naming scheme
-kernel_module = "sbp_target"
-
-# We need a single unique value to create the target.
-# Return the first local 1394 device's guid.
-def wwns():
- import os
- for fname in glob("/sys/bus/firewire/devices/fw*/is_local"):
- if bool(int(fread(fname))):
- guid_path = os.path.dirname(fname) + "/guid"
- yield fread(guid_path)[2:].strip()
- break
-
-# The configfs group
-configfs_group = "sbp"
-
diff --git a/specs/tcm_fc.spec b/specs/tcm_fc.spec
deleted file mode 100644
index 11dc050..0000000
--- a/specs/tcm_fc.spec
+++ /dev/null
@@ -1,30 +0,0 @@
-# The tcm_fc fabric module specfile.
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-# The fabric module feature set
-features = ("acls",)
-
-# Non-standard module naming scheme
-kernel_module = "tcm_fc"
-
-# Transform '0x1234567812345678' WWN notation to '12:34:56:78:12:34:56:78'
-def wwns():
- for wwn_file in glob("/sys/class/fc_host/host*/port_name"):
- yield colonize(fread(wwn_file)[2:])
-
-# The configfs group
-configfs_group = "fc"
diff --git a/specs/usb_gadget.spec b/specs/usb_gadget.spec
deleted file mode 100644
index 94f82bf..0000000
--- a/specs/usb_gadget.spec
+++ /dev/null
@@ -1,21 +0,0 @@
-# The USB-gadget fabric module specification
-#
-# This file is part of RTSLib Community Edition.
-# Copyright (c) 2011 by RisingTide Systems LLC
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as
-# published by the Free Software Foundation, version 3 (AGPLv3).
-#
-# 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 Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-features = ("nexus",)
-wwn_type = "naa"
-kernel_module = "tcm_usb_gadget"
-configfs_group = "usb_gadget"