[Libguestfs] [PATCH 2/3] Avoid race conditions when nbdkit exits.

Eric Blake eblake at redhat.com
Tue Nov 14 18:28:31 UTC 2017


On 11/14/2017 11:30 AM, Richard W.M. Jones wrote:
> There are several race conditions where nbdkit exits (calling
> plugin_cleanup() which unloads the plugin), while the plugin is either
> in a callback or in plugin.close().
> 
> Avoid these by:
> 
> (1) Taking a shared lock around all plugin callbacks.
> 
> (2) Taking the same as an exclusive lock in plugin_cleanup.
> 
> This delays plugin_cleanup until all callbacks have finished.
> 
> (3) Removing a few unnecessary ‘assert (dl)’.
> 
> This is necessary because the plugin can now be unloaded while holding
> locks.  ‘dl’ is not needed to lock or unlock the plugin so asserting
> it is useless.
> 
> (4) Don't call plugin.close on the quit path.
> 
> Another thread could be unloading the plugin so we cannot call
> the .close callback.

Yes, this looks like it solves the same race in a much nicer manner.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20171114/c543a6d8/attachment.sig>


More information about the Libguestfs mailing list