Whamcloud - gitweb
LU-14130 osc: skip 0 row for rpc_stats
[fs/lustre-release.git] / lustre / mdc / lproc_mdc.c
index 0c2e79a..b52f241 100644 (file)
 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
                           char *buf)
 {
-       struct obd_device *dev = container_of(kobj, struct obd_device,
+       struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
+       struct obd_import *imp;
        ssize_t len;
 
-       LPROCFS_CLIMP_CHECK(dev);
-       len = sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
-       LPROCFS_CLIMP_EXIT(dev);
+       with_imp_locked(obd, imp, len)
+               len = sprintf(buf, "%d\n", !imp->imp_deactive);
        return len;
 }
 
 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
                            const char *buffer, size_t count)
 {
-       struct obd_device *dev = container_of(kobj, struct obd_device,
+       struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        bool val;
        int rc;
@@ -64,8 +64,8 @@ static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
                return rc;
 
        /* opposite senses */
-       if (dev->u.cli.cl_import->imp_deactive == val)
-               rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
+       if (obd->u.cli.cl_import->imp_deactive == val)
+               rc = ptlrpc_set_import_active(obd->u.cli.cl_import, val);
        else
                CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
                       val);
@@ -78,12 +78,12 @@ static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
                                       struct attribute *attr,
                                       char *buf)
 {
-       struct obd_device *dev = container_of(kobj, struct obd_device,
+       struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        ssize_t len;
        u32 max;
 
-       max = obd_get_max_rpcs_in_flight(&dev->u.cli);
+       max = obd_get_max_rpcs_in_flight(&obd->u.cli);
        len = sprintf(buf, "%u\n", max);
 
        return len;
@@ -94,7 +94,7 @@ static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
                                        const char *buffer,
                                        size_t count)
 {
-       struct obd_device *dev = container_of(kobj, struct obd_device,
+       struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        unsigned int val;
        int rc;
@@ -103,7 +103,7 @@ static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
        if (rc)
                return rc;
 
-       rc = obd_set_max_rpcs_in_flight(&dev->u.cli, val);
+       rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
        if (rc)
                count = rc;
 
@@ -115,11 +115,11 @@ static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
                                           struct attribute *attr,
                                           char *buf)
 {
-       struct obd_device *dev = container_of(kobj, struct obd_device,
+       struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        u16 max;
 
-       max = obd_get_max_mod_rpcs_in_flight(&dev->u.cli);
+       max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
        return sprintf(buf, "%hu\n", max);
 }
 
@@ -128,7 +128,7 @@ static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
                                            const char *buffer,
                                            size_t count)
 {
-       struct obd_device *dev = container_of(kobj, struct obd_device,
+       struct obd_device *obd = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        u16 val;
        int rc;
@@ -137,7 +137,7 @@ static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
        if (rc)
                return rc;
 
-       rc = obd_set_max_mod_rpcs_in_flight(&dev->u.cli, val);
+       rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
        if (rc)
                count = rc;
 
@@ -147,15 +147,10 @@ LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
 
 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev = m->private;
-       struct client_obd *cli = &dev->u.cli;
-       unsigned long val;
+       struct obd_device *obd = m->private;
+       struct client_obd *cli = &obd->u.cli;
 
-       spin_lock(&cli->cl_loi_list_lock);
-       val = PAGES_TO_MiB(cli->cl_dirty_max_pages);
-       spin_unlock(&cli->cl_loi_list_lock);
-
-       seq_printf(m, "%lu\n", val);
+       seq_printf(m, "%lu\n", PAGES_TO_MiB(cli->cl_dirty_max_pages));
        return 0;
 }
 
@@ -164,13 +159,21 @@ static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
                                          size_t count, loff_t *off)
 {
        struct seq_file *sfl = file->private_data;
-       struct obd_device *dev = sfl->private;
-       struct client_obd *cli = &dev->u.cli;
-       s64 pages_number;
+       struct obd_device *obd = sfl->private;
+       struct client_obd *cli = &obd->u.cli;
+       char kernbuf[22] = "";
+       u64 pages_number;
        int rc;
 
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
-       if (rc)
+       if (count >= sizeof(kernbuf))
+               return -EINVAL;
+
+       if (copy_from_user(kernbuf, buffer, count))
+               return -EFAULT;
+       kernbuf[count] = 0;
+
+       rc = sysfs_memparse(kernbuf, count, &pages_number, "MiB");
+       if (rc < 0)
                return rc;
 
        /* MB -> pages */
@@ -228,8 +231,8 @@ LUSTRE_RW_ATTR(ping);
 
 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev = m->private;
-       struct client_obd *cli = &dev->u.cli;
+       struct obd_device *obd = m->private;
+       struct client_obd *cli = &obd->u.cli;
        int shift = 20 - PAGE_SHIFT;
 
        seq_printf(m, "used_mb: %ld\n"
@@ -249,9 +252,10 @@ mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
                        size_t count, loff_t *off)
 {
        struct seq_file *sfl = file->private_data;
-       struct obd_device *dev = sfl->private;
-       struct client_obd *cli = &dev->u.cli;
-       __s64 pages_number;
+       struct obd_device *obd = sfl->private;
+       struct client_obd *cli = &obd->u.cli;
+       u64 pages_number;
+       const char *tmp;
        long rc;
        char kernbuf[128];
 
@@ -262,17 +266,13 @@ mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
                return -EFAULT;
        kernbuf[count] = 0;
 
-       buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
-                 kernbuf;
-       rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
-       if (rc)
+       tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
+       rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
+       if (rc < 0)
                return rc;
 
        pages_number >>= PAGE_SHIFT;
 
-       if (pages_number < 0)
-               return -ERANGE;
-
        rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
        if (rc > 0) {
                struct lu_env *env;
@@ -291,8 +291,8 @@ LPROC_SEQ_FOPS(mdc_cached_mb);
 
 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev = m->private;
-       struct client_obd *cli = &dev->u.cli;
+       struct obd_device *obd = m->private;
+       struct client_obd *cli = &obd->u.cli;
        long pages;
        int mb;
 
@@ -310,8 +310,8 @@ static ssize_t mdc_rpc_stats_seq_write(struct file *file,
                                       size_t len, loff_t *off)
 {
        struct seq_file *seq = file->private_data;
-       struct obd_device *dev = seq->private;
-       struct client_obd *cli = &dev->u.cli;
+       struct obd_device *obd = seq->private;
+       struct client_obd *cli = &obd->u.cli;
 
        lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
 
@@ -327,12 +327,12 @@ static ssize_t mdc_rpc_stats_seq_write(struct file *file,
 
 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 {
-       struct obd_device *dev = seq->private;
-       struct client_obd *cli = &dev->u.cli;
+       struct obd_device *obd = seq->private;
+       struct client_obd *cli = &obd->u.cli;
        unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
        int i;
 
-       obd_mod_rpc_stats_seq_show(&dev->u.cli, seq);
+       obd_mod_rpc_stats_seq_show(cli, seq);
 
        spin_lock(&cli->cl_loi_list_lock);
 
@@ -378,7 +378,7 @@ static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 
        read_cum = 0;
        write_cum = 0;
-       for (i = 0; i < OBD_HIST_MAX; i++) {
+       for (i = 1; i < OBD_HIST_MAX; i++) {
                unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
                unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
 
@@ -422,8 +422,8 @@ LPROC_SEQ_FOPS(mdc_rpc_stats);
 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
 {
        struct timespec64 now;
-       struct obd_device *dev = seq->private;
-       struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
+       struct obd_device *obd = seq->private;
+       struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
 
        ktime_get_real_ts64(&now);
 
@@ -443,8 +443,8 @@ static ssize_t mdc_stats_seq_write(struct file *file,
                                   size_t len, loff_t *off)
 {
        struct seq_file *seq = file->private_data;
-       struct obd_device *dev = seq->private;
-       struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
+       struct obd_device *obd = seq->private;
+       struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
 
        memset(stats, 0, sizeof(*stats));
        return len;
@@ -453,9 +453,9 @@ LPROC_SEQ_FOPS(mdc_stats);
 
 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
 {
-       struct obd_device *dev = m->private;
+       struct obd_device *obd = m->private;
 
-       seq_printf(m, "%u\n", dev->u.cli.cl_dom_min_inline_repsize);
+       seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
 
        return 0;
 }
@@ -464,11 +464,11 @@ static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
                                             const char __user *buffer,
                                             size_t count, loff_t *off)
 {
-       struct obd_device *dev;
+       struct seq_file *m = file->private_data;
+       struct obd_device *obd = m->private;
        unsigned int val;
        int rc;
 
-       dev =  ((struct seq_file *)file->private_data)->private;
        rc = kstrtouint_from_user(buffer, count, 0, &val);
        if (rc)
                return rc;
@@ -476,7 +476,7 @@ static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
        if (val > MDC_DOM_MAX_INLINE_REPSIZE)
                return -ERANGE;
 
-       dev->u.cli.cl_dom_min_inline_repsize = val;
+       obd->u.cli.cl_dom_min_inline_repsize = val;
        return count;
 }
 LPROC_SEQ_FOPS(mdc_dom_min_repsize);