Whamcloud - gitweb
LU-8767 llite: Improve proc file text in lproc_llite.c
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index fdbe966..ab3c1a2 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -54,6 +50,7 @@ struct proc_dir_entry *proc_lustre_fs_root;
 static const struct file_operations ll_rw_extents_stats_fops;
 static const struct file_operations ll_rw_extents_stats_pp_fops;
 static const struct file_operations ll_rw_offset_stats_fops;
+static __s64 ll_stats_pid_write(const char __user *buf, size_t len);
 
 static int ll_blksize_seq_show(struct seq_file *m, void *v)
 {
@@ -88,7 +85,7 @@ static int ll_kbytestotal_seq_show(struct seq_file *m, void *v)
                while (blk_size >>= 1)
                        result <<= 1;
 
-               seq_printf(m, LPU64"\n", result);
+               seq_printf(m, "%llu\n", result);
        }
        return rc;
 }
@@ -111,7 +108,7 @@ static int ll_kbytesfree_seq_show(struct seq_file *m, void *v)
                while (blk_size >>= 1)
                        result <<= 1;
 
-               seq_printf(m, LPU64"\n", result);
+               seq_printf(m, "%llu\n", result);
        }
        return rc;
 }
@@ -134,7 +131,7 @@ static int ll_kbytesavail_seq_show(struct seq_file *m, void *v)
                while (blk_size >>= 1)
                        result <<= 1;
 
-               seq_printf(m, LPU64"\n", result);
+               seq_printf(m, "%llu\n", result);
        }
        return rc;
 }
@@ -151,7 +148,7 @@ static int ll_filestotal_seq_show(struct seq_file *m, void *v)
                                cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                                OBD_STATFS_NODELAY);
        if (!rc)
-               seq_printf(m, LPU64"\n", osfs.os_files);
+               seq_printf(m, "%llu\n", osfs.os_files);
        return rc;
 }
 LPROC_SEQ_FOPS_RO(ll_filestotal);
@@ -167,7 +164,7 @@ static int ll_filesfree_seq_show(struct seq_file *m, void *v)
                                cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
                                OBD_STATFS_NODELAY);
        if (!rc)
-               seq_printf(m, LPU64"\n", osfs.os_ffree);
+               seq_printf(m, "%llu\n", osfs.os_ffree);
        return rc;
 }
 LPROC_SEQ_FOPS_RO(ll_filesfree);
@@ -178,10 +175,7 @@ static int ll_client_type_seq_show(struct seq_file *m, void *v)
 
        LASSERT(sbi != NULL);
 
-       if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
-               seq_puts(m, "remote client\n");
-       else
-               seq_puts(m, "local client\n");
+       seq_puts(m, "local client\n");
        return 0;
 }
 LPROC_SEQ_FOPS_RO(ll_client_type);
@@ -262,7 +256,7 @@ static int ll_max_readahead_mb_seq_show(struct seq_file *m, void *v)
        pages_number = sbi->ll_ra_info.ra_max_pages;
        spin_unlock(&sbi->ll_lock);
 
-       mult = 1 << (20 - PAGE_CACHE_SHIFT);
+       mult = 1 << (20 - PAGE_SHIFT);
        return lprocfs_seq_read_frac_helper(m, pages_number, mult);
 }
 
@@ -280,14 +274,14 @@ ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
        if (rc)
                return rc;
 
-       pages_number >>= PAGE_CACHE_SHIFT;
+       pages_number >>= PAGE_SHIFT;
 
        if (pages_number < 0 || pages_number > totalram_pages / 2) {
                /* 1/2 of RAM */
                CERROR("%s: can't set max_readahead_mb=%lu > %luMB\n",
                       ll_get_fsname(sb, NULL, 0),
-                      (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
-                      totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1));
+                      (unsigned long)pages_number >> (20 - PAGE_SHIFT),
+                      totalram_pages >> (20 - PAGE_SHIFT + 1));
                return -ERANGE;
        }
 
@@ -309,7 +303,7 @@ static int ll_max_readahead_per_file_mb_seq_show(struct seq_file *m, void *v)
        pages_number = sbi->ll_ra_info.ra_max_pages_per_file;
        spin_unlock(&sbi->ll_lock);
 
-       mult = 1 << (20 - PAGE_CACHE_SHIFT);
+       mult = 1 << (20 - PAGE_SHIFT);
        return lprocfs_seq_read_frac_helper(m, pages_number, mult);
 }
 
@@ -328,13 +322,13 @@ ll_max_readahead_per_file_mb_seq_write(struct file *file,
        if (rc)
                return rc;
 
-       pages_number >>= PAGE_CACHE_SHIFT;
+       pages_number >>= PAGE_SHIFT;
 
        if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
                CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
                       "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
-                      (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
-                      sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_CACHE_SHIFT));
+                      (unsigned long)pages_number >> (20 - PAGE_SHIFT),
+                      sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_SHIFT));
                return -ERANGE;
        }
 
@@ -356,7 +350,7 @@ static int ll_max_read_ahead_whole_mb_seq_show(struct seq_file *m, void *v)
        pages_number = sbi->ll_ra_info.ra_max_read_ahead_whole_pages;
        spin_unlock(&sbi->ll_lock);
 
-       mult = 1 << (20 - PAGE_CACHE_SHIFT);
+       mult = 1 << (20 - PAGE_SHIFT);
        return lprocfs_seq_read_frac_helper(m, pages_number, mult);
 }
 
@@ -375,13 +369,13 @@ ll_max_read_ahead_whole_mb_seq_write(struct file *file,
        if (rc)
                return rc;
 
-       pages_number >>= PAGE_CACHE_SHIFT;
+       pages_number >>= PAGE_SHIFT;
 
        /* Cap this at the current max readahead window size, the readahead
         * algorithm does this anyway so it's pointless to set it larger. */
        if (pages_number < 0 ||
            pages_number > sbi->ll_ra_info.ra_max_pages_per_file) {
-               int pages_shift = 20 - PAGE_CACHE_SHIFT;
+               int pages_shift = 20 - PAGE_SHIFT;
                CERROR("%s: can't set max_read_ahead_whole_mb=%lu > "
                       "max_read_ahead_per_file_mb=%lu\n",
                       ll_get_fsname(sb, NULL, 0),
@@ -402,7 +396,7 @@ static int ll_max_cached_mb_seq_show(struct seq_file *m, void *v)
        struct super_block     *sb    = m->private;
        struct ll_sb_info      *sbi   = ll_s2sbi(sb);
        struct cl_client_cache *cache = sbi->ll_cache;
-       int shift = 20 - PAGE_CACHE_SHIFT;
+       int shift = 20 - PAGE_SHIFT;
        long max_cached_mb;
        long unused_mb;
 
@@ -451,12 +445,12 @@ ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
        if (rc)
                RETURN(rc);
 
-       pages_number >>= PAGE_CACHE_SHIFT;
+       pages_number >>= PAGE_SHIFT;
 
        if (pages_number < 0 || pages_number > totalram_pages) {
                CERROR("%s: can't set max cache more than %lu MB\n",
                       ll_get_fsname(sb, NULL, 0),
-                      totalram_pages >> (20 - PAGE_CACHE_SHIFT));
+                      totalram_pages >> (20 - PAGE_SHIFT));
                RETURN(-ERANGE);
        }
        /* Allow enough cache so clients can make well-formed RPCs */
@@ -672,7 +666,7 @@ static ssize_t ll_statahead_max_seq_write(struct file *file,
        if (val >= 0 && val <= LL_SA_RPC_MAX)
                sbi->ll_sa_max = val;
        else
-               CERROR("Bad statahead_max value "LPD64". Valid values are in "
+               CERROR("Bad statahead_max value %lld. Valid values are in "
                       "the range [0, %d]\n", val, LL_SA_RPC_MAX);
 
        return count;
@@ -910,7 +904,7 @@ static int ll_unstable_stats_seq_show(struct seq_file *m, void *v)
        int mb;
 
        pages = atomic_long_read(&cache->ccc_unstable_nr);
-       mb    = (pages * PAGE_CACHE_SIZE) >> 20;
+       mb    = (pages * PAGE_SIZE) >> 20;
 
        seq_printf(m, "unstable_check:     %8d\n"
                   "unstable_pages: %12ld\n"
@@ -1387,9 +1381,9 @@ static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
        do_gettimeofday(&now);
 
        if (!sbi->ll_rw_stats_on) {
-               seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \[D/d]isabled\" to deactivate\n");
-                return 0;
-        }
+               seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
+               return 0;
+       }
         seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
                    now.tv_sec, now.tv_usec);
         seq_printf(seq, "%15s %19s       | %20s\n", " ", "read", "write");
@@ -1417,27 +1411,12 @@ static ssize_t ll_rw_extents_stats_pp_seq_write(struct file *file,
        struct ll_sb_info *sbi = seq->private;
        struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
        int i;
-       __s64 value = 1;
-       int rc = 0;
+       __s64 value;
 
        if (len == 0)
                return -EINVAL;
 
-       rc = lprocfs_str_to_s64(buf, len, &value);
-       if (rc < 0 && len < 16) {
-               char kernbuf[16];
-
-               if (copy_from_user(kernbuf, buf, len))
-                       return -EFAULT;
-               kernbuf[len] = 0;
-
-               if (kernbuf[len - 1] == '\n')
-                       kernbuf[len - 1] = 0;
-
-               if (strcmp(kernbuf, "disabled") == 0 ||
-                   strcmp(kernbuf, "Disabled") == 0)
-                       value = 0;
-       }
+       value = ll_stats_pid_write(buf, len);
 
        if (value == 0)
                sbi->ll_rw_stats_on = 0;
@@ -1465,7 +1444,7 @@ static int ll_rw_extents_stats_seq_show(struct seq_file *seq, void *v)
        do_gettimeofday(&now);
 
        if (!sbi->ll_rw_stats_on) {
-               seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
+               seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
                return 0;
        }
        seq_printf(seq, "snapshot_time:         %lu.%lu (secs.usecs)\n",
@@ -1490,27 +1469,12 @@ static ssize_t ll_rw_extents_stats_seq_write(struct file *file,
        struct ll_sb_info *sbi = seq->private;
        struct ll_rw_extents_info *io_extents = &sbi->ll_rw_extents_info;
        int i;
-       __s64 value = 1;
-       int rc = 0;
+       __s64 value;
 
        if (len == 0)
                return -EINVAL;
 
-       rc = lprocfs_str_to_s64(buf, len, &value);
-       if (rc < 0 && len < 16) {
-               char kernbuf[16];
-
-               if (copy_from_user(kernbuf, buf, len))
-                       return -EFAULT;
-               kernbuf[len] = 0;
-
-               if (kernbuf[len - 1] == '\n')
-                       kernbuf[len - 1] = 0;
-
-               if (strcmp(kernbuf, "disabled") == 0 ||
-                   strcmp(kernbuf, "Disabled") == 0)
-                       value = 0;
-       }
+       value = ll_stats_pid_write(buf, len);
 
        if (value == 0)
                sbi->ll_rw_stats_on = 0;
@@ -1643,7 +1607,7 @@ static int ll_rw_offset_stats_seq_show(struct seq_file *seq, void *v)
        do_gettimeofday(&now);
 
        if (!sbi->ll_rw_stats_on) {
-               seq_puts(seq, "disabled\n write anything in this file to activate, then 0 or \"[D/d]isabled\" to deactivate\n");
+               seq_puts(seq, "disabled\n write anything to this file to activate, then '0' or 'disable' to deactivate\n");
                return 0;
        }
        spin_lock(&sbi->ll_process_lock);
@@ -1694,28 +1658,12 @@ static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
        struct ll_sb_info *sbi = seq->private;
        struct ll_rw_process_info *process_info = sbi->ll_rw_process_info;
        struct ll_rw_process_info *offset_info = sbi->ll_rw_offset_info;
-       __s64 value = 1;
-       int rc = 0;
+       __s64 value;
 
        if (len == 0)
                return -EINVAL;
 
-       rc = lprocfs_str_to_s64(buf, len, &value);
-
-       if (rc < 0 && len < 16) {
-               char kernbuf[16];
-
-               if (copy_from_user(kernbuf, buf, len))
-                       return -EFAULT;
-               kernbuf[len] = 0;
-
-               if (kernbuf[len - 1] == '\n')
-                       kernbuf[len - 1] = 0;
-
-               if (strcmp(kernbuf, "disabled") == 0 ||
-                   strcmp(kernbuf, "Disabled") == 0)
-                       value = 0;
-       }
+       value = ll_stats_pid_write(buf, len);
 
        if (value == 0)
                sbi->ll_rw_stats_on = 0;
@@ -1734,5 +1682,42 @@ static ssize_t ll_rw_offset_stats_seq_write(struct file *file,
        return len;
 }
 
+/**
+ * ll_stats_pid_write() - Determine if stats collection should be enabled
+ * @buf: Buffer containing the data written
+ * @len: Number of bytes in the buffer
+ *
+ * Several proc files begin collecting stats when a value is written, and stop
+ * collecting when either '0' or 'disable' is written. This function checks the
+ * written value to see if collection should be enabled or disabled.
+ *
+ * Return: If '0' or 'disable' is provided, 0 is returned. If the text
+ * equivalent of a number is written, that number is returned. Otherwise,
+ * 1 is returned. Non-zero return values indicate collection should be enabled.
+ */
+static __s64 ll_stats_pid_write(const char __user *buf, size_t len)
+{
+       __s64 value = 1;
+       int rc;
+       char kernbuf[16];
+
+       rc = lprocfs_str_to_s64(buf, len, &value);
+
+       if (rc < 0 && len < sizeof(kernbuf)) {
+
+               if (copy_from_user(kernbuf, buf, len))
+                       return -EFAULT;
+               kernbuf[len] = 0;
+
+               if (kernbuf[len - 1] == '\n')
+                       kernbuf[len - 1] = 0;
+
+               if (strncasecmp(kernbuf, "disable", 7) == 0)
+                       value = 0;
+       }
+
+       return value;
+}
+
 LPROC_SEQ_FOPS(ll_rw_offset_stats);
 #endif /* CONFIG_PROC_FS */