diff options
author | 2010-04-30 08:10:12 -0400 | |
---|---|---|
committer | 2010-04-30 08:10:12 -0400 | |
commit | ebacb31fb5619bfe405107c53b9e27dc9724c29a (patch) | |
tree | 25f55b791b01e38140eabd748c6b900854d05a4e | |
parent | Clean all tables before applying 'basic' rules (diff) | |
download | libvirt-ebacb31fb5619bfe405107c53b9e27dc9724c29a.tar.gz libvirt-ebacb31fb5619bfe405107c53b9e27dc9724c29a.tar.bz2 libvirt-ebacb31fb5619bfe405107c53b9e27dc9724c29a.zip |
Syncronize the teardown of rules with the thread
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.
-rw-r--r-- | src/nwfilter/nwfilter_gentech_driver.c | 8 | ||||
-rw-r--r-- | src/nwfilter/nwfilter_learnipaddr.c | 27 | ||||
-rw-r--r-- | src/nwfilter/nwfilter_learnipaddr.h | 1 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 095dc9293..9fede3b67 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -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; } diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index 2bb777bad..71dc240b4 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -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; diff --git a/src/nwfilter/nwfilter_learnipaddr.h b/src/nwfilter/nwfilter_learnipaddr.h index 6f3cb7f20..ebe65c2c9 100644 --- a/src/nwfilter/nwfilter_learnipaddr.h +++ b/src/nwfilter/nwfilter_learnipaddr.h @@ -46,6 +46,7 @@ struct _virNWFilterIPAddrLearnReq { int status; pthread_t thread; + volatile bool terminate; }; int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, |