libvirt/src/hypervisor
Erik Skultety 49cb59778a hostdev: mdev: Lookup mdevs by sysfs path rather than mdev struct
The lookup didn't do anything apart from comparing the sysfs paths
anyway since that's what makes each mdev unique.
The most ridiculous usage of the old logic was in
virHostdevReAttachMediatedDevices where in order to drop an mdev
hostdev from the list of active devices we first had to create a new
mdev and use it in the lookup call. Why couldn't we have used the
hostdev directly? Because the hostdev and mdev structures are
incompatible.

The way mdevs are currently removed is via a write to a specific sysfs
attribute. If you do it while the machine which has the mdev assigned
is running, the write call may block (with a new enough kernel, with
older kernels it would return a write error!) until the device
is no longer in use which is when the QEMU process exits.

The interesting part here comes afterwards when we're cleaning up and
call virHostdevReAttachMediatedDevices. The domain doesn't exist
anymore, so the list of active hostdevs needs to be updated and the
respective hostdevs removed from the list, but remember we had to
create an mdev object in the memory in order to find it in the list
first which will fail because the write to sysfs had already removed
the mdev instance from the host system.
And so the next time you try to start the same domain you'll get:

"Requested operation is not valid: mediated device <path> is in use by
driver QEMU, domain <name>"

Fixes: https://gitlab.com/libvirt/libvirt/-/issues/119

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-01-08 08:10:02 +01:00
..
domain_cgroup.c virsh: include virutil.h where used 2020-02-24 23:15:50 +01:00
domain_cgroup.h domain_cgroup.c: add virDomainCgroupSetMemoryLimitParameters() 2020-02-23 14:02:24 +01:00
domain_driver.c src: use g_new0 instead of VIR_ALLOC 2020-10-08 19:19:22 +02:00
domain_driver.h virDomainDriverGenerateMachineName: Factor out embed path hashing 2020-04-07 15:26:22 +02:00
meson.build meson: src: build libvirt.so library 2020-08-03 09:27:04 +02:00
virclosecallbacks.c util: hash: Retire 'virHashTable' in favor of 'GHashTable' 2020-11-06 10:40:51 +01:00
virclosecallbacks.h virclosecallbacks: move to src/hypervisor 2020-02-24 16:47:21 +01:00
virhostdev.c hostdev: mdev: Lookup mdevs by sysfs path rather than mdev struct 2021-01-08 08:10:02 +01:00
virhostdev.h virhostdev: move to src/hypervisor 2020-02-24 16:47:21 +01:00