static int idescsi_eh_abort (struct scsi_cmnd *cmd) { idescsi_scsi_t *scsi = scsihost_to_idescsi(cmd->device->host); ide_drive_t *drive = scsi->drive; int busy; int ret = FAILED; /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */ if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) printk (KERN_WARNING "ide-scsi: abort called for %lu\n", cmd->serial_number); if (!drive) { printk (KERN_WARNING "ide-scsi: Drive not set in idescsi_eh_abort\n"); WARN_ON(1); goto no_drive; } /* First give it some more time, how much is "right" is hard to say :-( */ busy = ide_wait_not_busy(HWIF(drive), 100); /* FIXME - uses mdelay which causes latency? */ if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) printk (KERN_WARNING "ide-scsi: drive did%s become ready\n", busy?" not":""); spin_lock_irq(&ide_lock); /* If there is no pc running we're done (our interrupt took care of it) */ if (!scsi->pc) { ret = SUCCESS; goto ide_unlock; } /* It's somewhere in flight. Does ide subsystem agree? */ if (scsi->pc->scsi_cmd->serial_number == cmd->serial_number && !busy && elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != scsi->pc->rq) { /* * FIXME - not sure this condition can ever occur */ printk (KERN_ERR "ide-scsi: cmd aborted!\n"); if (blk_sense_request(scsi->pc->rq)) kfree(scsi->pc->buf); /* 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; ret = SUCCESS; } ide_unlock: spin_unlock_irq(&ide_lock); no_drive: if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) printk (KERN_WARNING "ide-scsi: abort returns %s\n", ret == SUCCESS?"success":"failed"); return ret; }
static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup) { ide_drive_t *drive, *best; repeat: best = NULL; drive = hwgroup->drive; /* * drive is doing pre-flush, ordered write, post-flush sequence. even * though that is 3 requests, it must be seen as a single transaction. * we must not preempt this drive until that is complete */ if (blk_queue_flushing(drive->queue)) { /* * small race where queue could get replugged during * the 3-request flush cycle, just yank the plug since * we want it to finish asap */ blk_remove_plug(drive->queue); return drive; } do { u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING); u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING)); if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) && !elv_queue_empty(drive->queue)) { if (best == NULL || (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) || (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) { if (!blk_queue_plugged(drive->queue)) best = drive; } } } while ((drive = drive->next) != hwgroup->drive); if (best && (best->dev_flags & IDE_DFLAG_NICE1) && (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) { long t = (signed long)(WAKEUP(best) - jiffies); if (t >= WAIT_MIN_SLEEP) { /* * We *may* have some time to spare, but first let's see if * someone can potentially benefit from our nice mood today.. */ drive = best->next; do { if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0 && time_before(jiffies - best->service_time, WAKEUP(drive)) && time_before(WAKEUP(drive), jiffies + t)) { ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP)); goto repeat; } } while ((drive = drive->next) != best); }
static void ide_plug_device(ide_drive_t *drive) { struct request_queue *q = drive->queue; unsigned long flags; spin_lock_irqsave(q->queue_lock, flags); if (!elv_queue_empty(q)) blk_plug_device(q); spin_unlock_irqrestore(q->queue_lock, flags); }
static void blk_flush_complete_seq_end_io(struct request_queue *q, unsigned seq, int error) { bool was_empty = elv_queue_empty(q); struct request *next_rq; next_rq = blk_flush_complete_seq(q, seq, error); /* * Moving a request silently to empty queue_head may stall the * queue. Kick the queue in those cases. */ if (was_empty && next_rq) __blk_run_queue(q); }
/* * Issue a new request to a device. */ void do_ide_request(struct request_queue *q) { ide_drive_t *drive = q->queuedata; ide_hwif_t *hwif = drive->hwif; struct ide_host *host = hwif->host; struct request *rq = NULL; ide_startstop_t startstop; /* * drive is doing pre-flush, ordered write, post-flush sequence. even * though that is 3 requests, it must be seen as a single transaction. * we must not preempt this drive until that is complete */ if (blk_queue_flushing(q)) /* * small race where queue could get replugged during * the 3-request flush cycle, just yank the plug since * we want it to finish asap */ blk_remove_plug(q); spin_unlock_irq(q->queue_lock); if (ide_lock_host(host, hwif)) goto plug_device_2; spin_lock_irq(&hwif->lock); if (!ide_lock_port(hwif)) { ide_hwif_t *prev_port; repeat: prev_port = hwif->host->cur_port; hwif->rq = NULL; if (drive->dev_flags & IDE_DFLAG_SLEEPING) { if (time_before(drive->sleep, jiffies)) { ide_unlock_port(hwif); goto plug_device; } } if ((hwif->host->host_flags & IDE_HFLAG_SERIALIZE) && hwif != prev_port) { /* * set nIEN for previous port, drives in the * quirk_list may not like intr setups/cleanups */ if (prev_port && prev_port->cur_dev->quirk_list == 0) prev_port->tp_ops->set_irq(prev_port, 0); hwif->host->cur_port = hwif; } hwif->cur_dev = drive; drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED); spin_unlock_irq(&hwif->lock); spin_lock_irq(q->queue_lock); /* * we know that the queue isn't empty, but this can happen * if the q->prep_rq_fn() decides to kill a request */ rq = elv_next_request(drive->queue); spin_unlock_irq(q->queue_lock); spin_lock_irq(&hwif->lock); if (!rq) { ide_unlock_port(hwif); goto out; } /* * Sanity: don't accept a request that isn't a PM request * if we are currently power managed. This is very important as * blk_stop_queue() doesn't prevent the elv_next_request() * above to return us whatever is in the queue. Since we call * ide_do_request() ourselves, we end up taking requests while * the queue is blocked... * * We let requests forced at head of queue with ide-preempt * though. I hope that doesn't happen too much, hopefully not * unless the subdriver triggers such a thing in its own PM * state machine. */ if ((drive->dev_flags & IDE_DFLAG_BLOCKED) && blk_pm_request(rq) == 0 && (rq->cmd_flags & REQ_PREEMPT) == 0) { /* there should be no pending command at this point */ ide_unlock_port(hwif); goto plug_device; } hwif->rq = rq; spin_unlock_irq(&hwif->lock); startstop = start_request(drive, rq); spin_lock_irq(&hwif->lock); if (startstop == ide_stopped) goto repeat; } else goto plug_device; out: spin_unlock_irq(&hwif->lock); if (rq == NULL) ide_unlock_host(host); spin_lock_irq(q->queue_lock); return; plug_device: spin_unlock_irq(&hwif->lock); ide_unlock_host(host); plug_device_2: spin_lock_irq(q->queue_lock); if (!elv_queue_empty(q)) blk_plug_device(q); }