[libvirt PATCH 2/6] slirp: add helper to VM cgroup

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>

The slirp helper process should be associated with the VM cgroup, like
other helpers.

Signed-off-by: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx>
---
 src/qemu/qemu_extdevice.c |  8 ++++++++
 src/qemu/qemu_slirp.c     | 14 ++++++++++++++
 src/qemu/qemu_slirp.h     |  3 +++
 3 files changed, 25 insertions(+)

diff --git a/src/qemu/qemu_extdevice.c b/src/qemu/qemu_extdevice.c
index 5a31b4d66e..dae3524307 100644
--- a/src/qemu/qemu_extdevice.c
+++ b/src/qemu/qemu_extdevice.c
@@ -284,6 +284,14 @@ qemuExtDevicesSetupCgroup(virQEMUDriverPtr driver,
             return -1;
     }
 
+    for (i = 0; i < def->nnets; i++) {
+        virDomainNetDefPtr net = def->nets[i];
+        qemuSlirpPtr slirp = QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp;
+
+        if (slirp && qemuSlirpSetupCgroup(slirp, cgroup) < 0)
+            return -1;
+    }
+
     if (def->tpm &&
         qemuExtTPMSetupCgroup(driver, def, cgroup) < 0)
         return -1;
diff --git a/src/qemu/qemu_slirp.c b/src/qemu/qemu_slirp.c
index 49bffa01b8..71dbded607 100644
--- a/src/qemu/qemu_slirp.c
+++ b/src/qemu/qemu_slirp.c
@@ -242,6 +242,14 @@ qemuSlirpStop(qemuSlirpPtr slirp,
 }
 
 
+int
+qemuSlirpSetupCgroup(qemuSlirpPtr slirp,
+                     virCgroupPtr cgroup)
+{
+    return virCgroupAddProcess(cgroup, slirp->pid);
+}
+
+
 int
 qemuSlirpStart(qemuSlirpPtr slirp,
                virDomainObjPtr vm,
@@ -249,6 +257,7 @@ qemuSlirpStart(qemuSlirpPtr slirp,
                virDomainNetDefPtr net,
                bool incoming)
 {
+    qemuDomainObjPrivatePtr priv = vm->privateData;
     g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
     g_autoptr(virCommand) cmd = NULL;
     g_autofree char *pidfile = NULL;
@@ -348,6 +357,10 @@ qemuSlirpStart(qemuSlirpPtr slirp,
     }
 
     slirp->pid = pid;
+
+    if (priv->cgroup && qemuSlirpSetupCgroup(slirp, priv->cgroup) < 0)
+        goto error;
+
     return 0;
 
  error:
@@ -355,6 +368,7 @@ qemuSlirpStart(qemuSlirpPtr slirp,
         virProcessKillPainfully(pid, true);
     if (pidfile)
         unlink(pidfile);
+    slirp->pid = 0;
     /* leave dbus daemon running, it may be used by others */
     return -1;
 }
diff --git a/src/qemu/qemu_slirp.h b/src/qemu/qemu_slirp.h
index 5bf9596053..e1db908814 100644
--- a/src/qemu/qemu_slirp.h
+++ b/src/qemu/qemu_slirp.h
@@ -75,4 +75,7 @@ void qemuSlirpStop(qemuSlirpPtr slirp,
 
 int qemuSlirpGetFD(qemuSlirpPtr slirp);
 
+int qemuSlirpSetupCgroup(qemuSlirpPtr slirp,
+                         virCgroupPtr cgroup);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuSlirp, qemuSlirpFree);
-- 
2.26.0.106.g9fadedd637





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux