addhw: set virtio-scsi controller index via max index in scsi controller list

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@cn.fujitsu.com>
This commit is contained in:
Chen Hanxiao 2014-01-21 16:24:09 +08:00 committed by Cole Robinson
parent 6d5acfab52
commit dc439b2c1c

View File

@ -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