mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-21 05:29:18 +00:00
qemu: command: move qemuBuildTPMDevStr TPM validation to qemu_domain.c
qemuBuildTPMDevStr() does TPM model validation that can be moved to qemu_domain.c, allowing validation in domain define time. This patch moves it to the existing qemuDomainDeviceDefValidateTPM() function. Reviewed-by: Cole Robinson <crobinso@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
f8b8bacd39
commit
3f86e39f7f
@ -9109,34 +9109,11 @@ qemuBuildDomainLoaderCommandLine(virCommandPtr cmd,
|
|||||||
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
qemuBuildTPMDevStr(const virDomainDef *def,
|
qemuBuildTPMDevStr(const virDomainDef *def)
|
||||||
virQEMUCapsPtr qemuCaps)
|
|
||||||
{
|
{
|
||||||
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
const virDomainTPMDef *tpm = def->tpm;
|
const virDomainTPMDef *tpm = def->tpm;
|
||||||
const char *model = virDomainTPMModelTypeToString(tpm->model);
|
const char *model = virDomainTPMModelTypeToString(tpm->model);
|
||||||
virQEMUCapsFlags flag;
|
|
||||||
|
|
||||||
switch (tpm->model) {
|
|
||||||
case VIR_DOMAIN_TPM_MODEL_TIS:
|
|
||||||
flag = QEMU_CAPS_DEVICE_TPM_TIS;
|
|
||||||
break;
|
|
||||||
case VIR_DOMAIN_TPM_MODEL_CRB:
|
|
||||||
flag = QEMU_CAPS_DEVICE_TPM_CRB;
|
|
||||||
break;
|
|
||||||
case VIR_DOMAIN_TPM_MODEL_LAST:
|
|
||||||
default:
|
|
||||||
virReportEnumRangeError(virDomainTPMModel, tpm->model);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!virQEMUCapsGet(qemuCaps, flag)) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
|
||||||
_("The QEMU executable %s does not support TPM "
|
|
||||||
"model %s"),
|
|
||||||
def->emulator, model);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
|
virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s",
|
||||||
model, tpm->info.alias, tpm->info.alias);
|
model, tpm->info.alias, tpm->info.alias);
|
||||||
@ -9230,8 +9207,7 @@ qemuBuildTPMBackendStr(const virDomainDef *def,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
qemuBuildTPMCommandLine(virCommandPtr cmd,
|
qemuBuildTPMCommandLine(virCommandPtr cmd,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def)
|
||||||
virQEMUCapsPtr qemuCaps)
|
|
||||||
{
|
{
|
||||||
char *optstr;
|
char *optstr;
|
||||||
g_autofree char *chardev = NULL;
|
g_autofree char *chardev = NULL;
|
||||||
@ -9271,7 +9247,7 @@ qemuBuildTPMCommandLine(virCommandPtr cmd,
|
|||||||
VIR_FREE(fdset);
|
VIR_FREE(fdset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(optstr = qemuBuildTPMDevStr(def, qemuCaps)))
|
if (!(optstr = qemuBuildTPMDevStr(def)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virCommandAddArgList(cmd, "-device", optstr, NULL);
|
virCommandAddArgList(cmd, "-device", optstr, NULL);
|
||||||
@ -9995,7 +9971,7 @@ qemuBuildCommandLine(virQEMUDriverPtr driver,
|
|||||||
chardevStdioLogd) < 0)
|
chardevStdioLogd) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildTPMCommandLine(cmd, def, qemuCaps) < 0)
|
if (qemuBuildTPMCommandLine(cmd, def) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
|
if (qemuBuildInputCommandLine(cmd, def, qemuCaps) < 0)
|
||||||
|
@ -7630,6 +7630,8 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
|
|||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps)
|
||||||
{
|
{
|
||||||
|
virQEMUCapsFlags flag;
|
||||||
|
|
||||||
/* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
|
/* TPM 1.2 and 2 are not compatible, so we choose a specific version here */
|
||||||
if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
|
if (tpm->version == VIR_DOMAIN_TPM_VERSION_DEFAULT)
|
||||||
tpm->version = VIR_DOMAIN_TPM_VERSION_1_2;
|
tpm->version = VIR_DOMAIN_TPM_VERSION_1_2;
|
||||||
@ -7666,6 +7668,28 @@ qemuDomainDeviceDefValidateTPM(virDomainTPMDef *tpm,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (tpm->model) {
|
||||||
|
case VIR_DOMAIN_TPM_MODEL_TIS:
|
||||||
|
flag = QEMU_CAPS_DEVICE_TPM_TIS;
|
||||||
|
break;
|
||||||
|
case VIR_DOMAIN_TPM_MODEL_CRB:
|
||||||
|
flag = QEMU_CAPS_DEVICE_TPM_CRB;
|
||||||
|
break;
|
||||||
|
case VIR_DOMAIN_TPM_MODEL_LAST:
|
||||||
|
default:
|
||||||
|
virReportEnumRangeError(virDomainTPMModel, tpm->model);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!virQEMUCapsGet(qemuCaps, flag)) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("The QEMU executable %s does not support TPM "
|
||||||
|
"model %s"),
|
||||||
|
def->emulator,
|
||||||
|
virDomainTPMModelTypeToString(tpm->model));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_support:
|
no_support:
|
||||||
|
Loading…
Reference in New Issue
Block a user