John Levon
2009-Mar-12 01:44 UTC
[Xen-devel] [PATCH] Allow replacement of a cdrom device on a device_add
# HG changeset patch
# User John Levon <john.levon@sun.com>
# Date 1236822231 25200
# Node ID 523bc3b8d32f426a8c6ce44a6d9ea97b37ae6035
# Parent 881ec0e9ee98464d74df6e113924cbd9d53240a5
Allow replacement of a cdrom device on a device_add
When adding a device, allow a cd to replace another if the device is a cdrom.
Signed-off by: Ryan Scott <ryan.scott@sun.com>
diff --git a/tools/python/xen/xend/XendConfig.py
b/tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py
+++ b/tools/python/xen/xend/XendConfig.py
@@ -1159,7 +1159,7 @@ class XendConfig(dict):
return None
return devid
- def device_duplicate_check(self, dev_type, dev_info, defined_config):
+ def device_duplicate_check(self, dev_type, dev_info, defined_config,
config):
defined_devices_sxpr = self.all_devices_sxpr(target = defined_config)
if dev_type == ''vbd'' or dev_type ==
''tap'':
@@ -1178,9 +1178,34 @@ class XendConfig(dict):
if blkdev_file == o_blkdev_file:
raise XendConfigError(''The file
"%s" is already used'' %
blkdev_file)
+ if dev_uname == o_dev_uname:
+ raise XendConfigError(''The uname
"%s" is already defined'' %
+ dev_uname)
o_blkdev_name = sxp.child_value(o_dev_info,
''dev'')
o_devid = self._blkdev_name_to_number(o_blkdev_name)
if o_devid != None and devid == o_devid:
+ name_array = blkdev_name.split('':'',
2)
+ if len(name_array) == 2 and name_array[1] ==
''cdrom'':
+ #
+ # Since the device is a cdrom, we are most likely
+ # inserting, changing, or removing a cd. We can
+ # update the old device instead of creating a new
+ # one.
+ #
+ if o_dev_uname != None and dev_uname == None:
+ #
+ # We are removing a cd. We can simply update
+ # the uname on the existing device.
+ #
+ merge_sxp =
sxp.from_string("(''vbd'' (''uname''
''''))")
+ else:
+ merge_sxp = config
+
+ dev_uuid = sxp.child_value(o_dev_info,
''uuid'')
+ if dev_uuid != None and \
+ self.device_update(dev_uuid, cfg_sxp =
merge_sxp):
+ return dev_uuid
+
raise XendConfigError(''The device
"%s" is already defined'' %
blkdev_name)
@@ -1192,6 +1217,7 @@ class XendConfig(dict):
if dev_mac.lower() == sxp.child_value(o_dev_info,
''mac'').lower():
raise XendConfigError(''The mac "%s"
is already defined'' %
dev_mac)
+ return None
def device_add(self, dev_type, cfg_sxp = None, cfg_xenapi = None,
target = None):
@@ -1330,7 +1356,9 @@ class XendConfig(dict):
if not dev_info.get(''mac''):
dev_info[''mac''] = randomMAC()
- self.device_duplicate_check(dev_type, dev_info, target)
+ ret_uuid = self.device_duplicate_check(dev_type, dev_info, target,
config)
+ if ret_uuid != None:
+ return ret_uuid
if dev_type == ''vif'':
if dev_info.get(''policy'') and
dev_info.get(''label''):
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel