]> git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/commitdiff
block: unify request timeout handling
authorJens Axboe <jens.axboe@oracle.com>
Sun, 14 Sep 2008 12:55:09 +0000 (05:55 -0700)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 9 Oct 2008 06:56:13 +0000 (08:56 +0200)
Right now SCSI and others do their own command timeout handling.
Move those bits to the block layer.

Instead of having a timer per command, we try to be a bit more clever
and simply have one per-queue. This avoids the overhead of having to
tear down and setup a timer for each command, so it will result in a lot
less timer fiddling.

Signed-off-by: Mike Anderson <andmike@linux.vnet.ibm.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
39 files changed:
block/Makefile
block/blk-core.c
block/blk-settings.c
block/blk-softirq.c
block/blk-timeout.c [new file with mode: 0644]
block/blk.h
block/elevator.c
drivers/ata/libata-eh.c
drivers/ata/libata.h
drivers/scsi/aacraid/aachba.c
drivers/scsi/gdth.c
drivers/scsi/gdth.h
drivers/scsi/gdth_proc.c
drivers/scsi/gdth_proc.h
drivers/scsi/ibmvscsi/ibmvscsi.c
drivers/scsi/ide-scsi.c
drivers/scsi/ipr.c
drivers/scsi/ips.c
drivers/scsi/libiscsi.c
drivers/scsi/libsas/sas_ata.c
drivers/scsi/libsas/sas_internal.h
drivers/scsi/libsas/sas_scsi_host.c
drivers/scsi/megaraid/megaraid_sas.c
drivers/scsi/ncr53c8xx.c
drivers/scsi/qla1280.c
drivers/scsi/qla4xxx/ql4_os.c
drivers/scsi/scsi.c
drivers/scsi/scsi_error.c
drivers/scsi/scsi_lib.c
drivers/scsi/scsi_priv.h
drivers/scsi/scsi_sysfs.c
drivers/scsi/scsi_transport_fc.c
drivers/scsi/sd.c
drivers/scsi/sr.c
drivers/scsi/sym53c8xx_2/sym_glue.c
include/linux/blkdev.h
include/scsi/scsi_cmnd.h
include/scsi/scsi_host.h
include/scsi/scsi_transport.h

index 0da976ce67dd218a54241be36b2f624e3e19d951..bfe73049f939925aa03136121f7a56b0914eab4d 100644 (file)
@@ -4,8 +4,8 @@
 
 obj-$(CONFIG_BLOCK) := elevator.o blk-core.o blk-tag.o blk-sysfs.o \
                        blk-barrier.o blk-settings.o blk-ioc.o blk-map.o \
-                       blk-exec.o blk-merge.o blk-softirq.o ioctl.o genhd.o \
-                       scsi_ioctl.o cmd-filter.o
+                       blk-exec.o blk-merge.o blk-softirq.o blk-timeout.o \
+                       ioctl.o genhd.o scsi_ioctl.o cmd-filter.o
 
 obj-$(CONFIG_BLK_DEV_BSG)      += bsg.o
 obj-$(CONFIG_IOSCHED_NOOP)     += noop-iosched.o
index f25eb9786d94f6fa7d0846fda46043e2712fd6ce..d768a8ddc173a7ae5b0162c43218bd244e1aadb7 100644 (file)
@@ -110,6 +110,7 @@ void blk_rq_init(struct request_queue *q, struct request *rq)
        memset(rq, 0, sizeof(*rq));
 
        INIT_LIST_HEAD(&rq->queuelist);
+       INIT_LIST_HEAD(&rq->timeout_list);
        rq->cpu = -1;
        rq->q = q;
        rq->sector = rq->hard_sector = (sector_t) -1;
@@ -490,6 +491,8 @@ struct request_queue *blk_alloc_queue_node(gfp_t gfp_mask, int node_id)
        }
 
        init_timer(&q->unplug_timer);
+       setup_timer(&q->timeout, blk_rq_timed_out_timer, (unsigned long) q);
+       INIT_LIST_HEAD(&q->timeout_list);
 
        kobject_init(&q->kobj, &blk_queue_ktype);
 
@@ -897,6 +900,8 @@ EXPORT_SYMBOL(blk_start_queueing);
  */
 void blk_requeue_request(struct request_queue *q, struct request *rq)
 {
+       blk_delete_timer(rq);
+       blk_clear_rq_complete(rq);
        blk_add_trace_rq(q, rq, BLK_TA_REQUEUE);
 
        if (blk_rq_tagged(rq))
@@ -1650,6 +1655,8 @@ static void end_that_request_last(struct request *req, int error)
 {
        struct gendisk *disk = req->rq_disk;
 
+       blk_delete_timer(req);
+
        if (blk_rq_tagged(req))
                blk_queue_end_tag(req->q, req);
 
index d70692badcdb75fb9ca4021b763c31a60dd156e7..1d0330d0b40a7103cf81f22cfec9726935e449f6 100644 (file)
@@ -77,6 +77,18 @@ void blk_queue_softirq_done(struct request_queue *q, softirq_done_fn *fn)
 }
 EXPORT_SYMBOL(blk_queue_softirq_done);
 
+void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout)
+{
+       q->rq_timeout = timeout;
+}
+EXPORT_SYMBOL_GPL(blk_queue_rq_timeout);
+
+void blk_queue_rq_timed_out(struct request_queue *q, rq_timed_out_fn *fn)
+{
+       q->rq_timed_out_fn = fn;
+}
+EXPORT_SYMBOL_GPL(blk_queue_rq_timed_out);
+
 /**
  * blk_queue_make_request - define an alternate make_request function for a device
  * @q:  the request queue for the device to be affected
index 3a1af551191e0986e3f5b1462d7cdb0c01b21a5d..7ab344afb16f8e26d7cd2fed856ebb4c62202d55 100644 (file)
@@ -101,18 +101,7 @@ static struct notifier_block __cpuinitdata blk_cpu_notifier = {
        .notifier_call  = blk_cpu_notify,
 };
 
-/**
- * blk_complete_request - end I/O on a request
- * @req:      the request being processed
- *
- * Description:
- *     Ends all I/O on a request. It does not handle partial completions,
- *     unless the driver actually implements this in its completion callback
- *     through requeueing. The actual completion happens out-of-order,
- *     through a softirq handler. The user must have registered a completion
- *     callback through blk_queue_softirq_done().
- **/
-void blk_complete_request(struct request *req)
+void __blk_complete_request(struct request *req)
 {
        struct request_queue *q = req->q;
        unsigned long flags;
@@ -151,6 +140,23 @@ do_local:
 
        local_irq_restore(flags);
 }
+
+/**
+ * blk_complete_request - end I/O on a request
+ * @req:      the request being processed
+ *
+ * Description:
+ *     Ends all I/O on a request. It does not handle partial completions,
+ *     unless the driver actually implements this in its completion callback
+ *     through requeueing. The actual completion happens out-of-order,
+ *     through a softirq handler. The user must have registered a completion
+ *     callback through blk_queue_softirq_done().
+ **/
+void blk_complete_request(struct request *req)
+{
+       if (!blk_mark_rq_complete(req))
+               __blk_complete_request(req);
+}
 EXPORT_SYMBOL(blk_complete_request);
 
 __init int blk_softirq_init(void)
diff --git a/block/blk-timeout.c b/block/blk-timeout.c
new file mode 100644 (file)
index 0000000..b36d07b
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * Functions related to generic timeout handling of requests.
+ */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/blkdev.h>
+
+#include "blk.h"
+
+/*
+ * blk_delete_timer - Delete/cancel timer for a given function.
+ * @req:       request that we are canceling timer for
+ *
+ */
+void blk_delete_timer(struct request *req)
+{
+       struct request_queue *q = req->q;
+
+       /*
+        * Nothing to detach
+        */
+       if (!q->rq_timed_out_fn || !req->deadline)
+               return;
+
+       list_del_init(&req->timeout_list);
+
+       if (list_empty(&q->timeout_list))
+               del_timer(&q->timeout);
+}
+
+static void blk_rq_timed_out(struct request *req)
+{
+       struct request_queue *q = req->q;
+       enum blk_eh_timer_return ret;
+
+       ret = q->rq_timed_out_fn(req);
+       switch (ret) {
+       case BLK_EH_HANDLED:
+               __blk_complete_request(req);
+               break;
+       case BLK_EH_RESET_TIMER:
+               blk_clear_rq_complete(req);
+               blk_add_timer(req);
+               break;
+       case BLK_EH_NOT_HANDLED:
+               /*
+                * LLD handles this for now but in the future
+                * we can send a request msg to abort the command
+                * and we can move more of the generic scsi eh code to
+                * the blk layer.
+                */
+               break;
+       default:
+               printk(KERN_ERR "block: bad eh return: %d\n", ret);
+               break;
+       }
+}
+
+void blk_rq_timed_out_timer(unsigned long data)
+{
+       struct request_queue *q = (struct request_queue *) data;
+       unsigned long flags, uninitialized_var(next), next_set = 0;
+       struct request *rq, *tmp;
+
+       spin_lock_irqsave(q->queue_lock, flags);
+
+       list_for_each_entry_safe(rq, tmp, &q->timeout_list, timeout_list) {
+               if (time_after_eq(jiffies, rq->deadline)) {
+                       list_del_init(&rq->timeout_list);
+
+                       /*
+                        * Check if we raced with end io completion
+                        */
+                       if (blk_mark_rq_complete(rq))
+                               continue;
+                       blk_rq_timed_out(rq);
+               }
+               if (!next_set) {
+                       next = rq->deadline;
+                       next_set = 1;
+               } else if (time_after(next, rq->deadline))
+                       next = rq->deadline;
+       }
+
+       if (next_set && !list_empty(&q->timeout_list))
+               mod_timer(&q->timeout, round_jiffies(next));
+
+       spin_unlock_irqrestore(q->queue_lock, flags);
+}
+
+/**
+ * blk_abort_request -- Request request recovery for the specified command
+ * @req:       pointer to the request of interest
+ *
+ * This function requests that the block layer start recovery for the
+ * request by deleting the timer and calling the q's timeout function.
+ * LLDDs who implement their own error recovery MAY ignore the timeout
+ * event if they generated blk_abort_req. Must hold queue lock.
+ */
+void blk_abort_request(struct request *req)
+{
+       blk_delete_timer(req);
+       blk_rq_timed_out(req);
+}
+EXPORT_SYMBOL_GPL(blk_abort_request);
+
+/**
+ * blk_add_timer - Start timeout timer for a single request
+ * @req:       request that is about to start running.
+ *
+ * Notes:
+ *    Each request has its own timer, and as it is added to the queue, we
+ *    set up the timer. When the request completes, we cancel the timer.
+ */
+void blk_add_timer(struct request *req)
+{
+       struct request_queue *q = req->q;
+       unsigned long expiry;
+
+       if (!q->rq_timed_out_fn)
+               return;
+
+       BUG_ON(!list_empty(&req->timeout_list));
+       BUG_ON(test_bit(REQ_ATOM_COMPLETE, &req->atomic_flags));
+
+       if (req->timeout)
+               req->deadline = jiffies + req->timeout;
+       else {
+               req->deadline = jiffies + q->rq_timeout;
+               /*
+                * Some LLDs, like scsi, peek at the timeout to prevent
+                * a command from being retried forever.
+                */
+               req->timeout = q->rq_timeout;
+       }
+       list_add_tail(&req->timeout_list, &q->timeout_list);
+
+       /*
+        * If the timer isn't already pending or this timeout is earlier
+        * than an existing one, modify the timer. Round to next nearest
+        * second.
+        */
+       expiry = round_jiffies(req->deadline);
+
+       /*
+        * We use ->deadline == 0 to detect whether a timer was added or
+        * not, so just increase to next jiffy for that specific case
+        */
+       if (unlikely(!req->deadline))
+               req->deadline = 1;
+
+       if (!timer_pending(&q->timeout) ||
+           time_before(expiry, q->timeout.expires))
+               mod_timer(&q->timeout, expiry);
+}
index de74254cb9161918121e10189fc095abfc897b1d..a4f4a50aefaabaec703ba77d777e505c27a1c450 100644 (file)
@@ -17,6 +17,30 @@ void __blk_queue_free_tags(struct request_queue *q);
 
 void blk_unplug_work(struct work_struct *work);
 void blk_unplug_timeout(unsigned long data);
+void blk_rq_timed_out_timer(unsigned long data);
+void blk_delete_timer(struct request *);
+void blk_add_timer(struct request *);
+
+/*
+ * Internal atomic flags for request handling
+ */
+enum rq_atomic_flags {
+       REQ_ATOM_COMPLETE = 0,
+};
+
+/*
+ * EH timer and IO completion will both attempt to 'grab' the request, make
+ * sure that only one of them suceeds
+ */
+static inline int blk_mark_rq_complete(struct request *rq)
+{
+       return test_and_set_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
+}
+
+static inline void blk_clear_rq_complete(struct request *rq)
+{
+       clear_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags);
+}
 
 struct io_context *current_io_context(gfp_t gfp_flags, int node);
 
index 8e3fc3afc77b31e0abef2c42b5c1fe315f789968..a91fc59edd017f7ac3cdbe8626f0b95c56dd7c2d 100644 (file)
@@ -36,6 +36,8 @@
 #include <linux/hash.h>
 #include <linux/uaccess.h>
 
+#include "blk.h"
+
 static DEFINE_SPINLOCK(elv_list_lock);
 static LIST_HEAD(elv_list);
 
@@ -771,6 +773,12 @@ struct request *elv_next_request(struct request_queue *q)
                         */
                        rq->cmd_flags |= REQ_STARTED;
                        blk_add_trace_rq(q, rq, BLK_TA_ISSUE);
+
+                       /*
+                        * We are now handing the request to the hardware,
+                        * add the timeout handler
+                        */
+                       blk_add_timer(rq);
                }
 
                if (!q->boundary_rq || q->boundary_rq == rq) {
index c1db2f234d2e409d21851c91c77a292cc631406e..bd0b2bc76f1077761fb1aa56d4d238305468abb6 100644 (file)
@@ -33,6 +33,7 @@
  */
 
 #include <linux/kernel.h>
+#include <linux/blkdev.h>
 #include <linux/pci.h>
 #include <scsi/scsi.h>
 #include <scsi/scsi_host.h>
@@ -457,29 +458,29 @@ static void ata_eh_clear_action(struct ata_link *link, struct ata_device *dev,
  *     RETURNS:
  *     EH_HANDLED or EH_NOT_HANDLED
  */
-enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
+enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd)
 {
        struct Scsi_Host *host = cmd->device->host;
        struct ata_port *ap = ata_shost_to_port(host);
        unsigned long flags;
        struct ata_queued_cmd *qc;
-       enum scsi_eh_timer_return ret;
+       enum blk_eh_timer_return ret;
 
        DPRINTK("ENTER\n");
 
        if (ap->ops->error_handler) {
-               ret = EH_NOT_HANDLED;
+               ret = BLK_EH_NOT_HANDLED;
                goto out;
        }
 
-       ret = EH_HANDLED;
+       ret = BLK_EH_HANDLED;
        spin_lock_irqsave(ap->lock, flags);
        qc = ata_qc_from_tag(ap, ap->link.active_tag);
        if (qc) {
                WARN_ON(qc->scsicmd != cmd);
                qc->flags |= ATA_QCFLAG_EH_SCHEDULED;
                qc->err_mask |= AC_ERR_TIMEOUT;
-               ret = EH_NOT_HANDLED;
+               ret = BLK_EH_NOT_HANDLED;
        }
        spin_unlock_irqrestore(ap->lock, flags);
 
@@ -831,7 +832,7 @@ void ata_qc_schedule_eh(struct ata_queued_cmd *qc)
         * Note that ATA_QCFLAG_FAILED is unconditionally set after
         * this function completes.
         */
-       scsi_req_abort_cmd(qc->scsicmd);
+       blk_abort_request(qc->scsicmd->request);
 }
 
 /**
index ade5c75b61446c75adb4174ea3c967c872c548fa..24f5005478b004df41550a6c64f055e2314d7620 100644 (file)
@@ -152,7 +152,7 @@ extern int ata_bus_probe(struct ata_port *ap);
 /* libata-eh.c */
 extern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd);
 extern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd);
-extern enum scsi_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
+extern enum blk_eh_timer_return ata_scsi_timed_out(struct scsi_cmnd *cmd);
 extern void ata_scsi_error(struct Scsi_Host *host);
 extern void ata_port_wait_eh(struct ata_port *ap);
 extern void ata_eh_fastdrain_timerfn(unsigned long arg);
index aa4e77c252735c593e523ae4a9f516045b674733..8abfd06b5a72c19a766edd41706a9ec0b00a802b 100644 (file)
@@ -1139,7 +1139,7 @@ static struct aac_srb * aac_scsi_common(struct fib * fib, struct scsi_cmnd * cmd
        srbcmd->id       = cpu_to_le32(scmd_id(cmd));
        srbcmd->lun      = cpu_to_le32(cmd->device->lun);
        srbcmd->flags    = cpu_to_le32(flag);
-       timeout = cmd->timeout_per_command/HZ;
+       timeout = cmd->request->timeout/HZ;
        if (timeout == 0)
                timeout = 1;
        srbcmd->timeout  = cpu_to_le32(timeout);  // timeout in seconds
index 822d5214692bfe3663b5acb8987ffec5a0ec0cd5..c387c15a21282e250b6291ac9872ba91877a1dc2 100644 (file)
@@ -464,7 +464,6 @@ int __gdth_execute(struct scsi_device *sdev, gdth_cmd_str *gdtcmd, char *cmnd,
 
     /* use request field to save the ptr. to completion struct. */
     scp->request = (struct request *)&wait;
-    scp->timeout_per_command = timeout*HZ;
     scp->cmd_len = 12;
     scp->cmnd = cmnd;
     cmndinfo.priority = IOCTL_PRI;
@@ -1995,23 +1994,12 @@ static void gdth_putq(gdth_ha_str *ha, Scsi_Cmnd *scp, unchar priority)
     register Scsi_Cmnd *pscp;
     register Scsi_Cmnd *nscp;
     ulong flags;
-    unchar b, t;
 
     TRACE(("gdth_putq() priority %d\n",priority));
     spin_lock_irqsave(&ha->smp_lock, flags);
 
-    if (!cmndinfo->internal_command) {
+    if (!cmndinfo->internal_command)
         cmndinfo->priority = priority;
-        b = scp->device->channel;
-        t = scp->device->id;
-        if (priority >= DEFAULT_PRI) {
-            if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha,b)].lock) ||
-                (b==ha->virt_bus && t<MAX_HDRIVES && ha->hdr[t].lock)) {
-                TRACE2(("gdth_putq(): locked IO ->update_timeout()\n"));
-                cmndinfo->timeout = gdth_update_timeout(scp, 0);
-            }
-        }
-    }
 
     if (ha->req_first==NULL) {
         ha->req_first = scp;                    /* queue was empty */
@@ -3899,6 +3887,39 @@ static const char *gdth_info(struct Scsi_Host *shp)
     return ((const char *)ha->binfo.type_string);
 }
 
+static enum blk_eh_timer_return gdth_timed_out(struct scsi_cmnd *scp)
+{
+       gdth_ha_str *ha = shost_priv(scp->device->host);
+       struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
+       unchar b, t;
+       ulong flags;
+       enum blk_eh_timer_return retval = BLK_EH_NOT_HANDLED;
+
+       TRACE(("%s() cmd 0x%x\n", scp->cmnd[0], __func__));
+       b = scp->device->channel;
+       t = scp->device->id;
+
+       /*
+        * We don't really honor the command timeout, but we try to
+        * honor 6 times of the actual command timeout! So reset the
+        * timer if this is less than 6th timeout on this command!
+        */
+       if (++cmndinfo->timeout_count < 6)
+               retval = BLK_EH_RESET_TIMER;
+
+       /* Reset the timeout if it is locked IO */
+       spin_lock_irqsave(&ha->smp_lock, flags);
+       if ((b != ha->virt_bus && ha->raw[BUS_L2P(ha, b)].lock) ||
+           (b == ha->virt_bus && t < MAX_HDRIVES && ha->hdr[t].lock)) {
+               TRACE2(("%s(): locked IO, reset timeout\n", __func__));
+               retval = BLK_EH_RESET_TIMER;
+       }
+       spin_unlock_irqrestore(&ha->smp_lock, flags);
+
+       return retval;
+}
+
+
 static int gdth_eh_bus_reset(Scsi_Cmnd *scp)
 {
     gdth_ha_str *ha = shost_priv(scp->device->host);
@@ -3992,7 +4013,7 @@ static int gdth_queuecommand(struct scsi_cmnd *scp,
     BUG_ON(!cmndinfo);
 
     scp->scsi_done = done;
-    gdth_update_timeout(scp, scp->timeout_per_command * 6);
+    cmndinfo->timeout_count = 0;
     cmndinfo->priority = DEFAULT_PRI;
 
     return __gdth_queuecommand(ha, scp, cmndinfo);
@@ -4096,12 +4117,10 @@ static int ioc_lockdrv(void __user *arg)
             ha->hdr[j].lock = 1;
             spin_unlock_irqrestore(&ha->smp_lock, flags);
             gdth_wait_completion(ha, ha->bus_cnt, j);
-            gdth_stop_timeout(ha, ha->bus_cnt, j);
         } else {
             spin_lock_irqsave(&ha->smp_lock, flags);
             ha->hdr[j].lock = 0;
             spin_unlock_irqrestore(&ha->smp_lock, flags);
-            gdth_start_timeout(ha, ha->bus_cnt, j);
             gdth_next(ha);
         }
     } 
@@ -4539,18 +4558,14 @@ static int gdth_ioctl(struct inode *inode, struct file *filep,
                 spin_lock_irqsave(&ha->smp_lock, flags);
                 ha->raw[i].lock = 1;
                 spin_unlock_irqrestore(&ha->smp_lock, flags);
-                for (j = 0; j < ha->tid_cnt; ++j) {
+               for (j = 0; j < ha->tid_cnt; ++j)
                     gdth_wait_completion(ha, i, j);
-                    gdth_stop_timeout(ha, i, j);
-                }
             } else {
                 spin_lock_irqsave(&ha->smp_lock, flags);
                 ha->raw[i].lock = 0;
                 spin_unlock_irqrestore(&ha->smp_lock, flags);
-                for (j = 0; j < ha->tid_cnt; ++j) {
-                    gdth_start_timeout(ha, i, j);
+               for (j = 0; j < ha->tid_cnt; ++j)
                     gdth_next(ha);
-                }
             }
         } 
         break;
@@ -4644,6 +4659,7 @@ static struct scsi_host_template gdth_template = {
         .slave_configure        = gdth_slave_configure,
         .bios_param             = gdth_bios_param,
         .proc_info              = gdth_proc_info,
+       .eh_timed_out           = gdth_timed_out,
         .proc_name              = "gdth",
         .can_queue              = GDTH_MAXCMDS,
         .this_id                = -1,
index ca92476727cfae82b258107405023f9a98baf661..1646444e9bd58894ef8af3cadcfe3b2bd7287be0 100644 (file)
@@ -916,7 +916,7 @@ typedef struct {
         gdth_cmd_str *internal_cmd_str;         /* crier for internal messages*/
         dma_addr_t sense_paddr;                 /* sense dma-addr */
         unchar priority;
-        int timeout;
+       int timeout_count;                      /* # of timeout calls */
         volatile int wait_for_completion;
         ushort status;
         ulong32 info;
index ce0228e26aec24fe070acb47b93451b0c377af23..59349a316e137facdd9b7f76b412ac14f23190ae 100644 (file)
@@ -748,69 +748,3 @@ static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id)
     }
     spin_unlock_irqrestore(&ha->smp_lock, flags);
 }
-
-static void gdth_stop_timeout(gdth_ha_str *ha, int busnum, int id)
-{
-    ulong flags;
-    Scsi_Cmnd *scp;
-    unchar b, t;
-
-    spin_lock_irqsave(&ha->smp_lock, flags);
-
-    for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
-        struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
-        if (!cmndinfo->internal_command) {
-            b = scp->device->channel;
-            t = scp->device->id;
-            if (t == (unchar)id && b == (unchar)busnum) {
-                TRACE2(("gdth_stop_timeout(): update_timeout()\n"));
-                cmndinfo->timeout = gdth_update_timeout(scp, 0);
-            }
-        }
-    }
-    spin_unlock_irqrestore(&ha->smp_lock, flags);
-}
-
-static void gdth_start_timeout(gdth_ha_str *ha, int busnum, int id)
-{
-    ulong flags;
-    Scsi_Cmnd *scp;
-    unchar b, t;
-
-    spin_lock_irqsave(&ha->smp_lock, flags);
-
-    for (scp = ha->req_first; scp; scp = (Scsi_Cmnd *)scp->SCp.ptr) {
-        struct gdth_cmndinfo *cmndinfo = gdth_cmnd_priv(scp);
-        if (!cmndinfo->internal_command) {
-            b = scp->device->channel;
-            t = scp->device->id;
-            if (t == (unchar)id && b == (unchar)busnum) {
-                TRACE2(("gdth_start_timeout(): update_timeout()\n"));
-                gdth_update_timeout(scp, cmndinfo->timeout);
-            }
-        }
-    }
-    spin_unlock_irqrestore(&ha->smp_lock, flags);
-}
-
-static int gdth_update_timeout(Scsi_Cmnd *scp, int timeout)
-{
-    int oldto;
-
-    oldto = scp->timeout_per_command;
-    scp->timeout_per_command = timeout;
-
-    if (timeout == 0) {
-        del_timer(&scp->eh_timeout);
-        scp->eh_timeout.data = (unsigned long) NULL;
-        scp->eh_timeout.expires = 0;
-    } else {
-        if (scp->eh_timeout.data != (unsigned long) NULL) 
-            del_timer(&scp->eh_timeout);
-        scp->eh_timeout.data = (unsigned long) scp;
-        scp->eh_timeout.expires = jiffies + timeout;
-        add_timer(&scp->eh_timeout);
-    }
-
-    return oldto;
-}
index 45e6fdacf36e39d06eee15ba10e7c12f396673a5..9b900cc9ebe898dca7bb4ce12fd35851a6bb21bc 100644 (file)
@@ -20,9 +20,6 @@ static char *gdth_ioctl_alloc(gdth_ha_str *ha, int size, int scratch,
                               ulong64 *paddr);
 static void gdth_ioctl_free(gdth_ha_str *ha, int size, char *buf, ulong64 paddr);
 static void gdth_wait_completion(gdth_ha_str *ha, int busnum, int id);
-static void gdth_stop_timeout(gdth_ha_str *ha, int busnum, int id);
-static void gdth_start_timeout(gdth_ha_str *ha, int busnum, int id);
-static int gdth_update_timeout(Scsi_Cmnd *scp, int timeout);
 
 #endif
 
index 7b1502c0ab6e5e049a66058be068478ebc5886ec..87e09f35d3d4cb2bb50de263098d0a4c9ea2b66b 100644 (file)
@@ -756,7 +756,7 @@ static int ibmvscsi_queuecommand(struct scsi_cmnd *cmnd,
        init_event_struct(evt_struct,
                          handle_cmd_rsp,
                          VIOSRP_SRP_FORMAT,
-                         cmnd->timeout_per_command/HZ);
+                         cmnd->request->timeout/HZ);
 
        evt_struct->cmnd = cmnd;
        evt_struct->cmnd_done = done;
index 461331d3dc45f041fd23bb8c02cc0f87b6737fe8..81c16cba5417ff76a0f11006193e2747438e6154 100644 (file)
@@ -612,7 +612,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        pc->req_xfer = pc->buf_size = scsi_bufflen(cmd);
        pc->scsi_cmd = cmd;
        pc->done = done;
-       pc->timeout = jiffies + cmd->timeout_per_command;
+       pc->timeout = jiffies + cmd->request->timeout;
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) {
                printk ("ide-scsi: %s: que %lu, cmd = ", drive->name, cmd->serial_number);
index e7a3a655442562186328d81df9d81be9f744f5f6..d30eb7ba018e6dde266ac53253b95c8687dde8e8 100644 (file)
@@ -3670,7 +3670,8 @@ static int ipr_slave_configure(struct scsi_device *sdev)
                        sdev->no_uld_attach = 1;
                }
                if (ipr_is_vset_device(res)) {
-                       sdev->timeout = IPR_VSET_RW_TIMEOUT;
+                       blk_queue_rq_timeout(sdev->request_queue,
+                                            IPR_VSET_RW_TIMEOUT);
                        blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
                }
                if (ipr_is_vset_device(res) || ipr_is_scsi_disk(res))
index bc9e6ddf41df237ec5dd030950d42619174b883e..ef683f0d2b5a94c5f66626a49f3b954e9c0862ab 100644 (file)
@@ -3818,7 +3818,7 @@ ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
                scb->cmd.dcdb.segment_4G = 0;
                scb->cmd.dcdb.enhanced_sg = 0;
 
-               TimeOut = scb->scsi_cmd->timeout_per_command;
+               TimeOut = scb->scsi_cmd->request->timeout;
 
                if (ha->subsys->param[4] & 0x00100000) {        /* If NEW Tape DCDB is Supported */
                        if (!scb->sg_len) {
index 299e075a7b34295f6a8ea8721270a329913a3244..1eca82420aab06bbb96696fb916e8afddcd3890b 100644 (file)
@@ -1476,12 +1476,12 @@ static void iscsi_start_tx(struct iscsi_conn *conn)
                scsi_queue_work(conn->session->host, &conn->xmitwork);
 }
 
-static enum scsi_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
+static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
 {
        struct iscsi_cls_session *cls_session;
        struct iscsi_session *session;
        struct iscsi_conn *conn;
-       enum scsi_eh_timer_return rc = EH_NOT_HANDLED;
+       enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
 
        cls_session = starget_to_session(scsi_target(scmd->device));
        session = cls_session->dd_data;
@@ -1494,14 +1494,14 @@ static enum scsi_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
                 * We are probably in the middle of iscsi recovery so let
                 * that complete and handle the error.
                 */
-               rc = EH_RESET_TIMER;
+               rc = BLK_EH_RESET_TIMER;
                goto done;
        }
 
        conn = session->leadconn;
        if (!conn) {
                /* In the middle of shuting down */
-               rc = EH_RESET_TIMER;
+               rc = BLK_EH_RESET_TIMER;
                goto done;
        }
 
@@ -1513,20 +1513,21 @@ static enum scsi_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
         */
        if (time_before_eq(conn->last_recv + (conn->recv_timeout * HZ) +
                            (conn->ping_timeout * HZ), jiffies))
-               rc = EH_RESET_TIMER;
+               rc = BLK_EH_RESET_TIMER;
        /*
         * if we are about to check the transport then give the command
         * more time
         */
        if (time_before_eq(conn->last_recv + (conn->recv_timeout * HZ),
                           jiffies))
-               rc = EH_RESET_TIMER;
+               rc = BLK_EH_RESET_TIMER;
        /* if in the middle of checking the transport then give us more time */
        if (conn->ping_task)
-               rc = EH_RESET_TIMER;
+               rc = BLK_EH_RESET_TIMER;
 done:
        spin_unlock(&session->lock);
-       debug_scsi("return %s\n", rc == EH_RESET_TIMER ? "timer reset" : "nh");
+       debug_scsi("return %s\n", rc == BLK_EH_RESET_TIMER ?
+                                       "timer reset" : "nh");
        return rc;
 }
 
index 48ee8c7f5bdd270351bcdf0dae895e0ae572a3f2..837b095ba90dd40a9bf46953423e8abfa7732117 100644 (file)
@@ -398,7 +398,7 @@ void sas_ata_task_abort(struct sas_task *task)
 
        /* Bounce SCSI-initiated commands to the SCSI EH */
        if (qc->scsicmd) {
-               scsi_req_abort_cmd(qc->scsicmd);
+               blk_abort_request(qc->scsicmd->request);
                scsi_schedule_eh(qc->scsicmd->device->host);
                return;
        }
index b4f9368f116ac2002ac07741fd2f2ddc3b2ef33e..0001374bd6b251164d69d7fdf3b7ced78e4b5901 100644 (file)
@@ -55,7 +55,7 @@ void sas_unregister_phys(struct sas_ha_struct *sas_ha);
 int  sas_register_ports(struct sas_ha_struct *sas_ha);
 void sas_unregister_ports(struct sas_ha_struct *sas_ha);
 
-enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *);
+enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *);
 
 int  sas_init_queue(struct sas_ha_struct *sas_ha);
 int  sas_init_events(struct sas_ha_struct *sas_ha);
index a8e3ef309070ae9e0da26381668e0bd847b68e0b..744838780ada207964f5b8ffbc4749d6c098ae57 100644 (file)
@@ -673,43 +673,43 @@ out:
        return;
 }
 
-enum scsi_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
+enum blk_eh_timer_return sas_scsi_timed_out(struct scsi_cmnd *cmd)
 {
        struct sas_task *task = TO_SAS_TASK(cmd);
        unsigned long flags;
 
        if (!task) {
-               cmd->timeout_per_command /= 2;
+               cmd->request->timeout /= 2;
                SAS_DPRINTK("command 0x%p, task 0x%p, gone: %s\n",
-                           cmd, task, (cmd->timeout_per_command ?
-                           "EH_RESET_TIMER" : "EH_NOT_HANDLED"));
-               if (!cmd->timeout_per_command)
-                       return EH_NOT_HANDLED;
-               return EH_RESET_TIMER;
+                           cmd, task, (cmd->request->timeout ?
+                           "BLK_EH_RESET_TIMER" : "BLK_EH_NOT_HANDLED"));
+               if (!cmd->request->timeout)
+                       return BLK_EH_NOT_HANDLED;
+               return BLK_EH_RESET_TIMER;
        }
 
        spin_lock_irqsave(&task->task_state_lock, flags);
        BUG_ON(task->task_state_flags & SAS_TASK_STATE_ABORTED);
        if (task->task_state_flags & SAS_TASK_STATE_DONE) {
                spin_unlock_irqrestore(&task->task_state_lock, flags);
-               SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_HANDLED\n",
-                           cmd, task);
-               return EH_HANDLED;
+               SAS_DPRINTK("command 0x%p, task 0x%p, timed out: "
+                           "BLK_EH_HANDLED\n", cmd, task);
+               return BLK_EH_HANDLED;
        }
        if (!(task->task_state_flags & SAS_TASK_AT_INITIATOR)) {
                spin_unlock_irqrestore(&task->task_state_lock, flags);
                SAS_DPRINTK("command 0x%p, task 0x%p, not at initiator: "
-                           "EH_RESET_TIMER\n",
+                           "BLK_EH_RESET_TIMER\n",
                            cmd, task);
-               return EH_RESET_TIMER;
+               return BLK_EH_RESET_TIMER;
        }
        task->task_state_flags |= SAS_TASK_STATE_ABORTED;
        spin_unlock_irqrestore(&task->task_state_lock, flags);
 
-       SAS_DPRINTK("command 0x%p, task 0x%p, timed out: EH_NOT_HANDLED\n",
+       SAS_DPRINTK("command 0x%p, task 0x%p, timed out: BLK_EH_NOT_HANDLED\n",
                    cmd, task);
 
-       return EH_NOT_HANDLED;
+       return BLK_EH_NOT_HANDLED;
 }
 
 int sas_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
@@ -1039,7 +1039,7 @@ void sas_task_abort(struct sas_task *task)
                return;
        }
 
-       scsi_req_abort_cmd(sc);
+       blk_abort_request(sc->request);
        scsi_schedule_eh(sc->device->host);
 }
 
index 97b763378e7dca9e8de4678eeb013f25ac2da185..afe1de99876319ba40d7c28a884458a3bff1b91e 100644 (file)
@@ -1167,7 +1167,7 @@ static int megasas_generic_reset(struct scsi_cmnd *scmd)
  * cmd has not been completed within the timeout period.
  */
 static enum
-scsi_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
+blk_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
 {
        struct megasas_cmd *cmd = (struct megasas_cmd *)scmd->SCp.ptr;
        struct megasas_instance *instance;
@@ -1175,7 +1175,7 @@ scsi_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
 
        if (time_after(jiffies, scmd->jiffies_at_alloc +
                                (MEGASAS_DEFAULT_CMD_TIMEOUT * 2) * HZ)) {
-               return EH_NOT_HANDLED;
+               return BLK_EH_NOT_HANDLED;
        }
 
        instance = cmd->instance;
@@ -1189,7 +1189,7 @@ scsi_eh_timer_return megasas_reset_timer(struct scsi_cmnd *scmd)
 
                spin_unlock_irqrestore(instance->host->host_lock, flags);
        }
-       return EH_RESET_TIMER;
+       return BLK_EH_RESET_TIMER;
 }
 
 /**
index c57c94c0ffd237f1d39b0cf6ea164e737ac11643..3b7240e40819cb98a0024f031b964e306f17f990 100644 (file)
@@ -4170,8 +4170,8 @@ static int ncr_queue_command (struct ncb *np, struct scsi_cmnd *cmd)
        **
        **----------------------------------------------------
        */
-       if (np->settle_time && cmd->timeout_per_command >= HZ) {
-               u_long tlimit = jiffies + cmd->timeout_per_command - HZ;
+       if (np->settle_time && cmd->request->timeout >= HZ) {
+               u_long tlimit = jiffies + cmd->request->timeout - HZ;
                if (time_after(np->settle_time, tlimit))
                        np->settle_time = tlimit;
        }
index 37f9ba0cd798cf975a0139e5bf1fae99f5508923..b6cd12b2e9963468e32d00472ae3d0fd8a7d41bb 100644 (file)
@@ -2845,7 +2845,7 @@ qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
        memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
 
        /* Set ISP command timeout. */
-       pkt->timeout = cpu_to_le16(cmd->timeout_per_command/HZ);
+       pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
 
        /* Set device target ID and LUN */
        pkt->lun = SCSI_LUN_32(cmd);
@@ -3114,7 +3114,7 @@ qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
        memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
 
        /* Set ISP command timeout. */
-       pkt->timeout = cpu_to_le16(cmd->timeout_per_command/HZ);
+       pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
 
        /* Set device target ID and LUN */
        pkt->lun = SCSI_LUN_32(cmd);
index 88bebb13bc520ab0d3959426adcaf3f30986a320..de8279ad7d89dca83cc1e32e2f8fc5d091d7b3fb 100644 (file)
@@ -1542,7 +1542,7 @@ static int qla4xxx_eh_device_reset(struct scsi_cmnd *cmd)
        DEBUG2(printk(KERN_INFO
                      "scsi%ld: DEVICE_RESET cmd=%p jiffies = 0x%lx, to=%x,"
                      "dpc_flags=%lx, status=%x allowed=%d\n", ha->host_no,
-                     cmd, jiffies, cmd->timeout_per_command / HZ,
+                     cmd, jiffies, cmd->request->timeout / HZ,
                      ha->dpc_flags, cmd->result, cmd->allowed));
 
        /* FIXME: wait for hba to go online */
@@ -1598,7 +1598,7 @@ static int qla4xxx_eh_target_reset(struct scsi_cmnd *cmd)
        DEBUG2(printk(KERN_INFO
                      "scsi%ld: TARGET_DEVICE_RESET cmd=%p jiffies = 0x%lx, "
                      "to=%x,dpc_flags=%lx, status=%x allowed=%d\n",
-                     ha->host_no, cmd, jiffies, cmd->timeout_per_command / HZ,
+                     ha->host_no, cmd, jiffies, cmd->request->timeout / HZ,
                      ha->dpc_flags, cmd->result, cmd->allowed));
 
        stat = qla4xxx_reset_target(ha, ddb_entry);
index ee6be596503d1515dc855e6e5715267ac4edb4e1..dbeb86cafc0d9ca3d59205425186427e3dcab583 100644 (file)
@@ -291,7 +291,6 @@ struct scsi_cmnd *scsi_get_command(struct scsi_device *dev, gfp_t gfp_mask)
                unsigned long flags;
 
                cmd->device = dev;
-               init_timer(&cmd->eh_timeout);
                INIT_LIST_HEAD(&cmd->list);
                spin_lock_irqsave(&dev->list_lock, flags);
                list_add_tail(&cmd->list, &dev->cmd_list);
@@ -652,14 +651,19 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
        unsigned long timeout;
        int rtn = 0;
 
+       /*
+        * We will use a queued command if possible, otherwise we will
+        * emulate the queuing and calling of completion function ourselves.
+        */
+       atomic_inc(&cmd->device->iorequest_cnt);
+
        /* check if the device is still usable */
        if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
                /* in SDEV_DEL we error all commands. DID_NO_CONNECT
                 * returns an immediate error upwards, and signals
                 * that the device is no longer present */
                cmd->result = DID_NO_CONNECT << 16;
-               atomic_inc(&cmd->device->iorequest_cnt);
-               __scsi_done(cmd);
+               scsi_done(cmd);
                /* return 0 (because the command has been processed) */
                goto out;
        }
@@ -672,6 +676,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
                 * future requests should not occur until the device 
                 * transitions out of the suspend state.
                 */
+
                scsi_queue_insert(cmd, SCSI_MLQUEUE_DEVICE_BUSY);
 
                SCSI_LOG_MLQUEUE(3, printk("queuecommand : device blocked \n"));
@@ -714,20 +719,8 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
                host->resetting = 0;
        }
 
-       /* 
-        * AK: unlikely race here: for some reason the timer could
-        * expire before the serial number is set up below.
-        */
-       scsi_add_timer(cmd, cmd->timeout_per_command, scsi_times_out);
-
        scsi_log_send(cmd);
 
-       /*
-        * We will use a queued command if possible, otherwise we will
-        * emulate the queuing and calling of completion function ourselves.
-        */
-       atomic_inc(&cmd->device->iorequest_cnt);
-
        /*
         * Before we queue this command, check if the command
         * length exceeds what the host adapter can handle.
@@ -744,6 +737,12 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
        }
 
        spin_lock_irqsave(host->host_lock, flags);
+       /*
+        * AK: unlikely race here: for some reason the timer could
+        * expire before the serial number is set up below.
+        *
+        * TODO: kill serial or move to blk layer
+        */
        scsi_cmd_get_serial(host, cmd); 
 
        if (unlikely(host->shost_state == SHOST_DEL)) {
@@ -754,12 +753,8 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
        }
        spin_unlock_irqrestore(host->host_lock, flags);
        if (rtn) {
-               if (scsi_delete_timer(cmd)) {
-                       atomic_inc(&cmd->device->iodone_cnt);
-                       scsi_queue_insert(cmd,
-                                         (rtn == SCSI_MLQUEUE_DEVICE_BUSY) ?
-                                         rtn : SCSI_MLQUEUE_HOST_BUSY);
-               }
+               scsi_queue_insert(cmd, (rtn == SCSI_MLQUEUE_DEVICE_BUSY) ?
+                                               rtn : SCSI_MLQUEUE_HOST_BUSY);
                SCSI_LOG_MLQUEUE(3,
                    printk("queuecommand : request rejected\n"));
        }
@@ -769,24 +764,6 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
        return rtn;
 }
 
-/**
- * scsi_req_abort_cmd -- Request command recovery for the specified command
- * @cmd: pointer to the SCSI command of interest
- *
- * This function requests that SCSI Core start recovery for the
- * command by deleting the timer and adding the command to the eh
- * queue.  It can be called by either LLDDs or SCSI Core.  LLDDs who
- * implement their own error recovery MAY ignore the timeout event if
- * they generated scsi_req_abort_cmd.
- */
-void scsi_req_abort_cmd(struct scsi_cmnd *cmd)
-{
-       if (!scsi_delete_timer(cmd))
-               return;
-       scsi_times_out(cmd);
-}
-EXPORT_SYMBOL(scsi_req_abort_cmd);
-
 /**
  * scsi_done - Enqueue the finished SCSI command into the done queue.
  * @cmd: The SCSI Command for which a low-level device driver (LLDD) gives
@@ -802,42 +779,7 @@ EXPORT_SYMBOL(scsi_req_abort_cmd);
  */
 static void scsi_done(struct scsi_cmnd *cmd)
 {
-       /*
-        * We don't have to worry about this one timing out anymore.
-        * If we are unable to remove the timer, then the command
-        * has already timed out.  In which case, we have no choice but to
-        * let the timeout function run, as we have no idea where in fact
-        * that function could really be.  It might be on another processor,
-        * etc, etc.
-        */
-       if (!scsi_delete_timer(cmd))
-               return;
-       __scsi_done(cmd);
-}
-
-/* Private entry to scsi_done() to complete a command when the timer
- * isn't running --- used by scsi_times_out */
-void __scsi_done(struct scsi_cmnd *cmd)
-{
-       struct request *rq = cmd->request;
-
-       /*
-        * Set the serial numbers back to zero
-        */
-       cmd->serial_number = 0;
-
-       atomic_inc(&cmd->device->iodone_cnt);
-       if (cmd->result)
-               atomic_inc(&cmd->device->ioerr_cnt);
-
-       BUG_ON(!rq);
-
-       /*
-        * The uptodate/nbytes values don't matter, as we allow partial
-        * completes and thus will check this in the softirq callback
-        */
-       rq->completion_data = cmd;
-       blk_complete_request(rq);
+       blk_complete_request(cmd->request);
 }
 
 /* Move this to a header if it becomes more generally useful */
index 39ce3aba1dac5f459d668ee7ce4d15832918ec66..fecefa05cb62c4f586a1f1ed7183c4f93cbac902 100644 (file)
@@ -111,70 +111,9 @@ int scsi_eh_scmd_add(struct scsi_cmnd *scmd, int eh_flag)
        return ret;
 }
 
-/**
- * scsi_add_timer - Start timeout timer for a single scsi command.
- * @scmd:      scsi command that is about to start running.
- * @timeout:   amount of time to allow this command to run.
- * @complete:  timeout function to call if timer isn't canceled.
- *
- * Notes:
- *    This should be turned into an inline function.  Each scsi command
- *    has its own timer, and as it is added to the queue, we set up the
- *    timer.  When the command completes, we cancel the timer.
- */
-void scsi_add_timer(struct scsi_cmnd *scmd, int timeout,
-                   void (*complete)(struct scsi_cmnd *))
-{
-
-       /*
-        * If the clock was already running for this command, then
-        * first delete the timer.  The timer handling code gets rather
-        * confused if we don't do this.
-        */
-       if (scmd->eh_timeout.function)
-               del_timer(&scmd->eh_timeout);
-
-       scmd->eh_timeout.data = (unsigned long)scmd;
-       scmd->eh_timeout.expires = jiffies + timeout;
-       scmd->eh_timeout.function = (void (*)(unsigned long)) complete;
-
-       SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p, time:"
-                                         " %d, (%p)\n", __func__,
-                                         scmd, timeout, complete));
-
-       add_timer(&scmd->eh_timeout);
-}
-
-/**
- * scsi_delete_timer - Delete/cancel timer for a given function.
- * @scmd:      Cmd that we are canceling timer for
- *
- * Notes:
- *     This should be turned into an inline function.
- *
- * Return value:
- *     1 if we were able to detach the timer.  0 if we blew it, and the
- *     timer function has already started to run.
- */
-int scsi_delete_timer(struct scsi_cmnd *scmd)
-{
-       int rtn;
-
-       rtn = del_timer(&scmd->eh_timeout);
-
-       SCSI_LOG_ERROR_RECOVERY(5, printk("%s: scmd: %p,"
-                                        " rtn: %d\n", __func__,
-                                        scmd, rtn));
-
-       scmd->eh_timeout.data = (unsigned long)NULL;
-       scmd->eh_timeout.function = NULL;
-
-       return rtn;
-}
-
 /**
  * scsi_times_out - Timeout function for normal scsi commands.
- * @scmd:      Cmd that is timing out.
+ * @req:       request that is timing out.
  *
  * Notes:
  *     We do not need to lock this.  There is the potential for a race
@@ -182,9 +121,11 @@ int scsi_delete_timer(struct scsi_cmnd *scmd)
  *     normal completion function determines that the timer has already
  *     fired, then it mustn't do anything.
  */
-void scsi_times_out(struct scsi_cmnd *scmd)
+enum blk_eh_timer_return scsi_times_out(struct request *req)
 {
-       enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
+       struct scsi_cmnd *scmd = req->special;
+       enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);
+       enum blk_eh_timer_return rtn = BLK_EH_NOT_HANDLED;
 
        scsi_log_completion(scmd, TIMEOUT_ERROR);
 
@@ -196,22 +137,20 @@ void scsi_times_out(struct scsi_cmnd *scmd)
                eh_timed_out = NULL;
 
        if (eh_timed_out)
-               switch (eh_timed_out(scmd)) {
-               case EH_HANDLED:
-                       __scsi_done(scmd);
-                       return;
-               case EH_RESET_TIMER:
-                       scsi_add_timer(scmd, scmd->timeout_per_command,
-                                      scsi_times_out);
-                       return;
-               case EH_NOT_HANDLED:
+               rtn = eh_timed_out(scmd);
+               switch (rtn) {
+               case BLK_EH_NOT_HANDLED:
                        break;
+               default:
+                       return rtn;
                }
 
        if (unlikely(!scsi_eh_scmd_add(scmd, SCSI_EH_CANCEL_CMD))) {
                scmd->result |= DID_TIME_OUT << 16;
-               __scsi_done(scmd);
+               return BLK_EH_HANDLED;
        }
+
+       return BLK_EH_NOT_HANDLED;
 }
 
 /**
@@ -1793,7 +1732,6 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
 
        blk_rq_init(NULL, &req);
        scmd->request = &req;
-       memset(&scmd->eh_timeout, 0, sizeof(scmd->eh_timeout));
 
        scmd->cmnd = req.cmd;
 
@@ -1804,8 +1742,6 @@ scsi_reset_provider(struct scsi_device *dev, int flag)
 
        scmd->sc_data_direction         = DMA_BIDIRECTIONAL;
 
-       init_timer(&scmd->eh_timeout);
-
        spin_lock_irqsave(shost->host_lock, flags);
        shost->tmf_in_progress = 1;
        spin_unlock_irqrestore(shost->host_lock, flags);
index 62307bd794a924c1f04d6b6822aa61dd2ef875c3..e7686500e9dd2105df892f6f4920b67559db9916 100644 (file)
@@ -1181,7 +1181,6 @@ int scsi_setup_blk_pc_cmnd(struct scsi_device *sdev, struct request *req)
        
        cmd->transfersize = req->data_len;
        cmd->allowed = req->retries;
-       cmd->timeout_per_command = req->timeout;
        return BLKPREP_OK;
 }
 EXPORT_SYMBOL(scsi_setup_blk_pc_cmnd);
@@ -1416,17 +1415,26 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
        spin_unlock(shost->host_lock);
        spin_lock(sdev->request_queue->queue_lock);
 
-       __scsi_done(cmd);
+       blk_complete_request(req);
 }
 
 static void scsi_softirq_done(struct request *rq)
 {
-       struct scsi_cmnd *cmd = rq->completion_data;
-       unsigned long wait_for = (cmd->allowed + 1) * cmd->timeout_per_command;
+       struct scsi_cmnd *cmd = rq->special;
+       unsigned long wait_for = (cmd->allowed + 1) * rq->timeout;
        int disposition;
 
        INIT_LIST_HEAD(&cmd->eh_entry);
 
+       /*
+        * Set the serial numbers back to zero
+        */
+       cmd->serial_number = 0;
+
+       atomic_inc(&cmd->device->iodone_cnt);
+       if (cmd->result)
+               atomic_inc(&cmd->device->ioerr_cnt);
+
        disposition = scsi_decide_disposition(cmd);
        if (disposition != SUCCESS &&
            time_before(cmd->jiffies_at_alloc + wait_for, jiffies)) {
@@ -1675,6 +1683,7 @@ struct request_queue *scsi_alloc_queue(struct scsi_device *sdev)
 
        blk_queue_prep_rq(q, scsi_prep_fn);
        blk_queue_softirq_done(q, scsi_softirq_done);
+       blk_queue_rq_timed_out(q, scsi_times_out);
        return q;
 }
 
index 79f0f7511204594186a36bae6e62acb4c3cd1a9c..6cddd5dd323cbb578af7bd3bc8209bc1b9ce7736 100644 (file)
@@ -4,6 +4,7 @@
 #include <linux/device.h>
 
 struct request_queue;
+struct request;
 struct scsi_cmnd;
 struct scsi_device;
 struct scsi_host_template;
@@ -27,7 +28,6 @@ extern void scsi_exit_hosts(void);
 extern int scsi_dispatch_cmd(struct scsi_cmnd *cmd);
 extern int scsi_setup_command_freelist(struct Scsi_Host *shost);
 extern void scsi_destroy_command_freelist(struct Scsi_Host *shost);
-extern void __scsi_done(struct scsi_cmnd *cmd);
 #ifdef CONFIG_SCSI_LOGGING
 void scsi_log_send(struct scsi_cmnd *cmd);
 void scsi_log_completion(struct scsi_cmnd *cmd, int disposition);
@@ -49,10 +49,7 @@ extern int __init scsi_init_devinfo(void);
 extern void scsi_exit_devinfo(void);
 
 /* scsi_error.c */
-extern void scsi_add_timer(struct scsi_cmnd *, int,
-               void (*)(struct scsi_cmnd *));
-extern int scsi_delete_timer(struct scsi_cmnd *);
-extern void scsi_times_out(struct scsi_cmnd *cmd);
+extern enum blk_eh_timer_return scsi_times_out(struct request *req);
 extern int scsi_error_handler(void *host);
 extern int scsi_decide_disposition(struct scsi_cmnd *cmd);
 extern void scsi_eh_wakeup(struct Scsi_Host *shost);
index ab3c71869be55d9deeb8ca101c59faf80e140561..7f618ee5eceafdb55a3f68cef45ec9db708cf15f 100644 (file)
@@ -560,12 +560,15 @@ sdev_rd_attr (vendor, "%.8s\n");
 sdev_rd_attr (model, "%.16s\n");
 sdev_rd_attr (rev, "%.4s\n");
 
+/*
+ * TODO: can we make these symlinks to the block layer ones?
+ */
 static ssize_t
 sdev_show_timeout (struct device *dev, struct device_attribute *attr, char *buf)
 {
        struct scsi_device *sdev;
        sdev = to_scsi_device(dev);
-       return snprintf (buf, 20, "%d\n", sdev->timeout / HZ);
+       return snprintf(buf, 20, "%d\n", sdev->request_queue->rq_timeout / HZ);
 }
 
 static ssize_t
@@ -576,7 +579,7 @@ sdev_store_timeout (struct device *dev, struct device_attribute *attr,
        int timeout;
        sdev = to_scsi_device(dev);
        sscanf (buf, "%d\n", &timeout);
-       sdev->timeout = timeout * HZ;
+       blk_queue_rq_timeout(sdev->request_queue, timeout * HZ);
        return count;
 }
 static DEVICE_ATTR(timeout, S_IRUGO | S_IWUSR, sdev_show_timeout, sdev_store_timeout);
index 56823fd1fb8418811da8fc4418ec271b846b65da..9168883d0dfe09fb16a5123c6d6c0c46dafe3b5b 100644 (file)
@@ -1950,15 +1950,15 @@ static int fc_vport_match(struct attribute_container *cont,
  * Notes:
  *     This routine assumes no locks are held on entry.
  */
-static enum scsi_eh_timer_return
+static enum blk_eh_timer_return
 fc_timed_out(struct scsi_cmnd *scmd)
 {
        struct fc_rport *rport = starget_to_rport(scsi_target(scmd->device));
 
        if (rport->port_state == FC_PORTSTATE_BLOCKED)
-               return EH_RESET_TIMER;
+               return BLK_EH_RESET_TIMER;
 
-       return EH_NOT_HANDLED;
+       return BLK_EH_NOT_HANDLED;
 }
 
 /*
index cb115d1bf228437770c03b549f001e95a03ab83c..c0cf4acda7de9d4c6b52f8ba01b47a24ea4d03c2 100644 (file)
@@ -383,7 +383,6 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
        sector_t block = rq->sector;
        sector_t threshold;
        unsigned int this_count = rq->nr_sectors;
-       unsigned int timeout = sdp->timeout;
        int ret;
 
        if (rq->cmd_type == REQ_TYPE_BLOCK_PC) {
@@ -584,7 +583,6 @@ static int sd_prep_fn(struct request_queue *q, struct request *rq)
        SCpnt->transfersize = sdp->sector_size;
        SCpnt->underflow = this_count << 9;
        SCpnt->allowed = SD_MAX_RETRIES;
-       SCpnt->timeout_per_command = timeout;
 
        /*
         * This indicates that the command is ready from our end to be
@@ -1878,11 +1876,12 @@ static int sd_probe(struct device *dev)
        sdkp->openers = 0;
        sdkp->previous_state = 1;
 
-       if (!sdp->timeout) {
+       if (!sdp->request_queue->rq_timeout) {
                if (sdp->type != TYPE_MOD)
-                       sdp->timeout = SD_TIMEOUT;
+                       blk_queue_rq_timeout(sdp->request_queue, SD_TIMEOUT);
                else
-                       sdp->timeout = SD_MOD_TIMEOUT;
+                       blk_queue_rq_timeout(sdp->request_queue,
+                                            SD_MOD_TIMEOUT);
        }
 
        device_initialize(&sdkp->dev);
index 8dbe3798d5fd744ca43f19fbf63b3db0741a6a10..0f17009c99d2f75581ea96b30e3927f89beaa408 100644 (file)
@@ -331,7 +331,7 @@ static int sr_done(struct scsi_cmnd *SCpnt)
 
 static int sr_prep_fn(struct request_queue *q, struct request *rq)
 {
-       int block=0, this_count, s_size, timeout = SR_TIMEOUT;
+       int block = 0, this_count, s_size;
        struct scsi_cd *cd;
        struct scsi_cmnd *SCpnt;
        struct scsi_device *sdp = q->queuedata;
@@ -461,7 +461,6 @@ static int sr_prep_fn(struct request_queue *q, struct request *rq)
        SCpnt->transfersize = cd->device->sector_size;
        SCpnt->underflow = this_count << 9;
        SCpnt->allowed = MAX_RETRIES;
-       SCpnt->timeout_per_command = timeout;
 
        /*
         * This indicates that the command is ready from our end to be
@@ -620,6 +619,8 @@ static int sr_probe(struct device *dev)
        disk->fops = &sr_bdops;
        disk->flags = GENHD_FL_CD;
 
+       blk_queue_rq_timeout(sdev->request_queue, SR_TIMEOUT);
+
        cd->device = sdev;
        cd->disk = disk;
        cd->driver = &sr_template;
index d39107b7669bfb22e3fa1e278166dd2c2766616f..f4e6cde1fd0d5ed132723e57bfabac9c261f54cd 100644 (file)
@@ -519,8 +519,8 @@ static int sym53c8xx_queue_command(struct scsi_cmnd *cmd,
         *  Shorten our settle_time if needed for 
         *  this command not to time out.
         */
-       if (np->s.settle_time_valid && cmd->timeout_per_command) {
-               unsigned long tlimit = jiffies + cmd->timeout_per_command;
+       if (np->s.settle_time_valid && cmd->request->timeout) {
+               unsigned long tlimit = jiffies + cmd->request->timeout;
                tlimit -= SYM_CONF_TIMER_INTERVAL*2;
                if (time_after(np->s.settle_time, tlimit)) {
                        np->s.settle_time = tlimit;
index 9c25492604272827da2aaf80ded2850c66e03cf1..067f28b800722c366a22dbb21458874ad836d015 100644 (file)
@@ -147,6 +147,7 @@ struct request {
 
        unsigned int cmd_flags;
        enum rq_cmd_type_bits cmd_type;
+       unsigned long atomic_flags;
 
        /* Maintain bio traversal state for part by part I/O submission.
         * hard_* are block layer internals, no driver should touch them!
@@ -214,6 +215,8 @@ struct request {
        void *data;
        void *sense;
 
+       unsigned long deadline;
+       struct list_head timeout_list;
        unsigned int timeout;
        int retries;
 
@@ -266,6 +269,14 @@ typedef void (prepare_flush_fn) (struct request_queue *, struct request *);
 typedef void (softirq_done_fn)(struct request *);
 typedef int (dma_drain_needed_fn)(struct request *);
 
+enum blk_eh_timer_return {
+       BLK_EH_NOT_HANDLED,
+       BLK_EH_HANDLED,
+       BLK_EH_RESET_TIMER,
+};
+
+typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *);
+
 enum blk_queue_state {
        Queue_down,
        Queue_up,
@@ -311,6 +322,7 @@ struct request_queue
        merge_bvec_fn           *merge_bvec_fn;
        prepare_flush_fn        *prepare_flush_fn;
        softirq_done_fn         *softirq_done_fn;
+       rq_timed_out_fn         *rq_timed_out_fn;
        dma_drain_needed_fn     *dma_drain_needed;
 
        /*
@@ -386,6 +398,10 @@ struct request_queue
        unsigned int            nr_sorted;
        unsigned int            in_flight;
 
+       unsigned int            rq_timeout;
+       struct timer_list       timeout;
+       struct list_head        timeout_list;
+
        /*
         * sg stuff
         */
@@ -770,6 +786,8 @@ extern int blk_end_request_callback(struct request *rq, int error,
                                unsigned int nr_bytes,
                                int (drv_callback)(struct request *));
 extern void blk_complete_request(struct request *);
+extern void __blk_complete_request(struct request *);
+extern void blk_abort_request(struct request *);
 
 /*
  * blk_end_request() takes bytes instead of sectors as a complete size.
@@ -811,6 +829,8 @@ extern void blk_queue_dma_alignment(struct request_queue *, int);
 extern void blk_queue_update_dma_alignment(struct request_queue *, int);
 extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *);
 extern void blk_queue_set_discard(struct request_queue *, prepare_discard_fn *);
+extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *);
+extern void blk_queue_rq_timeout(struct request_queue *, unsigned int);
 extern struct backing_dev_info *blk_get_backing_dev_info(struct block_device *bdev);
 extern int blk_queue_ordered(struct request_queue *, unsigned, prepare_flush_fn *);
 extern int blk_do_ordered(struct request_queue *, struct request **);
index f9f6e793575c0b7114c3162b25e430978977d2eb..855bf95963e7e37e792ecf8485b66f2093efe2b7 100644 (file)
@@ -75,7 +75,6 @@ struct scsi_cmnd {
 
        int retries;
        int allowed;
-       int timeout_per_command;
 
        unsigned char prot_op;
        unsigned char prot_type;
@@ -86,7 +85,6 @@ struct scsi_cmnd {
        /* These elements define the operation we are about to perform */
        unsigned char *cmnd;
 
-       struct timer_list eh_timeout;   /* Used to time out the command. */
 
        /* These elements define the operation we ultimately want to perform */
        struct scsi_data_buffer sdb;
@@ -139,7 +137,6 @@ extern void scsi_put_command(struct scsi_cmnd *);
 extern void __scsi_put_command(struct Scsi_Host *, struct scsi_cmnd *,
                               struct device *);
 extern void scsi_finish_command(struct scsi_cmnd *cmd);
-extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
 
 extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
                                 size_t *offset, size_t *len);
index 44a55d1bf530c070e86eb8381901a3ba63dfd51c..d123ca84e732bf711fb965c66db8017ad468ec6a 100644 (file)
@@ -43,13 +43,6 @@ struct blk_queue_tags;
 #define DISABLE_CLUSTERING 0
 #define ENABLE_CLUSTERING 1
 
-enum scsi_eh_timer_return {
-       EH_NOT_HANDLED,
-       EH_HANDLED,
-       EH_RESET_TIMER,
-};
-
-
 struct scsi_host_template {
        struct module *module;
        const char *name;
@@ -347,7 +340,7 @@ struct scsi_host_template {
         *
         * Status: OPTIONAL
         */
-       enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
+       enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);
 
        /*
         * Name of proc directory
index 490bd13a634cc7eff4e61bfab5104b1e28047e2a..0de32cd4e8a7c21d3a931c8d81381577b9853bb4 100644 (file)
@@ -21,6 +21,7 @@
 #define SCSI_TRANSPORT_H
 
 #include <linux/transport_class.h>
+#include <linux/blkdev.h>
 #include <scsi/scsi_host.h>
 #include <scsi/scsi_device.h>
 
@@ -64,7 +65,7 @@ struct scsi_transport_template {
         *                      begin counting again
         * EH_NOT_HANDLED       Begin normal error recovery
         */
-       enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
+       enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);
 
        /*
         * Used as callback for the completion of i_t_nexus request