From owner-svn-src-head@FreeBSD.ORG Wed Sep 26 20:33:54 2012 Return-Path: Delivered-To: svn-src-head@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E0DE5106564A; Wed, 26 Sep 2012 20:33:53 +0000 (UTC) (envelope-from ken@kdm.org) Received: from nargothrond.kdm.org (nargothrond.kdm.org [70.56.43.81]) by mx1.freebsd.org (Postfix) with ESMTP id 99D0C8FC08; Wed, 26 Sep 2012 20:33:53 +0000 (UTC) Received: from nargothrond.kdm.org (localhost [127.0.0.1]) by nargothrond.kdm.org (8.14.2/8.14.2) with ESMTP id q8QKXqph002706; Wed, 26 Sep 2012 14:33:52 -0600 (MDT) (envelope-from ken@nargothrond.kdm.org) Received: (from ken@localhost) by nargothrond.kdm.org (8.14.2/8.14.2/Submit) id q8QKXqGV002705; Wed, 26 Sep 2012 14:33:52 -0600 (MDT) (envelope-from ken) Date: Wed, 26 Sep 2012 14:33:52 -0600 From: "Kenneth D. Merry" To: Pawel Jakub Dawidek Message-ID: <20120926203352.GA2687@nargothrond.kdm.org> References: <201209221241.q8MCfnhJ067937@svn.freebsd.org> <20120925233712.GA26920@nargothrond.kdm.org> <20120926072005.GH1391@garage.freebsd.pl> <20120926172917.GA71268@nargothrond.kdm.org> <20120926185339.GA1402@garage.freebsd.pl> <20120926192117.GA89741@nargothrond.kdm.org> <20120926194541.GB1402@garage.freebsd.pl> <20120926195820.GA96844@nargothrond.kdm.org> <20120926200231.GD1402@garage.freebsd.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120926200231.GD1402@garage.freebsd.pl> User-Agent: Mutt/1.4.2i Cc: svn-src-head@FreeBSD.org, jdp@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, phk@FreeBSD.org Subject: Re: svn commit: r240822 - head/sys/geom X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Sep 2012 20:33:54 -0000 On Wed, Sep 26, 2012 at 22:02:31 +0200, Pawel Jakub Dawidek wrote: > On Wed, Sep 26, 2012 at 01:58:20PM -0600, Kenneth D. Merry wrote: > > On Wed, Sep 26, 2012 at 21:45:41 +0200, Pawel Jakub Dawidek wrote: > > > On Wed, Sep 26, 2012 at 01:21:17PM -0600, Kenneth D. Merry wrote: > > > > On Wed, Sep 26, 2012 at 20:53:39 +0200, Pawel Jakub Dawidek wrote: > > > > > On Wed, Sep 26, 2012 at 11:29:17AM -0600, Kenneth D. Merry wrote: > > > > > > Here is what CAM needs at each step: > > > > > > > > > > > > 1. When a device goes away, we need a method to call from daoninvalidate() > > > > > > (or any other peripheral driver invalidate routine) with these > > > > > > properties: > > > > > > - It tells GEOM that the device has gone away, and starts the process > > > > > > of shutting down the device. (i.e. withers/orphans the provider) > > > > > > - It is callable from an interrupt context, with the SIM (MTX_DEF) lock > > > > > > held, so it can't sleep. > > > > > > > > > > Neither g_wither_provider() nor g_orphan_provider() require the topology > > > > > lock. They only acquire the event lock, but it is regular mutex, so this > > > > > is fine. Traversing geom's providers list looks like something that does > > > > > need the topology lock, but maybe traversing is not needed at all. > > > > > The reason for this change was a panic in iSCSI initiator where > > > > > disk_gone() was called and provider was destroyed before g_wither_geom() > > > > > returned. > > > > > > > > Ahh. How about using LIST_FOREACH_SAFE? Would that address the problem at > > > > hand? Are there any other races in there? > > > > > > It depends. If one geom can hold more than one provider then it might be > > > racy, but from what I see there is always only one provider - there has > > > to be only one, because disk_destroy() destroys it and struct disk > > > represents always only one disk. If that's true then I see not reason to > > > have a loop in there. I'd change it to: > > > > > > void > > > disk_gone(struct disk *dp) > > > { > > > struct g_geom *gp; > > > struct g_provider *pp; > > > > > > gp = dp->d_geom; > > > if (gp != NULL) { > > > pp = LIST_FIRST(&gp->provider); > > > if (pp != NULL) > > > g_wither_provider(pp, ENXIO); > > > } > > > } > > > > I would suggest doing LIST_FOREACH_SAFE() (with a comment explaining why) > > instead. That way just in case someone adds another provider down the > > road it will be handled properly. > > > > Otherwise we need a comment or KASSERT somewhere to explain that we depend > > on there only being one provider, and things will break if there is more > > than one. > > I'm happy with adding KASSERT(), as I don't believe LIST_FOREACH_SAFE() > will be safe there, as disk_gone() itself doesn't prevent the function > to be called for two different disks, but one geom. LIST_FOREACH_SAFE() > make it safe to remove only the current element. If any other elements > is removed while we are traversing the list it will most likely panic. Ahh, okay. A KASSERT is fine then. Ken -- Kenneth Merry ken@FreeBSD.ORG