[Libguestfs] [PATCH nbdkit 1/3] plugins: Move locking to a new file.

Richard W.M. Jones rjones at redhat.com
Tue Jan 16 15:51:56 UTC 2018


On Tue, Jan 16, 2018 at 09:37:09AM -0600, Eric Blake wrote:
> On 01/16/2018 08:11 AM, Richard W.M. Jones wrote:
> > Mostly code motion.
> > ---
> >  src/Makefile.am   |   1 +
> >  src/connections.c |  14 +++----
> >  src/internal.h    |  14 ++++---
> >  src/locks.c       | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  src/plugins.c     |  77 +++++-------------------------------
> >  5 files changed, 142 insertions(+), 79 deletions(-)
> > 
> 
> > +++ b/src/locks.c
> 
> > +void
> > +lock_connection (void)
> > +{
> > +  int thread_model = plugin_thread_model ();
> > +
> > +  if (thread_model <= NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS) {
> 
> > +++ b/src/plugins.c
> 
> > +int
> > +plugin_thread_model (void)
> > +{
> > +  assert (dl);
> > +
> > +  return plugin._thread_model;
> > +}
> 
> The new code asserts dl prior to locking the connection;
> 
> > +
> >  const char *
> >  plugin_name (void)
> >  {
> > @@ -312,67 +316,6 @@ plugin_config_complete (void)
> >      exit (EXIT_FAILURE);
> >  }
> >  
> > -/* Handle the thread model. */
> > -void
> > -plugin_lock_connection (void)
> > -{
> > -  if (plugin._thread_model <= NBDKIT_THREAD_MODEL_SERIALIZE_CONNECTIONS) {
> > -    debug ("%s: acquire connection lock", filename);
> > -    pthread_mutex_lock (&connection_lock);
> > -  }
> > -}
> 
> but the old code did not (and just blindly assumed that _thread_model is
> always valid).  Can that new assertion ever fire during racy unload
> sequences?
> 
> Otherwise, looks right to me.

I think we're OK, if only because the second patch drops this
assertion completely.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list