From nobody Sun May 5 03:30:50 2024 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 1509082064375230.90725490148543; Thu, 26 Oct 2017 22:27:44 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0DE6461C1; Fri, 27 Oct 2017 05:27:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5FFF5C549; Fri, 27 Oct 2017 05:27:42 +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 D29946B48D; Fri, 27 Oct 2017 05:27:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9R5RYA2027548 for ; Fri, 27 Oct 2017 01:27:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8948A51DD8; Fri, 27 Oct 2017 05:27:34 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3341360C8A; Fri, 27 Oct 2017 05:27:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com F0DE6461C1 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 27 Oct 2017 01:26:11 -0400 Message-Id: <20171027052612.6720-2-jferlan@redhat.com> In-Reply-To: <20171027052612.6720-1-jferlan@redhat.com> References: <20171027052612.6720-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v4 1/2] rpc: When adding srv to dmn servers, need to add ref 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 27 Oct 2017 05:27:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Nikolay Shirokovskiy Commit id '252610f7d' modified net server management to use a hash table to store/manage the various servers; however, during virNetDaemonAddServerPostExec an @srv object is created, added to the dmn->servers hash table, but did not increment the object refcnt like was done during virNetDaemonAddServer as if @srv were being created for the first time. Without the proper ref a subsequent virObjectUnref done during virNetDaemonDispose when virHashFree calls the hash table entry @dataFree function virObjectFreeHashData could inadvertently free the memory before some caller is really done with it or cause the caller to attempt to free something that's already been freed (and it no longer necessarily owns). Additionally, since commit id 'f08b1c58f3' removed the @srv from virLockManager in favor of using virNetDaemonGetServer which creates a ref on @srv, we need to modify the lock_manager code in order to properly handle and dispose the references to the @srv object allowing either the cleanup processing or the virNetDaemonDispose processing to remove the last ref to the object. Signed-off-by: John Ferlan --- src/locking/lock_daemon.c | 19 ++++++++++++++----- src/rpc/virnetdaemon.c | 2 ++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index fe3eaf9032..ee2c35fdb8 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -1312,14 +1312,14 @@ int main(int argc, char **argv) { srv =3D virNetDaemonGetServer(lockDaemon->dmn, "virtlockd"); if ((rv =3D virLockDaemonSetupNetworkingSystemD(srv)) < 0) { ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; - goto cleanup; + goto cleanup_srvref; } =20 /* Only do this, if systemd did not pass a FD */ if (rv =3D=3D 0 && virLockDaemonSetupNetworkingNative(srv, sock_file) < 0) { ret =3D VIR_LOCK_DAEMON_ERR_NETWORK; - goto cleanup; + goto cleanup_srvref; } } else if (rv =3D=3D 1) { srv =3D virNetDaemonGetServer(lockDaemon->dmn, "virtlockd"); @@ -1333,7 +1333,7 @@ int main(int argc, char **argv) { =20 if ((virLockDaemonSetupSignals(lockDaemon->dmn)) < 0) { ret =3D VIR_LOCK_DAEMON_ERR_SIGNAL; - goto cleanup; + goto cleanup_srvref; } =20 if (!(lockProgram =3D virNetServerProgramNew(VIR_LOCK_SPACE_PROTOCOL_P= ROGRAM, @@ -1341,14 +1341,17 @@ int main(int argc, char **argv) { virLockSpaceProtocolProcs, virLockSpaceProtocolNProcs)= )) { ret =3D VIR_LOCK_DAEMON_ERR_INIT; - goto cleanup; + goto cleanup_srvref; } =20 if (virNetServerAddProgram(srv, lockProgram) < 0) { ret =3D VIR_LOCK_DAEMON_ERR_INIT; - goto cleanup; + goto cleanup_srvref; } =20 + /* Completed srv usage from virNetDaemonGetServer */ + virObjectUnref(srv); + /* Disable error func, now logging is setup */ virSetErrorFunc(NULL, virLockDaemonErrorHandler); =20 @@ -1403,4 +1406,10 @@ int main(int argc, char **argv) { no_memory: VIR_ERROR(_("Can't allocate memory")); exit(EXIT_FAILURE); + + cleanup_srvref: + /* Unref for virNetDaemonGetServer ref - still have "our" ref from + * allocation and possibly a ref for being in netserver hash table */ + virObjectUnref(srv); + goto cleanup; } diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index e3b9390af2..d970c47ad4 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -313,6 +313,8 @@ virNetDaemonAddServerPostExec(virNetDaemonPtr dmn, if (virHashAddEntry(dmn->servers, serverName, srv) < 0) goto error; =20 + virObjectRef(srv); + virJSONValueFree(object); virObjectUnlock(dmn); return srv; --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 03:30:50 2024 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 1509082064409794.1320544345758; Thu, 26 Oct 2017 22:27:44 -0700 (PDT) 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 BFF9F5F7B1; Fri, 27 Oct 2017 05:27:42 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5FA1718AD3; Fri, 27 Oct 2017 05:27:42 +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 E39876B592; Fri, 27 Oct 2017 05:27:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v9R5Re5B027561 for ; Fri, 27 Oct 2017 01:27:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4B83A5CC01; Fri, 27 Oct 2017 05:27:40 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-40.ams2.redhat.com [10.36.116.40]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84C9E60C8A; Fri, 27 Oct 2017 05:27:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BFF9F5F7B1 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: John Ferlan To: libvir-list@redhat.com Date: Fri, 27 Oct 2017 01:26:12 -0400 Message-Id: <20171027052612.6720-3-jferlan@redhat.com> In-Reply-To: <20171027052612.6720-1-jferlan@redhat.com> References: <20171027052612.6720-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: nshirokovskiy@virtuozzo.com Subject: [libvirt] [PATCH v4 2/2] libvirtd: fix crash on termination 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.39]); Fri, 27 Oct 2017 05:27:43 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Nikolay Shirokovskiy The problem is incorrect order of qemu driver shutdown and shutdown of netserver threads that serve client requests (thru qemu driver particularly). Net server threads are shutdown upon dispose which is triggered by last daemon object unref at the end of main function. At the same time qemu driver is shutdown earlier in virStateCleanup. As a result netserver threads see invalid driver object in the middle of request processing. Let's move shutting down netserver threads earlier to virNetDaemonClose. Note: order of last daemon unref and virStateCleanup is introduced in 85c3a182 for a valid reason. Signed-off-by: John Ferlan --- src/rpc/virnetdaemon.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index d970c47ad4..7cb3214166 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -882,6 +882,8 @@ virNetDaemonClose(virNetDaemonPtr dmn) virObjectLock(dmn); =20 virHashForEach(dmn->servers, daemonServerClose, NULL); + virHashRemoveAll(dmn->servers); + dmn->servers =3D NULL; =20 virObjectUnlock(dmn); } --=20 2.13.6 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list