From nobody Tue Feb 10 00:38:43 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622450203; cv=none; d=zohomail.com; s=zohoarc; b=BR0q4xmNAZhqpjkYz7612pjsgwEYHNWYpmJ9GXqC238QPlByrXCpBXn999Qig/VTbm6ls73xexRgyZ8yHAvcKqUD769mj/Z7HaTsFF/64QaHBGTa4efzlE2vFrR1OijRZeJLfLUtEiUkovKVWtd3yZPi7wsJw+r8dGG8m+20JyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622450203; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TTKulBOrkT90JaunOH+kiK/u/Jg1WaP/5jZJCp15tho=; b=Xf4Pht3h+qDFXn7610AK4CZqvkrcepC1JOl5yPBgLx+N4Vaq7RVLQ9+DGHHIRnfmiB+ZOIwlUJdmNR3FYbhCSsTfCPKJKwrANGx2Tt+PQCcnEA/TVdqfghzPOyPXAnj4oBab5yfTTTmiCFpB4o4AjGLbi+Q7wCEWtpmpfUPxTtg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1622450203938148.43400038915172; Mon, 31 May 2021 01:36:43 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-556-miznUvg8O_SF9P7u37tC-Q-1; Mon, 31 May 2021 04:36:40 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 36E0A19253CC; Mon, 31 May 2021 08:36:36 +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 A66B65D766; Mon, 31 May 2021 08:36:35 +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 69A03180B464; Mon, 31 May 2021 08:36:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14V8aUZK007515 for ; Mon, 31 May 2021 04:36:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0046F6A04D; Mon, 31 May 2021 08:36:30 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.219]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67CCF687EE for ; Mon, 31 May 2021 08:36:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622450202; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TTKulBOrkT90JaunOH+kiK/u/Jg1WaP/5jZJCp15tho=; b=Mkt4Bm7XYvlV7UfNP3ehsg8AfBlBcwJ4Lpbwm16e3de6/Qu5h8Vhif858jl04UdRC/ODUh yLJEdV8vezXBZSExIqpabDkfDiysYd8TwVSfd3idqunR5ykvvKDWFT6KqtnE2SHWCOMJAf qGHpBhxr3yM/xk6Sf/IzRkcdVPFQtYg= X-MC-Unique: miznUvg8O_SF9P7u37tC-Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v1 08/10] numa_conf: Expose virNumaInterconnect formatter Date: Mon, 31 May 2021 10:36:09 +0200 Message-Id: <863f77e35e0adc5dd96c2b89c6e1fdb079384526.1622449288.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Expose virNumaInterconnect XML formatter so that it can be re-used by other parts of the code. Signed-off-by: Michal Privoznik --- src/conf/numa_conf.c | 101 +++++++++++++++++++-------------------- src/conf/numa_conf.h | 16 +++++++ src/libvirt_private.syms | 1 + 3 files changed, 66 insertions(+), 52 deletions(-) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index c8b3212e5c..9a9b5f4b60 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -82,8 +82,6 @@ VIR_ENUM_IMPL(virMemoryLatency, "write" ); =20 -typedef struct _virNumaInterconnect virNumaInterconnect; - typedef struct _virDomainNumaNode virDomainNumaNode; =20 struct _virDomainNuma { @@ -110,16 +108,7 @@ struct _virDomainNuma { } *mem_nodes; /* guest node configuration */ size_t nmem_nodes; =20 - struct _virNumaInterconnect { - virNumaInterconnectType type; /* whether structure describes late= ncy - or bandwidth */ - unsigned int initiator; /* the initiator NUMA node */ - unsigned int target; /* the target NUMA node */ - unsigned int cache; /* the target cache on @target; if 0 then = the - memory on @target */ - virMemoryLatency accessType; /* what type of access is defined */ - unsigned long value; /* value itself */ - } *interconnects; + virNumaInterconnect *interconnects; size_t ninterconnects; =20 /* Future NUMA tuning related stuff should go here. */ @@ -1129,46 +1118,7 @@ virDomainNumaDefFormatXML(virBuffer *buf, virXMLFormatElement(buf, "cell", &attrBuf, &childBuf); } =20 - if (def->ninterconnects) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - } - - for (i =3D 0; i < def->ninterconnects; i++) { - virNumaInterconnect *l =3D &def->interconnects[i]; - - switch (l->type) { - case VIR_NUMA_INTERCONNECT_TYPE_LATENCY: - virBufferAddLit(buf, "initiator, l->target); - - if (l->cache > 0) { - virBufferAsprintf(buf, - " cache=3D'%u'", - l->cache); - } - - virBufferAsprintf(buf, - " type=3D'%s' value=3D'%lu'", - virMemoryLatencyTypeToString(l->accessType), - l->value); - - if (l->type =3D=3D VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH) - virBufferAddLit(buf, " unit=3D'KiB'"); - virBufferAddLit(buf, "/>\n"); - } - - if (def->ninterconnects) { - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } + virNumaInterconnectFormat(buf, def->interconnects, def->ninterconnects= ); =20 virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); @@ -1842,3 +1792,50 @@ virNumaCacheFormat(virBuffer *buf, virXMLFormatElement(buf, "cache", &attrBuf, &childBuf); } } + + +void +virNumaInterconnectFormat(virBuffer *buf, + const virNumaInterconnect *interconnects, + size_t ninterconnects) +{ + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + size_t i; + + for (i =3D 0; i < ninterconnects; i++) { + const virNumaInterconnect *l =3D &interconnects[i]; + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + const char *elem =3D NULL; + + switch (l->type) { + case VIR_NUMA_INTERCONNECT_TYPE_LATENCY: + elem =3D "latency"; + break; + case VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH: + elem =3D "bandwidth"; + break; + } + + virBufferAsprintf(&attrBuf, + " initiator=3D'%u' target=3D'%u'", + l->initiator, l->target); + + if (l->cache > 0) { + virBufferAsprintf(&attrBuf, + " cache=3D'%u'", + l->cache); + } + + virBufferAsprintf(&attrBuf, + " type=3D'%s' value=3D'%lu'", + virMemoryLatencyTypeToString(l->accessType), + l->value); + + if (l->type =3D=3D VIR_NUMA_INTERCONNECT_TYPE_BANDWIDTH) + virBufferAddLit(&attrBuf, " unit=3D'KiB'"); + + virXMLFormatElement(&childBuf, elem, &attrBuf, NULL); + } + + virXMLFormatElement(buf, "interconnects", NULL, &childBuf); +} diff --git a/src/conf/numa_conf.h b/src/conf/numa_conf.h index 5baf68348c..1d1e816870 100644 --- a/src/conf/numa_conf.h +++ b/src/conf/numa_conf.h @@ -272,3 +272,19 @@ struct _virNumaCache { void virNumaCacheFormat(virBuffer *buf, const virNumaCache *caches, size_t ncaches); + +typedef struct _virNumaInterconnect virNumaInterconnect; +struct _virNumaInterconnect { + virNumaInterconnectType type; /* whether structure describes latency + or bandwidth */ + unsigned int initiator; /* the initiator NUMA node */ + unsigned int target; /* the target NUMA node */ + unsigned int cache; /* the target cache on @target; if 0 then the + memory on @target */ + virMemoryLatency accessType; /* what type of access is defined */ + unsigned long value; /* value itself */ +}; + +void virNumaInterconnectFormat(virBuffer *buf, + const virNumaInterconnect *interconnects, + size_t ninterconnects); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d7f6dfd534..8f0945f581 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -915,6 +915,7 @@ virNumaCacheFormat; virNumaCachePolicyTypeFromString; virNumaCachePolicyTypeToString; virNumaDistanceFormat; +virNumaInterconnectFormat; =20 =20 # conf/nwfilter_conf.h --=20 2.31.1