From nobody Sat Apr 27 07:27:55 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1622720067; cv=none; d=zohomail.com; s=zohoarc; b=PD5HcoP7xRkuX0vBa5CL8/zSAzz0S5uCm67dCjtEaMDmTg9HNOy3BspNWfkLN+u8Xdajp15QdDny+UAZ4EvKvUyLPkfbm1RNTD5mWn4VR4Yv5nRvZbRBiVW+lueUiUUTPCoJo/A41xSgra/RnwoST0OxdNw+ynQ4z2doeIMY1UQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622720067; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=SsarVD0vU/jjP2opAPzZI8TZr/DEcko23riJqTxIvHU=; b=Z2ayps8nnhlXjuO7SFP4ijME5ZQwcfIs89v2Q2L7zvPmT2nVRZMvzebMm8zI2YVyoSo6Uo/NHYSwh8locd9ZHItzl4lnAKw/Fv0T+AaWtQXDFMHAAi/BBSxfMpACkZxmKI53rHd6ExxgkzdI7TVs6i/XFBswXccde2FEAUlOsWQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1622720067816908.4138152853072; Thu, 3 Jun 2021 04:34:27 -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-273-Qj0stJ8hMgCpzKUJMINhfg-1; Thu, 03 Jun 2021 07:34:24 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C6BB4801107; Thu, 3 Jun 2021 11:34:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 53747101E249; Thu, 3 Jun 2021 11:34:18 +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 C5F96383D; Thu, 3 Jun 2021 11:34:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 153BYEpd015588 for ; Thu, 3 Jun 2021 07:34:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id B009119C97; Thu, 3 Jun 2021 11:34:14 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.157]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34822620DE for ; Thu, 3 Jun 2021 11:34:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622720066; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=SsarVD0vU/jjP2opAPzZI8TZr/DEcko23riJqTxIvHU=; b=CSctmvtVyontR+a+ckU0VrvxIHgR2Xlp96IOTybQ+wUnwidVrEvdArJ4c+8qr4iHgX4XFa q2dQwO6QlDG5dfQI3Ag+6NtTctLiXNiE8PJap/B4zRiVsx3HiQfN5iG2B2iu4f1tU167lj hP1W+OuMBX6jp/ERQgKu+hWfwixQCoE= X-MC-Unique: Qj0stJ8hMgCpzKUJMINhfg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] domain_conf: Use virXMLFormatElement() more Date: Thu, 3 Jun 2021 13:34:06 +0200 Message-Id: <19ae221f07e31b7147b52ec5aaab9dd860405a22.1622720013.git.mprivozn@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.84 on 10.5.11.22 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" I've identified some places (mostly by looking for virBufferUse()) that can use virXMLFormatElement() instead of open coded version of it. I'm sure there are many more places that could use the same treatment. Let's cure them some other time. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- Based on Dan's series he posted earlier today: https://listman.redhat.com/archives/libvir-list/2021-June/msg00060.html src/conf/domain_conf.c | 74 +++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 7b9de2e92d..139cdfc0a7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25177,6 +25177,7 @@ virDomainSmartcardDefFormat(virBuffer *buf, { const char *mode =3D virDomainSmartcardTypeToString(def->type); g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; size_t i; =20 if (!mode) { @@ -25209,19 +25210,13 @@ virDomainSmartcardDefFormat(virBuffer *buf, } virDomainDeviceInfoFormat(&childBuf, &def->info, flags); =20 - virBufferAsprintf(buf, "type =3D=3D VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH && - virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0) { + virDomainChrAttrsDefFormat(&attrBuf, def->data.passthru, false) < = 0) { return -1; } =20 - if (virBufferUse(&childBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } + virXMLFormatElement(buf, "smartcard", &attrBuf, &childBuf); =20 return 0; } @@ -25300,6 +25295,7 @@ virDomainSoundDefFormat(virBuffer *buf, { const char *model =3D virDomainSoundModelTypeToString(def->model); g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; size_t i; =20 if (!model) { @@ -25316,14 +25312,9 @@ virDomainSoundDefFormat(virBuffer *buf, =20 virDomainDeviceInfoFormat(&childBuf, &def->info, flags); =20 - virBufferAsprintf(buf, "\n"); - virBufferAddBuffer(buf, &childBuf); - virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } + virBufferAsprintf(&attrBuf, " model=3D'%s'", model); + + virXMLFormatElement(buf, "sound", &attrBuf, &childBuf); =20 return 0; } @@ -25453,6 +25444,7 @@ virDomainAudioDefFormat(virBuffer *buf, virDomainAudioDef *def) { g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) inputBuf =3D VIR_BUFFER_INITIALIZER; g_auto(virBuffer) outputBuf =3D VIR_BUFFER_INITIALIZER; const char *type =3D virDomainAudioTypeTypeToString(def->type); @@ -25463,10 +25455,10 @@ virDomainAudioDefFormat(virBuffer *buf, return -1; } =20 - virBufferAsprintf(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); - } + virXMLFormatElement(buf, "audio", &attrBuf, &childBuf); =20 return 0; } @@ -27002,6 +26988,7 @@ virDomainCachetuneDefFormat(virBuffer *buf, unsigned int flags) { g_auto(virBuffer) childrenBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; size_t i =3D 0; g_autofree char *vcpus =3D NULL; =20 @@ -27024,19 +27011,17 @@ virDomainCachetuneDefFormat(virBuffer *buf, if (!vcpus) return -1; =20 - virBufferAsprintf(buf, "alloc); if (!alloc_id) return -1; =20 - virBufferAsprintf(buf, " id=3D'%s'", alloc_id); + virBufferAsprintf(&attrBuf, " id=3D'%s'", alloc_id); } - virBufferAddLit(buf, ">\n"); =20 - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "cachetune", &attrBuf, &childrenBuf); =20 return 0; } @@ -27062,6 +27047,7 @@ virDomainMemorytuneDefFormat(virBuffer *buf, unsigned int flags) { g_auto(virBuffer) childrenBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; g_autofree char *vcpus =3D NULL; size_t i =3D 0; =20 @@ -27084,19 +27070,17 @@ virDomainMemorytuneDefFormat(virBuffer *buf, if (!vcpus) return -1; =20 - virBufferAsprintf(buf, "alloc); if (!alloc_id) return -1; =20 - virBufferAsprintf(buf, " id=3D'%s'", alloc_id); + virBufferAsprintf(&attrBuf, " id=3D'%s'", alloc_id); } - virBufferAddLit(buf, ">\n"); =20 - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "memorytune", &attrBuf, &childrenBuf); =20 return 0; } @@ -27213,11 +27197,7 @@ virDomainCputuneDefFormat(virBuffer *buf, for (i =3D 0; i < def->nresctrls; i++) virDomainMemorytuneDefFormat(&childrenBuf, def->resctrls[i], flags= ); =20 - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, "\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "\n"); - } + virXMLFormatElement(buf, "cputune", NULL, &childrenBuf); =20 return 0; } --=20 2.31.1