Whamcloud - gitweb
LU-14428 libcfs: discard cfs_trace_copyin_string()
[fs/lustre-release.git] / lnet / lnet / router_proc.c
index 126fe1e..c99454c 100644 (file)
@@ -36,7 +36,8 @@
  */
 #define LNET_PROC_CPT_BITS     (LNET_CPT_BITS + 1)
 /* change version, 16 bits or 8 bits */
-#define LNET_PROC_VER_BITS     MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8)
+#define LNET_PROC_VER_BITS             \
+       clamp_t(int, LNET_LOFFT_BITS / 4, 8, 16)
 
 #define LNET_PROC_HASH_BITS    LNET_PEER_HASH_BITS
 /*
@@ -84,8 +85,7 @@ static int __proc_lnet_stats(void *data, int write,
        struct lnet_counters *ctrs;
        struct lnet_counters_common common;
        int              len;
-       char            *tmpstr;
-       const int        tmpsiz = 256; /* 7 %u and 4 __u64 */
+       char tmpstr[256]; /* 7 %u and 4 u64 */
 
        if (write) {
                lnet_counters_reset();
@@ -98,16 +98,13 @@ static int __proc_lnet_stats(void *data, int write,
        if (ctrs == NULL)
                return -ENOMEM;
 
-       LIBCFS_ALLOC(tmpstr, tmpsiz);
-       if (tmpstr == NULL) {
-               LIBCFS_FREE(ctrs, sizeof(*ctrs));
-               return -ENOMEM;
-       }
+       rc = lnet_counters_get(ctrs);
+       if (rc)
+               goto out_no_ctrs;
 
-       lnet_counters_get(ctrs);
        common = ctrs->lct_common;
 
-       len = scnprintf(tmpstr, tmpsiz,
+       len = scnprintf(tmpstr, sizeof(tmpstr),
                        "%u %u %u %u %u %u %u %llu %llu "
                        "%llu %llu",
                        common.lcc_msgs_alloc, common.lcc_msgs_max,
@@ -122,8 +119,7 @@ static int __proc_lnet_stats(void *data, int write,
        else
                rc = cfs_trace_copyout_string(buffer, nob,
                                              tmpstr + pos, "\n");
-
-       LIBCFS_FREE(tmpstr, tmpsiz);
+out_no_ctrs:
        LIBCFS_FREE(ctrs, sizeof(*ctrs));
        return rc;
 }
@@ -800,11 +796,11 @@ static int __proc_lnet_portal_rotor(void *data, int write,
        int             rc;
        int             i;
 
-       LIBCFS_ALLOC(buf, buf_len);
-       if (buf == NULL)
-               return -ENOMEM;
-
        if (!write) {
+               LIBCFS_ALLOC(buf, buf_len);
+               if (buf == NULL)
+                       return -ENOMEM;
+
                lnet_res_lock(0);
 
                for (i = 0; portal_rotors[i].pr_value >= 0; i++) {
@@ -825,14 +821,16 @@ static int __proc_lnet_portal_rotor(void *data, int write,
                        rc = 0;
                } else {
                        rc = cfs_trace_copyout_string(buffer, nob,
-                                       buf + pos, "\n");
+                                                     buf + pos, "\n");
                }
-               goto out;
+               LIBCFS_FREE(buf, buf_len);
+
+               return rc;
        }
 
-       rc = cfs_trace_copyin_string(buf, buf_len, buffer, nob);
-       if (rc < 0)
-               goto out;
+       buf = memdup_user_nul(buffer, nob);
+       if (!buf)
+               return -ENOMEM;
 
        tmp = strim(buf);
 
@@ -847,8 +845,8 @@ static int __proc_lnet_portal_rotor(void *data, int write,
                }
        }
        lnet_res_unlock(0);
-out:
-       LIBCFS_FREE(buf, buf_len);
+       kfree(buf);
+
        return rc;
 }
 
@@ -901,6 +899,13 @@ static struct ctl_table lnet_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_lnet_portal_rotor,
        },
+       {
+               .procname       = "lnet_lnd_timeout",
+               .data           = &lnet_lnd_timeout,
+               .maxlen         = sizeof(lnet_lnd_timeout),
+               .mode           = 0444,
+               .proc_handler   = &debugfs_doint,
+       },
        { .procname = NULL }
 };