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.133.124]) by passt.top (Postfix) with ESMTP id 47CA65A0082 for ; Thu, 16 Feb 2023 14:33:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676554379; 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=cD0XqH2CsbiKH3w0JChN05KcKDU4a2nowg4/CngzxYE=; b=SwqLJxlLPwkblhbTpjM6DrQxQoCXFJXC2QvdZZIM1ucrpMvgDC2L8ArAiYJ2/Mz5cJvuRN gK0NRSph/I6cTwMZ2Ds2Fr19QgryUxp0U0utvakXmE/YcA1Jh4jgSB3YP9NzI0dfcUKYr4 73h5w54DTEeaEJ34HVnD4P0vx5WsoMw= 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-348-zdnIpGmJP423msaDJluzJg-1; Thu, 16 Feb 2023 08:32:58 -0500 X-MC-Unique: zdnIpGmJP423msaDJluzJg-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 BBD461871DB5 for ; Thu, 16 Feb 2023 13:32:57 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.39]) by smtp.corp.redhat.com (Postfix) with ESMTP id 306C22166B31; Thu, 16 Feb 2023 13:32:57 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 4/5] qemu_passt: Deduplicate passt killing code Date: Thu, 16 Feb 2023 14:32:51 +0100 Message-Id: <662496e21f07a201eb0ff453306acc286530f1c1.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: KGDVPGS34TL7Y2YKIJ7WBY6MUBOPW7RP X-Message-ID-Hash: KGDVPGS34TL7Y2YKIJ7WBY6MUBOPW7RP 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: 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) { - 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); return -1; } -- 2.39.1