Fix pci-irq-affinity-agent xml parser (devices)

There are issues when the agent tries to parse domxml from instances
using multiple 'device/interface'. Furthermore, instances using
pci-passtrough creates creates devices at 'device/hostdev' in some
cases.

Signed-off-by: hbrito <hugo.brito@windriver.com>
Signed-off-by: Lucas Cavalcante <lucasmedeiros.cavalcante@windriver.com>
Partial-bug: 1945201
Change-Id: Ia486ab61286c2474878856ae5e7bce0216e618d0
This commit is contained in:
Lucas Cavalcante 2021-09-30 11:50:54 -03:00
parent 3991552c19
commit 6b14a5dad4
1 changed files with 22 additions and 10 deletions

View File

@ -229,17 +229,29 @@ def get_guest_domain_info(dom):
d_nodelist = list(sorted(nodeset))
# Get pci info.
def find_pci_addr(dom_xml, device_type):
LOG.debug("Finding pci_addrs for %s devices" % device_type)
def parse_pci_addr(tag):
return "%04x:%02x:%02x.%01x" % (
int(tag.get('domain'), base=16),
int(tag.get('bus'), base=16),
int(tag.get('slot'), base=16),
int(tag.get('function'), base=16))
for node in dom_xml.findall('./devices/' + device_type):
for driver in node.findall('driver'):
if driver.get('name').startswith('vfio'):
addr_tag = node.find('source/address')
if (addr_tag.get('type') == 'pci' or
node.get('type') == 'pci'):
pci_addr = parse_pci_addr(addr_tag)
LOG.debug("Add pci device: %s" % pci_addr)
pci_addrs.update([pci_addr])
pci_addrs = set()
for interface in dom_xml.findall('./devices/interface'):
if interface.find('driver').get('name').startswith('vfio'):
addr_tag = interface.find('source/address')
if addr_tag.get('type') == 'pci':
pci_addr = "%04x:%02x:%02x.%01x" % (
addr_tag.get('domain'),
addr_tag.get('bus'),
addr_tag.get('slot'),
addr_tag.get('function'))
pci_addrs.update([pci_addr])
pci_addrs.update([find_pci_addr(dom_xml, 'interface')])
pci_addrs.update([find_pci_addr(dom_xml, 'hostdev')])
# Update dictionary with per-domain information
domain = {