ide: add ide_[un]lock_hwgroup() helpers
[linux-2.6-block.git] / drivers / ide / ide-io.c
index 23754bc5e595ec87d41d957a7c837c2eb27e77bf..ab480042757ad722a3bf40052f5d24d0d31a7be6 100644 (file)
@@ -786,15 +786,11 @@ void do_ide_request(struct request_queue *q)
        ide_hwif_t      *hwif;
        struct request  *rq;
        ide_startstop_t startstop;
-       int             loops = 0;
 
        /* caller must own hwgroup->lock */
        BUG_ON(!irqs_disabled());
 
-       while (!hwgroup->busy) {
-               hwgroup->busy = 1;
-               /* for atari only */
-               ide_get_lock(ide_intr, hwgroup);
+       while (!ide_lock_hwgroup(hwgroup)) {
                drive = choose_drive(hwgroup);
                if (drive == NULL) {
                        int sleeping = 0;
@@ -826,17 +822,10 @@ void do_ide_request(struct request_queue *q)
                                hwgroup->sleeping = 1;
                                hwgroup->req_gen_timer = hwgroup->req_gen;
                                mod_timer(&hwgroup->timer, sleep);
-                               /* we purposely leave hwgroup->busy==1
+                               /* we purposely leave hwgroup locked
                                 * while sleeping */
-                       } else {
-                               /* Ugly, but how can we sleep for the lock
-                                * otherwise? perhaps from tq_disk?
-                                */
-
-                               /* for atari only */
-                               ide_release_lock();
-                               hwgroup->busy = 0;
-                       }
+                       } else
+                               ide_unlock_hwgroup(hwgroup);
 
                        /* no more work for this hwgroup (for now) */
                        goto plug_device;
@@ -844,7 +833,7 @@ void do_ide_request(struct request_queue *q)
 
                if (drive != orig_drive)
                        goto plug_device;
-again:
+
                hwif = drive->hwif;
 
                if (hwif != hwgroup->hwif) {
@@ -866,7 +855,7 @@ again:
                 */
                rq = elv_next_request(drive->queue);
                if (!rq) {
-                       hwgroup->busy = 0;
+                       ide_unlock_hwgroup(hwgroup);
                        break;
                }
 
@@ -882,18 +871,12 @@ again:
                 * though. I hope that doesn't happen too much, hopefully not
                 * unless the subdriver triggers such a thing in its own PM
                 * state machine.
-                *
-                * We count how many times we loop here to make sure we service
-                * all drives in the hwgroup without looping for ever
                 */
                if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
                    blk_pm_request(rq) == 0 &&
                    (rq->cmd_flags & REQ_PREEMPT) == 0) {
-                       drive = drive->next ? drive->next : hwgroup->drive;
-                       if (loops++ < 4 && !blk_queue_plugged(drive->queue))
-                               goto again;
-                       /* We clear busy, there should be no pending ATA command at this point. */
-                       hwgroup->busy = 0;
+                       /* there should be no pending command at this point */
+                       ide_unlock_hwgroup(hwgroup);
                        goto plug_device;
                }
 
@@ -904,7 +887,7 @@ again:
                spin_lock_irq(&hwgroup->lock);
 
                if (startstop == ide_stopped) {
-                       hwgroup->busy = 0;
+                       ide_unlock_hwgroup(hwgroup);
                        if (!elv_queue_empty(orig_drive->queue))
                                blk_plug_device(orig_drive->queue);
                }
@@ -1008,7 +991,7 @@ void ide_timer_expiry (unsigned long data)
                 */
                if (hwgroup->sleeping) {
                        hwgroup->sleeping = 0;
-                       hwgroup->busy = 0;
+                       ide_unlock_hwgroup(hwgroup);
                }
        } else {
                ide_drive_t *drive = hwgroup->drive;
@@ -1018,10 +1001,7 @@ void ide_timer_expiry (unsigned long data)
                } else {
                        ide_hwif_t *hwif;
                        ide_startstop_t startstop = ide_stopped;
-                       if (!hwgroup->busy) {
-                               hwgroup->busy = 1;      /* paranoia */
-                               printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name);
-                       }
+
                        if ((expiry = hwgroup->expiry) != NULL) {
                                /* continue */
                                if ((wait = expiry(drive)) > 0) {
@@ -1066,7 +1046,7 @@ void ide_timer_expiry (unsigned long data)
                        spin_lock_irq(&hwgroup->lock);
                        enable_irq(hwif->irq);
                        if (startstop == ide_stopped) {
-                               hwgroup->busy = 0;
+                               ide_unlock_hwgroup(hwgroup);
                                if (!elv_queue_empty(drive->queue))
                                        blk_plug_device(drive->queue);
                        }
@@ -1234,10 +1214,6 @@ irqreturn_t ide_intr (int irq, void *dev_id)
                 */
                goto out;
 
-       if (!hwgroup->busy) {
-               hwgroup->busy = 1;      /* paranoia */
-               printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name);
-       }
        hwgroup->handler = NULL;
        hwgroup->req_gen++;
        del_timer(&hwgroup->timer);
@@ -1263,7 +1239,7 @@ irqreturn_t ide_intr (int irq, void *dev_id)
        drive->service_time = jiffies - drive->service_start;
        if (startstop == ide_stopped) {
                if (hwgroup->handler == NULL) { /* paranoia */
-                       hwgroup->busy = 0;
+                       ide_unlock_hwgroup(hwgroup);
                        if (!elv_queue_empty(drive->queue))
                                blk_plug_device(drive->queue);
                } else