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;
149 spin_lock(&cli->cl_loi_list_lock);
150 val = PAGES_TO_MiB(cli->cl_dirty_max_pages);
151 spin_unlock(&cli->cl_loi_list_lock);
153 return sprintf(buf, "%lu\n", val);
156 static ssize_t max_dirty_mb_store(struct kobject *kobj,
157 struct attribute *attr,
161 struct obd_device *dev = container_of(kobj, struct obd_device,
163 struct client_obd *cli = &dev->u.cli;
164 unsigned long pages_number, max_dirty_mb;
167 rc = kstrtoul(buffer, 10, &max_dirty_mb);
171 pages_number = MiB_TO_PAGES(max_dirty_mb);
173 if (pages_number >= MiB_TO_PAGES(OSC_MAX_DIRTY_MB_MAX) ||
174 pages_number > totalram_pages / 4) /* 1/4 of RAM */
177 spin_lock(&cli->cl_loi_list_lock);
178 cli->cl_dirty_max_pages = pages_number;
179 osc_wake_cache_waiters(cli);
180 spin_unlock(&cli->cl_loi_list_lock);
184 LUSTRE_RW_ATTR(max_dirty_mb);
186 LUSTRE_ATTR(ost_conn_uuid, 0444, conn_uuid_show, NULL);
187 LUSTRE_RO_ATTR(conn_uuid);
189 LUSTRE_RW_ATTR(ping);
191 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
193 struct obd_device *dev = m->private;
194 struct client_obd *cli = &dev->u.cli;
195 int shift = 20 - PAGE_SHIFT;
197 seq_printf(m, "used_mb: %ld\n"
200 (atomic_long_read(&cli->cl_lru_in_list) +
201 atomic_long_read(&cli->cl_lru_busy)) >> shift,
202 atomic_long_read(&cli->cl_lru_busy),
203 cli->cl_lru_reclaim);
208 /* shrink the number of caching pages to a specific number */
209 static ssize_t osc_cached_mb_seq_write(struct file *file,
210 const char __user *buffer,
211 size_t count, loff_t *off)
213 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
214 struct client_obd *cli = &dev->u.cli;
219 if (count >= sizeof(kernbuf))
222 if (copy_from_user(kernbuf, buffer, count))
226 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
228 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
232 pages_number >>= PAGE_SHIFT;
234 if (pages_number < 0)
237 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
242 env = cl_env_get(&refcheck);
244 (void)osc_lru_shrink(env, cli, rc, true);
245 cl_env_put(env, &refcheck);
252 LPROC_SEQ_FOPS(osc_cached_mb);
254 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
255 struct attribute *attr,
258 struct obd_device *dev = container_of(kobj, struct obd_device,
260 struct client_obd *cli = &dev->u.cli;
263 spin_lock(&cli->cl_loi_list_lock);
264 len = sprintf(buf, "%lu\n", cli->cl_dirty_pages << PAGE_SHIFT);
265 spin_unlock(&cli->cl_loi_list_lock);
269 LUSTRE_RO_ATTR(cur_dirty_bytes);
271 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
273 struct obd_device *dev = m->private;
274 struct client_obd *cli = &dev->u.cli;
276 spin_lock(&cli->cl_loi_list_lock);
277 seq_printf(m, "%lu\n", cli->cl_avail_grant);
278 spin_unlock(&cli->cl_loi_list_lock);
282 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
283 const char __user *buffer,
284 size_t count, loff_t *off)
286 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
287 struct client_obd *cli = &obd->u.cli;
294 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
300 /* this is only for shrinking grant */
301 spin_lock(&cli->cl_loi_list_lock);
302 if (val >= cli->cl_avail_grant) {
303 spin_unlock(&cli->cl_loi_list_lock);
307 spin_unlock(&cli->cl_loi_list_lock);
309 LPROCFS_CLIMP_CHECK(obd);
310 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
311 rc = osc_shrink_grant_to_target(cli, val);
312 LPROCFS_CLIMP_EXIT(obd);
314 return rc ? rc : count;
316 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
318 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
319 struct attribute *attr,
322 struct obd_device *dev = container_of(kobj, struct obd_device,
324 struct client_obd *cli = &dev->u.cli;
327 spin_lock(&cli->cl_loi_list_lock);
328 len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
329 spin_unlock(&cli->cl_loi_list_lock);
332 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
334 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
335 struct attribute *attr,
338 struct obd_device *obd = container_of(kobj, struct obd_device,
341 return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
344 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
345 struct attribute *attr,
349 struct obd_device *obd = container_of(kobj, struct obd_device,
354 rc = kstrtouint(buffer, 0, &val);
361 obd->u.cli.cl_grant_shrink_interval = val;
365 LUSTRE_RW_ATTR(grant_shrink_interval);
367 static ssize_t checksums_show(struct kobject *kobj,
368 struct attribute *attr,
371 struct obd_device *obd = container_of(kobj, struct obd_device,
374 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
377 static ssize_t checksums_store(struct kobject *kobj,
378 struct attribute *attr,
382 struct obd_device *obd = container_of(kobj, struct obd_device,
387 rc = kstrtobool(buffer, &val);
391 obd->u.cli.cl_checksum = val;
395 LUSTRE_RW_ATTR(checksums);
397 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
399 struct obd_device *obd = m->private;
406 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
407 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
409 if (obd->u.cli.cl_cksum_type == (1 << i))
410 seq_printf(m, "[%s] ", cksum_name[i]);
412 seq_printf(m, "%s ", cksum_name[i]);
418 static ssize_t osc_checksum_type_seq_write(struct file *file,
419 const char __user *buffer,
420 size_t count, loff_t *off)
422 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
430 if (count > sizeof(kernbuf) - 1)
432 if (copy_from_user(kernbuf, buffer, count))
434 if (count > 0 && kernbuf[count - 1] == '\n')
435 kernbuf[count - 1] = '\0';
437 kernbuf[count] = '\0';
439 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
440 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
442 if (!strcmp(kernbuf, cksum_name[i])) {
443 obd->u.cli.cl_cksum_type = 1 << i;
449 LPROC_SEQ_FOPS(osc_checksum_type);
451 static ssize_t resend_count_show(struct kobject *kobj,
452 struct attribute *attr,
455 struct obd_device *obd = container_of(kobj, struct obd_device,
458 return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
461 static ssize_t resend_count_store(struct kobject *kobj,
462 struct attribute *attr,
466 struct obd_device *obd = container_of(kobj, struct obd_device,
471 rc = kstrtouint(buffer, 10, &val);
475 atomic_set(&obd->u.cli.cl_resends, val);
479 LUSTRE_RW_ATTR(resend_count);
481 static ssize_t checksum_dump_show(struct kobject *kobj,
482 struct attribute *attr,
485 struct obd_device *obd = container_of(kobj, struct obd_device,
488 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum_dump ? 1 : 0);
491 static ssize_t checksum_dump_store(struct kobject *kobj,
492 struct attribute *attr,
496 struct obd_device *obd = container_of(kobj, struct obd_device,
501 rc = kstrtobool(buffer, &val);
505 obd->u.cli.cl_checksum_dump = val;
509 LUSTRE_RW_ATTR(checksum_dump);
511 static ssize_t contention_seconds_show(struct kobject *kobj,
512 struct attribute *attr,
515 struct obd_device *obd = container_of(kobj, struct obd_device,
517 struct osc_device *od = obd2osc_dev(obd);
519 return sprintf(buf, "%lld\n", od->od_contention_time);
522 static ssize_t contention_seconds_store(struct kobject *kobj,
523 struct attribute *attr,
527 struct obd_device *obd = container_of(kobj, struct obd_device,
529 struct osc_device *od = obd2osc_dev(obd);
533 rc = kstrtouint(buffer, 0, &val);
537 od->od_contention_time = val;
541 LUSTRE_RW_ATTR(contention_seconds);
543 static ssize_t lockless_truncate_show(struct kobject *kobj,
544 struct attribute *attr,
547 struct obd_device *obd = container_of(kobj, struct obd_device,
549 struct osc_device *od = obd2osc_dev(obd);
551 return sprintf(buf, "%u\n", od->od_lockless_truncate);
554 static ssize_t lockless_truncate_store(struct kobject *kobj,
555 struct attribute *attr,
559 struct obd_device *obd = container_of(kobj, struct obd_device,
561 struct osc_device *od = obd2osc_dev(obd);
565 rc = kstrtobool(buffer, &val);
569 od->od_lockless_truncate = val;
573 LUSTRE_RW_ATTR(lockless_truncate);
575 static ssize_t destroys_in_flight_show(struct kobject *kobj,
576 struct attribute *attr,
579 struct obd_device *obd = container_of(kobj, struct obd_device,
582 return sprintf(buf, "%u\n",
583 atomic_read(&obd->u.cli.cl_destroy_in_flight));
585 LUSTRE_RO_ATTR(destroys_in_flight);
587 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
589 LUSTRE_RW_ATTR(short_io_bytes);
591 #ifdef CONFIG_PROC_FS
592 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
594 struct obd_device *dev = m->private;
595 struct client_obd *cli = &dev->u.cli;
599 pages = atomic_long_read(&cli->cl_unstable_count);
600 mb = (pages * PAGE_SIZE) >> 20;
602 seq_printf(m, "unstable_pages: %20ld\n"
603 "unstable_mb: %10d\n",
607 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
609 static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr,
612 struct obd_device *obd = container_of(kobj, struct obd_device,
614 struct client_obd *cli = &obd->u.cli;
617 LPROCFS_CLIMP_CHECK(obd);
618 ret = sprintf(buf, "%u\n", cli->cl_import->imp_idle_timeout);
619 LPROCFS_CLIMP_EXIT(obd);
624 static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr,
625 const char *buffer, size_t count)
627 struct obd_device *dev = container_of(kobj, struct obd_device,
629 struct client_obd *cli = &dev->u.cli;
630 struct ptlrpc_request *req;
631 unsigned int idle_debug = 0;
635 if (strncmp(buffer, "debug", 5) == 0) {
636 idle_debug = D_CONSOLE;
637 } else if (strncmp(buffer, "nodebug", 6) == 0) {
640 rc = kstrtouint(buffer, 10, &val);
644 if (val > CONNECTION_SWITCH_MAX)
648 LPROCFS_CLIMP_CHECK(dev);
650 cli->cl_import->imp_idle_debug = idle_debug;
653 /* initiate the connection if it's in IDLE state */
654 req = ptlrpc_request_alloc(cli->cl_import,
657 ptlrpc_req_finished(req);
659 cli->cl_import->imp_idle_timeout = val;
661 LPROCFS_CLIMP_EXIT(dev);
665 LUSTRE_RW_ATTR(idle_timeout);
667 static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr,
668 const char *buffer, size_t count)
670 struct obd_device *dev = container_of(kobj, struct obd_device,
672 struct client_obd *cli = &dev->u.cli;
673 struct ptlrpc_request *req;
675 LPROCFS_CLIMP_CHECK(dev);
676 /* to initiate the connection if it's in IDLE state */
677 req = ptlrpc_request_alloc(cli->cl_import, &RQF_OST_STATFS);
679 ptlrpc_req_finished(req);
680 ptlrpc_pinger_force(cli->cl_import);
681 LPROCFS_CLIMP_EXIT(dev);
685 LUSTRE_WO_ATTR(idle_connect);
687 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
690 struct obd_device *obd = container_of(kobj, struct obd_device,
692 struct obd_import *imp;
695 LPROCFS_CLIMP_CHECK(obd);
696 imp = obd->u.cli.cl_import;
697 len = snprintf(buf, PAGE_SIZE, "%d\n",
698 !imp->imp_grant_shrink_disabled &&
699 OCD_HAS_FLAG(&imp->imp_connect_data, GRANT_SHRINK));
700 LPROCFS_CLIMP_EXIT(obd);
705 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
706 const char *buffer, size_t count)
708 struct obd_device *dev = container_of(kobj, struct obd_device,
710 struct obd_import *imp;
717 rc = kstrtobool(buffer, &val);
721 LPROCFS_CLIMP_CHECK(dev);
723 imp = dev->u.cli.cl_import;
724 spin_lock(&imp->imp_lock);
725 imp->imp_grant_shrink_disabled = !val;
726 spin_unlock(&imp->imp_lock);
728 LPROCFS_CLIMP_EXIT(dev);
732 LUSTRE_RW_ATTR(grant_shrink);
734 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
735 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
736 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
737 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
739 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
740 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
742 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
743 { .name = "connect_flags",
744 .fops = &osc_connect_flags_fops },
745 { .name = "ost_server_uuid",
746 .fops = &osc_server_uuid_fops },
747 { .name = "max_pages_per_rpc",
748 .fops = &osc_obd_max_pages_per_rpc_fops },
749 { .name = "osc_cached_mb",
750 .fops = &osc_cached_mb_fops },
751 { .name = "cur_grant_bytes",
752 .fops = &osc_cur_grant_bytes_fops },
753 { .name = "checksum_type",
754 .fops = &osc_checksum_type_fops },
755 { .name = "timeouts",
756 .fops = &osc_timeouts_fops },
758 .fops = &osc_import_fops },
760 .fops = &osc_state_fops },
761 { .name = "pinger_recov",
762 .fops = &osc_pinger_recov_fops },
763 { .name = "unstable_stats",
764 .fops = &osc_unstable_stats_fops },
768 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
770 struct timespec64 now;
771 struct obd_device *dev = seq->private;
772 struct client_obd *cli = &dev->u.cli;
773 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
776 ktime_get_real_ts64(&now);
778 spin_lock(&cli->cl_loi_list_lock);
780 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
781 (s64)now.tv_sec, now.tv_nsec);
782 seq_printf(seq, "read RPCs in flight: %d\n",
783 cli->cl_r_in_flight);
784 seq_printf(seq, "write RPCs in flight: %d\n",
785 cli->cl_w_in_flight);
786 seq_printf(seq, "pending write pages: %d\n",
787 atomic_read(&cli->cl_pending_w_pages));
788 seq_printf(seq, "pending read pages: %d\n",
789 atomic_read(&cli->cl_pending_r_pages));
791 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
792 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
793 seq_printf(seq, " rpcs %% cum %%\n");
795 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
796 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
800 for (i = 0; i < OBD_HIST_MAX; i++) {
801 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
802 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
806 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
807 1 << i, r, pct(r, read_tot),
808 pct(read_cum, read_tot), w,
810 pct(write_cum, write_tot));
811 if (read_cum == read_tot && write_cum == write_tot)
815 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
816 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
817 seq_printf(seq, " rpcs %% cum %%\n");
819 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
820 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
824 for (i = 0; i < OBD_HIST_MAX; i++) {
825 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
826 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
829 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
830 i, r, pct(r, read_tot),
831 pct(read_cum, read_tot), w,
833 pct(write_cum, write_tot));
834 if (read_cum == read_tot && write_cum == write_tot)
838 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
839 seq_printf(seq, "offset rpcs %% cum %% |");
840 seq_printf(seq, " rpcs %% cum %%\n");
842 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
843 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
847 for (i = 0; i < OBD_HIST_MAX; i++) {
848 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
849 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
852 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
853 (i == 0) ? 0 : 1 << (i - 1),
854 r, pct(r, read_tot), pct(read_cum, read_tot),
855 w, pct(w, write_tot), pct(write_cum, write_tot));
856 if (read_cum == read_tot && write_cum == write_tot)
860 spin_unlock(&cli->cl_loi_list_lock);
865 static ssize_t osc_rpc_stats_seq_write(struct file *file,
866 const char __user *buf,
867 size_t len, loff_t *off)
869 struct seq_file *seq = file->private_data;
870 struct obd_device *dev = seq->private;
871 struct client_obd *cli = &dev->u.cli;
873 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
874 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
875 lprocfs_oh_clear(&cli->cl_read_page_hist);
876 lprocfs_oh_clear(&cli->cl_write_page_hist);
877 lprocfs_oh_clear(&cli->cl_read_offset_hist);
878 lprocfs_oh_clear(&cli->cl_write_offset_hist);
882 LPROC_SEQ_FOPS(osc_rpc_stats);
884 static int osc_stats_seq_show(struct seq_file *seq, void *v)
886 struct timespec64 now;
887 struct obd_device *dev = seq->private;
888 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
890 ktime_get_real_ts64(&now);
892 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
893 (s64)now.tv_sec, now.tv_nsec);
894 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
895 stats->os_lockless_writes);
896 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
897 stats->os_lockless_reads);
898 seq_printf(seq, "lockless_truncate\t\t%llu\n",
899 stats->os_lockless_truncates);
903 static ssize_t osc_stats_seq_write(struct file *file,
904 const char __user *buf,
905 size_t len, loff_t *off)
907 struct seq_file *seq = file->private_data;
908 struct obd_device *dev = seq->private;
909 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
911 memset(stats, 0, sizeof(*stats));
915 LPROC_SEQ_FOPS(osc_stats);
917 int lprocfs_osc_attach_seqstat(struct obd_device *dev)
921 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
922 &osc_stats_fops, dev);
924 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
925 &osc_rpc_stats_fops, dev);
929 #endif /* CONFIG_PROC_FS */
931 static struct attribute *osc_attrs[] = {
932 &lustre_attr_active.attr,
933 &lustre_attr_checksums.attr,
934 &lustre_attr_checksum_dump.attr,
935 &lustre_attr_contention_seconds.attr,
936 &lustre_attr_cur_dirty_bytes.attr,
937 &lustre_attr_cur_lost_grant_bytes.attr,
938 &lustre_attr_destroys_in_flight.attr,
939 &lustre_attr_grant_shrink_interval.attr,
940 &lustre_attr_lockless_truncate.attr,
941 &lustre_attr_max_dirty_mb.attr,
942 &lustre_attr_max_rpcs_in_flight.attr,
943 &lustre_attr_short_io_bytes.attr,
944 &lustre_attr_resend_count.attr,
945 &lustre_attr_ost_conn_uuid.attr,
946 &lustre_attr_conn_uuid.attr,
947 &lustre_attr_ping.attr,
948 &lustre_attr_idle_timeout.attr,
949 &lustre_attr_idle_connect.attr,
950 &lustre_attr_grant_shrink.attr,
954 int osc_tunables_init(struct obd_device *obd)
956 #if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
957 struct obd_type *type;
961 obd->obd_vars = lprocfs_osc_obd_vars;
962 #if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
963 /* If this is true then both client (osc) and server (osp) are on the
964 * same node. The osp layer if loaded first will register the osc proc
965 * directory. In that case this obd_device will be attached its proc
966 * tree to type->typ_procsym instead of obd->obd_type->typ_procroot.
968 type = class_search_type(LUSTRE_OSP_NAME);
969 if (type && type->typ_procsym) {
970 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
973 if (IS_ERR(obd->obd_proc_entry)) {
974 rc = PTR_ERR(obd->obd_proc_entry);
975 CERROR("error %d setting up lprocfs for %s\n", rc,
977 obd->obd_proc_entry = NULL;
981 obd->obd_ktype.default_attrs = osc_attrs;
982 rc = lprocfs_obd_setup(obd, false);
985 #ifdef CONFIG_PROC_FS
986 /* If the basic OSC proc tree construction succeeded then
989 rc = lprocfs_osc_attach_seqstat(obd);
993 #endif /* CONFIG_PROC_FS */
994 rc = sptlrpc_lprocfs_cliobd_attach(obd);
998 ptlrpc_lprocfs_register_obd(obd);
1001 lprocfs_obd_cleanup(obd);