mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 05:17:59 +03:00
Simplify "NWFilterPool" to "NWFilter"
The public object is called NWFilter but the corresponding private object is called NWFilterPool. I don't see compelling reasons for this Pool suffix. One might argue that an NWFilter is a "pool" of rules, etc. Remove the Pool suffix from NWFilterPool. No functional change included.
This commit is contained in:
parent
f002e9218d
commit
2c0db5b5dc
8
cfg.mk
8
cfg.mk
@ -116,7 +116,7 @@ useless_free_options = \
|
||||
--name=virNWFilterHashTableFree \
|
||||
--name=virNWFilterIPAddrLearnReqFree \
|
||||
--name=virNWFilterIncludeDefFree \
|
||||
--name=virNWFilterPoolObjFree \
|
||||
--name=virNWFilterObjFree \
|
||||
--name=virNWFilterRuleDefFree \
|
||||
--name=virNWFilterRuleInstFree \
|
||||
--name=virNetworkDefFree \
|
||||
@ -194,9 +194,9 @@ useless_free_options = \
|
||||
# y virNWFilterHashTableFree
|
||||
# y virNWFilterIPAddrLearnReqFree
|
||||
# y virNWFilterIncludeDefFree
|
||||
# n virNWFilterPoolFreeName (returns int)
|
||||
# y virNWFilterPoolObjFree
|
||||
# n virNWFilterPoolObjListFree FIXME
|
||||
# n virNWFilterFreeName (returns int)
|
||||
# y virNWFilterObjFree
|
||||
# n virNWFilterObjListFree FIXME
|
||||
# y virNWFilterRuleDefFree
|
||||
# n virNWFilterRuleFreeInstanceData (typedef)
|
||||
# y virNWFilterRuleInstFree
|
||||
|
@ -299,7 +299,8 @@ virNWFilterDefFree(virNWFilterDefPtr def) {
|
||||
|
||||
|
||||
void
|
||||
virNWFilterPoolObjFree(virNWFilterPoolObjPtr obj) {
|
||||
virNWFilterObjFree(virNWFilterObjPtr obj)
|
||||
{
|
||||
if (!obj)
|
||||
return;
|
||||
|
||||
@ -315,13 +316,13 @@ virNWFilterPoolObjFree(virNWFilterPoolObjPtr obj) {
|
||||
|
||||
|
||||
void
|
||||
virNWFilterPoolObjListFree(virNWFilterPoolObjListPtr pools)
|
||||
virNWFilterObjListFree(virNWFilterObjListPtr nwfilters)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0 ; i < pools->count ; i++)
|
||||
virNWFilterPoolObjFree(pools->objs[i]);
|
||||
VIR_FREE(pools->objs);
|
||||
pools->count = 0;
|
||||
for (i = 0 ; i < nwfilters->count ; i++)
|
||||
virNWFilterObjFree(nwfilters->objs[i]);
|
||||
VIR_FREE(nwfilters->objs);
|
||||
nwfilters->count = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -382,31 +383,31 @@ virNWFilterRuleDefAddString(virNWFilterRuleDefPtr nwf,
|
||||
|
||||
|
||||
void
|
||||
virNWFilterPoolObjRemove(virNWFilterPoolObjListPtr pools,
|
||||
virNWFilterPoolObjPtr pool)
|
||||
virNWFilterObjRemove(virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterObjPtr nwfilter)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
|
||||
for (i = 0 ; i < pools->count ; i++) {
|
||||
virNWFilterPoolObjLock(pools->objs[i]);
|
||||
if (pools->objs[i] == pool) {
|
||||
virNWFilterPoolObjUnlock(pools->objs[i]);
|
||||
virNWFilterPoolObjFree(pools->objs[i]);
|
||||
for (i = 0 ; i < nwfilters->count ; i++) {
|
||||
virNWFilterObjLock(nwfilters->objs[i]);
|
||||
if (nwfilters->objs[i] == nwfilter) {
|
||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
||||
virNWFilterObjFree(nwfilters->objs[i]);
|
||||
|
||||
if (i < (pools->count - 1))
|
||||
memmove(pools->objs + i, pools->objs + i + 1,
|
||||
sizeof(*(pools->objs)) * (pools->count - (i + 1)));
|
||||
if (i < (nwfilters->count - 1))
|
||||
memmove(nwfilters->objs + i, nwfilters->objs + i + 1,
|
||||
sizeof(*(nwfilters->objs)) * (nwfilters->count - (i + 1)));
|
||||
|
||||
if (VIR_REALLOC_N(pools->objs, pools->count - 1) < 0) {
|
||||
if (VIR_REALLOC_N(nwfilters->objs, nwfilters->count - 1) < 0) {
|
||||
; /* Failure to reduce memory allocation isn't fatal */
|
||||
}
|
||||
pools->count--;
|
||||
nwfilters->count--;
|
||||
|
||||
break;
|
||||
}
|
||||
virNWFilterPoolObjUnlock(pools->objs[i]);
|
||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1998,7 +1999,7 @@ virNWFilterDefParseNode(xmlDocPtr xml,
|
||||
if (STRNEQ((const char *)root->name, "filter")) {
|
||||
virNWFilterReportError(VIR_ERR_XML_ERROR,
|
||||
"%s",
|
||||
_("unknown root element for nw filter pool"));
|
||||
_("unknown root element for nw filter"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -2089,34 +2090,33 @@ virNWFilterDefParseFile(virConnectPtr conn,
|
||||
}
|
||||
|
||||
|
||||
virNWFilterPoolObjPtr
|
||||
virNWFilterPoolObjFindByUUID(virNWFilterPoolObjListPtr pools,
|
||||
const unsigned char *uuid)
|
||||
virNWFilterObjPtr
|
||||
virNWFilterObjFindByUUID(virNWFilterObjListPtr nwfilters,
|
||||
const unsigned char *uuid)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < pools->count ; i++) {
|
||||
virNWFilterPoolObjLock(pools->objs[i]);
|
||||
if (!memcmp(pools->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
|
||||
return pools->objs[i];
|
||||
virNWFilterPoolObjUnlock(pools->objs[i]);
|
||||
for (i = 0 ; i < nwfilters->count ; i++) {
|
||||
virNWFilterObjLock(nwfilters->objs[i]);
|
||||
if (!memcmp(nwfilters->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
|
||||
return nwfilters->objs[i];
|
||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
virNWFilterPoolObjPtr
|
||||
virNWFilterPoolObjFindByName(virNWFilterPoolObjListPtr pools,
|
||||
const char *name)
|
||||
virNWFilterObjPtr
|
||||
virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters, const char *name)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0 ; i < pools->count ; i++) {
|
||||
virNWFilterPoolObjLock(pools->objs[i]);
|
||||
if (STREQ(pools->objs[i]->def->name, name))
|
||||
return pools->objs[i];
|
||||
virNWFilterPoolObjUnlock(pools->objs[i]);
|
||||
for (i = 0 ; i < nwfilters->count ; i++) {
|
||||
virNWFilterObjLock(nwfilters->objs[i]);
|
||||
if (STREQ(nwfilters->objs[i]->def->name, name))
|
||||
return nwfilters->objs[i];
|
||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -2197,14 +2197,14 @@ cleanup:
|
||||
|
||||
static int
|
||||
_virNWFilterDefLoopDetect(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterDefPtr def,
|
||||
const char *filtername)
|
||||
{
|
||||
int rc = 0;
|
||||
int i;
|
||||
virNWFilterEntryPtr entry;
|
||||
virNWFilterPoolObjPtr obj;
|
||||
virNWFilterObjPtr obj;
|
||||
|
||||
if (!def)
|
||||
return 0;
|
||||
@ -2218,14 +2218,13 @@ _virNWFilterDefLoopDetect(virConnectPtr conn,
|
||||
break;
|
||||
}
|
||||
|
||||
obj = virNWFilterPoolObjFindByName(pools,
|
||||
entry->include->filterref);
|
||||
obj = virNWFilterObjFindByName(nwfilters,
|
||||
entry->include->filterref);
|
||||
if (obj) {
|
||||
rc = _virNWFilterDefLoopDetect(conn,
|
||||
pools,
|
||||
rc = _virNWFilterDefLoopDetect(conn, nwfilters,
|
||||
obj->def, filtername);
|
||||
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
if (rc)
|
||||
break;
|
||||
}
|
||||
@ -2239,7 +2238,7 @@ _virNWFilterDefLoopDetect(virConnectPtr conn,
|
||||
/*
|
||||
* virNWFilterDefLoopDetect:
|
||||
* @conn: pointer to virConnect object
|
||||
* @pools : the pools to search
|
||||
* @nwfilters : the nwfilters to search
|
||||
* @def : the filter definiton that may add a loop and is to be tested
|
||||
*
|
||||
* Detect a loop introduced through the filters being able to
|
||||
@ -2249,10 +2248,10 @@ _virNWFilterDefLoopDetect(virConnectPtr conn,
|
||||
*/
|
||||
static int
|
||||
virNWFilterDefLoopDetect(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterDefPtr def)
|
||||
{
|
||||
return _virNWFilterDefLoopDetect(conn, pools, def, def->name);
|
||||
return _virNWFilterDefLoopDetect(conn, nwfilters, def, def->name);
|
||||
}
|
||||
|
||||
int nCallbackDriver;
|
||||
@ -2339,104 +2338,104 @@ virNWFilterTriggerVMFilterRebuild(virConnectPtr conn)
|
||||
|
||||
int
|
||||
virNWFilterTestUnassignDef(virConnectPtr conn,
|
||||
virNWFilterPoolObjPtr pool)
|
||||
virNWFilterObjPtr nwfilter)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
virNWFilterLockFilterUpdates();
|
||||
|
||||
pool->wantRemoved = 1;
|
||||
nwfilter->wantRemoved = 1;
|
||||
// trigger the update on VMs referencing the filter
|
||||
if (virNWFilterTriggerVMFilterRebuild(conn))
|
||||
rc = 1;
|
||||
|
||||
pool->wantRemoved = 0;
|
||||
nwfilter->wantRemoved = 0;
|
||||
virNWFilterUnlockFilterUpdates();
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
virNWFilterPoolObjPtr
|
||||
virNWFilterPoolObjAssignDef(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
virNWFilterDefPtr def)
|
||||
virNWFilterObjPtr
|
||||
virNWFilterObjAssignDef(virConnectPtr conn,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterDefPtr def)
|
||||
{
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
|
||||
pool = virNWFilterPoolObjFindByUUID(pools, def->uuid);
|
||||
nwfilter = virNWFilterObjFindByUUID(nwfilters, def->uuid);
|
||||
|
||||
if (pool) {
|
||||
if (!STREQ(def->name, pool->def->name)) {
|
||||
if (nwfilter) {
|
||||
if (!STREQ(def->name, nwfilter->def->name)) {
|
||||
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
|
||||
_("filter with same UUID but different name "
|
||||
"('%s') already exists"),
|
||||
pool->def->name);
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
_("filter with same UUID but different name "
|
||||
"('%s') already exists"),
|
||||
nwfilter->def->name);
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
return NULL;
|
||||
}
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
}
|
||||
|
||||
if (virNWFilterDefLoopDetect(conn, pools, def)) {
|
||||
if (virNWFilterDefLoopDetect(conn, nwfilters, def)) {
|
||||
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
|
||||
"%s", _("filter would introduce a loop"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((pool = virNWFilterPoolObjFindByName(pools, def->name))) {
|
||||
if ((nwfilter = virNWFilterObjFindByName(nwfilters, def->name))) {
|
||||
virNWFilterLockFilterUpdates();
|
||||
pool->newDef = def;
|
||||
nwfilter->newDef = def;
|
||||
// trigger the update on VMs referencing the filter
|
||||
if (virNWFilterTriggerVMFilterRebuild(conn)) {
|
||||
pool->newDef = NULL;
|
||||
nwfilter->newDef = NULL;
|
||||
virNWFilterUnlockFilterUpdates();
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virNWFilterDefFree(pool->def);
|
||||
pool->def = def;
|
||||
pool->newDef = NULL;
|
||||
virNWFilterDefFree(nwfilter->def);
|
||||
nwfilter->def = def;
|
||||
nwfilter->newDef = NULL;
|
||||
virNWFilterUnlockFilterUpdates();
|
||||
return pool;
|
||||
return nwfilter;
|
||||
}
|
||||
|
||||
if (VIR_ALLOC(pool) < 0) {
|
||||
if (VIR_ALLOC(nwfilter) < 0) {
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virMutexInitRecursive(&pool->lock) < 0) {
|
||||
if (virMutexInitRecursive(&nwfilter->lock) < 0) {
|
||||
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"%s", _("cannot initialize mutex"));
|
||||
VIR_FREE(pool);
|
||||
VIR_FREE(nwfilter);
|
||||
return NULL;
|
||||
}
|
||||
virNWFilterPoolObjLock(pool);
|
||||
pool->active = 0;
|
||||
pool->def = def;
|
||||
virNWFilterObjLock(nwfilter);
|
||||
nwfilter->active = 0;
|
||||
nwfilter->def = def;
|
||||
|
||||
if (VIR_REALLOC_N(pools->objs, pools->count+1) < 0) {
|
||||
pool->def = NULL;
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
virNWFilterPoolObjFree(pool);
|
||||
if (VIR_REALLOC_N(nwfilters->objs, nwfilters->count + 1) < 0) {
|
||||
nwfilter->def = NULL;
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
virNWFilterObjFree(nwfilter);
|
||||
virReportOOMError();
|
||||
return NULL;
|
||||
}
|
||||
pools->objs[pools->count++] = pool;
|
||||
nwfilters->objs[nwfilters->count++] = nwfilter;
|
||||
|
||||
return pool;
|
||||
return nwfilter;
|
||||
}
|
||||
|
||||
|
||||
static virNWFilterPoolObjPtr
|
||||
virNWFilterPoolObjLoad(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
const char *file,
|
||||
const char *path)
|
||||
static virNWFilterObjPtr
|
||||
virNWFilterObjLoad(virConnectPtr conn,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
const char *file,
|
||||
const char *path)
|
||||
{
|
||||
virNWFilterDefPtr def;
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
|
||||
if (!(def = virNWFilterDefParseFile(conn, path))) {
|
||||
return NULL;
|
||||
@ -2444,33 +2443,33 @@ virNWFilterPoolObjLoad(virConnectPtr conn,
|
||||
|
||||
if (!virFileMatchesNameSuffix(file, def->name, ".xml")) {
|
||||
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
|
||||
_("network filter pool config filename '%s' does not match pool name '%s'"),
|
||||
_("network filter config filename '%s' does not match name '%s'"),
|
||||
path, def->name);
|
||||
virNWFilterDefFree(def);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!(pool = virNWFilterPoolObjAssignDef(conn, pools, def))) {
|
||||
if (!(nwfilter = virNWFilterObjAssignDef(conn, nwfilters, def))) {
|
||||
virNWFilterDefFree(def);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
VIR_FREE(pool->configFile); // for driver reload
|
||||
pool->configFile = strdup(path);
|
||||
if (pool->configFile == NULL) {
|
||||
VIR_FREE(nwfilter->configFile); // for driver reload
|
||||
nwfilter->configFile = strdup(path);
|
||||
if (nwfilter->configFile == NULL) {
|
||||
virReportOOMError();
|
||||
virNWFilterDefFree(def);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pool;
|
||||
return nwfilter;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virNWFilterPoolLoadAllConfigs(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
const char *configDir)
|
||||
virNWFilterLoadAllConfigs(virConnectPtr conn,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
const char *configDir)
|
||||
{
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
@ -2486,7 +2485,7 @@ virNWFilterPoolLoadAllConfigs(virConnectPtr conn,
|
||||
|
||||
while ((entry = readdir(dir))) {
|
||||
char path[PATH_MAX];
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
|
||||
if (entry->d_name[0] == '.')
|
||||
continue;
|
||||
@ -2502,9 +2501,9 @@ virNWFilterPoolLoadAllConfigs(virConnectPtr conn,
|
||||
continue;
|
||||
}
|
||||
|
||||
pool = virNWFilterPoolObjLoad(conn, pools, entry->d_name, path);
|
||||
if (pool)
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
nwfilter = virNWFilterObjLoad(conn, nwfilters, entry->d_name, path);
|
||||
if (nwfilter)
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
}
|
||||
|
||||
closedir(dir);
|
||||
@ -2514,15 +2513,15 @@ virNWFilterPoolLoadAllConfigs(virConnectPtr conn,
|
||||
|
||||
|
||||
int
|
||||
virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
virNWFilterPoolObjPtr pool,
|
||||
virNWFilterDefPtr def)
|
||||
virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
virNWFilterObjPtr nwfilter,
|
||||
virNWFilterDefPtr def)
|
||||
{
|
||||
char *xml;
|
||||
int fd = -1, ret = -1;
|
||||
ssize_t towrite;
|
||||
|
||||
if (!pool->configFile) {
|
||||
if (!nwfilter->configFile) {
|
||||
int err;
|
||||
char path[PATH_MAX];
|
||||
|
||||
@ -2539,7 +2538,7 @@ virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
"%s", _("cannot construct config file path"));
|
||||
return -1;
|
||||
}
|
||||
if (!(pool->configFile = strdup(path))) {
|
||||
if (!(nwfilter->configFile = strdup(path))) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
@ -2551,12 +2550,12 @@ virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((fd = open(pool->configFile,
|
||||
if ((fd = open(nwfilter->configFile,
|
||||
O_WRONLY | O_CREAT | O_TRUNC,
|
||||
S_IRUSR | S_IWUSR )) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("cannot create config file %s"),
|
||||
pool->configFile);
|
||||
nwfilter->configFile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -2564,14 +2563,14 @@ virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
if (safewrite(fd, xml, towrite) != towrite) {
|
||||
virReportSystemError(errno,
|
||||
_("cannot write config file %s"),
|
||||
pool->configFile);
|
||||
nwfilter->configFile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (VIR_CLOSE(fd) < 0) {
|
||||
virReportSystemError(errno,
|
||||
_("cannot save config file %s"),
|
||||
pool->configFile);
|
||||
nwfilter->configFile);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
@ -2587,18 +2586,18 @@ virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
|
||||
|
||||
int
|
||||
virNWFilterPoolObjDeleteDef(virNWFilterPoolObjPtr pool)
|
||||
virNWFilterObjDeleteDef(virNWFilterObjPtr nwfilter)
|
||||
{
|
||||
if (!pool->configFile) {
|
||||
if (!nwfilter->configFile) {
|
||||
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("no config file for %s"), pool->def->name);
|
||||
_("no config file for %s"), nwfilter->def->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (unlink(pool->configFile) < 0) {
|
||||
if (unlink(nwfilter->configFile) < 0) {
|
||||
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("cannot remove config for %s"),
|
||||
pool->def->name);
|
||||
nwfilter->def->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -2900,12 +2899,12 @@ void virNWFilterConfLayerShutdown(void)
|
||||
}
|
||||
|
||||
|
||||
void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj)
|
||||
void virNWFilterObjLock(virNWFilterObjPtr obj)
|
||||
{
|
||||
virMutexLock(&obj->lock);
|
||||
}
|
||||
|
||||
void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj)
|
||||
void virNWFilterObjUnlock(virNWFilterObjPtr obj)
|
||||
{
|
||||
virMutexUnlock(&obj->lock);
|
||||
}
|
||||
|
@ -441,10 +441,10 @@ struct _virNWFilterDef {
|
||||
};
|
||||
|
||||
|
||||
typedef struct _virNWFilterPoolObj virNWFilterPoolObj;
|
||||
typedef virNWFilterPoolObj *virNWFilterPoolObjPtr;
|
||||
typedef struct _virNWFilterObj virNWFilterObj;
|
||||
typedef virNWFilterObj *virNWFilterObjPtr;
|
||||
|
||||
struct _virNWFilterPoolObj {
|
||||
struct _virNWFilterObj {
|
||||
virMutex lock;
|
||||
|
||||
char *configFile;
|
||||
@ -456,11 +456,11 @@ struct _virNWFilterPoolObj {
|
||||
};
|
||||
|
||||
|
||||
typedef struct _virNWFilterPoolObjList virNWFilterPoolObjList;
|
||||
typedef virNWFilterPoolObjList *virNWFilterPoolObjListPtr;
|
||||
struct _virNWFilterPoolObjList {
|
||||
typedef struct _virNWFilterObjList virNWFilterObjList;
|
||||
typedef virNWFilterObjList *virNWFilterObjListPtr;
|
||||
struct _virNWFilterObjList {
|
||||
unsigned int count;
|
||||
virNWFilterPoolObjPtr *objs;
|
||||
virNWFilterObjPtr *objs;
|
||||
};
|
||||
|
||||
|
||||
@ -469,7 +469,7 @@ typedef virNWFilterDriverState *virNWFilterDriverStatePtr;
|
||||
struct _virNWFilterDriverState {
|
||||
virMutex lock;
|
||||
|
||||
virNWFilterPoolObjList pools;
|
||||
virNWFilterObjList nwfilters;
|
||||
|
||||
char *configDir;
|
||||
};
|
||||
@ -583,33 +583,31 @@ struct _virNWFilterTechDriver {
|
||||
void virNWFilterRuleDefFree(virNWFilterRuleDefPtr def);
|
||||
|
||||
void virNWFilterDefFree(virNWFilterDefPtr def);
|
||||
void virNWFilterPoolObjListFree(virNWFilterPoolObjListPtr pools);
|
||||
void virNWFilterPoolObjRemove(virNWFilterPoolObjListPtr pools,
|
||||
virNWFilterPoolObjPtr pool);
|
||||
void virNWFilterObjListFree(virNWFilterObjListPtr nwfilters);
|
||||
void virNWFilterObjRemove(virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterObjPtr nwfilter);
|
||||
|
||||
void virNWFilterPoolObjFree(virNWFilterPoolObjPtr obj);
|
||||
void virNWFilterObjFree(virNWFilterObjPtr obj);
|
||||
|
||||
virNWFilterPoolObjPtr
|
||||
virNWFilterPoolObjFindByUUID(virNWFilterPoolObjListPtr pools,
|
||||
const unsigned char *uuid);
|
||||
virNWFilterObjPtr virNWFilterObjFindByUUID(virNWFilterObjListPtr nwfilters,
|
||||
const unsigned char *uuid);
|
||||
|
||||
virNWFilterPoolObjPtr
|
||||
virNWFilterPoolObjFindByName(virNWFilterPoolObjListPtr pools,
|
||||
const char *name);
|
||||
virNWFilterObjPtr virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters,
|
||||
const char *name);
|
||||
|
||||
|
||||
int virNWFilterPoolObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
virNWFilterPoolObjPtr pool,
|
||||
virNWFilterDefPtr def);
|
||||
int virNWFilterObjSaveDef(virNWFilterDriverStatePtr driver,
|
||||
virNWFilterObjPtr nwfilter,
|
||||
virNWFilterDefPtr def);
|
||||
|
||||
int virNWFilterPoolObjDeleteDef(virNWFilterPoolObjPtr pool);
|
||||
int virNWFilterObjDeleteDef(virNWFilterObjPtr nwfilter);
|
||||
|
||||
virNWFilterPoolObjPtr virNWFilterPoolObjAssignDef(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
virNWFilterDefPtr def);
|
||||
virNWFilterObjPtr virNWFilterObjAssignDef(virConnectPtr conn,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterDefPtr def);
|
||||
|
||||
int virNWFilterTestUnassignDef(virConnectPtr conn,
|
||||
virNWFilterPoolObjPtr pool);
|
||||
virNWFilterObjPtr nwfilter);
|
||||
|
||||
virNWFilterDefPtr virNWFilterDefParseNode(xmlDocPtr xml,
|
||||
xmlNodePtr root);
|
||||
@ -623,9 +621,9 @@ int virNWFilterSaveXML(const char *configDir,
|
||||
int virNWFilterSaveConfig(const char *configDir,
|
||||
virNWFilterDefPtr def);
|
||||
|
||||
int virNWFilterPoolLoadAllConfigs(virConnectPtr conn,
|
||||
virNWFilterPoolObjListPtr pools,
|
||||
const char *configDir);
|
||||
int virNWFilterLoadAllConfigs(virConnectPtr conn,
|
||||
virNWFilterObjListPtr nwfilters,
|
||||
const char *configDir);
|
||||
|
||||
char *virNWFilterConfigFile(const char *dir,
|
||||
const char *name);
|
||||
@ -635,8 +633,8 @@ virNWFilterDefPtr virNWFilterDefParseString(virConnectPtr conn,
|
||||
virNWFilterDefPtr virNWFilterDefParseFile(virConnectPtr conn,
|
||||
const char *filename);
|
||||
|
||||
void virNWFilterPoolObjLock(virNWFilterPoolObjPtr obj);
|
||||
void virNWFilterPoolObjUnlock(virNWFilterPoolObjPtr obj);
|
||||
void virNWFilterObjLock(virNWFilterObjPtr obj);
|
||||
void virNWFilterObjUnlock(virNWFilterObjPtr obj);
|
||||
|
||||
void virNWFilterLockFilterUpdates(void);
|
||||
void virNWFilterUnlockFilterUpdates(void);
|
||||
|
@ -126,17 +126,17 @@ virSecretFreeName(virSecretPtr secret, const char *name ATTRIBUTE_UNUSED)
|
||||
}
|
||||
|
||||
/**
|
||||
* virNWFilterPoolFreeName:
|
||||
* @pool: a nwfilter pool object
|
||||
* virNWFilterFreeName:
|
||||
* @nwfilter: a nwfilter object
|
||||
*
|
||||
* Destroy the nwfilter pool object, this is just used by the nwfilter pool hash callback.
|
||||
* Destroy the nwfilter object, this is just used by the nwfilter hash callback.
|
||||
*
|
||||
* Returns 0 in case of success and -1 in case of failure.
|
||||
*/
|
||||
static int
|
||||
virNWFilterPoolFreeName(virNWFilterPtr pool, const char *name ATTRIBUTE_UNUSED)
|
||||
virNWFilterFreeName(virNWFilterPtr nwfilter, const char *name ATTRIBUTE_UNUSED)
|
||||
{
|
||||
return (virUnrefNWFilter(pool));
|
||||
return virUnrefNWFilter(nwfilter);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -200,8 +200,8 @@ virGetConnect(void) {
|
||||
ret->secrets = virHashCreate(20);
|
||||
if (ret->secrets == NULL)
|
||||
goto failed;
|
||||
ret->nwfilterPools = virHashCreate(20);
|
||||
if (ret->nwfilterPools == NULL)
|
||||
ret->nwfilters = virHashCreate(20);
|
||||
if (ret->nwfilters == NULL)
|
||||
goto failed;
|
||||
|
||||
ret->refs = 1;
|
||||
@ -223,8 +223,8 @@ failed:
|
||||
virHashFree(ret->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
|
||||
if (ret->secrets != NULL)
|
||||
virHashFree(ret->secrets, (virHashDeallocator) virSecretFreeName);
|
||||
if (ret->nwfilterPools != NULL)
|
||||
virHashFree(ret->nwfilterPools, (virHashDeallocator) virNWFilterPoolFreeName);
|
||||
if (ret->nwfilters != NULL)
|
||||
virHashFree(ret->nwfilters, (virHashDeallocator) virNWFilterFreeName);
|
||||
|
||||
virMutexDestroy(&ret->lock);
|
||||
VIR_FREE(ret);
|
||||
@ -281,8 +281,8 @@ virReleaseConnect(virConnectPtr conn) {
|
||||
virHashFree(conn->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
|
||||
if (conn->secrets != NULL)
|
||||
virHashFree(conn->secrets, (virHashDeallocator) virSecretFreeName);
|
||||
if (conn->nwfilterPools != NULL)
|
||||
virHashFree(conn->nwfilterPools, (virHashDeallocator) virNWFilterPoolFreeName);
|
||||
if (conn->nwfilters != NULL)
|
||||
virHashFree(conn->nwfilters, (virHashDeallocator) virNWFilterFreeName);
|
||||
|
||||
virResetError(&conn->err);
|
||||
|
||||
@ -1466,7 +1466,7 @@ int virUnrefStream(virStreamPtr st) {
|
||||
* Lookup if the network filter is already registered for that connection,
|
||||
* if yes return a new pointer to it, if no allocate a new structure,
|
||||
* and register it in the table. In any case a corresponding call to
|
||||
* virFreeNWFilterPool() is needed to not leak data.
|
||||
* virUnrefNWFilter() is needed to not leak data.
|
||||
*
|
||||
* Returns a pointer to the network, or NULL in case of failure
|
||||
*/
|
||||
@ -1491,7 +1491,7 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
|
||||
|
||||
virUUIDFormat(uuid, uuidstr);
|
||||
|
||||
ret = (virNWFilterPtr) virHashLookup(conn->nwfilterPools, uuidstr);
|
||||
ret = (virNWFilterPtr) virHashLookup(conn->nwfilters, uuidstr);
|
||||
if (ret == NULL) {
|
||||
if (VIR_ALLOC(ret) < 0) {
|
||||
virMutexUnlock(&conn->lock);
|
||||
@ -1508,10 +1508,10 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
|
||||
ret->conn = conn;
|
||||
memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
|
||||
|
||||
if (virHashAddEntry(conn->nwfilterPools, uuidstr, ret) < 0) {
|
||||
if (virHashAddEntry(conn->nwfilters, uuidstr, ret) < 0) {
|
||||
virMutexUnlock(&conn->lock);
|
||||
virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("failed to add network filter pool to connection hash table"));
|
||||
_("failed to add network filter to connection hash table"));
|
||||
goto error;
|
||||
}
|
||||
conn->refs++;
|
||||
@ -1530,35 +1530,36 @@ error:
|
||||
|
||||
|
||||
/**
|
||||
* virReleaseNWFilterPool:
|
||||
* @pool: the pool to release
|
||||
* virReleaseNWFilter:
|
||||
* @nwfilter: the nwfilter to release
|
||||
*
|
||||
* Unconditionally release all memory associated with a pool.
|
||||
* Unconditionally release all memory associated with a nwfilter.
|
||||
* The conn.lock mutex must be held prior to calling this, and will
|
||||
* be released prior to this returning. The pool obj must not
|
||||
* be released prior to this returning. The nwfilter obj must not
|
||||
* be used once this method returns.
|
||||
*
|
||||
* It will also unreference the associated connection object,
|
||||
* which may also be released if its ref count hits zero.
|
||||
*/
|
||||
static void
|
||||
virReleaseNWFilterPool(virNWFilterPtr pool) {
|
||||
virConnectPtr conn = pool->conn;
|
||||
virReleaseNWFilter(virNWFilterPtr nwfilter)
|
||||
{
|
||||
virConnectPtr conn = nwfilter->conn;
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
virUUIDFormat(pool->uuid, uuidstr);
|
||||
DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
|
||||
virUUIDFormat(nwfilter->uuid, uuidstr);
|
||||
DEBUG("release nwfilter %p %s %s", nwfilter, nwfilter->name, uuidstr);
|
||||
|
||||
if (virHashRemoveEntry(conn->nwfilterPools, uuidstr, NULL) < 0) {
|
||||
if (virHashRemoveEntry(conn->nwfilters, uuidstr, NULL) < 0) {
|
||||
virMutexUnlock(&conn->lock);
|
||||
virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("pool missing from connection hash table"));
|
||||
conn = NULL;
|
||||
}
|
||||
|
||||
pool->magic = -1;
|
||||
VIR_FREE(pool->name);
|
||||
VIR_FREE(pool);
|
||||
nwfilter->magic = -1;
|
||||
VIR_FREE(nwfilter->name);
|
||||
VIR_FREE(nwfilter);
|
||||
|
||||
if (conn) {
|
||||
DEBUG("unref connection %p %d", conn, conn->refs);
|
||||
@ -1583,25 +1584,26 @@ virReleaseNWFilterPool(virNWFilterPtr pool) {
|
||||
* Returns the reference count or -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virUnrefNWFilter(virNWFilterPtr pool) {
|
||||
virUnrefNWFilter(virNWFilterPtr nwfilter)
|
||||
{
|
||||
int refs;
|
||||
|
||||
if (!VIR_IS_CONNECTED_NWFILTER(pool)) {
|
||||
if (!VIR_IS_CONNECTED_NWFILTER(nwfilter)) {
|
||||
virLibConnError(VIR_ERR_INVALID_ARG,
|
||||
_("bad nwfilter or no connection"));
|
||||
return -1;
|
||||
}
|
||||
virMutexLock(&pool->conn->lock);
|
||||
DEBUG("unref pool %p %s %d", pool, pool->name, pool->refs);
|
||||
pool->refs--;
|
||||
refs = pool->refs;
|
||||
virMutexLock(&nwfilter->conn->lock);
|
||||
DEBUG("unref pool %p %s %d", nwfilter, nwfilter->name, nwfilter->refs);
|
||||
nwfilter->refs--;
|
||||
refs = nwfilter->refs;
|
||||
if (refs == 0) {
|
||||
virReleaseNWFilterPool(pool);
|
||||
virReleaseNWFilter(nwfilter);
|
||||
/* Already unlocked mutex */
|
||||
return (0);
|
||||
}
|
||||
|
||||
virMutexUnlock(&pool->conn->lock);
|
||||
virMutexUnlock(&nwfilter->conn->lock);
|
||||
return (refs);
|
||||
}
|
||||
|
||||
|
@ -194,8 +194,8 @@ struct _virConnect {
|
||||
virHashTablePtr storagePools;/* hash table for known storage pools */
|
||||
virHashTablePtr storageVols;/* hash table for known storage vols */
|
||||
virHashTablePtr nodeDevices; /* hash table for known node devices */
|
||||
virHashTablePtr secrets; /* hash taboe for known secrets */
|
||||
virHashTablePtr nwfilterPools; /* hash tables ofr known nw filter pools */
|
||||
virHashTablePtr secrets; /* hash table for known secrets */
|
||||
virHashTablePtr nwfilters; /* hash table for known nw filters */
|
||||
int refs; /* reference count */
|
||||
};
|
||||
|
||||
@ -387,10 +387,10 @@ struct _virNWFilter {
|
||||
virNWFilterPtr virGetNWFilter(virConnectPtr conn,
|
||||
const char *name,
|
||||
const unsigned char *uuid);
|
||||
int virUnrefNWFilter(virNWFilterPtr pool);
|
||||
int virUnrefNWFilter(virNWFilterPtr nwfilter);
|
||||
|
||||
virDomainSnapshotPtr virGetDomainSnapshot(virDomainPtr domain,
|
||||
const char *name);
|
||||
int virUnrefDomainSnapshot(virDomainSnapshotPtr pool);
|
||||
int virUnrefDomainSnapshot(virDomainSnapshotPtr snapshot);
|
||||
|
||||
#endif
|
||||
|
@ -1138,10 +1138,10 @@ typedef virNWFilterPtr
|
||||
const char *xmlDesc,
|
||||
unsigned int flags);
|
||||
typedef int
|
||||
(*virDrvNWFilterUndefine) (virNWFilterPtr pool);
|
||||
(*virDrvNWFilterUndefine) (virNWFilterPtr nwfilter);
|
||||
|
||||
typedef char *
|
||||
(*virDrvNWFilterGetXMLDesc) (virNWFilterPtr pool,
|
||||
(*virDrvNWFilterGetXMLDesc) (virNWFilterPtr nwfilter,
|
||||
unsigned int flags);
|
||||
|
||||
|
||||
|
@ -705,7 +705,7 @@ virLibSecretError(virSecretPtr secret, virErrorNumber error, const char *info)
|
||||
* Handle an error at the connection level
|
||||
*/
|
||||
static void
|
||||
virLibNWFilterError(virNWFilterPtr pool, virErrorNumber error,
|
||||
virLibNWFilterError(virNWFilterPtr nwfilter, virErrorNumber error,
|
||||
const char *info)
|
||||
{
|
||||
virConnectPtr conn = NULL;
|
||||
@ -716,7 +716,7 @@ virLibNWFilterError(virNWFilterPtr pool, virErrorNumber error,
|
||||
|
||||
errmsg = virErrorMsg(error, info);
|
||||
if (error != VIR_ERR_INVALID_NWFILTER)
|
||||
conn = pool->conn;
|
||||
conn = nwfilter->conn;
|
||||
|
||||
virRaiseError(conn, NULL, NULL, VIR_FROM_NWFILTER, error, VIR_ERR_ERROR,
|
||||
errmsg, info, NULL, 0, 0, errmsg, info);
|
||||
|
@ -637,17 +637,17 @@ virNWFilterDefFormat;
|
||||
virNWFilterDefFree;
|
||||
virNWFilterDefParseString;
|
||||
virNWFilterJumpTargetTypeToString;
|
||||
virNWFilterLoadAllConfigs;
|
||||
virNWFilterLockFilterUpdates;
|
||||
virNWFilterPoolLoadAllConfigs;
|
||||
virNWFilterPoolObjAssignDef;
|
||||
virNWFilterPoolObjDeleteDef;
|
||||
virNWFilterPoolObjFindByName;
|
||||
virNWFilterPoolObjFindByUUID;
|
||||
virNWFilterPoolObjListFree;
|
||||
virNWFilterPoolObjLock;
|
||||
virNWFilterPoolObjRemove;
|
||||
virNWFilterPoolObjSaveDef;
|
||||
virNWFilterPoolObjUnlock;
|
||||
virNWFilterObjAssignDef;
|
||||
virNWFilterObjDeleteDef;
|
||||
virNWFilterObjFindByName;
|
||||
virNWFilterObjFindByUUID;
|
||||
virNWFilterObjListFree;
|
||||
virNWFilterObjLock;
|
||||
virNWFilterObjRemove;
|
||||
virNWFilterObjSaveDef;
|
||||
virNWFilterObjUnlock;
|
||||
virNWFilterPrintStateMatchFlags;
|
||||
virNWFilterRegisterCallbackDriver;
|
||||
virNWFilterRuleActionTypeToString;
|
||||
|
@ -105,9 +105,9 @@ nwfilterDriverStartup(int privileged) {
|
||||
|
||||
VIR_FREE(base);
|
||||
|
||||
if (virNWFilterPoolLoadAllConfigs(NULL,
|
||||
&driverState->pools,
|
||||
driverState->configDir) < 0)
|
||||
if (virNWFilterLoadAllConfigs(NULL,
|
||||
&driverState->nwfilters,
|
||||
driverState->configDir) < 0)
|
||||
goto error;
|
||||
|
||||
nwfilterDriverUnlock(driverState);
|
||||
@ -155,9 +155,9 @@ nwfilterDriverReload(void) {
|
||||
nwfilterDriverLock(driverState);
|
||||
virNWFilterCallbackDriversLock();
|
||||
|
||||
virNWFilterPoolLoadAllConfigs(conn,
|
||||
&driverState->pools,
|
||||
driverState->configDir);
|
||||
virNWFilterLoadAllConfigs(conn,
|
||||
&driverState->nwfilters,
|
||||
driverState->configDir);
|
||||
|
||||
virNWFilterCallbackDriversUnlock();
|
||||
nwfilterDriverUnlock(driverState);
|
||||
@ -171,7 +171,7 @@ nwfilterDriverReload(void) {
|
||||
/**
|
||||
* virNWFilterActive:
|
||||
*
|
||||
* Checks if the nwfilter driver is active, i.e. has an active pool
|
||||
* Checks if the nwfilter driver is active, i.e. has an active nwfilter
|
||||
*
|
||||
* Returns 1 if active, 0 otherwise
|
||||
*/
|
||||
@ -183,7 +183,7 @@ nwfilterDriverActive(void) {
|
||||
return 0;
|
||||
|
||||
nwfilterDriverLock(driverState);
|
||||
ret = driverState->pools.count ? 1 : 0;
|
||||
ret = driverState->nwfilters.count ? 1 : 0;
|
||||
nwfilterDriverUnlock(driverState);
|
||||
|
||||
return ret;
|
||||
@ -192,7 +192,7 @@ nwfilterDriverActive(void) {
|
||||
/**
|
||||
* virNWFilterShutdown:
|
||||
*
|
||||
* Shutdown the nwfilter driver, it will stop all active nwfilter pools
|
||||
* Shutdown the nwfilter driver, it will stop all active nwfilters
|
||||
*/
|
||||
static int
|
||||
nwfilterDriverShutdown(void) {
|
||||
@ -203,8 +203,8 @@ nwfilterDriverShutdown(void) {
|
||||
|
||||
nwfilterDriverLock(driverState);
|
||||
|
||||
/* free inactive pools */
|
||||
virNWFilterPoolObjListFree(&driverState->pools);
|
||||
/* free inactive nwfilters */
|
||||
virNWFilterObjListFree(&driverState->nwfilters);
|
||||
|
||||
VIR_FREE(driverState->configDir);
|
||||
nwfilterDriverUnlock(driverState);
|
||||
@ -219,24 +219,24 @@ static virNWFilterPtr
|
||||
nwfilterLookupByUUID(virConnectPtr conn,
|
||||
const unsigned char *uuid) {
|
||||
virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData;
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
virNWFilterPtr ret = NULL;
|
||||
|
||||
nwfilterDriverLock(driver);
|
||||
pool = virNWFilterPoolObjFindByUUID(&driver->pools, uuid);
|
||||
nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, uuid);
|
||||
nwfilterDriverUnlock(driver);
|
||||
|
||||
if (!pool) {
|
||||
if (!nwfilter) {
|
||||
virNWFilterReportError(VIR_ERR_NO_NWFILTER,
|
||||
"%s", _("no pool with matching uuid"));
|
||||
"%s", _("no nwfilter with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = virGetNWFilter(conn, pool->def->name, pool->def->uuid);
|
||||
ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid);
|
||||
|
||||
cleanup:
|
||||
if (pool)
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
if (nwfilter)
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -245,24 +245,24 @@ static virNWFilterPtr
|
||||
nwfilterLookupByName(virConnectPtr conn,
|
||||
const char *name) {
|
||||
virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData;
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
virNWFilterPtr ret = NULL;
|
||||
|
||||
nwfilterDriverLock(driver);
|
||||
pool = virNWFilterPoolObjFindByName(&driver->pools, name);
|
||||
nwfilter = virNWFilterObjFindByName(&driver->nwfilters, name);
|
||||
nwfilterDriverUnlock(driver);
|
||||
|
||||
if (!pool) {
|
||||
if (!nwfilter) {
|
||||
virNWFilterReportError(VIR_ERR_NO_NWFILTER,
|
||||
_("no pool with matching name '%s'"), name);
|
||||
_("no nwfilter with matching name '%s'"), name);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = virGetNWFilter(conn, pool->def->name, pool->def->uuid);
|
||||
ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid);
|
||||
|
||||
cleanup:
|
||||
if (pool)
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
if (nwfilter)
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -289,7 +289,7 @@ nwfilterClose(virConnectPtr conn) {
|
||||
static int
|
||||
nwfilterNumNWFilters(virConnectPtr conn) {
|
||||
virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData;
|
||||
return driver->pools.count;
|
||||
return driver->nwfilters.count;
|
||||
}
|
||||
|
||||
|
||||
@ -301,15 +301,15 @@ nwfilterListNWFilters(virConnectPtr conn,
|
||||
int got = 0, i;
|
||||
|
||||
nwfilterDriverLock(driver);
|
||||
for (i = 0 ; i < driver->pools.count && got < nnames ; i++) {
|
||||
virNWFilterPoolObjLock(driver->pools.objs[i]);
|
||||
if (!(names[got] = strdup(driver->pools.objs[i]->def->name))) {
|
||||
virNWFilterPoolObjUnlock(driver->pools.objs[i]);
|
||||
for (i = 0 ; i < driver->nwfilters.count && got < nnames ; i++) {
|
||||
virNWFilterObjLock(driver->nwfilters.objs[i]);
|
||||
if (!(names[got] = strdup(driver->nwfilters.objs[i]->def->name))) {
|
||||
virNWFilterObjUnlock(driver->nwfilters.objs[i]);
|
||||
virReportOOMError();
|
||||
goto cleanup;
|
||||
}
|
||||
got++;
|
||||
virNWFilterPoolObjUnlock(driver->pools.objs[i]);
|
||||
virNWFilterObjUnlock(driver->nwfilters.objs[i]);
|
||||
}
|
||||
nwfilterDriverUnlock(driver);
|
||||
return got;
|
||||
@ -329,7 +329,7 @@ nwfilterDefine(virConnectPtr conn,
|
||||
unsigned int flags ATTRIBUTE_UNUSED) {
|
||||
virNWFilterDriverStatePtr driver = conn->nwfilterPrivateData;
|
||||
virNWFilterDefPtr def;
|
||||
virNWFilterPoolObjPtr pool = NULL;
|
||||
virNWFilterObjPtr nwfilter = NULL;
|
||||
virNWFilterPtr ret = NULL;
|
||||
|
||||
nwfilterDriverLock(driver);
|
||||
@ -338,22 +338,22 @@ nwfilterDefine(virConnectPtr conn,
|
||||
if (!(def = virNWFilterDefParseString(conn, xml)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(pool = virNWFilterPoolObjAssignDef(conn, &driver->pools, def)))
|
||||
if (!(nwfilter = virNWFilterObjAssignDef(conn, &driver->nwfilters, def)))
|
||||
goto cleanup;
|
||||
|
||||
if (virNWFilterPoolObjSaveDef(driver, pool, def) < 0) {
|
||||
virNWFilterPoolObjRemove(&driver->pools, pool);
|
||||
if (virNWFilterObjSaveDef(driver, nwfilter, def) < 0) {
|
||||
virNWFilterObjRemove(&driver->nwfilters, nwfilter);
|
||||
def = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
def = NULL;
|
||||
|
||||
ret = virGetNWFilter(conn, pool->def->name, pool->def->uuid);
|
||||
ret = virGetNWFilter(conn, nwfilter->def->name, nwfilter->def->uuid);
|
||||
|
||||
cleanup:
|
||||
virNWFilterDefFree(def);
|
||||
if (pool)
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
if (nwfilter)
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
|
||||
virNWFilterCallbackDriversUnlock();
|
||||
nwfilterDriverUnlock(driver);
|
||||
@ -364,38 +364,38 @@ cleanup:
|
||||
static int
|
||||
nwfilterUndefine(virNWFilterPtr obj) {
|
||||
virNWFilterDriverStatePtr driver = obj->conn->nwfilterPrivateData;
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
int ret = -1;
|
||||
|
||||
nwfilterDriverLock(driver);
|
||||
virNWFilterCallbackDriversLock();
|
||||
|
||||
pool = virNWFilterPoolObjFindByUUID(&driver->pools, obj->uuid);
|
||||
if (!pool) {
|
||||
nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, obj->uuid);
|
||||
if (!nwfilter) {
|
||||
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
|
||||
"%s", _("no nwfilter pool with matching uuid"));
|
||||
"%s", _("no nwfilter with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNWFilterTestUnassignDef(obj->conn, pool)) {
|
||||
if (virNWFilterTestUnassignDef(obj->conn, nwfilter)) {
|
||||
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
|
||||
"%s",
|
||||
_("nwfilter is in use"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virNWFilterPoolObjDeleteDef(pool) < 0)
|
||||
if (virNWFilterObjDeleteDef(nwfilter) < 0)
|
||||
goto cleanup;
|
||||
|
||||
VIR_FREE(pool->configFile);
|
||||
VIR_FREE(nwfilter->configFile);
|
||||
|
||||
virNWFilterPoolObjRemove(&driver->pools, pool);
|
||||
pool = NULL;
|
||||
virNWFilterObjRemove(&driver->nwfilters, nwfilter);
|
||||
nwfilter = NULL;
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
if (pool)
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
if (nwfilter)
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
|
||||
virNWFilterCallbackDriversUnlock();
|
||||
nwfilterDriverUnlock(driver);
|
||||
@ -407,26 +407,26 @@ static char *
|
||||
nwfilterDumpXML(virNWFilterPtr obj,
|
||||
unsigned int flags) {
|
||||
virNWFilterDriverStatePtr driver = obj->conn->nwfilterPrivateData;
|
||||
virNWFilterPoolObjPtr pool;
|
||||
virNWFilterObjPtr nwfilter;
|
||||
char *ret = NULL;
|
||||
|
||||
virCheckFlags(0, NULL);
|
||||
|
||||
nwfilterDriverLock(driver);
|
||||
pool = virNWFilterPoolObjFindByUUID(&driver->pools, obj->uuid);
|
||||
nwfilter = virNWFilterObjFindByUUID(&driver->nwfilters, obj->uuid);
|
||||
nwfilterDriverUnlock(driver);
|
||||
|
||||
if (!pool) {
|
||||
if (!nwfilter) {
|
||||
virNWFilterReportError(VIR_ERR_INVALID_NWFILTER,
|
||||
"%s", _("no nwfilter pool with matching uuid"));
|
||||
"%s", _("no nwfilter with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
ret = virNWFilterDefFormat(pool->def);
|
||||
ret = virNWFilterDefFormat(nwfilter->def);
|
||||
|
||||
cleanup:
|
||||
if (pool)
|
||||
virNWFilterPoolObjUnlock(pool);
|
||||
if (nwfilter)
|
||||
virNWFilterObjUnlock(nwfilter);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -284,7 +284,7 @@ err_exit:
|
||||
|
||||
|
||||
/**
|
||||
* _virNWFilterPoolInstantiateRec:
|
||||
* _virNWFilterInstantiateRec:
|
||||
* @conn: pointer to virConnect object
|
||||
* @techdriver: The driver to use for instantiation
|
||||
* @filter: The filter to instantiate
|
||||
@ -319,7 +319,7 @@ _virNWFilterInstantiateRec(virConnectPtr conn,
|
||||
enum instCase useNewFilter, bool *foundNewFilter,
|
||||
virNWFilterDriverStatePtr driver)
|
||||
{
|
||||
virNWFilterPoolObjPtr obj;
|
||||
virNWFilterObjPtr obj;
|
||||
int rc = 0;
|
||||
int i;
|
||||
virNWFilterRuleInstPtr inst;
|
||||
@ -351,8 +351,7 @@ _virNWFilterInstantiateRec(virConnectPtr conn,
|
||||
|
||||
} else if (inc) {
|
||||
VIR_DEBUG("Instantiating filter %s", inc->filterref);
|
||||
obj = virNWFilterPoolObjFindByName(&driver->pools,
|
||||
inc->filterref);
|
||||
obj = virNWFilterObjFindByName(&driver->nwfilters, inc->filterref);
|
||||
if (obj) {
|
||||
|
||||
if (obj->wantRemoved) {
|
||||
@ -360,7 +359,7 @@ _virNWFilterInstantiateRec(virConnectPtr conn,
|
||||
_("Filter '%s' is in use."),
|
||||
inc->filterref);
|
||||
rc = 1;
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -371,7 +370,7 @@ _virNWFilterInstantiateRec(virConnectPtr conn,
|
||||
if (!tmpvars) {
|
||||
virReportOOMError();
|
||||
rc = 1;
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -401,7 +400,7 @@ _virNWFilterInstantiateRec(virConnectPtr conn,
|
||||
|
||||
virNWFilterHashTableFree(tmpvars);
|
||||
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
if (rc)
|
||||
break;
|
||||
} else {
|
||||
@ -425,7 +424,7 @@ virNWFilterDetermineMissingVarsRec(virConnectPtr conn,
|
||||
int useNewFilter,
|
||||
virNWFilterDriverStatePtr driver)
|
||||
{
|
||||
virNWFilterPoolObjPtr obj;
|
||||
virNWFilterObjPtr obj;
|
||||
int rc = 0;
|
||||
int i, j;
|
||||
virNWFilterDefPtr next_filter;
|
||||
@ -443,8 +442,7 @@ virNWFilterDetermineMissingVarsRec(virConnectPtr conn,
|
||||
}
|
||||
} else if (inc) {
|
||||
VIR_DEBUG("Following filter %s\n", inc->filterref);
|
||||
obj = virNWFilterPoolObjFindByName(&driver->pools,
|
||||
inc->filterref);
|
||||
obj = virNWFilterObjFindByName(&driver->nwfilters, inc->filterref);
|
||||
if (obj) {
|
||||
|
||||
if (obj->wantRemoved) {
|
||||
@ -452,7 +450,7 @@ virNWFilterDetermineMissingVarsRec(virConnectPtr conn,
|
||||
_("Filter '%s' is in use."),
|
||||
inc->filterref);
|
||||
rc = 1;
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -463,7 +461,7 @@ virNWFilterDetermineMissingVarsRec(virConnectPtr conn,
|
||||
if (!tmpvars) {
|
||||
virReportOOMError();
|
||||
rc = 1;
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -488,7 +486,7 @@ virNWFilterDetermineMissingVarsRec(virConnectPtr conn,
|
||||
|
||||
virNWFilterHashTableFree(tmpvars);
|
||||
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
if (rc)
|
||||
break;
|
||||
} else {
|
||||
@ -700,7 +698,7 @@ __virNWFilterInstantiateFilter(virConnectPtr conn,
|
||||
int rc;
|
||||
const char *drvname = EBIPTABLES_DRIVER_ID;
|
||||
virNWFilterTechDriverPtr techdriver;
|
||||
virNWFilterPoolObjPtr obj;
|
||||
virNWFilterObjPtr obj;
|
||||
virNWFilterHashTablePtr vars, vars1;
|
||||
virNWFilterDefPtr filter;
|
||||
char vmmacaddr[VIR_MAC_STRING_BUFLEN] = {0};
|
||||
@ -720,7 +718,7 @@ __virNWFilterInstantiateFilter(virConnectPtr conn,
|
||||
|
||||
VIR_DEBUG("filter name: %s", filtername);
|
||||
|
||||
obj = virNWFilterPoolObjFindByName(&driver->pools, filtername);
|
||||
obj = virNWFilterObjFindByName(&driver->nwfilters, filtername);
|
||||
if (!obj) {
|
||||
virNWFilterReportError(VIR_ERR_NO_NWFILTER,
|
||||
_("Could not find filter '%s'"),
|
||||
@ -804,7 +802,7 @@ err_exit_vars1:
|
||||
virNWFilterHashTableFree(vars1);
|
||||
|
||||
err_exit:
|
||||
virNWFilterPoolObjUnlock(obj);
|
||||
virNWFilterObjUnlock(obj);
|
||||
|
||||
VIR_FREE(str_ipaddr);
|
||||
VIR_FREE(str_macaddr);
|
||||
|
Loading…
Reference in New Issue
Block a user