From nobody Mon Feb 9 03:46:38 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 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