From nobody Wed May 1 08:16:51 2024 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=1641287139; cv=none; d=zohomail.com; s=zohoarc; b=EbEIQdnGStXZdaHamz39fuqrgeRuJJtLkNsBP1fShzDMsi8hQP8XhU8Bs9LbrCo0zD2XmISOrRYfZpE4ZoSjMyIrIF92MiMfJsnIDg8kRuNKJv3baQUfRKnzXefF5LzfsC6Dz6iHka5EKrYMU863ntx5A9UolQst84UQv2i6NI8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641287139; 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=YlKbErQxns1JHI7M1vN+TwmWtRb9FayyOMY+mROEGEM=; b=kbH3apjZzNOu7m6vCcj4cKOpcx7R1iTtMD2KLIa1oC7Je6gKv7l3iDHcs9VmmzyReiZ5S2os+DPBOAoWZHuJrSx8a2rkeCrcUzABowQP/IuAVRB7uXtaNzrQnl0EMnvYU8+0ZhynVynvJArns/ev81Tc9HLTGVmb1f6efQ8mDFI= 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 1641287139047577.9135987343969; Tue, 4 Jan 2022 01:05:39 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-140-Qt_UbYjWNx2ZgN4CXfDyXg-1; Tue, 04 Jan 2022 04:05:34 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 68528185302C; Tue, 4 Jan 2022 09:05:30 +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 48A4A5F91F; Tue, 4 Jan 2022 09:05:30 +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 8F79D4CA93; Tue, 4 Jan 2022 09:05:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20495RNw031363 for ; Tue, 4 Jan 2022 04:05:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id DF5B37CAF6; Tue, 4 Jan 2022 09:05:27 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A7687CD64 for ; Tue, 4 Jan 2022 09:05:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641287138; 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=YlKbErQxns1JHI7M1vN+TwmWtRb9FayyOMY+mROEGEM=; b=ZLq+Pf+6aJwiu63u9YbKpY7dt5Hqwmh4F3KqiYNnTs0AGtHA3QRl0kb1Av/iQNKsY2bU2H djae/nnDGJt+Gqy1hXrNNGhBw+s87NCO1G+kvGv6e1Y6j+czVvW457x6sJtxo5N3JBXZfB BESVFjhqT+kTsSfzQFFJjzqQFnRZCxI= X-MC-Unique: Qt_UbYjWNx2ZgN4CXfDyXg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 1/3] conf: Rework formatting Date: Tue, 4 Jan 2022 10:04:58 +0100 Message-Id: <5e2a368c618d645a0bc08f172052a410ff2d56ca.1641287042.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.79 on 10.5.11.14 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: 1641287140755100001 Content-Type: text/plain; charset="utf-8" The element formatting is handled in virDomainTPMDefFormat() which uses the "old style" - appending strings directly into the output buffer. With this, it's easy to get conditions that tell when an element has ended wrong. In this particular case, if both and are to be formatted the current code puts a stray '>' into the output buffer, resulting in invalid XML. Rewrite the function to use virXMLFormatElement() which is more clever. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2016599#c15 Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/conf/domain_conf.c | 53 ++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bba662bf4c..9e854d031e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25495,63 +25495,54 @@ virDomainTPMDefFormat(virBuffer *buf, virDomainTPMDef *def, unsigned int flags) { - virBufferAsprintf(buf, "\n", + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) backendAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) backendChildBuf =3D VIR_BUFFER_INIT_CHILD(&childBuf); + + virBufferAsprintf(&attrBuf, " model=3D'%s'", virDomainTPMModelTypeToString(def->model)); - virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "type)); =20 switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, "\n", + virBufferEscapeString(&backendChildBuf, "\n", def->data.passthrough.source->data.file.path= ); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: - virBufferAsprintf(buf, " version=3D'%s'", + virBufferAsprintf(&backendAttrBuf, " version=3D'%s'", virDomainTPMVersionTypeToString(def->version)); if (def->data.emulator.persistent_state) - virBufferAddLit(buf, " persistent_state=3D'yes'"); + virBufferAddLit(&backendAttrBuf, " persistent_state=3D'yes'"); if (def->data.emulator.hassecretuuid) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "\n", - virUUIDFormat(def->data.emulator.secretuuid, uuidstr)); - virBufferAdjustIndent(buf, -2); + + virBufferAsprintf(&backendChildBuf, "\n", + virUUIDFormat(def->data.emulator.secretuuid,= uuidstr)); } if (def->data.emulator.activePcrBanks) { + g_auto(virBuffer) activePcrBanksBuf =3D VIR_BUFFER_INIT_CHILD(= &backendChildBuf); size_t i; - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, 2); + for (i =3D VIR_DOMAIN_TPM_PCR_BANK_SHA1; i < VIR_DOMAIN_TPM_PC= R_BANK_LAST; i++) { if ((def->data.emulator.activePcrBanks & (1 << i))) - virBufferAsprintf(buf, "<%s/>\n", + virBufferAsprintf(&activePcrBanksBuf, "<%s/>\n", virDomainTPMPcrBankTypeToString(i)); } - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); - virBufferAdjustIndent(buf, -2); + + virXMLFormatElement(&backendChildBuf, "active_pcr_banks", NULL= , &activePcrBanksBuf); } - if (def->data.emulator.hassecretuuid || - def->data.emulator.activePcrBanks) - virBufferAddLit(buf, "\n"); - else - virBufferAddLit(buf, "/>\n"); break; case VIR_DOMAIN_TPM_TYPE_LAST: break; } =20 - virDomainDeviceInfoFormat(buf, &def->info, flags); + virXMLFormatElement(&childBuf, "backend", &backendAttrBuf, &backendChi= ldBuf); + virDomainDeviceInfoFormat(&childBuf, &def->info, flags); =20 - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "\n"); + virXMLFormatElement(buf, "tpm", &attrBuf, &childBuf); =20 return 0; } --=20 2.34.1 From nobody Wed May 1 08:16:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1641287147; cv=none; d=zohomail.com; s=zohoarc; b=Tn+bLZhoqXUeglTEH3Rj9FBieEYteT2QTW6UMgVUT6xaI6+2Mql9ddBseJe9A0ZraNa7aG18Z9wby6HY5THpkuVOjDEN+3GagxcTNy/nWwmE/MfoR057j00JNOj0ggXV8vIqGNjSfRTU0CdNJvcB318NshspR7hVZyuBZO7RmSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1641287147; 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=srH2oAXJH1/WGuOvLSBwYvU0B1DNllC7TkbIZbMmrOc=; b=f1G5nd/iyyaeBiuoYRjOA7DjixEMntVrMML4m+564SDhZ+SBW6oBZ46pa1kuZbeUkkBa+WPqBt+ca6x8UvypvO6b60e96gXY4mepcqpDf5Yg8w9EJEGciRRQ+neDp2tPhPTO7jI60Tg7j6EyHm2FWJhaqC8H3IdRVrcUbUFfGAQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 1641287147938183.19468755318314; Tue, 4 Jan 2022 01:05:47 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-271-GcfcR2oVMf2f22tRblrc1Q-1; Tue, 04 Jan 2022 04:05:45 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D4EE0801A02; Tue, 4 Jan 2022 09:05:38 +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 B04F91F2F6; Tue, 4 Jan 2022 09:05:38 +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 840CF4A7CB; Tue, 4 Jan 2022 09:05:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20495SVA031373 for ; Tue, 4 Jan 2022 04:05:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id D2EB57CAF6; Tue, 4 Jan 2022 09:05:28 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 375DA7CD63 for ; Tue, 4 Jan 2022 09:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641287146; 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=srH2oAXJH1/WGuOvLSBwYvU0B1DNllC7TkbIZbMmrOc=; b=ciI1fTlOIrRnKtXyPAIp6cxBtg9OoPuWMsQX9XEsyH9gIVnGv+17tFPpj7PzZSg7/Bu6Vs 5JSVOsryz1hHSI2+ex+19tBnTP5VpwZLkBO3zxDO+cFfQTQBsal2sEiJAC809kEeypOr0S q6xKkms9qXPglLrk+A010f1sD51rswQ= X-MC-Unique: GcfcR2oVMf2f22tRblrc1Q-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 2/3] qemuxml2xmloutdata: Turn tpm-*.xml files into symlinks Date: Tue, 4 Jan 2022 10:04:59 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.23 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: 1641287148526100001 Content-Type: text/plain; charset="utf-8" Make the tpm-*.xml files symlinks to their respective input XMLs from qemuxml2argvdata/ directory. Neither of the XMLs relies on autofill of any TPM data. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- .../tpm-emulator-tpm2-enc.xml | 12 ++++- .../tpm-emulator-tpm2-pstate.xml | 12 ++++- tests/qemuxml2argvdata/tpm-emulator-tpm2.xml | 13 +++++- tests/qemuxml2argvdata/tpm-emulator.xml | 12 ++++- .../qemuxml2argvdata/tpm-passthrough-crb.xml | 12 ++++- tests/qemuxml2argvdata/tpm-passthrough.xml | 12 ++++- .../tpm-emulator-tpm2-enc.x86_64-latest.xml | 41 +---------------- ...tpm-emulator-tpm2-pstate.x86_64-latest.xml | 39 +--------------- .../tpm-emulator-tpm2.x86_64-latest.xml | 44 +------------------ .../tpm-emulator.x86_64-latest.xml | 39 +--------------- .../tpm-passthrough-crb.x86_64-latest.xml | 41 +---------------- .../tpm-passthrough.x86_64-latest.xml | 41 +---------------- 12 files changed, 67 insertions(+), 251 deletions(-) mode change 100644 =3D> 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2-= enc.x86_64-latest.xml mode change 100644 =3D> 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2-= pstate.x86_64-latest.xml mode change 100644 =3D> 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2.= x86_64-latest.xml mode change 100644 =3D> 120000 tests/qemuxml2xmloutdata/tpm-emulator.x86_6= 4-latest.xml mode change 100644 =3D> 120000 tests/qemuxml2xmloutdata/tpm-passthrough-cr= b.x86_64-latest.xml mode change 100644 =3D> 120000 tests/qemuxml2xmloutdata/tpm-passthrough.x8= 6_64-latest.xml diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.xml b/tests/qemux= ml2argvdata/tpm-emulator-tpm2-enc.xml index d889aae4f6..9c2279b28b 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.xml +++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.xml @@ -12,13 +12,18 @@ + + qemu64 + destroy restart destroy /usr/bin/qemu-system-x86_64 - + +
+ @@ -27,6 +32,9 @@ - +