From owner-freebsd-arch@FreeBSD.ORG Tue Mar 30 14:02:32 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0C18516A4CE; Tue, 30 Mar 2004 14:02:32 -0800 (PST) Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by mx1.FreeBSD.org (Postfix) with ESMTP id 74D8543D39; Tue, 30 Mar 2004 14:02:31 -0800 (PST) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (localhost [127.0.0.1]) by fledge.watson.org (8.12.10/8.12.10) with ESMTP id i2UM06xC000519; Tue, 30 Mar 2004 17:00:06 -0500 (EST) (envelope-from robert@fledge.watson.org) Received: from localhost (robert@localhost)i2UM05Ob000516; Tue, 30 Mar 2004 17:00:05 -0500 (EST) (envelope-from robert@fledge.watson.org) Date: Tue, 30 Mar 2004 17:00:05 -0500 (EST) From: Robert Watson X-Sender: robert@fledge.watson.org To: Nik Clayton In-Reply-To: <20040327085537.GC33016@clan.nothing-going-on.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: arch@freebsd.org Subject: Re: Where should devctl notifications be sent from? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Mar 2004 22:02:32 -0000 On Sat, 27 Mar 2004, Nik Clayton wrote: > Apologies in advance if this is too trivial for -arch. > > I'm trying to work out where it's appropriate to add devctl > notifications. > > The specific problem I'm trying to solve involves an iPod connected > through firewire. I'd like to be able to have devd be notified when the > iPod arrives, so that various processes can kick off automatically. In > an ideal world, I'll drop the iPod in the dock, and some backup > processes start, thereby allowing me to justify the purchase of a model > several sizes larger than I actually need :-) > > It looks like there are several places where the devctl_queue_data() and > related calls could be placed: > > firewire(4) -- when the device is plugged in > fwohci(4) -- when the interface arrives > sbp(4) -- when it's recognised as a mass storage device > geom(4) -- when geom creates the device (/dev/da2 (and da2s2) in my > case). Robert Watson has a patch that implements this. > devfs -- specifically, in make_dev(9) and destroy_dev(9) > > The limited research that I've done suggests that the most generic place > to put this code is inside make_dev(9) and destroy_dev(9). But this > seems so trivial that I can't believe no one else hasn't done the work, > so I figure there's probably something important that I'm missing. I think all of those are interesting choices, but let me give you my spiel on why I think GEOM is a good place to start. We have many different object namespaces in the kernel, based on the different subsystems and abstractions present there. For example, "fxp" is the name of a newbus device attached to (potentially) a PCI bus. It's also the name of a network interface device attached to the ifnet mechanism. It's also a device node in /dev. Likewise with storage devices, which can appear at many layers. We currently have a bogosity in devd: with ethernet devices, we run dhclient on an interface based on the interface attaching to newbus, not the interface arriving at the network layer. Likewise, if you write an automounter based on what's there today (the newbus event), there's actually a potential race or weakness: a device attaching to newbus doesn't mean it's ready for disk I/O. What I'd like to see happen is the notion of "subsystem" or "class" be introduced to the devctl namespace. Off the top of my head, the classes I'm interested in would be "newbus" (device attachment), "geom" (disk objects), and "ifnet" (network interface objects), and perhaps "devfs" (entries in /dev). The same name appearing at different layers has different interpretations, and requires different activities. Likewise, an object may exist only at a few layers (network pseudo-interfaces don't appear in newbus, for example; likewise, layered storage abstractions). There's another benefit to doing this: it becomes easier to write things like automounters and network interface handlers in userspace because class information is exposed from the kernel. Instead of "/dev/foo arrived", you get "A network interface named fxp0 has arrived"; likewise, instead of "/dev/foo has arrived", you get "A storage device named ad0.gbde has arrived". This makes it a lot easier to decide whether you should run dhclient (no need to hard-code interface names in devd.conf) or whether you run the automounter (no need for the auto-mounter to try and see if /dev/mem is a disk). There are other approaches that could be taken -- for example, newbus could learn to incorporate much more stuff (all stuff). However, that's a much more complex answer, requiring a lot of implementation changes in a lot of critical subsystems. Adding a new field to /dev/devctl's output is almost a no-op in complexity, and buys us a lot. It also helps us avoid answering the question you posed: we don't have to identify The One True Place, instead, we let important subsystems announce events in a way that makes sense for them, in their own namespace. Sure, you get a few more events (different layers reporting a related event), but you actually get a lot more information, and in a much more useful way. Robert N M Watson FreeBSD Core Team, TrustedBSD Projects robert@fledge.watson.org Senior Research Scientist, McAfee Research