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,
107 rc = kstrtouint(buffer, 10, &val);
111 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
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,
141 rc = kstrtou16(buffer, 10, &val);
145 rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
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 int mdc_stats_seq_show(struct seq_file *seq, void *v)
519 struct obd_device *obd = seq->private;
520 struct osc_stats *stats = &obd2osc_dev(obd)->osc_stats;
522 lprocfs_stats_header(seq, ktime_get_real(), stats->os_init, 25, ":",
524 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
525 stats->os_lockless_writes);
526 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
527 stats->os_lockless_reads);
531 static ssize_t mdc_stats_seq_write(struct file *file,
532 const char __user *buf,
533 size_t len, loff_t *off)
535 struct seq_file *seq = file->private_data;
536 struct obd_device *obd = seq->private;
537 struct osc_stats *stats = &obd2osc_dev(obd)->osc_stats;
539 memset(stats, 0, sizeof(*stats));
540 stats->os_init = ktime_get_real();
544 LPROC_SEQ_FOPS(mdc_stats);
546 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
548 struct obd_device *obd = m->private;
550 seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
555 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
556 const char __user *buffer,
557 size_t count, loff_t *off)
559 struct seq_file *m = file->private_data;
560 struct obd_device *obd = m->private;
564 rc = kstrtouint_from_user(buffer, count, 0, &val);
568 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
571 obd->u.cli.cl_dom_min_inline_repsize = val;
574 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
576 static int mdc_lsom_seq_show(struct seq_file *m, void *v)
578 struct obd_device *dev = m->private;
580 seq_printf(m, "%s\n", dev->u.cli.cl_lsom_update ? "On" : "Off");
585 static ssize_t mdc_lsom_seq_write(struct file *file,
586 const char __user *buffer,
587 size_t count, loff_t *off)
589 struct obd_device *dev;
593 dev = ((struct seq_file *)file->private_data)->private;
594 rc = kstrtobool_from_user(buffer, count, &val);
598 dev->u.cli.cl_lsom_update = val;
601 LPROC_SEQ_FOPS(mdc_lsom);
604 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
605 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
606 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
607 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
608 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
609 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
610 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
612 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
613 { .name = "connect_flags",
614 .fops = &mdc_connect_flags_fops },
615 { .name = "mds_server_uuid",
616 .fops = &mdc_server_uuid_fops },
617 { .name = "max_pages_per_rpc",
618 .fops = &mdc_obd_max_pages_per_rpc_fops },
619 { .name = "max_dirty_mb",
620 .fops = &mdc_max_dirty_mb_fops },
621 { .name = "mdc_cached_mb",
622 .fops = &mdc_cached_mb_fops },
623 { .name = "checksum_type",
624 .fops = &mdc_checksum_type_fops },
625 { .name = "timeouts",
626 .fops = &mdc_timeouts_fops },
628 .fops = &mdc_import_fops },
630 .fops = &mdc_state_fops },
631 { .name = "pinger_recov",
632 .fops = &mdc_pinger_recov_fops },
633 { .name = "rpc_stats",
634 .fops = &mdc_rpc_stats_fops },
635 { .name = "unstable_stats",
636 .fops = &mdc_unstable_stats_fops },
637 { .name = "mdc_stats",
638 .fops = &mdc_stats_fops },
639 { .name = "mdc_dom_min_repsize",
640 .fops = &mdc_dom_min_repsize_fops },
641 { .name = "mdc_lsom",
642 .fops = &mdc_lsom_fops },
646 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
647 struct attribute *attr,
650 struct obd_device *obd = container_of(kobj, struct obd_device,
652 struct client_obd *cli = &obd->u.cli;
654 return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_lost_grant);
656 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
658 static ssize_t cur_dirty_grant_bytes_show(struct kobject *kobj,
659 struct attribute *attr,
662 struct obd_device *obd = container_of(kobj, struct obd_device,
664 struct client_obd *cli = &obd->u.cli;
666 return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_dirty_grant);
668 LUSTRE_RO_ATTR(cur_dirty_grant_bytes);
670 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
673 struct obd_device *obd = container_of(kobj, struct obd_device,
675 struct obd_import *imp;
678 with_imp_locked(obd, imp, len)
679 len = scnprintf(buf, PAGE_SIZE, "%d\n",
680 !imp->imp_grant_shrink_disabled &&
681 OCD_HAS_FLAG(&imp->imp_connect_data,
687 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
688 const char *buffer, size_t count)
690 struct obd_device *obd = container_of(kobj, struct obd_device,
692 struct obd_import *imp;
699 rc = kstrtobool(buffer, &val);
703 with_imp_locked(obd, imp, rc) {
704 spin_lock(&imp->imp_lock);
705 imp->imp_grant_shrink_disabled = !val;
706 spin_unlock(&imp->imp_lock);
711 LUSTRE_RW_ATTR(grant_shrink);
713 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
714 struct attribute *attr,
717 struct obd_device *obd = container_of(kobj, struct obd_device,
720 return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
723 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
724 struct attribute *attr,
728 struct obd_device *obd = container_of(kobj, struct obd_device,
733 rc = kstrtouint(buffer, 0, &val);
740 obd->u.cli.cl_grant_shrink_interval = val;
741 osc_update_next_shrink(&obd->u.cli);
742 osc_schedule_grant_work();
746 LUSTRE_RW_ATTR(grant_shrink_interval);
748 static struct attribute *mdc_attrs[] = {
749 &lustre_attr_active.attr,
750 &lustre_attr_checksums.attr,
751 &lustre_attr_checksum_dump.attr,
752 &lustre_attr_max_rpcs_in_flight.attr,
753 &lustre_attr_max_mod_rpcs_in_flight.attr,
754 &lustre_attr_mds_conn_uuid.attr,
755 &lustre_attr_conn_uuid.attr,
756 &lustre_attr_ping.attr,
757 &lustre_attr_grant_shrink.attr,
758 &lustre_attr_grant_shrink_interval.attr,
759 &lustre_attr_cur_lost_grant_bytes.attr,
760 &lustre_attr_cur_dirty_grant_bytes.attr,
764 KOBJ_ATTRIBUTE_GROUPS(mdc); /* creates mdc_groups */
766 int mdc_tunables_init(struct obd_device *obd)
770 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdc);
771 obd->obd_vars = lprocfs_mdc_obd_vars;
773 rc = lprocfs_obd_setup(obd, false);
776 #ifdef CONFIG_PROC_FS
777 rc = lprocfs_alloc_md_stats(obd, 0);
779 lprocfs_obd_cleanup(obd);
783 rc = sptlrpc_lprocfs_cliobd_attach(obd);
785 #ifdef CONFIG_PROC_FS
786 lprocfs_free_md_stats(obd);
788 lprocfs_obd_cleanup(obd);
791 ptlrpc_lprocfs_register_obd(obd);