Remove driver dependency from nwfilter_conf.c

This patch removes the driver dependency from nwfilter_conf.c and moves
a callback function calling into the driver into
nwfilter_gentech_driver.c and passes a pointer to that callback function
upon initialization of nwfilter_conf.c.
This commit is contained in:
Stefan Berger 2010-03-30 10:25:22 -04:00
parent 285d38931f
commit 0af0ded038
5 changed files with 65 additions and 55 deletions

View File

@ -39,7 +39,6 @@
#include "nwfilter_params.h" #include "nwfilter_params.h"
#include "nwfilter_conf.h" #include "nwfilter_conf.h"
#include "domain_conf.h" #include "domain_conf.h"
#include "nwfilter/nwfilter_gentech_driver.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
@ -2140,56 +2139,7 @@ virNWFilterRegisterCallbackDriver(virNWFilterCallbackDriverPtr cbd)
} }
enum UpdateStep { static virHashIterator virNWFilterDomainFWUpdateCB;
STEP_APPLY_NEW,
STEP_TEAR_NEW,
STEP_TEAR_OLD,
};
struct cbStruct {
virConnectPtr conn;
enum UpdateStep step;
int err;
};
static void
virNWFilterDomainFWUpdateCB(void *payload,
const char *name ATTRIBUTE_UNUSED,
void *data)
{
virDomainObjPtr obj = payload;
virDomainDefPtr vm = obj->def;
struct cbStruct *cb = data;
int i;
virDomainObjLock(obj);
if (virDomainObjIsActive(obj)) {
for (i = 0; i < vm->nnets; i++) {
virDomainNetDefPtr net = vm->nets[i];
if ((net->filter) && (net->ifname)) {
switch (cb->step) {
case STEP_APPLY_NEW:
cb->err = virNWFilterUpdateInstantiateFilter(cb->conn,
net);
break;
case STEP_TEAR_NEW:
cb->err = virNWFilterRollbackUpdateFilter(cb->conn, net);
break;
case STEP_TEAR_OLD:
cb->err = virNWFilterTearOldFilter(cb->conn, net);
break;
}
if (cb->err)
break;
}
}
}
virDomainObjUnlock(obj);
}
static int static int
@ -2197,7 +2147,7 @@ virNWFilterTriggerVMFilterRebuild(virConnectPtr conn)
{ {
int i; int i;
int err; int err;
struct cbStruct cb = { struct domUpdateCBStruct cb = {
.conn = conn, .conn = conn,
.err = 0, .err = 0,
.step = STEP_APPLY_NEW, .step = STEP_APPLY_NEW,
@ -2793,8 +2743,10 @@ char *virNWFilterConfigFile(virConnectPtr conn ATTRIBUTE_UNUSED,
} }
int virNWFilterConfLayerInit(void) int virNWFilterConfLayerInit(virHashIterator domUpdateCB)
{ {
virNWFilterDomainFWUpdateCB = domUpdateCB;
if (virMutexInit(&updateMutex)) if (virMutexInit(&updateMutex))
return 1; return 1;

View File

@ -432,6 +432,19 @@ struct _virNWFilterRuleInst {
}; };
enum UpdateStep {
STEP_APPLY_NEW,
STEP_TEAR_NEW,
STEP_TEAR_OLD,
};
struct domUpdateCBStruct {
virConnectPtr conn;
enum UpdateStep step;
int err;
};
enum virDomainNetType; enum virDomainNetType;
typedef int (*virNWFilterRuleCreateInstance)(virConnectPtr conn, typedef int (*virNWFilterRuleCreateInstance)(virConnectPtr conn,
@ -546,7 +559,7 @@ virNWFilterDefPtr virNWFilterDefParseFile(virConnectPtr conn,
void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj); void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj);
void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj); void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj);
int virNWFilterConfLayerInit(void); int virNWFilterConfLayerInit(virHashIterator domUpdateCB);
void virNWFilterConfLayerShutdown(void); void virNWFilterConfLayerShutdown(void);
int virNWFilterParamConfLayerInit(void); int virNWFilterParamConfLayerInit(void);

View File

@ -34,6 +34,7 @@
#include "memory.h" #include "memory.h"
#include "domain_conf.h" #include "domain_conf.h"
#include "nwfilter_driver.h" #include "nwfilter_driver.h"
#include "nwfilter_gentech_driver.h"
#define VIR_FROM_THIS VIR_FROM_NWFILTER #define VIR_FROM_THIS VIR_FROM_NWFILTER
@ -64,7 +65,7 @@ static int
nwfilterDriverStartup(int privileged) { nwfilterDriverStartup(int privileged) {
char *base = NULL; char *base = NULL;
if (virNWFilterConfLayerInit() < 0) if (virNWFilterConfLayerInit(virNWFilterDomainFWUpdateCB) < 0)
return -1; return -1;
if (VIR_ALLOC(driverState) < 0) if (VIR_ALLOC(driverState) < 0)

View File

@ -681,3 +681,43 @@ virNWFilterTeardownFilter(const virDomainNetDefPtr net)
return 0; return 0;
} }
void
virNWFilterDomainFWUpdateCB(void *payload,
const char *name ATTRIBUTE_UNUSED,
void *data)
{
virDomainObjPtr obj = payload;
virDomainDefPtr vm = obj->def;
struct domUpdateCBStruct *cb = data;
int i;
virDomainObjLock(obj);
if (virDomainObjIsActive(obj)) {
for (i = 0; i < vm->nnets; i++) {
virDomainNetDefPtr net = vm->nets[i];
if ((net->filter) && (net->ifname)) {
switch (cb->step) {
case STEP_APPLY_NEW:
cb->err = virNWFilterUpdateInstantiateFilter(cb->conn,
net);
break;
case STEP_TEAR_NEW:
cb->err = virNWFilterRollbackUpdateFilter(cb->conn, net);
break;
case STEP_TEAR_OLD:
cb->err = virNWFilterTearOldFilter(cb->conn, net);
break;
}
if (cb->err)
break;
}
}
}
virDomainObjUnlock(obj);
}

View File

@ -51,4 +51,8 @@ int virNWFilterTeardownFilter(const virDomainNetDefPtr net);
virNWFilterHashTablePtr virNWFilterCreateVarHashmap(virConnectPtr conn, virNWFilterHashTablePtr virNWFilterCreateVarHashmap(virConnectPtr conn,
char *macaddr); char *macaddr);
void virNWFilterDomainFWUpdateCB(void *payload,
const char *name ATTRIBUTE_UNUSED,
void *data);
#endif #endif