[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] xen: handle TapdiskException when add device failed



From 367b54c018885d5a72bf7d5e76b71516d0342aec Mon Sep 17 00:00:00 2001
From: Yi Li <peteryili@xxxxxxxxxxx>
Date: Thu, 20 Mar 2014 21:52:05 +0800
Subject: [PATCH v3] xen: remove TapdiskException when add device

using the VmError instead of TapdiskException when add device
and check the args when using xm block-attach

Signed-off-by: Yi Li <peteryili@xxxxxxxxxxx>
---
Âtools/python/xen/xend/server/BlktapController.py |ÂÂÂ 5 +----
Âtools/python/xen/xm/main.pyÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |ÂÂ 12 ++++++++++++
Â2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/tools/python/xen/xend/server/BlktapController.py b/tools/python/xen/xend/server/BlktapController.py
index 60079eb..c8e5e24 100644
--- a/tools/python/xen/xend/server/BlktapController.py
+++ b/tools/python/xen/xend/server/BlktapController.py
@@ -198,9 +198,6 @@ class Blktap2Controller(BlktapController):
ÂÂÂÂÂÂÂÂ self.waitForBackend_destroy(backpath)
ÂÂÂÂÂÂÂÂ TapdiskController.destroy(path)
Â
-class TapdiskException(Exception):
-ÂÂÂ pass
-
Âclass TapdiskController(object):
ÂÂÂÂ '''class which encapsulates all tapdisk control operations'''
Â
@@ -229,7 +226,7 @@ class TapdiskController(object):
ÂÂÂÂÂÂÂÂ stdout.close()
ÂÂÂÂÂÂÂÂ stderr.close()
ÂÂÂÂÂÂÂÂ if rc:
-ÂÂÂÂÂÂÂÂÂÂÂ raise TapdiskException('%s failed (%s %s %s)' % \
+ÂÂÂÂÂÂÂÂÂÂÂ raise VmError('%s failed (%s %s %s)' % \
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ (args, rc, out, err))
ÂÂÂÂÂÂÂÂ return out
Â
diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py
index 5ed781c..ce5d9a2 100644
--- a/tools/python/xen/xm/main.py
+++ b/tools/python/xen/xm/main.py
@@ -2650,6 +2650,18 @@ def parse_block_configuration(args):
Âdef xm_block_attach(args):
ÂÂÂÂ arg_check(args, 'block-attach', 4, 5)
Â
+ÂÂÂ uname = args[1]
+ÂÂÂ uname_list = uname.split(":")
+ÂÂÂ back_dev = uname_list[len(uname_list)-1]
+ÂÂÂ front_dev = args[2]
+ÂÂÂ if not os.path.exists(back_dev):
+ÂÂÂÂÂÂÂ print "Error: %s not exist " % back_dev
+ÂÂÂÂÂÂÂ sys.exit(1)
+
+ÂÂÂ if os.path.exists(front_dev):
+ÂÂÂÂÂÂÂ print "Error: %s already exists " % front_dev
+ÂÂÂÂÂÂÂ sys.exit(1)
+
ÂÂÂÂ if serverType == SERVER_XEN_API:
ÂÂÂÂÂÂÂÂ domÂÂ = args[0]
ÂÂÂÂÂÂÂÂ uname = args[1]
--
1.7.1


2014-03-20 20:13 GMT+08:00 æä <yilikernel@xxxxxxxxx>:
From 2098e71261cf6a8b65524033f321d80a4f70c29d Mon Sep 17 00:00:00 2001
From: Yi Li <peteryili@xxxxxxxxxxx>
Date: Thu, 20 Mar 2014 19:55:10 +0800

Subject: [PATCH] xen: handle TapdiskException when add device failed

handle the TapdiskException when add device
and check the args when using xm block-attach
Signed-off-by: Yi Li <peteryili@xxxxxxxxxxx>
---
Âtools/python/xen/xend/XendDomainInfo.py | Â Â4 ++--
Âtools/python/xen/xm/main.py       |  12 ++++++++++++
Â2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py
index 8d4ff5c..2270ab1 100644
--- a/tools/python/xen/xend/XendDomainInfo.py
+++ b/tools/python/xen/xend/XendDomainInfo.py
@@ -65,7 +65,7 @@ from xen.xend.XendConstants import *
Âfrom xen.xend.XendAPIConstants import *
Âfrom xen.xend.XendCPUPool import XendCPUPool
Âfrom xen.xend.server.DevConstants import xenbusState
-from xen.xend.server.BlktapController import TapdiskController
+from xen.xend.server.BlktapController import TapdiskController, TapdiskException
Â
Âfrom xen.xend.XendVMMetrics import XendVMMetrics
Â
@@ -861,7 +861,7 @@ class XendDomainInfo:
          Â# blktap1
          Âdev_type = self.getBlockDeviceClass(devid)
        Âself._waitForDevice(dev_type, devid)
- Â Â Â Â Â Âexcept VmError, ex:
+ Â Â Â Â Â Âexcept (VmError, TapdiskException), ex:
        Âdel self.info['devices'][dev_uuid]
        Âif dev_type == 'pci':
          Âfor dev in dev_config_dict['devs']:
diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py
index 5ed781c..ce5d9a2 100644

--- a/tools/python/xen/xm/main.py
+++ b/tools/python/xen/xm/main.py
@@ -2650,6 +2650,18 @@ def parse_block_configuration(args):
Âdef xm_block_attach(args):
  Âarg_check(args, 'block-attach', 4, 5)
Â
+ Â Âuname = args[1]
+ Â Âuname_list = uname.split(":")
+ Â Âback_dev = uname_list[len(uname_list)-1]
+ Â Âfront_dev = args[2]
+ Â Âif not os.path.exists(back_dev):
+ Â Â Â Âprint "Error: %s not exist " % back_dev
+ Â Â Â Âsys.exit(1)
+
+ Â Âif os.path.exists(front_dev):
+ Â Â Â Âprint "Error: %s already exists " % front_dev
+ Â Â Â Âsys.exit(1)
+
  Âif serverType == SERVER_XEN_API:
    Âdom  = args[0]
    Âuname = args[1]
--
1.7.1


2014-03-20 19:38 GMT+08:00 Wei Liu <wei.liu2@xxxxxxxxxx>:

On Thu, Mar 20, 2014 at 06:36:54PM +0800, æä wrote:
> >From 79220a11ce64324228ba0390790773b41bf5f156 Mon Sep 17 00:00:00 2001
> From: Yi Li <peteryili@xxxxxxxxxxx>
> Date: Thu, 20 Mar 2014 18:25:03 +0800
> Subject: [PATCH] xen: handle TapdiskException when add device failed
>
> handle the TapdiskException when add device
> and check the args when using xm block-attach
>
> Signed-off-by: Yi Li <peteryili@xxxxxxxxxxx>
> ---
> Âtools/python/xen/xend/XendDomainInfo.py | Â Â4 ++--
> Âtools/python/xen/xm/main.py       |  12 ++++++++++++
> Â2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/tools/python/xen/xend/XendDomainInfo.py
> b/tools/python/xen/xend/XendDomainInfo.py
> index 8d4ff5c..2270ab1 100644
> --- a/tools/python/xen/xend/XendDomainInfo.py
> +++ b/tools/python/xen/xend/XendDomainInfo.py
> @@ -65,7 +65,7 @@ from xen.xend.XendConstants import *
> Âfrom xen.xend.XendAPIConstants import *
> Âfrom xen.xend.XendCPUPool import XendCPUPool
> Âfrom xen.xend.server.DevConstants import xenbusState
> -from xen.xend.server.BlktapController import TapdiskController
> +from xen.xend.server.BlktapController import TapdiskController,
> TapdiskException
>

This line is wrapped by your email client.

> Âfrom xen.xend.XendVMMetrics import XendVMMetrics
>
> @@ -861,7 +861,7 @@ class XendDomainInfo:
> Â Â Â Â Â Â Â Â Â Â Â# blktap1
> Â Â Â Â Â Â Â Â Â Â Âdev_type = self.getBlockDeviceClass(devid)
> Â Â Â Â Â Â Â Â Âself._waitForDevice(dev_type, devid)
> - Â Â Â Â Â Âexcept VmError, ex:
> + Â Â Â Â Â Âexcept (VmError, TapdiskException), ex:
> Â Â Â Â Â Â Â Â Âdel self.info['devices'][dev_uuid]
> Â Â Â Â Â Â Â Â Âif dev_type == 'pci':
> Â Â Â Â Â Â Â Â Â Â Âfor dev in dev_config_dict['devs']:
> diff --git a/tools/python/xen/xm/main.py b/tools/python/xen/xm/main.py
> index 5ed781c..d28fb68 100644
> --- a/tools/python/xen/xm/main.py
> +++ b/tools/python/xen/xm/main.py
> @@ -2650,6 +2650,18 @@ def parse_block_configuration(args):
> Âdef xm_block_attach(args):
> Â Â Âarg_check(args, 'block-attach', 4, 5)
>
> + Â Âuname=args[1]
> + Â Âuname_list=uname.split(":")
> + Â Âback_dev=uname_list[len(uname_list)-1]
> + Â Âfront_dev=args[2] if ("/dev" in args[2]) else ("/dev/" + args[2])

Coding style: need space between "=".

And hardcoding a path in code is not very good practice. Further more
what's the rationale to restrict everything in "/dev"? Isn't the most
rationale thing to do is for user to use the exact path he / she
provides?

> + Â Âif not os.path.exists(back_dev):
> + Â Â Â Âprint "Error: %s not exist " % back_dev
> + Â Â Â Âsys.exit(1)
> +
> + Â Âif os.path.exists(front_dev):
> + Â Â Â Âprint "Error: %s already exists " % front_dev
> + Â Â Â Âsys.exit(1)
> +
> Â Â Âif serverType == SERVER_XEN_API:
>     Âdom  = args[0]
> Â Â Â Â Âuname = args[1]
> --
> 1.7.1


> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxx
> http://lists.xen.org/xen-devel



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.