From owner-svn-src-all@FreeBSD.ORG Thu Sep 16 15:32:49 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A831A1065675; Thu, 16 Sep 2010 15:32:49 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail07.syd.optusnet.com.au (mail07.syd.optusnet.com.au [211.29.132.188]) by mx1.freebsd.org (Postfix) with ESMTP id 3CB1D8FC0C; Thu, 16 Sep 2010 15:32:45 +0000 (UTC) Received: from c122-107-116-249.carlnfd1.nsw.optusnet.com.au (c122-107-116-249.carlnfd1.nsw.optusnet.com.au [122.107.116.249]) by mail07.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id o8GFWgUN025871 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 17 Sep 2010 01:32:43 +1000 Date: Fri, 17 Sep 2010 01:32:42 +1000 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: Kostik Belousov In-Reply-To: <20100915150412.GM2465@deviant.kiev.zoral.com.ua> Message-ID: <20100916220620.W763@delplex.bde.org> References: <201009151424.o8FEOLZE039185@svn.freebsd.org> <20100915145209.GK2465@deviant.kiev.zoral.com.ua> <20100915150412.GM2465@deviant.kiev.zoral.com.ua> MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-1831366618-1284651162=:763" Cc: Attilio Rao , svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org Subject: Re: svn commit: r212661 - head/sys/dev/aac X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 16 Sep 2010 15:32:49 -0000 This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --0-1831366618-1284651162=:763 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Wed, 15 Sep 2010, Kostik Belousov wrote: > On Wed, Sep 15, 2010 at 04:57:15PM +0200, Attilio Rao wrote: >> 2010/9/15 Kostik Belousov : >>> On Wed, Sep 15, 2010 at 02:24:21PM +0000, Attilio Rao wrote: >>>> ... >>>> Log: >>>> =9A Fix bogus busying mechanism from cdevsw callbacks: >>>> =9A - D_TRACKCLOSE may be used there as d_close() are expected to matc= h up >>>> =9A =9A d_open() calls Some mail program made this hard to read by converting ASCII to hard \x9a's= =2E D_TRACKCLOSE may be useful for something, but it isn't for determining busyness. Rather the reverse -- it can be used for getting the driver called in cases where there is a thread busy (but sleeping) in the driver. It can also repeat devfs/vfs's broken device busyness counting. I know of a couple of useful uses for it in FreeBSD, but these are unimplemented, and all of the uses that I looked at are nonsense or broken. One nonsense and broken case is in ast-tape.c. This driver used to enforce exclusive access using vfs counting. I think the vfs counting works with exclusive access. But with exclusive access all closes are last-ones so D_TRACKCLOSE has no effect. Now, this driver doesn't enforce exclusive access, so D_TRACKCLOSE just gives bugs like writing filemarks and rewinding the rewindable device for non-last closes, if anyone actually uses non-exclusive access. >>> VFS is not very good at properly calling VOP_CLOSE(). As example, prema= ture >>> vnode reclaim due to devfs unmount would cause VOP_CLOSE() to be called >>> only once despite the number of opens being =9A> 1. This seems to invalidate all cases where D_TRACKCLOSE is (ab)used for reference counting. One such case is geom_dev.c:g_dev_close(). This does nothing commital except to decrement some of the r/w/e access counters. But if it is not called once for every device open, it cannot do that. Also, there is a problem initializing its flags arg for forced VOP_CLOSE() from general context, and no way to its flags arg to pass the necessary combined r/w/e adjustments if these adjustments sum to less than -1 for any of r/w/e. For normal open/close pairs, the close flags arg must equal the open flags arg, and a forced close from unrelated context will find it either difficult to find the open flags arg if there was only 1 open, or usually impossible to combine 2 open flags args if there was > 1 open. Otherwise, g_dev_close is the only useful use of D_TRACKCLOSE that I know of. >> Yes. >> That makes implementing a similar semantic in drivers very difficult >> and not very well fixable, in particular within the d_* callbacks. Vfs doesn't properly determine busyness (due to complications in itself and at the driver level), so individualy drivers have no chance of determining it (since to do so they would have to understand not only therir own complications, but also vfs complications which vfs itself doesn't completely understand). >> I'm seriously wondering if we might just make a shortcut just for >> supporting such a feature (busying the device on real devfs entry >> activity) as several of them may be needing and may be probabilly >> needing to be 100%. >> Luckilly, it seems that such paths are not experienced very frequently. > > I am not sure what do you mean by "busying the device on real devfs entry > activity". Is the operation made by dev_refthread() and friends enough ? > > Device cannot be destroyed by destroy_dev() until all threads leave the > cdevsw methods. Note that there may be other threads in a cdevsw method even when d_close() is called for the last-close. I think no other threads can be in a cdevsw read, write or ioctl method when last-close is called (since they must hold a dup'ed fd open, so any close cannot be the last one). Also, no other thread can be in an open method, due to bugs in devfs/vfs last-close counting (the count is incremented before devfs_open() is called; so cdevsw close is never called if there is a thread in an open method and D_TRACKCLOSE is not set). But any number of threads can be in the close method when cdevsw close is called, even if D_TRACKCLOSE is not set, due to a lesser bug in devfs/vfs last-close counting (the count is decremented before devfs_close() is called, so cdevsw close may be called for last-close before a previous call completes)= =2E Bruce --0-1831366618-1284651162=:763--