acda74
From 23c8e64cbbd9fe642f47808b19aba6cd5177fdd2 Mon Sep 17 00:00:00 2001
acda74
Message-Id: <23c8e64cbbd9fe642f47808b19aba6cd5177fdd2@dist-git>
acda74
From: Michal Privoznik <mprivozn@redhat.com>
acda74
Date: Thu, 16 Feb 2023 11:46:55 +0100
acda74
Subject: [PATCH] qemu_passt: Let passt write the PID file
acda74
acda74
The way we start passt currently is: we use
acda74
virCommandSetPidFile() to use our virCommand machinery to acquire
acda74
the PID file and leak opened FD into passt. Then, we use
acda74
virPidFile*() APIs to read the PID file (which is needed when
acda74
placing it into CGroups or killing it). But this does not fly
acda74
really because passt daemonizes itself. Thus the process we
acda74
started dies soon and thus the PID file is closed and unlocked.
acda74
acda74
We could work around this by passing '--foreground' argument, but
acda74
that weakens passt as it can't create new PID namespace (because
acda74
it doesn't fork()).
acda74
acda74
The solution is to let passt write the PID file, but since it
acda74
does not lock the file and closes it as soon as it is written, we
acda74
have to switch to those virPidFile APIs which don't expect PID
acda74
file to be locked.
acda74
acda74
Resolves: https://bugzilla.redhat.com/2169244
acda74
acda74
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
acda74
Reviewed-by: Laine Stump <laine@redhat.com>
acda74
(cherry picked from commit 029a892abdb2fe508f3fb77af00a14464b98b824)
acda74
Signed-off-by: Laine Stump <laine@redhat.com>
acda74
---
acda74
 src/qemu/qemu_passt.c | 11 +++++++----
acda74
 1 file changed, 7 insertions(+), 4 deletions(-)
acda74
acda74
diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c
acda74
index 2733f8e03f..1217a6a087 100644
acda74
--- a/src/qemu/qemu_passt.c
acda74
+++ b/src/qemu/qemu_passt.c
acda74
@@ -72,7 +72,7 @@ qemuPasstGetPid(virDomainObj *vm,
acda74
 {
acda74
     g_autofree char *pidfile = qemuPasstCreatePidFilename(vm, net);
acda74
 
acda74
-    return virPidFileReadPathIfLocked(pidfile, pid);
acda74
+    return virPidFileReadPath(pidfile, pid);
acda74
 }
acda74
 
acda74
 
acda74
@@ -106,11 +106,14 @@ static void
acda74
 qemuPasstKill(const char *pidfile)
acda74
 {
acda74
     virErrorPtr orig_err;
acda74
+    pid_t pid = 0;
acda74
 
acda74
     virErrorPreserveLast(&orig_err);
acda74
 
acda74
-    if (virPidFileForceCleanupPath(pidfile) < 0)
acda74
-        VIR_WARN("Unable to kill passt process");
acda74
+    ignore_value(virPidFileReadPath(pidfile, &pid));
acda74
+    if (pid != 0)
acda74
+        virProcessKillPainfully(pid, true);
acda74
+    unlink(pidfile);
acda74
 
acda74
     virErrorRestore(&orig_err);
acda74
 }
acda74
@@ -161,13 +164,13 @@ qemuPasstStart(virDomainObj *vm,
acda74
     cmd = virCommandNew(PASST);
acda74
 
acda74
     virCommandClearCaps(cmd);
acda74
-    virCommandSetPidFile(cmd, pidfile);
acda74
     virCommandSetErrorBuffer(cmd, &errbuf);
acda74
 
acda74
     virCommandAddArgList(cmd,
acda74
                          "--one-off",
acda74
                          "--socket", passtSocketName,
acda74
                          "--mac-addr", virMacAddrFormat(&net->mac, macaddr),
acda74
+                         "--pid", pidfile,
acda74
                          NULL);
acda74
 
acda74
     if (net->mtu) {
acda74
-- 
acda74
2.39.2
acda74