<br><tt><font size=2>libvir-list-bounces@redhat.com wrote on 08/13/2010
10:44:51 AM:<br>
<br>
> Please respond to "Daniel P. Berrange"</font></tt>
<br><tt><font size=2>> <br>
> On Thu, Aug 12, 2010 at 02:18:26PM -0400, Stefan Berger wrote:<br>
> > Index: libvirt-acl/src/nwfilter/nwfilter_driver.c<br>
> > ===================================================================<br>
> > --- libvirt-acl.orig/src/nwfilter/nwfilter_driver.c<br>
> > +++ libvirt-acl/src/nwfilter/nwfilter_driver.c<br>
> > @@ -143,15 +143,25 @@ conf_init_err:<br>
> >   */<br>
> >  static int<br>
> >  nwfilterDriverReload(void) {<br>
> > +    virConnectPtr conn;<br>
> >      if (!driverState) {<br>
> >          return -1;<br>
> >      }<br>
> > <br>
> > -    nwfilterDriverLock(driverState);<br>
> > -    virNWFilterPoolLoadAllConfigs(NULL,<br>
> > - &driverState->pools,<br>
> > -                  
               driverState->configDir);<br>
> > -    nwfilterDriverUnlock(driverState);<br>
> > +    conn = virConnectOpen("qemu:///system");<br>
> > +<br>
> > +    if (conn) {<br>
> > +        /* shut down all threads -- qemud
for example will restart them */<br>
> > +        virNWFilterLearnThreadsTerminate();<br>
> > +<br>
> > +        nwfilterDriverLock(driverState);<br>
> > +        virNWFilterPoolLoadAllConfigs(conn,<br>
> > + &driverState->pools,<br>
> > +                  
                   driverState->configDir);<br>
> > +        nwfilterDriverUnlock(driverState);<br>
> > +<br>
> > +        virConnectClose(conn);<br>
> > +    }<br>
> > <br>
> >      return 0;<br>
> <br>
> There's a small indentation issue here</font></tt>
<br>
<br><tt><font size=2>Oh, will fix it.</font></tt>
<br><tt><font size=2><br>
> <br>
> <br>
> >  }<br>
> > Index: libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c<br>
> > ===================================================================<br>
> > --- libvirt-acl.orig/src/nwfilter/nwfilter_learnipaddr.c<br>
> > +++ libvirt-acl/src/nwfilter/nwfilter_learnipaddr.c<br>
> > @@ -855,6 +855,16 @@ virNWFilterLearnInit(void) {<br>
> >  }<br>
> > <br>
> > <br>
> > +void<br>
> > +virNWFilterLearnThreadsTerminate() {<br>
> > +    threadsTerminate = true;<br>
> > +<br>
> > +    while (virHashSize(pendingLearnReq) != 0)<br>
> > +        usleep((PKT_TIMEOUT_MS * 1000) /
3);<br>
> > +<br>
> > +    threadsTerminate = false;<br>
> > +}<br>
> <br>
> Is there any risk of thread's failing to terminate, requiring<br>
> us to kill them, or ignore them instead of blocking forever ?</font></tt>
<br>
<br><tt><font size=2>A thread may just have been created with pthread_create()
but hasn't run yet to see that threadTerminate is 'true' -> in that
case the virHashSize() would count the thread until the thread itself has
deregistered itself from the pendingLearnReq list. So that case should
be ok.</font></tt>
<br>
<br><tt><font size=2>Assume a thread is just about to be created (due to
a VM start for example) and registered with the call to rc = virNWFilterRegisterLearnReq(req)
preceding the pthread_create(), in that case a 'threadsTerminate = false'
would allow that thread to run then. So I guess the 'threadsTerminate =
false' is wrong in that case and would prevent the thread from terminating.
The challenge is to do this correctly for reloading of the driver and at
the same time for shutting down. If I take out the 'threadsTerminate =
false', all threads and those about to be born should terminate, which
does it correctly for the libvirtd termination case. But in case of reload
where I would want new threads to run again I should probably introduce
a boolean parameter indicating into what state the threadsTerminate variable
should go once this above function terminates.</font></tt>
<br>
<br><tt><font size=2>What that I would do the following changes:</font></tt>
<br>
<br><tt><font size=2>void<br>
virNWFilterLearnThreadsTerminate(bool allowNewThreads) {<br>
    threadsTerminate = true;<br>
<br>
    while (virHashSize(pendingLearnReq) != 0)<br>
        usleep((PKT_TIMEOUT_MS * 1000) / 3);<br>
<br>
    if (allowNewThreads)</font></tt>
<br><tt><font size=2>        threadsTerminate = false;</font></tt>
<br><tt><font size=2>}<br>
</font></tt>
<br>
<br><tt><font size=2>Above call (with the indentation error) would then
look like this:</font></tt>
<br>
<br><tt><font size=2>[...]</font></tt>
<br><tt><font size=2>    if (conn) {<br>
        /* shut down all threads -- qemud for example
will restart them */<br>
        virNWFilterLearnThreadsTerminate(true);<br>
</font></tt>
<br><tt><font size=2>        nwfilterDriverLock(driverState);<br>
        virNWFilterPoolLoadAllConfigs(conn,</font></tt>
<br><tt><font size=2>               
                     
&driverState->pools,<br>
                    
                 driverState->configDir);<br>
        nwfilterDriverUnlock(driverState);<br>
<br>
        virConnectClose(conn);<br>
    }<br>
[...]</font></tt>
<br>
<br><tt><font size=2>Does this sound right?</font></tt>
<br>
<br><tt><font size=2>   Stefan</font></tt>
<br><tt><font size=2><br>
> <br>
> Daniel<br>
> -- <br>
> |: Red Hat, Engineering, London    -o-   </font></tt><a href=http://people.redhat.com/berrange/:|><tt><font size=2>http://people.redhat.com/berrange/:|</font></tt></a><tt><font size=2><br>
> |: </font></tt><a href=http://libvirt.org/><tt><font size=2>http://libvirt.org</font></tt></a><tt><font size=2>
-o- </font></tt><a href="http://virt-manager.org/"><tt><font size=2>http://virt-manager.org</font></tt></a><tt><font size=2>
-o- </font></tt><a href=http://deltacloud.org:|/><tt><font size=2>http://deltacloud.org:|</font></tt></a><tt><font size=2><br>
> |: </font></tt><a href=http://autobuild.org/><tt><font size=2>http://autobuild.org</font></tt></a><tt><font size=2>
       -o-         </font></tt><a href=http://search.cpan.org/~danberr/:|><tt><font size=2>http://search.cpan.org/~danberr/:|</font></tt></a><tt><font size=2><br>
> |: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1
B3DF F742 7D3B 9505 :|<br>
> <br>
> --<br>
> libvir-list mailing list<br>
> libvir-list@redhat.com<br>
> </font></tt><a href="https://www.redhat.com/mailman/listinfo/libvir-list"><tt><font size=2>https://www.redhat.com/mailman/listinfo/libvir-list</font></tt></a><tt><font size=2><br>
</font></tt>