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,
63 rc = kstrtobool(buffer, &val);
68 if (obd->u.cli.cl_import->imp_deactive == val)
69 rc = ptlrpc_set_import_active(obd->u.cli.cl_import, val);
71 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
76 LUSTRE_RW_ATTR(active);
78 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
79 struct attribute *attr,
82 struct obd_device *obd = container_of(kobj, struct obd_device,
87 max = obd_get_max_rpcs_in_flight(&obd->u.cli);
88 len = sprintf(buf, "%u\n", max);
93 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
94 struct attribute *attr,
98 struct obd_device *obd = container_of(kobj, struct obd_device,
103 rc = kstrtouint(buffer, 10, &val);
107 rc = obd_set_max_rpcs_in_flight(&obd->u.cli, val);
113 LUSTRE_RW_ATTR(max_rpcs_in_flight);
115 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
116 struct attribute *attr,
119 struct obd_device *obd = container_of(kobj, struct obd_device,
123 max = obd_get_max_mod_rpcs_in_flight(&obd->u.cli);
124 return sprintf(buf, "%hu\n", max);
127 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
128 struct attribute *attr,
132 struct obd_device *obd = container_of(kobj, struct obd_device,
137 rc = kstrtou16(buffer, 10, &val);
141 rc = obd_set_max_mod_rpcs_in_flight(&obd->u.cli, val);
147 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
149 static int mdc_max_dirty_mb_seq_show(struct seq_file *m, void *v)
151 struct obd_device *obd = m->private;
152 struct client_obd *cli = &obd->u.cli;
154 seq_printf(m, "%lu\n", PAGES_TO_MiB(cli->cl_dirty_max_pages));
158 static ssize_t mdc_max_dirty_mb_seq_write(struct file *file,
159 const char __user *buffer,
160 size_t count, loff_t *off)
162 struct seq_file *sfl = file->private_data;
163 struct obd_device *obd = sfl->private;
164 struct client_obd *cli = &obd->u.cli;
165 char kernbuf[22] = "";
169 if (count >= sizeof(kernbuf))
172 if (copy_from_user(kernbuf, buffer, count))
176 rc = sysfs_memparse(kernbuf, count, &pages_number, "MiB");
181 pages_number = round_up(pages_number, 1024 * 1024) >> PAGE_SHIFT;
182 if (pages_number <= 0 ||
183 pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
184 pages_number > cfs_totalram_pages() / 4) /* 1/4 of RAM */
187 spin_lock(&cli->cl_loi_list_lock);
188 cli->cl_dirty_max_pages = pages_number;
189 osc_wake_cache_waiters(cli);
190 spin_unlock(&cli->cl_loi_list_lock);
194 LPROC_SEQ_FOPS(mdc_max_dirty_mb);
198 static int mdc_checksum_type_seq_show(struct seq_file *m, void *v)
200 struct obd_device *obd = m->private;
206 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
207 if ((BIT(i) & obd->u.cli.cl_supp_cksum_types) == 0)
209 if (obd->u.cli.cl_cksum_type == BIT(i))
210 seq_printf(m, "[%s] ", cksum_name[i]);
212 seq_printf(m, "%s ", cksum_name[i]);
219 static ssize_t mdc_checksum_type_seq_write(struct file *file,
220 const char __user *buffer,
221 size_t count, loff_t *off)
223 struct seq_file *m = file->private_data;
224 struct obd_device *obd = m->private;
232 if (count > sizeof(kernbuf) - 1)
234 if (copy_from_user(kernbuf, buffer, count))
237 if (count > 0 && kernbuf[count - 1] == '\n')
238 kernbuf[count - 1] = '\0';
240 kernbuf[count] = '\0';
242 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
243 if (strcmp(kernbuf, cksum_name[i]) == 0) {
244 obd->u.cli.cl_preferred_cksum_type = BIT(i);
245 if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
246 obd->u.cli.cl_cksum_type = BIT(i);
257 LPROC_SEQ_FOPS(mdc_checksum_type);
259 static ssize_t checksums_show(struct kobject *kobj,
260 struct attribute *attr, char *buf)
262 struct obd_device *obd = container_of(kobj, struct obd_device,
265 return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum);
268 static ssize_t checksums_store(struct kobject *kobj,
269 struct attribute *attr,
273 struct obd_device *obd = container_of(kobj, struct obd_device,
278 rc = kstrtobool(buffer, &val);
282 obd->u.cli.cl_checksum = val;
286 LUSTRE_RW_ATTR(checksums);
288 static ssize_t checksum_dump_show(struct kobject *kobj,
289 struct attribute *attr, char *buf)
291 struct obd_device *obd = container_of(kobj, struct obd_device,
294 return scnprintf(buf, PAGE_SIZE, "%d\n", !!obd->u.cli.cl_checksum_dump);
297 static ssize_t checksum_dump_store(struct kobject *kobj,
298 struct attribute *attr,
302 struct obd_device *obd = container_of(kobj, struct obd_device,
307 rc = kstrtobool(buffer, &val);
311 obd->u.cli.cl_checksum_dump = val;
315 LUSTRE_RW_ATTR(checksum_dump);
317 static ssize_t contention_seconds_show(struct kobject *kobj,
318 struct attribute *attr,
321 struct obd_device *obd = container_of(kobj, struct obd_device,
323 struct osc_device *od = obd2osc_dev(obd);
325 return sprintf(buf, "%lld\n", od->od_contention_time);
328 static ssize_t contention_seconds_store(struct kobject *kobj,
329 struct attribute *attr,
333 struct obd_device *obd = container_of(kobj, struct obd_device,
335 struct osc_device *od = obd2osc_dev(obd);
339 rc = kstrtoll(buffer, 0, &val);
343 od->od_contention_time = val;
347 LUSTRE_RW_ATTR(contention_seconds);
349 LUSTRE_ATTR(mds_conn_uuid, 0444, conn_uuid_show, NULL);
350 LUSTRE_RO_ATTR(conn_uuid);
352 LUSTRE_RW_ATTR(ping);
354 static int mdc_cached_mb_seq_show(struct seq_file *m, void *v)
356 struct obd_device *obd = m->private;
357 struct client_obd *cli = &obd->u.cli;
358 int shift = 20 - PAGE_SHIFT;
360 seq_printf(m, "used_mb: %ld\n"
363 (atomic_long_read(&cli->cl_lru_in_list) +
364 atomic_long_read(&cli->cl_lru_busy)) >> shift,
365 atomic_long_read(&cli->cl_lru_busy),
366 cli->cl_lru_reclaim);
371 /* shrink the number of caching pages to a specific number */
373 mdc_cached_mb_seq_write(struct file *file, const char __user *buffer,
374 size_t count, loff_t *off)
376 struct seq_file *sfl = file->private_data;
377 struct obd_device *obd = sfl->private;
378 struct client_obd *cli = &obd->u.cli;
384 if (count >= sizeof(kernbuf))
387 if (copy_from_user(kernbuf, buffer, count))
391 tmp = lprocfs_find_named_value(kernbuf, "used_mb:", &count);
392 rc = sysfs_memparse(tmp, count, &pages_number, "MiB");
396 pages_number >>= PAGE_SHIFT;
398 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
403 env = cl_env_get(&refcheck);
405 (void)osc_lru_shrink(env, cli, rc, true);
406 cl_env_put(env, &refcheck);
412 LPROC_SEQ_FOPS(mdc_cached_mb);
414 static int mdc_unstable_stats_seq_show(struct seq_file *m, void *v)
416 struct obd_device *obd = m->private;
417 struct client_obd *cli = &obd->u.cli;
421 pages = atomic_long_read(&cli->cl_unstable_count);
422 mb = (pages * PAGE_SIZE) >> 20;
424 seq_printf(m, "unstable_pages: %20ld\n"
425 "unstable_mb: %10d\n", pages, mb);
428 LPROC_SEQ_FOPS_RO(mdc_unstable_stats);
430 static ssize_t mdc_rpc_stats_seq_write(struct file *file,
431 const char __user *buf,
432 size_t len, loff_t *off)
434 struct seq_file *seq = file->private_data;
435 struct obd_device *obd = seq->private;
436 struct client_obd *cli = &obd->u.cli;
438 lprocfs_oh_clear(&cli->cl_mod_rpcs_hist);
440 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
441 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
442 lprocfs_oh_clear(&cli->cl_read_page_hist);
443 lprocfs_oh_clear(&cli->cl_write_page_hist);
444 lprocfs_oh_clear(&cli->cl_read_offset_hist);
445 lprocfs_oh_clear(&cli->cl_write_offset_hist);
450 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
452 struct obd_device *obd = seq->private;
453 struct client_obd *cli = &obd->u.cli;
454 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
457 obd_mod_rpc_stats_seq_show(cli, seq);
459 spin_lock(&cli->cl_loi_list_lock);
461 seq_printf(seq, "\nread RPCs in flight: %d\n",
462 cli->cl_r_in_flight);
463 seq_printf(seq, "write RPCs in flight: %d\n",
464 cli->cl_w_in_flight);
465 seq_printf(seq, "pending write pages: %d\n",
466 atomic_read(&cli->cl_pending_w_pages));
467 seq_printf(seq, "pending read pages: %d\n",
468 atomic_read(&cli->cl_pending_r_pages));
470 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
471 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
472 seq_printf(seq, " rpcs %% cum %%\n");
474 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
475 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
479 for (i = 0; i < OBD_HIST_MAX; i++) {
480 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
481 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
485 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
486 1 << i, r, pct(r, read_tot),
487 pct(read_cum, read_tot), w,
489 pct(write_cum, write_tot));
490 if (read_cum == read_tot && write_cum == write_tot)
494 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
495 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
496 seq_printf(seq, " rpcs %% cum %%\n");
498 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
499 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
503 for (i = 1; i < OBD_HIST_MAX; i++) {
504 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
505 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
509 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
510 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
511 pct(w, write_tot), pct(write_cum, write_tot));
512 if (read_cum == read_tot && write_cum == write_tot)
516 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
517 seq_printf(seq, "offset rpcs %% cum %% |");
518 seq_printf(seq, " rpcs %% cum %%\n");
520 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
521 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
525 for (i = 0; i < OBD_HIST_MAX; i++) {
526 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
527 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
531 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
532 (i == 0) ? 0 : 1 << (i - 1),
533 r, pct(r, read_tot), pct(read_cum, read_tot),
534 w, pct(w, write_tot), pct(write_cum, write_tot));
535 if (read_cum == read_tot && write_cum == write_tot)
538 spin_unlock(&cli->cl_loi_list_lock);
542 LPROC_SEQ_FOPS(mdc_rpc_stats);
544 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
546 struct timespec64 now;
547 struct obd_device *obd = seq->private;
548 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
550 ktime_get_real_ts64(&now);
552 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
553 (s64)now.tv_sec, now.tv_nsec);
554 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
555 stats->os_lockless_writes);
556 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
557 stats->os_lockless_reads);
558 seq_printf(seq, "lockless_truncate\t\t%llu\n",
559 stats->os_lockless_truncates);
563 static ssize_t mdc_stats_seq_write(struct file *file,
564 const char __user *buf,
565 size_t len, loff_t *off)
567 struct seq_file *seq = file->private_data;
568 struct obd_device *obd = seq->private;
569 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
571 memset(stats, 0, sizeof(*stats));
574 LPROC_SEQ_FOPS(mdc_stats);
576 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
578 struct obd_device *obd = m->private;
580 seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
585 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
586 const char __user *buffer,
587 size_t count, loff_t *off)
589 struct seq_file *m = file->private_data;
590 struct obd_device *obd = m->private;
594 rc = kstrtouint_from_user(buffer, count, 0, &val);
598 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
601 obd->u.cli.cl_dom_min_inline_repsize = val;
604 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
606 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
607 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
608 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
609 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
610 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
611 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
612 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
614 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
615 { .name = "connect_flags",
616 .fops = &mdc_connect_flags_fops },
617 { .name = "mds_server_uuid",
618 .fops = &mdc_server_uuid_fops },
619 { .name = "max_pages_per_rpc",
620 .fops = &mdc_obd_max_pages_per_rpc_fops },
621 { .name = "max_dirty_mb",
622 .fops = &mdc_max_dirty_mb_fops },
623 { .name = "mdc_cached_mb",
624 .fops = &mdc_cached_mb_fops },
625 { .name = "checksum_type",
626 .fops = &mdc_checksum_type_fops },
627 { .name = "timeouts",
628 .fops = &mdc_timeouts_fops },
630 .fops = &mdc_import_fops },
632 .fops = &mdc_state_fops },
633 { .name = "pinger_recov",
634 .fops = &mdc_pinger_recov_fops },
635 { .name = "rpc_stats",
636 .fops = &mdc_rpc_stats_fops },
637 { .name = "unstable_stats",
638 .fops = &mdc_unstable_stats_fops },
639 { .name = "mdc_stats",
640 .fops = &mdc_stats_fops },
641 { .name = "mdc_dom_min_repsize",
642 .fops = &mdc_dom_min_repsize_fops },
646 static struct attribute *mdc_attrs[] = {
647 &lustre_attr_active.attr,
648 &lustre_attr_checksums.attr,
649 &lustre_attr_checksum_dump.attr,
650 &lustre_attr_max_rpcs_in_flight.attr,
651 &lustre_attr_max_mod_rpcs_in_flight.attr,
652 &lustre_attr_contention_seconds.attr,
653 &lustre_attr_mds_conn_uuid.attr,
654 &lustre_attr_conn_uuid.attr,
655 &lustre_attr_ping.attr,
659 int mdc_tunables_init(struct obd_device *obd)
663 obd->obd_ktype.default_attrs = mdc_attrs;
664 obd->obd_vars = lprocfs_mdc_obd_vars;
666 rc = lprocfs_obd_setup(obd, false);
669 #ifdef CONFIG_PROC_FS
670 rc = lprocfs_alloc_md_stats(obd, 0);
672 lprocfs_obd_cleanup(obd);
676 rc = sptlrpc_lprocfs_cliobd_attach(obd);
678 #ifdef CONFIG_PROC_FS
679 lprocfs_free_md_stats(obd);
681 lprocfs_obd_cleanup(obd);
684 ptlrpc_lprocfs_register_obd(obd);