Add ide_[un]lock_hwgroup() inline helpers for obtaining exclusive
access to the given hwgroup and update the core code accordingly.
[ This change besides making code saner results in more efficient
use of ide_{get,release}_lock(). ]
Cc: Michael Schmitz <schmitz@biophys.uni-duesseldorf.de>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Elias Oltmanns <eo@nebensachen.de>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
/* caller must own hwgroup->lock */
BUG_ON(!irqs_disabled());
/* 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;
drive = choose_drive(hwgroup);
if (drive == NULL) {
int sleeping = 0;
hwgroup->sleeping = 1;
hwgroup->req_gen_timer = hwgroup->req_gen;
mod_timer(&hwgroup->timer, sleep);
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
- } 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;
/* no more work for this hwgroup (for now) */
goto plug_device;
*/
rq = elv_next_request(drive->queue);
if (!rq) {
*/
rq = elv_next_request(drive->queue);
if (!rq) {
+ ide_unlock_hwgroup(hwgroup);
if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
blk_pm_request(rq) == 0 &&
(rq->cmd_flags & REQ_PREEMPT) == 0) {
if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
blk_pm_request(rq) == 0 &&
(rq->cmd_flags & REQ_PREEMPT) == 0) {
- /* 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);
spin_lock_irq(&hwgroup->lock);
if (startstop == ide_stopped) {
spin_lock_irq(&hwgroup->lock);
if (startstop == ide_stopped) {
+ ide_unlock_hwgroup(hwgroup);
if (!elv_queue_empty(orig_drive->queue))
blk_plug_device(orig_drive->queue);
}
if (!elv_queue_empty(orig_drive->queue))
blk_plug_device(orig_drive->queue);
}
*/
if (hwgroup->sleeping) {
hwgroup->sleeping = 0;
*/
if (hwgroup->sleeping) {
hwgroup->sleeping = 0;
+ ide_unlock_hwgroup(hwgroup);
}
} else {
ide_drive_t *drive = hwgroup->drive;
}
} else {
ide_drive_t *drive = hwgroup->drive;
spin_lock_irq(&hwgroup->lock);
enable_irq(hwif->irq);
if (startstop == ide_stopped) {
spin_lock_irq(&hwgroup->lock);
enable_irq(hwif->irq);
if (startstop == ide_stopped) {
+ ide_unlock_hwgroup(hwgroup);
if (!elv_queue_empty(drive->queue))
blk_plug_device(drive->queue);
}
if (!elv_queue_empty(drive->queue))
blk_plug_device(drive->queue);
}
drive->service_time = jiffies - drive->service_start;
if (startstop == ide_stopped) {
if (hwgroup->handler == NULL) { /* paranoia */
drive->service_time = jiffies - drive->service_start;
if (startstop == ide_stopped) {
if (hwgroup->handler == NULL) { /* paranoia */
+ ide_unlock_hwgroup(hwgroup);
if (!elv_queue_empty(drive->queue))
blk_plug_device(drive->queue);
} else
if (!elv_queue_empty(drive->queue))
blk_plug_device(drive->queue);
} else
if (reset_timer && hwgroup->sleeping &&
del_timer(&hwgroup->timer)) {
hwgroup->sleeping = 0;
if (reset_timer && hwgroup->sleeping &&
del_timer(&hwgroup->timer)) {
hwgroup->sleeping = 0;
+ ide_unlock_hwgroup(hwgroup);
blk_start_queueing(q);
}
spin_unlock_irq(&hwgroup->lock);
blk_start_queueing(q);
}
spin_unlock_irq(&hwgroup->lock);
extern void ide_timer_expiry(unsigned long);
extern irqreturn_t ide_intr(int irq, void *dev_id);
extern void ide_timer_expiry(unsigned long);
extern irqreturn_t ide_intr(int irq, void *dev_id);
+
+static inline int ide_lock_hwgroup(ide_hwgroup_t *hwgroup)
+{
+ if (hwgroup->busy)
+ return 1;
+
+ hwgroup->busy = 1;
+ /* for atari only */
+ ide_get_lock(ide_intr, hwgroup);
+
+ return 0;
+}
+
+static inline void ide_unlock_hwgroup(ide_hwgroup_t *hwgroup)
+{
+ /* for atari only */
+ ide_release_lock();
+ hwgroup->busy = 0;
+}
+
extern void do_ide_request(struct request_queue *);
void ide_init_disk(struct gendisk *, ide_drive_t *);
extern void do_ide_request(struct request_queue *);
void ide_init_disk(struct gendisk *, ide_drive_t *);