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

[Xen-changelog] [xen-unstable] xend: Allow replacement of a cdrom device on a device_add



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1236855685 0
# Node ID 99771e02b38a609de3bf2ded966fbdea00f77960
# Parent  db53046ca5f0f1410cfba7ef4d40eb9ea2198d89
xend: 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@xxxxxxx>
---
 tools/python/xen/xend/XendConfig.py |   32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diff -r db53046ca5f0 -r 99771e02b38a tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Thu Mar 12 11:00:52 2009 +0000
+++ b/tools/python/xen/xend/XendConfig.py       Thu Mar 12 11:01:25 2009 +0000
@@ -1155,7 +1155,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':
@@ -1174,9 +1174,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)
                     
@@ -1188,6 +1213,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):
@@ -1326,7 +1352,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-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

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