Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / osc / lproc_osc.c
index 9337450..414d918 100644 (file)
@@ -143,16 +143,14 @@ static ssize_t max_dirty_mb_show(struct kobject *kobj,
 {
        struct obd_device *dev = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
-        struct client_obd *cli = &dev->u.cli;
-        long val;
-        int mult;
+       struct client_obd *cli = &dev->u.cli;
+       unsigned long val;
 
        spin_lock(&cli->cl_loi_list_lock);
-       val = cli->cl_dirty_max_pages;
+       val = PAGES_TO_MiB(cli->cl_dirty_max_pages);
        spin_unlock(&cli->cl_loi_list_lock);
 
-       mult = 1 << (20 - PAGE_SHIFT);
-       return lprocfs_read_frac_helper(buf, PAGE_SIZE, val, mult);
+       return sprintf(buf, "%lu\n", val);
 }
 
 static ssize_t max_dirty_mb_store(struct kobject *kobj,
@@ -163,18 +161,17 @@ static ssize_t max_dirty_mb_store(struct kobject *kobj,
        struct obd_device *dev = container_of(kobj, struct obd_device,
                                              obd_kset.kobj);
        struct client_obd *cli = &dev->u.cli;
-       unsigned long pages_number;
+       unsigned long pages_number, max_dirty_mb;
        int rc;
 
-       rc = kstrtoul(buffer, 10, &pages_number);
+       rc = kstrtoul(buffer, 10, &max_dirty_mb);
        if (rc)
                return rc;
 
-       pages_number *= 1 << (20 - PAGE_SHIFT); /* MB -> pages */
+       pages_number = MiB_TO_PAGES(max_dirty_mb);
 
-       if (pages_number <= 0 ||
-           pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
-           pages_number > totalram_pages / 4) /* 1/4 of RAM */
+       if (pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
+           pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
                return -ERANGE;
 
        spin_lock(&cli->cl_loi_list_lock);
@@ -186,9 +183,10 @@ static ssize_t max_dirty_mb_store(struct kobject *kobj,
 }
 LUSTRE_RW_ATTR(max_dirty_mb);
 
+LUSTRE_ATTR(ost_conn_uuid, 0444, conn_uuid_show, NULL);
 LUSTRE_RO_ATTR(conn_uuid);
 
-LUSTRE_WO_ATTR(ping);
+LUSTRE_RW_ATTR(ping);
 
 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
 {
@@ -361,6 +359,8 @@ static ssize_t grant_shrink_interval_store(struct kobject *kobj,
                return -ERANGE;
 
        obd->u.cli.cl_grant_shrink_interval = val;
+       osc_update_next_shrink(&obd->u.cli);
+       osc_schedule_grant_work();
 
        return count;
 }
@@ -425,28 +425,34 @@ static ssize_t osc_checksum_type_seq_write(struct file *file,
        int i;
        DECLARE_CKSUM_NAME;
        char kernbuf[10];
+       int rc = -EINVAL;
 
-        if (obd == NULL)
-                return 0;
+       if (obd == NULL)
+               return 0;
 
-        if (count > sizeof(kernbuf) - 1)
-                return -EINVAL;
+       if (count > sizeof(kernbuf) - 1)
+               return -EINVAL;
        if (copy_from_user(kernbuf, buffer, count))
-                return -EFAULT;
-        if (count > 0 && kernbuf[count - 1] == '\n')
-                kernbuf[count - 1] = '\0';
-        else
-                kernbuf[count] = '\0';
-
-        for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
-                if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
-                        continue;
-                if (!strcmp(kernbuf, cksum_name[i])) {
-                       obd->u.cli.cl_cksum_type = 1 << i;
-                       return count;
-                }
-        }
-        return -EINVAL;
+               return -EFAULT;
+
+       if (count > 0 && kernbuf[count - 1] == '\n')
+               kernbuf[count - 1] = '\0';
+       else
+               kernbuf[count] = '\0';
+
+       for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
+               if (strcmp(kernbuf, cksum_name[i]) == 0) {
+                       obd->u.cli.cl_preferred_cksum_type = BIT(i);
+                       if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
+                               obd->u.cli.cl_cksum_type = BIT(i);
+                               rc = count;
+                       } else {
+                               rc = -ENOTSUPP;
+                       }
+                       break;
+               }
+       }
+       return rc;
 }
 LPROC_SEQ_FOPS(osc_checksum_type);
 
@@ -608,6 +614,144 @@ static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
 }
 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
 
+static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr,
+                                char *buf)
+{
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct client_obd *cli = &obd->u.cli;
+       int ret;
+
+       LPROCFS_CLIMP_CHECK(obd);
+       ret = sprintf(buf, "%u\n", cli->cl_import->imp_idle_timeout);
+       LPROCFS_CLIMP_EXIT(obd);
+
+       return ret;
+}
+
+static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
+{
+       struct obd_device *dev = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct client_obd *cli = &dev->u.cli;
+       struct ptlrpc_request *req;
+       unsigned int idle_debug = 0;
+       unsigned int val;
+       int rc;
+
+       if (strncmp(buffer, "debug", 5) == 0) {
+               idle_debug = D_CONSOLE;
+       } else if (strncmp(buffer, "nodebug", 6) == 0) {
+               idle_debug = D_HA;
+       } else {
+               rc = kstrtouint(buffer, 10, &val);
+               if (rc)
+                       return rc;
+
+               if (val > CONNECTION_SWITCH_MAX)
+                       return -ERANGE;
+       }
+
+       LPROCFS_CLIMP_CHECK(dev);
+       if (idle_debug) {
+               cli->cl_import->imp_idle_debug = idle_debug;
+       } else {
+               if (!val) {
+                       /* initiate the connection if it's in IDLE state */
+                       req = ptlrpc_request_alloc(cli->cl_import,
+                                                  &RQF_OST_STATFS);
+                       if (req != NULL)
+                               ptlrpc_req_finished(req);
+               }
+               cli->cl_import->imp_idle_timeout = val;
+       }
+       LPROCFS_CLIMP_EXIT(dev);
+
+       return count;
+}
+LUSTRE_RW_ATTR(idle_timeout);
+
+static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
+{
+       struct obd_device *dev = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct client_obd *cli = &dev->u.cli;
+       struct ptlrpc_request *req;
+
+       LPROCFS_CLIMP_CHECK(dev);
+       /* to initiate the connection if it's in IDLE state */
+       req = ptlrpc_request_alloc(cli->cl_import, &RQF_OST_STATFS);
+       if (req)
+               ptlrpc_req_finished(req);
+       ptlrpc_pinger_force(cli->cl_import);
+       LPROCFS_CLIMP_EXIT(dev);
+
+       return count;
+}
+LUSTRE_WO_ATTR(idle_connect);
+
+static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
+                                char *buf)
+{
+       struct obd_device *obd = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct client_obd *cli = &obd->u.cli;
+       struct obd_connect_data *ocd;
+       ssize_t len;
+
+       LPROCFS_CLIMP_CHECK(obd);
+       ocd = &cli->cl_import->imp_connect_data;
+
+       len = snprintf(buf, PAGE_SIZE, "%d\n",
+                      !!OCD_HAS_FLAG(ocd, GRANT_SHRINK));
+       LPROCFS_CLIMP_EXIT(obd);
+
+       return len;
+}
+
+static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
+                                 const char *buffer, size_t count)
+{
+       struct obd_device *dev = container_of(kobj, struct obd_device,
+                                             obd_kset.kobj);
+       struct client_obd *cli = &dev->u.cli;
+       struct obd_connect_data *ocd;
+       bool val;
+       int rc;
+
+       if (dev == NULL)
+               return 0;
+
+       rc = kstrtobool(buffer, &val);
+       if (rc)
+               return rc;
+
+       LPROCFS_CLIMP_CHECK(dev);
+       ocd = &cli->cl_import->imp_connect_data;
+
+       if (!val) {
+               if (OCD_HAS_FLAG(ocd, GRANT_SHRINK))
+                       ocd->ocd_connect_flags &= ~OBD_CONNECT_GRANT_SHRINK;
+       } else {
+               /**
+                * server replied obd_connect_data is always bigger, so
+                * client's imp_connect_flags_orig are always supported
+                * by the server
+                */
+               if (!OCD_HAS_FLAG(ocd, GRANT_SHRINK) &&
+                   cli->cl_import->imp_connect_flags_orig &
+                   OBD_CONNECT_GRANT_SHRINK)
+                       ocd->ocd_connect_flags |= OBD_CONNECT_GRANT_SHRINK;
+       }
+
+       LPROCFS_CLIMP_EXIT(dev);
+
+       return count;
+}
+LUSTRE_RW_ATTR(grant_shrink);
+
 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
@@ -642,8 +786,6 @@ struct lprocfs_vars lprocfs_osc_obd_vars[] = {
        { NULL }
 };
 
-#define pct(a,b) (b ? a * 100 / b : 0)
-
 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 {
        struct timespec64 now;
@@ -682,7 +824,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 
                read_cum += r;
                write_cum += w;
-               seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
+               seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
                           1 << i, r, pct(r, read_tot),
                           pct(read_cum, read_tot), w,
                           pct(w, write_tot),
@@ -705,7 +847,7 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
                 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
                 read_cum += r;
                 write_cum += w;
-               seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
+               seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
                           i, r, pct(r, read_tot),
                           pct(read_cum, read_tot), w,
                           pct(w, write_tot),
@@ -728,10 +870,10 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
                 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
                 read_cum += r;
                 write_cum += w;
-                seq_printf(seq, "%d:\t\t%10lu %3lu %3lu   | %10lu %3lu %3lu\n",
-                           (i == 0) ? 0 : 1 << (i - 1),
-                           r, pct(r, read_tot), pct(read_cum, read_tot),
-                           w, pct(w, write_tot), pct(write_cum, write_tot));
+               seq_printf(seq, "%d:\t\t%10lu %3u %3u   | %10lu %3u %3u\n",
+                          (i == 0) ? 0 : 1 << (i - 1),
+                          r, pct(r, read_tot), pct(read_cum, read_tot),
+                          w, pct(w, write_tot), pct(write_cum, write_tot));
                 if (read_cum == read_tot && write_cum == write_tot)
                         break;
         }
@@ -740,7 +882,6 @@ static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
 
         return 0;
 }
-#undef pct
 
 static ssize_t osc_rpc_stats_seq_write(struct file *file,
                                       const char __user *buf,
@@ -822,38 +963,20 @@ static struct attribute *osc_attrs[] = {
        &lustre_attr_max_rpcs_in_flight.attr,
        &lustre_attr_short_io_bytes.attr,
        &lustre_attr_resend_count.attr,
+       &lustre_attr_ost_conn_uuid.attr,
        &lustre_attr_conn_uuid.attr,
        &lustre_attr_ping.attr,
+       &lustre_attr_idle_timeout.attr,
+       &lustre_attr_idle_connect.attr,
+       &lustre_attr_grant_shrink.attr,
        NULL,
 };
 
 int osc_tunables_init(struct obd_device *obd)
 {
-#if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
-       struct obd_type *type;
-#endif
        int rc;
 
        obd->obd_vars = lprocfs_osc_obd_vars;
-#if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
-       /* If this is true then both client (osc) and server (osp) are on the
-        * same node. The osp layer if loaded first will register the osc proc
-        * directory. In that case this obd_device will be attached its proc
-        * tree to type->typ_procsym instead of obd->obd_type->typ_procroot.
-        */
-       type = class_search_type(LUSTRE_OSP_NAME);
-       if (type && type->typ_procsym) {
-               obd->obd_proc_entry = lprocfs_register(obd->obd_name,
-                                                      type->typ_procsym,
-                                                      obd->obd_vars, obd);
-               if (IS_ERR(obd->obd_proc_entry)) {
-                       rc = PTR_ERR(obd->obd_proc_entry);
-                       CERROR("error %d setting up lprocfs for %s\n", rc,
-                              obd->obd_name);
-                       obd->obd_proc_entry = NULL;
-               }
-       }
-#endif
        obd->obd_ktype.default_attrs = osc_attrs;
        rc = lprocfs_obd_setup(obd, false);
        if (rc)