X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=drivers%2Fscsi%2Fsr.c;h=47c3d08e01f2aaf6a0fdf7144de4092d4f8ac79c;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=b80aa283c9212955bae627e19e71969683233490;hpb=9bf4aaab3e101692164d49b7ca357651eb691cb6;p=linux-2.6.git diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index b80aa283c..47c3d08e0 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -59,9 +59,6 @@ #include "sr.h" -MODULE_PARM(xa_test, "i"); /* see sr_ioctl.c */ - - #define SR_DISKS 256 #define MAX_RETRIES 3 @@ -88,7 +85,7 @@ static struct scsi_driver sr_template = { }; static unsigned long sr_index_bits[SR_DISKS / BITS_PER_LONG]; -static spinlock_t sr_index_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(sr_index_lock); /* This semaphore is used to mediate the 0->1 reference get in the * face of object destruction (i.e. we can't allow a get on an @@ -140,15 +137,13 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) if (disk->private_data == NULL) goto out; cd = scsi_cd(disk); - if (!kref_get(&cd->kref)) - goto out_null; + kref_get(&cd->kref); if (scsi_device_get(cd->device)) goto out_put; goto out; out_put: - kref_put(&cd->kref); - out_null: + kref_put(&cd->kref, sr_kref_release); cd = NULL; out: up(&sr_ref_sem); @@ -157,9 +152,11 @@ static inline struct scsi_cd *scsi_cd_get(struct gendisk *disk) static inline void scsi_cd_put(struct scsi_cd *cd) { + struct scsi_device *sdev = cd->device; + down(&sr_ref_sem); - scsi_device_put(cd->device); - kref_put(&cd->kref); + kref_put(&cd->kref, sr_kref_release); + scsi_device_put(sdev); up(&sr_ref_sem); } @@ -183,7 +180,7 @@ int sr_media_change(struct cdrom_device_info *cdi, int slot) return -EINVAL; } - retval = scsi_ioctl(cd->device, SCSI_IOCTL_TEST_UNIT_READY, NULL); + retval = scsi_test_unit_ready(cd->device, SR_TIMEOUT, MAX_RETRIES); if (retval) { /* Unable to test, unit probably not ready. This usually * means there is no disc in the drive. Mark as changed, @@ -379,6 +376,7 @@ static int sr_init_command(struct scsi_cmnd * SCpnt) return 0; SCpnt->cmnd[0] = WRITE_10; SCpnt->sc_data_direction = DMA_TO_DEVICE; + cd->cdi.media_written = 1; } else if (rq_data_dir(SCpnt->request) == READ) { SCpnt->cmnd[0] = READ_10; SCpnt->sc_data_direction = DMA_FROM_DEVICE; @@ -546,7 +544,6 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose) return 0; error_out: - scsi_cd_put(cd); return retval; } @@ -576,7 +573,7 @@ static int sr_probe(struct device *dev) goto fail; memset(cd, 0, sizeof(*cd)); - kref_init(&cd->kref, sr_kref_release); + kref_init(&cd->kref); disk = alloc_disk(1); if (!disk) @@ -877,10 +874,10 @@ static void get_capabilities(struct scsi_cd *cd) cd->cdi.mask |= CDC_CLOSE_TRAY; */ /* - * if DVD-RAM of MRW-W, we are randomly writeable + * if DVD-RAM, MRW-W or CD-RW, we are randomly writable */ - if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) != - (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM)) { + if ((cd->cdi.mask & (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) != + (CDC_DVD_RAM | CDC_MRW_W | CDC_RAM | CDC_CD_RW)) { cd->device->writeable = 1; } @@ -937,7 +934,7 @@ static int sr_remove(struct device *dev) del_gendisk(cd->disk); down(&sr_ref_sem); - kref_put(&cd->kref); + kref_put(&cd->kref, sr_kref_release); up(&sr_ref_sem); return 0;