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 165345A0082 for ; Thu, 16 Feb 2023 18:06:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676567159; 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=UlbqEvGmw71+eG5ud9yC3RhjhcucJ3CVmngOWpmfBoo=; b=gXMvlB9XsHK3a5JnmixXBAc0tdgBRiSJQi5sOMdcdw72H5Xlvi7YuUe6/RxmC9X7PonRZP eAtBSvnwwz9RtnNBr0ncyNYVaIeeoK2oJ6ILVFPgp8GDiI8DxgsfhxAKmTngWJQwf9vOA9 DDv1CPsTF/RqBKkDPFvdUpMCJMDnCHQ= 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-639-D5HJBfYCNyu_cgQb-YZCHA-1; Thu, 16 Feb 2023 12:05:57 -0500 X-MC-Unique: D5HJBfYCNyu_cgQb-YZCHA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2EE1080D0E2 for ; Thu, 16 Feb 2023 17:05:57 +0000 (UTC) Received: from maya.cloud.tilaa.com (unknown [10.33.32.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DA91D2026D4B; Thu, 16 Feb 2023 17:05:56 +0000 (UTC) Date: Thu, 16 Feb 2023 18:05:53 +0100 From: Stefano Brivio To: Michal =?UTF-8?B?UHLDrXZvem7DrWs=?= Subject: Re: [PATCH v2 4/5] qemu_passt: Deduplicate passt killing code Message-ID: <20230216180553.49bde5ab@elisabeth> In-Reply-To: References: <662496e21f07a201eb0ff453306acc286530f1c1.1676554196.git.mprivozn@redhat.com> <20230216170708.6012a7ef@elisabeth> Organization: Red Hat MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: Y7UI7QWHWBDTINJWUP5QCIWTUAMMZSBJ X-Message-ID-Hash: Y7UI7QWHWBDTINJWUP5QCIWTUAMMZSBJ 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: libvir-list@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: On Thu, 16 Feb 2023 17:38:47 +0100 Michal Pr=C3=ADvozn=C3=ADk wrote: > On 2/16/23 17:07, Stefano Brivio wrote: > > On Thu, 16 Feb 2023 14:32:51 +0100 > > Michal Privoznik wrote: > > =20 > >> There are two places where we kill passt: > >> > >> 1) qemuPasstStop() - called transitively from qemuProcessStop(), > >> 2) qemuPasstStart() - after failed start. > >> > >> Now, the code from 2) lack error preservation (so if there's > >> another error during cleanup we might overwrite the original > >> error). Therefore, move the internals of qemuPasstStop() into a > >> separate function and call it from both places. > >> > >> Signed-off-by: Michal Privoznik > >> --- > >> src/qemu/qemu_passt.c | 23 +++++++++++++---------- > >> 1 file changed, 13 insertions(+), 10 deletions(-) > >> > >> diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c > >> index 881205449b..a4cc9e7166 100644 > >> --- a/src/qemu/qemu_passt.c > >> +++ b/src/qemu/qemu_passt.c > >> @@ -102,11 +102,9 @@ qemuPasstAddNetProps(virDomainObj *vm, > >> } > >> =20 > >> =20 > >> -void > >> -qemuPasstStop(virDomainObj *vm, > >> - virDomainNetDef *net) > >> +static void > >> +qemuPasstKill(const char *pidfile) =20 > >=20 > > A minor comment, should you respin: I think it should be made clear tha= t > > this is not the expected/normal way in which passt will terminate -- > > here or in the next patch. Removing the PID file is nice, but that's > > (usually) about it. =20 >=20 > I can adjust the commit message. Okay, I'm not really familiar with libvirt's code, so I don't know how appropriate this is -- I was just suggesting that a _comment_ to a qemuPasstKill() function which does *not* actually kill the passt process, unless an error occurs, wouldn't look so bizarre. > >> { > >> - g_autofree char *pidfile =3D qemuPasstCreatePidFilename(vm, net); > >> virErrorPtr orig_err; > >> =20 > >> virErrorPreserveLast(&orig_err); > >> @@ -118,6 +116,16 @@ qemuPasstStop(virDomainObj *vm, > >> } > >> =20 > >> =20 > >> +void > >> +qemuPasstStop(virDomainObj *vm, > >> + virDomainNetDef *net) > >> +{ > >> + g_autofree char *pidfile =3D qemuPasstCreatePidFilename(vm, net); > >> + > >> + qemuPasstKill(pidfile); > >> +} > >> + > >> + > >> int > >> qemuPasstSetupCgroup(virDomainObj *vm, > >> virDomainNetDef *net, > >> @@ -147,7 +155,6 @@ qemuPasstStart(virDomainObj *vm, > >> 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; > >> =20 > >> @@ -289,10 +296,6 @@ qemuPasstStart(virDomainObj *vm, > >> return 0; > >> =20 > >> error: > >> - ignore_value(virPidFileReadPathIfLocked(pidfile, &pid)); > >> - if (pid !=3D -1) > >> - virProcessKillPainfully(pid, true); > >> - unlink(pidfile); > >> - > >> + qemuPasstKill(pidfile); =20 > >=20 > > ...what takes care of terminating passt in case qemu doesn't start, now= ? > > The fact that the process is in the cgroup, right? =20 >=20 > No, it's qemuPasstKill(). Starting a guest is done in > qemuProcessStart(). In here, qemuProcessLaunch() -> > qemuExtDevicesStart() -> qemuPasstStart() is called. Now, in the top > most parent (qemuProcessStart()) - you can see the 'stop' label in which > qemuProcessStop() -> qemuExtDevicesStop() -> qemuPasstStop() is called. Ah, okay, thanks for the explanation, I see now (well, it makes sense with 5/5). --=20 Stefano