nodedev: fix xml output for mdev parents in test suite

Commit 51fbbfdce8 attempted to get the proper nodedev name for the
parent of an defined mdev by traversing the filesystem and looking for a
device that had the appropriate sysfs path.  This works, but it would be
cleaner to to avoid mucking around in the filesystem and instead just
just examine the list of devices we have in memory.

We already had a function nodeDeviceFindAddressByName() which constructs
an address for parent device in a format that can be used with mdevctl.
So if we refactor this function into a a function that simply formats an
address for an arbitrary virNodeDeviceObj*, then we can use this
function as a predicate for our new virNodeDeviceObjListFind() function
from the previous commit. This will search our list of devices for one
whose address matches the address we get from mdevctl.

One nice benefit of this approach is that our test cases will now
display xml output with the proper parent name for mdevs (assuming that
we've added the appropriate mock parent devices to the test driver).
Previously they just displayed 'computer' for the parent because the
alternative would have required specially constructing a mock filesystem
environment with a sysfs that mapped to the appropriate parent.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Jonathon Jongsma
2021-07-07 15:01:20 -05:00
parent fdfe4b2837
commit a9c1febcf4
3 changed files with 59 additions and 32 deletions

View File

@@ -1,6 +1,6 @@
<device>
<name>mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045</name>
<parent>computer</parent>
<parent>pci_0000_00_02_0</parent>
<capability type='mdev'>
<type id='i915-GVTg_V5_4'/>
<uuid>200f228a-c80a-4d50-bfb7-f5a0e4e34045</uuid>
@@ -9,7 +9,7 @@
</device>
<device>
<name>mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b</name>
<parent>computer</parent>
<parent>pci_0000_00_02_0</parent>
<capability type='mdev'>
<type id='i915-GVTg_V5_4'/>
<uuid>de807ffc-1923-4d5f-b6c9-b20ecebc6d4b</uuid>
@@ -18,7 +18,7 @@
</device>
<device>
<name>mdev_435722ea_5f43_468a_874f_da34f1217f13</name>
<parent>computer</parent>
<parent>pci_0000_00_02_0</parent>
<capability type='mdev'>
<type id='i915-GVTg_V5_8'/>
<uuid>435722ea-5f43-468a-874f-da34f1217f13</uuid>
@@ -28,7 +28,7 @@
</device>
<device>
<name>mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf</name>
<parent>computer</parent>
<parent>ap_matrix</parent>
<capability type='mdev'>
<type id='vfio_ap-passthrough'/>
<uuid>783e6dbb-ea0e-411f-94e2-717eaad438bf</uuid>