CAM SCSI, finding out bus ID, target and LUN

Kenneth D. Merry ken at freebsd.org
Tue Aug 2 16:08:39 GMT 2005


On Tue, Aug 02, 2005 at 16:32:00 +0200, Reinhold Huber wrote:
> Hello,
> 
> I'm trying to get bus ID, target and LUN to an open fd which is afaik
> opened to the device special file, e.g. /dev/cd0 .
> 
> So how do I get the information? Up to now, I didn't find IOCTL calls
> (like in NetBSD) which deliver this kind of info, and first tries to
> browse in CAM examples didn't help either.
> 
> I tried on FreeBSD 5.3 and currently hope that there are no big
> changes to this between 5.3 and 5.4 or even -current. If I'm
> wrong with this, please correct me.
> 
> Any pointer to docs or source is welcome.

(For this sort of query you might get better answers from the freebsd-scsi
list, CCed.)

You could try issuing the CAMGETPASSTHRU ioctl.  Unfortunately it was
broken for the cd(4) driver before 5.4 when there is no media in the drive.

It will give you the pass(4) instance associated with that particular cd(4)
instance.  It doesn't work for the da(4) driver, since the GEOM code has
taken over the ioctl routine for that driver.  It should work for the
cd(4), ch(4), pass(4), pt(4), sa(4) and ses(4) drivers.

The CCB header for the XPT_GDEVLIST CCB returned from the CAMGETPASSTHRU
ioctl should have the correct path, target and LUN if that's all you want.
(The pass driver instance and unit number are in the payload.)

If you want something that works consistently across all CAM peripheral
drivers, you'll need to know the device name and unit number of the device
you're talking to.

Then you can open its associated pass(4) device with cam_open_spec_device(3).

If you just have the device path name, you can try cam_open_device(3).  It
will attempt to parse out the path name for you.

In either case, the cam_device structure returned will also have the path,
target and LUN for the device.

One obvious prerequisite for all of this is that you have to know ahead of
time that you're talking to a CAM device.  These mechanisms don't work
otherwise.

Ken
-- 
Kenneth Merry
ken at FreeBSD.ORG


More information about the freebsd-scsi mailing list