svc: Add /proc/sys/sunrpc/transport files

Add a file that when read lists the set of registered svc
transports.

Signed-off-by: Tom Tucker <tom@opengridcomputing.com>
Acked-by: Neil Brown <neilb@suse.de>
Reviewed-by: Chuck Lever <chuck.lever@oracle.com>
Reviewed-by: Greg Banks <gnb@sgi.com>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>

authored by Tom Tucker and committed by J. Bruce Fields dc9a16e4 260c1d12

+60
+1
include/linux/sunrpc/svc_xprt.h
··· 79 void svc_close_xprt(struct svc_xprt *xprt); 80 void svc_delete_xprt(struct svc_xprt *xprt); 81 int svc_port_is_privileged(struct sockaddr *sin); 82 83 static inline void svc_xprt_get(struct svc_xprt *xprt) 84 {
··· 79 void svc_close_xprt(struct svc_xprt *xprt); 80 void svc_delete_xprt(struct svc_xprt *xprt); 81 int svc_port_is_privileged(struct sockaddr *sin); 82 + int svc_print_xprts(char *buf, int maxlen); 83 84 static inline void svc_xprt_get(struct svc_xprt *xprt) 85 {
+28
net/sunrpc/svc_xprt.c
··· 112 } 113 EXPORT_SYMBOL_GPL(svc_unreg_xprt_class); 114 115 static void svc_xprt_free(struct kref *kref) 116 { 117 struct svc_xprt *xprt =
··· 112 } 113 EXPORT_SYMBOL_GPL(svc_unreg_xprt_class); 114 115 + /* 116 + * Format the transport list for printing 117 + */ 118 + int svc_print_xprts(char *buf, int maxlen) 119 + { 120 + struct list_head *le; 121 + char tmpstr[80]; 122 + int len = 0; 123 + buf[0] = '\0'; 124 + 125 + spin_lock(&svc_xprt_class_lock); 126 + list_for_each(le, &svc_xprt_class_list) { 127 + int slen; 128 + struct svc_xprt_class *xcl = 129 + list_entry(le, struct svc_xprt_class, xcl_list); 130 + 131 + sprintf(tmpstr, "%s %d\n", xcl->xcl_name, xcl->xcl_max_payload); 132 + slen = strlen(tmpstr); 133 + if (len + slen > maxlen) 134 + break; 135 + len += slen; 136 + strcat(buf, tmpstr); 137 + } 138 + spin_unlock(&svc_xprt_class_lock); 139 + 140 + return len; 141 + } 142 + 143 static void svc_xprt_free(struct kref *kref) 144 { 145 struct svc_xprt *xprt =
+31
net/sunrpc/sysctl.c
··· 18 #include <linux/sunrpc/types.h> 19 #include <linux/sunrpc/sched.h> 20 #include <linux/sunrpc/stats.h> 21 22 /* 23 * Declare the debug flags here ··· 54 unregister_sysctl_table(sunrpc_table_header); 55 sunrpc_table_header = NULL; 56 } 57 } 58 59 static int ··· 171 .maxlen = sizeof(int), 172 .mode = 0644, 173 .proc_handler = &proc_dodebug 174 }, 175 { .ctl_name = 0 } 176 };
··· 18 #include <linux/sunrpc/types.h> 19 #include <linux/sunrpc/sched.h> 20 #include <linux/sunrpc/stats.h> 21 + #include <linux/sunrpc/svc_xprt.h> 22 23 /* 24 * Declare the debug flags here ··· 53 unregister_sysctl_table(sunrpc_table_header); 54 sunrpc_table_header = NULL; 55 } 56 + } 57 + 58 + static int proc_do_xprt(ctl_table *table, int write, struct file *file, 59 + void __user *buffer, size_t *lenp, loff_t *ppos) 60 + { 61 + char tmpbuf[256]; 62 + int len; 63 + if ((*ppos && !write) || !*lenp) { 64 + *lenp = 0; 65 + return 0; 66 + } 67 + if (write) 68 + return -EINVAL; 69 + else { 70 + len = svc_print_xprts(tmpbuf, sizeof(tmpbuf)); 71 + if (!access_ok(VERIFY_WRITE, buffer, len)) 72 + return -EFAULT; 73 + 74 + if (__copy_to_user(buffer, tmpbuf, len)) 75 + return -EFAULT; 76 + } 77 + *lenp -= len; 78 + *ppos += len; 79 + return 0; 80 } 81 82 static int ··· 146 .maxlen = sizeof(int), 147 .mode = 0644, 148 .proc_handler = &proc_dodebug 149 + }, 150 + { 151 + .procname = "transports", 152 + .maxlen = 256, 153 + .mode = 0444, 154 + .proc_handler = &proc_do_xprt, 155 }, 156 { .ctl_name = 0 } 157 };