Whamcloud - gitweb
LU-7334 lprocfs: Refactored string to value helpers
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index 1767a00..dba3bac 100644 (file)
@@ -220,9 +220,10 @@ static ssize_t ll_xattr_cache_seq_write(struct file *file,
 {
        struct seq_file *m = file->private_data;
        struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
-       int val, rc;
+       __s64 val;
+       int rc;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
        if (rc)
                return rc;
 
@@ -272,26 +273,21 @@ ll_max_readahead_mb_seq_write(struct file *file, const char __user *buffer,
        struct seq_file *m = file->private_data;
        struct super_block *sb = m->private;
        struct ll_sb_info *sbi = ll_s2sbi(sb);
-       __u64 val;
-       long pages_number;
-       int pages_shift;
+       __s64 pages_number;
        int rc;
 
-       pages_shift = 20 - PAGE_CACHE_SHIFT;
-       rc = lprocfs_write_frac_u64_helper(buffer, count, &val,
-                                          1 << pages_shift);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
        if (rc)
                return rc;
 
-       if (val > LONG_MAX)
-               return -ERANGE;
-       pages_number = (long)val;
+       pages_number >>= PAGE_CACHE_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), pages_number >> pages_shift,
-                      totalram_pages >> (pages_shift + 1));
+                      ll_get_fsname(sb, NULL, 0),
+                      (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
+                      totalram_pages >> (20 - PAGE_CACHE_SHIFT + 1));
                return -ERANGE;
        }
 
@@ -325,19 +321,20 @@ ll_max_readahead_per_file_mb_seq_write(struct file *file,
        struct seq_file *m = file->private_data;
        struct super_block *sb = m->private;
        struct ll_sb_info *sbi = ll_s2sbi(sb);
-       int pages_shift, rc, pages_number;
+       int rc;
+       __s64 pages_number;
 
-       pages_shift = 20 - PAGE_CACHE_SHIFT;
-       rc = lprocfs_write_frac_helper(buffer, count, &pages_number,
-                                      1 << pages_shift);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
        if (rc)
                return rc;
 
+       pages_number >>= PAGE_CACHE_SHIFT;
+
        if (pages_number < 0 || pages_number > sbi->ll_ra_info.ra_max_pages) {
-               CERROR("%s: can't set max_readahead_per_file_mb=%u > "
+               CERROR("%s: can't set max_readahead_per_file_mb=%lu > "
                       "max_read_ahead_mb=%lu\n", ll_get_fsname(sb, NULL, 0),
-                      pages_number >> pages_shift,
-                      sbi->ll_ra_info.ra_max_pages >> pages_shift);
+                      (unsigned long)pages_number >> (20 - PAGE_CACHE_SHIFT),
+                      sbi->ll_ra_info.ra_max_pages >> (20 - PAGE_CACHE_SHIFT));
                return -ERANGE;
        }
 
@@ -371,22 +368,24 @@ ll_max_read_ahead_whole_mb_seq_write(struct file *file,
        struct seq_file *m = file->private_data;
        struct super_block *sb = m->private;
        struct ll_sb_info *sbi = ll_s2sbi(sb);
-       int pages_shift, rc, pages_number;
+       int rc;
+       __s64 pages_number;
 
-       pages_shift = 20 - PAGE_CACHE_SHIFT;
-       rc = lprocfs_write_frac_helper(buffer, count, &pages_number,
-                                      1 << pages_shift);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
        if (rc)
                return rc;
 
+       pages_number >>= PAGE_CACHE_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) {
-               CERROR("%s: can't set max_read_ahead_whole_mb=%u > "
+               int pages_shift = 20 - PAGE_CACHE_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),
-                      pages_number >> pages_shift,
+                      (unsigned long)pages_number >> pages_shift,
                       sbi->ll_ra_info.ra_max_pages_per_file >> pages_shift);
                return -ERANGE;
        }
@@ -431,12 +430,10 @@ ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
        struct ll_sb_info *sbi = ll_s2sbi(sb);
        struct cl_client_cache *cache = sbi->ll_cache;
        struct lu_env *env;
-       __u64 val;
        long diff = 0;
        long nrpages = 0;
-       long pages_number;
        __u16 refcheck;
-       int mult;
+       __s64 pages_number;
        long rc;
        char kernbuf[128];
        ENTRY;
@@ -448,16 +445,13 @@ ll_max_cached_mb_seq_write(struct file *file, const char __user *buffer,
                RETURN(-EFAULT);
        kernbuf[count] = 0;
 
-       mult = 1 << (20 - PAGE_CACHE_SHIFT);
        buffer += lprocfs_find_named_value(kernbuf, "max_cached_mb:", &count) -
                  kernbuf;
-       rc = lprocfs_write_frac_u64_helper(buffer, count, &val, mult);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
        if (rc)
                RETURN(rc);
 
-       if (val > LONG_MAX)
-               return -ERANGE;
-       pages_number = (long)val;
+       pages_number >>= PAGE_CACHE_SHIFT;
 
        if (pages_number < 0 || pages_number > totalram_pages) {
                CERROR("%s: can't set max cache more than %lu MB\n",
@@ -550,26 +544,27 @@ static ssize_t ll_checksum_seq_write(struct file *file,
 {
        struct seq_file *m = file->private_data;
        struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
-        int val, rc;
+       int rc;
+       __s64 val;
 
-        if (!sbi->ll_dt_exp)
-                /* Not set up yet */
-                return -EAGAIN;
+       if (!sbi->ll_dt_exp)
+               /* Not set up yet */
+               return -EAGAIN;
 
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
-        if (val)
-                sbi->ll_flags |= LL_SBI_CHECKSUM;
-        else
-                sbi->ll_flags &= ~LL_SBI_CHECKSUM;
-
-        rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
-                                KEY_CHECKSUM, sizeof(val), &val, NULL);
-        if (rc)
-                CWARN("Failed to set OSC checksum flags: %d\n", rc);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
+       if (rc)
+               return rc;
+       if (val)
+               sbi->ll_flags |= LL_SBI_CHECKSUM;
+       else
+               sbi->ll_flags &= ~LL_SBI_CHECKSUM;
 
-        return count;
+       rc = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
+                               KEY_CHECKSUM, sizeof(val), &val, NULL);
+       if (rc)
+               CWARN("Failed to set OSC checksum flags: %d\n", rc);
+
+       return count;
 }
 LPROC_SEQ_FOPS(ll_checksum);
 
@@ -592,18 +587,22 @@ static int ll_wr_track_id(const char __user *buffer, unsigned long count,
                          void *data, enum stats_track_type type)
 {
        struct super_block *sb = data;
-        int rc, pid;
+       int rc;
+       __s64 pid;
 
-        rc = lprocfs_write_helper(buffer, count, &pid);
-        if (rc)
-                return rc;
-        ll_s2sbi(sb)->ll_stats_track_id = pid;
-        if (pid == 0)
-                ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
-        else
-                ll_s2sbi(sb)->ll_stats_track_type = type;
-        lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
-        return count;
+       rc = lprocfs_str_to_s64(buffer, count, &pid);
+       if (rc)
+               return rc;
+       if (pid > INT_MAX || pid < 0)
+               return -ERANGE;
+
+       ll_s2sbi(sb)->ll_stats_track_id = pid;
+       if (pid == 0)
+               ll_s2sbi(sb)->ll_stats_track_type = STATS_TRACK_ALL;
+       else
+               ll_s2sbi(sb)->ll_stats_track_type = type;
+       lprocfs_clear_stats(ll_s2sbi(sb)->ll_stats);
+       return count;
 }
 
 static int ll_track_pid_seq_show(struct seq_file *m, void *v)
@@ -663,19 +662,20 @@ static ssize_t ll_statahead_max_seq_write(struct file *file,
 {
        struct seq_file *m = file->private_data;
        struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
-       int val, rc;
+       int rc;
+       __s64 val;
 
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
+       rc = lprocfs_str_to_s64(buffer, count, &val);
+       if (rc)
+               return rc;
 
-        if (val >= 0 && val <= LL_SA_RPC_MAX)
-                sbi->ll_sa_max = val;
-        else
-                CERROR("Bad statahead_max value %d. Valid values are in the "
-                       "range [0, %d]\n", val, LL_SA_RPC_MAX);
+       if (val >= 0 && val <= LL_SA_RPC_MAX)
+               sbi->ll_sa_max = val;
+       else
+               CERROR("Bad statahead_max value "LPD64". Valid values are in "
+                      "the range [0, %d]\n", val, LL_SA_RPC_MAX);
 
-        return count;
+       return count;
 }
 LPROC_SEQ_FOPS(ll_statahead_max);
 
@@ -695,18 +695,19 @@ static ssize_t ll_statahead_agl_seq_write(struct file *file,
 {
        struct seq_file *m = file->private_data;
        struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
-       int val, rc;
+       int rc;
+       __s64 val;
 
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
+       rc = lprocfs_str_to_s64(buffer, count, &val);
+       if (rc)
+               return rc;
 
-        if (val)
-                sbi->ll_flags |= LL_SBI_AGL_ENABLED;
-        else
-                sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
+       if (val)
+               sbi->ll_flags |= LL_SBI_AGL_ENABLED;
+       else
+               sbi->ll_flags &= ~LL_SBI_AGL_ENABLED;
 
-        return count;
+       return count;
 }
 LPROC_SEQ_FOPS(ll_statahead_agl);
 
@@ -741,18 +742,19 @@ static ssize_t ll_lazystatfs_seq_write(struct file *file,
 {
        struct seq_file *m = file->private_data;
        struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)m->private);
-       int val, rc;
+       int rc;
+       __s64 val;
 
-        rc = lprocfs_write_helper(buffer, count, &val);
-        if (rc)
-                return rc;
+       rc = lprocfs_str_to_s64(buffer, count, &val);
+       if (rc)
+               return rc;
 
-        if (val)
-                sbi->ll_flags |= LL_SBI_LAZYSTATFS;
-        else
-                sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
+       if (val)
+               sbi->ll_flags |= LL_SBI_LAZYSTATFS;
+       else
+               sbi->ll_flags &= ~LL_SBI_LAZYSTATFS;
 
-        return count;
+       return count;
 }
 LPROC_SEQ_FOPS(ll_lazystatfs);
 
@@ -818,18 +820,20 @@ static ssize_t ll_default_easize_seq_write(struct file *file,
                                           const char __user *buffer,
                                           size_t count, loff_t *unused)
 {
-       struct seq_file         *seq = file->private_data;
-       struct super_block      *sb = (struct super_block *)seq->private;
-       struct ll_sb_info       *sbi = ll_s2sbi(sb);
-       int                      val;
-       int                      rc;
+       struct seq_file *seq = file->private_data;
+       struct super_block *sb = (struct super_block *)seq->private;
+       struct ll_sb_info *sbi = ll_s2sbi(sb);
+       __s64 val;
+       int rc;
 
        if (count == 0)
                return 0;
 
-       rc = lprocfs_write_helper(buffer, count, &val);
-       if (rc < 0)
+       rc = lprocfs_str_to_s64(buffer, count, &val);
+       if (rc)
                return rc;
+       if (val < 0 || val > INT_MAX)
+               return -ERANGE;
 
        rc = ll_set_default_mdsize(sbi, val);
        if (rc)
@@ -888,7 +892,8 @@ static ssize_t ll_unstable_stats_seq_write(struct file *file,
        struct seq_file *seq = file->private_data;
        struct ll_sb_info *sbi = ll_s2sbi((struct super_block *)seq->private);
        char kernbuf[128];
-       int val, rc;
+       int rc;
+       __s64 val;
 
        if (count == 0)
                return 0;
@@ -901,7 +906,7 @@ static ssize_t ll_unstable_stats_seq_write(struct file *file,
 
        buffer += lprocfs_find_named_value(kernbuf, "unstable_check:", &count) -
                  kernbuf;
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
        if (rc < 0)
                return rc;
 
@@ -1374,12 +1379,13 @@ 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;
-       int value = 1, rc = 0;
+       __s64 value = 1;
+       int rc = 0;
 
        if (len == 0)
                return -EINVAL;
 
-       rc = lprocfs_write_helper(buf, len, &value);
+       rc = lprocfs_str_to_s64(buf, len, &value);
        if (rc < 0 && len < 16) {
                char kernbuf[16];
 
@@ -1446,12 +1452,13 @@ 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;
-       int value = 1, rc = 0;
+       __s64 value = 1;
+       int rc = 0;
 
        if (len == 0)
                return -EINVAL;
 
-       rc = lprocfs_write_helper(buf, len, &value);
+       rc = lprocfs_str_to_s64(buf, len, &value);
        if (rc < 0 && len < 16) {
                char kernbuf[16];
 
@@ -1649,12 +1656,13 @@ 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;
-       int value = 1, rc = 0;
+       __s64 value = 1;
+       int rc = 0;
 
        if (len == 0)
                return -EINVAL;
 
-       rc = lprocfs_write_helper(buf, len, &value);
+       rc = lprocfs_str_to_s64(buf, len, &value);
 
        if (rc < 0 && len < 16) {
                char kernbuf[16];