From owner-freebsd-hackers@FreeBSD.ORG Wed Apr 27 19:44:50 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 2671A1065673 for ; Wed, 27 Apr 2011 19:44:50 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id EF9598FC18 for ; Wed, 27 Apr 2011 19:44:49 +0000 (UTC) Received: from bigwig.baldwin.cx (66.111.2.69.static.nyinternet.net [66.111.2.69]) by cyrus.watson.org (Postfix) with ESMTPSA id 8E8B546B35; Wed, 27 Apr 2011 15:44:49 -0400 (EDT) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 13A258A027; Wed, 27 Apr 2011 15:44:49 -0400 (EDT) From: John Baldwin To: Bartosz Fabianowski Date: Wed, 27 Apr 2011 13:34:07 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110325; KDE/4.5.5; amd64; ; ) References: <4DB695DB.1080505@chillt.de> <201104271019.31844.jhb@freebsd.org> <4DB818A3.1020104@chillt.de> In-Reply-To: <4DB818A3.1020104@chillt.de> MIME-Version: 1.0 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <201104271334.07170.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.6 (bigwig.baldwin.cx); Wed, 27 Apr 2011 15:44:49 -0400 (EDT) Cc: Kostik Belousov , 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 19:44:50 -0000 On Wednesday, April 27, 2011 9:22:43 am Bartosz Fabianowski wrote: > > Err, if you use cdevpriv you shouldn't even have a d_close method. All your > > d_close logic should be in the cdevpriv destructor > > I see. There is no documentation for any of this, so I just implemented > it in the way I *thought* it should work: > > .d_close = drv_close, > > int drv_close(...) { > devfs_clear_cdevpriv(); > } > > static void cdevpriv_dtr(void *data) { > free(data, M_USBDEV); > } > > If I understand you correctly, I can leave out the drv_close() method. > When close() is called, devfs_clear_cdevpriv() will be executed > implcitly for me and my dstructor will run - right? Yes, if you only care about cleaning up per-fd data. If you have some sort of state that needs to get created on first open and then removed on last close, you may still want to use a d_close() method, but there are actually edge cases where that can still not be called. So, for that sort of data 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. -- John Baldwin