From nobody Mon Feb 9 07:55:57 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594749651; cv=none; d=zohomail.com; s=zohoarc; b=AeuTMJWKPPFDWGfAb83xgXL2Suv1Y/Ny7aJSNtmFrK/MtBwVmHe1Red1tlE+H0o3DYd5WflaR7SIPU6bOz0YpyEhMcSozbTdtQ3faZCfYuECiHZHb7P3CW6UfYXN3ht2OcPBFXMWubkcopXr3XNGVKHrb7jfIhqJmGoNzhTNabA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594749651; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=QBOf/oVgXEzDyQAmS1gh80sM0Fz4v9Ua6LY8QWETm1M=; b=OQr7UGWoPl78hokG4SBFDodnVsXIx3hoidCL2e06dvYN1/gmH9QVNhQ5R8kCUvq6QB7A72EmUlConWEFW4nBJJZIAtvy+PeHsB1GnU4gGpzvVGHhr6uAdMztExQfIePjkrbLYHpowu2Y1EKyD9LcrO1J/+sgtMDlQkY6efYcUSU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594749651599718.2986014423129; Tue, 14 Jul 2020 11:00:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-479-qjiWXr8WMBCyLWfOk1tkYA-1; Tue, 14 Jul 2020 14:00:48 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6BA98E2EA3; Tue, 14 Jul 2020 18:00:22 +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 30036102470F; Tue, 14 Jul 2020 18:00:22 +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 EAC53180954D; Tue, 14 Jul 2020 18:00:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 06EI0Kgw023929 for ; Tue, 14 Jul 2020 14:00:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E7FD61B9D; Tue, 14 Jul 2020 18:00:20 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id E5D6F69509 for ; Tue, 14 Jul 2020 18:00:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594749650; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=QBOf/oVgXEzDyQAmS1gh80sM0Fz4v9Ua6LY8QWETm1M=; b=Kfqt078VXhCzUN1A4oyEigJUrqs3wDN75QjHD7y9DDeZG3eP+kokpZL3F8MNQAcw7WtFxu ovhtLu2mbd6tkTwNtZglkaRfjrwmQaa9mzUlVdvpCb6cUWUkHjSXFpxj/GPrxqu+BEoI2v m68r3cgEgLTcq3L3x6HSE5u6CJ19EG8= X-MC-Unique: qjiWXr8WMBCyLWfOk1tkYA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/11] virDomainHostdevDefFormatSubsys: Use virXMLFormatElement Date: Tue, 14 Jul 2020 20:00:06 +0200 Message-Id: <9548efddb1396c4b879f582e288220c3637e54c9.1594749375.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Refactor the formatter to the new multiple buffer based approach so that we can easily separate it into formatters per subsys type. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 65 ++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 38 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 8f5a8ef4a4..4b1f27fcea 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -26030,7 +26030,9 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, bool includeTypeInAddr, virDomainXMLOptionPtr xmlopt) { - bool closedSource =3D false; + g_auto(virBuffer) sourceAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) sourceChildBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) origstatesChildBuf =3D VIR_BUFFER_INIT_CHILD(&source= ChildBuf); virDomainHostdevSubsysUSBPtr usbsrc =3D &def->source.subsys.u.usb; virDomainHostdevSubsysPCIPtr pcisrc =3D &def->source.subsys.u.pci; virDomainHostdevSubsysSCSIPtr scsisrc =3D &def->source.subsys.u.scsi; @@ -26053,18 +26055,17 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, virBufferAsprintf(buf, "\n", backend); } - virBufferAddLit(buf, "source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)= { if (def->startupPolicy) { const char *policy; policy =3D virDomainStartupPolicyTypeToString(def->startupPoli= cy); - virBufferAsprintf(buf, " startupPolicy=3D'%s'", policy); + virBufferAsprintf(&sourceAttrBuf, " startupPolicy=3D'%s'", pol= icy); } if (usbsrc->autoAddress && (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATAB= LE)) - virBufferAddLit(buf, " autoAddress=3D'yes'"); + virBufferAddLit(&sourceAttrBuf, " autoAddress=3D'yes'"); if (def->missing && !(flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE)) - virBufferAddLit(buf, " missing=3D'yes'"); + virBufferAddLit(&sourceAttrBuf, " missing=3D'yes'"); } if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI= && @@ -26072,69 +26073,59 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, const char *protocol =3D virDomainHostdevSubsysSCSIProtocolTypeToString(scsisrc->protoc= ol); - virBufferAsprintf(buf, " protocol=3D'%s' name=3D'%s'", + virBufferAsprintf(&sourceAttrBuf, " protocol=3D'%s' name=3D'%s'", protocol, iscsisrc->src->path); } if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI= _HOST) { const char *protocol =3D virDomainHostdevSubsysSCSIHostProtocolTypeToString(hostsrc->pr= otocol); - closedSource =3D true; - virBufferAsprintf(buf, " protocol=3D'%s' wwpn=3D'%s'/", + virBufferAsprintf(&sourceAttrBuf, " protocol=3D'%s' wwpn=3D'%s'", protocol, hostsrc->wwpn); } - virBufferAddLit(buf, ">\n"); - - virBufferAdjustIndent(buf, 2); switch (def->source.subsys.type) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB: if (usbsrc->vendor) { - virBufferAsprintf(buf, "\n", usbsrc->ve= ndor); - virBufferAsprintf(buf, "\n", usbsrc->p= roduct); + virBufferAsprintf(&sourceChildBuf, "\n"= , usbsrc->vendor); + virBufferAsprintf(&sourceChildBuf, "\n= ", usbsrc->product); } if (usbsrc->bus || usbsrc->device) { - virBufferAsprintf(buf, "
\= n", + virBufferAsprintf(&sourceChildBuf, "
\n", includeTypeInAddr ? "type=3D'usb' " : "", usbsrc->bus, usbsrc->device); } break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: - virPCIDeviceAddressFormat(buf, pcisrc->addr, + virPCIDeviceAddressFormat(&sourceChildBuf, pcisrc->addr, includeTypeInAddr); - if ((flags & VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES) && - (def->origstates.states.pci.unbind_from_stub || - def->origstates.states.pci.remove_slot || - def->origstates.states.pci.reprobe)) { - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + if ((flags & VIR_DOMAIN_DEF_FORMAT_PCI_ORIG_STATES)) { if (def->origstates.states.pci.unbind_from_stub) - virBufferAddLit(buf, "\n"); + virBufferAddLit(&origstatesChildBuf, "\n"); if (def->origstates.states.pci.remove_slot) - virBufferAddLit(buf, "\n"); + virBufferAddLit(&origstatesChildBuf, "\n"); if (def->origstates.states.pci.reprobe) - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virBufferAddLit(&origstatesChildBuf, "\n"); + virXMLFormatElement(&sourceChildBuf, "origstates", NULL, &orig= statesChildBuf); } break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: if (scsisrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE= _ISCSI) { - virBufferAddLit(buf, "src->host= s[0].name); + virBufferAddLit(&sourceChildBuf, "src->hosts[0].name); if (iscsisrc->src->hosts[0].port) - virBufferAsprintf(buf, " port=3D'%u'", iscsisrc->src->host= s[0].port); - virBufferAddLit(buf, "/>\n"); + virBufferAsprintf(&sourceChildBuf, " port=3D'%u'", iscsisr= c->src->hosts[0].port); + virBufferAddLit(&sourceChildBuf, "/>\n"); - if (virDomainDiskSourceFormatPrivateData(buf, iscsisrc->src, + if (virDomainDiskSourceFormatPrivateData(&sourceChildBuf, iscs= isrc->src, flags, xmlopt) < 0) return -1; } else { - virBufferAsprintf(buf, "\n", + virBufferAsprintf(&sourceChildBuf, "\n", scsihostsrc->adapter); - virBufferAsprintf(buf, + virBufferAsprintf(&sourceChildBuf, "
\n", includeTypeInAddr ? "type=3D'scsi' " : "", scsihostsrc->bus, scsihostsrc->target, @@ -26144,7 +26135,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST: break; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - virBufferAsprintf(buf, "
\n", + virBufferAsprintf(&sourceChildBuf, "
\n", mdevsrc->uuidstr); break; default: @@ -26157,11 +26148,9 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf, if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI= && scsisrc->protocol =3D=3D VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISC= SI && iscsisrc->src->auth) - virStorageAuthDefFormat(buf, iscsisrc->src->auth); + virStorageAuthDefFormat(&sourceChildBuf, iscsisrc->src->auth); - virBufferAdjustIndent(buf, -2); - if (!closedSource) - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "source", &sourceAttrBuf, &sourceChildBuf); return 0; } --=20 2.26.2