Skip to contentSkip to conversation

bus:id:lun to device name

DISCUSSION Stefan Voelkel 4 participants 6 messages Jul 2, 2003 – Jul 17, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

Hi,

I want to convert a bus:id:lun triple to something like "/dev/sda".

From userspace I can ioctl() /dev/s[d|cd|...]* or parse /proc/scsi/scsi. I do not like any of those solutions.

Since a kernel module is already involved, I was wondering if it can/may/should be done from kernelspace. As of 2.4.21 some data structures from the middle layer are exported, but with a "debug only" comment.

regards
Stefan

Signature · 6 lines
--------------------------------------------------------------------
Stefan Völkel                            [email protected]
Millenux GmbH                              mobile: +49.170.79177.17
Lilienthalstraße 2                          phone: +49.711.88770.300
70825 Stuttgart-Korntal                       fax: +49.711.88770.349
     -= linux without limits -=- http://linux.zSeries.org/ =-
#1 lore raw

Hi Stefan,

Quoted 3 lines · Stefan Voelkel

I want to convert a bus:id:lun triple to something like "/dev/sda".

From userspace I can ioctl() /dev/s[d|cd|...]* or parse /proc/scsi/scsi.

Plain /proc/scsi/scsi does not help you.
You may want to have a lok at the scsi-many patches that export this information via /proc/scsi/scsi though.
http://www.suse.de/~garloff/linux/scsi-many/

Host: scsi3 Channel: 00 Id: 10 Lun: 00
Vendor: IBM Model: DDYS-T18350N Rev: S84D
Type: Direct-Access ANSI SCSI revision: 03
Attached drivers: sde(b:08:40) sg5(c:15:05)

Quoted 1 line

I do not like any of those solutions.

For non-removable harddisks, the ioctl() just works fine, BTW. I see no reason to dislike it.

Another option is to use scsidev
http://www.garloff.de/kurt/linux/scsidev/
where the device nodes are dynamically created and (by default) have names which contain this information.

Regards,

Signature · 3 lines
Kurt Garloff  <[email protected]>                          Eindhoven, NL
GPG key: See mail header, key servers                 SuSE Labs (Head)
SuSE Linux AG, Nuernberg, DE                            SCSI, Security
#2 lore raw
Quoted 11 lines · Kurt Garloff

Hi Stefan,

Quoted 3 lines · Stefan Voelkel

I want to convert a bus:id:lun triple to something like "/dev/sda".

From userspace I can ioctl() /dev/s[d|cd|...]* or parse /proc/scsi/scsi.

Plain /proc/scsi/scsi does not help you.
You may want to have a lok at the scsi-many patches that export this information via /proc/scsi/scsi though.
http://www.suse.de/~garloff/linux/scsi-many/

I can not patch the middle layer.

Quoted 9 lines

Host: scsi3 Channel: 00 Id: 10 Lun: 00
Vendor: IBM Model: DDYS-T18350N Rev: S84D
Type: Direct-Access ANSI SCSI revision: 03
Attached drivers: sde(b:08:40) sg5(c:15:05)

Quoted 1 line

I do not like any of those solutions.

For non-removable harddisks, the ioctl() just works fine, BTW. I see no reason to dislike it.

Theoretically /dev/foobar might be a scsi device, meaning that I must/should ioctl() all files under /dev/. Thats what I do not like about ioctl() :).

Quoted 4 lines

Another option is to use scsidev
http://www.garloff.de/kurt/linux/scsidev/
where the device nodes are dynamically created and (by default) have names which contain this information.

AFAIR devfs does this too, depending on devfs would be an option.

regards
Stefan

Signature · 6 lines
--------------------------------------------------------------------
Stefan Völkel                            [email protected]
Millenux GmbH                              mobile: +49.170.79177.17
Lilienthalstraße 2                          phone: +49.711.88770.300
70825 Stuttgart-Korntal                       fax: +49.711.88770.349
     -= linux without limits -=- http://linux.zSeries.org/ =-
#3 lore raw
Quoted 7 lines

Theoretically /dev/foobar might be a scsi device, meaning that I must/should ioctl() all files under /dev/. Thats what I do not like about ioctl() :).

Even that is an oversimplification of the problem. /home/bryanh/foo could be a SCSI device. It could be the same device as /dev/sda. The device could have no device special file at all (maybe a program that accesses the device creates the device special file on the fly. Maybe the file has been deleted since the device was opened).

Once you admit that devices in Linux are not fundamentally associated with names in the file tree, the problem takes on a whole new perspective.

On the other hand, if you're willing to constrain your world such that there is such an association (by setting up rules about how you will and will not use device special files), then there's really nothing wrong with saying all SCSI devices will be accessed via device special file names in a certain list, and then doing the ioctl to each file in that list to find out which SCSI device it is.

Quoted 6 lines
Quoted 4 lines

Another option is to use scsidev
http://www.garloff.de/kurt/linux/scsidev/
where the device nodes are dynamically created and (by default) have names which contain this information.

AFAIR devfs does this too, depending on devfs would be an option.

Then it isn't clear which specific problem you're trying to solve. Do you mean you want _a_ device special file by which you can access the device, and any will do? In that case a scsidev/devfs solution would work. You could also use sg devices (via permanent device special files, or ones made up on the fly). Or do you want the name by which people normally know and use the device? E.g. "I have /dev/sda mounted, but what device is that?"

#4 lore raw
Quoted 8 lines · Bryan Henderson
Quoted 5 lines

Theoretically /dev/foobar might be a scsi device, meaning that I must/should ioctl() all files under /dev/. Thats what I do not like about ioctl() :).

Once you admit that devices in Linux are not fundamentally associated with names in the file tree, the problem takes on a whole new perspective.

True. What I do not like about a list of devices is the fact that I will duplicate code, eg (from sd.c)

static void sd_devname(unsigned int disknum, char *buffer)

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines

Another option is to use scsidev
http://www.garloff.de/kurt/linux/scsidev/
where the device nodes are dynamically created and (by default) have names which contain this information.

AFAIR devfs does this too, depending on devfs would be an option.

[...] Or do you want the name by which people normally know and use the device? E.g. "I have /dev/sda mounted, but what device is that?"

Yes, basically. I have this information: host_id:bus:target:lun, and now I'd like the "device file name with which one normally access' this specific lun".

Let me give you some details (hope that will make it clearer). I am implementing FC-HBA (ftp://ftp.t11.org/t11/pub/fc/hba/03-108v2.pdf). The problem occures with HBA_GetFcpTargetMapping() on page 73 (7.4.4), the parameters are describerd on page 31 (6.6.1) and the specific struct is HBA_ScsiId (6.6.1.5), actually the member OSDeviceName (6.6.2.11).

As it seems, I must use the file-name-list-ioctl() approach without devfs and something like snprintf("/dev/scsi/host%d/bus%d/...", ...); if devfs is mounted.

Thank you all for your time

regards
Stefan

Signature · 6 lines
--------------------------------------------------------------------
Stefan Völkel                            [email protected]
Millenux GmbH                              mobile: +49.170.79177.17
Lilienthalstraße 2                          phone: +49.711.88770.300
70825 Stuttgart-Korntal                       fax: +49.711.88770.349
     -= linux without limits -=- http://linux.zSeries.org/ =-
#5 lore raw
Quoted 3 lines · Stefan Voelkel

Yes, basically. I have this information: host_id:bus:target:lun, and now I'd like the "device file name with which one normally access' this specific lun".

This is not possible in Linux as it's a userspace policy decision. E.g. scsi cdrom devices at least have three commonly used naming schemes.

Quoted 5 lines

Let me give you some details (hope that will make it clearer). I am implementing FC-HBA (ftp://ftp.t11.org/t11/pub/fc/hba/03-108v2.pdf). The problem occures with HBA_GetFcpTargetMapping() on page 73 (7.4.4), the parameters are describerd on page 31 (6.6.1) and the specific struct is HBA_ScsiId (6.6.1.5), actually the member OSDeviceName (6.6.2.11).

This doesn't make any sense in a linux enviroment. I'd rather try to get that draft fixed before it's ratified instead of working around it especially as they already mention Linux in some examples.

OTOH it's probably totally irrelevant for real life anyway.