X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fscsi%2Fsg.c;h=ed80392b0c53c2a7566b04e75b92413ccedda564;hb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;hp=5db8178c3b6cf2bb8e72b3186ed9727a02caabff;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 5db8178c3..ed80392b0 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -42,16 +42,16 @@ static int sg_version_num = 30531; /* 2 digits for each component */ #include #include #include -#include #include #include #include #include #include - #include +#include + #include "scsi.h" -#include "hosts.h" +#include #include #include #include @@ -60,7 +60,7 @@ static int sg_version_num = 30531; /* 2 digits for each component */ #ifdef CONFIG_SCSI_PROC_FS #include -static char *sg_version_date = "20040513"; +static char *sg_version_date = "20040516"; static int sg_proc_init(void); static void sg_proc_cleanup(void); @@ -73,7 +73,7 @@ static void sg_proc_cleanup(void); #define SG_ALLOW_DIO_DEF 0 #define SG_ALLOW_DIO_CODE /* compile out by commenting this define */ -#define SG_MAX_DEVS 8192 +#define SG_MAX_DEVS 32768 /* * Suppose you want to calculate the formula muldiv(x,m,d)=int(x * m / d) @@ -206,8 +206,6 @@ static Sg_request *sg_get_rq_mark(Sg_fd * sfp, int pack_id); static Sg_request *sg_add_request(Sg_fd * sfp); static int sg_remove_request(Sg_fd * sfp, Sg_request * srp); static int sg_res_in_use(Sg_fd * sfp); -static int sg_ms_to_jif(unsigned int msecs); -static inline unsigned sg_jif_to_ms(int jifs); static int sg_allow_access(unsigned char opcode, char dev_type); static int sg_build_direct(Sg_request * srp, Sg_fd * sfp, int dxfer_len); static Sg_device *sg_get_dev(int dev); @@ -235,6 +233,7 @@ sg_open(struct inode *inode, struct file *filp) int res; int retval; + nonseekable_open(inode, filp); SCSI_LOG_TIMEOUT(3, printk("sg_open: dev=%d, flags=0x%x\n", dev, flags)); sdp = sg_get_dev(dev); if ((!sdp) || (!sdp->device)) @@ -344,7 +343,6 @@ sg_read(struct file *filp, char __user *buf, size_t count, loff_t * ppos) return -ENXIO; SCSI_LOG_TIMEOUT(3, printk("sg_read: %s, count=%d\n", sdp->disk->disk_name, (int) count)); - if (ppos != &filp->f_pos) ; /* FIXME: Hmm. Seek to the right place, or fail? */ if ((k = verify_area(VERIFY_WRITE, buf, count))) return k; if (sfp->force_packid && (count >= SZ_SG_HEADER)) { @@ -502,7 +500,6 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos) if (!((filp->f_flags & O_NONBLOCK) || scsi_block_when_processing_errors(sdp->device))) return -ENXIO; - if (ppos != &filp->f_pos) ; /* FIXME: Hmm. Seek to the right place, or fail? */ if ((k = verify_area(VERIFY_READ, buf, count))) return k; /* protects following copy_from_user()s + get_user()s */ @@ -613,7 +610,7 @@ sg_new_write(Sg_fd * sfp, const char __user *buf, size_t count, return -EBUSY; /* reserve buffer already being used */ } } - timeout = sg_ms_to_jif(srp->header.timeout); + timeout = msecs_to_jiffies(srp->header.timeout); if ((!hp->cmdp) || (hp->cmd_len < 6) || (hp->cmd_len > sizeof (cmnd))) { sg_remove_request(sfp, srp); return -EMSGSIZE; @@ -718,7 +715,6 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp, (void *) SRpnt->sr_buffer, hp->dxfer_len, sg_cmd_done, timeout, SG_DEFAULT_RETRIES); /* dxfer_len overwrites SRpnt->sr_bufflen, hence need for b_malloc_len */ - generic_unplug_device(q); return 0; } @@ -931,7 +927,7 @@ sg_ioctl(struct inode *inode, struct file *filp, srp->header.driver_status; rinfo[val].duration = srp->done ? srp->header.duration : - sg_jif_to_ms( + jiffies_to_msecs( jiffies - srp->header.duration); rinfo[val].orphan = srp->orphan; rinfo[val].sg_io_owned = srp->sg_io_owned; @@ -1253,7 +1249,7 @@ sg_cmd_done(Scsi_Cmnd * SCpnt) srp->header.resid = SCpnt->resid; /* N.B. unit of duration changes here from jiffies to millisecs */ srp->header.duration = - sg_jif_to_ms(jiffies - (int) srp->header.duration); + jiffies_to_msecs(jiffies - srp->header.duration); if (0 != SRpnt->sr_result) { memcpy(srp->sense_b, SRpnt->sr_sense_buffer, sizeof (srp->sense_b)); @@ -1331,9 +1327,11 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp) void *old_sg_dev_arr = NULL; int k, error; - sdp = vmalloc(sizeof(Sg_device)); - if (!sdp) + sdp = kmalloc(sizeof(Sg_device), GFP_KERNEL); + if (!sdp) { + printk(KERN_WARNING "kmalloc Sg_device failure\n"); return -ENOMEM; + } write_lock_irqsave(&sg_dev_arr_lock, iflags); if (unlikely(sg_nr_dev >= sg_dev_max)) { /* try to resize */ @@ -1341,7 +1339,7 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp) int tmp_dev_max = sg_nr_dev + SG_DEV_ARR_LUMP; write_unlock_irqrestore(&sg_dev_arr_lock, iflags); - tmp_da = vmalloc(tmp_dev_max * sizeof(Sg_device *)); + tmp_da = kmalloc(tmp_dev_max * sizeof(Sg_device *), GFP_KERNEL); if (unlikely(!tmp_da)) goto expand_failed; @@ -1375,12 +1373,12 @@ static int sg_alloc(struct gendisk *disk, struct scsi_device *scsidp) out: if (error < 0) - vfree(sdp); - vfree(old_sg_dev_arr); + kfree(sdp); + kfree(old_sg_dev_arr); return error; expand_failed: - printk(KERN_ERR "sg_alloc: device array cannot be resized\n"); + printk(KERN_WARNING "sg_alloc: device array cannot be resized\n"); error = -ENOMEM; goto out; @@ -1404,20 +1402,26 @@ sg_add(struct class_device *cl_dev) int error, k; disk = alloc_disk(1); - if (!disk) + if (!disk) { + printk(KERN_WARNING "alloc_disk failed\n"); return -ENOMEM; + } disk->major = SCSI_GENERIC_MAJOR; error = -ENOMEM; cdev = cdev_alloc(); - if (!cdev) + if (!cdev) { + printk(KERN_WARNING "cdev_alloc failed\n"); goto out; + } cdev->owner = THIS_MODULE; cdev->ops = &sg_fops; error = sg_alloc(disk, scsidp); - if (error < 0) + if (error < 0) { + printk(KERN_WARNING "sg_alloc failed\n"); goto out; + } k = error; sdp = sg_dev_arr[k]; @@ -1525,11 +1529,11 @@ sg_remove(struct class_device *cl_dev) put_disk(sdp->disk); sdp->disk = NULL; if (NULL == sdp->headfp) - vfree((char *) sdp); + kfree((char *) sdp); } if (delay) - scsi_sleep(2); /* dirty detach so delay device destruction */ + msleep(10); /* dirty detach so delay device destruction */ } /* Set 'perm' (4th argument) to 0 to disable module_param's definition @@ -1590,7 +1594,7 @@ exit_sg(void) unregister_chrdev_region(MKDEV(SCSI_GENERIC_MAJOR, 0), SG_MAX_DEVS); if (sg_dev_arr != NULL) { - vfree((char *) sg_dev_arr); + kfree((char *) sg_dev_arr); sg_dev_arr = NULL; } sg_dev_max = 0; @@ -2398,7 +2402,7 @@ sg_add_sfp(Sg_device * sdp, int dev) Sg_fd *sfp; unsigned long iflags; - sfp = (Sg_fd *) sg_page_malloc(sizeof (Sg_fd), 0, 0); + sfp = (Sg_fd *) sg_page_malloc(sizeof (Sg_fd), 0, NULL); if (!sfp) return NULL; memset(sfp, 0, sizeof (Sg_fd)); @@ -2492,7 +2496,7 @@ sg_remove_sfp(Sg_device * sdp, Sg_fd * sfp) } if (k < maxd) sg_dev_arr[k] = NULL; - vfree((char *) sdp); + kfree((char *) sdp); res = 1; } write_unlock_irqrestore(&sg_dev_arr_lock, iflags); @@ -2569,30 +2573,6 @@ sg_page_free(char *buff, int size) free_pages((unsigned long) buff, order); } -static int -sg_ms_to_jif(unsigned int msecs) -{ - if ((UINT_MAX / 2U) < msecs) - return INT_MAX; /* special case, set largest possible */ - else - return ((int) msecs < - (INT_MAX / 1000)) ? (((int) msecs * HZ) / 1000) - : (((int) msecs / 1000) * HZ); -} - -static inline unsigned -sg_jif_to_ms(int jifs) -{ - if (jifs <= 0) - return 0U; - else { - unsigned int j = (unsigned int) jifs; - return (j < - (UINT_MAX / 1000)) ? ((j * 1000) / HZ) : ((j / HZ) * - 1000); - } -} - static unsigned char allow_ops[] = { TEST_UNIT_READY, REQUEST_SENSE, INQUIRY, READ_CAPACITY, READ_BUFFER, READ_6, READ_10, READ_12, MODE_SENSE, MODE_SENSE_10, LOG_SENSE @@ -2808,7 +2788,7 @@ sg_proc_write_adio(struct file *filp, const char __user *buffer, if (copy_from_user(buff, buffer, num)) return -EFAULT; buff[num] = '\0'; - sg_allow_dio = simple_strtoul(buff, 0, 10) ? 1 : 0; + sg_allow_dio = simple_strtoul(buff, NULL, 10) ? 1 : 0; return count; } @@ -2831,7 +2811,7 @@ sg_proc_write_dressz(struct file *filp, const char __user *buffer, if (copy_from_user(buff, buffer, num)) return -EFAULT; buff[num] = '\0'; - k = simple_strtoul(buff, 0, 10); + k = simple_strtoul(buff, NULL, 10); if (k <= 1048576) { /* limit "big buff" to 1 MB */ sg_big_buff = k; return count; @@ -2955,7 +2935,7 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp) for (k = 0; (fp = sg_get_nth_sfp(sdp, k)); ++k) { seq_printf(s, " FD(%d): timeout=%dms bufflen=%d " "(res)sgat=%d low_dma=%d\n", k + 1, - sg_jif_to_ms(fp->timeout), + jiffies_to_msecs(fp->timeout), fp->reserve.bufflen, (int) fp->reserve.k_use_sg, (int) fp->low_dma); @@ -2991,8 +2971,8 @@ static void sg_proc_debug_helper(struct seq_file *s, Sg_device * sdp) seq_printf(s, " dur=%d", hp->duration); else seq_printf(s, " t_o/elap=%d/%d", - new_interface ? hp->timeout : sg_jif_to_ms(fp->timeout), - sg_jif_to_ms(hp->duration ? (jiffies - hp->duration) : 0)); + new_interface ? hp->timeout : jiffies_to_msecs(fp->timeout), + jiffies_to_msecs(hp->duration ? (jiffies - hp->duration) : 0)); seq_printf(s, "ms sgat=%d op=0x%02x\n", usg, (int) srp->data.cmd_opcode); }