Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx> --- src/hypervisor/domain_driver.c | 18 ++++++++++++++++++ src/hypervisor/domain_driver.h | 3 +++ src/libvirt_private.syms | 1 + src/test/test_driver.c | 7 ++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 04c12dff5b..93754ae08a 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -779,3 +779,21 @@ virDomainDriverDetachVsockDeviceConfig(virDomainDef *vmdef, return 0; } + + +int +virDomainDriverDetachTPMDeviceConfig(virDomainDef *vmdef, + virDomainDeviceDef *dev) +{ + int idx; + + if ((idx = virDomainTPMDefFind(vmdef, dev->data.tpm)) < 0) { + virReportError(VIR_ERR_DEVICE_MISSING, "%s", + _("matching tpm device not found")); + return -1; + } + + virDomainTPMDefFree(virDomainTPMDefRemove(vmdef, idx)); + + return 0; +} diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index 9c089f17cc..6cb9defb58 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -101,3 +101,6 @@ int virDomainDriverDetachInputDeviceConfig(virDomainDef *vmdef, int virDomainDriverDetachVsockDeviceConfig(virDomainDef *vmdef, virDomainDeviceDef *dev); + +int virDomainDriverDetachTPMDeviceConfig(virDomainDef *vmdef, + virDomainDeviceDef *dev); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index f7f3726443..349cce2f00 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1548,6 +1548,7 @@ virDomainDriverDetachRedirdevDeviceConfig; virDomainDriverDetachRNGDeviceConfig; virDomainDriverDetachShmemDeviceConfig; virDomainDriverDetachSoundDeviceConfig; +virDomainDriverDetachTPMDeviceConfig; virDomainDriverDetachVsockDeviceConfig; virDomainDriverDetachWatchdogDeviceConfig; virDomainDriverGenerateMachineName; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index c6aead09c9..c12a76749c 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -9635,6 +9635,12 @@ testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef, virDomainChrDefFree(chr); break; + case VIR_DOMAIN_DEVICE_TPM: + if (virDomainDriverDetachTPMDeviceConfig(vmdef, dev) < 0) + return -1; + + break; + case VIR_DOMAIN_DEVICE_VIDEO: case VIR_DOMAIN_DEVICE_GRAPHICS: case VIR_DOMAIN_DEVICE_HUB: @@ -9642,7 +9648,6 @@ testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef, case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_NONE: - case VIR_DOMAIN_DEVICE_TPM: case VIR_DOMAIN_DEVICE_PANIC: case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_AUDIO: -- 2.33.0