[PATCH v2 0/3] Rework <tpm/> formatting

v2 of: https://listman.redhat.com/archives/libvir-list/2022-January/msg00047.html diff to v1: - Pushed 1/4 from the original series, because it was acked and independent of the rest. - Swapped two patches to make the test suite pass after each single patch. - Renamed variable in 1/3 (3/4 in the original series) per Peter's suggestion. Michal Prívozník (3): conf: Rework <tpm/> formatting qemuxml2xmloutdata: Turn tpm-*.xml files into symlinks conf: Make virDomainTPMDefFormat() return void src/conf/domain_conf.c | 65 ++++++++----------- .../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 +----------- 13 files changed, 94 insertions(+), 289 deletions(-) mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml -- 2.34.1

The <tpm/> 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 <encryption/> and <active_pcr_banks/> 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=2016599#c15 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> --- 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, "<tpm model='%s'>\n", + g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); + g_auto(virBuffer) backendAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) backendChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); + + virBufferAsprintf(&attrBuf, " model='%s'", virDomainTPMModelTypeToString(def->model)); - virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "<backend type='%s'", + + virBufferAsprintf(&backendAttrBuf, " type='%s'", virDomainTPMBackendTypeToString(def->type)); switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, "<device path='%s'/>\n", + virBufferEscapeString(&backendChildBuf, "<device path='%s'/>\n", def->data.passthrough.source->data.file.path); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "</backend>\n"); break; case VIR_DOMAIN_TPM_TYPE_EMULATOR: - virBufferAsprintf(buf, " version='%s'", + virBufferAsprintf(&backendAttrBuf, " version='%s'", virDomainTPMVersionTypeToString(def->version)); if (def->data.emulator.persistent_state) - virBufferAddLit(buf, " persistent_state='yes'"); + virBufferAddLit(&backendAttrBuf, " persistent_state='yes'"); if (def->data.emulator.hassecretuuid) { char uuidstr[VIR_UUID_STRING_BUFLEN]; - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferAsprintf(buf, "<encryption secret='%s'/>\n", - virUUIDFormat(def->data.emulator.secretuuid, uuidstr)); - virBufferAdjustIndent(buf, -2); + + virBufferAsprintf(&backendChildBuf, "<encryption secret='%s'/>\n", + virUUIDFormat(def->data.emulator.secretuuid, uuidstr)); } if (def->data.emulator.activePcrBanks) { + g_auto(virBuffer) activePcrBanksBuf = VIR_BUFFER_INIT_CHILD(&backendChildBuf); size_t i; - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferAddLit(buf, "<active_pcr_banks>\n"); - virBufferAdjustIndent(buf, 2); + for (i = VIR_DOMAIN_TPM_PCR_BANK_SHA1; i < VIR_DOMAIN_TPM_PCR_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, "</active_pcr_banks>\n"); - virBufferAdjustIndent(buf, -2); + + virXMLFormatElement(&backendChildBuf, "active_pcr_banks", NULL, &activePcrBanksBuf); } - if (def->data.emulator.hassecretuuid || - def->data.emulator.activePcrBanks) - virBufferAddLit(buf, "</backend>\n"); - else - virBufferAddLit(buf, "/>\n"); break; case VIR_DOMAIN_TPM_TYPE_LAST: break; } - virDomainDeviceInfoFormat(buf, &def->info, flags); + virXMLFormatElement(&childBuf, "backend", &backendAttrBuf, &backendChildBuf); + virDomainDeviceInfoFormat(&childBuf, &def->info, flags); - virBufferAdjustIndent(buf, -2); - virBufferAddLit(buf, "</tpm>\n"); + virXMLFormatElement(buf, "tpm", &attrBuf, &childBuf); return 0; } -- 2.34.1

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 <mprivozn@redhat.com> --- .../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 => 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml mode change 100644 => 120000 tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-enc.xml b/tests/qemuxml2argvdata/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 @@ <features> <acpi/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0'/> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> @@ -27,6 +32,9 @@ <encryption secret='32ee7e76-2178-47a1-ab7b-269e6e348015'/> </backend> </tpm> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.xml b/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.xml index 45fc4c0e1a..42e93cfcbe 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.xml +++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2-pstate.xml @@ -12,19 +12,27 @@ <features> <acpi/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0'/> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <tpm model='tpm-tis'> <backend type='emulator' version='2.0' persistent_state='yes'/> </tpm> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/tpm-emulator-tpm2.xml b/tests/qemuxml2argvdata/tpm-emulator-tpm2.xml index 68db8b9232..79acde218b 100644 --- a/tests/qemuxml2argvdata/tpm-emulator-tpm2.xml +++ b/tests/qemuxml2argvdata/tpm-emulator-tpm2.xml @@ -12,24 +12,33 @@ <features> <acpi/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0'/> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <tpm model='tpm-tis'> <backend type='emulator' version='2.0'> + <encryption secret='b4a117f1-8af2-44a4-91b8-7f0d2d4d68a3'/> <active_pcr_banks> <sha256/> <sha512/> </active_pcr_banks> </backend> </tpm> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/tpm-emulator.xml b/tests/qemuxml2argvdata/tpm-emulator.xml index defc3789ad..b98a3693b7 100644 --- a/tests/qemuxml2argvdata/tpm-emulator.xml +++ b/tests/qemuxml2argvdata/tpm-emulator.xml @@ -12,19 +12,27 @@ <features> <acpi/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0'/> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> <tpm model='tpm-tis'> <backend type='emulator' version='1.2'/> </tpm> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/tpm-passthrough-crb.xml b/tests/qemuxml2argvdata/tpm-passthrough-crb.xml index 2fce5ca342..47c622bd84 100644 --- a/tests/qemuxml2argvdata/tpm-passthrough-crb.xml +++ b/tests/qemuxml2argvdata/tpm-passthrough-crb.xml @@ -12,13 +12,18 @@ <features> <acpi/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0'/> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> @@ -27,6 +32,9 @@ <device path='/dev/tpm0'/> </backend> </tpm> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/tpm-passthrough.xml b/tests/qemuxml2argvdata/tpm-passthrough.xml index 036091d44f..1555de4e86 100644 --- a/tests/qemuxml2argvdata/tpm-passthrough.xml +++ b/tests/qemuxml2argvdata/tpm-passthrough.xml @@ -12,13 +12,18 @@ <features> <acpi/> </features> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0'/> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> <controller type='pci' index='0' model='pci-root'/> <input type='mouse' bus='ps2'/> <input type='keyboard' bus='ps2'/> @@ -27,6 +32,9 @@ <device path='/dev/tpm0'/> </backend> </tpm> - <memballoon model='virtio'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml deleted file mode 100644 index 9c2279b28b..0000000000 --- a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml +++ /dev/null @@ -1,40 +0,0 @@ -<domain type='qemu'> - <name>TPM-VM</name> - <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid> - <memory unit='KiB'>2097152</memory> - <currentMemory unit='KiB'>512288</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <features> - <acpi/> - </features> - <cpu mode='custom' match='exact' check='none'> - <model fallback='forbid'>qemu64</model> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0' model='piix3-uhci'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <tpm model='tpm-tis'> - <backend type='emulator' version='2.0'> - <encryption secret='32ee7e76-2178-47a1-ab7b-269e6e348015'/> - </backend> - </tpm> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml new file mode 120000 index 0000000000..030f4f373d --- /dev/null +++ b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-enc.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/tpm-emulator-tpm2-enc.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml deleted file mode 100644 index 42e93cfcbe..0000000000 --- a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml +++ /dev/null @@ -1,38 +0,0 @@ -<domain type='qemu'> - <name>TPM-VM</name> - <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid> - <memory unit='KiB'>2097152</memory> - <currentMemory unit='KiB'>512288</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <features> - <acpi/> - </features> - <cpu mode='custom' match='exact' check='none'> - <model fallback='forbid'>qemu64</model> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0' model='piix3-uhci'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <tpm model='tpm-tis'> - <backend type='emulator' version='2.0' persistent_state='yes'/> - </tpm> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml new file mode 120000 index 0000000000..eb65b59aac --- /dev/null +++ b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2-pstate.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/tpm-emulator-tpm2-pstate.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml deleted file mode 100644 index edab6db123..0000000000 --- a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml +++ /dev/null @@ -1,43 +0,0 @@ -<domain type='qemu'> - <name>TPM-VM</name> - <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid> - <memory unit='KiB'>2097152</memory> - <currentMemory unit='KiB'>512288</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <features> - <acpi/> - </features> - <cpu mode='custom' match='exact' check='none'> - <model fallback='forbid'>qemu64</model> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0' model='piix3-uhci'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <tpm model='tpm-tis'> - <backend type='emulator' version='2.0'> - <active_pcr_banks> - <sha256/> - <sha512/> - </active_pcr_banks> - </backend> - </tpm> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml new file mode 120000 index 0000000000..b8f1123553 --- /dev/null +++ b/tests/qemuxml2xmloutdata/tpm-emulator-tpm2.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/tpm-emulator-tpm2.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml deleted file mode 100644 index b98a3693b7..0000000000 --- a/tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml +++ /dev/null @@ -1,38 +0,0 @@ -<domain type='qemu'> - <name>TPM-VM</name> - <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid> - <memory unit='KiB'>2097152</memory> - <currentMemory unit='KiB'>512288</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <features> - <acpi/> - </features> - <cpu mode='custom' match='exact' check='none'> - <model fallback='forbid'>qemu64</model> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0' model='piix3-uhci'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <tpm model='tpm-tis'> - <backend type='emulator' version='1.2'/> - </tpm> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml new file mode 120000 index 0000000000..3ddc89fc94 --- /dev/null +++ b/tests/qemuxml2xmloutdata/tpm-emulator.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/tpm-emulator.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml deleted file mode 100644 index 47c622bd84..0000000000 --- a/tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml +++ /dev/null @@ -1,40 +0,0 @@ -<domain type='qemu'> - <name>TPM-VM</name> - <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid> - <memory unit='KiB'>2097152</memory> - <currentMemory unit='KiB'>512288</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <features> - <acpi/> - </features> - <cpu mode='custom' match='exact' check='none'> - <model fallback='forbid'>qemu64</model> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0' model='piix3-uhci'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <tpm model='tpm-crb'> - <backend type='passthrough'> - <device path='/dev/tpm0'/> - </backend> - </tpm> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml new file mode 120000 index 0000000000..2f5f021ee6 --- /dev/null +++ b/tests/qemuxml2xmloutdata/tpm-passthrough-crb.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/tpm-passthrough-crb.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml deleted file mode 100644 index 1555de4e86..0000000000 --- a/tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml +++ /dev/null @@ -1,40 +0,0 @@ -<domain type='qemu'> - <name>TPM-VM</name> - <uuid>11d7cd22-da89-3094-6212-079a48a309a1</uuid> - <memory unit='KiB'>2097152</memory> - <currentMemory unit='KiB'>512288</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-2.12'>hvm</type> - <boot dev='hd'/> - <bootmenu enable='yes'/> - </os> - <features> - <acpi/> - </features> - <cpu mode='custom' match='exact' check='none'> - <model fallback='forbid'>qemu64</model> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <controller type='usb' index='0' model='piix3-uhci'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> - </controller> - <controller type='pci' index='0' model='pci-root'/> - <input type='mouse' bus='ps2'/> - <input type='keyboard' bus='ps2'/> - <tpm model='tpm-tis'> - <backend type='passthrough'> - <device path='/dev/tpm0'/> - </backend> - </tpm> - <audio id='1' type='none'/> - <memballoon model='virtio'> - <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> - </memballoon> - </devices> -</domain> diff --git a/tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml b/tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml new file mode 120000 index 0000000000..2fbd46cad0 --- /dev/null +++ b/tests/qemuxml2xmloutdata/tpm-passthrough.x86_64-latest.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/tpm-passthrough.xml \ No newline at end of file -- 2.34.1

On Tue, Jan 04, 2022 at 10:04:59 +0100, Michal Privoznik wrote:
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 <mprivozn@redhat.com> ---
Reviewed-by: Peter Krempa <pkrempa@redhat.com>

The virDomainTPMDefFormat() function can't fail really. There's no point in it returning an integer then. Make it return void and fix both places which check for its retval. And while at it, turn @def into a const pointer to make it obvious the function does not modify passed struct. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9e854d031e..fe53a280d7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -25490,9 +25490,9 @@ virDomainSoundCodecDefFormat(virBuffer *buf, return 0; } -static int +static void virDomainTPMDefFormat(virBuffer *buf, - virDomainTPMDef *def, + const virDomainTPMDef *def, unsigned int flags) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; @@ -25543,8 +25543,6 @@ virDomainTPMDefFormat(virBuffer *buf, virDomainDeviceInfoFormat(&childBuf, &def->info, flags); virXMLFormatElement(buf, "tpm", &attrBuf, &childBuf); - - return 0; } @@ -28531,8 +28529,7 @@ virDomainDefFormatInternalSetRootName(virDomainDef *def, } for (n = 0; n < def->ntpms; n++) { - if (virDomainTPMDefFormat(buf, def->tpms[n], flags) < 0) - return -1; + virDomainTPMDefFormat(buf, def->tpms[n], flags); } for (n = 0; n < def->ngraphics; n++) { @@ -29762,7 +29759,8 @@ virDomainDeviceDefCopy(virDomainDeviceDef *src, rc = virDomainChrDefFormat(&buf, src->data.chr, flags); break; case VIR_DOMAIN_DEVICE_TPM: - rc = virDomainTPMDefFormat(&buf, src->data.tpm, flags); + virDomainTPMDefFormat(&buf, src->data.tpm, flags); + rc = 0; break; case VIR_DOMAIN_DEVICE_PANIC: virDomainPanicDefFormat(&buf, src->data.panic); -- 2.34.1
participants (2)
-
Michal Privoznik
-
Peter Krempa