@@ -466,14 +466,10 @@ void do_ide_request(struct request_queue *q)
466466
467467 if (!ide_lock_port (hwif )) {
468468 ide_hwif_t * prev_port ;
469+
470+ WARN_ON_ONCE (hwif -> rq );
469471repeat :
470472 prev_port = hwif -> host -> cur_port ;
471-
472- if (drive -> dev_flags & IDE_DFLAG_BLOCKED )
473- rq = hwif -> rq ;
474- else
475- WARN_ON_ONCE (hwif -> rq );
476-
477473 if (drive -> dev_flags & IDE_DFLAG_SLEEPING &&
478474 time_after (drive -> sleep , jiffies )) {
479475 ide_unlock_port (hwif );
@@ -500,29 +496,43 @@ void do_ide_request(struct request_queue *q)
500496 hwif -> cur_dev = drive ;
501497 drive -> dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED );
502498
503- if ( rq == NULL ) {
504- spin_unlock_irq ( & hwif -> lock );
505- spin_lock_irq ( q -> queue_lock );
506- /*
507- * we know that the queue isn't empty, but this can
508- * happen if ->prep_rq_fn() decides to kill a request
509- */
499+ spin_unlock_irq ( & hwif -> lock );
500+ spin_lock_irq ( q -> queue_lock );
501+ /*
502+ * we know that the queue isn't empty, but this can happen
503+ * if the q->prep_rq_fn() decides to kill a request
504+ */
505+ if (! rq )
510506 rq = blk_fetch_request (drive -> queue );
511- spin_unlock_irq (q -> queue_lock );
512- spin_lock_irq (& hwif -> lock );
513507
514- if (rq == NULL ) {
515- ide_unlock_port (hwif );
516- goto out ;
517- }
508+ spin_unlock_irq (q -> queue_lock );
509+ spin_lock_irq (& hwif -> lock );
510+
511+ if (!rq ) {
512+ ide_unlock_port (hwif );
513+ goto out ;
518514 }
519515
520516 /*
521517 * Sanity: don't accept a request that isn't a PM request
522- * if we are currently power managed.
518+ * if we are currently power managed. This is very important as
519+ * blk_stop_queue() doesn't prevent the blk_fetch_request()
520+ * above to return us whatever is in the queue. Since we call
521+ * ide_do_request() ourselves, we end up taking requests while
522+ * the queue is blocked...
523+ *
524+ * We let requests forced at head of queue with ide-preempt
525+ * though. I hope that doesn't happen too much, hopefully not
526+ * unless the subdriver triggers such a thing in its own PM
527+ * state machine.
523528 */
524- BUG_ON ((drive -> dev_flags & IDE_DFLAG_BLOCKED ) &&
525- blk_pm_request (rq ) == 0 );
529+ if ((drive -> dev_flags & IDE_DFLAG_BLOCKED ) &&
530+ blk_pm_request (rq ) == 0 &&
531+ (rq -> cmd_flags & REQ_PREEMPT ) == 0 ) {
532+ /* there should be no pending command at this point */
533+ ide_unlock_port (hwif );
534+ goto plug_device ;
535+ }
526536
527537 hwif -> rq = rq ;
528538
0 commit comments