From nobody Wed May 14 06:43:21 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 1526051374786748.4687471859894; Fri, 11 May 2018 08:09:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.25]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 611E33003C6F; Fri, 11 May 2018 15:09:33 +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 EF0F32016200; Fri, 11 May 2018 15:09:32 +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 A51ED4CAA7; Fri, 11 May 2018 15:09:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w4BF9TuU008543 for ; Fri, 11 May 2018 11:09:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id E011C83B6C; Fri, 11 May 2018 15:09:29 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 678E4728F5; Fri, 11 May 2018 15:09:29 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Fri, 11 May 2018 17:09:16 +0200 Message-Id: <7dd96912564cfa041e55a18ee5e211d664c404ed.1526051215.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com Subject: [libvirt] [PATCH v5 5/7] conf: Move virDomainMemtune formatting into a separate function 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.84 on 10.5.11.25 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 11 May 2018 15:09:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" At the same time convert the code to use virXMLFormatElement. Signed-off-by: Michal Privoznik Reviewed-by: J=EF=BF=BDn Tomko --- src/conf/domain_conf.c | 114 +++++++++++++++++++++++++++------------------= ---- 1 file changed, 63 insertions(+), 51 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 5d9148c1b1..6786d81c9b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26555,6 +26555,67 @@ virDomainIOMMUDefFormat(virBufferPtr buf, } =20 =20 +static int +virDomainMemtuneFormat(virBufferPtr buf, + const virDomainMemtune *mem) +{ + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + virBufferSetChildIndent(&childBuf, buf); + + if (virMemoryLimitIsSet(mem->hard_limit)) { + virBufferAsprintf(&childBuf, + "%llu\n", + mem->hard_limit); + } + if (virMemoryLimitIsSet(mem->soft_limit)) { + virBufferAsprintf(&childBuf, + "%llu\n", + mem->soft_limit); + } + if (mem->min_guarantee) { + virBufferAsprintf(&childBuf, + "%llu\n", + mem->min_guarantee); + } + if (virMemoryLimitIsSet(mem->swap_hard_limit)) { + virBufferAsprintf(&childBuf, + "%llu\n", + mem->swap_hard_limit); + } + + if (virXMLFormatElement(buf, "memtune", NULL, &childBuf) < 0) + goto cleanup; + + virBufferSetChildIndent(&childBuf, buf); + + if (mem->nhugepages) + virDomainHugepagesFormat(&childBuf, mem->hugepages, mem->nhugepage= s); + if (mem->nosharepages) + virBufferAddLit(&childBuf, "\n"); + if (mem->locked) + virBufferAddLit(&childBuf, "\n"); + if (mem->source) + virBufferAsprintf(&childBuf, "\n", + virDomainMemorySourceTypeToString(mem->source)); + if (mem->access) + virBufferAsprintf(&childBuf, "\n", + virDomainMemoryAccessTypeToString(mem->access)); + if (mem->allocation) + virBufferAsprintf(&childBuf, "\n", + virDomainMemoryAllocationTypeToString(mem->alloc= ation)); + + if (virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&childBuf); + return ret; +} + + /* This internal version appends to an existing buffer * (possibly with auto-indent), rather than flattening * to string. @@ -26693,57 +26754,8 @@ virDomainDefFormatInternal(virDomainDefPtr def, } virBufferFreeAndReset(&childrenBuf); =20 - /* add memtune only if there are any */ - if (virMemoryLimitIsSet(def->mem.hard_limit) || - virMemoryLimitIsSet(def->mem.soft_limit) || - virMemoryLimitIsSet(def->mem.swap_hard_limit) || - def->mem.min_guarantee) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - if (virMemoryLimitIsSet(def->mem.hard_limit)) { - virBufferAsprintf(buf, "" - "%llu\n", def->mem.hard_limit); - } - if (virMemoryLimitIsSet(def->mem.soft_limit)) { - virBufferAsprintf(buf, "" - "%llu\n", def->mem.soft_limit); - } - if (def->mem.min_guarantee) { - virBufferAsprintf(buf, "" - "%llu\n", def->mem.min_guara= ntee); - } - if (virMemoryLimitIsSet(def->mem.swap_hard_limit)) { - virBufferAsprintf(buf, "" - "%llu\n", def->mem.swap_ha= rd_limit); - } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } - - if (def->mem.nhugepages || def->mem.nosharepages || def->mem.locked - || def->mem.source || def->mem.access || def->mem.allocation) - { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - if (def->mem.nhugepages) - virDomainHugepagesFormat(buf, def->mem.hugepages, def->mem.nhu= gepages); - if (def->mem.nosharepages) - virBufferAddLit(buf, "\n"); - if (def->mem.locked) - virBufferAddLit(buf, "\n"); - if (def->mem.source) - virBufferAsprintf(buf, "\n", - virDomainMemorySourceTypeToString(def->mem.source)); - if (def->mem.access) - virBufferAsprintf(buf, "\n", - virDomainMemoryAccessTypeToString(def->mem.access)); - if (def->mem.allocation) - virBufferAsprintf(buf, "\n", - virDomainMemoryAllocationTypeToString(def->mem.allocation)= ); - - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } + if (virDomainMemtuneFormat(buf, &def->mem) < 0) + goto error; =20 if (virDomainCpuDefFormat(buf, def) < 0) goto error; --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list