[virt-tools-list] [virt-manager PATCH] addhw: set virtio-scsi controller index via max index in scsi controller list

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Tue Jan 21 08:24:09 UTC 2014


From: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>

We set virtio-scsi controller index according to
the number of scsi controller in VM.
This patch will set virtio-scsi controller index
via max index in scsi controller list.

How to reproduce:
a)
If we got an VM with two scsi controller:
<controller type='scsi' index='0'>
<controller type='scsi' index='2'>

#reason for index='2':
someone delete a scsi controller with index=1
by virsh

b)
add a virtio-scsi disk by virt-manager

c)
error threw by virt-manager:
libvirtError: XML error: Multiple 'scsi' controllers with index '2'

Signed-off-by: Chen Hanxiao <chenhanxiao at cn.fujitsu.com>
---
 virtManager/addhardware.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index d7ee161..a0facf2 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -1546,13 +1546,19 @@ class vmmAddHardware(vmmGObjectUI):
         disk.vmm_controller = None
         if (controller_model == "virtio-scsi") and (bus == "scsi"):
             controllers = self.vm.get_controller_devices()
+            ctrls_scsi = [x for x in controllers if
+                    (x.type == VirtualController.TYPE_SCSI)]
+            if len(ctrls_scsi) > 0:
+                index_new = max([x.index for x in ctrls_scsi]) + 1
+            else:
+                index_new = 0
             controller = VirtualController(conn)
             controller.type = "scsi"
             controller.model = controller_model
             disk.vmm_controller = controller
             for d in controllers:
                 if controller.type == d.type:
-                    controller.index += 1
+                    controller.index = index_new
                 if controller_model == d.model:
                     disk.vmm_controller = None
                     controller = d
-- 
1.8.2.1




More information about the virt-tools-list mailing list