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);
422 static int mdc_rpc_stats_seq_show(struct seq_file *seq, void *v)
424 struct obd_device *obd = seq->private;
425 struct client_obd *cli = &obd->u.cli;
426 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
429 obd_mod_rpc_stats_seq_show(cli, seq);
431 spin_lock(&cli->cl_loi_list_lock);
433 seq_printf(seq, "\nread RPCs in flight: %d\n",
434 cli->cl_r_in_flight);
435 seq_printf(seq, "write RPCs in flight: %d\n",
436 cli->cl_w_in_flight);
437 seq_printf(seq, "pending write pages: %d\n",
438 atomic_read(&cli->cl_pending_w_pages));
439 seq_printf(seq, "pending read pages: %d\n",
440 atomic_read(&cli->cl_pending_r_pages));
442 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
443 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
444 seq_printf(seq, " rpcs %% cum %%\n");
446 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
447 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
451 for (i = 0; i < OBD_HIST_MAX; i++) {
452 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
453 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
457 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
458 1 << i, r, pct(r, read_tot),
459 pct(read_cum, read_tot), w,
461 pct(write_cum, write_tot));
462 if (read_cum == read_tot && write_cum == write_tot)
466 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
467 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
468 seq_printf(seq, " rpcs %% cum %%\n");
470 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
471 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
475 for (i = 1; i < OBD_HIST_MAX; i++) {
476 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
477 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
481 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
482 i, r, pct(r, read_tot), pct(read_cum, read_tot), w,
483 pct(w, write_tot), pct(write_cum, write_tot));
484 if (read_cum == read_tot && write_cum == write_tot)
488 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
489 seq_printf(seq, "offset rpcs %% cum %% |");
490 seq_printf(seq, " rpcs %% cum %%\n");
492 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
493 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
497 for (i = 0; i < OBD_HIST_MAX; i++) {
498 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
499 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
503 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
504 (i == 0) ? 0 : 1 << (i - 1),
505 r, pct(r, read_tot), pct(read_cum, read_tot),
506 w, pct(w, write_tot), pct(write_cum, write_tot));
507 if (read_cum == read_tot && write_cum == write_tot)
510 spin_unlock(&cli->cl_loi_list_lock);
514 LPROC_SEQ_FOPS(mdc_rpc_stats);
516 static int mdc_stats_seq_show(struct seq_file *seq, void *v)
518 struct obd_device *obd = seq->private;
519 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
521 lprocfs_stats_header(seq, ktime_get(), stats->os_init, 25, ":", true);
522 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
523 stats->os_lockless_writes);
524 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
525 stats->os_lockless_reads);
529 static ssize_t mdc_stats_seq_write(struct file *file,
530 const char __user *buf,
531 size_t len, loff_t *off)
533 struct seq_file *seq = file->private_data;
534 struct obd_device *obd = seq->private;
535 struct osc_stats *stats = &obd2osc_dev(obd)->od_stats;
537 memset(stats, 0, sizeof(*stats));
538 stats->os_init = ktime_get();
542 LPROC_SEQ_FOPS(mdc_stats);
544 static int mdc_dom_min_repsize_seq_show(struct seq_file *m, void *v)
546 struct obd_device *obd = m->private;
548 seq_printf(m, "%u\n", obd->u.cli.cl_dom_min_inline_repsize);
553 static ssize_t mdc_dom_min_repsize_seq_write(struct file *file,
554 const char __user *buffer,
555 size_t count, loff_t *off)
557 struct seq_file *m = file->private_data;
558 struct obd_device *obd = m->private;
562 rc = kstrtouint_from_user(buffer, count, 0, &val);
566 if (val > MDC_DOM_MAX_INLINE_REPSIZE)
569 obd->u.cli.cl_dom_min_inline_repsize = val;
572 LPROC_SEQ_FOPS(mdc_dom_min_repsize);
574 LPROC_SEQ_FOPS_RO_TYPE(mdc, connect_flags);
575 LPROC_SEQ_FOPS_RO_TYPE(mdc, server_uuid);
576 LPROC_SEQ_FOPS_RO_TYPE(mdc, timeouts);
577 LPROC_SEQ_FOPS_RO_TYPE(mdc, state);
578 LPROC_SEQ_FOPS_RW_TYPE(mdc, obd_max_pages_per_rpc);
579 LPROC_SEQ_FOPS_RW_TYPE(mdc, import);
580 LPROC_SEQ_FOPS_RW_TYPE(mdc, pinger_recov);
582 struct lprocfs_vars lprocfs_mdc_obd_vars[] = {
583 { .name = "connect_flags",
584 .fops = &mdc_connect_flags_fops },
585 { .name = "mds_server_uuid",
586 .fops = &mdc_server_uuid_fops },
587 { .name = "max_pages_per_rpc",
588 .fops = &mdc_obd_max_pages_per_rpc_fops },
589 { .name = "max_dirty_mb",
590 .fops = &mdc_max_dirty_mb_fops },
591 { .name = "mdc_cached_mb",
592 .fops = &mdc_cached_mb_fops },
593 { .name = "checksum_type",
594 .fops = &mdc_checksum_type_fops },
595 { .name = "timeouts",
596 .fops = &mdc_timeouts_fops },
598 .fops = &mdc_import_fops },
600 .fops = &mdc_state_fops },
601 { .name = "pinger_recov",
602 .fops = &mdc_pinger_recov_fops },
603 { .name = "rpc_stats",
604 .fops = &mdc_rpc_stats_fops },
605 { .name = "unstable_stats",
606 .fops = &mdc_unstable_stats_fops },
607 { .name = "mdc_stats",
608 .fops = &mdc_stats_fops },
609 { .name = "mdc_dom_min_repsize",
610 .fops = &mdc_dom_min_repsize_fops },
614 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
615 struct attribute *attr,
618 struct obd_device *obd = container_of(kobj, struct obd_device,
620 struct client_obd *cli = &obd->u.cli;
622 return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_lost_grant);
624 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
626 static ssize_t cur_dirty_grant_bytes_show(struct kobject *kobj,
627 struct attribute *attr,
630 struct obd_device *obd = container_of(kobj, struct obd_device,
632 struct client_obd *cli = &obd->u.cli;
634 return scnprintf(buf, PAGE_SIZE, "%lu\n", cli->cl_dirty_grant);
636 LUSTRE_RO_ATTR(cur_dirty_grant_bytes);
638 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
641 struct obd_device *obd = container_of(kobj, struct obd_device,
643 struct obd_import *imp;
646 with_imp_locked(obd, imp, len)
647 len = scnprintf(buf, PAGE_SIZE, "%d\n",
648 !imp->imp_grant_shrink_disabled &&
649 OCD_HAS_FLAG(&imp->imp_connect_data,
655 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
656 const char *buffer, size_t count)
658 struct obd_device *obd = container_of(kobj, struct obd_device,
660 struct obd_import *imp;
667 rc = kstrtobool(buffer, &val);
671 with_imp_locked(obd, imp, rc) {
672 spin_lock(&imp->imp_lock);
673 imp->imp_grant_shrink_disabled = !val;
674 spin_unlock(&imp->imp_lock);
679 LUSTRE_RW_ATTR(grant_shrink);
681 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
682 struct attribute *attr,
685 struct obd_device *obd = container_of(kobj, struct obd_device,
688 return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
691 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
692 struct attribute *attr,
696 struct obd_device *obd = container_of(kobj, struct obd_device,
701 rc = kstrtouint(buffer, 0, &val);
708 obd->u.cli.cl_grant_shrink_interval = val;
709 osc_update_next_shrink(&obd->u.cli);
710 osc_schedule_grant_work();
714 LUSTRE_RW_ATTR(grant_shrink_interval);
716 static struct attribute *mdc_attrs[] = {
717 &lustre_attr_active.attr,
718 &lustre_attr_checksums.attr,
719 &lustre_attr_checksum_dump.attr,
720 &lustre_attr_max_rpcs_in_flight.attr,
721 &lustre_attr_max_mod_rpcs_in_flight.attr,
722 &lustre_attr_mds_conn_uuid.attr,
723 &lustre_attr_conn_uuid.attr,
724 &lustre_attr_ping.attr,
725 &lustre_attr_grant_shrink.attr,
726 &lustre_attr_grant_shrink_interval.attr,
727 &lustre_attr_cur_lost_grant_bytes.attr,
728 &lustre_attr_cur_dirty_grant_bytes.attr,
732 int mdc_tunables_init(struct obd_device *obd)
736 obd->obd_ktype.default_attrs = mdc_attrs;
737 obd->obd_vars = lprocfs_mdc_obd_vars;
739 rc = lprocfs_obd_setup(obd, false);
742 #ifdef CONFIG_PROC_FS
743 rc = lprocfs_alloc_md_stats(obd, 0);
745 lprocfs_obd_cleanup(obd);
749 rc = sptlrpc_lprocfs_cliobd_attach(obd);
751 #ifdef CONFIG_PROC_FS
752 lprocfs_free_md_stats(obd);
754 lprocfs_obd_cleanup(obd);
757 ptlrpc_lprocfs_register_obd(obd);