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/version.h>
35 #include <asm/statfs.h>
36 #include <obd_cksum.h>
37 #include <obd_class.h>
38 #include <lprocfs_status.h>
39 #include <linux/seq_file.h>
40 #include <lustre_osc.h>
42 #include "osc_internal.h"
44 static ssize_t active_show(struct kobject *kobj, struct attribute *attr,
47 struct obd_device *dev = container_of(kobj, struct obd_device,
51 LPROCFS_CLIMP_CHECK(dev);
52 rc = sprintf(buf, "%d\n", !dev->u.cli.cl_import->imp_deactive);
53 LPROCFS_CLIMP_EXIT(dev);
57 static ssize_t active_store(struct kobject *kobj, struct attribute *attr,
58 const char *buffer, size_t count)
60 struct obd_device *dev = container_of(kobj, struct obd_device,
65 rc = kstrtobool(buffer, &val);
70 if (dev->u.cli.cl_import->imp_deactive == val)
71 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
73 CDEBUG(D_CONFIG, "activate %u: ignoring repeat request\n",
78 LUSTRE_RW_ATTR(active);
80 static ssize_t max_rpcs_in_flight_show(struct kobject *kobj,
81 struct attribute *attr,
84 struct obd_device *dev = container_of(kobj, struct obd_device,
86 struct client_obd *cli = &dev->u.cli;
89 spin_lock(&cli->cl_loi_list_lock);
90 len = sprintf(buf, "%u\n", cli->cl_max_rpcs_in_flight);
91 spin_unlock(&cli->cl_loi_list_lock);
95 static ssize_t max_rpcs_in_flight_store(struct kobject *kobj,
96 struct attribute *attr,
100 struct obd_device *dev = container_of(kobj, struct obd_device,
102 struct client_obd *cli = &dev->u.cli;
103 int adding, added, req_count;
107 rc = kstrtouint(buffer, 0, &val);
111 if (val == 0 || val > OSC_MAX_RIF_MAX)
114 LPROCFS_CLIMP_CHECK(dev);
116 adding = (int)val - cli->cl_max_rpcs_in_flight;
117 req_count = atomic_read(&osc_pool_req_count);
118 if (adding > 0 && req_count < osc_reqpool_maxreqcount) {
120 * There might be some race which will cause over-limit
121 * allocation, but it is fine.
123 if (req_count + adding > osc_reqpool_maxreqcount)
124 adding = osc_reqpool_maxreqcount - req_count;
126 added = osc_rq_pool->prp_populate(osc_rq_pool, adding);
127 atomic_add(added, &osc_pool_req_count);
130 spin_lock(&cli->cl_loi_list_lock);
131 cli->cl_max_rpcs_in_flight = val;
132 client_adjust_max_dirty(cli);
133 spin_unlock(&cli->cl_loi_list_lock);
135 LPROCFS_CLIMP_EXIT(dev);
138 LUSTRE_RW_ATTR(max_rpcs_in_flight);
140 static ssize_t max_dirty_mb_show(struct kobject *kobj,
141 struct attribute *attr,
144 struct obd_device *dev = container_of(kobj, struct obd_device,
146 struct client_obd *cli = &dev->u.cli;
150 spin_lock(&cli->cl_loi_list_lock);
151 val = cli->cl_dirty_max_pages;
152 spin_unlock(&cli->cl_loi_list_lock);
154 mult = 1 << (20 - PAGE_SHIFT);
155 return lprocfs_read_frac_helper(buf, PAGE_SIZE, val, mult);
158 static ssize_t max_dirty_mb_store(struct kobject *kobj,
159 struct attribute *attr,
163 struct obd_device *dev = container_of(kobj, struct obd_device,
165 struct client_obd *cli = &dev->u.cli;
166 unsigned long pages_number;
169 rc = kstrtoul(buffer, 10, &pages_number);
173 pages_number *= 1 << (20 - PAGE_SHIFT); /* MB -> pages */
175 if (pages_number <= 0 ||
176 pages_number >= OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_SHIFT) ||
177 pages_number > totalram_pages / 4) /* 1/4 of RAM */
180 spin_lock(&cli->cl_loi_list_lock);
181 cli->cl_dirty_max_pages = pages_number;
182 osc_wake_cache_waiters(cli);
183 spin_unlock(&cli->cl_loi_list_lock);
187 LUSTRE_RW_ATTR(max_dirty_mb);
189 LUSTRE_RO_ATTR(conn_uuid);
191 LUSTRE_WO_ATTR(ping);
193 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
195 struct obd_device *dev = m->private;
196 struct client_obd *cli = &dev->u.cli;
197 int shift = 20 - PAGE_SHIFT;
199 seq_printf(m, "used_mb: %ld\n"
202 (atomic_long_read(&cli->cl_lru_in_list) +
203 atomic_long_read(&cli->cl_lru_busy)) >> shift,
204 atomic_long_read(&cli->cl_lru_busy),
205 cli->cl_lru_reclaim);
210 /* shrink the number of caching pages to a specific number */
211 static ssize_t osc_cached_mb_seq_write(struct file *file,
212 const char __user *buffer,
213 size_t count, loff_t *off)
215 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
216 struct client_obd *cli = &dev->u.cli;
221 if (count >= sizeof(kernbuf))
224 if (copy_from_user(kernbuf, buffer, count))
228 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
230 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
234 pages_number >>= PAGE_SHIFT;
236 if (pages_number < 0)
239 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
244 env = cl_env_get(&refcheck);
246 (void)osc_lru_shrink(env, cli, rc, true);
247 cl_env_put(env, &refcheck);
254 LPROC_SEQ_FOPS(osc_cached_mb);
256 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
257 struct attribute *attr,
260 struct obd_device *dev = container_of(kobj, struct obd_device,
262 struct client_obd *cli = &dev->u.cli;
265 spin_lock(&cli->cl_loi_list_lock);
266 len = sprintf(buf, "%lu\n", cli->cl_dirty_pages << PAGE_SHIFT);
267 spin_unlock(&cli->cl_loi_list_lock);
271 LUSTRE_RO_ATTR(cur_dirty_bytes);
273 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
275 struct obd_device *dev = m->private;
276 struct client_obd *cli = &dev->u.cli;
278 spin_lock(&cli->cl_loi_list_lock);
279 seq_printf(m, "%lu\n", cli->cl_avail_grant);
280 spin_unlock(&cli->cl_loi_list_lock);
284 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
285 const char __user *buffer,
286 size_t count, loff_t *off)
288 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
289 struct client_obd *cli = &obd->u.cli;
296 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
302 /* this is only for shrinking grant */
303 spin_lock(&cli->cl_loi_list_lock);
304 if (val >= cli->cl_avail_grant) {
305 spin_unlock(&cli->cl_loi_list_lock);
309 spin_unlock(&cli->cl_loi_list_lock);
311 LPROCFS_CLIMP_CHECK(obd);
312 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
313 rc = osc_shrink_grant_to_target(cli, val);
314 LPROCFS_CLIMP_EXIT(obd);
316 return rc ? rc : count;
318 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
320 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
321 struct attribute *attr,
324 struct obd_device *dev = container_of(kobj, struct obd_device,
326 struct client_obd *cli = &dev->u.cli;
329 spin_lock(&cli->cl_loi_list_lock);
330 len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
331 spin_unlock(&cli->cl_loi_list_lock);
334 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
336 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
337 struct attribute *attr,
340 struct obd_device *obd = container_of(kobj, struct obd_device,
343 return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
346 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
347 struct attribute *attr,
351 struct obd_device *obd = container_of(kobj, struct obd_device,
356 rc = kstrtouint(buffer, 0, &val);
363 obd->u.cli.cl_grant_shrink_interval = val;
367 LUSTRE_RW_ATTR(grant_shrink_interval);
369 static ssize_t checksums_show(struct kobject *kobj,
370 struct attribute *attr,
373 struct obd_device *obd = container_of(kobj, struct obd_device,
376 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
379 static ssize_t checksums_store(struct kobject *kobj,
380 struct attribute *attr,
384 struct obd_device *obd = container_of(kobj, struct obd_device,
389 rc = kstrtobool(buffer, &val);
393 obd->u.cli.cl_checksum = val;
397 LUSTRE_RW_ATTR(checksums);
399 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
401 struct obd_device *obd = m->private;
408 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
409 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
411 if (obd->u.cli.cl_cksum_type == (1 << i))
412 seq_printf(m, "[%s] ", cksum_name[i]);
414 seq_printf(m, "%s ", cksum_name[i]);
420 static ssize_t osc_checksum_type_seq_write(struct file *file,
421 const char __user *buffer,
422 size_t count, loff_t *off)
424 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
432 if (count > sizeof(kernbuf) - 1)
434 if (copy_from_user(kernbuf, buffer, count))
436 if (count > 0 && kernbuf[count - 1] == '\n')
437 kernbuf[count - 1] = '\0';
439 kernbuf[count] = '\0';
441 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
442 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
444 if (!strcmp(kernbuf, cksum_name[i])) {
445 obd->u.cli.cl_cksum_type = 1 << i;
451 LPROC_SEQ_FOPS(osc_checksum_type);
453 static ssize_t resend_count_show(struct kobject *kobj,
454 struct attribute *attr,
457 struct obd_device *obd = container_of(kobj, struct obd_device,
460 return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
463 static ssize_t resend_count_store(struct kobject *kobj,
464 struct attribute *attr,
468 struct obd_device *obd = container_of(kobj, struct obd_device,
473 rc = kstrtouint(buffer, 10, &val);
477 atomic_set(&obd->u.cli.cl_resends, val);
481 LUSTRE_RW_ATTR(resend_count);
483 static ssize_t checksum_dump_show(struct kobject *kobj,
484 struct attribute *attr,
487 struct obd_device *obd = container_of(kobj, struct obd_device,
490 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum_dump ? 1 : 0);
493 static ssize_t checksum_dump_store(struct kobject *kobj,
494 struct attribute *attr,
498 struct obd_device *obd = container_of(kobj, struct obd_device,
503 rc = kstrtobool(buffer, &val);
507 obd->u.cli.cl_checksum_dump = val;
511 LUSTRE_RW_ATTR(checksum_dump);
513 static ssize_t contention_seconds_show(struct kobject *kobj,
514 struct attribute *attr,
517 struct obd_device *obd = container_of(kobj, struct obd_device,
519 struct osc_device *od = obd2osc_dev(obd);
521 return sprintf(buf, "%lld\n", od->od_contention_time);
524 static ssize_t contention_seconds_store(struct kobject *kobj,
525 struct attribute *attr,
529 struct obd_device *obd = container_of(kobj, struct obd_device,
531 struct osc_device *od = obd2osc_dev(obd);
535 rc = kstrtouint(buffer, 0, &val);
539 od->od_contention_time = val;
543 LUSTRE_RW_ATTR(contention_seconds);
545 static ssize_t lockless_truncate_show(struct kobject *kobj,
546 struct attribute *attr,
549 struct obd_device *obd = container_of(kobj, struct obd_device,
551 struct osc_device *od = obd2osc_dev(obd);
553 return sprintf(buf, "%u\n", od->od_lockless_truncate);
556 static ssize_t lockless_truncate_store(struct kobject *kobj,
557 struct attribute *attr,
561 struct obd_device *obd = container_of(kobj, struct obd_device,
563 struct osc_device *od = obd2osc_dev(obd);
567 rc = kstrtobool(buffer, &val);
571 od->od_lockless_truncate = val;
575 LUSTRE_RW_ATTR(lockless_truncate);
577 static ssize_t destroys_in_flight_show(struct kobject *kobj,
578 struct attribute *attr,
581 struct obd_device *obd = container_of(kobj, struct obd_device,
584 return sprintf(buf, "%u\n",
585 atomic_read(&obd->u.cli.cl_destroy_in_flight));
587 LUSTRE_RO_ATTR(destroys_in_flight);
589 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
591 LUSTRE_RW_ATTR(short_io_bytes);
593 #ifdef CONFIG_PROC_FS
594 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
596 struct obd_device *dev = m->private;
597 struct client_obd *cli = &dev->u.cli;
601 pages = atomic_long_read(&cli->cl_unstable_count);
602 mb = (pages * PAGE_SIZE) >> 20;
604 seq_printf(m, "unstable_pages: %20ld\n"
605 "unstable_mb: %10d\n",
609 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
611 static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr,
614 struct obd_device *obd = container_of(kobj, struct obd_device,
616 struct client_obd *cli = &obd->u.cli;
619 LPROCFS_CLIMP_CHECK(obd);
620 ret = sprintf(buf, "%u\n", cli->cl_import->imp_idle_timeout);
621 LPROCFS_CLIMP_EXIT(obd);
626 static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr,
627 const char *buffer, size_t count)
629 struct obd_device *dev = container_of(kobj, struct obd_device,
631 struct client_obd *cli = &dev->u.cli;
632 struct ptlrpc_request *req;
636 rc = kstrtouint(buffer, 10, &val);
640 if (val > CONNECTION_SWITCH_MAX)
643 LPROCFS_CLIMP_CHECK(dev);
644 cli->cl_import->imp_idle_timeout = val;
646 /* to initiate the connection if it's in IDLE state */
648 req = ptlrpc_request_alloc(cli->cl_import, &RQF_OST_STATFS);
650 ptlrpc_req_finished(req);
652 LPROCFS_CLIMP_EXIT(dev);
656 LUSTRE_RW_ATTR(idle_timeout);
658 static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr,
659 const char *buffer, size_t count)
661 struct obd_device *dev = container_of(kobj, struct obd_device,
663 struct client_obd *cli = &dev->u.cli;
664 struct ptlrpc_request *req;
666 LPROCFS_CLIMP_CHECK(dev);
667 /* to initiate the connection if it's in IDLE state */
668 req = ptlrpc_request_alloc(cli->cl_import, &RQF_OST_STATFS);
670 ptlrpc_req_finished(req);
671 ptlrpc_pinger_force(cli->cl_import);
672 LPROCFS_CLIMP_EXIT(dev);
676 LUSTRE_WO_ATTR(idle_connect);
678 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
681 struct obd_device *obd = container_of(kobj, struct obd_device,
683 struct client_obd *cli = &obd->u.cli;
684 struct obd_connect_data *ocd;
687 LPROCFS_CLIMP_CHECK(obd);
688 ocd = &cli->cl_import->imp_connect_data;
690 len = snprintf(buf, PAGE_SIZE, "%d\n",
691 !!OCD_HAS_FLAG(ocd, GRANT_SHRINK));
692 LPROCFS_CLIMP_EXIT(obd);
697 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
698 const char *buffer, size_t count)
700 struct obd_device *dev = container_of(kobj, struct obd_device,
702 struct client_obd *cli = &dev->u.cli;
703 struct obd_connect_data *ocd;
710 rc = kstrtobool(buffer, &val);
714 LPROCFS_CLIMP_CHECK(dev);
715 ocd = &cli->cl_import->imp_connect_data;
718 if (OCD_HAS_FLAG(ocd, GRANT_SHRINK))
719 ocd->ocd_connect_flags &= ~OBD_CONNECT_GRANT_SHRINK;
722 * server replied obd_connect_data is always bigger, so
723 * client's imp_connect_flags_orig are always supported
726 if (!OCD_HAS_FLAG(ocd, GRANT_SHRINK) &&
727 cli->cl_import->imp_connect_flags_orig &
728 OBD_CONNECT_GRANT_SHRINK)
729 ocd->ocd_connect_flags |= OBD_CONNECT_GRANT_SHRINK;
732 LPROCFS_CLIMP_EXIT(dev);
736 LUSTRE_RW_ATTR(grant_shrink);
738 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
739 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
740 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
741 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
743 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
744 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
746 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
747 { .name = "connect_flags",
748 .fops = &osc_connect_flags_fops },
749 { .name = "ost_server_uuid",
750 .fops = &osc_server_uuid_fops },
751 { .name = "max_pages_per_rpc",
752 .fops = &osc_obd_max_pages_per_rpc_fops },
753 { .name = "osc_cached_mb",
754 .fops = &osc_cached_mb_fops },
755 { .name = "cur_grant_bytes",
756 .fops = &osc_cur_grant_bytes_fops },
757 { .name = "checksum_type",
758 .fops = &osc_checksum_type_fops },
759 { .name = "timeouts",
760 .fops = &osc_timeouts_fops },
762 .fops = &osc_import_fops },
764 .fops = &osc_state_fops },
765 { .name = "pinger_recov",
766 .fops = &osc_pinger_recov_fops },
767 { .name = "unstable_stats",
768 .fops = &osc_unstable_stats_fops },
772 #define pct(a,b) (b ? a * 100 / b : 0)
774 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
776 struct timespec64 now;
777 struct obd_device *dev = seq->private;
778 struct client_obd *cli = &dev->u.cli;
779 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
782 ktime_get_real_ts64(&now);
784 spin_lock(&cli->cl_loi_list_lock);
786 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
787 (s64)now.tv_sec, now.tv_nsec);
788 seq_printf(seq, "read RPCs in flight: %d\n",
789 cli->cl_r_in_flight);
790 seq_printf(seq, "write RPCs in flight: %d\n",
791 cli->cl_w_in_flight);
792 seq_printf(seq, "pending write pages: %d\n",
793 atomic_read(&cli->cl_pending_w_pages));
794 seq_printf(seq, "pending read pages: %d\n",
795 atomic_read(&cli->cl_pending_r_pages));
797 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
798 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
799 seq_printf(seq, " rpcs %% cum %%\n");
801 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
802 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
806 for (i = 0; i < OBD_HIST_MAX; i++) {
807 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
808 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
812 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
813 1 << i, r, pct(r, read_tot),
814 pct(read_cum, read_tot), w,
816 pct(write_cum, write_tot));
817 if (read_cum == read_tot && write_cum == write_tot)
821 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
822 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
823 seq_printf(seq, " rpcs %% cum %%\n");
825 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
826 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
830 for (i = 0; i < OBD_HIST_MAX; i++) {
831 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
832 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
835 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
836 i, r, pct(r, read_tot),
837 pct(read_cum, read_tot), w,
839 pct(write_cum, write_tot));
840 if (read_cum == read_tot && write_cum == write_tot)
844 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
845 seq_printf(seq, "offset rpcs %% cum %% |");
846 seq_printf(seq, " rpcs %% cum %%\n");
848 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
849 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
853 for (i = 0; i < OBD_HIST_MAX; i++) {
854 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
855 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
858 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
859 (i == 0) ? 0 : 1 << (i - 1),
860 r, pct(r, read_tot), pct(read_cum, read_tot),
861 w, pct(w, write_tot), pct(write_cum, write_tot));
862 if (read_cum == read_tot && write_cum == write_tot)
866 spin_unlock(&cli->cl_loi_list_lock);
872 static ssize_t osc_rpc_stats_seq_write(struct file *file,
873 const char __user *buf,
874 size_t len, loff_t *off)
876 struct seq_file *seq = file->private_data;
877 struct obd_device *dev = seq->private;
878 struct client_obd *cli = &dev->u.cli;
880 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
881 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
882 lprocfs_oh_clear(&cli->cl_read_page_hist);
883 lprocfs_oh_clear(&cli->cl_write_page_hist);
884 lprocfs_oh_clear(&cli->cl_read_offset_hist);
885 lprocfs_oh_clear(&cli->cl_write_offset_hist);
889 LPROC_SEQ_FOPS(osc_rpc_stats);
891 static int osc_stats_seq_show(struct seq_file *seq, void *v)
893 struct timespec64 now;
894 struct obd_device *dev = seq->private;
895 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
897 ktime_get_real_ts64(&now);
899 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
900 (s64)now.tv_sec, now.tv_nsec);
901 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
902 stats->os_lockless_writes);
903 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
904 stats->os_lockless_reads);
905 seq_printf(seq, "lockless_truncate\t\t%llu\n",
906 stats->os_lockless_truncates);
910 static ssize_t osc_stats_seq_write(struct file *file,
911 const char __user *buf,
912 size_t len, loff_t *off)
914 struct seq_file *seq = file->private_data;
915 struct obd_device *dev = seq->private;
916 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
918 memset(stats, 0, sizeof(*stats));
922 LPROC_SEQ_FOPS(osc_stats);
924 int lprocfs_osc_attach_seqstat(struct obd_device *dev)
928 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
929 &osc_stats_fops, dev);
931 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
932 &osc_rpc_stats_fops, dev);
936 #endif /* CONFIG_PROC_FS */
938 static struct attribute *osc_attrs[] = {
939 &lustre_attr_active.attr,
940 &lustre_attr_checksums.attr,
941 &lustre_attr_checksum_dump.attr,
942 &lustre_attr_contention_seconds.attr,
943 &lustre_attr_cur_dirty_bytes.attr,
944 &lustre_attr_cur_lost_grant_bytes.attr,
945 &lustre_attr_destroys_in_flight.attr,
946 &lustre_attr_grant_shrink_interval.attr,
947 &lustre_attr_lockless_truncate.attr,
948 &lustre_attr_max_dirty_mb.attr,
949 &lustre_attr_max_rpcs_in_flight.attr,
950 &lustre_attr_short_io_bytes.attr,
951 &lustre_attr_resend_count.attr,
952 &lustre_attr_conn_uuid.attr,
953 &lustre_attr_ping.attr,
954 &lustre_attr_idle_timeout.attr,
955 &lustre_attr_idle_connect.attr,
956 &lustre_attr_grant_shrink.attr,
960 int osc_tunables_init(struct obd_device *obd)
962 #if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
963 struct obd_type *type;
967 obd->obd_vars = lprocfs_osc_obd_vars;
968 #if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
969 /* If this is true then both client (osc) and server (osp) are on the
970 * same node. The osp layer if loaded first will register the osc proc
971 * directory. In that case this obd_device will be attached its proc
972 * tree to type->typ_procsym instead of obd->obd_type->typ_procroot.
974 type = class_search_type(LUSTRE_OSP_NAME);
975 if (type && type->typ_procsym) {
976 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
979 if (IS_ERR(obd->obd_proc_entry)) {
980 rc = PTR_ERR(obd->obd_proc_entry);
981 CERROR("error %d setting up lprocfs for %s\n", rc,
983 obd->obd_proc_entry = NULL;
987 obd->obd_ktype.default_attrs = osc_attrs;
988 rc = lprocfs_obd_setup(obd, false);
991 #ifdef CONFIG_PROC_FS
992 /* If the basic OSC proc tree construction succeeded then
995 rc = lprocfs_osc_attach_seqstat(obd);
999 #endif /* CONFIG_PROC_FS */
1000 rc = sptlrpc_lprocfs_cliobd_attach(obd);
1004 ptlrpc_lprocfs_register_obd(obd);
1007 lprocfs_obd_cleanup(obd);