From nobody Mon Feb 9 04:15:08 2026 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 1528729237468341.42216690591636; Mon, 11 Jun 2018 08:00:37 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D8CC8356F0; Mon, 11 Jun 2018 15:00:34 +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 6C216308332B; Mon, 11 Jun 2018 15:00:34 +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 D2ED4180121D; Mon, 11 Jun 2018 15:00:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w5BF09QV012248 for ; Mon, 11 Jun 2018 11:00:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB0442166BB6; Mon, 11 Jun 2018 15:00:09 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B6B62166BB3 for ; Mon, 11 Jun 2018 15:00:09 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 11 Jun 2018 16:59:52 +0200 Message-Id: <99e304650fb30a01c0c0eefc0f1f0b2573c01a19.1528729138.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/3] conf: Use virXMLFormatElement to format disk IO tuning 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.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 11 Jun 2018 15:00:36 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extract and refactor the code to use the new approach which allows to delete a monster condition to check if the element needs to be formatted. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/conf/domain_conf.c | 116 +++++++++++++++++++++++----------------------= ---- 1 file changed, 54 insertions(+), 62 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ab93bb7b45..20862bd3a7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23533,11 +23533,60 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, #define FORMAT_IOTUNE(val) \ - if (def->blkdeviotune.val) { \ - virBufferAsprintf(buf, "<" #val ">%llu\n", \ - def->blkdeviotune.val); \ + if (disk->blkdeviotune.val) { \ + virBufferAsprintf(&childBuf, "<" #val ">%llu\n", \ + disk->blkdeviotune.val); \ } +static int +virDomainDiskDefFormatIotune(virBufferPtr buf, + virDomainDiskDefPtr disk) +{ + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + virBufferSetChildIndent(&childBuf, buf); + + FORMAT_IOTUNE(total_bytes_sec); + FORMAT_IOTUNE(read_bytes_sec); + FORMAT_IOTUNE(write_bytes_sec); + FORMAT_IOTUNE(total_iops_sec); + FORMAT_IOTUNE(read_iops_sec); + FORMAT_IOTUNE(write_iops_sec); + + FORMAT_IOTUNE(total_bytes_sec_max); + FORMAT_IOTUNE(read_bytes_sec_max); + FORMAT_IOTUNE(write_bytes_sec_max); + FORMAT_IOTUNE(total_iops_sec_max); + FORMAT_IOTUNE(read_iops_sec_max); + FORMAT_IOTUNE(write_iops_sec_max); + + if (disk->blkdeviotune.size_iops_sec) { + virBufferAsprintf(&childBuf, "%llu\= n", + disk->blkdeviotune.size_iops_sec); + } + + if (disk->blkdeviotune.group_name) { + virBufferEscapeString(&childBuf, "%s\n", + disk->blkdeviotune.group_name); + } + + FORMAT_IOTUNE(total_bytes_sec_max_length); + FORMAT_IOTUNE(read_bytes_sec_max_length); + FORMAT_IOTUNE(write_bytes_sec_max_length); + FORMAT_IOTUNE(total_iops_sec_max_length); + FORMAT_IOTUNE(read_iops_sec_max_length); + FORMAT_IOTUNE(write_iops_sec_max_length); + + ret =3D virXMLFormatElement(buf, "iotune", NULL, &childBuf); + + virBufferFreeAndReset(&childBuf); + return ret; +} + +#undef FORMAT_IOTUNE + + static int virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, @@ -23717,64 +23766,8 @@ virDomainDiskDefFormat(virBufferPtr buf, } virBufferAddLit(buf, "/>\n"); - /*disk I/O throttling*/ - if (def->blkdeviotune.total_bytes_sec || - def->blkdeviotune.read_bytes_sec || - def->blkdeviotune.write_bytes_sec || - def->blkdeviotune.total_iops_sec || - def->blkdeviotune.read_iops_sec || - def->blkdeviotune.write_iops_sec || - def->blkdeviotune.total_bytes_sec_max || - def->blkdeviotune.read_bytes_sec_max || - def->blkdeviotune.write_bytes_sec_max || - def->blkdeviotune.total_iops_sec_max || - def->blkdeviotune.read_iops_sec_max || - def->blkdeviotune.write_iops_sec_max || - def->blkdeviotune.size_iops_sec || - def->blkdeviotune.group_name || - def->blkdeviotune.total_bytes_sec_max_length || - def->blkdeviotune.read_bytes_sec_max_length || - def->blkdeviotune.write_bytes_sec_max_length || - def->blkdeviotune.total_iops_sec_max_length || - def->blkdeviotune.read_iops_sec_max_length || - def->blkdeviotune.write_iops_sec_max_length) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); - - FORMAT_IOTUNE(total_bytes_sec); - FORMAT_IOTUNE(read_bytes_sec); - FORMAT_IOTUNE(write_bytes_sec); - FORMAT_IOTUNE(total_iops_sec); - FORMAT_IOTUNE(read_iops_sec); - FORMAT_IOTUNE(write_iops_sec); - - FORMAT_IOTUNE(total_bytes_sec_max); - FORMAT_IOTUNE(read_bytes_sec_max); - FORMAT_IOTUNE(write_bytes_sec_max); - FORMAT_IOTUNE(total_iops_sec_max); - FORMAT_IOTUNE(read_iops_sec_max); - FORMAT_IOTUNE(write_iops_sec_max); - - if (def->blkdeviotune.size_iops_sec) { - virBufferAsprintf(buf, "%llu\n", - def->blkdeviotune.size_iops_sec); - } - - if (def->blkdeviotune.group_name) { - virBufferEscapeString(buf, "%s\n", - def->blkdeviotune.group_name); - } - - FORMAT_IOTUNE(total_bytes_sec_max_length); - FORMAT_IOTUNE(read_bytes_sec_max_length); - FORMAT_IOTUNE(write_bytes_sec_max_length); - FORMAT_IOTUNE(total_iops_sec_max_length); - FORMAT_IOTUNE(read_iops_sec_max_length); - FORMAT_IOTUNE(write_iops_sec_max_length); - - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } + if (virDomainDiskDefFormatIotune(buf, def) < 0) + return -1; if (def->src->readonly) virBufferAddLit(buf, "\n"); @@ -23799,7 +23792,6 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, "\n"); return 0; } -#undef FORMAT_IOTUNE static void --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list