]> git.ipfire.org Git - thirdparty/libvirt.git/commit
qemuDomainWaitForDeviceRemoval: recheck the value of priv->unplug.alias when timeout
authorzuoboqun <zuoboqun@baidu.com>
Mon, 5 Jun 2023 03:59:36 +0000 (11:59 +0800)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 26 Jun 2023 11:40:58 +0000 (13:40 +0200)
commitb7f7f07542fd2569fec2ae925330eea1e2989d40
treed59119e61977bd2989aa9750f7964cb3f4d2984b
parent2fbc1b05d900d1d3540e66bdb93a6642756b07d2
qemuDomainWaitForDeviceRemoval: recheck the value of priv->unplug.alias when timeout

When detaching a device, the following race condition may happen:
Once qemuDomainSignalDeviceRemoval() marks the device for
removal, it returns true, which means it is the caller
that marked the device for removal is going to remove the
device from domain definition.

But qemuDomainWaitForDeviceRemoval() may still receive
timeout from virDomainObjWaitUntil() which is implemented
by pthread_cond_timedwait() due to an unavoidable race
between the expiration of the timeout and the predicate
state(priv->unplug.alias) change.

And then qemuDomainWaitForDeviceRemoval() will return 0,
thus the caller will not remove the device from domain
definition.

In this situation, the device is still present in the domain
definition but doesn't exist in qemu anymore. Worse, there is
no way to remove it from the domain definition.

Solution is to recheck the value of priv->unplug.alias to
determine who is going to remove the device from domain
definition.

Signed-off-by: zuo boqun <zuoboqun@baidu.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/qemu/qemu_hotplug.c