From owner-freebsd-scsi Tue Oct 20 13:20:28 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA28177 for freebsd-scsi-outgoing; Tue, 20 Oct 1998 13:20:28 -0700 (PDT) (envelope-from owner-freebsd-scsi@FreeBSD.ORG) Received: from panzer.plutotech.com (panzer.plutotech.com [206.168.67.125]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA28172 for ; Tue, 20 Oct 1998 13:20:26 -0700 (PDT) (envelope-from ken@panzer.plutotech.com) Received: (from ken@localhost) by panzer.plutotech.com (8.9.1/8.8.5) id OAA05203; Tue, 20 Oct 1998 14:19:54 -0600 (MDT) From: "Kenneth D. Merry" Message-Id: <199810202019.OAA05203@panzer.plutotech.com> Subject: Re: for i in disks In-Reply-To: <199810201143.EAA17327@silvia.hip.berkeley.edu> from Satoshi Asami at "Oct 20, 98 04:43:02 am" To: asami@cs.berkeley.edu (Satoshi Asami) Date: Tue, 20 Oct 1998 14:19:54 -0600 (MDT) Cc: scsi@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL28s (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-scsi@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Satoshi Asami wrote... > Hi folks, > > I'm thinking about implementing an "autorun"-like mechanism for disks. > The idea is to have a script with a known name on a known position > (say, partition `a' on the first BSD slice) which is called during > boot. The script does something to set up the disk (mount some other > partition, or set up a ccd, or something like that). > > However, to do this, I need to be able to write a loop in /etc/rc* to > iterate through all available disks. I guess devfs when fully > implemented will make this easy ("/devfs/da[0-9]*s?a"?) but my > understanding is that it is not ready yet. I could try mounting all > the nodes in /dev (the ones that are not available will presumably > just fail) but with up to 96 disks per system, that could be a lot of > failures. > > I could do something like > > grep 'da[^ ]* at ahc' /var/run/dmesg.boot > > but it sometimes overlaps other messages and it also appears to be > very incomplete on some machines. [ ... ] > (There are 42 disks on this machine.) > > Any ideas? > > Satoshi (I know I know, one of these days I'll actually implement something) Well, there are several ways you can do this. The first question is whether you want to do this for just CAM-accessible disks, or for all disks in the system. If you just want a listing of CAM-accessible disks, I've attached a program that will do that. 'camcontrol devlist' will also list all CAM devices. The attached program takes as arguments the peripheral names you're interested in. e.g.: {roadwarrior:/usr/home/ken/src/camtest:41:0} ./devmatch da da0 da1 {roadwarrior:/usr/home/ken/src/camtest:42:0} ./devmatch da cd da0 da1 cd0 {roadwarrior:/usr/home/ken/src/camtest:43:0} ./devmatch da cd pass da0 da1 cd0 pass0 pass1 pass2 It's also available here: ftp://ftp.kdm.org/pub/FreeBSD/cam/devmatch.c Notice that the peripheral names passed in are ORed in and compsed into a matching expression. You can also do much more complicated matching expressions if you want. (You can even match against inquiry patterns, just like the kernel quirk matching code does.) I plan on adding code similar to 'devmatch.c' to camcontrol at some point. It'll hopefully take advantage of more of the transport layer matching functionality, though. If you want to get a listing of all disks, SCSI, IDE, etc., you'll need to get that from the devstat(9) code. There's a program here to dump out all the devstat structures: ftp://ftp.kdm.org/pub/FreeBSD/cam/ds.c The devstat structures have the device name and unit number for each device. They also have flags indicating what type of device it is (direct access, sequential access, cdrom), the interface (IDE, SCSI or other), and whether or not it's a passthrough device. (The passthrough device flag allows you to figure out what the underlying device type is, rather than just that the peripheral driver in question is a passthrough driver.) iostat(8), systat(1) and vmstat(8) use matching code from the devstat(3) library to build matching expressions. You can probably look at the ds.c program above, iostat, and the devstat library to get an idea of how to do what you want to do using the devstat code. So, depending on whether you want just SCSI disks, or all disks, there are different alternatives you can use. And, unlike grepping through the dmesg information, these actually give deterministic results. :) Ken -- Kenneth Merry ken@plutotech.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-scsi" in the body of the message