public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Douglas Gilbert <dgilbert@interlog.com>
To: Adar Dembo <adar@vmware.com>
Cc: "linux-scsi@vger.kernel.org" <linux-scsi@vger.kernel.org>
Subject: Re: allow_dio/SG_FLAG_DIRECT_IO for sr devices
Date: Wed, 24 Feb 2010 17:54:31 -0500	[thread overview]
Message-ID: <4B85AE27.40606@interlog.com> (raw)
In-Reply-To: <6E637B430FD37A4AB921E6D15291BCAB018054B9B2@EXCH-MBX-4.vmware.com>

Adar Dembo wrote:
> When sending SG_IO ioctls to a device:
> - /dev/sgX devices (using sg.c) follow the behavior described at http://tldp.org/HOWTO/SCSI-Generic-HOWTO/dio.html in terms of defaulting to indirect I/O, and using direct I/O only if both /proc/scsi/sg/allow_dio and SG_FLAG_DIRECT_IO in the request are set.
> - /dev/srX devices (using sr.c) default to direct I/O. At least, that appears to be the case from inspecting the code, as sr_block_ioctl->cdrom_ioctl->scsi_cmd_ioctl->sg_io->blk_rq_map_user->__blk_rq_map_user will attempt to map the pages, regardless of what the user specified in the request or in the proc node.
> 
> This difference caught me by surprise; my expectation would be that an sg_io_hdr_t passed via SG_IO would be serviced in the same way regardless of the underlying driver. Is this a bug, or a feature? If the latter, is it documented somewhere?

As the name suggests the SG_IO ioctl was originally
implemented in the sg driver. Due to difficulties in
discovering which sg device corresponded to a particular
SCSI device node belonging to another driver (e.g. /dev/sr0
belonging to the sr driver), the SG_IO ioctl was
grafted on to various other drivers (in some cases via
the block layer).

The result is not always pretty and there are many
subtle differences. There is no 100% clean SCSI
pass-through in Linux (and if there was it could not
easily share a device with another high level SCSI driver
such as sr). The sg and the bsg drivers give the cleanest
pass-throughs. The rest tend to make assumptions appropriate
to their class of devices. And it is not just the SG_IO
ioctl that you need to take care of: some other drivers
will hang on open() if the device is not ready and the
O_NONBLOCK flag is not given.

Summary: the driver "owning" the file descriptor that
the SG_IO ioctl uses, is in control.

Doug Gilbert


  reply	other threads:[~2010-02-24 22:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-24 21:46 allow_dio/SG_FLAG_DIRECT_IO for sr devices Adar Dembo
2010-02-24 22:54 ` Douglas Gilbert [this message]
2010-02-24 23:30   ` Adar Dembo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B85AE27.40606@interlog.com \
    --to=dgilbert@interlog.com \
    --cc=adar@vmware.com \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox