Whamcloud - gitweb
LU-6401 uapi: migrate remaining uapi headers to uapi directory
[fs/lustre-release.git] / lustre / lod / lproc_lod.c
index fe89355..8003fb6 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  2008 Sun Microsystems, Inc. All rights reserved
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2013, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -39,7 +35,7 @@
 #include <obd_class.h>
 #include <linux/seq_file.h>
 #include "lod_internal.h"
-#include <lustre_param.h>
+#include <uapi/linux/lustre/lustre_param.h>
 
 /*
  * Notice, all the functions below (except for lod_procfs_init() and
@@ -47,7 +43,7 @@
  * called by Linux kernel's procfs.
  */
 
-#ifdef LPROCFS
+#ifdef CONFIG_PROC_FS
 
 /**
  * Show default stripe size.
@@ -65,8 +61,9 @@ static int lod_stripesize_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, LPU64"\n",
-                       lod->lod_desc.ld_default_stripe_size);
+       seq_printf(m, "%llu\n",
+                  lod->lod_desc.ld_default_stripe_size);
+       return 0;
 }
 
 /**
@@ -83,23 +80,26 @@ static int lod_stripesize_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code if failed
  */
 static ssize_t
-lod_stripesize_seq_write(struct file *file, const char *buffer,
+lod_stripesize_seq_write(struct file *file, const char __user *buffer,
                         size_t count, loff_t *off)
 {
-       struct seq_file   *m = file->private_data;
+       struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct lod_device *lod;
-       __u64 val;
+       __s64 val;
        int rc;
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_u64_helper(buffer, count, &val);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
        if (rc)
                return rc;
+       if (val < 0)
+               return -ERANGE;
 
        lod_fix_desc_stripe_size(&val);
        lod->lod_desc.ld_default_stripe_size = val;
+
        return count;
 }
 LPROC_SEQ_FOPS(lod_stripesize);
@@ -120,8 +120,9 @@ static int lod_stripeoffset_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, LPU64"\n",
-                       lod->lod_desc.ld_default_stripe_offset);
+       seq_printf(m, "%llu\n",
+                  lod->lod_desc.ld_default_stripe_offset);
+       return 0;
 }
 
 /**
@@ -139,22 +140,25 @@ static int lod_stripeoffset_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code if failed
  */
 static ssize_t
-lod_stripeoffset_seq_write(struct file *file, const char *buffer,
+lod_stripeoffset_seq_write(struct file *file, const char __user *buffer,
                           size_t count, loff_t *off)
 {
-       struct seq_file   *m = file->private_data;
+       struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct lod_device *lod;
-       __u64 val;
+       __s64 val;
        int rc;
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_u64_helper(buffer, count, &val);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
        if (rc)
                return rc;
+       if (val < -1)
+               return -ERANGE;
 
        lod->lod_desc.ld_default_stripe_offset = val;
+
        return count;
 }
 LPROC_SEQ_FOPS(lod_stripeoffset);
@@ -175,7 +179,8 @@ static int lod_stripetype_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%u\n", lod->lod_desc.ld_pattern);
+       seq_printf(m, "%u\n", lod->lod_desc.ld_pattern);
+       return 0;
 }
 
 /**
@@ -191,22 +196,28 @@ static int lod_stripetype_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code if failed
  */
 static ssize_t
-lod_stripetype_seq_write(struct file *file, const char *buffer,
+lod_stripetype_seq_write(struct file *file, const char __user *buffer,
                         size_t count, loff_t *off)
 {
-       struct seq_file   *m = file->private_data;
+       struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct lod_device *lod;
-       int val, rc;
+       int rc;
+       __u32 pattern;
+       __s64 val;
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
        if (rc)
                return rc;
+       if (val < 0)
+               return -ERANGE;
+
+       pattern = val;
+       lod_fix_desc_pattern(&pattern);
+       lod->lod_desc.ld_pattern = pattern;
 
-       lod_fix_desc_pattern(&val);
-       lod->lod_desc.ld_pattern = val;
        return count;
 }
 LPROC_SEQ_FOPS(lod_stripetype);
@@ -227,8 +238,9 @@ static int lod_stripecount_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%d\n",
-                       (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
+       seq_printf(m, "%d\n",
+                  (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
+       return 0;
 }
 
 /**
@@ -244,22 +256,28 @@ static int lod_stripecount_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code otherwise
  */
 static ssize_t
-lod_stripecount_seq_write(struct file *file, const char *buffer,
+lod_stripecount_seq_write(struct file *file, const char __user *buffer,
                          size_t count, loff_t *off)
 {
-       struct seq_file   *m = file->private_data;
+       struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct lod_device *lod;
-       int val, rc;
+       int rc;
+       __s64 val;
+       __u32 stripe_count;
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
        if (rc)
                return rc;
+       if (val < -1)
+               return -ERANGE;
+
+       stripe_count = val;
+       lod_fix_desc_stripe_count(&stripe_count);
+       lod->lod_desc.ld_default_stripe_count = stripe_count;
 
-       lod_fix_desc_stripe_count(&val);
-       lod->lod_desc.ld_default_stripe_count = val;
        return count;
 }
 LPROC_SEQ_FOPS(lod_stripecount);
@@ -280,7 +298,8 @@ static int lod_numobd_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%u\n", lod->lod_desc.ld_tgt_count);
+       seq_printf(m, "%u\n", lod->lod_desc.ld_tgt_count);
+       return 0;
 }
 LPROC_SEQ_FOPS_RO(lod_numobd);
 
@@ -300,7 +319,8 @@ static int lod_activeobd_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%u\n", lod->lod_desc.ld_active_tgt_count);
+       seq_printf(m, "%u\n", lod->lod_desc.ld_active_tgt_count);
+       return 0;
 }
 LPROC_SEQ_FOPS_RO(lod_activeobd);
 
@@ -320,7 +340,8 @@ static int lod_desc_uuid_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod  = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%s\n", lod->lod_desc.ld_uuid.uuid);
+       seq_printf(m, "%s\n", lod->lod_desc.ld_uuid.uuid);
+       return 0;
 }
 LPROC_SEQ_FOPS_RO(lod_desc_uuid);
 
@@ -344,8 +365,9 @@ static int lod_qos_priofree_seq_show(struct seq_file *m, void *v)
        struct lod_device *lod = lu2lod_dev(dev->obd_lu_dev);
 
        LASSERT(lod != NULL);
-       return seq_printf(m, "%d%%\n",
-                       (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
+       seq_printf(m, "%d%%\n",
+                  (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
+       return 0;
 }
 
 /**
@@ -368,23 +390,25 @@ static ssize_t
 lod_qos_priofree_seq_write(struct file *file, const char __user *buffer,
                           size_t count, loff_t *off)
 {
-       struct seq_file   *m = file->private_data;
+       struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct lod_device *lod;
-       int val, rc;
+       int rc;
+       __s64 val;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
        if (rc)
                return rc;
 
-       if (val > 100)
+       if (val < 0 || val > 100)
                return -EINVAL;
        lod->lod_qos.lq_prio_free = (val << 8) / 100;
        lod->lod_qos.lq_dirty = 1;
        lod->lod_qos.lq_reset = 1;
+
        return count;
 }
 LPROC_SEQ_FOPS(lod_qos_priofree);
@@ -405,8 +429,9 @@ static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%d%%\n",
-                       (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
+       seq_printf(m, "%d%%\n",
+                  (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
+       return 0;
 }
 
 /**
@@ -427,18 +452,19 @@ static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code if failed
  */
 static ssize_t
-lod_qos_thresholdrr_seq_write(struct file *file, const char *buffer,
+lod_qos_thresholdrr_seq_write(struct file *file, const char __user *buffer,
                              size_t count, loff_t *off)
 {
-       struct seq_file   *m = file->private_data;
+       struct seq_file *m = file->private_data;
        struct obd_device *dev = m->private;
        struct lod_device *lod;
-       int val, rc;
+       int rc;
+       __s64 val;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '%');
        if (rc)
                return rc;
 
@@ -447,6 +473,7 @@ lod_qos_thresholdrr_seq_write(struct file *file, const char *buffer,
 
        lod->lod_qos.lq_threshold_rr = (val << 8) / 100;
        lod->lod_qos.lq_dirty = 1;
+
        return count;
 }
 LPROC_SEQ_FOPS(lod_qos_thresholdrr);
@@ -468,7 +495,8 @@ static int lod_qos_maxage_seq_show(struct seq_file *m, void *v)
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
-       return seq_printf(m, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
+       seq_printf(m, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
+       return 0;
 }
 
 /**
@@ -483,23 +511,24 @@ static int lod_qos_maxage_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code if failed
  */
 static ssize_t
-lod_qos_maxage_seq_write(struct file *file, const char *buffer,
+lod_qos_maxage_seq_write(struct file *file, const char __user *buffer,
                         size_t count, loff_t *off)
 {
-       struct seq_file         *m = file->private_data;
-       struct obd_device       *dev = m->private;
-       struct lustre_cfg_bufs   bufs;
-       struct lod_device       *lod;
-       struct lu_device        *next;
-       struct lustre_cfg       *lcfg;
-       char                     str[32];
-       unsigned int             i;
-       int                      val, rc;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
+       struct lustre_cfg_bufs bufs;
+       struct lod_device *lod;
+       struct lu_device *next;
+       struct lustre_cfg *lcfg;
+       char str[32];
+       unsigned int i;
+       int rc;
+       __s64 val;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
 
-       rc = lprocfs_write_helper(buffer, count, &val);
+       rc = lprocfs_str_to_s64(buffer, count, &val);
        if (rc)
                return rc;
 
@@ -511,9 +540,13 @@ lod_qos_maxage_seq_write(struct file *file, const char *buffer,
         * propogate the value down to OSPs
         */
        lustre_cfg_bufs_reset(&bufs, NULL);
-       sprintf(str, "%smaxage=%d", PARAM_OSP, val);
+       snprintf(str, 32, "%smaxage=%u", PARAM_OSP, (__u32)val);
        lustre_cfg_bufs_set_string(&bufs, 1, str);
-       lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
+       OBD_ALLOC(lcfg, lustre_cfg_len(bufs.lcfg_bufcount, bufs.lcfg_buflen));
+       if (lcfg == NULL)
+               return -ENOMEM;
+       lustre_cfg_init(lcfg, LCFG_PARAM, &bufs);
+
        lod_getref(&lod->lod_ost_descs);
        lod_foreach_ost(lod, i) {
                next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
@@ -522,7 +555,7 @@ lod_qos_maxage_seq_write(struct file *file, const char *buffer,
                        CERROR("can't set maxage on #%d: %d\n", i, rc);
        }
        lod_putref(lod, &lod->lod_ost_descs);
-       lustre_cfg_free(lcfg);
+       OBD_FREE(lcfg, lustre_cfg_len(lcfg->lcfg_bufcount, lcfg->lcfg_buflens));
 
        return count;
 }
@@ -609,9 +642,10 @@ static int lod_osts_seq_show(struct seq_file *p, void *v)
        } else if (rc)
                return rc;
 
-       return seq_printf(p, "%d: %s %sACTIVE\n", idx,
-                         obd_uuid2str(&ost_desc->ltd_uuid),
-                         active ? "" : "IN");
+       seq_printf(p, "%d: %s %sACTIVE\n", idx,
+                  obd_uuid2str(&ost_desc->ltd_uuid),
+                  active ? "" : "IN");
+       return 0;
 }
 
 static const struct seq_operations lod_osts_sops = {
@@ -635,8 +669,6 @@ static int lod_osts_seq_open(struct inode *inode, struct file *file)
        return 0;
 }
 
-LPROC_SEQ_FOPS_RO_TYPE(lod, uuid);
-
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_blksize);
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytestotal);
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesfree);
@@ -661,7 +693,8 @@ static int lod_lmv_failout_seq_show(struct seq_file *m, void *v)
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
 
-       return seq_printf(m, "%d\n", lod->lod_lmv_failout ? 1 : 0);
+       seq_printf(m, "%d\n", lod->lod_lmv_failout ? 1 : 0);
+       return 0;
 }
 
 /**
@@ -680,34 +713,29 @@ static int lod_lmv_failout_seq_show(struct seq_file *m, void *v)
  * \retval negative    error code if failed
  */
 static ssize_t
-lod_lmv_failout_seq_write(struct file *file, const char *buffer,
+lod_lmv_failout_seq_write(struct file *file, const char __user *buffer,
                          size_t count, loff_t *off)
 {
-       struct seq_file         *m      = file->private_data;
-       struct obd_device       *dev    = m->private;
-       struct lod_device       *lod;
-       int                      val    = 0;
-       int                      rc;
+       struct seq_file *m = file->private_data;
+       struct obd_device *dev = m->private;
+       struct lod_device *lod;
+       __s64 val = 0;
+       int rc;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
 
-       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)
-               lod->lod_lmv_failout = 1;
-       else
-               lod->lod_lmv_failout = 0;
+       lod->lod_lmv_failout = !!val;
 
        return count;
 }
 LPROC_SEQ_FOPS(lod_lmv_failout);
 
-static struct lprocfs_seq_vars lprocfs_lod_obd_vars[] = {
-       { .name =       "uuid",
-         .fops =       &lod_uuid_fops          },
+static struct lprocfs_vars lprocfs_lod_obd_vars[] = {
        { .name =       "stripesize",
          .fops =       &lod_stripesize_fops    },
        { .name =       "stripeoffset",
@@ -730,17 +758,17 @@ static struct lprocfs_seq_vars lprocfs_lod_obd_vars[] = {
          .fops =       &lod_qos_maxage_fops    },
        { .name =       "lmv_failout",
          .fops =       &lod_lmv_failout_fops   },
-       { 0 }
+       { NULL }
 };
 
-static struct lprocfs_seq_vars lprocfs_lod_osd_vars[] = {
-       { "blocksize",          &lod_dt_blksize_fops            },
-       { "kbytestotal",        &lod_dt_kbytestotal_fops        },
-       { "kbytesfree",         &lod_dt_kbytesfree_fops         },
-       { "kbytesavail",        &lod_dt_kbytesavail_fops        },
-       { "filestotal",         &lod_dt_filestotal_fops         },
-       { "filesfree",          &lod_dt_filesfree_fops          },
-       { 0 }
+static struct lprocfs_vars lprocfs_lod_osd_vars[] = {
+       { .name = "blocksize",   .fops = &lod_dt_blksize_fops },
+       { .name = "kbytestotal", .fops = &lod_dt_kbytestotal_fops },
+       { .name = "kbytesfree",  .fops = &lod_dt_kbytesfree_fops },
+       { .name = "kbytesavail", .fops = &lod_dt_kbytesavail_fops },
+       { .name = "filestotal",  .fops = &lod_dt_filestotal_fops },
+       { .name = "filesfree",   .fops = &lod_dt_filesfree_fops },
+       { .name = NULL }
 };
 
 static const struct file_operations lod_proc_target_fops = {
@@ -767,15 +795,15 @@ int lod_procfs_init(struct lod_device *lod)
        int                      rc;
 
        obd->obd_vars = lprocfs_lod_obd_vars;
-       rc = lprocfs_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd, true);
        if (rc) {
                CERROR("%s: cannot setup procfs entry: %d\n",
                       obd->obd_name, rc);
                RETURN(rc);
        }
 
-       rc = lprocfs_seq_add_vars(obd->obd_proc_entry, lprocfs_lod_osd_vars,
-                                 &lod->lod_dt_dev);
+       rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_lod_osd_vars,
+                             &lod->lod_dt_dev);
        if (rc) {
                CERROR("%s: cannot setup procfs entry: %d\n",
                       obd->obd_name, rc);
@@ -790,9 +818,9 @@ int lod_procfs_init(struct lod_device *lod)
                GOTO(out, rc);
        }
 
-       lod->lod_pool_proc_entry = lprocfs_seq_register("pools",
-                                                       obd->obd_proc_entry,
-                                                       NULL, NULL);
+       lod->lod_pool_proc_entry = lprocfs_register("pools",
+                                                   obd->obd_proc_entry,
+                                                   NULL, NULL);
        if (IS_ERR(lod->lod_pool_proc_entry)) {
                rc = PTR_ERR(lod->lod_pool_proc_entry);
                lod->lod_pool_proc_entry = NULL;
@@ -817,8 +845,8 @@ int lod_procfs_init(struct lod_device *lod)
        lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir,
                                               "../lod/%s", obd->obd_name);
        if (lod->lod_symlink == NULL)
-               CERROR("could not register LOV symlink for "
-                       "/proc/fs/lustre/lod/%s.", obd->obd_name);
+               CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
+                      obd->obd_name);
        RETURN(0);
 
 out:
@@ -836,8 +864,10 @@ void lod_procfs_fini(struct lod_device *lod)
 {
        struct obd_device *obd = lod2obd(lod);
 
-       if (lod->lod_symlink != NULL)
+       if (lod->lod_symlink != NULL) {
                lprocfs_remove(&lod->lod_symlink);
+               lod->lod_symlink = NULL;
+       }
 
        if (lod->lod_pool_proc_entry != NULL) {
                lprocfs_remove(&lod->lod_pool_proc_entry);
@@ -847,5 +877,5 @@ void lod_procfs_fini(struct lod_device *lod)
        lprocfs_obd_cleanup(obd);
 }
 
-#endif /* LPROCFS */
+#endif /* CONFIG_PROC_FS */