Skip to content

Commit

Permalink
Merge d527dbc into dd36c65
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSymsCtx committed Jun 1, 2020
2 parents dd36c65 + d527dbc commit 8e847f2
Show file tree
Hide file tree
Showing 2 changed files with 650 additions and 55 deletions.
70 changes: 17 additions & 53 deletions drivers/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ def __getattr__(self, key):
if self.info.has_key(key): return self.info[key]
return object.__getattribute__(self, key)

@property
def has_status(self):
return 'status' in self.info

@property
def has_signal(self):
return 'signal' in self.info

# Retrieves the error code returned by the command. If the error code
# was not supplied at object-construction time, zero is returned.
def get_error_code(self):
Expand All @@ -185,55 +193,6 @@ def _mkcmd(cls, args):

return __next_mkcmd(args)

@classmethod
def failwith(cls, status, prev=False):
"""
Fail next invocation with @status. If @prev is true, execute
the original command
"""

__prev_mkcmd = cls.__next_mkcmd

@classmethod
def __mkcmd(cls, args):
if prev:
cmd = __prev_mkcmd(args)
cmd = "'%s' && exit %d" % ("' '".join(cmd), status)
else:
cmd = "exit %d" % status

return [ '/bin/sh', '-c', cmd ]

cls.__next_mkcmd = __mkcmd

__strace_n = 0

@classmethod
def strace(cls):
"""
Run next invocation through strace.
Output goes to /tmp/tap-ctl.<sm-pid>.<n>; <n> counts invocations.
"""

__prev_mkcmd = cls.__next_mkcmd

@classmethod
def __next_mkcmd(cls, args):

# pylint: disable = E1101

cmd = __prev_mkcmd(args)

tracefile = "/tmp/%s.%d.%d" % (os.path.basename(cls.PATH),
os.getpid(),
cls.__strace_n)
cls.__strace_n += 1

return \
[ '/usr/bin/strace', '-o', tracefile, '--'] + cmd

cls.__next_mkcmd = __next_mkcmd

@classmethod
def _call(cls, args, quiet = False, input = None):
"""
Expand Down Expand Up @@ -351,7 +310,7 @@ def list(cls, **args):

except cls.CommandFailure, e:
transient = [ errno.EPROTO, errno.ENOENT ]
if e.status in transient:
if e.has_status and e.status in transient:
raise RetryLoop.TransientFailure(e)
raise

Expand Down Expand Up @@ -389,6 +348,12 @@ def detach(cls, pid, minor):
args = [ "detach", "-p", pid, "-m", minor ]
cls._pread(args)

@classmethod
def _load_key(cls, key_hash, vdi_uuid):
import plugins

return plugins.load_key(key_hash, vdi_uuid)

@classmethod
def open(cls, pid, minor, _type, _file, options):
params = Tapdisk.Arg(_type, _file)
Expand All @@ -414,11 +379,10 @@ def open(cls, pid, minor, _type, _file, options):
if options.get('cbtlog'):
args.extend(['-C', options['cbtlog']])
if options.get('key_hash'):
import plugins

key_hash = options['key_hash']
vdi_uuid = options['vdi_uuid']
key = plugins.load_key(key_hash, vdi_uuid)
key = cls._load_key(key_hash, vdi_uuid)

if not key:
raise util.SMException("No key found with key hash {}".format(key_hash))
input = key
Expand Down

0 comments on commit 8e847f2

Please sign in to comment.