From nobody Sat May 4 01:13:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675898003; cv=none; d=zohomail.com; s=zohoarc; b=OQNCvojs9H41ZhjlOnm7tUnTjrd0n6jzln1JMAeWP3jAhK6e0W0GBQnaO9eMH/SekxUinfvahjKY3cCFXyOpa49lOjuIrN208nISMeEKY+u1Z5L82AW9WQmG+N1GsPX8E5qgaGroXykRKMTe2OkbdznDJzYeOikdSw1mVyofHjg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675898003; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=bCDxixUJW7uGqXzoZTeLnRukttBt4wF9G3xOSqqURXE=; b=NFzQQcPJkugZyc0hoO2vcZwS/zkYbrSpsNN3FklfmasVguzy1TO1KJ2Df5AiR2wfmUalbXMbUkCXlsRqvx6mfd/5J0IRzqpv/uxTQlHf9YKlQ1N7DKssqfNlienAH8gYFRA/MuRR/bOR5jysMV5eDQOzUIleU8gq6bVdkn8e0jM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 167589800398239.79770843903111; Wed, 8 Feb 2023 15:13:23 -0800 (PST) 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-460-TOePc9lePFaCz46ZwMZU6A-1; Wed, 08 Feb 2023 18:13:16 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7DD2B101CC60; Wed, 8 Feb 2023 23:13:14 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1211C15BA0; Wed, 8 Feb 2023 23:13:12 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 9FB1B194658D; Wed, 8 Feb 2023 23:13:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 95362194658D for ; Wed, 8 Feb 2023 23:13:11 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 83EFD2026D68; Wed, 8 Feb 2023 23:13:11 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.17.81]) by smtp.corp.redhat.com (Postfix) with ESMTP id 120002026D4B; Wed, 8 Feb 2023 23:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675898003; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bCDxixUJW7uGqXzoZTeLnRukttBt4wF9G3xOSqqURXE=; b=Av2V3DzJfpcPxsmx41U8Rs42GsH1Tw1R5rv1dJ1Ho7zeM5TS1/2s1fzolSAhWV06skOqba x7z2ovc3CQiaj3dg+vYbjjn9/wI7O9XwK/xuMrJpHnAqojDCh8trvvw1EHvItLLxVWXvd3 J07Ep+yesvexLDZmkzrjARU4gKTdYKE= X-MC-Unique: TOePc9lePFaCz46ZwMZU6A-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH] qemu: allow passt to self-daemonize Date: Wed, 8 Feb 2023 18:13:10 -0500 Message-Id: <20230208231310.1728051-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: passt-dev@passt.top Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675898004240100001 Content-Type: text/plain; charset="utf-8"; x-default="true" I initially had the passt process being started in an identical fashion to the slirp-helper - libvirt was daemonizing the new process and recording its pid in a pidfile. The problem with this is that, since it is daemonized immediately, any startup error in passt happens after the daemonization, and thus isn't seen by libvirt - libvirt believes that the process has started successfully and continues on its merry way. The result was that sometimes a guest would be started, but there would be no passt process for qemu to use for network traffic. Instead, we should be starting passt in the same manner we start dnsmasq - we just exec it as normal (along with a request that passt create the pidfile, which is just another option on the passt commandline) and wait for the child process to exit; passt then has a chance to parse its commandline and complete all the setup prior to daemonizing itself; if it encounters an error and exits with a non-0 code, libvirt will see the code and know about the failure. We can then grab the output from stderr, log that so the "user" has some idea of what went wrong, and then fail the guest startup. Signed-off-by: Laine Stump Reviewed-by: Martin Kletzander Reviewed-by: Peter Krempa --- src/qemu/qemu_passt.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c index 0f09bf3db8..f640a69c00 100644 --- a/src/qemu/qemu_passt.c +++ b/src/qemu/qemu_passt.c @@ -141,24 +141,23 @@ qemuPasstStart(virDomainObj *vm, g_autofree char *passtSocketName =3D qemuPasstCreateSocketPath(vm, net= ); g_autoptr(virCommand) cmd =3D NULL; g_autofree char *pidfile =3D qemuPasstCreatePidFilename(vm, net); + g_autofree char *errbuf =3D NULL; char macaddr[VIR_MAC_STRING_BUFLEN]; size_t i; pid_t pid =3D (pid_t) -1; int exitstatus =3D 0; int cmdret =3D 0; - VIR_AUTOCLOSE errfd =3D -1; =20 cmd =3D virCommandNew(PASST); =20 virCommandClearCaps(cmd); - virCommandSetPidFile(cmd, pidfile); - virCommandSetErrorFD(cmd, &errfd); - virCommandDaemonize(cmd); + virCommandSetErrorBuffer(cmd, &errbuf); =20 virCommandAddArgList(cmd, "--one-off", "--socket", passtSocketName, "--mac-addr", virMacAddrFormat(&net->mac, macaddr= ), + "--pid", pidfile, NULL); =20 if (net->mtu) { @@ -264,7 +263,7 @@ qemuPasstStart(virDomainObj *vm, =20 if (cmdret < 0 || exitstatus !=3D 0) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not start 'passt'. exitstatus: %d"), exits= tatus); + _("Could not start 'passt': %s"), errbuf); goto error; } =20 --=20 2.39.1