Skip to content

Commit b3c4517

Browse files
AlanJagerliang-hanyu
authored andcommitted
<fix>[vm]: fix cdrom device address wrong usage
Resolves: ZSTAC-47843 Change-Id: I746a62747a777175656464796e79687977697861 Signed-off-by: AlanJager <ye.zou@zstack.io>
1 parent f0caa9f commit b3c4517

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

kvmagent/kvmagent/plugins/vm_plugin.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4063,11 +4063,20 @@ def make_cdrom():
40634063
if len(empty_cdrom_configs) != max_cdrom_num:
40644064
logger.error('ISO_DEVICE_LETTERS or EMPTY_CDROM_CONFIGS config error')
40654065

4066-
def make_empty_cdrom(target_dev, bus, unit, bootOrder, resourceUuid):
4066+
# legacy_cdrom_config used for cdrom without deivce address
4067+
# cdrom given address record from management node side
4068+
def make_empty_cdrom(iso, legacy_cdrom_config, bootOrder, resourceUuid):
40674069
cdrom = e(devices, 'disk', None, {'type': 'file', 'device': 'cdrom'})
40684070
e(cdrom, 'driver', None, {'name': 'qemu', 'type': 'raw'})
4069-
e(cdrom, 'target', None, {'dev': target_dev, 'bus': default_bus_type})
4070-
e(cdrom, 'address', None, {'type': 'drive', 'bus': bus, 'unit': unit})
4071+
e(cdrom, 'target', None, {'dev': legacy_cdrom_config.targetDev, 'bus': default_bus_type})
4072+
4073+
if iso.pciAddress:
4074+
# domain:bus:slot:function
4075+
# controller:bus:target:unit
4076+
e(cdrom, 'address', None, {'type': 'drive', 'controller': iso.pciAddress.domain, 'bus': iso.pciAddress.bus,
4077+
'target': iso.pciAddress.slot, 'unit': iso.pciAddress.function})
4078+
else:
4079+
e(cdrom, 'address', None, {'type': 'drive', 'bus': legacy_cdrom_config.bus, 'unit': legacy_cdrom_config.unit})
40714080
e(cdrom, 'readonly', None)
40724081
e(cdrom, 'serial', resourceUuid)
40734082
if bootOrder is not None and bootOrder > 0:
@@ -4109,15 +4118,15 @@ def generate_floppy_device_id(index):
41094118
cdrom_config = empty_cdrom_configs[iso.deviceId]
41104119

41114120
if iso.isEmpty:
4112-
make_empty_cdrom(cdrom_config.targetDev, cdrom_config.bus, cdrom_config.unit, iso.bootOrder, iso.resourceUuid)
4121+
make_empty_cdrom(iso, cdrom_config, iso.bootOrder, iso.resourceUuid)
41134122
continue
41144123

41154124
if iso.path.startswith('ceph'):
41164125
ic = IsoCeph()
41174126
ic.iso = iso
41184127
devices.append(ic.to_xmlobject(cdrom_config.targetDev, default_bus_type, cdrom_config.bus, cdrom_config.unit, iso.bootOrder))
41194128
else:
4120-
cdrom = make_empty_cdrom(cdrom_config.targetDev, cdrom_config.bus , cdrom_config.unit, iso.bootOrder, iso.resourceUuid)
4129+
cdrom = make_empty_cdrom(iso, cdrom_config, iso.bootOrder, iso.resourceUuid)
41214130
e(cdrom, 'source', None, {'file': iso.path})
41224131

41234132
def make_volumes():

0 commit comments

Comments
 (0)