From nobody Sun Feb 8 20:00:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1493159850728602.6620125844414; Tue, 25 Apr 2017 15:37:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03D4661B8C; Tue, 25 Apr 2017 22:37:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C64E17BE49; Tue, 25 Apr 2017 22:37:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6D0A018523D7; Tue, 25 Apr 2017 22:37:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3PMb4Sg029204 for ; Tue, 25 Apr 2017 18:37:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BCBE1811B; Tue, 25 Apr 2017 22:37:04 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-16.phx2.redhat.com [10.3.116.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 595D460E3E for ; Tue, 25 Apr 2017 22:37:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 03D4661B8C Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 03D4661B8C From: John Ferlan To: libvir-list@redhat.com Date: Tue, 25 Apr 2017 18:36:53 -0400 Message-Id: <20170425223656.20740-6-jferlan@redhat.com> In-Reply-To: <20170425223656.20740-1-jferlan@redhat.com> References: <20170425223656.20740-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/8] interface: Make _virInterfaceObjList struct private X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 25 Apr 2017 22:37:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the structs into virinterfaceobj.c, create necessary accessors, and initializers. This also includes reworking virInterfaceObjListClone to handle receiving a source interfaces list pointer, creating the destination interfaces objec= t, and copying everything from source into dest. Signed-off-by: John Ferlan --- src/conf/virinterfaceobj.c | 58 ++++++++++++++++++++++++++++--------------= ---- src/conf/virinterfaceobj.h | 12 ++++------ src/test/test_driver.c | 38 ++++++++++++++---------------- 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src/conf/virinterfaceobj.c b/src/conf/virinterfaceobj.c index 68faa66..301ad94 100644 --- a/src/conf/virinterfaceobj.c +++ b/src/conf/virinterfaceobj.c @@ -39,6 +39,10 @@ struct _virInterfaceObj { virInterfaceDefPtr def; /* The interface definition */ }; =20 +struct _virInterfaceObjList { + size_t count; + virInterfaceObjPtr *objs; +}; =20 /* virInterfaceObj manipulation */ =20 @@ -90,6 +94,17 @@ virInterfaceObjSetActive(virInterfaceObjPtr obj, =20 =20 /* virInterfaceObjList manipulation */ +virInterfaceObjListPtr +virInterfaceObjListNew(void) +{ + virInterfaceObjListPtr interfaces; + + if (VIR_ALLOC(interfaces) < 0) + return NULL; + return interfaces; +} + + int virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, const char *mac, @@ -148,50 +163,49 @@ virInterfaceObjListFree(virInterfaceObjListPtr interf= aces) =20 for (i =3D 0; i < interfaces->count; i++) virInterfaceObjFree(interfaces->objs[i]); - - VIR_FREE(interfaces->objs); - interfaces->count =3D 0; + VIR_FREE(interfaces); } =20 =20 -int -virInterfaceObjListClone(virInterfaceObjListPtr src, - virInterfaceObjListPtr dest) +virInterfaceObjListPtr +virInterfaceObjListClone(virInterfaceObjListPtr interfaces) { - int ret =3D -1; size_t i; unsigned int cnt; + virInterfaceObjListPtr dest; =20 - if (!src || !dest) - goto cleanup; + if (!interfaces) + return NULL; =20 - virInterfaceObjListFree(dest); /* start with an empty list */ - cnt =3D src->count; + if (!(dest =3D virInterfaceObjListNew())) + return NULL; + + cnt =3D interfaces->count; for (i =3D 0; i < cnt; i++) { - virInterfaceObjPtr srcobj =3D src->objs[i]; + virInterfaceObjPtr srcobj =3D interfaces->objs[i]; virInterfaceDefPtr backup; virInterfaceObjPtr obj; char *xml =3D virInterfaceDefFormat(srcobj->def); =20 if (!xml) - goto cleanup; + goto error; =20 - if ((backup =3D virInterfaceDefParseString(xml)) =3D=3D NULL) { + if (!(backup =3D virInterfaceDefParseString(xml))) { VIR_FREE(xml); - goto cleanup; + goto error; } =20 VIR_FREE(xml); - if ((obj =3D virInterfaceObjAssignDef(dest, backup)) =3D=3D NULL) - goto cleanup; + if (!(obj =3D virInterfaceObjAssignDef(dest, backup))) + goto error; virInterfaceObjUnlock(obj); /* locked by virInterfaceObjAssignDef = */ } =20 - ret =3D cnt; - cleanup: - if ((ret < 0) && dest) - virInterfaceObjListFree(dest); - return ret; + return dest; + + error: + virInterfaceObjListFree(dest); + return NULL; } =20 =20 diff --git a/src/conf/virinterfaceobj.h b/src/conf/virinterfaceobj.h index 79b6fc9..19c4947 100644 --- a/src/conf/virinterfaceobj.h +++ b/src/conf/virinterfaceobj.h @@ -27,10 +27,6 @@ typedef virInterfaceObj *virInterfaceObjPtr; =20 typedef struct _virInterfaceObjList virInterfaceObjList; typedef virInterfaceObjList *virInterfaceObjListPtr; -struct _virInterfaceObjList { - size_t count; - virInterfaceObjPtr *objs; -}; =20 virInterfaceDefPtr virInterfaceObjGetDef(virInterfaceObjPtr obj); @@ -42,6 +38,9 @@ void virInterfaceObjSetActive(virInterfaceObjPtr obj, bool active); =20 +virInterfaceObjListPtr +virInterfaceObjListNew(void); + int virInterfaceObjFindByMACString(virInterfaceObjListPtr interfaces, const char *mac, @@ -57,9 +56,8 @@ virInterfaceObjFree(virInterfaceObjPtr obj); void virInterfaceObjListFree(virInterfaceObjListPtr vms); =20 -int -virInterfaceObjListClone(virInterfaceObjListPtr src, - virInterfaceObjListPtr dest); +virInterfaceObjListPtr +virInterfaceObjListClone(virInterfaceObjListPtr interfaces); =20 virInterfaceObjPtr virInterfaceObjAssignDef(virInterfaceObjListPtr interfaces, diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 412d9f1..2cd55ec 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -97,9 +97,9 @@ struct _testDriver { virMutex lock; =20 virNodeInfo nodeInfo; - virInterfaceObjList ifaces; + virInterfaceObjListPtr ifaces; bool transaction_running; - virInterfaceObjList backupIfaces; + virInterfaceObjListPtr backupIfaces; virStoragePoolObjList pools; virNodeDeviceObjList devs; int numCells; @@ -154,7 +154,7 @@ testDriverFree(testDriverPtr driver) virObjectUnref(driver->domains); virNodeDeviceObjListFree(&driver->devs); virObjectUnref(driver->networks); - virInterfaceObjListFree(&driver->ifaces); + virInterfaceObjListFree(driver->ifaces); virStoragePoolObjListFree(&driver->pools); virObjectUnref(driver->eventState); virMutexUnlock(&driver->lock); @@ -416,6 +416,7 @@ testDriverNew(void) =20 if (!(ret->xmlopt =3D virDomainXMLOptionNew(NULL, NULL, &ns)) || !(ret->eventState =3D virObjectEventStateNew()) || + !(ret->ifaces =3D virInterfaceObjListNew()) || !(ret->domains =3D virDomainObjListNew()) || !(ret->networks =3D virNetworkObjListNew())) goto error; @@ -1020,7 +1021,7 @@ testParseInterfaces(testDriverPtr privconn, if (!def) goto error; =20 - if (!(obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def))) { + if (!(obj =3D virInterfaceObjAssignDef(privconn->ifaces, def))) { virInterfaceDefFree(def); goto error; } @@ -3630,7 +3631,7 @@ testInterfaceObjFindByName(testDriverPtr privconn, virInterfaceObjPtr obj; =20 testDriverLock(privconn); - obj =3D virInterfaceObjFindByName(&privconn->ifaces, name); + obj =3D virInterfaceObjFindByName(privconn->ifaces, name); testDriverUnlock(privconn); =20 if (!obj) @@ -3649,7 +3650,7 @@ testConnectNumOfInterfaces(virConnectPtr conn) int ninterfaces; =20 testDriverLock(privconn); - ninterfaces =3D virInterfaceObjNumOfInterfaces(&privconn->ifaces, true= ); + ninterfaces =3D virInterfaceObjNumOfInterfaces(privconn->ifaces, true); testDriverUnlock(privconn); return ninterfaces; } @@ -3664,7 +3665,7 @@ testConnectListInterfaces(virConnectPtr conn, int nnames; =20 testDriverLock(privconn); - nnames =3D virInterfaceObjGetNames(&privconn->ifaces, true, names, max= names); + nnames =3D virInterfaceObjGetNames(privconn->ifaces, true, names, maxn= ames); testDriverUnlock(privconn); =20 return nnames; @@ -3678,7 +3679,7 @@ testConnectNumOfDefinedInterfaces(virConnectPtr conn) int ninterfaces; =20 testDriverLock(privconn); - ninterfaces =3D virInterfaceObjNumOfInterfaces(&privconn->ifaces, fals= e); + ninterfaces =3D virInterfaceObjNumOfInterfaces(privconn->ifaces, false= ); testDriverUnlock(privconn); return ninterfaces; } @@ -3693,7 +3694,7 @@ testConnectListDefinedInterfaces(virConnectPtr conn, int nnames; =20 testDriverLock(privconn); - nnames =3D virInterfaceObjGetNames(&privconn->ifaces, false, names, ma= xnames); + nnames =3D virInterfaceObjGetNames(privconn->ifaces, false, names, max= names); testDriverUnlock(privconn); =20 return nnames; @@ -3731,7 +3732,7 @@ testInterfaceLookupByMACString(virConnectPtr conn, virInterfacePtr ret =3D NULL; =20 testDriverLock(privconn); - ifacect =3D virInterfaceObjFindByMACString(&privconn->ifaces, mac, &ob= j, 1); + ifacect =3D virInterfaceObjFindByMACString(privconn->ifaces, mac, &obj= , 1); testDriverUnlock(privconn); =20 if (ifacect =3D=3D 0) { @@ -3789,8 +3790,7 @@ testInterfaceChangeBegin(virConnectPtr conn, =20 privconn->transaction_running =3D true; =20 - if (virInterfaceObjListClone(&privconn->ifaces, - &privconn->backupIfaces) < 0) + if (!(privconn->backupIfaces =3D virInterfaceObjListClone(privconn->if= aces))) goto cleanup; =20 ret =3D 0; @@ -3818,7 +3818,7 @@ testInterfaceChangeCommit(virConnectPtr conn, goto cleanup; } =20 - virInterfaceObjListFree(&privconn->backupIfaces); + virInterfaceObjListFree(privconn->backupIfaces); privconn->transaction_running =3D false; =20 ret =3D 0; @@ -3848,11 +3848,9 @@ testInterfaceChangeRollback(virConnectPtr conn, goto cleanup; } =20 - virInterfaceObjListFree(&privconn->ifaces); - privconn->ifaces.count =3D privconn->backupIfaces.count; - privconn->ifaces.objs =3D privconn->backupIfaces.objs; - privconn->backupIfaces.count =3D 0; - privconn->backupIfaces.objs =3D NULL; + virInterfaceObjListFree(privconn->ifaces); + privconn->ifaces =3D privconn->backupIfaces; + privconn->backupIfaces =3D NULL; =20 privconn->transaction_running =3D false; =20 @@ -3903,7 +3901,7 @@ testInterfaceDefineXML(virConnectPtr conn, if (!(def =3D virInterfaceDefParseString(xmlStr))) goto cleanup; =20 - if ((obj =3D virInterfaceObjAssignDef(&privconn->ifaces, def)) =3D=3D = NULL) + if ((obj =3D virInterfaceObjAssignDef(privconn->ifaces, def)) =3D=3D N= ULL) goto cleanup; def =3D NULL; objdef =3D virInterfaceObjGetDef(obj); @@ -3928,7 +3926,7 @@ testInterfaceUndefine(virInterfacePtr iface) if (!(obj =3D testInterfaceObjFindByName(privconn, iface->name))) return -1; =20 - virInterfaceObjRemove(&privconn->ifaces, obj); + virInterfaceObjRemove(privconn->ifaces, obj); =20 return 0; } --=20 2.9.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list