mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +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)
|
||||
{
|
||||
size_t i;
|
||||
virNWFilterObjPtr obj;
|
||||
virNWFilterDefPtr def;
|
||||
|
||||
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]);
|
||||
obj = nwfilters->objs[i];
|
||||
virNWFilterObjLock(obj);
|
||||
def = obj->def;
|
||||
if (!memcmp(def->uuid, uuid, VIR_UUID_BUFLEN))
|
||||
return obj;
|
||||
virNWFilterObjUnlock(obj);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -104,12 +108,16 @@ virNWFilterObjFindByName(virNWFilterObjListPtr nwfilters,
|
||||
const char *name)
|
||||
{
|
||||
size_t i;
|
||||
virNWFilterObjPtr obj;
|
||||
virNWFilterDefPtr def;
|
||||
|
||||
for (i = 0; i < nwfilters->count; i++) {
|
||||
virNWFilterObjLock(nwfilters->objs[i]);
|
||||
if (STREQ_NULLABLE(nwfilters->objs[i]->def->name, name))
|
||||
return nwfilters->objs[i];
|
||||
virNWFilterObjUnlock(nwfilters->objs[i]);
|
||||
obj = nwfilters->objs[i];
|
||||
virNWFilterObjLock(obj);
|
||||
def = obj->def;
|
||||
if (STREQ_NULLABLE(def->name, name))
|
||||
return obj;
|
||||
virNWFilterObjUnlock(obj);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
@ -141,9 +149,8 @@ _virNWFilterObjDefLoopDetect(virNWFilterObjListPtr nwfilters,
|
||||
obj = virNWFilterObjFindByName(nwfilters,
|
||||
entry->include->filterref);
|
||||
if (obj) {
|
||||
rc = _virNWFilterObjDefLoopDetect(nwfilters,
|
||||
obj->def, filtername);
|
||||
|
||||
rc = _virNWFilterObjDefLoopDetect(nwfilters, obj->def,
|
||||
filtername);
|
||||
virNWFilterObjUnlock(obj);
|
||||
if (rc < 0)
|
||||
break;
|
||||
@ -226,24 +233,26 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
|
||||
virNWFilterDefPtr def)
|
||||
{
|
||||
virNWFilterObjPtr obj;
|
||||
virNWFilterDefPtr objdef;
|
||||
|
||||
obj = virNWFilterObjFindByUUID(nwfilters, def->uuid);
|
||||
if ((obj = virNWFilterObjFindByUUID(nwfilters, def->uuid))) {
|
||||
objdef = obj->def;
|
||||
|
||||
if (obj) {
|
||||
if (STRNEQ(def->name, obj->def->name)) {
|
||||
if (STRNEQ(def->name, objdef->name)) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("filter with same UUID but different name "
|
||||
"('%s') already exists"),
|
||||
obj->def->name);
|
||||
objdef->name);
|
||||
virNWFilterObjUnlock(obj);
|
||||
return NULL;
|
||||
}
|
||||
virNWFilterObjUnlock(obj);
|
||||
} else {
|
||||
obj = virNWFilterObjFindByName(nwfilters, def->name);
|
||||
if (obj) {
|
||||
if ((obj = virNWFilterObjFindByName(nwfilters, def->name))) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
virUUIDFormat(obj->def->uuid, uuidstr);
|
||||
|
||||
objdef = obj->def;
|
||||
virUUIDFormat(objdef->uuid, uuidstr);
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("filter '%s' already exists with uuid %s"),
|
||||
def->name, uuidstr);
|
||||
@ -261,8 +270,9 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
|
||||
|
||||
if ((obj = virNWFilterObjFindByName(nwfilters, def->name))) {
|
||||
|
||||
if (virNWFilterDefEqual(def, obj->def, false)) {
|
||||
virNWFilterDefFree(obj->def);
|
||||
objdef = obj->def;
|
||||
if (virNWFilterDefEqual(def, objdef, false)) {
|
||||
virNWFilterDefFree(objdef);
|
||||
obj->def = def;
|
||||
return obj;
|
||||
}
|
||||
@ -275,7 +285,7 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
virNWFilterDefFree(obj->def);
|
||||
virNWFilterDefFree(objdef);
|
||||
obj->def = def;
|
||||
obj->newDef = NULL;
|
||||
return obj;
|
||||
@ -334,12 +344,14 @@ virNWFilterObjGetNames(virNWFilterObjListPtr nwfilters,
|
||||
{
|
||||
int nnames = 0;
|
||||
size_t i;
|
||||
virNWFilterDefPtr def;
|
||||
|
||||
for (i = 0; i < nwfilters->count && nnames < maxnames; i++) {
|
||||
virNWFilterObjPtr obj = nwfilters->objs[i];
|
||||
virNWFilterObjLock(obj);
|
||||
if (!aclfilter || aclfilter(conn, obj->def)) {
|
||||
if (VIR_STRDUP(names[nnames], obj->def->name) < 0) {
|
||||
def = obj->def;
|
||||
if (!aclfilter || aclfilter(conn, def)) {
|
||||
if (VIR_STRDUP(names[nnames], def->name) < 0) {
|
||||
virNWFilterObjUnlock(obj);
|
||||
goto failure;
|
||||
}
|
||||
@ -368,6 +380,7 @@ virNWFilterObjListExport(virConnectPtr conn,
|
||||
int nfilters = 0;
|
||||
virNWFilterPtr filter = NULL;
|
||||
virNWFilterObjPtr obj = NULL;
|
||||
virNWFilterDefPtr def;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
@ -382,9 +395,9 @@ virNWFilterObjListExport(virConnectPtr conn,
|
||||
for (i = 0; i < nwfilters->count; i++) {
|
||||
obj = nwfilters->objs[i];
|
||||
virNWFilterObjLock(obj);
|
||||
if (!aclfilter || aclfilter(conn, obj->def)) {
|
||||
if (!(filter = virGetNWFilter(conn, obj->def->name,
|
||||
obj->def->uuid))) {
|
||||
def = obj->def;
|
||||
if (!aclfilter || aclfilter(conn, def)) {
|
||||
if (!(filter = virGetNWFilter(conn, def->name, def->uuid))) {
|
||||
virNWFilterObjUnlock(obj);
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -358,6 +358,7 @@ nwfilterLookupByUUID(virConnectPtr conn,
|
||||
const unsigned char *uuid)
|
||||
{
|
||||
virNWFilterObjPtr obj;
|
||||
virNWFilterDefPtr def;
|
||||
virNWFilterPtr ret = NULL;
|
||||
|
||||
nwfilterDriverLock();
|
||||
@ -369,11 +370,12 @@ nwfilterLookupByUUID(virConnectPtr conn,
|
||||
"%s", _("no nwfilter with matching uuid"));
|
||||
goto cleanup;
|
||||
}
|
||||
def = obj->def;
|
||||
|
||||
if (virNWFilterLookupByUUIDEnsureACL(conn, obj->def) < 0)
|
||||
if (virNWFilterLookupByUUIDEnsureACL(conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = virGetNWFilter(conn, obj->def->name, obj->def->uuid);
|
||||
ret = virGetNWFilter(conn, def->name, def->uuid);
|
||||
|
||||
cleanup:
|
||||
if (obj)
|
||||
@ -387,6 +389,7 @@ nwfilterLookupByName(virConnectPtr conn,
|
||||
const char *name)
|
||||
{
|
||||
virNWFilterObjPtr obj;
|
||||
virNWFilterDefPtr def;
|
||||
virNWFilterPtr ret = NULL;
|
||||
|
||||
nwfilterDriverLock();
|
||||
@ -398,11 +401,12 @@ nwfilterLookupByName(virConnectPtr conn,
|
||||
_("no nwfilter with matching name '%s'"), name);
|
||||
goto cleanup;
|
||||
}
|
||||
def = obj->def;
|
||||
|
||||
if (virNWFilterLookupByNameEnsureACL(conn, obj->def) < 0)
|
||||
if (virNWFilterLookupByNameEnsureACL(conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = virGetNWFilter(conn, obj->def->name, obj->def->uuid);
|
||||
ret = virGetNWFilter(conn, def->name, def->uuid);
|
||||
|
||||
cleanup:
|
||||
if (obj)
|
||||
@ -467,6 +471,7 @@ nwfilterDefineXML(virConnectPtr conn,
|
||||
{
|
||||
virNWFilterDefPtr def;
|
||||
virNWFilterObjPtr obj = NULL;
|
||||
virNWFilterDefPtr objdef;
|
||||
virNWFilterPtr ret = NULL;
|
||||
|
||||
if (!driver->privileged) {
|
||||
@ -487,15 +492,15 @@ nwfilterDefineXML(virConnectPtr conn,
|
||||
|
||||
if (!(obj = virNWFilterObjAssignDef(&driver->nwfilters, def)))
|
||||
goto cleanup;
|
||||
def = NULL;
|
||||
objdef = obj->def;
|
||||
|
||||
if (virNWFilterSaveDef(driver->configDir, def) < 0) {
|
||||
if (virNWFilterSaveDef(driver->configDir, objdef) < 0) {
|
||||
virNWFilterObjRemove(&driver->nwfilters, obj);
|
||||
def = NULL;
|
||||
goto cleanup;
|
||||
}
|
||||
def = NULL;
|
||||
|
||||
ret = virGetNWFilter(conn, obj->def->name, obj->def->uuid);
|
||||
ret = virGetNWFilter(conn, objdef->name, objdef->uuid);
|
||||
|
||||
cleanup:
|
||||
virNWFilterDefFree(def);
|
||||
|
Loading…
Reference in New Issue
Block a user