mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
qemuBuildTPMCommandLine: Generate via JSON
We control only the 'tpmdev' property of TPM devices which is a string. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
173b990a82
commit
89ba187943
@ -9948,24 +9948,33 @@ qemuBuildDomainLoaderCommandLine(virCommand *cmd,
|
||||
}
|
||||
|
||||
|
||||
static char *
|
||||
qemuBuildTPMDevStr(const virDomainDef *def,
|
||||
static int
|
||||
qemuBuildTPMDevCmd(virCommand *cmd,
|
||||
const virDomainDef *def,
|
||||
virDomainTPMDef *tpm,
|
||||
virQEMUCaps *qemuCaps G_GNUC_UNUSED)
|
||||
virQEMUCaps *qemuCaps)
|
||||
{
|
||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||
g_autoptr(virJSONValue) props = NULL;
|
||||
const char *model = virDomainTPMModelTypeToString(tpm->model);
|
||||
g_autofree char *tpmdev = g_strdup_printf("tpm-%s", tpm->info.alias);
|
||||
|
||||
if (tpm->model == VIR_DOMAIN_TPM_MODEL_TIS && def->os.arch == VIR_ARCH_AARCH64)
|
||||
model = "tpm-tis-device";
|
||||
|
||||
virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
|
||||
model, tpm->info.alias, tpm->info.alias);
|
||||
if (virJSONValueObjectCreate(&props,
|
||||
"s:driver", model,
|
||||
"s:tpmdev", tpmdev,
|
||||
"s:id", tpm->info.alias,
|
||||
NULL) < 0)
|
||||
return -1;
|
||||
|
||||
if (qemuBuildDeviceAddressStr(&buf, def, &tpm->info) < 0)
|
||||
return NULL;
|
||||
if (qemuBuildDeviceAddressProps(props, def, &tpm->info) < 0)
|
||||
return -1;
|
||||
|
||||
return virBufferContentAndReset(&buf);
|
||||
if (qemuBuildDeviceCommandlineFromJSON(cmd, props, qemuCaps) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -10092,12 +10101,9 @@ qemuBuildTPMCommandLine(virCommand *cmd,
|
||||
VIR_FREE(fdset);
|
||||
}
|
||||
|
||||
if (!(optstr = qemuBuildTPMDevStr(def, tpm, qemuCaps)))
|
||||
if (qemuBuildTPMDevCmd(cmd, def, tpm, qemuCaps) < 0)
|
||||
return -1;
|
||||
|
||||
virCommandAddArgList(cmd, "-device", optstr, NULL);
|
||||
VIR_FREE(optstr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
|
||||
-device spapr-tpm-proxy,id=tpm0,host-path=/dev/tpmrm0 \
|
||||
-tpmdev emulator,id=tpm-tpm1,chardev=chrtpm \
|
||||
-chardev socket,id=chrtpm,path=/dev/test \
|
||||
-device tpm-spapr,tpmdev=tpm-tpm1,id=tpm1,reg=0x00004000 \
|
||||
-device tpm-spapr,tpmdev=tpm-tpm1,id=tpm1,reg=16384 \
|
||||
-audiodev id=audio1,driver=none \
|
||||
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6 \
|
||||
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
|
||||
|
@ -37,7 +37,7 @@ XDG_CONFIG_HOME=/tmp/lib/domain--1-TPM-VM/.config \
|
||||
-device spapr-vty,chardev=charserial1,id=serial1,reg=805310464 \
|
||||
-tpmdev emulator,id=tpm-tpm0,chardev=chrtpm \
|
||||
-chardev socket,id=chrtpm,path=/dev/test \
|
||||
-device tpm-spapr,tpmdev=tpm-tpm0,id=tpm0,reg=0x00005000 \
|
||||
-device tpm-spapr,tpmdev=tpm-tpm0,id=tpm0,reg=20480 \
|
||||
-audiodev id=audio1,driver=none \
|
||||
-global spapr-nvram.reg=0x4000 \
|
||||
-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \
|
||||
|
Loading…
Reference in New Issue
Block a user