On Wed, Oct 06, 2021 at 09:15:21 +0200, Ján Tomko wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1897708
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/qemu/qemu_driver.c | 9 +++-
src/qemu/qemu_hotplug.c | 96 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+), 1 deletion(-)
[...]
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 22239b2689..f5dad0b829 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
[...]
@@ -3396,6 +3397,101 @@ qemuDomainAttachVsockDevice(virQEMUDriver
*driver,
}
+int
+qemuDomainAttachFSDevice(virQEMUDriver *driver,
+ virDomainObj *vm,
+ virDomainFSDef *fs)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_FS,
+ { .fs = fs } };
+ g_autoptr(virDomainChrSourceDef) chardev = NULL;
+ virErrorPtr origErr = NULL;
+ bool releaseaddr = false;
+ bool chardevAdded = false;
+ bool started = false;
+ g_autofree char *devstr = NULL;
+ g_autofree char *charAlias = NULL;
+ int ret = -1;
+
+ if (fs->fsdriver != VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) {
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+ _("only virtiofs filesystems can be hotplugged"));
+ return -1;
+ }
+
+ if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0)
+ return -1;
+
+ if (qemuAssignDeviceFSAlias(vm->def, fs) < 0)
+ goto cleanup;
+
+ chardev = qemuDomainGetVHostUserChrSourceDef(priv, fs);
+ charAlias = qemuDomainGetVhostUserChrAlias(fs->info.alias);
+
+ if (!(devstr = qemuBuildVHostUserFsDevStr(fs, vm->def, charAlias, priv)))
+ goto cleanup;
+
+ if (!fs->sock) {
+ if (qemuVirtioFSPrepareDomain(driver, fs) < 0)
+ goto cleanup;
+
+ if (qemuVirtioFSStart(qemuDomainLogContextGetManager(priv->logCtxt), driver,
vm, fs) < 0)
+ goto cleanup;
+ started = true;
As noted, this won't work after restart of libvirtd.
+
+ if (qemuVirtioFSSetupCgroup(vm, fs, priv->cgroup) < 0)
+ goto cleanup;
+ }
+
+ qemuDomainObjEnterMonitor(driver, vm);
+
+ if (qemuMonitorAttachCharDev(priv->mon, charAlias, chardev) < 0)
+ goto exit_monitor;
+ chardevAdded = true;
+
+ if (qemuDomainAttachExtensionDevice(priv->mon, &fs->info) < 0)
+ goto exit_monitor;
+
+ if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
+ ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &fs->info));
+ goto exit_monitor;
+ }
+
+ if (qemuDomainObjExitMonitor(driver, vm) < 0) {
+ releaseaddr = false;
+ goto cleanup;
+ }
+
+ VIR_APPEND_ELEMENT(vm->def->fss, vm->def->nfss, fs);
This clears 'fs' ...
+
+ ret = 0;
+
+ audit:
+ virDomainAuditFS(vm, NULL, fs, "attach", ret == 0);
... but you reference it here.
+ cleanup:
+ if (ret < 0) {
+ virErrorPreserveLast(&origErr);
+ if (releaseaddr)
+ qemuDomainReleaseDeviceAddress(vm, &fs->info);
+ if (started)
+ qemuVirtioFSStop(driver, vm, fs);
+ virErrorRestore(&origErr);
+ }
+
+ return ret;
+
+ exit_monitor:
+ virErrorPreserveLast(&origErr);
+ if (chardevAdded)
+ ignore_value(qemuMonitorDetachCharDev(priv->mon, charAlias));
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ releaseaddr = false;
+ virErrorRestore(&origErr);
+ goto audit;
+}