* [PATCH][1] xend: avoid tapdisk2 not exit for tap-ctl list failed
@ 2014-03-24 12:42 yili
0 siblings, 0 replies; only message in thread
From: yili @ 2014-03-24 12:42 UTC (permalink / raw)
To: Xen-devel; +Cc: yili, Yi Li
Process a is closing tapdisk2 for vm1.
Process b is starting to close vm2.
Process b maybe cannot get the tapdisk info of vm2 using tap-ctl list.
Signed-off-by: Yi Li <peteryili@tencent.com>
---
tools/python/xen/xend/server/BlktapController.py | 31 ++++++++++++++++++++----
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/tools/python/xen/xend/server/BlktapController.py b/tools/python/xen/xend/server/BlktapController.py
index 60079eb..0bff247 100644
--- a/tools/python/xen/xend/server/BlktapController.py
+++ b/tools/python/xen/xend/server/BlktapController.py
@@ -206,6 +206,8 @@ class TapdiskController(object):
TAP_CTL = 'tap-ctl'
TAP_DEV = '/dev/xen/blktap-2/tapdev'
+ TAPDISK_SYSFS = '/sys/class/blktap2'
+ TAPDISK_CONTROL = TAPDISK_SYSFS + '/blktap'
class Tapdisk(object):
def __init__(self, pid=None, minor=-1, state=None,
@@ -274,11 +276,30 @@ class TapdiskController(object):
@staticmethod
def fromDevice(device):
if device.startswith(TapdiskController.TAP_DEV):
- minor = os.minor(os.stat(device).st_rdev)
- tapdisks = filter(lambda x: x.minor == minor,
- TapdiskController.list())
- if len(tapdisks) == 1:
- return tapdisks[0]
+ tapdisk = TapdiskController.Tapdisk()
+ pattern = re.compile(TapdiskController.TAP_DEV + '(\d+)$')
+ groups = pattern.search(device)
+ if not groups:
+ raise Exception, 'malformed tap device: ' + device
+ minor = groups.group(1)
+ control = TapdiskController.TAPDISK_CONTROL + minor
+
+ tapdisk.minor = int(minor)
+ if tapdisk.minor >= 0:
+ tapdisk.device = '%s%s' % \
+ (TapdiskController.TAP_DEV, tapdisk.minor)
+
+ pid_file = open(control + '/task')
+ tapdisk.pid = int(pid_file.readline())
+ pid_file.close()
+
+ args_file = open(control + '/name')
+ value = args_file.readline()
+ args_file.close()
+ if value.find(':') != -1:
+ tapdisk.dtype, tapdisk.image = value.split(':', 1)
+
+ return tapdisk
return None
@staticmethod
--
1.7.12.4
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2014-03-24 12:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-24 12:42 [PATCH][1] xend: avoid tapdisk2 not exit for tap-ctl list failed yili
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).