4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 #define DEBUG_SUBSYSTEM S_CLASS
33 #include <linux/vfs.h>
34 #include <obd_class.h>
35 #include <obd_cksum.h>
36 #include <lprocfs_status.h>
37 #include <lustre_osc.h>
38 #include <cl_object.h>
39 #include "mdc_internal.h"
41 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
44 struct obd_device *obd = container_of(kobj, struct obd_device,
46 struct obd_import *imp;
49 with_imp_locked(obd, imp, len)
50 len = sprintf(buf, "%d\n", !imp->imp_deactive);
54 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
55 const char *buffer, size_t count)
57 struct obd_device *obd = container_of(kobj, struct obd_device,
59 struct obd_import *imp, *imp0;
63 rc = kstrtobool(buffer, &val);
67 with_imp_locked(obd, imp0, rc)
68 imp = class_import_get(imp0);
72 if (imp->imp_deactive == val)
73 rc = ptlrpc_set_import_active(imp, val);
75 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
77 class_import_put(imp);
80 LUSTRE_RW_ATTR(active);
82 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
83 struct attribute *attr,
86 struct obd_device *obd = container_of(kobj, struct obd_device,
91 max = obd_get_max_rpcs_in_flight(&obd->u.cli);
92 len = sprintf(buf, "%u\n", max);
97 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
98 struct attribute *attr,
102 struct obd_device *obd = container_of(kobj, struct obd_device,
104 struct obd_import *imp;
108 rc = kstrtouint(buffer, 10, &val);
112 with_imp_locked(obd, imp, rc)
113 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
115 return rc ? rc : count;
117 LUSTRE_RW_ATTR(max_rpcs_in_flight);
119 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
120 struct attribute *attr,
123 struct obd_device *obd = container_of(kobj, struct obd_device,
127 max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
128 return sprintf(buf, "%hu\n", max);
131 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
132 struct attribute *attr,
136 struct obd_device *obd = container_of(kobj, struct obd_device,
138 struct obd_import *imp;
142 rc = kstrtou16(buffer, 10, &val);
146 with_imp_locked(obd, imp, rc)
147 rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
149 return rc ? rc : count;
151 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
153 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
155 struct obd_device *obd = m->private;
156 struct client_obd *cli = &obd->u.cli;
158 seq_printf(m, "%lu\n", PAGES_TO_MiB(cli->cl_dirty_max_pages));
162 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
163 const char __user *buffer,
164 size_t count, loff_t *off)
166 struct seq_file *sfl = file->private_data;
167 struct obd_device *obd = sfl->private;
168 struct client_obd *cli = &obd->u.cli;
169 char kernbuf[22] = "";
173 if (count >= sizeof(kernbuf))
176 if (copy_from_user(kernbuf, buffer, count))
180 rc = sysfs_memparse(kernbuf, count, &pages_number, "MiB");
185 pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT;
186 if (pages_number <= 0 ||
187 pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
188 pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
191 spin_lock(&cli->cl_loi_list_lock);
192 cli->cl_dirty_max_pages = pages_number;
193 osc_wake_cache_waiters(cli);
194 spin_unlock(&cli->cl_loi_list_lock);
198 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
202 static int mdc_checksum_type_seq_show(struct seq_file *m, void *v)
204 struct obd_device *obd = m->private;
210 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
211 if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0)
213 if (obd->u.cli.cl_cksum_type == BIT(i))
214 seq_printf(m, "[%s] ", cksum_name[i]);
216 seq_printf(m, "%s ", cksum_name[i]);
223 static ssize_t mdc_checksum_type_seq_write(struct file *file,
224 const char __user *buffer,
225 size_t count, loff_t *off)
227 struct seq_file *m = file->private_data;
228 struct obd_device *obd = m->private;
236 if (count > sizeof(kernbuf) - 1)
238 if (copy_from_user(kernbuf, buffer, count))
241 if (count > 0 && kernbuf[count - 1] == '\n')
242 kernbuf[count - 1] = '\0';
244 kernbuf[count] = '\0';
246 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
247 if (strcasecmp(kernbuf, cksum_name[i]) == 0) {
248 obd->u.cli.cl_preferred_cksum_type = BIT(i);
249 if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
250 obd->u.cli.cl_cksum_type = BIT(i);
261 LPROC_SEQ_FOPS(mdc_checksum_type);
263 static ssize_t checksums_show(struct kobject *kobj,
264 struct attribute *attr, char *buf)
266 struct obd_device *obd = container_of(kobj, struct obd_device,
269 return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum);
272 static ssize_t checksums_store(struct kobject *kobj,
273 struct attribute *attr,
277 struct obd_device *obd = container_of(kobj, struct obd_device,
282 rc = kstrtobool(buffer, &val);
286 obd->u.cli.cl_checksum = val;
290 LUSTRE_RW_ATTR(checksums);
292 static ssize_t checksum_dump_show(struct kobject *kobj,
293 struct attribute *attr, char *buf)
295 struct obd_device *obd = container_of(kobj, struct obd_device,
298 return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum_dump);
301 static ssize_t checksum_dump_store(struct kobject *kobj,
302 struct attribute *attr,
306 struct obd_device *obd = container_of(kobj, struct obd_device,
311 rc = kstrtobool(buffer, &val);
315 obd->u.cli.cl_checksum_dump = val;
319 LUSTRE_RW_ATTR(checksum_dump);
321 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
322 LUSTRE_RO_ATTR(conn_uuid);
324 LUSTRE_RW_ATTR(ping);
326 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
328 struct obd_device *obd = m->private;
329 struct client_obd *cli = &obd->u.cli;
330 int shift = 20 - PAGE_SHIFT;
332 seq_printf(m, "used_mb: %ld\n"
335 (atomic_long_read(&cli->cl_lru_in_list) +
336 atomic_long_read(&cli->cl_lru_busy)) >> shift,
337 atomic_long_read(&cli->cl_lru_busy),
338 cli->cl_lru_reclaim);
343 /* shrink the number of caching pages to a specific number */
345 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
346 size_t count, loff_t *off)
348 struct seq_file *sfl = file->private_data;
349 struct obd_device *obd = sfl->private;
350 struct client_obd *cli = &obd->u.cli;
356 if (count >= sizeof(kernbuf))
359 if (copy_from_user(kernbuf, buffer, count))
363 tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
364 rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
368 pages_number >>= PAGE_SHIFT;
370 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
375 env = cl_env_get(&refcheck);
377 (void)osc_lru_shrink(env, cli, rc, true);
378 cl_env_put(env, &refcheck);
384 LPROC_SEQ_FOPS(mdc_cached_mb);
386 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
388 struct obd_device *obd = m->private;
389 struct client_obd *cli = &obd->u.cli;
393 pages = atomic_long_read(&cli->cl_unstable_count);
394 mb = (pages * PAGE_SIZE) >> 20;
396 seq_printf(m, "unstable_pages: %20ld\n"
397 "unstable_mb: %10d\n", pages, mb);
400 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
402 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
403 const char __user *buf,
404 size_t len, loff_t *off)
406 struct seq_file *seq = file->private_data;
407 struct obd_device *obd = seq->private;
408 struct client_obd *cli = &obd->u.cli;
410 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
412 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
413 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
414 lprocfs_oh_clear(&cli->cl_read_page_hist);
415 lprocfs_oh_clear(&cli->cl_write_page_hist);
416 lprocfs_oh_clear(&cli->cl_read_offset_hist);
417 lprocfs_oh_clear(&cli->cl_write_offset_hist);
418 cli->cl_mod_rpcs_init = ktime_get_real();
423 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
425 struct obd_device *obd = seq->private;
426 struct client_obd *cli = &obd->u.cli;
427 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
430 obd_mod_rpc_stats_seq_show(cli, seq);
432 spin_lock(&cli->cl_loi_list_lock);
434 seq_printf(seq, "\nread RPCs in flight: %d\n",
435 cli->cl_r_in_flight);
436 seq_printf(seq, "write RPCs in flight: %d\n",
437 cli->cl_w_in_flight);
438 seq_printf(seq, "pending write pages: %d\n",
439 atomic_read(&cli->cl_pending_w_pages));
440 seq_printf(seq, "pending read pages: %d\n",
441 atomic_read(&cli->cl_pending_r_pages));
443 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
444 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
445 seq_printf(seq, " rpcs %% cum %%\n");
447 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
448 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
452 for (i = 0; i < OBD_HIST_MAX; i++) {
453 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
454 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
458 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
459 1 << i, r, pct(r, read_tot),
460 pct(read_cum, read_tot), w,
462 pct(write_cum, write_tot));
463 if (read_cum == read_tot && write_cum == write_tot)
467 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
468 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
469 seq_printf(seq, " rpcs %% cum %%\n");
471 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
472 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
476 for (i = 1; i < OBD_HIST_MAX; i++) {
477 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
478 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
482 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
483 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
484 pct(w, write_tot), pct(write_cum, write_tot));
485 if (read_cum == read_tot && write_cum == write_tot)
489 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
490 seq_printf(seq, "offset rpcs %% cum %% |");
491 seq_printf(seq, " rpcs %% cum %%\n");
493 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
494 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
498 for (i = 0; i < OBD_HIST_MAX; i++) {
499 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
500 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
504 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
505 (i == 0) ? 0 : 1 << (i - 1),
506 r, pct(r, read_tot), pct(read_cum, read_tot),
507 w, pct(w, write_tot), pct(write_cum, write_tot));
508 if (read_cum == read_tot && write_cum == write_tot)
511 spin_unlock(&cli->cl_loi_list_lock);
515 LPROC_SEQ_FOPS(mdc_rpc_stats);
517 static ssize_t mdc_batch_stats_seq_write(struct file *file,
518 const char __user *buf,
519 size_t len, loff_t *off)
521 struct seq_file *seq = file->private_data;
522 struct obd_device *obd = seq->private;
523 struct client_obd *cli = &obd->u.cli;
525 lprocfs_oh_clear(&cli->cl_batch_rpc_hist);
526 cli->cl_batch_stats_init = ktime_get_real();
531 static int mdc_batch_stats_seq_show(struct seq_file *seq, void *v)
533 struct obd_device *obd = seq->private;
534 struct client_obd *cli = &obd->u.cli;
539 lprocfs_stats_header(seq, ktime_get_real(), cli->cl_batch_stats_init,
541 seq_printf(seq, "subreqs per batch batches %% cum %%\n");
542 tot = lprocfs_oh_sum(&cli->cl_batch_rpc_hist);
545 for (i = 0; i < OBD_HIST_MAX; i++) {
546 unsigned long cnt = cli->cl_batch_rpc_hist.oh_buckets[i];
549 seq_printf(seq, "%d:\t\t%10lu %3u %3u\n",
550 1 << i, cnt, pct(cnt, tot), pct(cum, tot));
557 LPROC_SEQ_FOPS(mdc_batch_stats);
559 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
561 struct obd_device *obd = seq->private;
562 struct osc_stats *stats = &obd2osc_dev(obd)->osc_stats;
564 lprocfs_stats_header(seq, ktime_get_real(), stats->os_init, 25, ":",
566 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
567 stats->os_lockless_writes);
568 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
569 stats->os_lockless_reads);
573 static ssize_t mdc_stats_seq_write(struct file *file,
574 const char __user *buf,
575 size_t len, loff_t *off)
577 struct seq_file *seq = file->private_data;
578 struct obd_device *obd = seq->private;
579 struct osc_stats *stats = &obd2osc_dev(obd)->osc_stats;
581 memset(stats, 0, sizeof(*stats));
582 stats->os_init = ktime_get_real();
586 LPROC_SEQ_FOPS(mdc_stats);
588 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
590 struct obd_device *obd = m->private;
592 seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
597 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
598 const char __user *buffer,
599 size_t count, loff_t *off)
601 struct seq_file *m = file->private_data;
602 struct obd_device *obd = m->private;
606 rc = kstrtouint_from_user(buffer, count, 0, &val);
610 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
613 obd->u.cli.cl_dom_min_inline_repsize = val;
616 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
618 static int mdc_lsom_seq_show(struct seq_file *m, void *v)
620 struct obd_device *dev = m->private;
622 seq_printf(m, "%s\n", dev->u.cli.cl_lsom_update ? "On" : "Off");
627 static ssize_t mdc_lsom_seq_write(struct file *file,
628 const char __user *buffer,
629 size_t count, loff_t *off)
631 struct obd_device *dev;
635 dev = ((struct seq_file *)file->private_data)->private;
636 rc = kstrtobool_from_user(buffer, count, &val);
640 dev->u.cli.cl_lsom_update = val;
643 LPROC_SEQ_FOPS(mdc_lsom);
646 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
647 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
648 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
649 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
650 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
651 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
652 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
654 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
655 { .name = "connect_flags",
656 .fops = &mdc_connect_flags_fops },
657 { .name = "mds_server_uuid",
658 .fops = &mdc_server_uuid_fops },
659 { .name = "max_pages_per_rpc",
660 .fops = &mdc_obd_max_pages_per_rpc_fops },
661 { .name = "max_dirty_mb",
662 .fops = &mdc_max_dirty_mb_fops },
663 { .name = "mdc_cached_mb",
664 .fops = &mdc_cached_mb_fops },
665 { .name = "checksum_type",
666 .fops = &mdc_checksum_type_fops },
667 { .name = "timeouts",
668 .fops = &mdc_timeouts_fops },
670 .fops = &mdc_import_fops },
672 .fops = &mdc_state_fops },
673 { .name = "pinger_recov",
674 .fops = &mdc_pinger_recov_fops },
675 { .name = "rpc_stats",
676 .fops = &mdc_rpc_stats_fops },
677 { .name = "batch_stats",
678 .fops = &mdc_batch_stats_fops },
679 { .name = "unstable_stats",
680 .fops = &mdc_unstable_stats_fops },
681 { .name = "mdc_stats",
682 .fops = &mdc_stats_fops },
683 { .name = "mdc_dom_min_repsize",
684 .fops = &mdc_dom_min_repsize_fops },
685 { .name = "mdc_lsom",
686 .fops = &mdc_lsom_fops },
690 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
691 struct attribute *attr,
694 struct obd_device *obd = container_of(kobj, struct obd_device,
696 struct client_obd *cli = &obd->u.cli;
698 return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_lost_grant);
700 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
702 static ssize_t cur_dirty_grant_bytes_show(struct kobject *kobj,
703 struct attribute *attr,
706 struct obd_device *obd = container_of(kobj, struct obd_device,
708 struct client_obd *cli = &obd->u.cli;
710 return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_dirty_grant);
712 LUSTRE_RO_ATTR(cur_dirty_grant_bytes);
714 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
717 struct obd_device *obd = container_of(kobj, struct obd_device,
719 struct obd_import *imp;
722 with_imp_locked(obd, imp, len)
723 len = scnprintf(buf, PAGE_SIZE, "%d\n",
724 !imp->imp_grant_shrink_disabled &&
725 OCD_HAS_FLAG(&imp->imp_connect_data,
731 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
732 const char *buffer, size_t count)
734 struct obd_device *obd = container_of(kobj, struct obd_device,
736 struct obd_import *imp;
743 rc = kstrtobool(buffer, &val);
747 with_imp_locked(obd, imp, rc) {
748 spin_lock(&imp->imp_lock);
749 imp->imp_grant_shrink_disabled = !val;
750 spin_unlock(&imp->imp_lock);
755 LUSTRE_RW_ATTR(grant_shrink);
757 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
758 struct attribute *attr,
761 struct obd_device *obd = container_of(kobj, struct obd_device,
764 return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
767 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
768 struct attribute *attr,
772 struct obd_device *obd = container_of(kobj, struct obd_device,
777 rc = kstrtouint(buffer, 0, &val);
784 obd->u.cli.cl_grant_shrink_interval = val;
785 osc_update_next_shrink(&obd->u.cli);
786 osc_schedule_grant_work();
790 LUSTRE_RW_ATTR(grant_shrink_interval);
792 static struct attribute *mdc_attrs[] = {
793 &lustre_attr_active.attr,
794 &lustre_attr_checksums.attr,
795 &lustre_attr_checksum_dump.attr,
796 &lustre_attr_max_rpcs_in_flight.attr,
797 &lustre_attr_max_mod_rpcs_in_flight.attr,
798 &lustre_attr_mds_conn_uuid.attr,
799 &lustre_attr_conn_uuid.attr,
800 &lustre_attr_ping.attr,
801 &lustre_attr_grant_shrink.attr,
802 &lustre_attr_grant_shrink_interval.attr,
803 &lustre_attr_cur_lost_grant_bytes.attr,
804 &lustre_attr_cur_dirty_grant_bytes.attr,
808 KOBJ_ATTRIBUTE_GROUPS(mdc); /* creates mdc_groups */
810 int mdc_tunables_init(struct obd_device *obd)
814 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdc);
815 obd->obd_vars = lprocfs_mdc_obd_vars;
817 rc = lprocfs_obd_setup(obd, false);
820 #ifdef CONFIG_PROC_FS
821 rc = lprocfs_alloc_md_stats(obd, 0);
823 lprocfs_obd_cleanup(obd);
827 rc = sptlrpc_lprocfs_cliobd_attach(obd);
829 #ifdef CONFIG_PROC_FS
830 lprocfs_free_md_stats(obd);
832 lprocfs_obd_cleanup(obd);
835 ptlrpc_lprocfs_register_obd(obd);