diff options
-rw-r--r-- | drivers/ide/ide-cd.c | 15 | ||||
-rw-r--r-- | drivers/ide/ide-disk.c | 14 | ||||
-rw-r--r-- | drivers/ide/ide-floppy.c | 18 | ||||
-rw-r--r-- | drivers/ide/ide-tape.c | 8 | ||||
-rw-r--r-- | drivers/scsi/ide-scsi.c | 8 | ||||
-rw-r--r-- | include/linux/ide.h | 1 |
6 files changed, 22 insertions, 42 deletions
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index e6e350cdfbf9..624d48841533 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c | |||
@@ -3353,21 +3353,16 @@ static int idecd_open(struct inode * inode, struct file * file) | |||
3353 | { | 3353 | { |
3354 | struct gendisk *disk = inode->i_bdev->bd_disk; | 3354 | struct gendisk *disk = inode->i_bdev->bd_disk; |
3355 | struct cdrom_info *info; | 3355 | struct cdrom_info *info; |
3356 | ide_drive_t *drive; | ||
3357 | int rc = -ENOMEM; | 3356 | int rc = -ENOMEM; |
3358 | 3357 | ||
3359 | if (!(info = ide_cd_get(disk))) | 3358 | if (!(info = ide_cd_get(disk))) |
3360 | return -ENXIO; | 3359 | return -ENXIO; |
3361 | 3360 | ||
3362 | drive = info->drive; | ||
3363 | |||
3364 | drive->usage++; | ||
3365 | |||
3366 | if (!info->buffer) | 3361 | if (!info->buffer) |
3367 | info->buffer = kmalloc(SECTOR_BUFFER_SIZE, | 3362 | info->buffer = kmalloc(SECTOR_BUFFER_SIZE, GFP_KERNEL|__GFP_REPEAT); |
3368 | GFP_KERNEL|__GFP_REPEAT); | 3363 | |
3369 | if (!info->buffer || (rc = cdrom_open(&info->devinfo, inode, file))) | 3364 | if (info->buffer) |
3370 | drive->usage--; | 3365 | rc = cdrom_open(&info->devinfo, inode, file); |
3371 | 3366 | ||
3372 | if (rc < 0) | 3367 | if (rc < 0) |
3373 | ide_cd_put(info); | 3368 | ide_cd_put(info); |
@@ -3379,10 +3374,8 @@ static int idecd_release(struct inode * inode, struct file * file) | |||
3379 | { | 3374 | { |
3380 | struct gendisk *disk = inode->i_bdev->bd_disk; | 3375 | struct gendisk *disk = inode->i_bdev->bd_disk; |
3381 | struct cdrom_info *info = ide_cd_g(disk); | 3376 | struct cdrom_info *info = ide_cd_g(disk); |
3382 | ide_drive_t *drive = info->drive; | ||
3383 | 3377 | ||
3384 | cdrom_release (&info->devinfo, file); | 3378 | cdrom_release (&info->devinfo, file); |
3385 | drive->usage--; | ||
3386 | 3379 | ||
3387 | ide_cd_put(info); | 3380 | ide_cd_put(info); |
3388 | 3381 | ||
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c index 0a05a377d66a..e2cea1889c4d 100644 --- a/drivers/ide/ide-disk.c +++ b/drivers/ide/ide-disk.c | |||
@@ -77,6 +77,7 @@ struct ide_disk_obj { | |||
77 | ide_driver_t *driver; | 77 | ide_driver_t *driver; |
78 | struct gendisk *disk; | 78 | struct gendisk *disk; |
79 | struct kref kref; | 79 | struct kref kref; |
80 | unsigned int openers; /* protected by BKL for now */ | ||
80 | }; | 81 | }; |
81 | 82 | ||
82 | static DEFINE_MUTEX(idedisk_ref_mutex); | 83 | static DEFINE_MUTEX(idedisk_ref_mutex); |
@@ -1081,8 +1082,9 @@ static int idedisk_open(struct inode *inode, struct file *filp) | |||
1081 | 1082 | ||
1082 | drive = idkp->drive; | 1083 | drive = idkp->drive; |
1083 | 1084 | ||
1084 | drive->usage++; | 1085 | idkp->openers++; |
1085 | if (drive->removable && drive->usage == 1) { | 1086 | |
1087 | if (drive->removable && idkp->openers == 1) { | ||
1086 | ide_task_t args; | 1088 | ide_task_t args; |
1087 | memset(&args, 0, sizeof(ide_task_t)); | 1089 | memset(&args, 0, sizeof(ide_task_t)); |
1088 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK; | 1090 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORLOCK; |
@@ -1106,9 +1108,10 @@ static int idedisk_release(struct inode *inode, struct file *filp) | |||
1106 | struct ide_disk_obj *idkp = ide_disk_g(disk); | 1108 | struct ide_disk_obj *idkp = ide_disk_g(disk); |
1107 | ide_drive_t *drive = idkp->drive; | 1109 | ide_drive_t *drive = idkp->drive; |
1108 | 1110 | ||
1109 | if (drive->usage == 1) | 1111 | if (idkp->openers == 1) |
1110 | ide_cacheflush_p(drive); | 1112 | ide_cacheflush_p(drive); |
1111 | if (drive->removable && drive->usage == 1) { | 1113 | |
1114 | if (drive->removable && idkp->openers == 1) { | ||
1112 | ide_task_t args; | 1115 | ide_task_t args; |
1113 | memset(&args, 0, sizeof(ide_task_t)); | 1116 | memset(&args, 0, sizeof(ide_task_t)); |
1114 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK; | 1117 | args.tfRegister[IDE_COMMAND_OFFSET] = WIN_DOORUNLOCK; |
@@ -1117,7 +1120,8 @@ static int idedisk_release(struct inode *inode, struct file *filp) | |||
1117 | if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL)) | 1120 | if (drive->doorlocking && ide_raw_taskfile(drive, &args, NULL)) |
1118 | drive->doorlocking = 0; | 1121 | drive->doorlocking = 0; |
1119 | } | 1122 | } |
1120 | drive->usage--; | 1123 | |
1124 | idkp->openers--; | ||
1121 | 1125 | ||
1122 | ide_disk_put(idkp); | 1126 | ide_disk_put(idkp); |
1123 | 1127 | ||
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index 07fa37d84df2..61969415c57b 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c | |||
@@ -279,6 +279,7 @@ typedef struct ide_floppy_obj { | |||
279 | ide_driver_t *driver; | 279 | ide_driver_t *driver; |
280 | struct gendisk *disk; | 280 | struct gendisk *disk; |
281 | struct kref kref; | 281 | struct kref kref; |
282 | unsigned int openers; /* protected by BKL for now */ | ||
282 | 283 | ||
283 | /* Current packet command */ | 284 | /* Current packet command */ |
284 | idefloppy_pc_t *pc; | 285 | idefloppy_pc_t *pc; |
@@ -1950,9 +1951,9 @@ static int idefloppy_open(struct inode *inode, struct file *filp) | |||
1950 | 1951 | ||
1951 | drive = floppy->drive; | 1952 | drive = floppy->drive; |
1952 | 1953 | ||
1953 | drive->usage++; | 1954 | floppy->openers++; |
1954 | 1955 | ||
1955 | if (drive->usage == 1) { | 1956 | if (floppy->openers == 1) { |
1956 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); | 1957 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); |
1957 | /* Just in case */ | 1958 | /* Just in case */ |
1958 | 1959 | ||
@@ -1970,13 +1971,11 @@ static int idefloppy_open(struct inode *inode, struct file *filp) | |||
1970 | ** capacity of the drive or begin the format - Sam | 1971 | ** capacity of the drive or begin the format - Sam |
1971 | */ | 1972 | */ |
1972 | ) { | 1973 | ) { |
1973 | drive->usage--; | ||
1974 | ret = -EIO; | 1974 | ret = -EIO; |
1975 | goto out_put_floppy; | 1975 | goto out_put_floppy; |
1976 | } | 1976 | } |
1977 | 1977 | ||
1978 | if (floppy->wp && (filp->f_mode & 2)) { | 1978 | if (floppy->wp && (filp->f_mode & 2)) { |
1979 | drive->usage--; | ||
1980 | ret = -EROFS; | 1979 | ret = -EROFS; |
1981 | goto out_put_floppy; | 1980 | goto out_put_floppy; |
1982 | } | 1981 | } |
@@ -1988,13 +1987,13 @@ static int idefloppy_open(struct inode *inode, struct file *filp) | |||
1988 | } | 1987 | } |
1989 | check_disk_change(inode->i_bdev); | 1988 | check_disk_change(inode->i_bdev); |
1990 | } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) { | 1989 | } else if (test_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags)) { |
1991 | drive->usage--; | ||
1992 | ret = -EBUSY; | 1990 | ret = -EBUSY; |
1993 | goto out_put_floppy; | 1991 | goto out_put_floppy; |
1994 | } | 1992 | } |
1995 | return 0; | 1993 | return 0; |
1996 | 1994 | ||
1997 | out_put_floppy: | 1995 | out_put_floppy: |
1996 | floppy->openers--; | ||
1998 | ide_floppy_put(floppy); | 1997 | ide_floppy_put(floppy); |
1999 | return ret; | 1998 | return ret; |
2000 | } | 1999 | } |
@@ -2008,7 +2007,7 @@ static int idefloppy_release(struct inode *inode, struct file *filp) | |||
2008 | 2007 | ||
2009 | debug_log(KERN_INFO "Reached idefloppy_release\n"); | 2008 | debug_log(KERN_INFO "Reached idefloppy_release\n"); |
2010 | 2009 | ||
2011 | if (drive->usage == 1) { | 2010 | if (floppy->openers == 1) { |
2012 | /* IOMEGA Clik! drives do not support lock/unlock commands */ | 2011 | /* IOMEGA Clik! drives do not support lock/unlock commands */ |
2013 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { | 2012 | if (!test_bit(IDEFLOPPY_CLIK_DRIVE, &floppy->flags)) { |
2014 | idefloppy_create_prevent_cmd(&pc, 0); | 2013 | idefloppy_create_prevent_cmd(&pc, 0); |
@@ -2017,7 +2016,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp) | |||
2017 | 2016 | ||
2018 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); | 2017 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, &floppy->flags); |
2019 | } | 2018 | } |
2020 | drive->usage--; | 2019 | |
2020 | floppy->openers--; | ||
2021 | 2021 | ||
2022 | ide_floppy_put(floppy); | 2022 | ide_floppy_put(floppy); |
2023 | 2023 | ||
@@ -2051,7 +2051,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file, | |||
2051 | prevent = 0; | 2051 | prevent = 0; |
2052 | /* fall through */ | 2052 | /* fall through */ |
2053 | case CDROM_LOCKDOOR: | 2053 | case CDROM_LOCKDOOR: |
2054 | if (drive->usage > 1) | 2054 | if (floppy->openers > 1) |
2055 | return -EBUSY; | 2055 | return -EBUSY; |
2056 | 2056 | ||
2057 | /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */ | 2057 | /* The IOMEGA Clik! Drive doesn't support this command - no room for an eject mechanism */ |
@@ -2073,7 +2073,7 @@ static int idefloppy_ioctl(struct inode *inode, struct file *file, | |||
2073 | if (!(file->f_mode & 2)) | 2073 | if (!(file->f_mode & 2)) |
2074 | return -EPERM; | 2074 | return -EPERM; |
2075 | 2075 | ||
2076 | if (drive->usage > 1) { | 2076 | if (floppy->openers > 1) { |
2077 | /* Don't format if someone is using the disk */ | 2077 | /* Don't format if someone is using the disk */ |
2078 | 2078 | ||
2079 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, | 2079 | clear_bit(IDEFLOPPY_FORMAT_IN_PROGRESS, |
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index c6eec0413a6c..be6d818d0db8 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c | |||
@@ -4792,15 +4792,10 @@ static int idetape_open(struct inode *inode, struct file *filp) | |||
4792 | { | 4792 | { |
4793 | struct gendisk *disk = inode->i_bdev->bd_disk; | 4793 | struct gendisk *disk = inode->i_bdev->bd_disk; |
4794 | struct ide_tape_obj *tape; | 4794 | struct ide_tape_obj *tape; |
4795 | ide_drive_t *drive; | ||
4796 | 4795 | ||
4797 | if (!(tape = ide_tape_get(disk))) | 4796 | if (!(tape = ide_tape_get(disk))) |
4798 | return -ENXIO; | 4797 | return -ENXIO; |
4799 | 4798 | ||
4800 | drive = tape->drive; | ||
4801 | |||
4802 | drive->usage++; | ||
4803 | |||
4804 | return 0; | 4799 | return 0; |
4805 | } | 4800 | } |
4806 | 4801 | ||
@@ -4808,9 +4803,6 @@ static int idetape_release(struct inode *inode, struct file *filp) | |||
4808 | { | 4803 | { |
4809 | struct gendisk *disk = inode->i_bdev->bd_disk; | 4804 | struct gendisk *disk = inode->i_bdev->bd_disk; |
4810 | struct ide_tape_obj *tape = ide_tape_g(disk); | 4805 | struct ide_tape_obj *tape = ide_tape_g(disk); |
4811 | ide_drive_t *drive = tape->drive; | ||
4812 | |||
4813 | drive->usage--; | ||
4814 | 4806 | ||
4815 | ide_tape_put(tape); | 4807 | ide_tape_put(tape); |
4816 | 4808 | ||
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c index 8f6b5bf580f6..2b5b8a93bc10 100644 --- a/drivers/scsi/ide-scsi.c +++ b/drivers/scsi/ide-scsi.c | |||
@@ -801,15 +801,10 @@ static int idescsi_ide_open(struct inode *inode, struct file *filp) | |||
801 | { | 801 | { |
802 | struct gendisk *disk = inode->i_bdev->bd_disk; | 802 | struct gendisk *disk = inode->i_bdev->bd_disk; |
803 | struct ide_scsi_obj *scsi; | 803 | struct ide_scsi_obj *scsi; |
804 | ide_drive_t *drive; | ||
805 | 804 | ||
806 | if (!(scsi = ide_scsi_get(disk))) | 805 | if (!(scsi = ide_scsi_get(disk))) |
807 | return -ENXIO; | 806 | return -ENXIO; |
808 | 807 | ||
809 | drive = scsi->drive; | ||
810 | |||
811 | drive->usage++; | ||
812 | |||
813 | return 0; | 808 | return 0; |
814 | } | 809 | } |
815 | 810 | ||
@@ -817,9 +812,6 @@ static int idescsi_ide_release(struct inode *inode, struct file *filp) | |||
817 | { | 812 | { |
818 | struct gendisk *disk = inode->i_bdev->bd_disk; | 813 | struct gendisk *disk = inode->i_bdev->bd_disk; |
819 | struct ide_scsi_obj *scsi = ide_scsi_g(disk); | 814 | struct ide_scsi_obj *scsi = ide_scsi_g(disk); |
820 | ide_drive_t *drive = scsi->drive; | ||
821 | |||
822 | drive->usage--; | ||
823 | 815 | ||
824 | ide_scsi_put(scsi); | 816 | ide_scsi_put(scsi); |
825 | 817 | ||
diff --git a/include/linux/ide.h b/include/linux/ide.h index 606cef727c5a..40b5fa2f2627 100644 --- a/include/linux/ide.h +++ b/include/linux/ide.h | |||
@@ -636,7 +636,6 @@ typedef struct ide_drive_s { | |||
636 | unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */ | 636 | unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */ |
637 | unsigned int cyl; /* "real" number of cyls */ | 637 | unsigned int cyl; /* "real" number of cyls */ |
638 | unsigned int drive_data; /* use by tuneproc/selectproc */ | 638 | unsigned int drive_data; /* use by tuneproc/selectproc */ |
639 | unsigned int usage; /* current "open()" count for drive */ | ||
640 | unsigned int failures; /* current failure count */ | 639 | unsigned int failures; /* current failure count */ |
641 | unsigned int max_failures; /* maximum allowed failure count */ | 640 | unsigned int max_failures; /* maximum allowed failure count */ |
642 | u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */ | 641 | u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */ |