X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fscsi%2Fsr.c;h=47c3d08e01f2aaf6a0fdf7144de4092d4f8ac79c;hb=6a77f38946aaee1cd85eeec6cf4229b204c15071;hp=9c3ddba40ded124a834688a5b627ab7f6dc7b510;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 9c3ddba40..47c3d08e0 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -46,19 +46,19 @@ #include #include -#include "scsi.h" -#include "hosts.h" - +#include +#include +#include #include +#include +#include #include /* For the door lock/unlock commands */ +#include #include "scsi_logging.h" #include "sr.h" -MODULE_PARM(xa_test, "i"); /* see sr_ioctl.c */ - - #define SR_DISKS 256 #define MAX_RETRIES 3 @@ -85,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 @@ -137,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); @@ -154,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); } @@ -180,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, 0); + 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, @@ -282,7 +282,7 @@ static void rw_intr(struct scsi_cmnd * SCpnt) * user, but make sure that it's not treated as a * hard error. */ - print_sense("sr", SCpnt); + scsi_print_sense("sr", SCpnt); SCpnt->result = 0; SCpnt->sense_buffer[0] = 0x0; good_bytes = this_count; @@ -335,11 +335,11 @@ static int sr_init_command(struct scsi_cmnd * SCpnt) memcpy(SCpnt->cmnd, rq->cmd, sizeof(SCpnt->cmnd)); if (!rq->data_len) - SCpnt->sc_data_direction = SCSI_DATA_NONE; + SCpnt->sc_data_direction = DMA_NONE; else if (rq_data_dir(rq) == WRITE) - SCpnt->sc_data_direction = SCSI_DATA_WRITE; + SCpnt->sc_data_direction = DMA_TO_DEVICE; else - SCpnt->sc_data_direction = SCSI_DATA_READ; + SCpnt->sc_data_direction = DMA_FROM_DEVICE; this_count = rq->data_len; if (rq->timeout) @@ -375,10 +375,11 @@ static int sr_init_command(struct scsi_cmnd * SCpnt) if (!cd->device->writeable) return 0; SCpnt->cmnd[0] = WRITE_10; - SCpnt->sc_data_direction = SCSI_DATA_WRITE; + 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 = SCSI_DATA_READ; + SCpnt->sc_data_direction = DMA_FROM_DEVICE; } else { blk_dump_rq_flags(SCpnt->request, "Unknown sr command"); return 0; @@ -501,7 +502,7 @@ static int sr_block_ioctl(struct inode *inode, struct file *file, unsigned cmd, case SCSI_IOCTL_GET_BUS_NUMBER: return scsi_ioctl(sdev, cmd, (void __user *)arg); } - return cdrom_ioctl(&cd->cdi, inode, cmd, arg); + return cdrom_ioctl(file, &cd->cdi, inode, cmd, arg); } static int sr_block_media_changed(struct gendisk *disk) @@ -543,7 +544,6 @@ static int sr_open(struct cdrom_device_info *cdi, int purpose) return 0; error_out: - scsi_cd_put(cd); return retval; } @@ -573,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) @@ -674,7 +674,7 @@ static void get_sectorsize(struct scsi_cd *cd) memset(buffer, 0, 8); /* Do the command and wait.. */ - SRpnt->sr_data_direction = SCSI_DATA_READ; + SRpnt->sr_data_direction = DMA_FROM_DEVICE; scsi_wait_req(SRpnt, (void *) cmd, (void *) buffer, 8, SR_TIMEOUT, MAX_RETRIES); @@ -754,12 +754,11 @@ Enomem: static void get_capabilities(struct scsi_cd *cd) { unsigned char *buffer; - int rc, n, mrw_write = 0, mrw = 1,ram_write=0; struct scsi_mode_data data; struct scsi_request *SRpnt; unsigned char cmd[MAX_COMMAND_SIZE]; unsigned int the_result; - int retries; + int retries, rc, n; static char *loadmech[] = { @@ -773,9 +772,6 @@ static void get_capabilities(struct scsi_cd *cd) "" }; - /* Set read only initially */ - set_disk_ro(cd->disk, 1); - /* allocate a request for the TEST_UNIT_READY */ SRpnt = scsi_allocate_request(cd->device, GFP_KERNEL); if (!SRpnt) { @@ -831,19 +827,6 @@ static void get_capabilities(struct scsi_cd *cd) return; } - if (cdrom_is_mrw(&cd->cdi, &mrw_write)) { - mrw = 0; - cd->cdi.mask |= CDC_MRW; - cd->cdi.mask |= CDC_MRW_W; - } - if (!mrw_write) - cd->cdi.mask |= CDC_MRW_W; - - if (cdrom_is_random_writable(&cd->cdi, &ram_write)) - cd->cdi.mask |= CDC_RAM; - if (!ram_write) - cd->cdi.mask |= CDC_RAM; - n = data.header_length + data.block_descriptor_length; cd->cdi.speed = ((buffer[n + 8] << 8) + buffer[n + 9]) / 176; cd->readcd_known = 1; @@ -891,12 +874,11 @@ 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; - set_disk_ro(cd->disk, 0); } scsi_release_request(SRpnt); @@ -952,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;