From nobody Thu May 15 00:14:13 2025 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 1519927265308532.9338750804894; Thu, 1 Mar 2018 10:01:05 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45A145AFD9; Thu, 1 Mar 2018 18:01:03 +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 0C0A95F70A; Thu, 1 Mar 2018 18:01:03 +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 C3FC141F72; Thu, 1 Mar 2018 18:01:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w21I0XPc017003 for ; Thu, 1 Mar 2018 13:00:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id DE0FD2026609; Thu, 1 Mar 2018 18:00:32 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 690CE2026E04; Thu, 1 Mar 2018 18:00:32 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 1 Mar 2018 18:59:46 +0100 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH 5/6] qemu: domain: Use virXMLFormatElement in qemuDomainObjPrivateXMLFormatJob 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: , MIME-Version: 1.0 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 01 Mar 2018 18:01:03 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Modernize the code by using the clever formatter rather than checking manually when to format the end of the element. Signed-off-by: Peter Krempa --- src/qemu/qemu_domain.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index b7fb9f264d..e4088665ee 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2035,11 +2035,13 @@ qemuDomainObjPrivateXMLFormatAllowReboot(virBufferP= tr buf, } -static void +static int qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, virDomainObjPtr vm, qemuDomainObjPrivatePtr priv) { + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; qemuDomainJob job =3D priv->job.active; if (!qemuDomainTrackJob(job)) @@ -2047,37 +2049,34 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, if (job =3D=3D QEMU_JOB_NONE && priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_NONE) - return; + return 0; + + virBufferSetChildIndent(&childBuf, buf); - virBufferAsprintf(buf, "job.asyncJob)); + if (priv->job.phase) { - virBufferAsprintf(buf, " phase=3D'%s'", + virBufferAsprintf(&attrBuf, " phase=3D'%s'", qemuDomainAsyncJobPhaseToString(priv->job.asyncJ= ob, priv->job.phase)= ); } - if (priv->job.asyncJob !=3D QEMU_ASYNC_JOB_MIGRATION_OUT) { - virBufferAddLit(buf, "/>\n"); - } else { + + if (priv->job.asyncJob =3D=3D QEMU_ASYNC_JOB_MIGRATION_OUT) { size_t i; virDomainDiskDefPtr disk; qemuDomainDiskPrivatePtr diskPriv; - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - for (i =3D 0; i < vm->def->ndisks; i++) { disk =3D vm->def->disks[i]; diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - virBufferAsprintf(buf, "\n", - disk->dst, - diskPriv->migrating ? "yes" : "no"); + virBufferAsprintf(&childBuf, "\n", + disk->dst, diskPriv->migrating ? "yes" : "no= "); } - - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); } + + return virXMLFormatElement(buf, "job", &attrBuf, &childBuf); } @@ -2137,7 +2136,8 @@ qemuDomainObjPrivateXMLFormat(virBufferPtr buf, if (priv->lockState) virBufferAsprintf(buf, "%s\n", priv->lockSt= ate); - qemuDomainObjPrivateXMLFormatJob(buf, vm, priv); + if (qemuDomainObjPrivateXMLFormatJob(buf, vm, priv) < 0) + return -1; if (priv->fakeReboot) virBufferAddLit(buf, "\n"); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list