Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
src/qemu/qemu_driver.c | 6 ++--
src/qemu/qemu_hotplug.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++-
src/qemu/qemu_hotplug.h | 3 ++
3 files changed, 102 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b5a0be0..7c585a3 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -7887,6 +7887,9 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_MEMORY:
ret = qemuDomainDetachMemoryDevice(driver, vm, dev->data.memory);
break;
+ case VIR_DOMAIN_DEVICE_SHMEM:
+ ret = qemuDomainDetachShmemDevice(driver, vm, dev->data.shmem);
+ break;
case VIR_DOMAIN_DEVICE_FS:
case VIR_DOMAIN_DEVICE_INPUT:
@@ -7898,7 +7901,6 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
case VIR_DOMAIN_DEVICE_SMARTCARD:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
- case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_REDIRDEV:
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_TPM:
@@ -8315,7 +8317,7 @@ qemuDomainDetachDeviceConfig(virDomainDefPtr vmdef,
case VIR_DOMAIN_DEVICE_SHMEM:
if ((idx = virDomainShmemFind(vmdef, dev->data.shmem)) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
- _("no matching share memory device was found"));
+ _("no matching shared memory device was found"));
return -1;
}
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 188807e..0f996c3 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -3298,6 +3298,47 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
}
+static int
+qemuDomainRemoveShmemDevice(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainShmemDefPtr shmem)
+{
+ virObjectEventPtr event;
+ char *charAlias = NULL;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ ssize_t idx;
+ int rc = 0;
+
+ VIR_DEBUG("Removing shared memory device %s from domain %p %s",
+ shmem->info.alias, vm, vm->def->name);
+
+ if (shmem->server.enabled) {
+ if (virAsprintf(&charAlias, "char%s", shmem->info.alias) <
0)
+ return -1;
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ rc = qemuMonitorDetachCharDev(priv->mon, charAlias);
+ VIR_FREE(charAlias);
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ return -1;
+ }
+
+ virDomainAuditShmem(vm, shmem, NULL, "detach", rc == 0);
+
+ if (rc < 0)
+ return -1;
+
+ if ((event = virDomainEventDeviceRemovedNewFromObj(vm, shmem->info.alias)))
+ qemuDomainEventQueue(driver, event);
+
+ if ((idx = virDomainShmemFind(vm->def, shmem)) >= 0)
+ virDomainShmemRemove(vm->def, idx);
+ qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL);
+ virDomainShmemDefFree(shmem);
+ return 0;
+}
+
+
int
qemuDomainRemoveDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
@@ -3329,6 +3370,10 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
ret = qemuDomainRemoveMemoryDevice(driver, vm, dev->data.memory);
break;
+ case VIR_DOMAIN_DEVICE_SHMEM:
+ ret = qemuDomainRemoveShmemDevice(driver, vm, dev->data.shmem);
+ break;
+
case VIR_DOMAIN_DEVICE_NONE:
case VIR_DOMAIN_DEVICE_LEASE:
case VIR_DOMAIN_DEVICE_FS:
@@ -3342,7 +3387,6 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
case VIR_DOMAIN_DEVICE_SMARTCARD:
case VIR_DOMAIN_DEVICE_MEMBALLOON:
case VIR_DOMAIN_DEVICE_NVRAM:
- case VIR_DOMAIN_DEVICE_SHMEM:
case VIR_DOMAIN_DEVICE_TPM:
case VIR_DOMAIN_DEVICE_PANIC:
case VIR_DOMAIN_DEVICE_LAST:
@@ -4335,3 +4379,53 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
qemuDomainResetDeviceRemoval(vm);
return ret;
}
+
+
+int
+qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainShmemDefPtr shmem)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ ssize_t idx;
+ virDomainShmemDefPtr tmpshmem;
+ int rc;
+ int ret = -1;
+
+ if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("qemu does not support -device"));
+ return -1;
+ }
+
+ if ((idx = virDomainShmemFind(vm->def, shmem)) < 0) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("device not present in domain configuration"));
+ return -1;
+ }
+
+ tmpshmem = vm->def->shmems[idx];
+
+ if (!tmpshmem->info.alias) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("alias not set for shared memory device"));
+ return -1;
+ }
+
+ qemuDomainMarkDeviceForRemoval(vm, &tmpshmem->info);
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ rc = qemuMonitorDelDevice(priv->mon, tmpshmem->info.alias);
+ if (qemuDomainObjExitMonitor(driver, vm) || rc < 0)
+ goto cleanup;
+
+ rc = qemuDomainWaitForDeviceRemoval(vm);
+ if (rc == 0 || rc == 1)
+ ret = qemuDomainRemoveShmemDevice(driver, vm, tmpshmem);
+ else
+ ret = 0;
+
+ cleanup:
+ qemuDomainResetDeviceRemoval(vm);
+ return ret;
+}
diff --git a/src/qemu/qemu_hotplug.h b/src/qemu/qemu_hotplug.h
index 60137a6..1b18e8a 100644
--- a/src/qemu/qemu_hotplug.h
+++ b/src/qemu/qemu_hotplug.h
@@ -112,6 +112,9 @@ int qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
int qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainShmemDefPtr shmem);
+int qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
+ virDomainObjPtr vm,
+ virDomainShmemDefPtr shmem);
int
qemuDomainChrInsert(virDomainDefPtr vmdef,
--
1.8.3.1