From nobody Sun Feb 8 21:11:41 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=1623333845; cv=none; d=zohomail.com; s=zohoarc; b=jvU+wNzETodqmQMZS+QUukfUW1EqkwGmu5P1g0XEnBLgV0Y6LwDJCjLIE9IPyLwCV0tWdU0SFcGR2Jeh7N+acolfZPz7MTG3114TsnAafJGOFheTOgPl2CkDmTT+SnPdfiFpCW38D0eYL/BXozxWBOAaQss4Fk3AxtbduVuJvyg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1623333845; 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=qI756UGXYvagIcEWQNJGPs5pk1NaCiRoZb5yOXHFrtE=; b=EFZbkVaWMQQGGSPSG/STkrHybEG65lZwufq14yjOUZtr9IijDtNiZ9CELMpZSMswonOU9cUT3VUOpz9cyIDe4jVRTcRkC1vZmO7KCl5tHIYET86ImK7ARwA5g3u8MmOVOyOA7UbLJ40nm2vRy7/H3nPOTrGN+y4fw0Rcj/JRP6M= 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) 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 1623333845845855.2720829632158; Thu, 10 Jun 2021 07:04:05 -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-236-MPtUdg7zNo6I1pOTP1j2kg-1; Thu, 10 Jun 2021 10:04:00 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2BCBC1084F5A; Thu, 10 Jun 2021 14:03:55 +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 095C319813; Thu, 10 Jun 2021 14:03:55 +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 B97931800BB8; Thu, 10 Jun 2021 14:03:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15ADvRlh005304 for ; Thu, 10 Jun 2021 09:57:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id C9BD819D7C; Thu, 10 Jun 2021 13:57:27 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C26819C45 for ; Thu, 10 Jun 2021 13:57:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1623333842; 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=qI756UGXYvagIcEWQNJGPs5pk1NaCiRoZb5yOXHFrtE=; b=XtiRnp/d8Db6u75zSK3o9/KnRtqbEuGhsvmMKX+KAB9MIWFlbqYIB5PWVNPmWKpvAhVSFj q3rQD8uCq/3Ifb6X8uASEsxPFh4tu4keMflaM3KkrJFYvRpO3etI0qhZujyNW6HwkBPmGt l3U4MuOvVYyesdetVBBoyqIK4oTssEg= X-MC-Unique: MPtUdg7zNo6I1pOTP1j2kg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 03/10] capabilities: Separate formatting into a function Date: Thu, 10 Jun 2021 15:57:12 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.11 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" The way we format element for capabilities is not ideal, because if there are no CPUs, i.e. no child elements, we still output opening and closing element. To solve this, virXMLFormatElement() could be used but that would introduce more variables into the loop. Therefore, move the formatter into a separate function and use virXMLFormatElement(). Signed-off-by: Michal Privoznik Reviewed-by: Martin Kletzander --- src/conf/capabilities.c | 58 ++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 21 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 2f9a1e7d1f..9332daf6a6 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -802,6 +802,41 @@ virCapabilitiesAddStoragePool(virCaps *caps, } =20 =20 +static int +virCapsHostNUMACellCPUFormat(virBuffer *buf, + const virCapsHostNUMACellCPU *cpus, + int ncpus) +{ + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + size_t j; + + virBufferAsprintf(&attrBuf, " num=3D'%d'", ncpus); + + for (j =3D 0; j < ncpus; j++) { + virBufferAsprintf(&childBuf, "\n"); + } + + virXMLFormatElement(buf, "cpus", &attrBuf, &childBuf); + return 0; +} + + static int virCapabilitiesHostNUMAFormat(virBuffer *buf, virCapsHostNUMA *caps) @@ -835,28 +870,9 @@ virCapabilitiesHostNUMAFormat(virBuffer *buf, =20 virNumaDistanceFormat(buf, cell->distances, cell->ndistances); =20 - virBufferAsprintf(buf, "\n", cell->ncpus); - virBufferAdjustIndent(buf, 2); - for (j =3D 0; j < cell->ncpus; j++) { - virBufferAsprintf(buf, "cpus[j].id); + if (virCapsHostNUMACellCPUFormat(buf, cell->cpus, cell->ncpus) < 0) + return -1; =20 - if (cell->cpus[j].siblings) { - g_autofree char *siblings =3D NULL; - - if (!(siblings =3D virBitmapFormat(cell->cpus[j].siblings)= )) - return -1; - - virBufferAsprintf(buf, - " socket_id=3D'%d' die_id=3D'%d' core_id= =3D'%d' siblings=3D'%s'", - cell->cpus[j].socket_id, - cell->cpus[j].die_id, - cell->cpus[j].core_id, - siblings); - } - virBufferAddLit(buf, "/>\n"); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } --=20 2.31.1