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/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 #define DEBUG_SUBSYSTEM S_CLASS
34 #include <linux/vfs.h>
35 #include <obd_class.h>
36 #include <obd_cksum.h>
37 #include <lprocfs_status.h>
38 #include <lustre_osc.h>
39 #include <cl_object.h>
40 #include "mdc_internal.h"
42 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
45 struct obd_device *obd = container_of(kobj, struct obd_device,
47 struct obd_import *imp;
50 with_imp_locked(obd, imp, len)
51 len = sprintf(buf, "%d\n", !imp->imp_deactive);
55 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
56 const char *buffer, size_t count)
58 struct obd_device *obd = container_of(kobj, struct obd_device,
60 struct obd_import *imp, *imp0;
64 rc = kstrtobool(buffer, &val);
68 with_imp_locked(obd, imp0, rc)
69 imp = class_import_get(imp0);
73 if (imp->imp_deactive == val)
74 rc = ptlrpc_set_import_active(imp, val);
76 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
78 class_import_put(imp);
81 LUSTRE_RW_ATTR(active);
83 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
84 struct attribute *attr,
87 struct obd_device *obd = container_of(kobj, struct obd_device,
92 max = obd_get_max_rpcs_in_flight(&obd->u.cli);
93 len = sprintf(buf, "%u\n", max);
98 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
99 struct attribute *attr,
103 struct obd_device *obd = container_of(kobj, struct obd_device,
108 rc = kstrtouint(buffer, 10, &val);
112 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
118 LUSTRE_RW_ATTR(max_rpcs_in_flight);
120 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
121 struct attribute *attr,
124 struct obd_device *obd = container_of(kobj, struct obd_device,
128 max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
129 return sprintf(buf, "%hu\n", max);
132 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
133 struct attribute *attr,
137 struct obd_device *obd = container_of(kobj, struct obd_device,
142 rc = kstrtou16(buffer, 10, &val);
146 rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
152 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
154 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
156 struct obd_device *obd = m->private;
157 struct client_obd *cli = &obd->u.cli;
159 seq_printf(m, "%lu\n", PAGES_TO_MiB(cli->cl_dirty_max_pages));
163 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
164 const char __user *buffer,
165 size_t count, loff_t *off)
167 struct seq_file *sfl = file->private_data;
168 struct obd_device *obd = sfl->private;
169 struct client_obd *cli = &obd->u.cli;
170 char kernbuf[22] = "";
174 if (count >= sizeof(kernbuf))
177 if (copy_from_user(kernbuf, buffer, count))
181 rc = sysfs_memparse(kernbuf, count, &pages_number, "MiB");
186 pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT;
187 if (pages_number <= 0 ||
188 pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
189 pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
192 spin_lock(&cli->cl_loi_list_lock);
193 cli->cl_dirty_max_pages = pages_number;
194 osc_wake_cache_waiters(cli);
195 spin_unlock(&cli->cl_loi_list_lock);
199 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
203 static int mdc_checksum_type_seq_show(struct seq_file *m, void *v)
205 struct obd_device *obd = m->private;
211 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
212 if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0)
214 if (obd->u.cli.cl_cksum_type == BIT(i))
215 seq_printf(m, "[%s] ", cksum_name[i]);
217 seq_printf(m, "%s ", cksum_name[i]);
224 static ssize_t mdc_checksum_type_seq_write(struct file *file,
225 const char __user *buffer,
226 size_t count, loff_t *off)
228 struct seq_file *m = file->private_data;
229 struct obd_device *obd = m->private;
237 if (count > sizeof(kernbuf) - 1)
239 if (copy_from_user(kernbuf, buffer, count))
242 if (count > 0 && kernbuf[count - 1] == '\n')
243 kernbuf[count - 1] = '\0';
245 kernbuf[count] = '\0';
247 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
248 if (strcmp(kernbuf, cksum_name[i]) == 0) {
249 obd->u.cli.cl_preferred_cksum_type = BIT(i);
250 if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
251 obd->u.cli.cl_cksum_type = BIT(i);
262 LPROC_SEQ_FOPS(mdc_checksum_type);
264 static ssize_t checksums_show(struct kobject *kobj,
265 struct attribute *attr, char *buf)
267 struct obd_device *obd = container_of(kobj, struct obd_device,
270 return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum);
273 static ssize_t checksums_store(struct kobject *kobj,
274 struct attribute *attr,
278 struct obd_device *obd = container_of(kobj, struct obd_device,
283 rc = kstrtobool(buffer, &val);
287 obd->u.cli.cl_checksum = val;
291 LUSTRE_RW_ATTR(checksums);
293 static ssize_t checksum_dump_show(struct kobject *kobj,
294 struct attribute *attr, char *buf)
296 struct obd_device *obd = container_of(kobj, struct obd_device,
299 return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum_dump);
302 static ssize_t checksum_dump_store(struct kobject *kobj,
303 struct attribute *attr,
307 struct obd_device *obd = container_of(kobj, struct obd_device,
312 rc = kstrtobool(buffer, &val);
316 obd->u.cli.cl_checksum_dump = val;
320 LUSTRE_RW_ATTR(checksum_dump);
322 static ssize_t contention_seconds_show(struct kobject *kobj,
323 struct attribute *attr,
326 struct obd_device *obd = container_of(kobj, struct obd_device,
328 struct osc_device *od = obd2osc_dev(obd);
330 return sprintf(buf, "%lld\n", od->od_contention_time);
333 static ssize_t contention_seconds_store(struct kobject *kobj,
334 struct attribute *attr,
338 struct obd_device *obd = container_of(kobj, struct obd_device,
340 struct osc_device *od = obd2osc_dev(obd);
344 rc = kstrtoll(buffer, 0, &val);
348 od->od_contention_time = val;
352 LUSTRE_RW_ATTR(contention_seconds);
354 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
355 LUSTRE_RO_ATTR(conn_uuid);
357 LUSTRE_RW_ATTR(ping);
359 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
361 struct obd_device *obd = m->private;
362 struct client_obd *cli = &obd->u.cli;
363 int shift = 20 - PAGE_SHIFT;
365 seq_printf(m, "used_mb: %ld\n"
368 (atomic_long_read(&cli->cl_lru_in_list) +
369 atomic_long_read(&cli->cl_lru_busy)) >> shift,
370 atomic_long_read(&cli->cl_lru_busy),
371 cli->cl_lru_reclaim);
376 /* shrink the number of caching pages to a specific number */
378 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
379 size_t count, loff_t *off)
381 struct seq_file *sfl = file->private_data;
382 struct obd_device *obd = sfl->private;
383 struct client_obd *cli = &obd->u.cli;
389 if (count >= sizeof(kernbuf))
392 if (copy_from_user(kernbuf, buffer, count))
396 tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
397 rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
401 pages_number >>= PAGE_SHIFT;
403 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
408 env = cl_env_get(&refcheck);
410 (void)osc_lru_shrink(env, cli, rc, true);
411 cl_env_put(env, &refcheck);
417 LPROC_SEQ_FOPS(mdc_cached_mb);
419 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
421 struct obd_device *obd = m->private;
422 struct client_obd *cli = &obd->u.cli;
426 pages = atomic_long_read(&cli->cl_unstable_count);
427 mb = (pages * PAGE_SIZE) >> 20;
429 seq_printf(m, "unstable_pages: %20ld\n"
430 "unstable_mb: %10d\n", pages, mb);
433 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
435 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
436 const char __user *buf,
437 size_t len, loff_t *off)
439 struct seq_file *seq = file->private_data;
440 struct obd_device *obd = seq->private;
441 struct client_obd *cli = &obd->u.cli;
443 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
445 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
446 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
447 lprocfs_oh_clear(&cli->cl_read_page_hist);
448 lprocfs_oh_clear(&cli->cl_write_page_hist);
449 lprocfs_oh_clear(&cli->cl_read_offset_hist);
450 lprocfs_oh_clear(&cli->cl_write_offset_hist);
455 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
457 struct obd_device *obd = seq->private;
458 struct client_obd *cli = &obd->u.cli;
459 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
462 obd_mod_rpc_stats_seq_show(cli, seq);
464 spin_lock(&cli->cl_loi_list_lock);
466 seq_printf(seq, "\nread RPCs in flight: %d\n",
467 cli->cl_r_in_flight);
468 seq_printf(seq, "write RPCs in flight: %d\n",
469 cli->cl_w_in_flight);
470 seq_printf(seq, "pending write pages: %d\n",
471 atomic_read(&cli->cl_pending_w_pages));
472 seq_printf(seq, "pending read pages: %d\n",
473 atomic_read(&cli->cl_pending_r_pages));
475 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
476 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
477 seq_printf(seq, " rpcs %% cum %%\n");
479 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
480 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
484 for (i = 0; i < OBD_HIST_MAX; i++) {
485 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
486 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
490 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
491 1 << i, r, pct(r, read_tot),
492 pct(read_cum, read_tot), w,
494 pct(write_cum, write_tot));
495 if (read_cum == read_tot && write_cum == write_tot)
499 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
500 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
501 seq_printf(seq, " rpcs %% cum %%\n");
503 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
504 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
508 for (i = 1; i < OBD_HIST_MAX; i++) {
509 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
510 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
514 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
515 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
516 pct(w, write_tot), pct(write_cum, write_tot));
517 if (read_cum == read_tot && write_cum == write_tot)
521 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
522 seq_printf(seq, "offset rpcs %% cum %% |");
523 seq_printf(seq, " rpcs %% cum %%\n");
525 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
526 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
530 for (i = 0; i < OBD_HIST_MAX; i++) {
531 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
532 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
536 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
537 (i == 0) ? 0 : 1 << (i - 1),
538 r, pct(r, read_tot), pct(read_cum, read_tot),
539 w, pct(w, write_tot), pct(write_cum, write_tot));
540 if (read_cum == read_tot && write_cum == write_tot)
543 spin_unlock(&cli->cl_loi_list_lock);
547 LPROC_SEQ_FOPS(mdc_rpc_stats);
549 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
551 struct timespec64 now;
552 struct obd_device *obd = seq->private;
553 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
555 ktime_get_real_ts64(&now);
557 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
558 (s64)now.tv_sec, now.tv_nsec);
559 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
560 stats->os_lockless_writes);
561 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
562 stats->os_lockless_reads);
563 seq_printf(seq, "lockless_truncate\t\t%llu\n",
564 stats->os_lockless_truncates);
568 static ssize_t mdc_stats_seq_write(struct file *file,
569 const char __user *buf,
570 size_t len, loff_t *off)
572 struct seq_file *seq = file->private_data;
573 struct obd_device *obd = seq->private;
574 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
576 memset(stats, 0, sizeof(*stats));
579 LPROC_SEQ_FOPS(mdc_stats);
581 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
583 struct obd_device *obd = m->private;
585 seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
590 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
591 const char __user *buffer,
592 size_t count, loff_t *off)
594 struct seq_file *m = file->private_data;
595 struct obd_device *obd = m->private;
599 rc = kstrtouint_from_user(buffer, count, 0, &val);
603 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
606 obd->u.cli.cl_dom_min_inline_repsize = val;
609 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
611 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
612 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
613 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
614 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
615 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
616 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
617 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
619 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
620 { .name = "connect_flags",
621 .fops = &mdc_connect_flags_fops },
622 { .name = "mds_server_uuid",
623 .fops = &mdc_server_uuid_fops },
624 { .name = "max_pages_per_rpc",
625 .fops = &mdc_obd_max_pages_per_rpc_fops },
626 { .name = "max_dirty_mb",
627 .fops = &mdc_max_dirty_mb_fops },
628 { .name = "mdc_cached_mb",
629 .fops = &mdc_cached_mb_fops },
630 { .name = "checksum_type",
631 .fops = &mdc_checksum_type_fops },
632 { .name = "timeouts",
633 .fops = &mdc_timeouts_fops },
635 .fops = &mdc_import_fops },
637 .fops = &mdc_state_fops },
638 { .name = "pinger_recov",
639 .fops = &mdc_pinger_recov_fops },
640 { .name = "rpc_stats",
641 .fops = &mdc_rpc_stats_fops },
642 { .name = "unstable_stats",
643 .fops = &mdc_unstable_stats_fops },
644 { .name = "mdc_stats",
645 .fops = &mdc_stats_fops },
646 { .name = "mdc_dom_min_repsize",
647 .fops = &mdc_dom_min_repsize_fops },
651 static struct attribute *mdc_attrs[] = {
652 &lustre_attr_active.attr,
653 &lustre_attr_checksums.attr,
654 &lustre_attr_checksum_dump.attr,
655 &lustre_attr_max_rpcs_in_flight.attr,
656 &lustre_attr_max_mod_rpcs_in_flight.attr,
657 &lustre_attr_contention_seconds.attr,
658 &lustre_attr_mds_conn_uuid.attr,
659 &lustre_attr_conn_uuid.attr,
660 &lustre_attr_ping.attr,
664 int mdc_tunables_init(struct obd_device *obd)
668 obd->obd_ktype.default_attrs = mdc_attrs;
669 obd->obd_vars = lprocfs_mdc_obd_vars;
671 rc = lprocfs_obd_setup(obd, false);
674 #ifdef CONFIG_PROC_FS
675 rc = lprocfs_alloc_md_stats(obd, 0);
677 lprocfs_obd_cleanup(obd);
681 rc = sptlrpc_lprocfs_cliobd_attach(obd);
683 #ifdef CONFIG_PROC_FS
684 lprocfs_free_md_stats(obd);
686 lprocfs_obd_cleanup(obd);
689 ptlrpc_lprocfs_register_obd(obd);