debuggers.hg

view tools/python/xen/xend/server/blkif.py @ 10988:353404fe850c

[xend] Fix reboot for hvm domains with cdrom devices.
The device-type was not added to the device details which caused
cdrom devices to appear as harddisks after a reboot.

From: Alex Brett <Alex.Brett@xensource.com>
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Mon Aug 07 11:59:31 2006 +0100 (2006-08-07)
parents 4c2fab8f8c34
children ff124973a28a
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.util import security
25 from xen.xend import sxp
26 from xen.xend.XendError import VmError
28 from xen.xend.server.DevController import DevController
31 class BlkifController(DevController):
32 """Block device interface controller. Handles all block devices
33 for a domain.
34 """
36 def __init__(self, vm):
37 """Create a block device controller.
38 """
39 DevController.__init__(self, vm)
42 def getDeviceDetails(self, config):
43 """@see DevController.getDeviceDetails"""
44 uname = sxp.child_value(config, 'uname')
46 dev = sxp.child_value(config, 'dev')
48 if 'ioemu:' in dev:
49 (_, dev) = string.split(dev, ':', 1)
50 try:
51 (dev, dev_type) = string.split(dev, ':', 1)
52 except ValueError:
53 dev_type = "disk"
55 try:
56 (typ, params) = string.split(uname, ':', 1)
57 except ValueError:
58 (typ, params) = ("", "")
59 back = { 'dev' : dev,
60 'type' : typ,
61 'params' : params,
62 'mode' : sxp.child_value(config, 'mode', 'r')
63 }
65 if security.on():
66 (label, ssidref, policy) = security.get_res_security_details(uname)
67 back.update({'acm_label' : label,
68 'acm_ssidref': str(ssidref),
69 'acm_policy' : policy})
71 devid = blkif.blkdev_name_to_number(dev)
72 front = { 'virtual-device' : "%i" % devid,
73 'device-type' : dev_type
74 }
76 return (devid, back, front)
79 def configuration(self, devid):
80 """@see DevController.configuration"""
82 result = DevController.configuration(self, devid)
84 (dev, typ, params, mode) = self.readBackend(devid,
85 'dev', 'type', 'params',
86 'mode')
88 if dev:
89 (dev_type) = self.readFrontend(devid, 'device-type')
90 if dev_type:
91 dev += ":" + dev_type
92 result.append(['dev', dev])
93 if typ and params:
94 result.append(['uname', typ + ":" + params])
95 if mode:
96 result.append(['mode', mode])
98 return result
101 def destroyDevice(self, devid):
102 """@see DevController.destroyDevice"""
104 # If we are given a device name, then look up the device ID from it,
105 # and destroy that ID instead. If what we are given is an integer,
106 # then assume it's a device ID and pass it straight through to our
107 # superclass's method.
109 try:
110 DevController.destroyDevice(self, int(devid))
111 except ValueError:
112 devid_end = type(devid) is str and devid.split('/')[-1] or None
114 for i in self.deviceIDs():
115 d = self.readBackend(i, 'dev')
116 if d == devid or (devid_end and d == devid_end):
117 DevController.destroyDevice(self, i)
118 return
119 raise VmError("Device %s not connected" % devid)