]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Syncronize the teardown of rules with the thread
authorStefan Berger <stefanb@us.ibm.com>
Fri, 30 Apr 2010 12:10:12 +0000 (08:10 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Fri, 30 Apr 2010 12:10:12 +0000 (08:10 -0400)
Introduce a function to notify the IP address learning
thread to terminate and thus release the lock on the interface.
Notify the thread before grabbing the lock on the interface
and tearing down the rules. This prevents a 'virsh destroy' to
tear down the rules that the IP address learning thread has
applied.

src/nwfilter/nwfilter_gentech_driver.c
src/nwfilter/nwfilter_learnipaddr.c
src/nwfilter/nwfilter_learnipaddr.h

index 095dc9293171f6e1022d7b4700a7d58ca5bdc574..9fede3b673bb37a5241de6fa9148e1827ea1381e 100644 (file)
@@ -937,10 +937,18 @@ _virNWFilterTeardownFilter(const char *ifname)
                                drvname);
         return 1;
     }
+
+    virNWFilterTerminateLearnReq(ifname);
+
+    if (virNWFilterLockIface(ifname))
+       return 1;
+
     techdriver->allTeardown(ifname);
 
     virNWFilterDelIpAddrForIfname(ifname);
 
+    virNWFilterUnlockIface(ifname);
+
     return 0;
 }
 
index 2bb777bad0aee8cd003466a01e3133e85e906a3f..71dc240b4f43bed66374607490106daaf733d8fe 100644 (file)
@@ -243,8 +243,33 @@ virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req) {
     return res;
 }
 
+
 #endif
 
+int
+virNWFilterTerminateLearnReq(const char *ifname) {
+    int rc = 1;
+    int ifindex;
+    virNWFilterIPAddrLearnReqPtr req;
+
+    if (ifaceGetIndex(false, ifname, &ifindex) == 0) {
+
+        IFINDEX2STR(ifindex_str, ifindex);
+
+        virMutexLock(&pendingLearnReqLock);
+
+        req = virHashLookup(pendingLearnReq, ifindex_str);
+        if (req) {
+            rc = 0;
+            req->terminate = true;
+        }
+
+        virMutexUnlock(&pendingLearnReqLock);
+    }
+
+    return rc;
+}
+
 
 virNWFilterIPAddrLearnReqPtr
 virNWFilterLookupLearnReq(int ifindex) {
@@ -472,7 +497,7 @@ learnIPAddressThread(void *arg)
 
         if (!packet) {
 
-            if (threadsTerminate) {
+            if (threadsTerminate || req->terminate) {
                 req->status = ECANCELED;
                 showError = false;
                 break;
index 6f3cb7f20147f32e92f547dd5f3089556c23cdc1..ebe65c2c9efaf39e0d6c4755ab3eda98cc246767 100644 (file)
@@ -46,6 +46,7 @@ struct _virNWFilterIPAddrLearnReq {
 
     int status;
     pthread_t thread;
+    volatile bool terminate;
 };
 
 int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,