As the memballoon device shouldn't be hot-(un)pluggable, so error if try
to remove it on a running domain, for removing from config, it's fine.
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 | 19 ++++++++++++++++---
4 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c
index 2461d977a3..0a0ff7b361 100644
--- a/src/hypervisor/domain_driver.c
+++ b/src/hypervisor/domain_driver.c
@@ -928,3 +928,21 @@ virDomainDriverDetachTPMDeviceConfig(virDomainDef *vmdef,
return 0;
}
+
+
+int
+virDomainDriverDetachMemballoonDeviceConfig(virDomainDef *vmdef,
+ virDomainDeviceDef *dev)
+{
+ if (!vmdef->memballoon ||
+ !virDomainMemballoonDefEquals(dev->data.memballoon,
+ vmdef->memballoon)) {
+ virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+ _("matching memballoon device not found"));
+ return -1;
+ }
+ virDomainMemballoonDefFree(vmdef->memballoon);
+ vmdef->memballoon = NULL;
+
+ return 0;
+}
diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h
index 51dc109c38..5920854b13 100644
--- a/src/hypervisor/domain_driver.h
+++ b/src/hypervisor/domain_driver.h
@@ -114,3 +114,6 @@ int virDomainDriverDetachVsockDeviceConfig(virDomainDef *vmdef,
int virDomainDriverDetachTPMDeviceConfig(virDomainDef *vmdef,
virDomainDeviceDef *dev);
+
+int virDomainDriverDetachMemballoonDeviceConfig(virDomainDef *vmdef,
+ virDomainDeviceDef *dev);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index b143537bb4..19cc301a20 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1560,6 +1560,7 @@ virDomainDriverDetachFSDeviceConfig;
virDomainDriverDetachHostdevDeviceConfig;
virDomainDriverDetachInputDeviceConfig;
virDomainDriverDetachLeaseDeviceConfig;
+virDomainDriverDetachMemballoonDeviceConfig;
virDomainDriverDetachMemoryDeviceConfig;
virDomainDriverDetachNetDeviceConfig;
virDomainDriverDetachRedirdevDeviceConfig;
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 15b4332769..317aa0181b 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10053,7 +10053,8 @@ testConnectGetAllDomainStats(virConnectPtr conn,
static int
testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef,
- virDomainDeviceDef *dev)
+ virDomainDeviceDef *dev,
+ unsigned int flags)
{
virDomainChrDef *chr;
@@ -10155,11 +10156,23 @@ testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef,
break;
+ case VIR_DOMAIN_DEVICE_MEMBALLOON:
+ if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("detach of device '%s' on running domain
"
+ "is not supported"),
+ virDomainDeviceTypeToString(dev->type));
+ return -1;
+ } else {
+ if (virDomainDriverDetachMemballoonDeviceConfig(vmdef, dev) < 0)
+ return -1;
+ }
+ break;
+
case VIR_DOMAIN_DEVICE_VIDEO:
case VIR_DOMAIN_DEVICE_GRAPHICS:
case VIR_DOMAIN_DEVICE_HUB:
case VIR_DOMAIN_DEVICE_SMARTCARD:
- case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_PANIC:
@@ -10225,7 +10238,7 @@ testDomainChgDevice(virDomainPtr dom,
break;
case VIR_DOMAIN_DEVICE_ACTION_DETACH:
- if (testDomainDetachDeviceLiveAndConfig(def, dev) < 0)
+ if (testDomainDetachDeviceLiveAndConfig(def, dev, flags) < 0)
goto cleanup;
break;
--
2.33.1