From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id 46C025A0082 for ; Thu, 16 Feb 2023 14:33:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676554380; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J3RjkQnREkQqM0zQ+XPCW+NlJN21CooXEdao/RywWW0=; b=M3zpbUhWA+H9odOTvFisQVPGPCiYuvW7v5ZbKxqE54+lP02uCLZQqaVFU9rCUmKAhNJISa JomrcZbfHUxSEnjuhVFnorOkzBtbkRnDlP0Uk6fh6IAu/Jf9MhekGt/kmNwQtBw09QR6gx RgDnNAYmSBlEN+QSFxNMIv7KBMfboEc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-uC6oultvNLqPny9vfZwtjA-1; Thu, 16 Feb 2023 08:32:58 -0500 X-MC-Unique: uC6oultvNLqPny9vfZwtjA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8FEF08041BF for ; Thu, 16 Feb 2023 13:32:58 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01B472166B31; Thu, 16 Feb 2023 13:32:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 5/5] qemu_passt: Let passt write the PID file Date: Thu, 16 Feb 2023 14:32:52 +0100 Message-Id: <0d438dabe6479dc8f0f159b3afd3f3656b62cec7.1676554196.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-MailFrom: mprivozn@redhat.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: 3B2ZZYUNB6XK2UAJTWKPO53D2TSOADMZ X-Message-ID-Hash: 3B2ZZYUNB6XK2UAJTWKPO53D2TSOADMZ X-Mailman-Approved-At: Thu, 16 Feb 2023 18:44:36 +0100 CC: sbrivio@redhat.com, passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The way we start passt currently is: we use virCommandSetPidFile() to use our virCommand machinery to acquire the PID file and leak opened FD into passt. Then, we use virPidFile*() APIs to read the PID file (which is needed when placing it into CGroups or killing it). But this does not fly really because passt daemonizes itself. Thus the process we started dies soon and thus the PID file is closed and unlocked. We could work around this by passing '--foreground' argument, but that weakens passt as it can't create new PID namespace (because it doesn't fork()). The solution is to let passt write the PID file, but since it does not lock the file and closes it as soon as it is written, we have to switch to those virPidFile APIs which don't expect PID file to be locked. Signed-off-by: Michal Privoznik --- src/qemu/qemu_passt.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c index a4cc9e7166..47f4b5fcae 100644 --- a/src/qemu/qemu_passt.c +++ b/src/qemu/qemu_passt.c @@ -72,7 +72,7 @@ qemuPasstGetPid(virDomainObj *vm, { g_autofree char *pidfile = qemuPasstCreatePidFilename(vm, net); - return virPidFileReadPathIfLocked(pidfile, pid); + return virPidFileReadPath(pidfile, pid); } @@ -106,11 +106,14 @@ static void qemuPasstKill(const char *pidfile) { virErrorPtr orig_err; + pid_t pid = 0; virErrorPreserveLast(&orig_err); - if (virPidFileForceCleanupPath(pidfile) < 0) - VIR_WARN("Unable to kill passt process"); + ignore_value(virPidFileReadPath(pidfile, &pid)); + if (pid != 0) + virProcessKillPainfully(pid, true); + unlink(pidfile); virErrorRestore(&orig_err); } @@ -161,13 +164,13 @@ qemuPasstStart(virDomainObj *vm, cmd = virCommandNew(PASST); virCommandClearCaps(cmd); - virCommandSetPidFile(cmd, pidfile); virCommandSetErrorBuffer(cmd, &errbuf); virCommandAddArgList(cmd, "--one-off", "--socket", passtSocketName, "--mac-addr", virMacAddrFormat(&net->mac, macaddr), + "--pid", pidfile, NULL); if (net->mtu) { -- 2.39.1