From nobody Thu Apr 18 23:27:04 2024 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 From nobody Thu Apr 18 23:27:04 2024 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 1528729221618497.7611436305708; Mon, 11 Jun 2018 08:00:21 -0700 (PDT) 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 8F93E3078AB4; Mon, 11 Jun 2018 15:00:16 +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 307518C7DF; Mon, 11 Jun 2018 15:00:16 +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 846454CA84; Mon, 11 Jun 2018 15:00:14 +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 w5BF0A6W012254 for ; Mon, 11 Jun 2018 11:00:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 80D4B2166BB3; Mon, 11 Jun 2018 15:00:10 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id 228EE2166BDB for ; Mon, 11 Jun 2018 15:00:10 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 11 Jun 2018 16:59:53 +0200 Message-Id: <1d1600f1caa4e521850649fbe5e85ac280930ab1.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 2/3] conf: Use virXMLFormatElement to format disk 'driver' element 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.48]); Mon, 11 Jun 2018 15:00:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Formatting of 'driver' already used a separate buffer but was part of the main function. Separate it and remove bunch of unnecessary temporary variables. Note that some checks are removed but they are not really necessary anyways. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/conf/domain_conf.c | 121 ++++++++++++++++++++++++++-------------------= ---- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 20862bd3a7..6461dfb936 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23587,6 +23587,70 @@ virDomainDiskDefFormatIotune(virBufferPtr buf, #undef FORMAT_IOTUNE +static int +virDomainDiskDefFormatDriver(virBufferPtr buf, + virDomainDiskDefPtr disk) +{ + virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + virBufferEscapeString(&driverBuf, " name=3D'%s'", virDomainDiskGetDriv= er(disk)); + + if (disk->src->format > 0) + virBufferAsprintf(&driverBuf, " type=3D'%s'", + virStorageFileFormatTypeToString(disk->src->form= at)); + + if (disk->cachemode) + virBufferAsprintf(&driverBuf, " cache=3D'%s'", + virDomainDiskCacheTypeToString(disk->cachemode)); + + if (disk->error_policy) + virBufferAsprintf(&driverBuf, " error_policy=3D'%s'", + virDomainDiskErrorPolicyTypeToString(disk->error= _policy)); + + if (disk->rerror_policy) + virBufferAsprintf(&driverBuf, " rerror_policy=3D'%s'", + virDomainDiskErrorPolicyTypeToString(disk->rerro= r_policy)); + + if (disk->iomode) + virBufferAsprintf(&driverBuf, " io=3D'%s'", + virDomainDiskIoTypeToString(disk->iomode)); + + if (disk->ioeventfd) + virBufferAsprintf(&driverBuf, " ioeventfd=3D'%s'", + virTristateSwitchTypeToString(disk->ioeventfd)); + + if (disk->event_idx) + virBufferAsprintf(&driverBuf, " event_idx=3D'%s'", + virTristateSwitchTypeToString(disk->event_idx)); + + if (disk->copy_on_read) + virBufferAsprintf(&driverBuf, " copy_on_read=3D'%s'", + virTristateSwitchTypeToString(disk->copy_on_read= )); + + if (disk->discard) + virBufferAsprintf(&driverBuf, " discard=3D'%s'", + virDomainDiskDiscardTypeToString(disk->discard)); + + if (disk->iothread) + virBufferAsprintf(&driverBuf, " iothread=3D'%u'", disk->iothread); + + if (disk->detect_zeroes) + virBufferAsprintf(&driverBuf, " detect_zeroes=3D'%s'", + virDomainDiskDetectZeroesTypeToString(disk->dete= ct_zeroes)); + + if (disk->queues) + virBufferAsprintf(&driverBuf, " queues=3D'%u'", disk->queues); + + virDomainVirtioOptionsFormat(&driverBuf, disk->virtio); + + ret =3D virXMLFormatElement(buf, "driver", &driverBuf, NULL); + + virBufferFreeAndReset(&driverBuf); + return ret; +} + + static int virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, @@ -23596,17 +23660,7 @@ virDomainDiskDefFormat(virBufferPtr buf, const char *type =3D virStorageTypeToString(def->src->type); const char *device =3D virDomainDiskDeviceTypeToString(def->device); const char *bus =3D virDomainDiskBusTypeToString(def->bus); - const char *cachemode =3D virDomainDiskCacheTypeToString(def->cachemod= e); - const char *error_policy =3D virDomainDiskErrorPolicyTypeToString(def-= >error_policy); - const char *rerror_policy =3D virDomainDiskErrorPolicyTypeToString(def= ->rerror_policy); - const char *iomode =3D virDomainDiskIoTypeToString(def->iomode); - const char *ioeventfd =3D virTristateSwitchTypeToString(def->ioeventfd= ); - const char *event_idx =3D virTristateSwitchTypeToString(def->event_idx= ); - const char *copy_on_read =3D virTristateSwitchTypeToString(def->copy_o= n_read); const char *sgio =3D virDomainDeviceSGIOTypeToString(def->sgio); - const char *discard =3D virDomainDiskDiscardTypeToString(def->discard); - const char *detect_zeroes =3D virDomainDiskDetectZeroesTypeToString(de= f->detect_zeroes); - virBuffer driverBuf =3D VIR_BUFFER_INITIALIZER; if (!type || !def->src->type) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -23623,16 +23677,6 @@ virDomainDiskDefFormat(virBufferPtr buf, _("unexpected disk bus %d"), def->bus); return -1; } - if (!cachemode) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected disk cache mode %d"), def->cachemode); - return -1; - } - if (!iomode) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected disk io mode %d"), def->iomode); - return -1; - } if (!sgio) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unexpected disk sgio mode '%d'"), def->sgio); @@ -23658,44 +23702,9 @@ virDomainDiskDefFormat(virBufferPtr buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); - virBufferEscapeString(&driverBuf, " name=3D'%s'", virDomainDiskGetDriv= er(def)); - if (def->src->format > 0) - virBufferAsprintf(&driverBuf, " type=3D'%s'", - virStorageFileFormatTypeToString(def->src->forma= t)); - if (def->cachemode) - virBufferAsprintf(&driverBuf, " cache=3D'%s'", cachemode); - if (def->error_policy) - virBufferAsprintf(&driverBuf, " error_policy=3D'%s'", error_policy= ); - if (def->rerror_policy) - virBufferAsprintf(&driverBuf, " rerror_policy=3D'%s'", rerror_poli= cy); - if (def->iomode) - virBufferAsprintf(&driverBuf, " io=3D'%s'", iomode); - if (def->ioeventfd) - virBufferAsprintf(&driverBuf, " ioeventfd=3D'%s'", ioeventfd); - if (def->event_idx) - virBufferAsprintf(&driverBuf, " event_idx=3D'%s'", event_idx); - if (def->copy_on_read) - virBufferAsprintf(&driverBuf, " copy_on_read=3D'%s'", copy_on_read= ); - if (def->discard) - virBufferAsprintf(&driverBuf, " discard=3D'%s'", discard); - if (def->iothread) - virBufferAsprintf(&driverBuf, " iothread=3D'%u'", def->iothread); - if (def->detect_zeroes) - virBufferAsprintf(&driverBuf, " detect_zeroes=3D'%s'", detect_zero= es); - if (def->queues) - virBufferAsprintf(&driverBuf, " queues=3D'%u'", def->queues); - - virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - - if (virBufferCheckError(&driverBuf) < 0) + if (virDomainDiskDefFormatDriver(buf, def) < 0) return -1; - if (virBufferUse(&driverBuf)) { - virBufferAddLit(buf, "\n"); - } - /* Format as child of if defined there; otherwise, * if defined as child of , then format later */ if (def->src->auth && !def->src->authInherited) --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 18 23:27:04 2024 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 1528729239708452.4250103306317; Mon, 11 Jun 2018 08:00:39 -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 AC16A5F7BF; Mon, 11 Jun 2018 15:00:35 +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 522543083328; Mon, 11 Jun 2018 15:00:35 +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 C0E4D180BA80; Mon, 11 Jun 2018 15:00:34 +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 w5BF0Bn7012262 for ; Mon, 11 Jun 2018 11:00:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2740A2166BB3; Mon, 11 Jun 2018 15:00:11 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD3852166BB6 for ; Mon, 11 Jun 2018 15:00:10 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Mon, 11 Jun 2018 16:59:54 +0200 Message-Id: <662ed7fbac268e638bcf3d4cce7139e4f5c76690.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 3/3] conf: Extract formatting of 'mirror' disk sub-element 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.39]); Mon, 11 Jun 2018 15:00:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the code to a separate function. Signed-off-by: Peter Krempa Reviewed-by: J=EF=BF=BDn Tomko --- src/conf/domain_conf.c | 84 ++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6461dfb936..30078bb14b 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23651,6 +23651,54 @@ virDomainDiskDefFormatDriver(virBufferPtr buf, } +static int +virDomainDiskDefFormatMirror(virBufferPtr buf, + virDomainDiskDefPtr disk, + unsigned int flags, + virDomainXMLOptionPtr xmlopt) +{ + const char *formatStr =3D NULL; + + /* For now, mirroring is currently output-only: we only output it + * for live domains, therefore we ignore it on input except for + * the internal parse on libvirtd restart. We prefer to output + * the new style similar to backingStore, but for back-compat on + * blockcopy files we also have to output old style attributes. + * The parser accepts either style across libvirtd upgrades. */ + + if (!disk->mirror || + (flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) + return 0; + + if (disk->mirror->format) + formatStr =3D virStorageFileFormatTypeToString(disk->mirror->forma= t); + virBufferAsprintf(buf, "mirror->type)); + if (disk->mirror->type =3D=3D VIR_STORAGE_TYPE_FILE && + disk->mirrorJob =3D=3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) { + virBufferEscapeString(buf, " file=3D'%s'", disk->mirror->path); + virBufferEscapeString(buf, " format=3D'%s'", formatStr); + } + virBufferEscapeString(buf, " job=3D'%s'", + virDomainBlockJobTypeToString(disk->mirrorJob)); + if (disk->mirrorState) { + const char *mirror; + + mirror =3D virDomainDiskMirrorStateTypeToString(disk->mirrorState); + virBufferEscapeString(buf, " ready=3D'%s'", mirror); + } + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "\n", formatStr); + if (virDomainDiskSourceFormat(buf, disk->mirror, 0, 0, xmlopt) < 0) + return -1; + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + + static int virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskDefPtr def, @@ -23726,40 +23774,8 @@ virDomainDiskDefFormat(virBufferPtr buf, virDomainDiskGeometryDefFormat(buf, def); virDomainDiskBlockIoDefFormat(buf, def); - /* For now, mirroring is currently output-only: we only output it - * for live domains, therefore we ignore it on input except for - * the internal parse on libvirtd restart. We prefer to output - * the new style similar to backingStore, but for back-compat on - * blockcopy files we also have to output old style attributes. - * The parser accepts either style across libvirtd upgrades. */ - if (def->mirror && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) { - const char *formatStr =3D NULL; - - if (def->mirror->format) - formatStr =3D virStorageFileFormatTypeToString(def->mirror->fo= rmat); - virBufferAsprintf(buf, "mirror->type)); - if (def->mirror->type =3D=3D VIR_STORAGE_TYPE_FILE && - def->mirrorJob =3D=3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY) { - virBufferEscapeString(buf, " file=3D'%s'", def->mirror->path); - virBufferEscapeString(buf, " format=3D'%s'", formatStr); - } - virBufferEscapeString(buf, " job=3D'%s'", - virDomainBlockJobTypeToString(def->mirrorJob= )); - if (def->mirrorState) { - const char *mirror; - - mirror =3D virDomainDiskMirrorStateTypeToString(def->mirrorSta= te); - virBufferEscapeString(buf, " ready=3D'%s'", mirror); - } - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, "\n", formatStr); - if (virDomainDiskSourceFormat(buf, def->mirror, 0, 0, xmlopt) < 0) - return -1; - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - } + if (virDomainDiskDefFormatMirror(buf, def, flags, xmlopt) < 0) + return -1; virBufferAsprintf(buf, "dst, bus); --=20 2.16.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list