Skip to content
Snippets Groups Projects
Commit 31d82d1b authored by Christoph Hellwig's avatar Christoph Hellwig
Browse files

nvmet: improve enable semantics


Allow for a None state of the _enable variable, and use that fact to
automatically set up the enabled state in the primary Node class.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 64946077
No related branches found
No related tags found
No related merge requests found
...@@ -50,7 +50,7 @@ class CFSNode(object): ...@@ -50,7 +50,7 @@ class CFSNode(object):
def __init__(self): def __init__(self):
self._path = self.configfs_dir self._path = self.configfs_dir
self._enable = 0 self._enable = None
self.attr_groups = [] self.attr_groups = []
def __eq__(self, other): def __eq__(self, other):
...@@ -85,6 +85,7 @@ class CFSNode(object): ...@@ -85,6 +85,7 @@ class CFSNode(object):
except: except:
raise CFSError("Could not create %s in configFS" % raise CFSError("Could not create %s in configFS" %
self.__class__.__name__) self.__class__.__name__)
self.get_enable()
def _exists(self): def _exists(self):
return os.path.isdir(self.path) return os.path.isdir(self.path)
...@@ -138,7 +139,7 @@ class CFSNode(object): ...@@ -138,7 +139,7 @@ class CFSNode(object):
if not os.path.isfile(path): if not os.path.isfile(path):
raise CFSError("Cannot find attribute: %s" % path) raise CFSError("Cannot find attribute: %s" % path)
if self._enable > 0: if self._enable:
raise CFSError("Cannot set attribute while %s is enabled" % raise CFSError("Cannot set attribute while %s is enabled" %
self.__class__.__name__) self.__class__.__name__)
...@@ -167,7 +168,7 @@ class CFSNode(object): ...@@ -167,7 +168,7 @@ class CFSNode(object):
self._check_self() self._check_self()
path = "%s/enable" % self.path path = "%s/enable" % self.path
if not os.path.isfile(path): if not os.path.isfile(path):
return False return None
with open(path, 'r') as file_fd: with open(path, 'r') as file_fd:
self._enable = int(file_fd.read().strip()) self._enable = int(file_fd.read().strip())
...@@ -177,14 +178,14 @@ class CFSNode(object): ...@@ -177,14 +178,14 @@ class CFSNode(object):
self._check_self() self._check_self()
path = "%s/enable" % self.path path = "%s/enable" % self.path
if not os.path.isfile(path): if not os.path.isfile(path) or self._enable is None:
raise CFSError("Cannot enable %s" % self.path) raise CFSError("Cannot enable %s" % self.path)
try: try:
with open(path, 'w') as file_fd: with open(path, 'w') as file_fd:
file_fd.write(str(value)) file_fd.write(str(value))
except Exception as e: except Exception as e:
raise CFSError("Cannot enable attribute %s: %s (%s)" % raise CFSError("Cannot enable %s: %s (%s)" %
(self.path, e, value)) (self.path, e, value))
self._enable = value self._enable = value
...@@ -479,7 +480,6 @@ class Namespace(CFSNode): ...@@ -479,7 +480,6 @@ class Namespace(CFSNode):
self._nsid = nsid self._nsid = nsid
self._path = "%s/namespaces/%d" % (self.subsystem.path, self.nsid) self._path = "%s/namespaces/%d" % (self.subsystem.path, self.nsid)
self._create_in_cfs(mode) self._create_in_cfs(mode)
self.get_enable() # XXX should move to baseclass
def _get_subsystem(self): def _get_subsystem(self):
return self._subsystem return self._subsystem
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment