Skip to content

Commit

Permalink
viommu: Fixup incorrect disk xml issues
Browse files Browse the repository at this point in the history
The disk and scsi controller may enable iommu by default, so update
to use the proper disk and controller settings.

Signed-off-by: Yingshun Cui <yicui@redhat.com>
  • Loading branch information
Yingshun committed Sep 19, 2024
1 parent 59792ec commit 91b7eee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
3 changes: 2 additions & 1 deletion libvirt/tests/cfg/sriov/vIOMMU/iommu_device_settings.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
- scsi_controller:
test_devices = ["scsi"]
controller_dicts = [{'type': 'scsi', 'model': 'virtio-scsi','driver': {'iommu': 'on'}}]
disk_dict = {'target': {'dev': 'sda', 'bus': 'scsi'}}
disk_driver = {'name': 'qemu', 'type': 'qcow2'}
disk_dict = {'target': {'dev': 'sda', 'bus': 'scsi'}, 'driver': ${disk_driver}}
cleanup_ifaces = no
- pcie_to_pci_bridge_controller:
test_devices = ["Eth", "block"]
Expand Down
3 changes: 3 additions & 0 deletions libvirt/tests/src/sriov/vIOMMU/iommu_device_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def run(test, params, env):
dev_dict = eval(params.get('%s_dict' % dev, '{}'))
if dev == "disk":
dev_dict = test_obj.update_disk_addr(dev_dict)
if dev_dict["target"].get("bus") != "virtio":
libvirt_vmxml.modify_vm_device(
vm_xml.VMXML.new_from_dumpxml(vm.name), dev, {'driver': None})

libvirt_vmxml.modify_vm_device(
vm_xml.VMXML.new_from_dumpxml(vm.name), dev, dev_dict)
Expand Down
51 changes: 26 additions & 25 deletions provider/viommu/viommu_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ def parse_iface_dict(self):
:return: The updated iface_dict
"""
mac_addr = utils_net.generate_mac_address_simple()
iface_dict = eval(self.params.get('iface_dict', '{}'))
iface_dict = eval(self.params.get("iface_dict", "{}"))
self.test.log.debug("iface_dict2: %s.", iface_dict)

if self.controller_dicts and iface_dict:
iface_bus = "%0#4x" % int(self.controller_dicts[-1].get('index'))
iface_attrs = {'bus': iface_bus}
iface_bus = "%0#4x" % int(self.controller_dicts[-1].get("index"))
iface_attrs = {"bus": iface_bus}
if isinstance(self.dev_slot, int):
self.dev_slot += 1
iface_attrs.update({'slot': self.dev_slot})
iface_dict.update({"address": {'attrs': iface_attrs}})
iface_attrs.update({"slot": self.dev_slot})
iface_dict.update({"address": {"attrs": iface_attrs}})
self.test.log.debug("iface_dict: %s.", iface_dict)
return iface_dict

Expand All @@ -85,25 +85,25 @@ def prepare_controller(self):
pre_controller = contr_dict.get("pre_controller")
if pre_controller:
pre_contrs = list(
filter(None, [c.get('index') for c in self.controller_dicts
if c['type'] == contr_dict['type'] and
c['model'] == pre_controller]))
filter(None, [c.get("index") for c in self.controller_dicts
if c["type"] == contr_dict["type"] and
c["model"] == pre_controller]))
if pre_contrs:
pre_idx = pre_contrs[0]
else:
pre_idx = libvirt_pcicontr.get_max_contr_indexes(
vm_xml.VMXML.new_from_dumpxml(self.vm.name),
contr_dict['type'], pre_controller)
contr_dict["type"], pre_controller)
if not pre_idx:
self.test.error(
f"Unable to get index of {pre_controller} controller!")
contr_dict.pop("pre_controller")
libvirt_vmxml.modify_vm_device(
vm_xml.VMXML.new_from_dumpxml(self.vm.name), 'controller',
vm_xml.VMXML.new_from_dumpxml(self.vm.name), "controller",
contr_dict, 100)
contr_dict['index'] = libvirt_pcicontr.get_max_contr_indexes(
contr_dict["index"] = libvirt_pcicontr.get_max_contr_indexes(
vm_xml.VMXML.new_from_dumpxml(self.vm.name),
contr_dict['type'], contr_dict['model'])[-1]
contr_dict["type"], contr_dict["model"])[-1]
return self.controller_dicts

def update_disk_addr(self, disk_dict):
Expand All @@ -114,19 +114,20 @@ def update_disk_addr(self, disk_dict):
:return: The updated disk attrs
"""
if self.controller_dicts:
dev_bus = self.controller_dicts[-1].get('index')
dev_attrs = {'bus': dev_bus}
if disk_dict['target']['bus'] != "scsi":
dev_attrs.update({'type': self.controller_dicts[-1].get('type')})
if self.controller_dicts[-1].get('model') == 'pcie-to-pci-bridge':
dev_bus = self.controller_dicts[-1].get("index")
dev_attrs = {"bus": "0"}
if disk_dict["target"]["bus"] != "scsi":
dev_attrs = {"bus": dev_bus}
dev_attrs.update({"type": self.controller_dicts[-1].get("type")})
if self.controller_dicts[-1].get("model") == "pcie-to-pci-bridge":
self.dev_slot = 1
dev_attrs.update({'slot': self.dev_slot})
dev_attrs.update({"slot": self.dev_slot})

disk_dict.update({"address": {'attrs': dev_attrs}})
if disk_dict['target']['bus'] == "scsi":
disk_dict['address']['attrs'].update({'type': 'drive'})
disk_dict.update({"address": {"attrs": dev_attrs}})
if disk_dict["target"]["bus"] == "scsi":
disk_dict["address"]["attrs"].update({"type": "drive", "controller": dev_bus})

if self.controller_dicts[-1]['model'] == 'pcie-root-port':
if self.controller_dicts[-1]["model"] == "pcie-root-port":
self.controller_dicts.pop()
return disk_dict

Expand All @@ -136,13 +137,13 @@ def setup_iommu_test(self, **dargs):
:param dargs: Other test keywords
"""
iommu_dict = dargs.get('iommu_dict', {})
iommu_dict = dargs.get("iommu_dict", {})
dev_type = dargs.get("dev_type", "interface")
cleanup_ifaces = "yes" == dargs.get("cleanup_ifaces", "yes")

if cleanup_ifaces:
libvirt_vmxml.remove_vm_devices_by_type(self.vm, 'interface')
libvirt_vmxml.remove_vm_devices_by_type(self.vm, 'hostdev')
libvirt_vmxml.remove_vm_devices_by_type(self.vm, "interface")
libvirt_vmxml.remove_vm_devices_by_type(self.vm, "hostdev")
if iommu_dict:
self.test.log.info("TEST_SETUP: Add iommu device.")
libvirt_virtio.add_iommu_dev(self.vm, iommu_dict)
Expand Down

0 comments on commit 91b7eee

Please sign in to comment.