From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 27 21:52:41 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 411D4106566B; Wed, 27 Apr 2011 21:52:41 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id A2C3F8FC0C; Wed, 27 Apr 2011 21:52:40 +0000 (UTC) Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id p3RLqSHw025278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 28 Apr 2011 00:52:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4) with ESMTP id p3RLqSSS088234; Thu, 28 Apr 2011 00:52:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.4/8.14.4/Submit) id p3RLqScN088233; Thu, 28 Apr 2011 00:52:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 28 Apr 2011 00:52:28 +0300 From: Kostik Belousov To: Bartosz Fabianowski Message-ID: <20110427215228.GY48734@deviant.kiev.zoral.com.ua> References: <4DB695DB.1080505@chillt.de> <201104271019.31844.jhb@freebsd.org> <4DB818A3.1020104@chillt.de> <201104271334.07170.jhb@freebsd.org> <4DB8873C.5020608@chillt.de> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="AMNVzrRY61gDOMe/" Content-Disposition: inline In-Reply-To: <4DB8873C.5020608@chillt.de> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-3.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00, DNS_FROM_OPENWHOIS autolearn=no version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-hackers@freebsd.org, Hans Petter Selasky Subject: Re: Is there some implicit locking of device methods? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Apr 2011 21:52:41 -0000 --AMNVzrRY61gDOMe/ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Apr 27, 2011 at 11:14:36PM +0200, Bartosz Fabianowski wrote: > >If you have some sort of state that needs to get created on first > >open and then removed on last close [...] I would still depend on the > >cdevpriv destructor and use a reference count between open() and the > >destructor to know when to cleanup shared state. >=20 > Yes, this is what I am doing. I am maintaining a list of all file=20 > descriptors open on the device. Once the length of that list reaches=20 > zero, I do global clean-up in the cdevpriv destructor. You are mixing things, and do repeat the work (probably buggy) that is already done by devfs. You should understand the relationship between basic concepts first. File descriptor !=3D opened file !=3D cdev node. Driver indeed may get notifications on all open(2) syscalls performed on the node, but is has absolutely no way to enumerate filedescriptors referencing that files. cdevpriv is per file, not per node. cdevpriv is cleaned automatically when last filedescriptor referencing the file is gone, not when the last file referencing the node is closed. The later is approximated by d_close(). --AMNVzrRY61gDOMe/ Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (FreeBSD) iEYEARECAAYFAk24kBwACgkQC3+MBN1Mb4iVHACguKtBZiISUM/bFpYerbzTCliT zzwAoMmnQszeDh27mxADSSmYx53Yfk2E =Zzpo -----END PGP SIGNATURE----- --AMNVzrRY61gDOMe/--