scsi: saner replacements for ->proc_info()
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 31 Mar 2013 03:58:05 +0000 (23:58 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Tue, 9 Apr 2013 18:13:14 +0000 (14:13 -0400)
It's still an obsolete interface; don't introduce those in new drivers.
However, it's saner than the ->proc_info() and commits after this one
will convert the existing ->proc_info() users to it.

The read side is ->show_info(seq_file *, struct Scsi_Host *); use
seq_... for generating contents.

The write side is ->write_info(struct Scsi_Host *, char *, int).

Again, this is driven by procfs needs; we are going to kill ->write_proc()
and ->read_proc() and this is the main obstacle to burying that piece of
shit.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/scsi/scsi_proc.c
include/scsi/scsi_host.h

index ad747dc..6f4c3cf 100644 (file)
@@ -97,6 +97,49 @@ out:
        return ret;
 }
 
+static ssize_t proc_scsi_host_write(struct file *file, const char __user *buf,
+                           size_t count, loff_t *ppos)
+{
+       struct Scsi_Host *shost = PDE(file_inode(file))->data;
+       ssize_t ret = -ENOMEM;
+       char *page;
+    
+       if (count > PROC_BLOCK_SIZE)
+               return -EOVERFLOW;
+
+       if (!shost->hostt->write_info)
+               return -EINVAL;
+
+       page = (char *)__get_free_page(GFP_KERNEL);
+       if (page) {
+               ret = -EFAULT;
+               if (copy_from_user(page, buf, count))
+                       goto out;
+               ret = shost->hostt->write_info(shost, page, count);
+       }
+out:
+       free_page((unsigned long)page);
+       return ret;
+}
+
+static int proc_scsi_show(struct seq_file *m, void *v)
+{
+       struct Scsi_Host *shost = m->private;
+       return shost->hostt->show_info(m, shost);
+}
+
+static int proc_scsi_host_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, proc_scsi_show, PDE(inode)->data);
+}
+
+static const struct file_operations proc_scsi_fops = {
+       .open = proc_scsi_host_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .write = proc_scsi_host_write
+};
+
 /**
  * scsi_proc_hostdir_add - Create directory in /proc for a scsi host
  * @sht: owner of this directory
@@ -106,7 +149,7 @@ out:
 
 void scsi_proc_hostdir_add(struct scsi_host_template *sht)
 {
-       if (!sht->proc_info)
+       if (!sht->proc_info && !sht->show_info)
                return;
 
        mutex_lock(&global_host_template_mutex);
@@ -125,7 +168,7 @@ void scsi_proc_hostdir_add(struct scsi_host_template *sht)
  */
 void scsi_proc_hostdir_rm(struct scsi_host_template *sht)
 {
-       if (!sht->proc_info)
+       if (!sht->proc_info && !sht->show_info)
                return;
 
        mutex_lock(&global_host_template_mutex);
@@ -151,16 +194,23 @@ void scsi_proc_host_add(struct Scsi_Host *shost)
                return;
 
        sprintf(name,"%d", shost->host_no);
+       if (sht->show_info) {
+               p = proc_create_data(name, S_IRUGO | S_IWUSR,
+                       sht->proc_dir, &proc_scsi_fops, shost);
+               if (!p)
+                       goto Fail;
+               return;
+       }
        p = create_proc_read_entry(name, S_IFREG | S_IRUGO | S_IWUSR,
                        sht->proc_dir, proc_scsi_read, shost);
-       if (!p) {
-               printk(KERN_ERR "%s: Failed to register host %d in"
-                      "%s\n", __func__, shost->host_no,
-                      sht->proc_name);
+       if (p) {
+               p->write_proc = proc_scsi_write_proc;
                return;
-       } 
-
-       p->write_proc = proc_scsi_write_proc;
+       }
+Fail:
+       printk(KERN_ERR "%s: Failed to register host %d in"
+              "%s\n", __func__, shost->host_no,
+              sht->proc_name);
 }
 
 /**
index 2b6956e..70e08e4 100644 (file)
@@ -6,6 +6,7 @@
 #include <linux/types.h>
 #include <linux/workqueue.h>
 #include <linux/mutex.h>
+#include <linux/seq_file.h>
 #include <scsi/scsi.h>
 
 struct request_queue;
@@ -341,6 +342,8 @@ struct scsi_host_template {
         * Status: OBSOLETE
         */
        int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
+       int (*show_info)(struct seq_file *, struct Scsi_Host *);
+       int (*write_info)(struct Scsi_Host *, char *, int);
 
        /*
         * This is an optional routine that allows the transport to become
@@ -375,7 +378,7 @@ struct scsi_host_template {
 
        /*
         * Used to store the procfs directory if a driver implements the
-        * proc_info method.
+        * proc_info or show_info method.
         */
        struct proc_dir_entry *proc_dir;