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 (strcmp(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 static ssize_t contention_seconds_show(struct kobject *kobj,
322 struct attribute *attr,
325 struct obd_device *obd = container_of(kobj, struct obd_device,
327 struct osc_device *od = obd2osc_dev(obd);
329 return sprintf(buf, "%lld\n", od->od_contention_time);
332 static ssize_t contention_seconds_store(struct kobject *kobj,
333 struct attribute *attr,
337 struct obd_device *obd = container_of(kobj, struct obd_device,
339 struct osc_device *od = obd2osc_dev(obd);
343 rc = kstrtoll(buffer, 0, &val);
347 od->od_contention_time = val;
351 LUSTRE_RW_ATTR(contention_seconds);
353 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
354 LUSTRE_RO_ATTR(conn_uuid);
356 LUSTRE_RW_ATTR(ping);
358 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
360 struct obd_device *obd = m->private;
361 struct client_obd *cli = &obd->u.cli;
362 int shift = 20 - PAGE_SHIFT;
364 seq_printf(m, "used_mb: %ld\n"
367 (atomic_long_read(&cli->cl_lru_in_list) +
368 atomic_long_read(&cli->cl_lru_busy)) >> shift,
369 atomic_long_read(&cli->cl_lru_busy),
370 cli->cl_lru_reclaim);
375 /* shrink the number of caching pages to a specific number */
377 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
378 size_t count, loff_t *off)
380 struct seq_file *sfl = file->private_data;
381 struct obd_device *obd = sfl->private;
382 struct client_obd *cli = &obd->u.cli;
388 if (count >= sizeof(kernbuf))
391 if (copy_from_user(kernbuf, buffer, count))
395 tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
396 rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
400 pages_number >>= PAGE_SHIFT;
402 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
407 env = cl_env_get(&refcheck);
409 (void)osc_lru_shrink(env, cli, rc, true);
410 cl_env_put(env, &refcheck);
416 LPROC_SEQ_FOPS(mdc_cached_mb);
418 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
420 struct obd_device *obd = m->private;
421 struct client_obd *cli = &obd->u.cli;
425 pages = atomic_long_read(&cli->cl_unstable_count);
426 mb = (pages * PAGE_SIZE) >> 20;
428 seq_printf(m, "unstable_pages: %20ld\n"
429 "unstable_mb: %10d\n", pages, mb);
432 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
434 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
435 const char __user *buf,
436 size_t len, loff_t *off)
438 struct seq_file *seq = file->private_data;
439 struct obd_device *obd = seq->private;
440 struct client_obd *cli = &obd->u.cli;
442 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
444 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
445 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
446 lprocfs_oh_clear(&cli->cl_read_page_hist);
447 lprocfs_oh_clear(&cli->cl_write_page_hist);
448 lprocfs_oh_clear(&cli->cl_read_offset_hist);
449 lprocfs_oh_clear(&cli->cl_write_offset_hist);
454 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
456 struct obd_device *obd = seq->private;
457 struct client_obd *cli = &obd->u.cli;
458 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
461 obd_mod_rpc_stats_seq_show(cli, seq);
463 spin_lock(&cli->cl_loi_list_lock);
465 seq_printf(seq, "\nread RPCs in flight: %d\n",
466 cli->cl_r_in_flight);
467 seq_printf(seq, "write RPCs in flight: %d\n",
468 cli->cl_w_in_flight);
469 seq_printf(seq, "pending write pages: %d\n",
470 atomic_read(&cli->cl_pending_w_pages));
471 seq_printf(seq, "pending read pages: %d\n",
472 atomic_read(&cli->cl_pending_r_pages));
474 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
475 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
476 seq_printf(seq, " rpcs %% cum %%\n");
478 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
479 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
483 for (i = 0; i < OBD_HIST_MAX; i++) {
484 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
485 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
489 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
490 1 << i, r, pct(r, read_tot),
491 pct(read_cum, read_tot), w,
493 pct(write_cum, write_tot));
494 if (read_cum == read_tot && write_cum == write_tot)
498 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
499 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
500 seq_printf(seq, " rpcs %% cum %%\n");
502 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
503 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
507 for (i = 1; i < OBD_HIST_MAX; i++) {
508 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
509 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
513 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
514 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
515 pct(w, write_tot), pct(write_cum, write_tot));
516 if (read_cum == read_tot && write_cum == write_tot)
520 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
521 seq_printf(seq, "offset rpcs %% cum %% |");
522 seq_printf(seq, " rpcs %% cum %%\n");
524 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
525 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
529 for (i = 0; i < OBD_HIST_MAX; i++) {
530 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
531 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
535 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
536 (i == 0) ? 0 : 1 << (i - 1),
537 r, pct(r, read_tot), pct(read_cum, read_tot),
538 w, pct(w, write_tot), pct(write_cum, write_tot));
539 if (read_cum == read_tot && write_cum == write_tot)
542 spin_unlock(&cli->cl_loi_list_lock);
546 LPROC_SEQ_FOPS(mdc_rpc_stats);
548 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
550 struct timespec64 now;
551 struct obd_device *obd = seq->private;
552 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
554 ktime_get_real_ts64(&now);
556 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
557 (s64)now.tv_sec, now.tv_nsec);
558 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
559 stats->os_lockless_writes);
560 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
561 stats->os_lockless_reads);
562 seq_printf(seq, "lockless_truncate\t\t%llu\n",
563 stats->os_lockless_truncates);
567 static ssize_t mdc_stats_seq_write(struct file *file,
568 const char __user *buf,
569 size_t len, loff_t *off)
571 struct seq_file *seq = file->private_data;
572 struct obd_device *obd = seq->private;
573 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
575 memset(stats, 0, sizeof(*stats));
578 LPROC_SEQ_FOPS(mdc_stats);
580 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
582 struct obd_device *obd = m->private;
584 seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
589 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
590 const char __user *buffer,
591 size_t count, loff_t *off)
593 struct seq_file *m = file->private_data;
594 struct obd_device *obd = m->private;
598 rc = kstrtouint_from_user(buffer, count, 0, &val);
602 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
605 obd->u.cli.cl_dom_min_inline_repsize = val;
608 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
610 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
611 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
612 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
613 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
614 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
615 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
616 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
618 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
619 { .name = "connect_flags",
620 .fops = &mdc_connect_flags_fops },
621 { .name = "mds_server_uuid",
622 .fops = &mdc_server_uuid_fops },
623 { .name = "max_pages_per_rpc",
624 .fops = &mdc_obd_max_pages_per_rpc_fops },
625 { .name = "max_dirty_mb",
626 .fops = &mdc_max_dirty_mb_fops },
627 { .name = "mdc_cached_mb",
628 .fops = &mdc_cached_mb_fops },
629 { .name = "checksum_type",
630 .fops = &mdc_checksum_type_fops },
631 { .name = "timeouts",
632 .fops = &mdc_timeouts_fops },
634 .fops = &mdc_import_fops },
636 .fops = &mdc_state_fops },
637 { .name = "pinger_recov",
638 .fops = &mdc_pinger_recov_fops },
639 { .name = "rpc_stats",
640 .fops = &mdc_rpc_stats_fops },
641 { .name = "unstable_stats",
642 .fops = &mdc_unstable_stats_fops },
643 { .name = "mdc_stats",
644 .fops = &mdc_stats_fops },
645 { .name = "mdc_dom_min_repsize",
646 .fops = &mdc_dom_min_repsize_fops },
650 static struct attribute *mdc_attrs[] = {
651 &lustre_attr_active.attr,
652 &lustre_attr_checksums.attr,
653 &lustre_attr_checksum_dump.attr,
654 &lustre_attr_max_rpcs_in_flight.attr,
655 &lustre_attr_max_mod_rpcs_in_flight.attr,
656 &lustre_attr_contention_seconds.attr,
657 &lustre_attr_mds_conn_uuid.attr,
658 &lustre_attr_conn_uuid.attr,
659 &lustre_attr_ping.attr,
663 int mdc_tunables_init(struct obd_device *obd)
667 obd->obd_ktype.default_attrs = mdc_attrs;
668 obd->obd_vars = lprocfs_mdc_obd_vars;
670 rc = lprocfs_obd_setup(obd, false);
673 #ifdef CONFIG_PROC_FS
674 rc = lprocfs_alloc_md_stats(obd, 0);
676 lprocfs_obd_cleanup(obd);
680 rc = sptlrpc_lprocfs_cliobd_attach(obd);
682 #ifdef CONFIG_PROC_FS
683 lprocfs_free_md_stats(obd);
685 lprocfs_obd_cleanup(obd);
688 ptlrpc_lprocfs_register_obd(obd);