[PATCH v3 3/9] interface: Use virInterfaceDefPtr rather than deref from virInterfaceObjPtr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/conf/virinterfaceobj.c | 32 +++++++++++++++++++++-----------
 src/test/test_driver.c     | 12 +++++++++---
 2 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c
index 62c3735..ead9512 100644
--- a/src/conf/virinterfaceobj.c
+++ b/src/conf/virinterfaceobj.c
@@ -72,18 +72,21 @@ virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces,
     unsigned int matchct = 0;
 
     for (i = 0; i < interfaces->count; i++) {
+        virInterfaceObjPtr obj = interfaces->objs[i];
+        virInterfaceDefPtr def;
 
-        virInterfaceObjLock(interfaces->objs[i]);
-        if (STRCASEEQ(interfaces->objs[i]->def->mac, mac)) {
+        virInterfaceObjLock(obj);
+        def = obj->def;
+        if (STRCASEEQ(def->mac, mac)) {
             matchct++;
             if (matchct <= maxmatches) {
-                matches[matchct - 1] = interfaces->objs[i];
+                matches[matchct - 1] = obj;
                 /* keep the lock if we're returning object to caller */
                 /* it is the caller's responsibility to unlock *all* matches */
                 continue;
             }
         }
-        virInterfaceObjUnlock(interfaces->objs[i]);
+        virInterfaceObjUnlock(obj);
 
     }
     return matchct;
@@ -97,10 +100,14 @@ virInterfaceObjFindByName(virInterfaceObjListPtr interfaces,
     size_t i;
 
     for (i = 0; i < interfaces->count; i++) {
-        virInterfaceObjLock(interfaces->objs[i]);
-        if (STREQ(interfaces->objs[i]->def->name, name))
-            return interfaces->objs[i];
-        virInterfaceObjUnlock(interfaces->objs[i]);
+        virInterfaceObjPtr obj = interfaces->objs[i];
+        virInterfaceDefPtr def;
+
+        virInterfaceObjLock(obj);
+        def = obj->def;
+        if (STREQ(def->name, name))
+            return obj;
+        virInterfaceObjUnlock(obj);
     }
 
     return NULL;
@@ -134,10 +141,10 @@ virInterfaceObjListClone(virInterfaceObjListPtr src,
     virInterfaceObjListFree(dest); /* start with an empty list */
     cnt = src->count;
     for (i = 0; i < cnt; i++) {
-        virInterfaceDefPtr def = src->objs[i]->def;
+        virInterfaceObjPtr srcobj = src->objs[i];
         virInterfaceDefPtr backup;
         virInterfaceObjPtr obj;
-        char *xml = virInterfaceDefFormat(def);
+        char *xml = virInterfaceDefFormat(srcobj->def);
 
         if (!xml)
             goto cleanup;
@@ -247,9 +254,12 @@ virInterfaceObjGetNames(virInterfaceObjListPtr interfaces,
 
     for (i = 0; i < interfaces->count && nnames < maxnames; i++) {
         virInterfaceObjPtr obj = interfaces->objs[i];
+        virInterfaceDefPtr def;
+
         virInterfaceObjLock(obj);
+        def = obj->def;
         if (wantActive == virInterfaceObjIsActive(obj)) {
-            if (VIR_STRDUP(names[nnames], obj->def->name) < 0) {
+            if (VIR_STRDUP(names[nnames], def->name) < 0) {
                 virInterfaceObjUnlock(obj);
                 goto failure;
             }
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 8f7ff63..29c31ad 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3706,12 +3706,14 @@ testInterfaceLookupByName(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virInterfaceObjPtr obj;
+    virInterfaceDefPtr def;
     virInterfacePtr ret = NULL;
 
     if (!(obj = testInterfaceObjFindByName(privconn, name)))
         return NULL;
+    def = obj->def;
 
-    ret = virGetInterface(conn, obj->def->name, obj->def->mac);
+    ret = virGetInterface(conn, def->name, def->mac);
 
     virInterfaceObjUnlock(obj);
     return ret;
@@ -3724,6 +3726,7 @@ testInterfaceLookupByMACString(virConnectPtr conn,
 {
     testDriverPtr privconn = conn->privateData;
     virInterfaceObjPtr obj;
+    virInterfaceDefPtr def;
     int ifacect;
     virInterfacePtr ret = NULL;
 
@@ -3741,7 +3744,8 @@ testInterfaceLookupByMACString(virConnectPtr conn,
         goto cleanup;
     }
 
-    ret = virGetInterface(conn, obj->def->name, obj->def->mac);
+    def = obj->def;
+    ret = virGetInterface(conn, def->name, def->mac);
 
  cleanup:
     if (obj)
@@ -3888,6 +3892,7 @@ testInterfaceDefineXML(virConnectPtr conn,
     testDriverPtr privconn = conn->privateData;
     virInterfaceDefPtr def;
     virInterfaceObjPtr obj = NULL;
+    virInterfaceDefPtr objdef;
     virInterfacePtr ret = NULL;
 
     virCheckFlags(0, NULL);
@@ -3899,8 +3904,9 @@ testInterfaceDefineXML(virConnectPtr conn,
     if ((obj = virInterfaceObjAssignDef(&privconn->ifaces, def)) == NULL)
         goto cleanup;
     def = NULL;
+    objdef = obj->def;
 
-    ret = virGetInterface(conn, obj->def->name, obj->def->mac);
+    ret = virGetInterface(conn, objdef->name, objdef->mac);
 
  cleanup:
     virInterfaceDefFree(def);
-- 
2.9.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux