mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
nwfilter: Use virNWFilterDefPtr rather than deref virNWFilterObjPtr
Rather than dereferencing obj->def->XXX or nwfilters->objs[i]->X create local virNWFilterObjPtr and virNWFilterDefPtr variables. Future adjustments will be privatizing the object more, so this just prepares the code for that reality. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
82769c4fdc
commit
fc07fd04e4
@ -87,12 +87,16 @@ virNWFilterObjFindByUUID(virNWFilterObjListPtr nwfilters,
|
|||||||
const unsigned char *uuid)
|
const unsigned char *uuid)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virNWFilterObjPtr obj;
|
||||||
|
virNWFilterDefPtr def;
|
||||||
|
|
||||||
for (i = 0; i < nwfilters->count; i++) {
|
for (i = 0; i < nwfilters->count; i++) {
|
||||||
virNWFilterObjLock(nwfilters->objs[i]);
|
obj = nwfilters->objs[i];
|
||||||
if (!memcmp(nwfilters->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
|
virNWFilterObjLock(obj);
|
||||||
return nwfilters->objs[i];
|
def = obj->def;
|
||||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
if (!memcmp(def->uuid, uuid, VIR_UUID_BUFLEN))
|
||||||
|
return obj;
|
||||||
|
virNWFilterObjUnlock(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -104,12 +108,16 @@ virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters,
|
|||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virNWFilterObjPtr obj;
|
||||||
|
virNWFilterDefPtr def;
|
||||||
|
|
||||||
for (i = 0; i < nwfilters->count; i++) {
|
for (i = 0; i < nwfilters->count; i++) {
|
||||||
virNWFilterObjLock(nwfilters->objs[i]);
|
obj = nwfilters->objs[i];
|
||||||
if (STREQ_NULLABLE(nwfilters->objs[i]->def->name, name))
|
virNWFilterObjLock(obj);
|
||||||
return nwfilters->objs[i];
|
def = obj->def;
|
||||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
if (STREQ_NULLABLE(def->name, name))
|
||||||
|
return obj;
|
||||||
|
virNWFilterObjUnlock(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -141,9 +149,8 @@ _virNWFilterObjDefLoopDetect(virNWFilterObjListPtr nwfilters,
|
|||||||
obj = virNWFilterObjFindByName(nwfilters,
|
obj = virNWFilterObjFindByName(nwfilters,
|
||||||
entry->include->filterref);
|
entry->include->filterref);
|
||||||
if (obj) {
|
if (obj) {
|
||||||
rc = _virNWFilterObjDefLoopDetect(nwfilters,
|
rc = _virNWFilterObjDefLoopDetect(nwfilters, obj->def,
|
||||||
obj->def, filtername);
|
filtername);
|
||||||
|
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
break;
|
break;
|
||||||
@ -226,24 +233,26 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
|
|||||||
virNWFilterDefPtr def)
|
virNWFilterDefPtr def)
|
||||||
{
|
{
|
||||||
virNWFilterObjPtr obj;
|
virNWFilterObjPtr obj;
|
||||||
|
virNWFilterDefPtr objdef;
|
||||||
|
|
||||||
obj = virNWFilterObjFindByUUID(nwfilters, def->uuid);
|
if ((obj = virNWFilterObjFindByUUID(nwfilters, def->uuid))) {
|
||||||
|
objdef = obj->def;
|
||||||
|
|
||||||
if (obj) {
|
if (STRNEQ(def->name, objdef->name)) {
|
||||||
if (STRNEQ(def->name, obj->def->name)) {
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("filter with same UUID but different name "
|
_("filter with same UUID but different name "
|
||||||
"('%s') already exists"),
|
"('%s') already exists"),
|
||||||
obj->def->name);
|
objdef->name);
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
} else {
|
} else {
|
||||||
obj = virNWFilterObjFindByName(nwfilters, def->name);
|
if ((obj = virNWFilterObjFindByName(nwfilters, def->name))) {
|
||||||
if (obj) {
|
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
virUUIDFormat(obj->def->uuid, uuidstr);
|
|
||||||
|
objdef = obj->def;
|
||||||
|
virUUIDFormat(objdef->uuid, uuidstr);
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("filter '%s' already exists with uuid %s"),
|
_("filter '%s' already exists with uuid %s"),
|
||||||
def->name, uuidstr);
|
def->name, uuidstr);
|
||||||
@ -261,8 +270,9 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
|
|||||||
|
|
||||||
if ((obj = virNWFilterObjFindByName(nwfilters, def->name))) {
|
if ((obj = virNWFilterObjFindByName(nwfilters, def->name))) {
|
||||||
|
|
||||||
if (virNWFilterDefEqual(def, obj->def, false)) {
|
objdef = obj->def;
|
||||||
virNWFilterDefFree(obj->def);
|
if (virNWFilterDefEqual(def, objdef, false)) {
|
||||||
|
virNWFilterDefFree(objdef);
|
||||||
obj->def = def;
|
obj->def = def;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -275,7 +285,7 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNWFilterDefFree(obj->def);
|
virNWFilterDefFree(objdef);
|
||||||
obj->def = def;
|
obj->def = def;
|
||||||
obj->newDef = NULL;
|
obj->newDef = NULL;
|
||||||
return obj;
|
return obj;
|
||||||
@ -334,12 +344,14 @@ virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
|
|||||||
{
|
{
|
||||||
int nnames = 0;
|
int nnames = 0;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
virNWFilterDefPtr def;
|
||||||
|
|
||||||
for (i = 0; i < nwfilters->count && nnames < maxnames; i++) {
|
for (i = 0; i < nwfilters->count && nnames < maxnames; i++) {
|
||||||
virNWFilterObjPtr obj = nwfilters->objs[i];
|
virNWFilterObjPtr obj = nwfilters->objs[i];
|
||||||
virNWFilterObjLock(obj);
|
virNWFilterObjLock(obj);
|
||||||
if (!aclfilter || aclfilter(conn, obj->def)) {
|
def = obj->def;
|
||||||
if (VIR_STRDUP(names[nnames], obj->def->name) < 0) {
|
if (!aclfilter || aclfilter(conn, def)) {
|
||||||
|
if (VIR_STRDUP(names[nnames], def->name) < 0) {
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
goto failure;
|
goto failure;
|
||||||
}
|
}
|
||||||
@ -368,6 +380,7 @@ virNWFilterObjListExport(virConnectPtr conn,
|
|||||||
int nfilters = 0;
|
int nfilters = 0;
|
||||||
virNWFilterPtr filter = NULL;
|
virNWFilterPtr filter = NULL;
|
||||||
virNWFilterObjPtr obj = NULL;
|
virNWFilterObjPtr obj = NULL;
|
||||||
|
virNWFilterDefPtr def;
|
||||||
size_t i;
|
size_t i;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
@ -382,9 +395,9 @@ virNWFilterObjListExport(virConnectPtr conn,
|
|||||||
for (i = 0; i < nwfilters->count; i++) {
|
for (i = 0; i < nwfilters->count; i++) {
|
||||||
obj = nwfilters->objs[i];
|
obj = nwfilters->objs[i];
|
||||||
virNWFilterObjLock(obj);
|
virNWFilterObjLock(obj);
|
||||||
if (!aclfilter || aclfilter(conn, obj->def)) {
|
def = obj->def;
|
||||||
if (!(filter = virGetNWFilter(conn, obj->def->name,
|
if (!aclfilter || aclfilter(conn, def)) {
|
||||||
obj->def->uuid))) {
|
if (!(filter = virGetNWFilter(conn, def->name, def->uuid))) {
|
||||||
virNWFilterObjUnlock(obj);
|
virNWFilterObjUnlock(obj);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -358,6 +358,7 @@ nwfilterLookupByUUID(virConnectPtr conn,
|
|||||||
const unsigned char *uuid)
|
const unsigned char *uuid)
|
||||||
{
|
{
|
||||||
virNWFilterObjPtr obj;
|
virNWFilterObjPtr obj;
|
||||||
|
virNWFilterDefPtr def;
|
||||||
virNWFilterPtr ret = NULL;
|
virNWFilterPtr ret = NULL;
|
||||||
|
|
||||||
nwfilterDriverLock();
|
nwfilterDriverLock();
|
||||||
@ -369,11 +370,12 @@ nwfilterLookupByUUID(virConnectPtr conn,
|
|||||||
"%s", _("no nwfilter with matching uuid"));
|
"%s", _("no nwfilter with matching uuid"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
def = obj->def;
|
||||||
|
|
||||||
if (virNWFilterLookupByUUIDEnsureACL(conn, obj->def) < 0)
|
if (virNWFilterLookupByUUIDEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virGetNWFilter(conn, obj->def->name, obj->def->uuid);
|
ret = virGetNWFilter(conn, def->name, def->uuid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (obj)
|
if (obj)
|
||||||
@ -387,6 +389,7 @@ nwfilterLookupByName(virConnectPtr conn,
|
|||||||
const char *name)
|
const char *name)
|
||||||
{
|
{
|
||||||
virNWFilterObjPtr obj;
|
virNWFilterObjPtr obj;
|
||||||
|
virNWFilterDefPtr def;
|
||||||
virNWFilterPtr ret = NULL;
|
virNWFilterPtr ret = NULL;
|
||||||
|
|
||||||
nwfilterDriverLock();
|
nwfilterDriverLock();
|
||||||
@ -398,11 +401,12 @@ nwfilterLookupByName(virConnectPtr conn,
|
|||||||
_("no nwfilter with matching name '%s'"), name);
|
_("no nwfilter with matching name '%s'"), name);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
def = obj->def;
|
||||||
|
|
||||||
if (virNWFilterLookupByNameEnsureACL(conn, obj->def) < 0)
|
if (virNWFilterLookupByNameEnsureACL(conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virGetNWFilter(conn, obj->def->name, obj->def->uuid);
|
ret = virGetNWFilter(conn, def->name, def->uuid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (obj)
|
if (obj)
|
||||||
@ -467,6 +471,7 @@ nwfilterDefineXML(virConnectPtr conn,
|
|||||||
{
|
{
|
||||||
virNWFilterDefPtr def;
|
virNWFilterDefPtr def;
|
||||||
virNWFilterObjPtr obj = NULL;
|
virNWFilterObjPtr obj = NULL;
|
||||||
|
virNWFilterDefPtr objdef;
|
||||||
virNWFilterPtr ret = NULL;
|
virNWFilterPtr ret = NULL;
|
||||||
|
|
||||||
if (!driver->privileged) {
|
if (!driver->privileged) {
|
||||||
@ -487,15 +492,15 @@ nwfilterDefineXML(virConnectPtr conn,
|
|||||||
|
|
||||||
if (!(obj = virNWFilterObjAssignDef(&driver->nwfilters, def)))
|
if (!(obj = virNWFilterObjAssignDef(&driver->nwfilters, def)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virNWFilterSaveDef(driver->configDir, def) < 0) {
|
|
||||||
virNWFilterObjRemove(&driver->nwfilters, obj);
|
|
||||||
def = NULL;
|
def = NULL;
|
||||||
|
objdef = obj->def;
|
||||||
|
|
||||||
|
if (virNWFilterSaveDef(driver->configDir, objdef) < 0) {
|
||||||
|
virNWFilterObjRemove(&driver->nwfilters, obj);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
def = NULL;
|
|
||||||
|
|
||||||
ret = virGetNWFilter(conn, obj->def->name, obj->def->uuid);
|
ret = virGetNWFilter(conn, objdef->name, objdef->uuid);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNWFilterDefFree(def);
|
virNWFilterDefFree(def);
|
||||||
|
Loading…
Reference in New Issue
Block a user