[libvirt] [PATCH v3 03/14] conf: Add support for external swtpm TPM emulator to domain XML

John Ferlan jferlan at redhat.com
Tue May 8 19:59:05 UTC 2018



On 05/04/2018 04:21 PM, Stefan Berger wrote:
> This patch adds support for an external swtpm TPM emulator. The XML for
> this type of TPM looks as follows:
> 
>  <tpm model='tpm-tis'>
>    <backend type='emulator'/>
>  </tpm>
> 
> The XML will currently only define a TPM 1.2.
> 
> Extend the documentation.
> 
> Add a test case testing the XML parser and formatter.
> 
> Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
> ---
>  docs/formatdomain.html.in                 | 30 +++++++++++++++++++++++++++
>  docs/schemas/domaincommon.rng             |  5 +++++
>  src/conf/domain_audit.c                   |  2 ++
>  src/conf/domain_conf.c                    | 28 ++++++++++++++++++-------
>  src/conf/domain_conf.h                    |  7 +++++++
>  src/qemu/qemu_cgroup.c                    |  1 +
>  src/qemu/qemu_command.c                   |  1 +
>  src/qemu/qemu_domain.c                    |  1 +
>  src/security/security_dac.c               |  2 ++
>  src/security/security_selinux.c           |  2 ++
>  tests/qemuxml2argvdata/tpm-emulator.xml   | 30 +++++++++++++++++++++++++++
>  tests/qemuxml2xmloutdata/tpm-emulator.xml | 34 +++++++++++++++++++++++++++++++
>  tests/qemuxml2xmltest.c                   |  1 +
>  13 files changed, 137 insertions(+), 7 deletions(-)
>  create mode 100644 tests/qemuxml2argvdata/tpm-emulator.xml
>  create mode 100644 tests/qemuxml2xmloutdata/tpm-emulator.xml
> 

[...]

>  static virDomainTPMDefPtr
>  virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt,
> @@ -12648,6 +12659,8 @@ virDomainTPMDefParseXML(virDomainXMLOptionPtr xmlopt,
>          def->data.passthrough.source.type = VIR_DOMAIN_CHR_TYPE_DEV;
>          path = NULL;
>          break;
> +    case VIR_DOMAIN_TPM_TYPE_EMULATOR:
> +        break;
>      case VIR_DOMAIN_TPM_TYPE_LAST:
>          goto error;
>      }
> @@ -24815,22 +24828,23 @@ virDomainTPMDefFormat(virBufferPtr buf,
>      virBufferAsprintf(buf, "<tpm model='%s'>\n",
>                        virDomainTPMModelTypeToString(def->model));
>      virBufferAdjustIndent(buf, 2);
> -    virBufferAsprintf(buf, "<backend type='%s'>\n",
> +    virBufferAsprintf(buf, "<backend type='%s'",
>                        virDomainTPMBackendTypeToString(def->type));
> -    virBufferAdjustIndent(buf, 2);
>  
>      switch (def->type) {
>      case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
> -        virBufferEscapeString(buf, "<device path='%s'/>\n",
> +        virBufferAddLit(buf, ">\n");
> +        virBufferEscapeString(buf, "  <device path='%s'/>\n",
>                                def->data.passthrough.source.data.file.path);

syntax-check would have told you to use virBufferAdjustIndent around
this and not use "  <device..."

> +        virBufferAddLit(buf, "</backend>\n");
> +        break;
> +    case VIR_DOMAIN_TPM_TYPE_EMULATOR:
> +        virBufferAddLit(buf, "/>\n");
>          break;
>      case VIR_DOMAIN_TPM_TYPE_LAST:
>          break;
>      }
>  
> -    virBufferAdjustIndent(buf, -2);
> -    virBufferAddLit(buf, "</backend>\n");
> -
>      virDomainDeviceInfoFormat(buf, &def->info, flags);
>  
>      virBufferAdjustIndent(buf, -2);

With the adjustment,

Reviewed-by: John Ferlan <jferlan at redhat.com>

John




More information about the libvir-list mailing list