sg: add SG_FLAG_Q_AT_TAIL flag
authorDouglas Gilbert <dgilbert@interlog.com>
Wed, 4 Jun 2014 14:58:30 +0000 (10:58 -0400)
committerChristoph Hellwig <hch@lst.de>
Thu, 17 Jul 2014 20:07:34 +0000 (22:07 +0200)
When the SG_IO ioctl was copied into the block layer and
later into the bsg driver, subtle differences emerged.

One difference is the way injected commands are queued through
the block layer (i.e. this is not SCSI device queueing nor SATA
NCQ). Summarizing:
   - SG_IO in the block layer: blk_exec*(at_head=false)
   - sg SG_IO: at_head=true
   - bsg SG_IO: at_head=true

Some time ago Boaz Harrosh introduced a sg v4 flag called
BSG_FLAG_Q_AT_TAIL to override the bsg driver default.
This patch does the equivalent for the sg driver.

ChangeLog:
     Introduce SG_FLAG_Q_AT_TAIL flag to cause commands
     to be injected into the block layer with
     at_head=false.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
Reviewed-by: Mike Christie <michaelc@cs.wisc.edu>
Reviewed-by: Ewan D. Milne <emilne@redhat.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/scsi/sg.c
include/scsi/sg.h

index 37fb44b0074b6222c1fc777e7e139be3b3c98584..32425ac61096a934ff5aa932faaf814ffda8fdeb 100644 (file)
@@ -741,7 +741,7 @@ static int
 sg_common_write(Sg_fd * sfp, Sg_request * srp,
                unsigned char *cmnd, int timeout, int blocking)
 {
-       int k, data_dir;
+       int k, data_dir, at_head;
        Sg_device *sdp = sfp->parentdp;
        sg_io_hdr_t *hp = &srp->header;
 
@@ -785,11 +785,16 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
                break;
        }
        hp->duration = jiffies_to_msecs(jiffies);
+       if (hp->interface_id != '\0' && /* v3 (or later) interface */
+           (SG_FLAG_Q_AT_TAIL & hp->flags))
+               at_head = 0;
+       else
+               at_head = 1;
 
        srp->rq->timeout = timeout;
        kref_get(&sfp->f_ref); /* sg_rq_end_io() does kref_put(). */
        blk_execute_rq_nowait(sdp->device->request_queue, sdp->disk,
-                             srp->rq, 1, sg_rq_end_io);
+                             srp->rq, at_head, sg_rq_end_io);
        return 0;
 }
 
index d8c0c4307fcaa084d2e3d418f869fbfae3d44b72..9859355a7cf9944a0fd27726b602733b2eea243b 100644 (file)
@@ -86,6 +86,7 @@ typedef struct sg_io_hdr
 #define SG_FLAG_MMAP_IO 4       /* request memory mapped IO */
 #define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */
                                /* user space (debug indirect IO) */
+#define SG_FLAG_Q_AT_TAIL 0x10  /* default is Q_AT_HEAD */
 
 /* following 'info' values are "or"-ed together */
 #define SG_INFO_OK_MASK 0x1