ia64/xen-unstable

view tools/python/xen/xend/server/blkif.py @ 9120:4e7c8eae6775

This patch undoes 8697 and makes xm reboot/shutdown work again. This code
does expose a bug in xenstored when it is killed & restarted, but that
is not caused by this code.

My sincere appology to Ke Yu for the long wait and assuming his code
was broken. His code was perfectly fine. Its just that my test scripts
did something for a historical reason that I should have removed a long
time ago.

Signed-Off-By: Leendert van Doorn <leendert@watson.ibm.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Mar 03 10:56:54 2006 +0100 (2006-03-03)
parents 11ed48af31d7
children 25c6ea6d4024
line source
1 #============================================================================
2 # This library is free software; you can redistribute it and/or
3 # modify it under the terms of version 2.1 of the GNU Lesser General Public
4 # License as published by the Free Software Foundation.
5 #
6 # This library is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9 # Lesser General Public License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with this library; if not, write to the Free Software
13 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
14 #============================================================================
15 # Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com>
16 # Copyright (C) 2005 XenSource Ltd
17 #============================================================================
20 import re
21 import string
23 from xen.util import blkif
24 from xen.xend import sxp
25 from xen.xend.XendError import VmError
27 from xen.xend.server.DevController import DevController
30 class BlkifController(DevController):
31 """Block device interface controller. Handles all block devices
32 for a domain.
33 """
35 def __init__(self, vm):
36 """Create a block device controller.
37 """
38 DevController.__init__(self, vm)
41 def getDeviceDetails(self, config):
42 """@see DevController.getDeviceDetails"""
44 dev = sxp.child_value(config, 'dev')
46 (typ, params) = string.split(sxp.child_value(config, 'uname'), ':', 1)
47 back = { 'dev' : dev,
48 'type' : typ,
49 'params' : params,
50 'mode' : sxp.child_value(config, 'mode', 'r')
51 }
53 if 'ioemu:' in dev:
54 (dummy, dev1) = string.split(dev, ':', 1)
55 devid = blkif.blkdev_name_to_number(dev1)
56 front = {}
57 else:
58 devid = blkif.blkdev_name_to_number(dev)
59 front = { 'virtual-device' : "%i" % devid }
61 return (devid, back, front)
64 def configuration(self, devid):
65 """@see DevController.configuration"""
67 result = DevController.configuration(self, devid)
69 (dev, typ, params, mode) = self.readBackend(devid,
70 'dev', 'type', 'params',
71 'mode')
73 if dev:
74 result.append(['dev', dev])
75 if typ and params:
76 result.append(['uname', typ + ":" + params])
77 if mode:
78 result.append(['mode', mode])
80 return result
83 def destroyDevice(self, devid):
84 """@see DevController.destroyDevice"""
86 # If we are given a device name, then look up the device ID from it,
87 # and destroy that ID instead. If what we are given is an integer,
88 # then assume it's a device ID and pass it straight through to our
89 # superclass's method.
91 try:
92 DevController.destroyDevice(self, int(devid))
93 except ValueError:
94 devid_end = type(devid) is str and devid.split('/')[-1] or None
96 for i in self.deviceIDs():
97 d = self.readBackend(i, 'dev')
98 if d == devid or (devid_end and d == devid_end):
99 DevController.destroyDevice(self, i)
100 return
101 raise VmError("Device %s not connected" % devid)