From nobody Thu May 15 08:45:02 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1510108816189955.8876911332967; Tue, 7 Nov 2017 18:40:16 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99DC9356D5; Wed, 8 Nov 2017 02:40:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 75EFD63F89; Wed, 8 Nov 2017 02:40:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3C3D61800FC4; Wed, 8 Nov 2017 02:40:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA82e2kh029416 for ; Tue, 7 Nov 2017 21:40:02 -0500 Received: by smtp.corp.redhat.com (Postfix) id 6EE2460630; Wed, 8 Nov 2017 02:40:02 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-90.phx2.redhat.com [10.3.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33E206BF69 for ; Wed, 8 Nov 2017 02:40:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 99DC9356D5 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Tue, 7 Nov 2017 21:39:56 -0500 Message-Id: <20171108023956.8920-6-jferlan@redhat.com> In-Reply-To: <20171108023956.8920-1-jferlan@redhat.com> References: <20171108023956.8920-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] libvirtd: Fix order of cleanup processing X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 08 Nov 2017 02:40:15 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Current cleanup processing is ad-hoc at best - it's led to a couple of strange and hard to diagnose timing problems and crashes. So rather than perform cleanup in a somewhat random order, let's perform cleanup in the exact opposite order of startup. Signed-off-by: John Ferlan Reviewed-by: Erik Skultety --- daemon/libvirtd.c | 42 +++++++++++++++++++++++++++++------------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 87c5b22710..92037e9070 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1524,9 +1524,35 @@ int main(int argc, char **argv) { 0, "shutdown", NULL, NULL); =20 cleanup: - virNetlinkEventServiceStopAll(); + /* NB: Order for cleanup should attempt to kept in the inverse order + * was was used to create/start the daemon - there are some fairly + * important reliances built into the startup processing that use + * refcnt's in order to manage objects. Removing too early could + * cause crashes. */ virNetDaemonClose(dmn); + + virNetlinkEventServiceStopAll(); + + if (driversInitialized) { + /* Set via daemonRunStateInit thread in daemonStateInit. + * NB: It is possible that virNetlinkEventServerStart fails + * and we jump to cleanup before driversInitialized has + * been set. That could leave things inconsistent; however, + * resolution of that possibility is perhaps more trouble than + * it's worth to handle. */ + driversInitialized =3D false; + virStateCleanup(); + } + + virObjectUnref(dmn); + virNetlinkShutdown(); + + if (pid_file_fd !=3D -1) + virPidFileReleasePath(pid_file, pid_file_fd); + + VIR_FREE(run_dir); + if (statuswrite !=3D -1) { if (ret !=3D 0) { /* Tell parent of daemon what failed */ @@ -1537,25 +1563,15 @@ int main(int argc, char **argv) { } VIR_FORCE_CLOSE(statuswrite); } - if (pid_file_fd !=3D -1) - virPidFileReleasePath(pid_file, pid_file_fd); =20 VIR_FREE(sock_file); VIR_FREE(sock_file_ro); VIR_FREE(sock_file_adm); + VIR_FREE(pid_file); - VIR_FREE(remote_config_file); - VIR_FREE(run_dir); =20 + VIR_FREE(remote_config_file); daemonConfigFree(config); =20 - if (driversInitialized) { - driversInitialized =3D false; - virStateCleanup(); - } - /* Now that the hypervisor shutdown inhibition functions that use - * 'dmn' as a parameter are done, we can finally unref 'dmn' */ - virObjectUnref(dmn); - return ret; } --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list