Signed-off-by: Luke Yue <lukedyue(a)gmail.com>
---
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 01ecb4e30e..2461d977a3 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -910,3 +910,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 e7fbd70d7b..51dc109c38 100644
--- a/src/hypervisor/domain_driver.h
+++ b/src/hypervisor/domain_driver.h
@@ -111,3 +111,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 68cc9c51cb..cfda58320a 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1565,6 +1565,7 @@ virDomainDriverDetachRedirdevDeviceConfig;
virDomainDriverDetachRNGDeviceConfig;
virDomainDriverDetachShmemDeviceConfig;
virDomainDriverDetachSoundDeviceConfig;
+virDomainDriverDetachTPMDeviceConfig;
virDomainDriverDetachVsockDeviceConfig;
virDomainDriverDetachWatchdogDeviceConfig;
virDomainDriverGenerateMachineName;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b1ca6a7b97..15b4332769 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10149,6 +10149,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:
@@ -10156,7 +10162,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.1