[libvirt] [PATCH v4 10/11] TPM support for QEMU command line
Daniel P. Berrange
berrange at redhat.com
Thu Apr 11 15:43:01 UTC 2013
On Fri, Apr 05, 2013 at 10:06:01AM -0400, Stefan Berger wrote:
> For TPM passthrough device support create command line parameters like:
>
> -tpmdev passthrough,id=tpm-tpm0,path=/dev/tpm0,cancel-path=/sys/class/misc/tpm0/device/cancel -device tpm-tis,tpmdev=tpm-tpm0,id=tpm0
>
> Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
> Reviewed-by: Corey Bryant <coreyb at linux.vnet.ibm.com>
> Tested-by: Corey Bryant <coreyb at linux.vnet.ibm.com>
>
> ---
> src/qemu/qemu_command.c | 217 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 217 insertions(+)
>
> Index: libvirt/src/qemu/qemu_command.c
> ===================================================================
> --- libvirt.orig/src/qemu/qemu_command.c
> +++ libvirt/src/qemu/qemu_command.c
> @@ -46,6 +46,7 @@
> #include "base64.h"
> #include "device_conf.h"
> #include "virstoragefile.h"
> +#include "virtpm.h"
>
> #include <sys/stat.h>
> #include <fcntl.h>
> @@ -799,6 +800,10 @@ qemuAssignDeviceAliases(virDomainDefPtr
> if (virAsprintf(&def->rng->info.alias, "rng%d", 0) < 0)
> goto no_memory;
> }
> + if (def->tpm) {
> + if (virAsprintf(&def->tpm->info.alias, "tpm%d", 0) < 0)
> + goto no_memory;
> + }
>
> return 0;
>
> @@ -4791,6 +4796,92 @@ cleanup:
> }
>
>
> +static char *qemuBuildTPMBackendStr(const virDomainDefPtr def,
> + virQEMUCapsPtr qemuCaps,
> + const char *emulator)
> +{
> + const virDomainTPMDefPtr tpm = def->tpm;
> + virBuffer buf = VIR_BUFFER_INITIALIZER;
> + const char *type = virDomainTPMBackendTypeToString(tpm->type);
> + const char *cancel_path;
> +
> + virBufferAsprintf(&buf, "%s,id=tpm-%s", type, tpm->info.alias);
> +
> + switch (tpm->type) {
> + case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH:
> + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_PASSTHROUGH))
> + goto no_support;
> +
> + virBufferAddLit(&buf, ",path=");
> + virBufferEscape(&buf, ',', ",", "%s",
> + tpm->data.passthrough.source.data.file.path);
> +
> + if (!(cancel_path = virTPMFindCancelPath())) {
> + virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> + _("TPM cancel path could not be determined"));
Again, don't overwrite errors raised by virTPMFindCancelPath().
> + goto error;
> + }
> +
> + virBufferAddLit(&buf, ",cancel-path=");
> + virBufferEscape(&buf, ',', ",", "%s", cancel_path);
> + VIR_FREE(cancel_path);
> +
> + break;
> + case VIR_DOMAIN_TPM_TYPE_LAST:
> + goto error;
> + }
> +
> + if (virBufferError(&buf)) {
> + virReportOOMError();
> + goto error;
> + }
> +
> + return virBufferContentAndReset(&buf);
> +
> + no_support:
> + virReportError(VIR_ERR_INTERNAL_ERROR,
s/INTERNAL_ERROR/CONFIG_UNSUPPORTED/
> + _("The QEMU executable %s does not support TPM "
> + "backend type %s"),
> + emulator, type);
> +
> + error:
> + virBufferFreeAndReset(&buf);
> + return NULL;
> +}
> +
> +
> +static char *qemuBuildTPMDevStr(const virDomainDefPtr def,
> + virQEMUCapsPtr qemuCaps,
> + const char *emulator)
> +{
> + virBuffer buf = VIR_BUFFER_INITIALIZER;
> + const virDomainTPMDefPtr tpm = def->tpm;
> + const char *model = virDomainTPMModelTypeToString(tpm->model);
> +
> + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_TPM_TIS)) {
> + virReportError(VIR_ERR_INTERNAL_ERROR,
> + _("The QEMU executable %s does not support TPM "
> + "model %s"),
> + emulator, model);
s/INTERNAL_ERROR/CONFIG_UNSUPPORTED/
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list