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 F19F65A026D for ; Thu, 16 Feb 2023 17:07:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676563634; 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=6TGoZT6T4B3vClzR2aQ4MzVjnCg9j/6ouQMte3Bwz1M=; b=A2Q7fVrGemww/7iuzZ2Ow118EKiNtE9ODVMtIgCHJuJ3QiY7yQARmwNuI2VxW3rt2W4mtg dd+7NegyAOaavYKNiV3uZtwgHm3+ZTkm12lsrd1foOspROwJ+AxwBWjLjJIyCpxdtnmc/C B/gICGnSQF0qRKqXBsCvZDtt9qg3OsA= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-613-teuEZYAVPw2r96RK_os2jw-1; Thu, 16 Feb 2023 11:07:12 -0500 X-MC-Unique: teuEZYAVPw2r96RK_os2jw-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 A140D1C02CB1 for ; Thu, 16 Feb 2023 16:07:10 +0000 (UTC) Received: from maya.cloud.tilaa.com (unknown [10.33.32.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7773D2026D4B; Thu, 16 Feb 2023 16:07:10 +0000 (UTC) Date: Thu, 16 Feb 2023 17:07:08 +0100 From: Stefano Brivio To: Michal Privoznik Subject: Re: [PATCH v2 4/5] qemu_passt: Deduplicate passt killing code Message-ID: <20230216170708.6012a7ef@elisabeth> In-Reply-To: <662496e21f07a201eb0ff453306acc286530f1c1.1676554196.git.mprivozn@redhat.com> References: <662496e21f07a201eb0ff453306acc286530f1c1.1676554196.git.mprivozn@redhat.com> 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=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 5WSOST2ENA3OU7LVCIVO7KBJMAWCFXAC X-Message-ID-Hash: 5WSOST2ENA3OU7LVCIVO7KBJMAWCFXAC 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 14:32:51 +0100 Michal Privoznik wrote: > 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, > } > > > -void > -qemuPasstStop(virDomainObj *vm, > - virDomainNetDef *net) > +static void > +qemuPasstKill(const char *pidfile) A minor comment, should you respin: I think it should be made clear that 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. > { > - g_autofree char *pidfile = qemuPasstCreatePidFilename(vm, net); > virErrorPtr orig_err; > > virErrorPreserveLast(&orig_err); > @@ -118,6 +116,16 @@ qemuPasstStop(virDomainObj *vm, > } > > > +void > +qemuPasstStop(virDomainObj *vm, > + virDomainNetDef *net) > +{ > + g_autofree char *pidfile = qemuPasstCreatePidFilename(vm, net); > + > + qemuPasstKill(pidfile); > +} > + > + > int > qemuPasstSetupCgroup(virDomainObj *vm, > virDomainNetDef *net, > @@ -147,7 +155,6 @@ qemuPasstStart(virDomainObj *vm, > g_autofree char *errbuf = NULL; > char macaddr[VIR_MAC_STRING_BUFLEN]; > size_t i; > - pid_t pid = (pid_t) -1; > int exitstatus = 0; > int cmdret = 0; > > @@ -289,10 +296,6 @@ qemuPasstStart(virDomainObj *vm, > return 0; > > error: > - ignore_value(virPidFileReadPathIfLocked(pidfile, &pid)); > - if (pid != -1) > - virProcessKillPainfully(pid, true); > - unlink(pidfile); > - > + qemuPasstKill(pidfile); ...what takes care of terminating passt in case qemu doesn't start, now? The fact that the process is in the cgroup, right? > return -1; > } -- Stefano