ia64/xen-unstable
changeset 18720:5c48ab6b1977
Fix xm scsi-attach/detach/list for inactive managed domains
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
Signed-off-by: Masaki Kanno <kanno.masaki@jp.fujitsu.com>
author | Keir Fraser <keir.fraser@citrix.com> |
---|---|
date | Mon Oct 27 10:03:17 2008 +0000 (2008-10-27) |
parents | 874d0d673ecb |
children | c3362551a424 |
files | tools/python/xen/util/diagnose.py tools/python/xen/xend/XendConfig.py tools/python/xen/xend/XendDomainInfo.py tools/python/xen/xend/server/DevConstants.py tools/python/xen/xend/server/DevController.py tools/python/xen/xend/server/pciif.py tools/python/xen/xend/server/vscsiif.py tools/python/xen/xm/create.py tools/python/xen/xm/main.py |
line diff
1.1 --- a/tools/python/xen/util/diagnose.py Thu Oct 23 15:38:52 2008 +0100 1.2 +++ b/tools/python/xen/util/diagnose.py Mon Oct 27 10:03:17 2008 +0000 1.3 @@ -23,7 +23,7 @@ from xen.xend import sxp 1.4 from xen.xend.XendClient import server 1.5 from xen.xend.XendError import XendError 1.6 from xen.xend.xenstore.xstransact import xstransact 1.7 -from xen.xend.server import DevController 1.8 +from xen.xend.server import DevConstants 1.9 1.10 import xen.xend.XendProtocol 1.11 1.12 @@ -169,7 +169,7 @@ def diagnose_hotplugging(): 1.13 1.14 1.15 def stateString(state): 1.16 - return state and DevController.xenbusState[int(state)] or '<None>' 1.17 + return state and DevConstants.xenbusState[int(state)] or '<None>' 1.18 1.19 1.20 def main(argv = None):
2.1 --- a/tools/python/xen/xend/XendConfig.py Thu Oct 23 15:38:52 2008 +0100 2.2 +++ b/tools/python/xen/xend/XendConfig.py Mon Oct 27 10:03:17 2008 +0000 2.3 @@ -1602,21 +1602,21 @@ class XendConfig(dict): 2.4 # [vscsi, 2.5 # [dev, 2.6 # [devid, 0], [p-devname, sdb], [p-dev, 1:0:0:1], 2.7 - # [v-dev, 0:0:0:0], [state, Initialising] 2.8 + # [v-dev, 0:0:0:0], [state, 1] 2.9 # ], 2.10 # [dev, 2.11 # [devid, 0], [p-devname, sdc], [p-dev, 1:0:0:2], 2.12 - # [v-dev, 0:0:0:1], [satet, Initialising] 2.13 + # [v-dev, 0:0:0:1], [satet, 1] 2.14 # ] 2.15 # ], 2.16 # [vscsi, 2.17 # [dev, 2.18 # [devid, 1], [p-devname, sdg], [p-dev, 2:0:0:0], 2.19 - # [v-dev, 1:0:0:0], [state, Initialising] 2.20 + # [v-dev, 1:0:0:0], [state, 1] 2.21 # ], 2.22 # [dev, 2.23 # [devid, 1], [p-devname, sdh], [p-dev, 2:0:0:1], 2.24 - # [v-dev, 1:0:0:1], [satet, Initialising] 2.25 + # [v-dev, 1:0:0:1], [satet, 1] 2.26 # ] 2.27 # ] 2.28 # ] 2.29 @@ -1632,18 +1632,19 @@ class XendConfig(dict): 2.30 # [vscsi, 2.31 # [dev, 2.32 # [devid, 0], [p-devname, sdd], [p-dev, 1:0:0:3], 2.33 - # [v-dev, 0:0:0:2], [state, Initialising] 2.34 + # [v-dev, 0:0:0:2], [state, 1] 2.35 # ] 2.36 # ] 2.37 # ] 2.38 # 2.39 - # state 'Initialising' indicates that the device is being attached, 2.40 - # while state 'Closing' indicates that the device is being detached. 2.41 + # state xenbusState['Initialising'] indicates that the device is 2.42 + # being attached, while state xenbusState['Closing'] indicates 2.43 + # that the device is being detached. 2.44 # 2.45 # The Dict looks like this: 2.46 # 2.47 # { devs: [ {devid: 0, p-devname: sdd, p-dev: 1:0:0:3, 2.48 - # v-dev: 0:0:0:2, state: Initialising} ] } 2.49 + # v-dev: 0:0:0:2, state: 1} ] } 2.50 2.51 dev_config = {} 2.52
3.1 --- a/tools/python/xen/xend/XendDomainInfo.py Thu Oct 23 15:38:52 2008 +0100 3.2 +++ b/tools/python/xen/xend/XendDomainInfo.py Mon Oct 27 10:03:17 2008 +0000 3.3 @@ -52,6 +52,7 @@ from xen.xend.xenstore.xsutil import Get 3.4 from xen.xend.xenstore.xswatch import xswatch 3.5 from xen.xend.XendConstants import * 3.6 from xen.xend.XendAPIConstants import * 3.7 +from xen.xend.server.DevConstants import xenbusState 3.8 3.9 from xen.xend.XendVMMetrics import XendVMMetrics 3.10 3.11 @@ -797,7 +798,7 @@ class XendDomainInfo: 3.12 existing_dev_info = self._getDeviceInfo_vscsi(req_devid, dev['v-dev']) 3.13 state = dev['state'] 3.14 3.15 - if state == 'Initialising': 3.16 + if state == xenbusState['Initialising']: 3.17 # new create 3.18 # If request devid does not exist, create and exit. 3.19 if existing_dev_info is None: 3.20 @@ -806,25 +807,48 @@ class XendDomainInfo: 3.21 elif existing_dev_info == "exists": 3.22 raise XendError("The virtual device %s is already defined" % dev['v-dev']) 3.23 3.24 - elif state == 'Closing': 3.25 + elif state == xenbusState['Closing']: 3.26 if existing_dev_info is None: 3.27 raise XendError("Cannot detach vscsi device does not exist") 3.28 3.29 - # use DevController.reconfigureDevice to change device config 3.30 - dev_control = self.getDeviceController(dev_class) 3.31 - dev_uuid = dev_control.reconfigureDevice(req_devid, dev_config) 3.32 - dev_control.waitForDevice_reconfigure(req_devid) 3.33 - num_devs = dev_control.cleanupDevice(req_devid) 3.34 - 3.35 - # update XendConfig with new device info 3.36 - if dev_uuid: 3.37 - new_dev_sxp = dev_control.configuration(req_devid) 3.38 + if self.domid is not None: 3.39 + # use DevController.reconfigureDevice to change device config 3.40 + dev_control = self.getDeviceController(dev_class) 3.41 + dev_uuid = dev_control.reconfigureDevice(req_devid, dev_config) 3.42 + dev_control.waitForDevice_reconfigure(req_devid) 3.43 + num_devs = dev_control.cleanupDevice(req_devid) 3.44 + 3.45 + # update XendConfig with new device info 3.46 + if dev_uuid: 3.47 + new_dev_sxp = dev_control.configuration(req_devid) 3.48 + self.info.device_update(dev_uuid, new_dev_sxp) 3.49 + 3.50 + # If there is no device left, destroy vscsi and remove config. 3.51 + if num_devs == 0: 3.52 + self.destroyDevice('vscsi', req_devid) 3.53 + del self.info['devices'][dev_uuid] 3.54 + 3.55 + else: 3.56 + cur_dev_sxp = self._getDeviceInfo_vscsi(req_devid, None) 3.57 + new_dev_sxp = ['vscsi'] 3.58 + for cur_dev in sxp.children(cur_dev_sxp, 'dev'): 3.59 + if state == xenbusState['Closing']: 3.60 + cur_dev_vdev = sxp.child_value(cur_dev, 'v-dev') 3.61 + if cur_dev_vdev == dev['v-dev']: 3.62 + continue 3.63 + new_dev_sxp.append(cur_dev) 3.64 + 3.65 + if state == xenbusState['Initialising']: 3.66 + new_dev_sxp.append(sxp.child0(dev_sxp, 'dev')) 3.67 + 3.68 + dev_uuid = sxp.child_value(cur_dev_sxp, 'uuid') 3.69 self.info.device_update(dev_uuid, new_dev_sxp) 3.70 3.71 - # If there is no device left, destroy vscsi and remove config. 3.72 - if num_devs == 0: 3.73 - self.destroyDevice('vscsi', req_devid) 3.74 - del self.info['devices'][dev_uuid] 3.75 + # If there is only 'vscsi' in new_dev_sxp, remove the config. 3.76 + if len(sxp.children(new_dev_sxp, 'dev')) == 0: 3.77 + del self.info['devices'][dev_uuid] 3.78 + 3.79 + xen.xend.XendDomain.instance().managed_config_save(self) 3.80 3.81 return True 3.82 3.83 @@ -986,7 +1010,17 @@ class XendDomainInfo: 3.84 sxprs = [] 3.85 dev_num = 0 3.86 for dev_type, dev_info in self.info.all_devices_sxpr(): 3.87 - if dev_type == deviceClass: 3.88 + if dev_type != deviceClass: 3.89 + continue 3.90 + 3.91 + if deviceClass == 'vscsi': 3.92 + vscsi_devs = ['devs', []] 3.93 + for vscsi_dev in sxp.children(dev_info, 'dev'): 3.94 + vscsi_dev.append(['frontstate', None]) 3.95 + vscsi_devs[1].append(vscsi_dev) 3.96 + dev_num = int(sxp.child_value(vscsi_dev, 'devid')) 3.97 + sxprs.append([dev_num, [vscsi_devs]]) 3.98 + else: 3.99 sxprs.append([dev_num, dev_info]) 3.100 dev_num += 1 3.101 return sxprs 3.102 @@ -2380,11 +2414,10 @@ class XendDomainInfo: 3.103 time.sleep(2) 3.104 for paths in plist: 3.105 if paths.find('backend') != -1: 3.106 - from xen.xend.server import DevController 3.107 # Modify online status /before/ updating state (latter is watched by 3.108 # drivers, so this ordering avoids a race). 3.109 xstransact.Write(paths, 'online', "0") 3.110 - xstransact.Write(paths, 'state', str(DevController.xenbusState['Closing'])) 3.111 + xstransact.Write(paths, 'state', str(xenbusState['Closing'])) 3.112 # force 3.113 xstransact.Remove(paths) 3.114 3.115 @@ -3439,7 +3472,7 @@ class XendDomainInfo: 3.116 ['p-devname', pscsi.get_dev_name()], 3.117 ['p-dev', pscsi.get_physical_HCTL()], 3.118 ['v-dev', xenapi_dscsi.get('virtual_HCTL')], 3.119 - ['state', 'Initialising'], 3.120 + ['state', xenbusState['Initialising']], 3.121 ['uuid', dscsi_uuid] 3.122 ] 3.123 ] 3.124 @@ -3558,7 +3591,7 @@ class XendDomainInfo: 3.125 if target_dev is None: 3.126 raise XendError('Failed to destroy device') 3.127 3.128 - target_dev.append(['state', 'Closing']) 3.129 + target_dev.append(['state', xenbusState['Closing']]) 3.130 target_vscsi_sxp = ['vscsi', target_dev] 3.131 3.132 if self._stateGet() != XEN_API_VM_POWER_STATE_RUNNING:
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tools/python/xen/xend/server/DevConstants.py Mon Oct 27 10:03:17 2008 +0000 4.3 @@ -0,0 +1,45 @@ 4.4 +#============================================================================ 4.5 +# This library is free software; you can redistribute it and/or 4.6 +# modify it under the terms of version 2.1 of the GNU Lesser General Public 4.7 +# License as published by the Free Software Foundation. 4.8 +# 4.9 +# This library is distributed in the hope that it will be useful, 4.10 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 4.11 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 4.12 +# Lesser General Public License for more details. 4.13 +# 4.14 +# You should have received a copy of the GNU Lesser General Public 4.15 +# License along with this library; if not, write to the Free Software 4.16 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 4.17 +#============================================================================ 4.18 +# Copyright (C) 2004, 2005 Mike Wray <mike.wray@hp.com> 4.19 +# Copyright (C) 2005 XenSource Ltd 4.20 +#============================================================================ 4.21 + 4.22 +DEVICE_CREATE_TIMEOUT = 100 4.23 +DEVICE_DESTROY_TIMEOUT = 100 4.24 +HOTPLUG_STATUS_NODE = "hotplug-status" 4.25 +HOTPLUG_ERROR_NODE = "hotplug-error" 4.26 +HOTPLUG_STATUS_ERROR = "error" 4.27 +HOTPLUG_STATUS_BUSY = "busy" 4.28 + 4.29 +Connected = 1 4.30 +Error = 2 4.31 +Missing = 3 4.32 +Timeout = 4 4.33 +Busy = 5 4.34 +Disconnected = 6 4.35 + 4.36 +xenbusState = { 4.37 + 'Unknown' : 0, 4.38 + 'Initialising' : 1, 4.39 + 'InitWait' : 2, 4.40 + 'Initialised' : 3, 4.41 + 'Connected' : 4, 4.42 + 'Closing' : 5, 4.43 + 'Closed' : 6, 4.44 + 'Reconfiguring' : 7, 4.45 + 'Reconfigured' : 8, 4.46 + } 4.47 +xenbusState.update(dict(zip(xenbusState.values(), xenbusState.keys()))) 4.48 +
5.1 --- a/tools/python/xen/xend/server/DevController.py Thu Oct 23 15:38:52 2008 +0100 5.2 +++ b/tools/python/xen/xend/server/DevController.py Mon Oct 27 10:03:17 2008 +0000 5.3 @@ -23,42 +23,15 @@ from xen.xend import sxp, XendOptions 5.4 from xen.xend.XendError import VmError 5.5 from xen.xend.XendLogging import log 5.6 import xen.xend.XendConfig 5.7 +from xen.xend.server.DevConstants import * 5.8 5.9 from xen.xend.xenstore.xstransact import xstransact, complete 5.10 from xen.xend.xenstore.xswatch import xswatch 5.11 5.12 import os 5.13 5.14 -DEVICE_CREATE_TIMEOUT = 100 5.15 -DEVICE_DESTROY_TIMEOUT = 100 5.16 -HOTPLUG_STATUS_NODE = "hotplug-status" 5.17 -HOTPLUG_ERROR_NODE = "hotplug-error" 5.18 -HOTPLUG_STATUS_ERROR = "error" 5.19 -HOTPLUG_STATUS_BUSY = "busy" 5.20 - 5.21 -Connected = 1 5.22 -Error = 2 5.23 -Missing = 3 5.24 -Timeout = 4 5.25 -Busy = 5 5.26 -Disconnected = 6 5.27 - 5.28 -xenbusState = { 5.29 - 'Unknown' : 0, 5.30 - 'Initialising' : 1, 5.31 - 'InitWait' : 2, 5.32 - 'Initialised' : 3, 5.33 - 'Connected' : 4, 5.34 - 'Closing' : 5, 5.35 - 'Closed' : 6, 5.36 - 'Reconfiguring': 7, 5.37 - 'Reconfigured' : 8, 5.38 - } 5.39 - 5.40 xoptions = XendOptions.instance() 5.41 5.42 -xenbusState.update(dict(zip(xenbusState.values(), xenbusState.keys()))) 5.43 - 5.44 5.45 class DevController: 5.46 """Abstract base class for a device controller. Device controllers create
6.1 --- a/tools/python/xen/xend/server/pciif.py Thu Oct 23 15:38:52 2008 +0100 6.2 +++ b/tools/python/xen/xend/server/pciif.py Mon Oct 27 10:03:17 2008 +0000 6.3 @@ -25,7 +25,8 @@ from xen.xend import arch 6.4 from xen.xend.XendError import VmError 6.5 from xen.xend.XendLogging import log 6.6 6.7 -from xen.xend.server.DevController import DevController, xenbusState 6.8 +from xen.xend.server.DevController import DevController 6.9 +from xen.xend.server.DevConstants import xenbusState 6.10 6.11 import xen.lowlevel.xc 6.12
7.1 --- a/tools/python/xen/xend/server/vscsiif.py Thu Oct 23 15:38:52 2008 +0100 7.2 +++ b/tools/python/xen/xend/server/vscsiif.py Mon Oct 27 10:03:17 2008 +0000 7.3 @@ -28,7 +28,8 @@ from xen.xend import sxp 7.4 from xen.xend.XendError import VmError 7.5 from xen.xend.XendLogging import log 7.6 7.7 -from xen.xend.server.DevController import DevController, xenbusState 7.8 +from xen.xend.server.DevController import DevController 7.9 +from xen.xend.server.DevConstants import xenbusState 7.10 from xen.xend.xenstore.xstransact import xstransact 7.11 7.12 class VSCSIController(DevController): 7.13 @@ -92,8 +93,8 @@ class VSCSIController(DevController): 7.14 back[devpath + '/p-devname'] = pdevname 7.15 vdev = vscsi_config.get('v-dev', '') 7.16 back[devpath + '/v-dev'] = vdev 7.17 - state = vscsi_config.get('state', '') 7.18 - back[devpath + '/state'] = str(xenbusState[state]) 7.19 + state = vscsi_config.get('state', xenbusState['Unknown']) 7.20 + back[devpath + '/state'] = str(state) 7.21 devid = vscsi_config.get('devid', '') 7.22 back[devpath + '/devid'] = str(devid) 7.23 7.24 @@ -168,17 +169,17 @@ class VSCSIController(DevController): 7.25 (devid, back, front) = self.getDeviceDetails(config) 7.26 devid = int(devid) 7.27 vscsi_config = config['devs'][0] 7.28 - state = vscsi_config.get('state', '') 7.29 + state = vscsi_config.get('state', xenbusState['Unknown']) 7.30 driver_state = self.readBackend(devid, 'state') 7.31 if str(xenbusState['Connected']) != driver_state: 7.32 raise VmError("Driver status is not connected") 7.33 7.34 uuid = self.readBackend(devid, 'uuid') 7.35 - if state == 'Initialising': 7.36 + if state == xenbusState['Initialising']: 7.37 back['uuid'] = uuid 7.38 self.writeBackend(devid, back) 7.39 7.40 - elif state == 'Closing': 7.41 + elif state == xenbusState['Closing']: 7.42 found = False 7.43 devs = self.readBackendList(devid, "vscsi-devs") 7.44 vscsipath = "vscsi-devs/" 7.45 @@ -198,7 +199,7 @@ class VSCSIController(DevController): 7.46 7.47 else: 7.48 raise XendError("Error configuring device invalid " 7.49 - "state '%s'" % state) 7.50 + "state '%s'" % xenbusState[state]) 7.51 7.52 self.writeBackend(devid, 'state', str(xenbusState['Reconfiguring'])) 7.53 return self.readBackend(devid, 'uuid')
8.1 --- a/tools/python/xen/xm/create.py Thu Oct 23 15:38:52 2008 +0100 8.2 +++ b/tools/python/xen/xm/create.py Mon Oct 27 10:03:17 2008 +0000 8.3 @@ -32,6 +32,7 @@ from xen.xend import PrettyPrint as SXPP 8.4 from xen.xend import osdep 8.5 import xen.xend.XendClient 8.6 from xen.xend.XendBootloader import bootloader 8.7 +from xen.xend.server.DevConstants import xenbusState 8.8 from xen.util import blkif 8.9 from xen.util import vscsi_util 8.10 import xen.util.xsm.xsm as security 8.11 @@ -707,7 +708,7 @@ def configure_vscsis(config_devs, vals): 8.12 vscsi_util.vscsi_get_hctl_and_devname_by(p_dev, scsi_devices) 8.13 8.14 if p_hctl == None: 8.15 - raise ValueError("Cannot find device \"%s\"" % p_dev) 8.16 + raise ValueError('Cannot find device "%s"' % p_dev) 8.17 8.18 for config in config_scsi: 8.19 dev = vscsi_convert_sxp_to_dict(config) 8.20 @@ -717,7 +718,7 @@ def configure_vscsis(config_devs, vals): 8.21 v_hctl = v_dev.split(':') 8.22 devid = int(v_hctl[0]) 8.23 config_scsi.append(['dev', \ 8.24 - ['state', 'Initialising'], \ 8.25 + ['state', xenbusState['Initialising']], \ 8.26 ['devid', devid], \ 8.27 ['p-dev', p_hctl], \ 8.28 ['p-devname', devname], \
9.1 --- a/tools/python/xen/xm/main.py Thu Oct 23 15:38:52 2008 +0100 9.2 +++ b/tools/python/xen/xm/main.py Mon Oct 27 10:03:17 2008 +0000 9.3 @@ -47,6 +47,7 @@ from xen.xend import PrettyPrint 9.4 from xen.xend import sxp 9.5 from xen.xend import XendClient 9.6 from xen.xend.XendConstants import * 9.7 +from xen.xend.server.DevConstants import xenbusState 9.8 9.9 from xen.xm.opts import OptionError, Opts, wrap, set_true 9.10 from xen.xm import console 9.11 @@ -2515,7 +2516,7 @@ def xm_scsi_attach(args): 9.12 dom = args[0] 9.13 p_scsi = args[1] 9.14 v_hctl = args[2] 9.15 - scsi = parse_scsi_configuration(p_scsi, v_hctl, 'Initialising') 9.16 + scsi = parse_scsi_configuration(p_scsi, v_hctl, xenbusState['Initialising']) 9.17 9.18 if serverType == SERVER_XEN_API: 9.19 9.20 @@ -2635,7 +2636,7 @@ def xm_scsi_detach(args): 9.21 arg_check(args, 'scsi-detach', 2) 9.22 dom = args[0] 9.23 v_hctl = args[1] 9.24 - scsi = parse_scsi_configuration(None, v_hctl, 'Closing') 9.25 + scsi = parse_scsi_configuration(None, v_hctl, xenbusState['Closing']) 9.26 9.27 if serverType == SERVER_XEN_API: 9.28