Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help - SCSI passthrough ioctl calls vs. sd/sg devices

206 views
Skip to first unread message

L

unread,
Apr 21, 2004, 6:29:05 PM4/21/04
to
Hi,

I would appreciate it if some one could clarify this. It's a bit confusing.

<<The Linux SCSI Generic (sg) HOWTO>> page 2 says "The sg driver permits
user applications to send SCSI commands to devices that understand them.
SCSI commands are 6, 10, 12 or 16 bytes long. The SCSI disk driver (sd),
once device initialization is complete, only sends SCSI READ and WRITE
commands."

<<The Linux 2.4 SCSI subsystem HOWTO>> page 3 says "Sg is a SCSI command
pass through device that uses a char device interface. General purpose
Linux commands should not be used on sg devices."

My questions are:

- sounds like SCSI passthrough ioctl calls can only apply
to sg devices. Is it right, or can we apply SCSI
passthrough ioctl calls to sd devices as well?
- what are the so-called "General purpose Linux commands"?
Are they read()/write() or 'mount' / 'dd' or something else?

What should we do if we need to 'mount' a file system on a disk and also
need to issue SCSI passthrough ioctl calls to the same disk? Maybe we
should use both sd and sg (i.e. mount the file system to /dev/sda1, and
issue SCSI passthrough ioctl calls to /dev/sg0 that maps to the same
disk/lun)? I was told 'mount' doesn't work on sg devices, right?

Many thanks,


T.


Josef Möllers

unread,
Apr 22, 2004, 3:28:10 AM4/22/04
to
L wrote:
> Hi,
>
> I would appreciate it if some one could clarify this. It's a bit confusing.
>
> <<The Linux SCSI Generic (sg) HOWTO>> page 2 says "The sg driver permits
> user applications to send SCSI commands to devices that understand them.
> SCSI commands are 6, 10, 12 or 16 bytes long. The SCSI disk driver (sd),
> once device initialization is complete, only sends SCSI READ and WRITE
> commands."
>
> <<The Linux 2.4 SCSI subsystem HOWTO>> page 3 says "Sg is a SCSI command
> pass through device that uses a char device interface. General purpose
> Linux commands should not be used on sg devices."
>
> My questions are:
>
> - sounds like SCSI passthrough ioctl calls can only apply
> to sg devices. Is it right, or can we apply SCSI
> passthrough ioctl calls to sd devices as well?

Each SCSI device found by the SCSI mid-layer is assigned an sg device.
If it happens to be a Direct-Access device, it will also be assigned an
sd device, if it is a Sequential-Access device, it will also be assigned
an st device.
So: each sd device also has an associated sg device. As a rule of thumb,
I always scan /proc/scsi/scsi and "mentally" assign an sg device to each
SCSI device found and an sd device to each Direct-Access device found. I
was told that this algorithm is not generally safe, e.g. if you remove
and add devices by hand.

> - what are the so-called "General purpose Linux commands"?
> Are they read()/write() or 'mount' / 'dd' or something else?

A command is a command, e.g. cp, cat, dd, mount. You can dd from/to
/dev/sda but you cannot dd from/to /dev/sg1.

System calls are used to access sg devices, you'll have to open(2)
/dev/sg..., the use ioctl(2) (or write(2)/read(2) with the old
interface) to issue commands, the close(2) the device afterwards.

> What should we do if we need to 'mount' a file system on a disk and also
> need to issue SCSI passthrough ioctl calls to the same disk? Maybe we
> should use both sd and sg (i.e. mount the file system to /dev/sda1, and
> issue SCSI passthrough ioctl calls to /dev/sg0 that maps to the same
> disk/lun)? I was told 'mount' doesn't work on sg devices, right?

Right, as stated above.
You can issue SCSI commands to a SCSI disk using the appropriate
/dev/sg... However, you must be veeeery carefully not to confuse the
disk driver! Better first issue the generic command(s), then mount the disk.

HTH,

Josef
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett

John-Paul Stewart

unread,
Apr 22, 2004, 10:47:51 AM4/22/04
to
L wrote:
>
> What should we do if we need to 'mount' a file system on a disk and also
> need to issue SCSI passthrough ioctl calls to the same disk? Maybe we
> should use both sd and sg (i.e. mount the file system to /dev/sda1, and
> issue SCSI passthrough ioctl calls to /dev/sg0 that maps to the same
> disk/lun)?

Can you clarify what you're trying to accomplish here? Under normal
operation, one accesses a SCSI disk as /dev/sdX. *All* normal
operations are handled that way.

The *only* time I've ever accessed a SCSI disk through the /dev/sgX
interface was to run a diagnostic program from the manufacturer on a
faulty drive.

I don't mean to be rude, but I get the impression that you fall into one
of two categories: 1) you're a newbie trying to do something you don't
need to do with the /dev/sgX devices, or 2) you're trying to do
something rather advanced (like disk diagnostics) without understanding
the basics of the SCSI drivers first.

> I was told 'mount' doesn't work on sg devices, right?

Right.

L

unread,
Apr 22, 2004, 11:22:31 AM4/22/04
to
I really appreciate your and other people's help. I'm not Linux expert, but
have been working on Windows for years.

Here are more details on what I'm trying to do:

- mount a small file system on a SCSI/FC disk.
- issue SCSI passthrough ioctl calls (with commands like INQUIRY,
READ/WRITE, RESERVE/RELEASE, MODE SELECT/SENSE, PERSISTENT RESERVATION) to
the same disk.

Thanks,


T.


"John-Paul Stewart" <jpst...@binaryfoundry.ca> wrote in message
news:4vl86c...@mail.binaryfoundry.ca...

L

unread,
Apr 22, 2004, 11:25:38 AM4/22/04
to
This is veeery helpfule, Josef.

Sounds to me like all SCSI passthrough ioctl calls (with commands like


INQUIRY, READ/WRITE, RESERVE/RELEASE, MODE SELECT/SENSE, PERSISTENT

RESERVATION) should be issued to sg devices, and none of them can be sent to
sd devices, correct?

Thanks,


T

"Josef Möllers" <josef.m...@fujitsu-siemens.com> wrote in message
news:c67s23$phl$1...@nntp.fujitsu-siemens.com...

Josef Möllers

unread,
Apr 22, 2004, 12:10:51 PM4/22/04
to
L wrote:
> This is veeery helpfule, Josef.
>
> Sounds to me like all SCSI passthrough ioctl calls (with commands like
> INQUIRY, READ/WRITE, RESERVE/RELEASE, MODE SELECT/SENSE, PERSISTENT
> RESERVATION) should be issued to sg devices, and none of them can be sent to
> sd devices, correct?

Cor...ect!

Although there seems to be a possibility to send an ioctl(2) to the sd
driver with a cmd of SCSI_IOCTL_SEND_COMMAND where you can pass
arbitrary commands through the sd driver, the source code says "This
interface is depreciated", so let's not use it.

L

unread,
Apr 22, 2004, 12:50:34 PM4/22/04
to
> Sounds to me like all SCSI passthrough ioctl calls (with commands like
> INQUIRY, READ/WRITE, RESERVE/RELEASE, MODE SELECT/SENSE, PERSISTENT
> RESERVATION) should be issued to sg devices, and none of them can be sent
to
> sd devices, correct?

Cor...ect!

Although there seems to be a possibility to send an ioctl(2) to the sd
driver with a cmd of SCSI_IOCTL_SEND_COMMAND where you can pass
arbitrary commands through the sd driver, the source code says "This
interface is depreciated", so let's not use it.

=============================
I really appreciate the information and your help, Josef.

Could you please tell me which source file says "This interface is
depreciated"? Is it Linux kernel 2.4's, and which source file (scsi.c or
what) says that? I'm currently using Linux kernel 2.4.

Just curiouse if Linux 2.4's sd driver still support SCSI_IOCTL_SEND_COMMAND
in ioctl calls, so we can send arbitrary SCSI commands to sd devices special
files.

Thanks,


T.


Josef Möllers

unread,
Apr 23, 2004, 2:53:25 AM4/23/04
to
L wrote:
>>Sounds to me like all SCSI passthrough ioctl calls (with commands like
>>INQUIRY, READ/WRITE, RESERVE/RELEASE, MODE SELECT/SENSE, PERSISTENT
>>RESERVATION) should be issued to sg devices, and none of them can be sent
>
> to
>
>>sd devices, correct?
>
>
> Cor...ect!
>
> Although there seems to be a possibility to send an ioctl(2) to the sd
> driver with a cmd of SCSI_IOCTL_SEND_COMMAND where you can pass
> arbitrary commands through the sd driver, the source code says "This
> interface is depreciated", so let's not use it.
> =============================
> I really appreciate the information and your help, Josef.
>
> Could you please tell me which source file says "This interface is
> depreciated"? Is it Linux kernel 2.4's, and which source file (scsi.c or
> what) says that? I'm currently using Linux kernel 2.4.

It's in drivers/scsi/scsi_ioctl.c, the function is
scsi_ioctl_send_command().

> Just curiouse if Linux 2.4's sd driver still support SCSI_IOCTL_SEND_COMMAND
> in ioctl calls, so we can send arbitrary SCSI commands to sd devices special
> files.

I've seen it in the 2.4.19 and 2.4.22 kernel.org source tree, so it
should work.
Because of the comment, I haven't tried it, but I have used a similar
interface on our own Reliant Unix (SVR4 based) and regard it as a viable
alternative, but then ...

L

unread,
Apr 23, 2004, 10:52:02 AM4/23/04
to
I really appreciate your help, Josef.

My questions have been answered.


T.


"Josef Möllers" <josef.m...@fujitsu-siemens.com> wrote in message

news:c6aecj$s76$1...@nntp.fujitsu-siemens.com...

Juha Laiho

unread,
Apr 25, 2004, 5:07:59 AM4/25/04
to
"L" <l_x...@yahoo.com> said:
>I really appreciate your and other people's help. I'm not Linux expert, but
>have been working on Windows for years.
>
>Here are more details on what I'm trying to do:
>
>- mount a small file system on a SCSI/FC disk.
>- issue SCSI passthrough ioctl calls (with commands like INQUIRY,
>READ/WRITE, RESERVE/RELEASE, MODE SELECT/SENSE, PERSISTENT RESERVATION) to
>the same disk.

Yes, that you described already, but could you describe for what you
need these commands -- what you're trying to accomplish with them?
So what are you needing from the disk in addition to the regular
data storage services?
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

0 new messages