]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/scsi/ide-scsi.c
block: unify request timeout handling
[linux-2.6-omap-h63xx.git] / drivers / scsi / ide-scsi.c
index 538552495d486da9f896e5cdc3067e360ea27109..81c16cba5417ff76a0f11006193e2747438e6154 100644 (file)
@@ -101,16 +101,23 @@ static struct ide_scsi_obj *ide_scsi_get(struct gendisk *disk)
 
        mutex_lock(&idescsi_ref_mutex);
        scsi = ide_scsi_g(disk);
-       if (scsi)
-               scsi_host_get(scsi->host);
+       if (scsi) {
+               if (ide_device_get(scsi->drive))
+                       scsi = NULL;
+               else
+                       scsi_host_get(scsi->host);
+       }
        mutex_unlock(&idescsi_ref_mutex);
        return scsi;
 }
 
 static void ide_scsi_put(struct ide_scsi_obj *scsi)
 {
+       ide_drive_t *drive = scsi->drive;
+
        mutex_lock(&idescsi_ref_mutex);
        scsi_host_put(scsi->host);
+       ide_device_put(drive);
        mutex_unlock(&idescsi_ref_mutex);
 }
 
@@ -201,15 +208,15 @@ static int idescsi_check_condition(ide_drive_t *drive,
 
        /* stuff a sense request in front of our current request */
        pc = kzalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
-       rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
+       rq = blk_get_request(drive->queue, READ, GFP_ATOMIC);
        buf = kzalloc(SCSI_SENSE_BUFFERSIZE, GFP_ATOMIC);
        if (!pc || !rq || !buf) {
                kfree(buf);
-               kfree(rq);
+               if (rq)
+                       blk_put_request(rq);
                kfree(pc);
                return -ENOMEM;
        }
-       blk_rq_init(NULL, rq);
        rq->special = (char *) pc;
        pc->rq = rq;
        pc->buf = buf;
@@ -226,6 +233,7 @@ static int idescsi_check_condition(ide_drive_t *drive,
                ide_scsi_hex_dump(pc->c, 6);
        }
        rq->rq_disk = scsi->disk;
+       rq->ref_count++;
        memcpy(rq->cmd, pc->c, 12);
        ide_do_drive_cmd(drive, rq);
        return 0;
@@ -272,7 +280,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
                        SCSI_SENSE_BUFFERSIZE);
                kfree(pc->buf);
                kfree(pc);
-               kfree(rq);
+               blk_put_request(rq);
                pc = opc;
                rq = pc->rq;
                pc->scsi_cmd->result = (CHECK_CONDITION << 1) |
@@ -303,7 +311,7 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
        pc->done(pc->scsi_cmd);
        spin_unlock_irqrestore(host->host_lock, flags);
        kfree(pc);
-       kfree(rq);
+       blk_put_request(rq);
        scsi->pc = NULL;
        return 0;
 }
@@ -577,6 +585,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        ide_drive_t *drive = scsi->drive;
        struct request *rq = NULL;
        struct ide_atapi_pc *pc = NULL;
+       int write = cmd->sc_data_direction == DMA_TO_DEVICE;
 
        if (!drive) {
                scmd_printk (KERN_ERR, cmd, "drive not present\n");
@@ -584,7 +593,7 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
        }
        scsi = drive_to_idescsi(drive);
        pc = kmalloc(sizeof(struct ide_atapi_pc), GFP_ATOMIC);
-       rq = kmalloc(sizeof(struct request), GFP_ATOMIC);
+       rq = blk_get_request(drive->queue, write, GFP_ATOMIC);
        if (rq == NULL || pc == NULL) {
                printk (KERN_ERR "ide-scsi: %s: out of memory\n", drive->name);
                goto abort;
@@ -603,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);
@@ -614,17 +623,18 @@ static int idescsi_queue (struct scsi_cmnd *cmd,
                }
        }
 
-       blk_rq_init(NULL, rq);
        rq->special = (char *) pc;
        rq->cmd_type = REQ_TYPE_SPECIAL;
        spin_unlock_irq(host->host_lock);
+       rq->ref_count++;
        memcpy(rq->cmd, pc->c, 12);
        blk_execute_rq_nowait(drive->queue, scsi->disk, rq, 0, NULL);
        spin_lock_irq(host->host_lock);
        return 0;
 abort:
        kfree (pc);
-       kfree (rq);
+       if (rq)
+               blk_put_request(rq);
        cmd->result = DID_ERROR << 16;
        done(cmd);
        return 0;
@@ -672,7 +682,9 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
 
                if (blk_sense_request(scsi->pc->rq))
                        kfree(scsi->pc->buf);
-               kfree(scsi->pc->rq);
+               /* we need to call blk_put_request twice. */
+               blk_put_request(scsi->pc->rq);
+               blk_put_request(scsi->pc->rq);
                kfree(scsi->pc);
                scsi->pc = NULL;
 
@@ -724,7 +736,7 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
                kfree(scsi->pc->buf);
        kfree(scsi->pc);
        scsi->pc = NULL;
-       kfree(req);
+       blk_put_request(req);
 
        /* now nuke the drive queue */
        while ((req = elv_next_request(drive->queue))) {