- 2.6.17 port work build breaks, but the patch set is relativly stable
[linux-flexiantxendom0-3.2.10.git] / drivers / ide / ide-tape.c
index 0101d0d..f04791a 100644 (file)
 #include <linux/timer.h>
 #include <linux/mm.h>
 #include <linux/interrupt.h>
+#include <linux/jiffies.h>
 #include <linux/major.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/errno.h>
 #include <linux/smp_lock.h>
 #include <linux/completion.h>
 #include <linux/bitops.h>
+#include <linux/mutex.h>
 
 #include <asm/byteorder.h>
 #include <asm/irq.h>
@@ -1011,7 +1013,7 @@ typedef struct ide_tape_obj {
          int debug_level; 
 } idetape_tape_t;
 
-static DECLARE_MUTEX(idetape_ref_sem);
+static DEFINE_MUTEX(idetape_ref_mutex);
 
 static struct class *idetape_sysfs_class;
 
@@ -1024,11 +1026,11 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
 {
        struct ide_tape_obj *tape = NULL;
 
-       down(&idetape_ref_sem);
+       mutex_lock(&idetape_ref_mutex);
        tape = ide_tape_g(disk);
        if (tape)
                kref_get(&tape->kref);
-       up(&idetape_ref_sem);
+       mutex_unlock(&idetape_ref_mutex);
        return tape;
 }
 
@@ -1036,9 +1038,9 @@ static void ide_tape_release(struct kref *);
 
 static void ide_tape_put(struct ide_tape_obj *tape)
 {
-       down(&idetape_ref_sem);
+       mutex_lock(&idetape_ref_mutex);
        kref_put(&tape->kref, ide_tape_release);
-       up(&idetape_ref_sem);
+       mutex_unlock(&idetape_ref_mutex);
 }
 
 /*
@@ -1290,11 +1292,11 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
 {
        struct ide_tape_obj *tape = NULL;
 
-       down(&idetape_ref_sem);
+       mutex_lock(&idetape_ref_mutex);
        tape = idetape_devs[i];
        if (tape)
                kref_get(&tape->kref);
-       up(&idetape_ref_sem);
+       mutex_unlock(&idetape_ref_mutex);
        return tape;
 }
 
@@ -2335,7 +2337,7 @@ static ide_startstop_t idetape_rw_callback (ide_drive_t *drive)
        }
        if (time_after(jiffies, tape->insert_time))
                tape->insert_speed = tape->insert_size / 1024 * HZ / (jiffies - tape->insert_time);
-       if (jiffies - tape->avg_time >= HZ) {
+       if (time_after_eq(jiffies, tape->avg_time + HZ)) {
                tape->avg_speed = tape->avg_size * HZ / (jiffies - tape->avg_time) / 1024;
                tape->avg_size = 0;
                tape->avg_time = jiffies;
@@ -2496,7 +2498,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
                        } else {
                                return ide_do_reset(drive);
                        }
-               } else if (jiffies - tape->dsc_polling_start > IDETAPE_DSC_MA_THRESHOLD)
+               } else if (time_after(jiffies, tape->dsc_polling_start + IDETAPE_DSC_MA_THRESHOLD))
                        tape->dsc_polling_frequency = IDETAPE_DSC_MA_SLOW;
                idetape_postpone_request(drive);
                return ide_stopped;
@@ -4870,11 +4872,11 @@ static int ide_tape_probe(ide_drive_t *drive)
 
        drive->driver_data = tape;
 
-       down(&idetape_ref_sem);
+       mutex_lock(&idetape_ref_mutex);
        for (minor = 0; idetape_devs[minor]; minor++)
                ;
        idetape_devs[minor] = tape;
-       up(&idetape_ref_sem);
+       mutex_unlock(&idetape_ref_mutex);
 
        idetape_setup(drive, tape, minor);