diff options
author | Andy Grover <agrover@redhat.com> | 2014-10-01 15:01:21 -0700 |
---|---|---|
committer | Andy Grover <agrover@redhat.com> | 2014-10-01 15:01:21 -0700 |
commit | 609bd9ed763d447af4bb050eedbaa777e8e672f7 (patch) | |
tree | 2ed497fce44fdb5a9529f8873725165bff57fa74 | |
parent | a020fbadfe530bc0773b73501c2cee420c435f87 (diff) | |
download | rtslib-fb-609bd9ed763d447af4bb050eedbaa777e8e672f7.tar.gz |
Support tcm-user
Support defining user-backed storage objects.
Signed-off-by: Andy Grover <agrover@redhat.com>
-rw-r--r-- | rtslib/__init__.py | 2 | ||||
-rw-r--r-- | rtslib/tcm.py | 88 |
2 files changed, 89 insertions, 1 deletions
diff --git a/rtslib/__init__.py b/rtslib/__init__.py index b643eab..72d3067 100644 --- a/rtslib/__init__.py +++ b/rtslib/__init__.py @@ -24,7 +24,7 @@ from target import NodeACL, NetworkPortal, TPG, Target from fabric import FabricModule from tcm import FileIOStorageObject, BlockStorageObject -from tcm import PSCSIStorageObject, RDMCPStorageObject +from tcm import PSCSIStorageObject, RDMCPStorageObject, UserBackedStorageObject from tcm import StorageObjectFactory __version__ = 'GIT_VERSION' diff --git a/rtslib/tcm.py b/rtslib/tcm.py index c3cb43a..0861ae6 100644 --- a/rtslib/tcm.py +++ b/rtslib/tcm.py @@ -733,6 +733,92 @@ class BlockStorageObject(StorageObject): return d +class UserBackedStorageObject(StorageObject): + ''' + An interface to configFS storage objects for userspace-backed backstore. + ''' + + def __init__(self, name, config=None, level=None, size=None, wwn=None): + ''' + @param name: The name of the UserBackedStorageObject. + @type name: string + @param dev: The path to the backend block device to be used. + - Example: I{dev="/dev/sda"}. + - The only device type that is accepted I{TYPE_DISK}. + For other device types, use pscsi. + @type dev: string + @param size: The size of the device to create, in bytes. + @type size: int + @param config: user-handler-specific config string. + - e.g. "rbd/machine1@snap4" + @type config: string + @param level: TCMU emulation level, 0 or 1. Level 0 will pass all SCSI + commands, 1 will just pass I/O commands, READ, WRITE, etc. + @type level: int + @return: A UserBackedStorageObject object. + ''' + + if size is not None: + if level is None or config is None: + raise RTSLibError("'size', 'level', and 'config' must be set when " + "creating a new UserBackedStorageObject.") + if '/' not in config: + raise RTSLibError("'config' must contain a '/' separating subtype " + "from its configuration string") + super(UserBackedStorageObject, self).__init__(name, 'create') + try: + self._configure(config, level, size, wwn) + except: + self.delete() + raise + else: + super(UserBackedStorageObject, self).__init__(name, 'lookup') + + def _configure(self, config, level, size, wwn): + self._check_self() + + if ':' in config: + raise RTSLibError("':' not allowed in config string") + if level not in (0, 1): + raise RTSLibError("Current allowable levels are 0 or 1") + self._control("dev_config=%s" % config) + self._control("pass_level=%d" % level) + self._control("dev_size=%d" % size) + self._enable() + + super(UserBackedStorageObject, self)._configure(wwn) + + def _get_size(self): + self._check_self() + return int(self._parse_info('Size')) + + def _get_level(self): + self._check_self() + return int(self._parse_info('PassLevel')) + + def _get_config(self): + self._check_self() + val = self._parse_info('Config') + if val == "NULL": + return None + return val + + size = property(_get_size, + doc="Get the size in bytes.") + level = property(_get_level, + doc="Get the command emulation level.") + config = property(_get_config, + doc="Get the TCMU config.") + + def dump(self): + d = super(UserBackedStorageObject, self).dump() + d['wwn'] = self.wwn + d['size'] = self.size + d['level'] = self.level + d['config'] = self.config + return d + + class StorageObjectFactory(object): """ Create a storage object based on a given path. @@ -761,6 +847,7 @@ so_mapping = { "fileio": FileIOStorageObject, "iblock": BlockStorageObject, "block": BlockStorageObject, + "user": UserBackedStorageObject, } @@ -769,6 +856,7 @@ bs_params = { RDMCPStorageObject: dict(name='ramdisk', alt_dirprefix='rd_mcp'), FileIOStorageObject: dict(name='fileio'), BlockStorageObject: dict(name='block', alt_dirprefix='iblock'), + UserBackedStorageObject: dict(name='user'), } bs_cache = {} |