a41c76
From 6c6f1a32c07941d6fe6208e1ad12dc137dbe7c41 Mon Sep 17 00:00:00 2001
a41c76
Message-Id: <6c6f1a32c07941d6fe6208e1ad12dc137dbe7c41@dist-git>
a41c76
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
a41c76
Date: Wed, 4 Mar 2020 12:42:47 +0100
a41c76
Subject: [PATCH] qemu: put virtiofsd in the emulator cgroup
a41c76
MIME-Version: 1.0
a41c76
Content-Type: text/plain; charset=UTF-8
a41c76
Content-Transfer-Encoding: 8bit
a41c76
a41c76
Wire up the code to put virtiofsd in the emulator cgroup on domain
a41c76
startup.
a41c76
a41c76
Signed-off-by: Ján Tomko <jtomko@redhat.com>
a41c76
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
a41c76
Tested-by: Andrea Bolognani <abologna@redhat.com>
a41c76
(cherry picked from commit 9de5d69c218faa0e25c5d6a56ab5f6bacbd1a132)
a41c76
Signed-off-by: Ján Tomko <jtomko@redhat.com>
a41c76
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
a41c76
Message-Id: <7653ce933656c9a13c9afa2a019ef11fb192bdc4.1583322091.git.jtomko@redhat.com>
a41c76
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
a41c76
---
a41c76
 src/qemu/qemu_extdevice.c | 15 +++++++++++++++
a41c76
 src/qemu/qemu_virtiofs.c  | 26 ++++++++++++++++++++++++++
a41c76
 src/qemu/qemu_virtiofs.h  |  5 +++++
a41c76
 3 files changed, 46 insertions(+)
a41c76
a41c76
diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
a41c76
index bfa770f45a..f66bafb62f 100644
a41c76
--- a/src/qemu/qemu_extdevice.c
a41c76
+++ b/src/qemu/qemu_extdevice.c
a41c76
@@ -248,6 +248,13 @@ qemuExtDevicesHasDevice(virDomainDefPtr def)
a41c76
     if (def->tpm && def->tpm->type == VIR_DOMAIN_TPM_TYPE_EMULATOR)
a41c76
         return true;
a41c76
 
a41c76
+    for (i = 0; i < def->nfss; i++) {
a41c76
+        virDomainFSDefPtr fs = def->fss[i];
a41c76
+
a41c76
+        if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS)
a41c76
+            return true;
a41c76
+    }
a41c76
+
a41c76
     return false;
a41c76
 }
a41c76
 
a41c76
@@ -272,5 +279,13 @@ qemuExtDevicesSetupCgroup(virQEMUDriverPtr driver,
a41c76
         qemuExtTPMSetupCgroup(driver, def, cgroup) < 0)
a41c76
         return -1;
a41c76
 
a41c76
+    for (i = 0; i < def->nfss; i++) {
a41c76
+        virDomainFSDefPtr fs = def->fss[i];
a41c76
+
a41c76
+        if (fs->fsdriver == VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS &&
a41c76
+            qemuVirtioFSSetupCgroup(vm, fs, cgroup) < 0)
a41c76
+            return -1;
a41c76
+    }
a41c76
+
a41c76
     return 0;
a41c76
 }
a41c76
diff --git a/src/qemu/qemu_virtiofs.c b/src/qemu/qemu_virtiofs.c
a41c76
index 09ab2cef27..194855ece8 100644
a41c76
--- a/src/qemu/qemu_virtiofs.c
a41c76
+++ b/src/qemu/qemu_virtiofs.c
a41c76
@@ -299,3 +299,29 @@ qemuVirtioFSStop(virQEMUDriverPtr driver G_GNUC_UNUSED,
a41c76
  cleanup:
a41c76
     virErrorRestore(&orig_err);
a41c76
 }
a41c76
+
a41c76
+
a41c76
+int
a41c76
+qemuVirtioFSSetupCgroup(virDomainObjPtr vm,
a41c76
+                        virDomainFSDefPtr fs,
a41c76
+                        virCgroupPtr cgroup)
a41c76
+{
a41c76
+    g_autofree char *pidfile = NULL;
a41c76
+    pid_t pid = -1;
a41c76
+    int rc;
a41c76
+
a41c76
+    if (!(pidfile = qemuVirtioFSCreatePidFilename(vm, fs->info.alias)))
a41c76
+        return -1;
a41c76
+
a41c76
+    rc = virPidFileReadPathIfAlive(pidfile, &pid, NULL);
a41c76
+    if (rc < 0 || pid == (pid_t) -1) {
a41c76
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
a41c76
+                       _("virtiofsd died unexpectedly"));
a41c76
+        return -1;
a41c76
+    }
a41c76
+
a41c76
+    if (virCgroupAddProcess(cgroup, pid) < 0)
a41c76
+        return -1;
a41c76
+
a41c76
+    return 0;
a41c76
+}
a41c76
diff --git a/src/qemu/qemu_virtiofs.h b/src/qemu/qemu_virtiofs.h
a41c76
index b2f0c57d0c..1db59917c6 100644
a41c76
--- a/src/qemu/qemu_virtiofs.h
a41c76
+++ b/src/qemu/qemu_virtiofs.h
a41c76
@@ -35,3 +35,8 @@ void
a41c76
 qemuVirtioFSStop(virQEMUDriverPtr driver,
a41c76
                  virDomainObjPtr vm,
a41c76
                  virDomainFSDefPtr fs);
a41c76
+
a41c76
+int
a41c76
+qemuVirtioFSSetupCgroup(virDomainObjPtr vm,
a41c76
+                        virDomainFSDefPtr fs,
a41c76
+                        virCgroupPtr cgroup);
a41c76
-- 
a41c76
2.25.1
a41c76