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.
This commit is contained in:
Stefan Berger 2010-04-30 08:10:12 -04:00
parent 59fe163f2f
commit ebacb31fb5
3 changed files with 35 additions and 1 deletions

View File

@ -937,10 +937,18 @@ _virNWFilterTeardownFilter(const char *ifname)
drvname); drvname);
return 1; return 1;
} }
virNWFilterTerminateLearnReq(ifname);
if (virNWFilterLockIface(ifname))
return 1;
techdriver->allTeardown(ifname); techdriver->allTeardown(ifname);
virNWFilterDelIpAddrForIfname(ifname); virNWFilterDelIpAddrForIfname(ifname);
virNWFilterUnlockIface(ifname);
return 0; return 0;
} }

View File

@ -243,8 +243,33 @@ virNWFilterRegisterLearnReq(virNWFilterIPAddrLearnReqPtr req) {
return res; return res;
} }
#endif #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 virNWFilterIPAddrLearnReqPtr
virNWFilterLookupLearnReq(int ifindex) { virNWFilterLookupLearnReq(int ifindex) {
@ -472,7 +497,7 @@ learnIPAddressThread(void *arg)
if (!packet) { if (!packet) {
if (threadsTerminate) { if (threadsTerminate || req->terminate) {
req->status = ECANCELED; req->status = ECANCELED;
showError = false; showError = false;
break; break;

View File

@ -46,6 +46,7 @@ struct _virNWFilterIPAddrLearnReq {
int status; int status;
pthread_t thread; pthread_t thread;
volatile bool terminate;
}; };
int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver, int virNWFilterLearnIPAddress(virNWFilterTechDriverPtr techdriver,