From nobody Tue Feb 10 05:44:02 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 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=1646916053; cv=none; d=zohomail.com; s=zohoarc; b=IrGq+eOhO+H+UuWmF2PgPyP4pBjCeThoBDJOU+7EgeJbMXkNDlbaWhvU6v/2okWTNe/hyHyHf1rf7pcsNjK6+RKIvUrfzrjlNGRhOs9lcV5DwaAscvNsYi8jB035inYXQcDsqoNzCLSbcf5vmEqADeeq5Ufrcq0U14L4jqgvdfY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646916053; 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=8A6CMjUZL3pBxtE0nnPE6N2fCdda2hTX4GfXEgYPqBU=; b=AF7jKd0e5a9FoludsfnpeVRHOu6qVVtcjHEFa0ooiB2wP6hsxTrUnV36ZI5rBOHNZTdYCeE/Gfe1GbXaEK0UlMu2Sx5Rrb7f1mLFHvmT6mIj4ip7ztGtqOtqrj9RpycC5pjTYxLoBCMcNtITVlLiknHMEqfYJavV0J4OB7nBsI4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1646916053295266.8208486509891; Thu, 10 Mar 2022 04:40:53 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-400-OdHbzX53NbKelX_5o7Nhvg-1; Thu, 10 Mar 2022 07:40:50 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBEB42A2AD47; Thu, 10 Mar 2022 12:40:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C6E01463EC6; Thu, 10 Mar 2022 12:40:47 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 8EF141953576; Thu, 10 Mar 2022 12:40:47 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 4DE48195FD44 for ; Thu, 10 Mar 2022 12:40:46 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id EAB617D3CC; Thu, 10 Mar 2022 12:40:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF4EB7D3CD for ; Thu, 10 Mar 2022 12:40:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646916052; 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=8A6CMjUZL3pBxtE0nnPE6N2fCdda2hTX4GfXEgYPqBU=; b=TugzkGEzSg2E3g3sdTNBtyFdGc+2isEqlBn3rJCWwEl3JolWAgi5H0RBUfdME/Pl8lB6Db 9xWZCNC1ncwwOYmGq7b1iRxz/6AqgrgwN+rmzinW7Apd0UxTa1EP1rI+dB4aSWJ+PFyxbe 2kAPaGPGNJZt/DxsI28rvnWF16reniI= X-MC-Unique: OdHbzX53NbKelX_5o7Nhvg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/14] virDomainDiskDefFormat: Refactor to virXMLFormatElement Date: Thu, 10 Mar 2022 13:40:29 +0100 Message-Id: <4e5d61cfe257e23161b6fa8d689e61e7c1fb8f20.1646915960.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646916053739100002 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 79 ++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 34fec887a3..69f61aadc1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23568,6 +23568,8 @@ virDomainDiskDefFormat(virBuffer *buf, const char *device =3D virDomainDiskDeviceTypeToString(def->device); const char *bus =3D virDomainDiskBusTypeToString(def->bus); const char *sgio =3D virDomainDeviceSGIOTypeToString(def->sgio); + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); if (!type || !def->src->type) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -23590,39 +23592,35 @@ virDomainDiskDefFormat(virBuffer *buf, return -1; } - virBufferAsprintf(buf, - "model) { - virBufferAsprintf(buf, " model=3D'%s'", + virBufferAsprintf(&attrBuf, " model=3D'%s'", virDomainDiskModelTypeToString(def->model)); } if (def->rawio) { - virBufferAsprintf(buf, " rawio=3D'%s'", + virBufferAsprintf(&attrBuf, " rawio=3D'%s'", virTristateBoolTypeToString(def->rawio)); } if (def->sgio) - virBufferAsprintf(buf, " sgio=3D'%s'", sgio); + virBufferAsprintf(&attrBuf, " sgio=3D'%s'", sgio); if (def->snapshot && !(def->snapshot =3D=3D VIR_DOMAIN_SNAPSHOT_LOCATION_NONE && def->src->readonly)) - virBufferAsprintf(buf, " snapshot=3D'%s'", + virBufferAsprintf(&attrBuf, " snapshot=3D'%s'", virDomainSnapshotLocationTypeToString(def->snaps= hot)); - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virDomainDiskDefFormatDriver(buf, def); + virDomainDiskDefFormatDriver(&childBuf, def); /* Format as child of if defined there; otherwise, * if defined as child of , then format later */ if (def->src->auth && def->diskElementAuth) - virStorageAuthDefFormat(buf, def->src->auth); + virStorageAuthDefFormat(&childBuf, def->src->auth); - if (virDomainDiskSourceFormat(buf, def->src, "source", def->startupPol= icy, + if (virDomainDiskSourceFormat(&childBuf, def->src, "source", def->star= tupPolicy, true, flags, def->diskElementAuth, def->diskElementEn= c, xmlopt) < 0) @@ -23630,75 +23628,74 @@ virDomainDiskDefFormat(virBuffer *buf, /* Don't format backingStore to inactive XMLs until the code for * persistent storage of backing chains is ready. */ - if (virDomainDiskBackingStoreFormat(buf, def->src, xmlopt, flags) < 0) + if (virDomainDiskBackingStoreFormat(&childBuf, def->src, xmlopt, flags= ) < 0) return -1; - virBufferEscapeString(buf, "\n", def->doma= in_name); + virBufferEscapeString(&childBuf, "\n", def= ->domain_name); - virDomainDiskGeometryDefFormat(buf, def); - virDomainDiskBlockIoDefFormat(buf, def); + virDomainDiskGeometryDefFormat(&childBuf, def); + virDomainDiskBlockIoDefFormat(&childBuf, def); - if (virDomainDiskDefFormatMirror(buf, def, flags, xmlopt) < 0) + if (virDomainDiskDefFormatMirror(&childBuf, def, flags, xmlopt) < 0) return -1; - virBufferAsprintf(buf, "dst, bus); if ((def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY || def->device =3D=3D VIR_DOMAIN_DISK_DEVICE_CDROM) && def->tray_status !=3D VIR_DOMAIN_DISK_TRAY_CLOSED) - virBufferAsprintf(buf, " tray=3D'%s'", + virBufferAsprintf(&childBuf, " tray=3D'%s'", virDomainDiskTrayTypeToString(def->tray_status)); if (def->bus =3D=3D VIR_DOMAIN_DISK_BUS_USB && def->removable !=3D VIR_TRISTATE_SWITCH_ABSENT) { - virBufferAsprintf(buf, " removable=3D'%s'", + virBufferAsprintf(&childBuf, " removable=3D'%s'", virTristateSwitchTypeToString(def->removable)); } if (def->rotation_rate) - virBufferAsprintf(buf, " rotation_rate=3D'%u'", def->rotation_rate= ); - virBufferAddLit(buf, "/>\n"); + virBufferAsprintf(&childBuf, " rotation_rate=3D'%u'", def->rotatio= n_rate); + virBufferAddLit(&childBuf, "/>\n"); - virDomainDiskDefFormatIotune(buf, def); + virDomainDiskDefFormatIotune(&childBuf, def); if (def->src->readonly) - virBufferAddLit(buf, "\n"); + virBufferAddLit(&childBuf, "\n"); if (def->src->shared) - virBufferAddLit(buf, "\n"); + virBufferAddLit(&childBuf, "\n"); if (def->transient) { - virBufferAddLit(buf, "transientShareBacking =3D=3D VIR_TRISTATE_BOOL_YES) - virBufferAddLit(buf, " shareBacking=3D'yes'"); - virBufferAddLit(buf, "/>\n"); + virBufferAddLit(&childBuf, " shareBacking=3D'yes'"); + virBufferAddLit(&childBuf, "/>\n"); } - virBufferEscapeString(buf, "%s\n", def->serial); - virBufferEscapeString(buf, "%s\n", def->wwn); - virBufferEscapeString(buf, "%s\n", def->vendor); - virBufferEscapeString(buf, "%s\n", def->product); + virBufferEscapeString(&childBuf, "%s\n", def->serial); + virBufferEscapeString(&childBuf, "%s\n", def->wwn); + virBufferEscapeString(&childBuf, "%s\n", def->vendor); + virBufferEscapeString(&childBuf, "%s\n", def->produ= ct); /* If originally found as a child of , then format thusly; * otherwise, will be formatted as child of */ if (def->src->encryption && def->diskElementEnc && - virStorageEncryptionFormat(buf, def->src->encryption) < 0) + virStorageEncryptionFormat(&childBuf, def->src->encryption) < 0) return -1; - virDomainDeviceInfoFormat(buf, &def->info, flags | VIR_DOMAIN_DEF_FORM= AT_ALLOW_BOOT); + virDomainDeviceInfoFormat(&childBuf, &def->info, flags | VIR_DOMAIN_DE= F_FORMAT_ALLOW_BOOT); - if (virDomainDiskDefFormatPrivateData(buf, def, flags, xmlopt) < 0) + if (virDomainDiskDefFormatPrivateData(&childBuf, def, flags, xmlopt) <= 0) return -1; /* format diskElementAuth and diskElementEnc into status XML to preser= ve * formatting */ if (flags & VIR_DOMAIN_DEF_FORMAT_STATUS) { - g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) secretPlacementAttrBuf =3D VIR_BUFFER_INITIALIZE= R; if (def->diskElementAuth) - virBufferAddLit(&attrBuf, " auth=3D'true'"); + virBufferAddLit(&secretPlacementAttrBuf, " auth=3D'true'"); if (def->diskElementEnc) - virBufferAddLit(&attrBuf, " enc=3D'true'"); + virBufferAddLit(&secretPlacementAttrBuf, " enc=3D'true'"); - virXMLFormatElement(buf, "diskSecretsPlacement", &attrBuf, NULL); + virXMLFormatElement(&childBuf, "diskSecretsPlacement", &secretPlac= ementAttrBuf, NULL); } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "disk", &attrBuf, &childBuf); return 0; } --=20 2.35.1