[libvirt PATCH 16/16] qemu: implement virtiofs hotunplug
Peter Krempa
pkrempa at redhat.com
Wed Oct 6 09:03:31 UTC 2021
On Wed, Oct 06, 2021 at 09:15:22 +0200, Ján Tomko wrote:
> Signed-off-by: Ján Tomko <jtomko at redhat.com>
> ---
> src/conf/domain_conf.c | 24 ++++++++++++
> src/conf/domain_conf.h | 2 +
> src/libvirt_private.syms | 1 +
> src/qemu/qemu_hotplug.c | 81 +++++++++++++++++++++++++++++++++++++++-
> 4 files changed, 106 insertions(+), 2 deletions(-)
[...]
> diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
> index f5dad0b829..713da5ebfc 100644
> --- a/src/qemu/qemu_hotplug.c
> +++ b/src/qemu/qemu_hotplug.c
> @@ -5180,6 +5180,45 @@ qemuDomainRemoveRedirdevDevice(virQEMUDriver *driver,
> }
>
>
> +static int
> +qemuDomainRemoveFSDevice(virQEMUDriver *driver,
> + virDomainObj *vm,
> + virDomainFSDef *fs)
> +{
> + g_autofree char *charAlias = NULL;
> + qemuDomainObjPrivate *priv = vm->privateData;
> + ssize_t idx;
> + int rc = 0;
> +
> + VIR_DEBUG("Removing FS device %s from domain %p %s",
> + fs->info.alias, vm, vm->def->name);
> +
> + charAlias = qemuDomainGetVhostUserChrAlias(fs->info.alias);
> +
> + qemuDomainObjEnterMonitor(driver, vm);
> +
> + if (qemuMonitorDetachCharDev(priv->mon, charAlias) < 0)
> + rc = -1;
Note that you must not assume here that the check below [1] that allows
only virtio-fs device unplug guards this code too.
The *Remove* code is executed always when we get a 'DEVICE_DELETED'
event from qemu thus also for guest-initiated unplug, which
theoretically can happen also for p9fs device.
> +
> + if (qemuDomainObjExitMonitor(driver, vm) < 0)
> + return -1;
> +
> + virDomainAuditFS(vm, fs, NULL, "detach", rc == 0);
> +
> + if (rc < 0)
> + return -1;
> +
> + if (!fs->sock)
> + qemuVirtioFSStop(driver, vm, fs);
> +
> + if ((idx = virDomainFSDefFind(vm->def, fs)) >= 0)
> + virDomainFSRemove(vm->def, idx);
> + qemuDomainReleaseDeviceAddress(vm, &fs->info);
> + virDomainFSDefFree(fs);
> + return 0;
> +}
> +
> +
> static void
> qemuDomainRemoveAuditDevice(virDomainObj *vm,
> virDomainDeviceDef *detach,
[...]
> @@ -6020,6 +6066,31 @@ qemuDomainDetachPrepVsock(virDomainObj *vm,
> }
>
>
> +static int
> +qemuDomainDetachPrepFS(virDomainObj *vm,
> + virDomainFSDef *match,
> + virDomainFSDef **detach)
> +{
> + ssize_t idx;
> +
> + if ((idx = virDomainFSDefFind(vm->def, match)) < 0) {
> + virReportError(VIR_ERR_DEVICE_MISSING, "%s",
> + _("matching filesystem not found"));
> + return -1;
> + }
> +
> + if (vm->def->fss[idx]->fsdriver != VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
> + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
> + _("only virtiofs filesystems can be hotplugged"));
> + return -1;
> + }
[1]. This check only guards host-initiated delete.
> +
> + *detach = vm->def->fss[idx];
> +
> + return 0;
> +}
> +
> +
> static int
> qemuDomainDetachDeviceLease(virQEMUDriver *driver,
> virDomainObj *vm,
More information about the libvir-list
mailing list