Wire up the code to put virtiofsd in the emulator cgroup on domain
startup.
Signed-off-by: Ján Tomko <jtomko(a)redhat.com>
---
src/qemu/qemu_extdevice.c | 15 +++++++++++++++
src/qemu/qemu_virtiofs.c | 28 ++++++++++++++++++++++++++++
src/qemu/qemu_virtiofs.h | 6 ++++++
3 files changed, 49 insertions(+)
diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index 5103d4921c..31655b7f0a 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -248,6 +248,13 @@ qemuExtDevicesHasDevice(virDomainDefPtr def)
if (def->tpm && def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
return true;
+ for (i = 0; i < def->nfss; i++) {
+ virDomainFSDefPtr fs = def->fss[i];
+
+ if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS)
+ return true;
+ }
+
return false;
}
@@ -271,5 +278,13 @@ qemuExtDevicesSetupCgroup(virQEMUDriverPtr driver,
qemuExtTPMSetupCgroup(driver, def, cgroup) < 0)
return -1;
+ for (i = 0; i < def->nfss; i++) {
+ virDomainFSDefPtr fs = def->fss[i];
+
+ if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS &&
+ qemuVirtioFSSetupCgroup(driver, def, fs, cgroup) < 0)
+ return -1;
+ }
+
return 0;
}
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
index 600a3644bd..9e354a30c6 100644
--- a/src/qemu/qemu_virtiofs.c
+++ b/src/qemu/qemu_virtiofs.c
@@ -298,3 +298,31 @@ qemuVirtioFSStop(virQEMUDriverPtr driver,
cleanup:
virErrorRestore(&orig_err);
}
+
+
+int
+qemuVirtioFSSetupCgroup(virQEMUDriverPtr driver,
+ virDomainDefPtr def,
+ virDomainFSDefPtr fs,
+ virCgroupPtr cgroup)
+{
+ g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+ g_autofree char *pidfile = NULL;
+ pid_t pid = -1;
+ int rc;
+
+ if (!(pidfile = qemuVirtioFSCreatePidFilename(cfg, def, fs->info.alias)))
+ return -1;
+
+ rc = virPidFileReadPathIfAlive(pidfile, &pid, NULL);
+ if (rc < 0 || pid == (pid_t) -1) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("virtiofsd died unexpectedly"));
+ return -1;
+ }
+
+ if (virCgroupAddProcess(cgroup, pid) < 0)
+ return -1;
+
+ return 0;
+}
diff --git a/src/qemu/qemu_virtiofs.h b/src/qemu/qemu_virtiofs.h
index 49db807b19..341fed1def 100644
--- a/src/qemu/qemu_virtiofs.h
+++ b/src/qemu/qemu_virtiofs.h
@@ -36,3 +36,9 @@ void
qemuVirtioFSStop(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainFSDefPtr fs);
+
+int
+qemuVirtioFSSetupCgroup(virQEMUDriverPtr driver,
+ virDomainDefPtr def,
+ virDomainFSDefPtr fs,
+ virCgroupPtr cgroup);
--
2.24.1