From nobody Mon Feb 9 03:17:30 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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=1573543746; cv=none; d=zoho.com; s=zohoarc; b=jHWut0FYp37BAl2BEIUjKQphUAkcl8LogsOfJLore458k9Ykwl4L0D6BMXZ0j+uqWPf5d59blwlURVNrPIpgoYsHSL9j3udl64BYt7z0TXd/FRQvQ/HPWKw1C2Fsjr8Ib9gS6xjhC6FaAHwag6Od736nUYl/WTG2LqhalGWg3Gc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1573543746; 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=ceJHf6tqnFhHPHwGFtKJKYNN5J17AJUu0UT7ZUU5m4s=; b=aQv6TPxHbtm6kwsOCvEE7ld6kOsIvbE9McLA+t7gxJqSAKZsYWxGEuKR3maQaExc5p0KRCRTOMOKkDVW7uNFKyhD02bQG/xqL9eppsYpOywPtem40wcqRof5aDthy3gYxTF3ifoDTmRDqFwPcaXH7nzTXjH+AJtsLGBgAP58lJs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1573543746098880.1932607312241; Mon, 11 Nov 2019 23:29:06 -0800 (PST) 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-151-cCsT453cMi-vc4Q0HMHcbQ-1; Tue, 12 Nov 2019 02:28:44 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E615ADB67; Tue, 12 Nov 2019 07:28:39 +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 BAC8C9F55; Tue, 12 Nov 2019 07:28:39 +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 7AF1E180880B; Tue, 12 Nov 2019 07:28:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id xAC7Rx1O011418 for ; Tue, 12 Nov 2019 02:27:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id A56AEBEA67; Tue, 12 Nov 2019 07:27:59 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 31338627DF for ; Tue, 12 Nov 2019 07:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1573543745; 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=ceJHf6tqnFhHPHwGFtKJKYNN5J17AJUu0UT7ZUU5m4s=; b=ct4HvN/IJqpPi3wrqM0Nu7qfRrE4eawdqnoqLWQfqrZs+A52zzozMX8Fqt1LVByo6kBYru wSYaPut081l52sg64bsmIwZmO6VSMC+2p30y85otMe4NUeqF91Nz4QsvgrnAmWl933x3Sh ZaAzEQ5hlQGzPzDz9ZRD14wMtTCQ2VM= From: Peter Krempa To: libvir-list@redhat.com Date: Tue, 12 Nov 2019 08:27:47 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 10/10] conf: capabilities: Modernize virCapabilitiesFormatMemoryBandwidth 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.12 X-MC-Unique: cCsT453cMi-vc4Q0HMHcbQ-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use virXMLFormatElement and the automatic memory handlers to simplfy the code. Signed-off-by: Peter Krempa Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/capabilities.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 1ab389bc65..f3b34b7040 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -1024,7 +1024,6 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, virCapsHostMemBWPtr memBW) { size_t i =3D 0; - virBuffer childrenBuf =3D VIR_BUFFER_INITIALIZER; if (!memBW->nnodes) return 0; @@ -1033,17 +1032,18 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr b= uf, virBufferAdjustIndent(buf, 2); for (i =3D 0; i < memBW->nnodes; i++) { + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf =3D VIR_BUFFER_INITIALIZER; virCapsHostMemBWNodePtr node =3D memBW->nodes[i]; virResctrlInfoMemBWPerNodePtr control =3D &node->control; - char *cpus_str =3D virBitmapFormat(node->cpus); + g_autofree char *cpus_str =3D virBitmapFormat(node->cpus); if (!cpus_str) return -1; - virBufferAsprintf(buf, - "id, cpus_str); - VIR_FREE(cpus_str); virBufferSetChildIndent(&childrenBuf, buf); virBufferAsprintf(&childrenBuf, @@ -1052,13 +1052,7 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr bu= f, control->granularity, control->min, control->max_allocation); - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } + virXMLFormatElement(buf, "node", &attrBuf, &childrenBuf); } if (virCapabilitiesFormatResctrlMonitor(buf, memBW->monitor) < 0) --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list