Skip to content

Commit c44472e

Browse files
AlanJagerliang-hanyu
authored andcommitted
<fix>[vm]: use device address instead of pci address
Change-Id: I75686872726a6976787a78726a6270756471666a Signed-off-by: AlanJager <ye.zou@zstack.io>
1 parent b3c4517 commit c44472e

File tree

1 file changed

+61
-71
lines changed

1 file changed

+61
-71
lines changed

kvmagent/kvmagent/plugins/vm_plugin.py

Lines changed: 61 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -198,26 +198,32 @@ def __init__(self):
198198

199199
class VirtualDeviceInfo():
200200
def __init__(self):
201-
self.pciInfo = PciAddressInfo()
201+
self.deviceAddress = DeviceAddress()
202202
self.resourceUuid = None
203203

204204
class VmNicInfo():
205205
def __init__(self):
206-
self.pciInfo = PciAddressInfo()
206+
self.deviceAddress = DeviceAddress()
207207
self.macAddress = None
208208

209-
class PciAddressInfo():
209+
class DeviceAddress():
210210
def __init__(self):
211211
self.type = None
212-
self.domain = None
213212
self.bus = None
213+
214+
# for pci address
215+
self.domain = None
214216
self.slot = None
215217
self.function = None
216218

219+
# for dirver address
220+
self.controller = None
221+
self.target = None
222+
self.unit = None
223+
217224
class AttachNicResponse(kvmagent.AgentResponse):
218225
def __init__(self):
219226
super(AttachNicResponse, self).__init__()
220-
self.pciAddress = PciAddressInfo()
221227
self.virtualDeviceInfoList = []
222228

223229
class GetVncPortCmd(kvmagent.AgentCommand):
@@ -1854,21 +1860,21 @@ def set_device_address(disk_element, vol, vm_to_attach=None):
18541860
target = disk_element.find('target')
18551861
bus = target.get('bus') if target is not None else None
18561862

1857-
if vol.pciAddress and vol.pciAddress.type == 'pci':
1863+
if vol.deviceAddress and vol.deviceAddress.type == 'pci':
18581864
attributes = {}
1859-
if vol.pciAddress.domain:
1860-
attributes['domain'] = vol.pciAddress.domain
1861-
if vol.pciAddress.bus:
1862-
attributes['bus'] = vol.pciAddress.bus
1863-
if vol.pciAddress.slot:
1864-
attributes['slot'] = vol.pciAddress.slot
1865-
if vol.pciAddress.function:
1866-
attributes['function'] = vol.pciAddress.function
1867-
1868-
attributes['type'] = vol.pciAddress.type
1865+
if vol.deviceAddress.domain:
1866+
attributes['domain'] = vol.deviceAddress.domain
1867+
if vol.deviceAddress.bus:
1868+
attributes['bus'] = vol.deviceAddress.bus
1869+
if vol.deviceAddress.slot:
1870+
attributes['slot'] = vol.deviceAddress.slot
1871+
if vol.deviceAddress.function:
1872+
attributes['function'] = vol.deviceAddress.function
1873+
1874+
attributes['type'] = vol.deviceAddress.type
18691875
e(disk_element, 'address', None, attributes)
1870-
elif vol.pciAddress and vol.pciAddress.type == 'driver':
1871-
e(disk_element, 'address', None, {'type': 'drive', 'controller': '0', 'unit': str(vol.pciAddress.function)})
1876+
elif vol.deviceAddress and vol.deviceAddress.type == 'driver':
1877+
e(disk_element, 'address', None, {'type': 'drive', 'controller': vol.deviceAddress.controller, 'unit': str(vol.deviceAddress.unit)})
18721878
elif bus == 'scsi':
18731879
occupied_units = vm_to_attach.get_occupied_disk_address_units(bus='scsi', controller=0) if vm_to_attach else []
18741880
default_unit = Vm.get_device_unit(vol.deviceId)
@@ -4070,11 +4076,9 @@ def make_empty_cdrom(iso, legacy_cdrom_config, bootOrder, resourceUuid):
40704076
e(cdrom, 'driver', None, {'name': 'qemu', 'type': 'raw'})
40714077
e(cdrom, 'target', None, {'dev': legacy_cdrom_config.targetDev, 'bus': default_bus_type})
40724078

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})
4079+
if iso.deviceAddress:
4080+
e(cdrom, 'address', None, {'type': 'drive', 'controller': iso.deviceAddress.controller, 'bus': iso.deviceAddress.bus,
4081+
'target': iso.deviceAddress.target, 'unit': iso.deviceAddress.unit})
40784082
else:
40794083
e(cdrom, 'address', None, {'type': 'drive', 'bus': legacy_cdrom_config.bus, 'unit': legacy_cdrom_config.unit})
40804084
e(cdrom, 'readonly', None)
@@ -4383,8 +4387,8 @@ def get_recover_path(v):
43834387
return qs.get("r")
43844388

43854389
def allocat_ide_config(_disk, _volume):
4386-
if _volume.pciAddress:
4387-
e(_disk, 'address', None, {'type': 'drive', 'bus': _volume.pciAddress.bus, 'unit': _volume.pciAddress.function})
4390+
if _volume.deviceAddress:
4391+
e(_disk, 'address', None, {'type': 'drive', 'bus': _volume.deviceAddress.bus, 'unit': _volume.deviceAddress.function})
43884392
else:
43894393
if len(volume_ide_configs) == 0:
43904394
err = "insufficient IDE address."
@@ -4819,8 +4823,9 @@ def make_balloon_memory():
48194823
devices = elements['devices']
48204824
b = e(devices, 'memballoon', None, {'model': 'virtio'})
48214825
e(b, 'stats', None, {'period': '10'})
4822-
if cmd.memBalloon.pciInfo:
4823-
e(b, 'address', None, {'type': 'pci', 'domain': cmd.memBalloon.pciInfo.domain, 'bus': cmd.memBalloon.pciInfo.bus, 'slot': cmd.memBalloon.pciInfo.slot, 'function': cmd.memBalloon.pciInfo.function})
4826+
if cmd.memBalloon.deviceAddress:
4827+
e(b, 'address', None, {'type': 'pci', 'domain': cmd.memBalloon.deviceAddress.domain, 'bus': cmd.memBalloon.deviceAddress.bus,
4828+
'slot': cmd.memBalloon.deviceAddress.slot, 'function': cmd.memBalloon.deviceAddress.function})
48244829
if kvmagent.get_host_os_type() == "debian":
48254830
e(b, 'address', None, {'type': 'pci', 'controller': '0', 'bus': '0x00', 'slot': '0x04', 'function':'0x0'})
48264831

@@ -5305,11 +5310,11 @@ def attach_nic(self, req):
53055310
continue
53065311

53075312
virtualDeviceInfo = VirtualDeviceInfo()
5308-
virtualDeviceInfo.pciInfo.bus = iface.address.bus_
5309-
virtualDeviceInfo.pciInfo.function = iface.address.function_
5310-
virtualDeviceInfo.pciInfo.type = iface.address.type_
5311-
virtualDeviceInfo.pciInfo.domain = iface.address.domain_
5312-
virtualDeviceInfo.pciInfo.slot = iface.address.slot_
5313+
virtualDeviceInfo.deviceAddress.bus = iface.address.bus_
5314+
virtualDeviceInfo.deviceAddress.function = iface.address.function_
5315+
virtualDeviceInfo.deviceAddress.type = iface.address.type_
5316+
virtualDeviceInfo.deviceAddress.domain = iface.address.domain_
5317+
virtualDeviceInfo.deviceAddress.slot = iface.address.slot_
53135318
rsp.virtualDeviceInfoList.append(virtualDeviceInfo)
53145319

53155320
return jsonobject.dumps(rsp)
@@ -5371,39 +5376,21 @@ def start_vm(self, req):
53715376
vm = get_vm_by_uuid(cmd.vmInstanceUuid)
53725377
for iface in vm.domain_xmlobject.devices.get_child_node_as_list('interface'):
53735378
vmNicInfo = VmNicInfo()
5374-
vmNicInfo.pciInfo.bus = iface.address.bus_
5375-
vmNicInfo.pciInfo.function = iface.address.function_
5376-
vmNicInfo.pciInfo.type = iface.address.type_
5377-
vmNicInfo.pciInfo.domain = iface.address.domain_
5378-
vmNicInfo.pciInfo.slot = iface.address.slot_
5379+
vmNicInfo.deviceAddress.bus = iface.address.bus_
5380+
vmNicInfo.deviceAddress.function = iface.address.function_
5381+
vmNicInfo.deviceAddress.type = iface.address.type_
5382+
vmNicInfo.deviceAddress.domain = iface.address.domain_
5383+
vmNicInfo.deviceAddress.slot = iface.address.slot_
53795384
vmNicInfo.macAddress = iface.mac.address_
53805385
rsp.nicInfos.append(vmNicInfo)
53815386

53825387

53835388
for disk in vm.domain_xmlobject.devices.get_child_node_as_list('disk'):
5384-
virtualDeviceInfo = VirtualDeviceInfo()
5385-
5386-
# domain:bus:slot:function
5387-
# controller:bus:target:unit
5388-
virtualDeviceInfo.pciInfo.domain = disk.address.domain_ if disk.address.domain__ else disk.address.controller_
5389-
virtualDeviceInfo.pciInfo.bus = disk.address.bus_
5390-
virtualDeviceInfo.pciInfo.slot = disk.address.slot_ if disk.address.slot__ else disk.address.target_
5391-
virtualDeviceInfo.pciInfo.function = disk.address.function_ if disk.address.function__ else disk.address.unit_
5392-
virtualDeviceInfo.pciInfo.type = disk.address.type_
5393-
if disk.has_element('serial'):
5394-
virtualDeviceInfo.resourceUuid = disk.serial.text_
5395-
5396-
rsp.virtualDeviceInfoList.append(virtualDeviceInfo)
5389+
rsp.virtualDeviceInfoList.append(self.get_device_address_info(disk))
53975390

53985391
memBalloonPci = vm.domain_xmlobject.devices.get_child_node('memballoon')
53995392
if memBalloonPci is not None:
5400-
memBalloonInfo = VirtualDeviceInfo()
5401-
memBalloonInfo.pciInfo.domain = memBalloonPci.address.domain_
5402-
memBalloonInfo.pciInfo.bus = memBalloonPci.address.bus_
5403-
memBalloonInfo.pciInfo.slot = memBalloonPci.address.slot_
5404-
memBalloonInfo.pciInfo.function = memBalloonPci.address.function_
5405-
memBalloonInfo.pciInfo.type = memBalloonPci.address.type_
5406-
rsp.memBalloonInfo = memBalloonInfo
5393+
rsp.memBalloonInfo = self.get_device_address_info(memBalloonPci)
54075394

54085395
return jsonobject.dumps(rsp)
54095396

@@ -5876,6 +5863,22 @@ def destroy_vm(self, req):
58765863

58775864
return jsonobject.dumps(rsp)
58785865

5866+
def get_device_address_info(self, device):
5867+
virtualDeviceInfo = VirtualDeviceInfo()
5868+
virtualDeviceInfo.deviceAddress.bus = device.address.bus_ if device.address.bus__ else None
5869+
virtualDeviceInfo.deviceAddress.domain = device.address.domain_ if device.address.domain__ else None
5870+
virtualDeviceInfo.deviceAddress.controller = device.address.controller_ if device.address.controller__ else None
5871+
virtualDeviceInfo.deviceAddress.slot = device.address.slot_ if device.address.slot__ else None
5872+
virtualDeviceInfo.deviceAddress.target = device.address.target_ if device.address.target__ else None
5873+
virtualDeviceInfo.deviceAddress.function = device.address.function_ if device.address.function__ else None
5874+
virtualDeviceInfo.deviceAddress.unit = device.address.unit_ if device.address.unit__ else None
5875+
virtualDeviceInfo.deviceAddress.type = device.address.type_ if device.address.type__ else None
5876+
5877+
if device.has_element('serial'):
5878+
virtualDeviceInfo.resourceUuid = device.serial.text_
5879+
5880+
return virtualDeviceInfo
5881+
58795882
@kvmagent.replyerror
58805883
def attach_data_volume(self, req):
58815884
cmd = jsonobject.loads(req[http.REQUEST_BODY])
@@ -5891,20 +5894,7 @@ def attach_data_volume(self, req):
58915894
vm.refresh()
58925895

58935896
disk, _ = vm._get_target_disk(volume)
5894-
5895-
virtualDeviceInfo = VirtualDeviceInfo()
5896-
virtualDeviceInfo.pciInfo.bus = disk.address.bus_
5897-
# domain:bus:slot:function
5898-
# controller:bus:target:unit
5899-
virtualDeviceInfo.pciInfo.domain = disk.address.domain_ if disk.address.domain__ else disk.address.controller_
5900-
virtualDeviceInfo.pciInfo.bus = disk.address.bus_
5901-
virtualDeviceInfo.pciInfo.slot = disk.address.slot_ if disk.address.slot__ else disk.address.target_
5902-
virtualDeviceInfo.pciInfo.function = disk.address.function_ if disk.address.function__ else disk.address.unit_
5903-
virtualDeviceInfo.pciInfo.type = disk.address.type_
5904-
if disk.has_element('serial'):
5905-
virtualDeviceInfo.resourceUuid = disk.serial.text_
5906-
5907-
rsp.virtualDeviceInfoList.append(virtualDeviceInfo)
5897+
rsp.virtualDeviceInfoList.append(self.get_device_address_info(disk))
59085898
except kvmagent.KvmError as e:
59095899
logger.warn(linux.get_exception_stacktrace())
59105900
rsp.error = str(e)

0 commit comments

Comments
 (0)