[libvirt] [PATCH v4 6/6] qemu: Add support for hot/cold-(un)plug of shmem devices
Peter Krempa
pkrempa at redhat.com
Wed Nov 2 15:17:33 UTC 2016
On Wed, Oct 26, 2016 at 12:51:37 +0200, Martin Kletzander wrote:
> This is needed in order to migrate a domain with shmem devices as that
> is not allowed to migrate.
>
> Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
> ---
> src/qemu/qemu_driver.c | 39 +++-
> src/qemu/qemu_hotplug.c | 248 ++++++++++++++++++++-
> src/qemu/qemu_hotplug.h | 6 +
> tests/qemuhotplugtest.c | 21 ++
> .../qemuhotplug-ivshmem-doorbell-detach.xml | 7 +
> .../qemuhotplug-ivshmem-doorbell.xml | 4 +
> .../qemuhotplug-ivshmem-plain-detach.xml | 6 +
> .../qemuhotplug-ivshmem-plain.xml | 3 +
> ...muhotplug-base-live+ivshmem-doorbell-detach.xml | 1 +
> .../qemuhotplug-base-live+ivshmem-doorbell.xml | 65 ++++++
> .../qemuhotplug-base-live+ivshmem-plain-detach.xml | 1 +
> .../qemuhotplug-base-live+ivshmem-plain.xml | 58 +++++
> 12 files changed, 454 insertions(+), 5 deletions(-)
> create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell-detach.xml
> create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-doorbell.xml
> create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain-detach.xml
> create mode 100644 tests/qemuhotplugtestdevices/qemuhotplug-ivshmem-plain.xml
> create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell-detach.xml
> create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-doorbell.xml
> create mode 120000 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain-detach.xml
> create mode 100644 tests/qemuhotplugtestdomains/qemuhotplug-base-live+ivshmem-plain.xml
>
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index bacabd2d348f..c164c390eccf 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -7601,6 +7601,15 @@ qemuDomainAttachDeviceLive(virDomainObjPtr vm,
> dev->data.memory = NULL;
> break;
>
> + case VIR_DOMAIN_DEVICE_SHMEM:
> + ret = qemuDomainAttachShmemDevice(driver, vm,
> + dev->data.shmem);
> + if (!ret) {
Change the condition to something more orthodox, like "< 0".
> + alias = dev->data.shmem->info.alias;
> + dev->data.shmem = NULL;
> + }
> + break;
> +
> case VIR_DOMAIN_DEVICE_NONE:
> case VIR_DOMAIN_DEVICE_FS:
> case VIR_DOMAIN_DEVICE_INPUT:
[...]
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index 7a21dc67f533..10236a0bccd9 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
[...]
> @@ -4271,6 +4455,68 @@ int qemuDomainDetachHostDevice(virQEMUDriverPtr driver,
> return qemuDomainDetachThisHostDevice(driver, vm, detach);
> }
>
> +
> +int
> +qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
> + virDomainObjPtr vm,
> + virDomainShmemDefPtr dev)
> +{
> + int ret = -1;
> + ssize_t idx = -1;
> + virErrorPtr orig_err = NULL;
> + virDomainShmemDefPtr shmem = NULL;
> + qemuDomainObjPrivatePtr priv = vm->privateData;
> +
> + if ((idx = virDomainShmemDefFind(vm->def, dev)) < 0) {
> + virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> + _("device not present in domain configuration"));
> + return -1;
> + }
> +
> + shmem = vm->def->shmems[idx];
> +
> + switch ((virDomainShmemModel)shmem->model) {
> + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_PLAIN:
> + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL:
> + break;
> +
> + case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM:
> + virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
> + _("live detach of shmem model '%s' is not supported"),
> + virDomainShmemModelTypeToString(shmem->model));
> + /* fall-through */
> + case VIR_DOMAIN_SHMEM_MODEL_LAST:
> + return -1;
> + }
> +
> + qemuDomainMarkDeviceForRemoval(vm, &shmem->info);
> + qemuDomainObjEnterMonitor(driver, vm);
> +
> + ret = qemuMonitorDelDevice(priv->mon, shmem->info.alias);
> +
> + if (ret < 0)
> + orig_err = virSaveLastError();
Is this necessary? The only place where it would be overwritten is ...
> +
> + if (qemuDomainObjExitMonitor(driver, vm) < 0)
... here and only if qemu crashes at this point.
> + ret = -1;
> +
> + if (ret == 0) {
> + if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) {
> + qemuDomainReleaseDeviceAddress(vm, &shmem->info, NULL);
> + ret = qemuDomainRemoveShmemDevice(driver, vm, shmem);
> + }
> + }
> + qemuDomainResetDeviceRemoval(vm);
> +
> + if (orig_err) {
> + virSetError(orig_err);
> + virFreeError(orig_err);
> + }
ACK
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20161102/49cf02ba/attachment-0001.sig>
More information about the libvir-list
mailing list