From: Marc-André Lureau <marcandre.lureau(a)redhat.com>
The slirp helper process should be associated with the VM cgroup, like
other helpers.
Signed-off-by: Marc-André Lureau <marcandre.lureau(a)redhat.com>
---
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.rc2.42.g98cedd0233