interface: Use virInterfaceDefPtr rather than deref from virInterfaceObjPtr

We're about to make the obj much more private, so make it easier to
see future changes which will require accessors for the obj->def

This also includes modifying some interfaces->objs[i]->X references to be
obj = interfaces->objs[i]; and then def = obj->def

Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
John Ferlan 2017-04-18 22:32:17 -04:00
parent 4845df2784
commit 4939f0b25d
2 changed files with 30 additions and 14 deletions

View File

@ -72,18 +72,21 @@ virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces,
unsigned int matchct = 0; unsigned int matchct = 0;
for (i = 0; i < interfaces->count; i++) { for (i = 0; i < interfaces->count; i++) {
virInterfaceObjPtr obj = interfaces->objs[i];
virInterfaceDefPtr def;
virInterfaceObjLock(interfaces->objs[i]); virInterfaceObjLock(obj);
if (STRCASEEQ(interfaces->objs[i]->def->mac, mac)) { def = obj->def;
if (STRCASEEQ(def->mac, mac)) {
matchct++; matchct++;
if (matchct <= maxmatches) { if (matchct <= maxmatches) {
matches[matchct - 1] = interfaces->objs[i]; matches[matchct - 1] = obj;
/* keep the lock if we're returning object to caller */ /* keep the lock if we're returning object to caller */
/* it is the caller's responsibility to unlock *all* matches */ /* it is the caller's responsibility to unlock *all* matches */
continue; continue;
} }
} }
virInterfaceObjUnlock(interfaces->objs[i]); virInterfaceObjUnlock(obj);
} }
return matchct; return matchct;
@ -97,10 +100,14 @@ virInterfaceObjFindByName(virInterfaceObjListPtr interfaces,
size_t i; size_t i;
for (i = 0; i < interfaces->count; i++) { for (i = 0; i < interfaces->count; i++) {
virInterfaceObjLock(interfaces->objs[i]); virInterfaceObjPtr obj = interfaces->objs[i];
if (STREQ(interfaces->objs[i]->def->name, name)) virInterfaceDefPtr def;
return interfaces->objs[i];
virInterfaceObjUnlock(interfaces->objs[i]); virInterfaceObjLock(obj);
def = obj->def;
if (STREQ(def->name, name))
return obj;
virInterfaceObjUnlock(obj);
} }
return NULL; return NULL;
@ -134,10 +141,10 @@ virInterfaceObjListClone(virInterfaceObjListPtr src,
virInterfaceObjListFree(dest); /* start with an empty list */ virInterfaceObjListFree(dest); /* start with an empty list */
cnt = src->count; cnt = src->count;
for (i = 0; i < cnt; i++) { for (i = 0; i < cnt; i++) {
virInterfaceDefPtr def = src->objs[i]->def; virInterfaceObjPtr srcobj = src->objs[i];
virInterfaceDefPtr backup; virInterfaceDefPtr backup;
virInterfaceObjPtr obj; virInterfaceObjPtr obj;
char *xml = virInterfaceDefFormat(def); char *xml = virInterfaceDefFormat(srcobj->def);
if (!xml) if (!xml)
goto cleanup; goto cleanup;
@ -247,9 +254,12 @@ virInterfaceObjGetNames(virInterfaceObjListPtr interfaces,
for (i = 0; i < interfaces->count && nnames < maxnames; i++) { for (i = 0; i < interfaces->count && nnames < maxnames; i++) {
virInterfaceObjPtr obj = interfaces->objs[i]; virInterfaceObjPtr obj = interfaces->objs[i];
virInterfaceDefPtr def;
virInterfaceObjLock(obj); virInterfaceObjLock(obj);
def = obj->def;
if (wantActive == virInterfaceObjIsActive(obj)) { if (wantActive == virInterfaceObjIsActive(obj)) {
if (VIR_STRDUP(names[nnames], obj->def->name) < 0) { if (VIR_STRDUP(names[nnames], def->name) < 0) {
virInterfaceObjUnlock(obj); virInterfaceObjUnlock(obj);
goto failure; goto failure;
} }

View File

@ -3706,12 +3706,14 @@ testInterfaceLookupByName(virConnectPtr conn,
{ {
testDriverPtr privconn = conn->privateData; testDriverPtr privconn = conn->privateData;
virInterfaceObjPtr obj; virInterfaceObjPtr obj;
virInterfaceDefPtr def;
virInterfacePtr ret = NULL; virInterfacePtr ret = NULL;
if (!(obj = testInterfaceObjFindByName(privconn, name))) if (!(obj = testInterfaceObjFindByName(privconn, name)))
return NULL; return NULL;
def = obj->def;
ret = virGetInterface(conn, obj->def->name, obj->def->mac); ret = virGetInterface(conn, def->name, def->mac);
virInterfaceObjUnlock(obj); virInterfaceObjUnlock(obj);
return ret; return ret;
@ -3724,6 +3726,7 @@ testInterfaceLookupByMACString(virConnectPtr conn,
{ {
testDriverPtr privconn = conn->privateData; testDriverPtr privconn = conn->privateData;
virInterfaceObjPtr obj; virInterfaceObjPtr obj;
virInterfaceDefPtr def;
int ifacect; int ifacect;
virInterfacePtr ret = NULL; virInterfacePtr ret = NULL;
@ -3741,7 +3744,8 @@ testInterfaceLookupByMACString(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
ret = virGetInterface(conn, obj->def->name, obj->def->mac); def = obj->def;
ret = virGetInterface(conn, def->name, def->mac);
cleanup: cleanup:
if (obj) if (obj)
@ -3888,6 +3892,7 @@ testInterfaceDefineXML(virConnectPtr conn,
testDriverPtr privconn = conn->privateData; testDriverPtr privconn = conn->privateData;
virInterfaceDefPtr def; virInterfaceDefPtr def;
virInterfaceObjPtr obj = NULL; virInterfaceObjPtr obj = NULL;
virInterfaceDefPtr objdef;
virInterfacePtr ret = NULL; virInterfacePtr ret = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
@ -3899,8 +3904,9 @@ testInterfaceDefineXML(virConnectPtr conn,
if ((obj = virInterfaceObjAssignDef(&privconn->ifaces, def)) == NULL) if ((obj = virInterfaceObjAssignDef(&privconn->ifaces, def)) == NULL)
goto cleanup; goto cleanup;
def = NULL; def = NULL;
objdef = obj->def;
ret = virGetInterface(conn, obj->def->name, obj->def->mac); ret = virGetInterface(conn, objdef->name, objdef->mac);
cleanup: cleanup:
virInterfaceDefFree(def); virInterfaceDefFree(def);