From nobody Wed May 14 20:23:16 2025 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.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1518433172462445.5539723180269; Mon, 12 Feb 2018 02:59:32 -0800 (PST) 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 2887249003; Mon, 12 Feb 2018 10:59:31 +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 F2E4B5C266; Mon, 12 Feb 2018 10:59:30 +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 B721918033E6; Mon, 12 Feb 2018 10:59:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w1CAr4PU025675 for ; Mon, 12 Feb 2018 05:53:04 -0500 Received: by smtp.corp.redhat.com (Postfix) id E0211124BB36; Mon, 12 Feb 2018 10:53:03 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-25.brq.redhat.com [10.40.204.25]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2CBBF1227923; Mon, 12 Feb 2018 10:53:03 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 12 Feb 2018 11:52:50 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/6] virNWFilterObj: Turn into virObjectLockable 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.38]); Mon, 12 Feb 2018 10:59:31 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The virNWFilterObj requires recursive locks, otherwise it is regular virObject. So when creating the object we must call virObjectRecursiveLockableNew(). Other than that, this is pure replacement of virNWFilterObj*() APIs with thei virObject*() counterparts. Based-on-work-of: John Ferlan Signed-off-by: Michal Privoznik --- src/conf/virnwfilterobj.c | 121 ++++++++++++++++-------------= ---- src/conf/virnwfilterobj.h | 6 -- src/libvirt_private.syms | 2 - src/nwfilter/nwfilter_driver.c | 10 +-- src/nwfilter/nwfilter_gentech_driver.c | 10 +-- 5 files changed, 67 insertions(+), 82 deletions(-) diff --git a/src/conf/virnwfilterobj.c b/src/conf/virnwfilterobj.c index 87d7e7270..a472ff531 100644 --- a/src/conf/virnwfilterobj.c +++ b/src/conf/virnwfilterobj.c @@ -34,7 +34,7 @@ VIR_LOG_INIT("conf.virnwfilterobj"); =20 struct _virNWFilterObj { - virMutex lock; + virObjectLockable parent; =20 bool wantRemoved; =20 @@ -42,32 +42,54 @@ struct _virNWFilterObj { virNWFilterDefPtr newDef; }; =20 +static virClassPtr virNWFilterObjClass; +static void virNWFilterObjDispose(void *obj); + struct _virNWFilterObjList { size_t count; virNWFilterObjPtr *objs; }; =20 +static int virNWFilterObjOnceInit(void) +{ + if (!(virNWFilterObjClass =3D virClassNew(virClassForObjectLockable(), + "virNWFilterObj", + sizeof(virNWFilterObj), + virNWFilterObjDispose))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virNWFilterObj) + =20 static virNWFilterObjPtr virNWFilterObjNew(void) { virNWFilterObjPtr obj; =20 - if (VIR_ALLOC(obj) < 0) + if (virNWFilterObjInitialize() < 0) return NULL; =20 - if (virMutexInitRecursive(&obj->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(obj); + if (!(obj =3D virObjectRecursiveLockableNew(virNWFilterObjClass))) return NULL; - } =20 - virNWFilterObjLock(obj); + virObjectLock(obj); return obj; } =20 =20 +static void +virNWFilterObjDispose(void *opaque) +{ + virNWFilterObjPtr obj =3D opaque; + + virNWFilterDefFree(obj->def); + virNWFilterDefFree(obj->newDef); +} + + virNWFilterDefPtr virNWFilterObjGetDef(virNWFilterObjPtr obj) { @@ -89,27 +111,12 @@ virNWFilterObjWantRemoved(virNWFilterObjPtr obj) } =20 =20 -static void -virNWFilterObjFree(virNWFilterObjPtr obj) -{ - if (!obj) - return; - - virNWFilterDefFree(obj->def); - virNWFilterDefFree(obj->newDef); - - virMutexDestroy(&obj->lock); - - VIR_FREE(obj); -} - - void virNWFilterObjListFree(virNWFilterObjListPtr nwfilters) { size_t i; for (i =3D 0; i < nwfilters->count; i++) - virNWFilterObjFree(nwfilters->objs[i]); + virObjectUnref(nwfilters->objs[i]); VIR_FREE(nwfilters->objs); VIR_FREE(nwfilters); } @@ -132,18 +139,18 @@ virNWFilterObjListRemove(virNWFilterObjListPtr nwfilt= ers, { size_t i; =20 - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); =20 for (i =3D 0; i < nwfilters->count; i++) { - virNWFilterObjLock(nwfilters->objs[i]); + virObjectLock(nwfilters->objs[i]); if (nwfilters->objs[i] =3D=3D obj) { - virNWFilterObjUnlock(nwfilters->objs[i]); - virNWFilterObjFree(nwfilters->objs[i]); + virObjectUnlock(nwfilters->objs[i]); + virObjectUnref(nwfilters->objs[i]); =20 VIR_DELETE_ELEMENT(nwfilters->objs, i, nwfilters->count); break; } - virNWFilterObjUnlock(nwfilters->objs[i]); + virObjectUnlock(nwfilters->objs[i]); } } =20 @@ -158,11 +165,11 @@ virNWFilterObjListFindByUUID(virNWFilterObjListPtr nw= filters, =20 for (i =3D 0; i < nwfilters->count; i++) { obj =3D nwfilters->objs[i]; - virNWFilterObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (!memcmp(def->uuid, uuid, VIR_UUID_BUFLEN)) return obj; - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -179,11 +186,11 @@ virNWFilterObjListFindByName(virNWFilterObjListPtr nw= filters, =20 for (i =3D 0; i < nwfilters->count; i++) { obj =3D nwfilters->objs[i]; - virNWFilterObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (STREQ_NULLABLE(def->name, name)) return obj; - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -205,7 +212,7 @@ virNWFilterObjListFindInstantiateFilter(virNWFilterObjL= istPtr nwfilters, if (virNWFilterObjWantRemoved(obj)) { virReportError(VIR_ERR_NO_NWFILTER, _("Filter '%s' is in use."), filtername); - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return NULL; } =20 @@ -240,7 +247,7 @@ _virNWFilterObjListDefLoopDetect(virNWFilterObjListPtr = nwfilters, if (obj) { rc =3D _virNWFilterObjListDefLoopDetect(nwfilters, obj->de= f, filtername); - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); if (rc < 0) break; } @@ -322,10 +329,10 @@ virNWFilterObjListAssignDef(virNWFilterObjListPtr nwf= ilters, _("filter with same UUID but different name " "('%s') already exists"), objdef->name); - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return NULL; } - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } else { if ((obj =3D virNWFilterObjListFindByName(nwfilters, def->name))) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -335,7 +342,7 @@ virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfil= ters, virReportError(VIR_ERR_OPERATION_FAILED, _("filter '%s' already exists with uuid %s"), def->name, uuidstr); - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return NULL; } } @@ -360,7 +367,7 @@ virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfil= ters, /* trigger the update on VMs referencing the filter */ if (virNWFilterTriggerVMFilterRebuild() < 0) { obj->newDef =3D NULL; - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return NULL; } =20 @@ -375,8 +382,8 @@ virNWFilterObjListAssignDef(virNWFilterObjListPtr nwfil= ters, =20 if (VIR_APPEND_ELEMENT_COPY(nwfilters->objs, nwfilters->count, obj) < 0) { - virNWFilterObjUnlock(obj); - virNWFilterObjFree(obj); + virObjectUnlock(obj); + virObjectUnref(obj); return NULL; } obj->def =3D def; @@ -395,10 +402,10 @@ virNWFilterObjListNumOfNWFilters(virNWFilterObjListPt= r nwfilters, =20 for (i =3D 0; i < nwfilters->count; i++) { virNWFilterObjPtr obj =3D nwfilters->objs[i]; - virNWFilterObjLock(obj); + virObjectLock(obj); if (!filter || filter(conn, obj->def)) nfilters++; - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } =20 return nfilters; @@ -418,16 +425,16 @@ virNWFilterObjListGetNames(virNWFilterObjListPtr nwfi= lters, =20 for (i =3D 0; i < nwfilters->count && nnames < maxnames; i++) { virNWFilterObjPtr obj =3D nwfilters->objs[i]; - virNWFilterObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (!filter || filter(conn, def)) { if (VIR_STRDUP(names[nnames], def->name) < 0) { - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); goto failure; } nnames++; } - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } =20 return nnames; @@ -464,16 +471,16 @@ virNWFilterObjListExport(virConnectPtr conn, =20 for (i =3D 0; i < nwfilters->count; i++) { obj =3D nwfilters->objs[i]; - virNWFilterObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (!filter || filter(conn, def)) { if (!(nwfilter =3D virGetNWFilter(conn, def->name, def->uuid))= ) { - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); goto cleanup; } tmp_filters[nfilters++] =3D nwfilter; } - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } =20 *filters =3D tmp_filters; @@ -552,23 +559,9 @@ virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr= nwfilters, =20 obj =3D virNWFilterObjListLoadConfig(nwfilters, configDir, entry->= d_name); if (obj) - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); } =20 VIR_DIR_CLOSE(dir); return ret; } - - -void -virNWFilterObjLock(virNWFilterObjPtr obj) -{ - virMutexLock(&obj->lock); -} - - -void -virNWFilterObjUnlock(virNWFilterObjPtr obj) -{ - virMutexUnlock(&obj->lock); -} diff --git a/src/conf/virnwfilterobj.h b/src/conf/virnwfilterobj.h index 8e79518ed..9faba264a 100644 --- a/src/conf/virnwfilterobj.h +++ b/src/conf/virnwfilterobj.h @@ -105,10 +105,4 @@ int virNWFilterObjListLoadAllConfigs(virNWFilterObjListPtr nwfilters, const char *configDir); =20 -void -virNWFilterObjLock(virNWFilterObjPtr obj); - -void -virNWFilterObjUnlock(virNWFilterObjPtr obj); - #endif /* VIRNWFILTEROBJ_H */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index fcf378105..67e3ade0f 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1052,9 +1052,7 @@ virNWFilterObjListLoadAllConfigs; virNWFilterObjListNew; virNWFilterObjListNumOfNWFilters; virNWFilterObjListRemove; -virNWFilterObjLock; virNWFilterObjTestUnassignDef; -virNWFilterObjUnlock; virNWFilterObjWantRemoved; =20 =20 diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c index 717bce269..ffd603d70 100644 --- a/src/nwfilter/nwfilter_driver.c +++ b/src/nwfilter/nwfilter_driver.c @@ -466,7 +466,7 @@ nwfilterLookupByUUID(virConnectPtr conn, nwfilter =3D virGetNWFilter(conn, def->name, def->uuid); =20 cleanup: - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return nwfilter; } =20 @@ -496,7 +496,7 @@ nwfilterLookupByName(virConnectPtr conn, nwfilter =3D virGetNWFilter(conn, def->name, def->uuid); =20 cleanup: - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return nwfilter; } =20 @@ -591,7 +591,7 @@ nwfilterDefineXML(virConnectPtr conn, cleanup: virNWFilterDefFree(def); if (obj) - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); =20 virNWFilterCallbackDriversUnlock(); virNWFilterUnlockFilterUpdates(); @@ -634,7 +634,7 @@ nwfilterUndefine(virNWFilterPtr nwfilter) =20 cleanup: if (obj) - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); =20 virNWFilterCallbackDriversUnlock(); virNWFilterUnlockFilterUpdates(); @@ -667,7 +667,7 @@ nwfilterGetXMLDesc(virNWFilterPtr nwfilter, ret =3D virNWFilterDefFormat(def); =20 cleanup: - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return ret; } =20 diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter= _gentech_driver.c index 840d419bb..106364c67 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -316,7 +316,7 @@ virNWFilterInstReset(virNWFilterInstPtr inst) size_t i; =20 for (i =3D 0; i < inst->nfilters; i++) - virNWFilterObjUnlock(inst->filters[i]); + virObjectUnlock(inst->filters[i]); VIR_FREE(inst->filters); inst->nfilters =3D 0; =20 @@ -427,7 +427,7 @@ virNWFilterIncludeDefToRuleInst(virNWFilterDriverStateP= tr driver, virNWFilterInstReset(inst); virNWFilterHashTableFree(tmpvars); if (obj) - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return ret; } =20 @@ -541,7 +541,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, =20 /* create a temporary hashmap for depth-first tree traversal */ if (!(tmpvars =3D virNWFilterCreateVarsFrom(inc->params, vars)= )) { - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); return -1; } =20 @@ -565,7 +565,7 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr fi= lter, =20 virNWFilterHashTableFree(tmpvars); =20 - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); if (rc < 0) return -1; } @@ -839,7 +839,7 @@ virNWFilterInstantiateFilterUpdate(virNWFilterDriverSta= tePtr driver, virNWFilterHashTableFree(vars1); =20 err_exit: - virNWFilterObjUnlock(obj); + virObjectUnlock(obj); =20 VIR_FREE(str_ipaddr); VIR_FREE(str_macaddr); --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list