]> git.ipfire.org Git - thirdparty/libvirt.git/commit
nodedev: fix race in API usage vs initial device enumeration
authorDaniel P. Berrangé <berrange@redhat.com>
Fri, 13 Mar 2020 11:53:25 +0000 (11:53 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Mon, 16 Mar 2020 17:35:04 +0000 (17:35 +0000)
commit008abeb03c262149b756ad5a226ff6cbc5e37e2c
treedeb0ee7f7403f9f055c9d24329b8eb37238b8d26
parent530ac288618b2f46e49f3ce86d4d89e7607ee3fe
nodedev: fix race in API usage vs initial device enumeration

During startup the udev node device driver impl uses a background thread
to populate the list of devices to avoid blocking the daemon startup
entirely. There is no synchronization to the public APIs, so it is
possible for an application to start calling APIs before the device
initialization is complete.

This was not a problem in the old approach where libvirtd was started
on boot, as initialization would easily complete before any APIs were
called.

With the use of socket activation, however, APIs are invoked from the
very moment the daemon starts. This is easily seen by doing a

  'virsh -c nodedev:///system list'

the first time it runs it will only show one or two devices. The second
time it runs it will show all devices. The solution is to introduce a
flag and condition variable for APIs to synchronize against before
returning any data.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/virnodedeviceobj.h
src/node_device/node_device_driver.c
src/node_device/node_device_hal.c
src/node_device/node_device_udev.c