Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Aug 2005 10:08:33 -0600
From:      "Kenneth D. Merry" <ken@freebsd.org>
To:        Reinhold Huber <rhuber@fs.tum.de>
Cc:        freebsd-scsi@freebsd.org, freebsd-questions@freebsd.org
Subject:   Re: CAM SCSI, finding out bus ID, target and LUN
Message-ID:  <20050802160833.GA40616@nargothrond.kdm.org>
In-Reply-To: <20050802143200.GA24341@fs.tum.de>
References:  <20050802143200.GA24341@fs.tum.de>

next in thread | previous in thread | raw e-mail | index | archive | help
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@FreeBSD.ORG



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050802160833.GA40616>