const: constify remaining file_operations
[safe/jmp/linux-2.6] / drivers / scsi / sg.c
index 1e40518..747a5e5 100644 (file)
@@ -179,7 +179,7 @@ typedef struct sg_device { /* holds the state of each scsi generic device */
 /* tasklet or soft irq callback */
 static void sg_rq_end_io(struct request *rq, int uptodate);
 static int sg_start_req(Sg_request *srp, unsigned char *cmd);
-static void sg_finish_rem_req(Sg_request * srp);
+static int sg_finish_rem_req(Sg_request * srp);
 static int sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size);
 static ssize_t sg_new_read(Sg_fd * sfp, char __user *buf, size_t count,
                           Sg_request * srp);
@@ -210,13 +210,11 @@ static void sg_put_dev(Sg_device *sdp);
 static int sg_allow_access(struct file *filp, unsigned char *cmd)
 {
        struct sg_fd *sfp = (struct sg_fd *)filp->private_data;
-       struct request_queue *q = sfp->parentdp->device->request_queue;
 
        if (sfp->parentdp->device->type == TYPE_SCANNER)
                return 0;
 
-       return blk_verify_command(&q->cmd_filter,
-                                 cmd, filp->f_mode & FMODE_WRITE);
+       return blk_verify_command(cmd, filp->f_mode & FMODE_WRITE);
 }
 
 static int
@@ -289,8 +287,8 @@ sg_open(struct inode *inode, struct file *filp)
        if (list_empty(&sdp->sfds)) {   /* no existing opens on this device */
                sdp->sgdebug = 0;
                q = sdp->device->request_queue;
-               sdp->sg_tablesize = min(q->max_hw_segments,
-                                       q->max_phys_segments);
+               sdp->sg_tablesize = min(queue_max_hw_segments(q),
+                                       queue_max_phys_segments(q));
        }
        if ((sfp = sg_add_sfp(sdp, dev)))
                filp->private_data = sfp;
@@ -518,7 +516,7 @@ sg_new_read(Sg_fd * sfp, char __user *buf, size_t count, Sg_request * srp)
                goto err_out;
        }
 err_out:
-       sg_finish_rem_req(srp);
+       err = sg_finish_rem_req(srp);
        return (0 == err) ? count : err;
 }
 
@@ -621,7 +619,7 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
                if (strcmp(current->comm, cmd) && printk_ratelimit()) {
                        printk(KERN_WARNING
                               "sg_write: data in/out %d/%d bytes for SCSI command 0x%x--"
-                              "guessing data in;\n" KERN_WARNING "   "
+                              "guessing data in;\n   "
                               "program %s not setting count and/or reply_len properly\n",
                               old_hdr.reply_len - (int)SZ_SG_HEADER,
                               input_size, (unsigned int) cmnd[0],
@@ -909,7 +907,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
                 if (val < 0)
                         return -EINVAL;
                val = min_t(int, val,
-                               sdp->device->request_queue->max_sectors * 512);
+                           queue_max_sectors(sdp->device->request_queue) * 512);
                if (val != sfp->reserve.bufflen) {
                        if (sg_res_in_use(sfp) || sfp->mmap_called)
                                return -EBUSY;
@@ -919,7 +917,7 @@ sg_ioctl(struct inode *inode, struct file *filp,
                return 0;
        case SG_GET_RESERVED_SIZE:
                val = min_t(int, sfp->reserve.bufflen,
-                               sdp->device->request_queue->max_sectors * 512);
+                           queue_max_sectors(sdp->device->request_queue) * 512);
                return put_user(val, ip);
        case SG_SET_COMMAND_Q:
                result = get_user(val, ip);
@@ -1059,12 +1057,13 @@ sg_ioctl(struct inode *inode, struct file *filp,
                        return -ENODEV;
                return scsi_ioctl(sdp->device, cmd_in, p);
        case BLKSECTGET:
-               return put_user(sdp->device->request_queue->max_sectors * 512,
+               return put_user(queue_max_sectors(sdp->device->request_queue) * 512,
                                ip);
        case BLKTRACESETUP:
                return blk_trace_setup(sdp->device->request_queue,
                                       sdp->disk->disk_name,
                                       MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
+                                      NULL,
                                       (char *)arg);
        case BLKTRACESTART:
                return blk_trace_startstop(sdp->device->request_queue, 1);
@@ -1186,7 +1185,7 @@ sg_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        return VM_FAULT_SIGBUS;
 }
 
-static struct vm_operations_struct sg_mmap_vm_ops = {
+static const struct vm_operations_struct sg_mmap_vm_ops = {
        .fault = sg_vma_fault,
 };
 
@@ -1260,7 +1259,7 @@ static void sg_rq_end_io(struct request *rq, int uptodate)
 
        sense = rq->sense;
        result = rq->errors;
-       resid = rq->data_len;
+       resid = rq->resid_len;
 
        SCSI_LOG_TIMEOUT(4, printk("sg_cmd_done: %s, pack_id=%d, res=0x%x\n",
                sdp->disk->disk_name, srp->header.pack_id, result));
@@ -1312,11 +1311,13 @@ static void sg_rq_end_io(struct request *rq, int uptodate)
                wake_up_interruptible(&sfp->read_wait);
                kill_fasync(&sfp->async_qp, SIGPOLL, POLL_IN);
                kref_put(&sfp->f_ref, sg_remove_sfp);
-       } else
-               execute_in_process_context(sg_rq_end_io_usercontext, &srp->ew);
+       } else {
+               INIT_WORK(&srp->ew.work, sg_rq_end_io_usercontext);
+               schedule_work(&srp->ew.work);
+       }
 }
 
-static struct file_operations sg_fops = {
+static const struct file_operations sg_fops = {
        .owner = THIS_MODULE,
        .read = sg_read,
        .write = sg_write,
@@ -1375,7 +1376,8 @@ static Sg_device *sg_alloc(struct gendisk *disk, struct scsi_device *scsidp)
        sdp->device = scsidp;
        INIT_LIST_HEAD(&sdp->sfds);
        init_waitqueue_head(&sdp->o_excl_wait);
-       sdp->sg_tablesize = min(q->max_hw_segments, q->max_phys_segments);
+       sdp->sg_tablesize = min(queue_max_hw_segments(q),
+                               queue_max_phys_segments(q));
        sdp->index = k;
        kref_init(&sdp->d_ref);
 
@@ -1654,6 +1656,10 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd)
                md->nr_entries = req_schp->k_use_sg;
                md->offset = 0;
                md->null_mapped = hp->dxferp ? 0 : 1;
+               if (dxfer_dir == SG_DXFER_TO_FROM_DEV)
+                       md->from_user = 1;
+               else
+                       md->from_user = 0;
        }
 
        if (iov_count) {
@@ -1694,9 +1700,10 @@ static int sg_start_req(Sg_request *srp, unsigned char *cmd)
        return res;
 }
 
-static void
-sg_finish_rem_req(Sg_request * srp)
+static int sg_finish_rem_req(Sg_request * srp)
 {
+       int ret = 0;
+
        Sg_fd *sfp = srp->parentfp;
        Sg_scatter_hold *req_schp = &srp->data;
 
@@ -1708,12 +1715,14 @@ sg_finish_rem_req(Sg_request * srp)
 
        if (srp->rq) {
                if (srp->bio)
-                       blk_rq_unmap_user(srp->bio);
+                       ret = blk_rq_unmap_user(srp->bio);
 
                blk_put_request(srp->rq);
        }
 
        sg_remove_request(sfp, srp);
+
+       return ret;
 }
 
 static int
@@ -1802,7 +1811,7 @@ retry:
        return 0;
 out:
        for (i = 0; i < k; i++)
-               __free_pages(schp->pages[k], order);
+               __free_pages(schp->pages[i], order);
 
        if (--order >= 0)
                goto retry;
@@ -2050,7 +2059,7 @@ sg_add_sfp(Sg_device * sdp, int dev)
                sg_big_buff = def_reserved_size;
 
        bufflen = min_t(int, sg_big_buff,
-                       sdp->device->request_queue->max_sectors * 512);
+                       queue_max_sectors(sdp->device->request_queue) * 512);
        sg_build_reserve(sfp, bufflen);
        SCSI_LOG_TIMEOUT(3, printk("sg_add_sfp:   bufflen=%d, k_use_sg=%d\n",
                           sfp->reserve.bufflen, sfp->reserve.k_use_sg));
@@ -2099,7 +2108,8 @@ static void sg_remove_sfp(struct kref *kref)
        write_unlock_irqrestore(&sg_index_lock, iflags);
        wake_up_interruptible(&sdp->o_excl_wait);
 
-       execute_in_process_context(sg_remove_sfp_usercontext, &sfp->ew);
+       INIT_WORK(&sfp->ew.work, sg_remove_sfp_usercontext);
+       schedule_work(&sfp->ew.work);
 }
 
 static int
@@ -2184,9 +2194,11 @@ static int sg_proc_seq_show_int(struct seq_file *s, void *v);
 static int sg_proc_single_open_adio(struct inode *inode, struct file *file);
 static ssize_t sg_proc_write_adio(struct file *filp, const char __user *buffer,
                                  size_t count, loff_t *off);
-static struct file_operations adio_fops = {
-       /* .owner, .read and .llseek added in sg_proc_init() */
+static const struct file_operations adio_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_single_open_adio,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .write = sg_proc_write_adio,
        .release = single_release,
 };
@@ -2194,23 +2206,32 @@ static struct file_operations adio_fops = {
 static int sg_proc_single_open_dressz(struct inode *inode, struct file *file);
 static ssize_t sg_proc_write_dressz(struct file *filp, 
                const char __user *buffer, size_t count, loff_t *off);
-static struct file_operations dressz_fops = {
+static const struct file_operations dressz_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_single_open_dressz,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .write = sg_proc_write_dressz,
        .release = single_release,
 };
 
 static int sg_proc_seq_show_version(struct seq_file *s, void *v);
 static int sg_proc_single_open_version(struct inode *inode, struct file *file);
-static struct file_operations version_fops = {
+static const struct file_operations version_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_single_open_version,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .release = single_release,
 };
 
 static int sg_proc_seq_show_devhdr(struct seq_file *s, void *v);
 static int sg_proc_single_open_devhdr(struct inode *inode, struct file *file);
-static struct file_operations devhdr_fops = {
+static const struct file_operations devhdr_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_single_open_devhdr,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .release = single_release,
 };
 
@@ -2219,11 +2240,14 @@ static int sg_proc_open_dev(struct inode *inode, struct file *file);
 static void * dev_seq_start(struct seq_file *s, loff_t *pos);
 static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos);
 static void dev_seq_stop(struct seq_file *s, void *v);
-static struct file_operations dev_fops = {
+static const struct file_operations dev_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_open_dev,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .release = seq_release,
 };
-static struct seq_operations dev_seq_ops = {
+static const struct seq_operations dev_seq_ops = {
        .start = dev_seq_start,
        .next  = dev_seq_next,
        .stop  = dev_seq_stop,
@@ -2232,11 +2256,14 @@ static struct seq_operations dev_seq_ops = {
 
 static int sg_proc_seq_show_devstrs(struct seq_file *s, void *v);
 static int sg_proc_open_devstrs(struct inode *inode, struct file *file);
-static struct file_operations devstrs_fops = {
+static const struct file_operations devstrs_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_open_devstrs,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .release = seq_release,
 };
-static struct seq_operations devstrs_seq_ops = {
+static const struct seq_operations devstrs_seq_ops = {
        .start = dev_seq_start,
        .next  = dev_seq_next,
        .stop  = dev_seq_stop,
@@ -2245,11 +2272,14 @@ static struct seq_operations devstrs_seq_ops = {
 
 static int sg_proc_seq_show_debug(struct seq_file *s, void *v);
 static int sg_proc_open_debug(struct inode *inode, struct file *file);
-static struct file_operations debug_fops = {
+static const struct file_operations debug_fops = {
+       .owner = THIS_MODULE,
        .open = sg_proc_open_debug,
+       .read = seq_read,
+       .llseek = seq_lseek,
        .release = seq_release,
 };
-static struct seq_operations debug_seq_ops = {
+static const struct seq_operations debug_seq_ops = {
        .start = dev_seq_start,
        .next  = dev_seq_next,
        .stop  = dev_seq_stop,
@@ -2259,7 +2289,7 @@ static struct seq_operations debug_seq_ops = {
 
 struct sg_proc_leaf {
        const char * name;
-       struct file_operations * fops;
+       const struct file_operations * fops;
 };
 
 static struct sg_proc_leaf sg_proc_leaf_arr[] = {
@@ -2285,9 +2315,6 @@ sg_proc_init(void)
        for (k = 0; k < num_leaves; ++k) {
                leaf = &sg_proc_leaf_arr[k];
                mask = leaf->fops->write ? S_IRUGO | S_IWUSR : S_IRUGO;
-               leaf->fops->owner = THIS_MODULE;
-               leaf->fops->read = seq_read;
-               leaf->fops->llseek = seq_lseek;
                proc_create(leaf->name, mask, sg_proc_sgp, leaf->fops);
        }
        return 0;