Whamcloud - gitweb
LU-9859 lnet: fold lprocfs_call_handler functionality into lnet_debugfs_* 09/44309/4
authorMr. NeilBrown <neilb@suse.de>
Wed, 4 Aug 2021 17:27:29 +0000 (13:27 -0400)
committerOleg Drokin <green@whamcloud.com>
Wed, 18 Aug 2021 01:59:31 +0000 (01:59 +0000)
The calling convention for ->proc_handler is rather clumsy,
as a comment in fs/procfs/proc_sysctl.c confirms.
lustre has copied this convention to lnet_debugfs_{read,write},
and then provided a wrapper for handlers - lprocfs_call_handler -
to work around the clumsiness.

It is cleaner to just fold the functionality of lprocfs_call_handler()
into lnet_debugfs_* and let them call the final handler directly.

If these files were ever moved to /proc/sys (which seems unlikely) the
handling in fs/procfs/proc_sysctl.c would need to be fixed to, but
that would not be a bad thing.

So modify all the functions that did use the wrapper to not need it
now that a more sane calling convention is available.

Signed-off-by: Mr. NeilBrown <neilb@suse.de>
Change-Id: I548ed6a3179cdb7cd5c024febd3fee4709285a82
Reviewed-on: https://review.whamcloud.com/44309
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Yang Sheng <ys@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/libcfs.h
libcfs/libcfs/module.c
lnet/lnet/router_proc.c

index 0556b6e..601ebfe 100644 (file)
@@ -88,10 +88,6 @@ void lnet_insert_debugfs(struct ctl_table *table);
 void lnet_remove_debugfs(struct ctl_table *table);
 
 /* helper for sysctl handlers */
 void lnet_remove_debugfs(struct ctl_table *table);
 
 /* helper for sysctl handlers */
-int lprocfs_call_handler(void *data, int write, loff_t *ppos,
-                        void __user *buffer, size_t *lenp,
-                        int (*handler)(void *data, int write, loff_t pos,
-                                       void __user *buffer, int len));
 int debugfs_doint(struct ctl_table *table, int write,
                  void __user *buffer, size_t *lenp, loff_t *ppos);
 
 int debugfs_doint(struct ctl_table *table, int write,
                  void __user *buffer, size_t *lenp, loff_t *ppos);
 
index 0554cc9..2355c8b 100644 (file)
@@ -267,33 +267,15 @@ static struct miscdevice libcfs_dev = {
        .fops                   = &libcfs_fops,
 };
 
        .fops                   = &libcfs_fops,
 };
 
-int lprocfs_call_handler(void *data, int write, loff_t *ppos,
-                        void __user *buffer, size_t *lenp,
-                        int (*handler)(void *data, int write, loff_t pos,
-                                       void __user *buffer, int len))
-{
-       int rc = handler(data, write, *ppos, buffer, *lenp);
-
-       if (rc < 0)
-               return rc;
-
-       if (write) {
-               *ppos += *lenp;
-       } else {
-               *lenp = rc;
-               *ppos += rc;
-       }
-       return 0;
-}
-EXPORT_SYMBOL(lprocfs_call_handler);
-
-static int __proc_dobitmasks(void *data, int write,
-                            loff_t pos, void __user *buffer, int nob)
+static int proc_dobitmasks(struct ctl_table *table, int write,
+                          void __user *buffer, size_t *lenp, loff_t *ppos)
 {
        const int     tmpstrlen = 512;
        char         *tmpstr = NULL;
        int           rc;
 {
        const int     tmpstrlen = 512;
        char         *tmpstr = NULL;
        int           rc;
-       unsigned int *mask = data;
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
+       unsigned int *mask = table->data;
        int           is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
        int           is_printk = (mask == &libcfs_printk) ? 1 : 0;
 
        int           is_subsys = (mask == &libcfs_subsystem_debug) ? 1 : 0;
        int           is_printk = (mask == &libcfs_printk) ? 1 : 0;
 
@@ -325,35 +307,26 @@ static int __proc_dobitmasks(void *data, int write,
        return rc;
 }
 
        return rc;
 }
 
-static int proc_dobitmasks(struct ctl_table *table, int write,
-                          void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_dobitmasks);
-}
-
 static int min_watchdog_ratelimit;             /* disable ratelimiting */
 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
 
 static int min_watchdog_ratelimit;             /* disable ratelimiting */
 static int max_watchdog_ratelimit = (24*60*60); /* limit to once per day */
 
-static int __proc_dump_kernel(void *data, int write,
-                             loff_t pos, void __user *buffer, int nob)
+static int proc_dump_kernel(struct ctl_table *table, int write,
+                           void __user *buffer, size_t *lenp, loff_t *ppos)
 {
 {
+       size_t nob = *lenp;
+
        if (!write)
                return 0;
 
        return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
 }
 
        if (!write)
                return 0;
 
        return cfs_trace_dump_debug_buffer_usrstr(buffer, nob);
 }
 
-static int proc_dump_kernel(struct ctl_table *table, int write,
+static int proc_daemon_file(struct ctl_table *table, int write,
                            void __user *buffer, size_t *lenp, loff_t *ppos)
 {
                            void __user *buffer, size_t *lenp, loff_t *ppos)
 {
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_dump_kernel);
-}
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
 
 
-static int __proc_daemon_file(void *data, int write,
-                             loff_t pos, void __user *buffer, int nob)
-{
        if (!write) {
                int len = strlen(cfs_tracefile);
 
        if (!write) {
                int len = strlen(cfs_tracefile);
 
@@ -367,13 +340,6 @@ static int __proc_daemon_file(void *data, int write,
        return cfs_trace_daemon_command_usrstr(buffer, nob);
 }
 
        return cfs_trace_daemon_command_usrstr(buffer, nob);
 }
 
-static int proc_daemon_file(struct ctl_table *table, int write,
-                           void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_daemon_file);
-}
-
 static int libcfs_force_lbug(struct ctl_table *table, int write,
                             void __user *buffer,
                             size_t *lenp, loff_t *ppos)
 static int libcfs_force_lbug(struct ctl_table *table, int write,
                             void __user *buffer,
                             size_t *lenp, loff_t *ppos)
@@ -534,9 +500,11 @@ static int debugfs_dostring(struct ctl_table *table, int write,
        return len;
 }
 
        return len;
 }
 
-static int __proc_cpt_table(void *data, int write,
-                           loff_t pos, void __user *buffer, int nob)
+static int proc_cpt_table(struct ctl_table *table, int write,
+                         void __user *buffer, size_t *lenp, loff_t *ppos)
 {
 {
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
        char *buf = NULL;
        int   len = 4096;
        int   rc  = 0;
        char *buf = NULL;
        int   len = 4096;
        int   rc  = 0;
@@ -573,16 +541,11 @@ out:
        return rc;
 }
 
        return rc;
 }
 
-static int proc_cpt_table(struct ctl_table *table, int write,
-                         void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_cpt_table);
-}
-
-static int __proc_cpt_distance(void *data, int write,
-                              loff_t pos, void __user *buffer, int nob)
+static int proc_cpt_distance(struct ctl_table *table, int write,
+                            void __user *buffer, size_t *lenp, loff_t *ppos)
 {
 {
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
        char *buf = NULL;
        int   len = 4096;
        int   rc  = 0;
        char *buf = NULL;
        int   len = 4096;
        int   rc  = 0;
@@ -619,13 +582,6 @@ static int __proc_cpt_distance(void *data, int write,
        return rc;
 }
 
        return rc;
 }
 
-static int proc_cpt_distance(struct ctl_table *table, int write,
-                            void __user *buffer, size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                    __proc_cpt_distance);
-}
-
 static struct ctl_table lnet_table[] = {
        {
                .procname       = "debug",
 static struct ctl_table lnet_table[] = {
        {
                .procname       = "debug",
@@ -756,13 +712,20 @@ static ssize_t lnet_debugfs_read(struct file *filp, char __user *buf,
                                 size_t count, loff_t *ppos)
 {
        struct ctl_table *table = filp->private_data;
                                 size_t count, loff_t *ppos)
 {
        struct ctl_table *table = filp->private_data;
+       loff_t old_pos = *ppos;
        ssize_t rc = -EINVAL;
 
        ssize_t rc = -EINVAL;
 
-       if (table) {
-               rc = table->proc_handler(table, 0, buf, &count, ppos);
-               if (!rc)
-                       rc = count;
-       }
+       if (table)
+               rc = table->proc_handler(table, 0, (void __user *)buf,
+                                        &count, ppos);
+       /*
+        * On success, the length read is either in error or in count.
+        * If ppos changed, then use count, else use error
+        */
+       if (!rc && *ppos != old_pos)
+               rc = count;
+       else if (rc > 0)
+               *ppos += rc;
 
        return rc;
 }
 
        return rc;
 }
@@ -771,16 +734,19 @@ static ssize_t lnet_debugfs_write(struct file *filp, const char __user *buf,
                                  size_t count, loff_t *ppos)
 {
        struct ctl_table *table = filp->private_data;
                                  size_t count, loff_t *ppos)
 {
        struct ctl_table *table = filp->private_data;
+       loff_t old_pos = *ppos;
        ssize_t rc = -EINVAL;
 
        ssize_t rc = -EINVAL;
 
-       if (table) {
+       if (table)
                rc = table->proc_handler(table, 1, (void __user *)buf, &count,
                                         ppos);
                rc = table->proc_handler(table, 1, (void __user *)buf, &count,
                                         ppos);
-               if (!rc)
-                       rc = count;
-       }
+       if (rc)
+               return rc;
 
 
-       return rc;
+       if (*ppos == old_pos)
+               *ppos += count;
+
+       return count;
 }
 
 static const struct file_operations lnet_debugfs_file_operations_rw = {
 }
 
 static const struct file_operations lnet_debugfs_file_operations_rw = {
index 5d84c73..df5e25a 100644 (file)
 
 #define LNET_PROC_VERSION(v)   ((unsigned int)((v) & LNET_PROC_VER_MASK))
 
 
 #define LNET_PROC_VERSION(v)   ((unsigned int)((v) & LNET_PROC_VER_MASK))
 
-static int __proc_lnet_stats(void *data, int write,
-                            loff_t pos, void __user *buffer, int nob)
+static int proc_lnet_stats(struct ctl_table *table, int write,
+                          void __user *buffer, size_t *lenp, loff_t *ppos)
 {
 {
-       int              rc;
+       int rc;
        struct lnet_counters *ctrs;
        struct lnet_counters_common common;
        struct lnet_counters *ctrs;
        struct lnet_counters_common common;
-       int              len;
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
+       int len;
        char tmpstr[256]; /* 7 %u and 4 u64 */
 
        if (write) {
        char tmpstr[256]; /* 7 %u and 4 u64 */
 
        if (write) {
@@ -125,14 +127,6 @@ out_no_ctrs:
 }
 
 static int
 }
 
 static int
-proc_lnet_stats(struct ctl_table *table, int write, void __user *buffer,
-               size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_lnet_stats);
-}
-
-static int
 proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer,
                 size_t *lenp, loff_t *ppos)
 {
 proc_lnet_routes(struct ctl_table *table, int write, void __user *buffer,
                 size_t *lenp, loff_t *ppos)
 {
@@ -541,9 +535,11 @@ proc_lnet_peers(struct ctl_table *table, int write, void __user *buffer,
        return rc;
 }
 
        return rc;
 }
 
-static int __proc_lnet_buffers(void *data, int write,
-                              loff_t pos, void __user *buffer, int nob)
+static int proc_lnet_buffers(struct ctl_table *table, int write,
+                            void __user *buffer, size_t *lenp, loff_t *ppos)
 {
 {
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
        char            *s;
        char            *tmpstr;
        int             tmpsiz;
        char            *s;
        char            *tmpstr;
        int             tmpsiz;
@@ -600,14 +596,6 @@ static int __proc_lnet_buffers(void *data, int write,
 }
 
 static int
 }
 
 static int
-proc_lnet_buffers(struct ctl_table *table, int write, void __user *buffer,
-                 size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_lnet_buffers);
-}
-
-static int
 proc_lnet_nis(struct ctl_table *table, int write, void __user *buffer,
              size_t *lenp, loff_t *ppos)
 {
 proc_lnet_nis(struct ctl_table *table, int write, void __user *buffer,
              size_t *lenp, loff_t *ppos)
 {
@@ -787,10 +775,13 @@ static struct lnet_portal_rotors  portal_rotors[] = {
        },
 };
 
        },
 };
 
-static int __proc_lnet_portal_rotor(void *data, int write,
-                                   loff_t pos, void __user *buffer, int nob)
+static int proc_lnet_portal_rotor(struct ctl_table *table, int write,
+                                 void __user *buffer, size_t *lenp,
+                                 loff_t *ppos)
 {
        const int       buf_len = 128;
 {
        const int       buf_len = 128;
+       size_t nob = *lenp;
+       loff_t pos = *ppos;
        char            *buf;
        char            *tmp;
        int             rc;
        char            *buf;
        char            *tmp;
        int             rc;
@@ -850,15 +841,6 @@ static int __proc_lnet_portal_rotor(void *data, int write,
        return rc;
 }
 
        return rc;
 }
 
-static int
-proc_lnet_portal_rotor(struct ctl_table *table, int write, void __user *buffer,
-                      size_t *lenp, loff_t *ppos)
-{
-       return lprocfs_call_handler(table->data, write, ppos, buffer, lenp,
-                                   __proc_lnet_portal_rotor);
-}
-
-
 static struct ctl_table lnet_table[] = {
        /*
         * NB No .strategy entries have been provided since sysctl(8) prefers
 static struct ctl_table lnet_table[] = {
        /*
         * NB No .strategy entries have been provided since sysctl(8) prefers