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 D54E15A005E
	for <passt-dev@passt.top>; Thu,  9 Feb 2023 11:31:12 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;
	s=mimecast20190719; t=1675938671;
	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=Vur81fNvGyzTA17YWj4lN54RVS9kk8x+nu6niRJ+JNw=;
	b=ExKeKPuNvbEK1hC/0xjWVw6pptUXxWSBffucuCtZymmNlGf14P0pgF3rmsvSf4q2pS6wQW
	H2lMgPDO1OXA3AvnKyAZKDUaRGgpp0jqe5FPv7YMT6cvPhNMgeHPaj2s7XT6VqwspIatDq
	Bh4jp1plKtVFj4nBE2A5C1av0A79OAA=
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-269-F4BEEjS4OH2lyhTHnKkHPw-1; Thu, 09 Feb 2023 05:31:04 -0500
X-MC-Unique: F4BEEjS4OH2lyhTHnKkHPw-1
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 80DBB802C1D
	for <passt-dev@passt.top>; Thu,  9 Feb 2023 10:31:04 +0000 (UTC)
Received: from maya.cloud.tilaa.com (ovpn-208-4.brq.redhat.com [10.40.208.4])
	by smtp.corp.redhat.com (Postfix) with ESMTPS id BAFE9C16022;
	Thu,  9 Feb 2023 10:31:03 +0000 (UTC)
Date: Thu, 9 Feb 2023 11:31:01 +0100
From: Stefano Brivio <sbrivio@redhat.com>
To: Michal =?UTF-8?B?UHLDrXZvem7DrWs=?= <mprivozn@redhat.com>
Subject: Re: [libvirt PATCH] qemu: allow passt to self-daemonize
Message-ID: <20230209113101.057d986c@elisabeth>
In-Reply-To: <41d2c66b-cb07-6e4a-4dd9-615ce46d5497@redhat.com>
References: <20230208231310.1728051-1-laine@redhat.com>
	<41d2c66b-cb07-6e4a-4dd9-615ce46d5497@redhat.com>
Organization: Red Hat
MIME-Version: 1.0
X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8
X-Mimecast-Spam-Score: 0
X-Mimecast-Originator: redhat.com
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Message-ID-Hash: 3QP3DEUTMV5RAFGEAELAKJH4EA5GGVWR
X-Message-ID-Hash: 3QP3DEUTMV5RAFGEAELAKJH4EA5GGVWR
X-MailFrom: sbrivio@redhat.com
X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header
CC: Laine Stump <laine@redhat.com>, libvir-list@redhat.com, passt-dev@passt.top
X-Mailman-Version: 3.3.3
Precedence: list
List-Id: Development discussion and patches for passt <passt-dev.passt.top>
Archived-At: <https://archives.passt.top/passt-dev/20230209113101.057d986c@elisabeth/>
Archived-At: <https://passt.top/hyperkitty/list/passt-dev@passt.top/message/3QP3DEUTMV5RAFGEAELAKJH4EA5GGVWR/>
List-Archive: <https://archives.passt.top/passt-dev/>
List-Archive: <https://passt.top/hyperkitty/list/passt-dev@passt.top/>
List-Help: <mailto:passt-dev-request@passt.top?subject=help>
List-Owner: <mailto:passt-dev-owner@passt.top>
List-Post: <mailto:passt-dev@passt.top>
List-Subscribe: <mailto:passt-dev-join@passt.top>
List-Unsubscribe: <mailto:passt-dev-leave@passt.top>

On Thu, 9 Feb 2023 09:52:00 +0100
Michal Pr=C3=ADvozn=C3=ADk <mprivozn@redhat.com> wrote:

> On 2/9/23 00:13, Laine Stump wrote:
> > 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.
> >=20
> > 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.
> >=20
> > Signed-off-by: Laine Stump <laine@redhat.com>
> > ---
> >  src/qemu/qemu_passt.c | 9 ++++-----
> >  1 file changed, 4 insertions(+), 5 deletions(-)
> >=20
> > 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, mac=
addr),
> > +                         "--pid", pidfile, =20
>=20
> The only problem with this approach is that our virPidFile*() functions
> rely on locking the very first byte. And when reading the pidfile, we
> try to lock the file and if we succeeded it means the file wasn't locked
> which means the process holding the lock died and thus the pid in the
> pidfile is stale.
>=20
> Now, I don't see passt locking the pidfile at all. So effectively, after
> this patch qemuPasstStop() would do nothing (well, okay, it'll remove
> the pidfile), qemuPasstSetupCgroup() does nothing, etc.

And it doesn't need to do anything, actually! passt is started with the
--one-off option:

       -1, --one-off
              Quit  after  handling  a single client connection, that is, o=
nce
              the client closes the socket, or once we get a socket error.

well, removing the PID file is nice (passt can't do it as it won't see
the filesystem after starting up), but that's about it.

--=20
Stefano