From patchwork Sun Apr 24 23:22:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cole Robinson X-Patchwork-Id: 66547 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp758351qge; Sun, 24 Apr 2016 16:26:01 -0700 (PDT) X-Received: by 10.66.41.43 with SMTP id c11mr44688988pal.96.1461540361621; Sun, 24 Apr 2016 16:26:01 -0700 (PDT) Return-Path: Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com. [209.132.183.24]) by mx.google.com with ESMTPS id hc2si2835936pac.65.2016.04.24.16.26.00 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 24 Apr 2016 16:26:01 -0700 (PDT) Received-SPF: pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) client-ip=209.132.183.24; Authentication-Results: mx.google.com; spf=pass (google.com: domain of libvir-list-bounces@redhat.com designates 209.132.183.24 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3ONN0X1012267; Sun, 24 Apr 2016 19:23:01 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u3ONMw6U015470 for ; Sun, 24 Apr 2016 19:22:58 -0400 Received: from colepc.redhat.com (ovpn-113-101.phx2.redhat.com [10.3.113.101]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u3ONMu3V006147; Sun, 24 Apr 2016 19:22:58 -0400 From: Cole Robinson To: libvirt-list@redhat.com Date: Sun, 24 Apr 2016 19:22:51 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/4] nwfilter: Push configFile building into LoadConfig 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 Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com This matches the pattern used for network object APIs, and we want configDir in LoadConfig for upcoming patches --- src/conf/nwfilter_conf.c | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) -- 2.7.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index d02bbff..d8e83f0 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -3156,30 +3156,39 @@ virNWFilterObjAssignDef(virNWFilterObjListPtr nwfilters, static virNWFilterObjPtr -virNWFilterObjLoad(virNWFilterObjListPtr nwfilters, - const char *file, - const char *path) +virNWFilterLoadConfig(virNWFilterObjListPtr nwfilters, + const char *configDir, + const char *name) { - virNWFilterDefPtr def; + virNWFilterDefPtr def = NULL; virNWFilterObjPtr nwfilter; + char *configFile = NULL; - if (!(def = virNWFilterDefParseFile(path))) - return NULL; + if (!(configFile = virFileBuildPath(configDir, name, ".xml"))) + goto error; - if (!virFileMatchesNameSuffix(file, def->name, ".xml")) { + if (!(def = virNWFilterDefParseFile(configFile))) + goto error; + + if (STRNEQ(name, def->name)) { virReportError(VIR_ERR_XML_ERROR, - _("network filter config filename '%s' does not match name '%s'"), - path, def->name); - virNWFilterDefFree(def); - return NULL; + _("network filter config filename '%s' " + "does not match name '%s'"), + configFile, def->name); + goto error; } if (!(nwfilter = virNWFilterObjAssignDef(nwfilters, def))) { - virNWFilterDefFree(def); - return NULL; + goto error; } + VIR_FREE(configFile); return nwfilter; + + error: + VIR_FREE(configFile); + virNWFilterDefFree(def); + return NULL; } @@ -3200,23 +3209,17 @@ virNWFilterLoadAllConfigs(virNWFilterObjListPtr nwfilters, } while ((ret = virDirRead(dir, &entry, configDir)) > 0) { - char *path; virNWFilterObjPtr nwfilter; if (entry->d_name[0] == '.') continue; - if (!virFileHasSuffix(entry->d_name, ".xml")) - continue; - - if (!(path = virFileBuildPath(configDir, entry->d_name, NULL))) + if (!virFileStripSuffix(entry->d_name, ".xml")) continue; - nwfilter = virNWFilterObjLoad(nwfilters, entry->d_name, path); + nwfilter = virNWFilterLoadConfig(nwfilters, configDir, entry->d_name); if (nwfilter) virNWFilterObjUnlock(nwfilter); - - VIR_FREE(path); } closedir(dir);