From: yili <yilikernel@gmail.com>
To: Xen-devel@lists.xen.org
Cc: yili <yilikernel@gmail.com>, Yi Li <peteryili@tencent.com>
Subject: [PATCH][1] xend: avoid tapdisk2 not exit for tap-ctl list failed
Date: Mon, 24 Mar 2014 08:42:52 -0400 [thread overview]
Message-ID: <1395664972-9743-1-git-send-email-yilikernel@gmail.com> (raw)
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
reply other threads:[~2014-03-24 12:42 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1395664972-9743-1-git-send-email-yilikernel@gmail.com \
--to=yilikernel@gmail.com \
--cc=Xen-devel@lists.xen.org \
--cc=peteryili@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).