From nobody Sat Feb 7 15:11:55 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.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 1534421449673519.2599504232816; Thu, 16 Aug 2018 05:10:49 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2C003169B2D; Thu, 16 Aug 2018 12:10:46 +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 B41765B68C; Thu, 16 Aug 2018 12:10:46 +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 5C71518363F4; Thu, 16 Aug 2018 12:10:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7GCAbs1026256 for ; Thu, 16 Aug 2018 08:10:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 03AA62166BB1; Thu, 16 Aug 2018 12:10:37 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-135.ams2.redhat.com [10.36.117.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 300FE2166BA0; Thu, 16 Aug 2018 12:10:35 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 16 Aug 2018 13:10:24 +0100 Message-Id: <20180816121031.10902-2-berrange@redhat.com> In-Reply-To: <20180816121031.10902-1-berrange@redhat.com> References: <20180816121031.10902-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/8] cpu: allow include files for CPU definition 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: , Content-Type: text/plain; charset="utf-8" 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Thu, 16 Aug 2018 12:10:47 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Allow for syntax to reference other files in the CPU database directory Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Jiri Denemark --- src/cpu/cpu_map.c | 87 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 3 deletions(-) diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index d263eb8cdd..bcd3e55417 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -1,7 +1,7 @@ /* * cpu_map.c: internal functions for handling CPU mapping configuration * - * Copyright (C) 2009-2010 Red Hat, Inc. + * Copyright (C) 2009-2018 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -70,6 +70,84 @@ static int load(xmlXPathContextPtr ctxt, return ret; } =20 +static int +cpuMapLoadInclude(const char *filename, + cpuMapLoadCallback cb, + void *data) +{ + xmlDocPtr xml =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + int ret =3D -1; + int element; + char *mapfile; + + if (!(mapfile =3D virFileFindResource(filename, + abs_topsrcdir "/src/cpu", + PKGDATADIR))) + return -1; + + VIR_DEBUG("Loading CPU map include from %s", mapfile); + + if (!(xml =3D virXMLParseFileCtxt(mapfile, &ctxt))) + goto cleanup; + + ctxt->node =3D xmlDocGetRootElement(xml); + + for (element =3D 0; element < CPU_MAP_ELEMENT_LAST; element++) { + if (load(ctxt, element, cb, data) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot parse CPU map '%s'"), mapfile); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(mapfile); + + return ret; +} + + +static int +loadIncludes(xmlXPathContextPtr ctxt, + cpuMapLoadCallback callback, + void *data) +{ + int ret =3D -1; + xmlNodePtr ctxt_node; + xmlNodePtr *nodes =3D NULL; + int n; + size_t i; + + ctxt_node =3D ctxt->node; + + n =3D virXPathNodeSet("include", ctxt, &nodes); + if (n < 0) + goto cleanup; + + for (i =3D 0; i < n; i++) { + char *filename =3D virXMLPropString(nodes[i], "filename"); + VIR_DEBUG("Finding CPU map include '%s'", filename); + if (cpuMapLoadInclude(filename, callback, data) < 0) { + VIR_FREE(filename); + goto cleanup; + } + VIR_FREE(filename); + } + + ret =3D 0; + + cleanup: + ctxt->node =3D ctxt_node; + VIR_FREE(nodes); + + return ret; +} + =20 int cpuMapLoad(const char *arch, cpuMapLoadCallback cb, @@ -88,7 +166,7 @@ int cpuMapLoad(const char *arch, PKGDATADIR))) return -1; =20 - VIR_DEBUG("Loading CPU map from %s", mapfile); + VIR_DEBUG("Loading '%s' CPU map from %s", NULLSTR(arch), mapfile); =20 if (arch =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -122,11 +200,14 @@ int cpuMapLoad(const char *arch, for (element =3D 0; element < CPU_MAP_ELEMENT_LAST; element++) { if (load(ctxt, element, cb, data) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse CPU map for %s architecture"), = arch); + _("cannot parse CPU map '%s'"), mapfile); goto cleanup; } } =20 + if (loadIncludes(ctxt, cb, data) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list