]> git.ipfire.org Git - thirdparty/libvirt.git/commit
nodedev: avoid delay when defining a new mdev
authorJonathon Jongsma <jjongsma@redhat.com>
Mon, 1 Mar 2021 20:36:10 +0000 (14:36 -0600)
committerJonathon Jongsma <jjongsma@redhat.com>
Wed, 7 Apr 2021 20:25:28 +0000 (15:25 -0500)
commitafda589d0574bd30b96f0d43489194f5b4c05355
treea15f151d01b7d8d6c5e6e52c3a9ae83d6366ab69
parent9e8e93dc6afbd2d5c9a7606983a24190e6105d77
nodedev: avoid delay when defining a new mdev

When calling virNodeDeviceDefineXML() to define a new mediated device,
we call virMdevctlDefine() and then wait for the new device to appear in
the driver's device list before returning. This caused long delays due
to the behavior of nodeDeviceFindNewMediatedDevice(). This function
checks to see if the device is in the list and then waits for 5s before
checking again.

Because mdevctl is relatively slow to query the list of defined
devices[0], the newly-defined device was generally not in the device
list when we first checked. This results in libvirt almost always taking
at least 5s to complete this API call for mediated devices, which is
unacceptable.

In order to avoid this long delay, we resort to a workaround. If the
call to virMdevctlDefine() was successful, we can assume that this new
device will exist the next time we query mdevctl for new devices. So we
simply add this provisional device definition directly to the nodedev
driver's device list and return from the function. At some point in the
future, the mdevctl handler will run and the "official" device will be
processed, which will update the provisional device if any new details
need to be added.

The reason that this is not necessary for virNodeDeviceCreateXML() is
because detecting newly-created (not defined) mdevs happens through
udev instead of mdevctl. And nodeDeviceFindNewMediatedDevice() always
calls 'udevadm settle' before checking to see whether the device is in
the list. This allows us to wait just long enough for all udev events to
be processed, so the device is almost always in the list the first time
we check and so we almost never end up hitting the 5s sleep.

[0] on my machine, 'mdevctl list --defined' took around 0.8s to
complete for only 3 defined mdevs.

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/node_device/node_device_driver.c