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_ATTR(ost_conn_uuid, 0444, conn_uuid_show, NULL);
190 LUSTRE_RO_ATTR(conn_uuid);
192 LUSTRE_RW_ATTR(ping);
194 static int osc_cached_mb_seq_show(struct seq_file *m, void *v)
196 struct obd_device *dev = m->private;
197 struct client_obd *cli = &dev->u.cli;
198 int shift = 20 - PAGE_SHIFT;
200 seq_printf(m, "used_mb: %ld\n"
203 (atomic_long_read(&cli->cl_lru_in_list) +
204 atomic_long_read(&cli->cl_lru_busy)) >> shift,
205 atomic_long_read(&cli->cl_lru_busy),
206 cli->cl_lru_reclaim);
211 /* shrink the number of caching pages to a specific number */
212 static ssize_t osc_cached_mb_seq_write(struct file *file,
213 const char __user *buffer,
214 size_t count, loff_t *off)
216 struct obd_device *dev = ((struct seq_file *)file->private_data)->private;
217 struct client_obd *cli = &dev->u.cli;
222 if (count >= sizeof(kernbuf))
225 if (copy_from_user(kernbuf, buffer, count))
229 buffer += lprocfs_find_named_value(kernbuf, "used_mb:", &count) -
231 rc = lprocfs_str_with_units_to_s64(buffer, count, &pages_number, 'M');
235 pages_number >>= PAGE_SHIFT;
237 if (pages_number < 0)
240 rc = atomic_long_read(&cli->cl_lru_in_list) - pages_number;
245 env = cl_env_get(&refcheck);
247 (void)osc_lru_shrink(env, cli, rc, true);
248 cl_env_put(env, &refcheck);
255 LPROC_SEQ_FOPS(osc_cached_mb);
257 static ssize_t cur_dirty_bytes_show(struct kobject *kobj,
258 struct attribute *attr,
261 struct obd_device *dev = container_of(kobj, struct obd_device,
263 struct client_obd *cli = &dev->u.cli;
266 spin_lock(&cli->cl_loi_list_lock);
267 len = sprintf(buf, "%lu\n", cli->cl_dirty_pages << PAGE_SHIFT);
268 spin_unlock(&cli->cl_loi_list_lock);
272 LUSTRE_RO_ATTR(cur_dirty_bytes);
274 static int osc_cur_grant_bytes_seq_show(struct seq_file *m, void *v)
276 struct obd_device *dev = m->private;
277 struct client_obd *cli = &dev->u.cli;
279 spin_lock(&cli->cl_loi_list_lock);
280 seq_printf(m, "%lu\n", cli->cl_avail_grant);
281 spin_unlock(&cli->cl_loi_list_lock);
285 static ssize_t osc_cur_grant_bytes_seq_write(struct file *file,
286 const char __user *buffer,
287 size_t count, loff_t *off)
289 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
290 struct client_obd *cli = &obd->u.cli;
297 rc = lprocfs_str_with_units_to_s64(buffer, count, &val, '1');
303 /* this is only for shrinking grant */
304 spin_lock(&cli->cl_loi_list_lock);
305 if (val >= cli->cl_avail_grant) {
306 spin_unlock(&cli->cl_loi_list_lock);
310 spin_unlock(&cli->cl_loi_list_lock);
312 LPROCFS_CLIMP_CHECK(obd);
313 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
314 rc = osc_shrink_grant_to_target(cli, val);
315 LPROCFS_CLIMP_EXIT(obd);
317 return rc ? rc : count;
319 LPROC_SEQ_FOPS(osc_cur_grant_bytes);
321 static ssize_t cur_lost_grant_bytes_show(struct kobject *kobj,
322 struct attribute *attr,
325 struct obd_device *dev = container_of(kobj, struct obd_device,
327 struct client_obd *cli = &dev->u.cli;
330 spin_lock(&cli->cl_loi_list_lock);
331 len = sprintf(buf, "%lu\n", cli->cl_lost_grant);
332 spin_unlock(&cli->cl_loi_list_lock);
335 LUSTRE_RO_ATTR(cur_lost_grant_bytes);
337 static ssize_t grant_shrink_interval_show(struct kobject *kobj,
338 struct attribute *attr,
341 struct obd_device *obd = container_of(kobj, struct obd_device,
344 return sprintf(buf, "%lld\n", obd->u.cli.cl_grant_shrink_interval);
347 static ssize_t grant_shrink_interval_store(struct kobject *kobj,
348 struct attribute *attr,
352 struct obd_device *obd = container_of(kobj, struct obd_device,
357 rc = kstrtouint(buffer, 0, &val);
364 obd->u.cli.cl_grant_shrink_interval = val;
365 osc_update_next_shrink(&obd->u.cli);
366 osc_schedule_grant_work();
370 LUSTRE_RW_ATTR(grant_shrink_interval);
372 static ssize_t checksums_show(struct kobject *kobj,
373 struct attribute *attr,
376 struct obd_device *obd = container_of(kobj, struct obd_device,
379 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum ? 1 : 0);
382 static ssize_t checksums_store(struct kobject *kobj,
383 struct attribute *attr,
387 struct obd_device *obd = container_of(kobj, struct obd_device,
392 rc = kstrtobool(buffer, &val);
396 obd->u.cli.cl_checksum = val;
400 LUSTRE_RW_ATTR(checksums);
402 static int osc_checksum_type_seq_show(struct seq_file *m, void *v)
404 struct obd_device *obd = m->private;
411 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
412 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
414 if (obd->u.cli.cl_cksum_type == (1 << i))
415 seq_printf(m, "[%s] ", cksum_name[i]);
417 seq_printf(m, "%s ", cksum_name[i]);
423 static ssize_t osc_checksum_type_seq_write(struct file *file,
424 const char __user *buffer,
425 size_t count, loff_t *off)
427 struct obd_device *obd = ((struct seq_file *)file->private_data)->private;
435 if (count > sizeof(kernbuf) - 1)
437 if (copy_from_user(kernbuf, buffer, count))
439 if (count > 0 && kernbuf[count - 1] == '\n')
440 kernbuf[count - 1] = '\0';
442 kernbuf[count] = '\0';
444 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
445 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
447 if (!strcmp(kernbuf, cksum_name[i])) {
448 obd->u.cli.cl_cksum_type = 1 << i;
454 LPROC_SEQ_FOPS(osc_checksum_type);
456 static ssize_t resend_count_show(struct kobject *kobj,
457 struct attribute *attr,
460 struct obd_device *obd = container_of(kobj, struct obd_device,
463 return sprintf(buf, "%u\n", atomic_read(&obd->u.cli.cl_resends));
466 static ssize_t resend_count_store(struct kobject *kobj,
467 struct attribute *attr,
471 struct obd_device *obd = container_of(kobj, struct obd_device,
476 rc = kstrtouint(buffer, 10, &val);
480 atomic_set(&obd->u.cli.cl_resends, val);
484 LUSTRE_RW_ATTR(resend_count);
486 static ssize_t checksum_dump_show(struct kobject *kobj,
487 struct attribute *attr,
490 struct obd_device *obd = container_of(kobj, struct obd_device,
493 return sprintf(buf, "%d\n", obd->u.cli.cl_checksum_dump ? 1 : 0);
496 static ssize_t checksum_dump_store(struct kobject *kobj,
497 struct attribute *attr,
501 struct obd_device *obd = container_of(kobj, struct obd_device,
506 rc = kstrtobool(buffer, &val);
510 obd->u.cli.cl_checksum_dump = val;
514 LUSTRE_RW_ATTR(checksum_dump);
516 static ssize_t contention_seconds_show(struct kobject *kobj,
517 struct attribute *attr,
520 struct obd_device *obd = container_of(kobj, struct obd_device,
522 struct osc_device *od = obd2osc_dev(obd);
524 return sprintf(buf, "%lld\n", od->od_contention_time);
527 static ssize_t contention_seconds_store(struct kobject *kobj,
528 struct attribute *attr,
532 struct obd_device *obd = container_of(kobj, struct obd_device,
534 struct osc_device *od = obd2osc_dev(obd);
538 rc = kstrtouint(buffer, 0, &val);
542 od->od_contention_time = val;
546 LUSTRE_RW_ATTR(contention_seconds);
548 static ssize_t lockless_truncate_show(struct kobject *kobj,
549 struct attribute *attr,
552 struct obd_device *obd = container_of(kobj, struct obd_device,
554 struct osc_device *od = obd2osc_dev(obd);
556 return sprintf(buf, "%u\n", od->od_lockless_truncate);
559 static ssize_t lockless_truncate_store(struct kobject *kobj,
560 struct attribute *attr,
564 struct obd_device *obd = container_of(kobj, struct obd_device,
566 struct osc_device *od = obd2osc_dev(obd);
570 rc = kstrtobool(buffer, &val);
574 od->od_lockless_truncate = val;
578 LUSTRE_RW_ATTR(lockless_truncate);
580 static ssize_t destroys_in_flight_show(struct kobject *kobj,
581 struct attribute *attr,
584 struct obd_device *obd = container_of(kobj, struct obd_device,
587 return sprintf(buf, "%u\n",
588 atomic_read(&obd->u.cli.cl_destroy_in_flight));
590 LUSTRE_RO_ATTR(destroys_in_flight);
592 LPROC_SEQ_FOPS_RW_TYPE(osc, obd_max_pages_per_rpc);
594 LUSTRE_RW_ATTR(short_io_bytes);
596 #ifdef CONFIG_PROC_FS
597 static int osc_unstable_stats_seq_show(struct seq_file *m, void *v)
599 struct obd_device *dev = m->private;
600 struct client_obd *cli = &dev->u.cli;
604 pages = atomic_long_read(&cli->cl_unstable_count);
605 mb = (pages * PAGE_SIZE) >> 20;
607 seq_printf(m, "unstable_pages: %20ld\n"
608 "unstable_mb: %10d\n",
612 LPROC_SEQ_FOPS_RO(osc_unstable_stats);
614 static ssize_t idle_timeout_show(struct kobject *kobj, struct attribute *attr,
617 struct obd_device *obd = container_of(kobj, struct obd_device,
619 struct client_obd *cli = &obd->u.cli;
622 LPROCFS_CLIMP_CHECK(obd);
623 ret = sprintf(buf, "%u\n", cli->cl_import->imp_idle_timeout);
624 LPROCFS_CLIMP_EXIT(obd);
629 static ssize_t idle_timeout_store(struct kobject *kobj, struct attribute *attr,
630 const char *buffer, size_t count)
632 struct obd_device *dev = container_of(kobj, struct obd_device,
634 struct client_obd *cli = &dev->u.cli;
635 struct ptlrpc_request *req;
636 unsigned int idle_debug = 0;
640 if (strncmp(buffer, "debug", 5) == 0) {
641 idle_debug = D_CONSOLE;
642 } else if (strncmp(buffer, "nodebug", 6) == 0) {
645 rc = kstrtouint(buffer, 10, &val);
649 if (val > CONNECTION_SWITCH_MAX)
653 LPROCFS_CLIMP_CHECK(dev);
655 cli->cl_import->imp_idle_debug = idle_debug;
658 /* initiate the connection if it's in IDLE state */
659 req = ptlrpc_request_alloc(cli->cl_import,
662 ptlrpc_req_finished(req);
664 cli->cl_import->imp_idle_timeout = val;
666 LPROCFS_CLIMP_EXIT(dev);
670 LUSTRE_RW_ATTR(idle_timeout);
672 static ssize_t idle_connect_store(struct kobject *kobj, struct attribute *attr,
673 const char *buffer, size_t count)
675 struct obd_device *dev = container_of(kobj, struct obd_device,
677 struct client_obd *cli = &dev->u.cli;
678 struct ptlrpc_request *req;
680 LPROCFS_CLIMP_CHECK(dev);
681 /* to initiate the connection if it's in IDLE state */
682 req = ptlrpc_request_alloc(cli->cl_import, &RQF_OST_STATFS);
684 ptlrpc_req_finished(req);
685 ptlrpc_pinger_force(cli->cl_import);
686 LPROCFS_CLIMP_EXIT(dev);
690 LUSTRE_WO_ATTR(idle_connect);
692 static ssize_t grant_shrink_show(struct kobject *kobj, struct attribute *attr,
695 struct obd_device *obd = container_of(kobj, struct obd_device,
697 struct client_obd *cli = &obd->u.cli;
698 struct obd_connect_data *ocd;
701 LPROCFS_CLIMP_CHECK(obd);
702 ocd = &cli->cl_import->imp_connect_data;
704 len = snprintf(buf, PAGE_SIZE, "%d\n",
705 !!OCD_HAS_FLAG(ocd, GRANT_SHRINK));
706 LPROCFS_CLIMP_EXIT(obd);
711 static ssize_t grant_shrink_store(struct kobject *kobj, struct attribute *attr,
712 const char *buffer, size_t count)
714 struct obd_device *dev = container_of(kobj, struct obd_device,
716 struct client_obd *cli = &dev->u.cli;
717 struct obd_connect_data *ocd;
724 rc = kstrtobool(buffer, &val);
728 LPROCFS_CLIMP_CHECK(dev);
729 ocd = &cli->cl_import->imp_connect_data;
732 if (OCD_HAS_FLAG(ocd, GRANT_SHRINK))
733 ocd->ocd_connect_flags &= ~OBD_CONNECT_GRANT_SHRINK;
736 * server replied obd_connect_data is always bigger, so
737 * client's imp_connect_flags_orig are always supported
740 if (!OCD_HAS_FLAG(ocd, GRANT_SHRINK) &&
741 cli->cl_import->imp_connect_flags_orig &
742 OBD_CONNECT_GRANT_SHRINK)
743 ocd->ocd_connect_flags |= OBD_CONNECT_GRANT_SHRINK;
746 LPROCFS_CLIMP_EXIT(dev);
750 LUSTRE_RW_ATTR(grant_shrink);
752 LPROC_SEQ_FOPS_RO_TYPE(osc, connect_flags);
753 LPROC_SEQ_FOPS_RO_TYPE(osc, server_uuid);
754 LPROC_SEQ_FOPS_RO_TYPE(osc, timeouts);
755 LPROC_SEQ_FOPS_RO_TYPE(osc, state);
757 LPROC_SEQ_FOPS_RW_TYPE(osc, import);
758 LPROC_SEQ_FOPS_RW_TYPE(osc, pinger_recov);
760 struct lprocfs_vars lprocfs_osc_obd_vars[] = {
761 { .name = "connect_flags",
762 .fops = &osc_connect_flags_fops },
763 { .name = "ost_server_uuid",
764 .fops = &osc_server_uuid_fops },
765 { .name = "max_pages_per_rpc",
766 .fops = &osc_obd_max_pages_per_rpc_fops },
767 { .name = "osc_cached_mb",
768 .fops = &osc_cached_mb_fops },
769 { .name = "cur_grant_bytes",
770 .fops = &osc_cur_grant_bytes_fops },
771 { .name = "checksum_type",
772 .fops = &osc_checksum_type_fops },
773 { .name = "timeouts",
774 .fops = &osc_timeouts_fops },
776 .fops = &osc_import_fops },
778 .fops = &osc_state_fops },
779 { .name = "pinger_recov",
780 .fops = &osc_pinger_recov_fops },
781 { .name = "unstable_stats",
782 .fops = &osc_unstable_stats_fops },
786 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
788 struct timespec64 now;
789 struct obd_device *dev = seq->private;
790 struct client_obd *cli = &dev->u.cli;
791 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
794 ktime_get_real_ts64(&now);
796 spin_lock(&cli->cl_loi_list_lock);
798 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
799 (s64)now.tv_sec, now.tv_nsec);
800 seq_printf(seq, "read RPCs in flight: %d\n",
801 cli->cl_r_in_flight);
802 seq_printf(seq, "write RPCs in flight: %d\n",
803 cli->cl_w_in_flight);
804 seq_printf(seq, "pending write pages: %d\n",
805 atomic_read(&cli->cl_pending_w_pages));
806 seq_printf(seq, "pending read pages: %d\n",
807 atomic_read(&cli->cl_pending_r_pages));
809 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
810 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
811 seq_printf(seq, " rpcs %% cum %%\n");
813 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
814 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
818 for (i = 0; i < OBD_HIST_MAX; i++) {
819 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
820 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
824 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
825 1 << i, r, pct(r, read_tot),
826 pct(read_cum, read_tot), w,
828 pct(write_cum, write_tot));
829 if (read_cum == read_tot && write_cum == write_tot)
833 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
834 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
835 seq_printf(seq, " rpcs %% cum %%\n");
837 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
838 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
842 for (i = 0; i < OBD_HIST_MAX; i++) {
843 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
844 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
847 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
848 i, r, pct(r, read_tot),
849 pct(read_cum, read_tot), w,
851 pct(write_cum, write_tot));
852 if (read_cum == read_tot && write_cum == write_tot)
856 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
857 seq_printf(seq, "offset rpcs %% cum %% |");
858 seq_printf(seq, " rpcs %% cum %%\n");
860 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
861 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
865 for (i = 0; i < OBD_HIST_MAX; i++) {
866 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
867 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
870 seq_printf(seq, "%d:\t\t%10lu %3u %3u | %10lu %3u %3u\n",
871 (i == 0) ? 0 : 1 << (i - 1),
872 r, pct(r, read_tot), pct(read_cum, read_tot),
873 w, pct(w, write_tot), pct(write_cum, write_tot));
874 if (read_cum == read_tot && write_cum == write_tot)
878 spin_unlock(&cli->cl_loi_list_lock);
883 static ssize_t osc_rpc_stats_seq_write(struct file *file,
884 const char __user *buf,
885 size_t len, loff_t *off)
887 struct seq_file *seq = file->private_data;
888 struct obd_device *dev = seq->private;
889 struct client_obd *cli = &dev->u.cli;
891 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
892 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
893 lprocfs_oh_clear(&cli->cl_read_page_hist);
894 lprocfs_oh_clear(&cli->cl_write_page_hist);
895 lprocfs_oh_clear(&cli->cl_read_offset_hist);
896 lprocfs_oh_clear(&cli->cl_write_offset_hist);
900 LPROC_SEQ_FOPS(osc_rpc_stats);
902 static int osc_stats_seq_show(struct seq_file *seq, void *v)
904 struct timespec64 now;
905 struct obd_device *dev = seq->private;
906 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
908 ktime_get_real_ts64(&now);
910 seq_printf(seq, "snapshot_time: %lld.%09lu (secs.nsecs)\n",
911 (s64)now.tv_sec, now.tv_nsec);
912 seq_printf(seq, "lockless_write_bytes\t\t%llu\n",
913 stats->os_lockless_writes);
914 seq_printf(seq, "lockless_read_bytes\t\t%llu\n",
915 stats->os_lockless_reads);
916 seq_printf(seq, "lockless_truncate\t\t%llu\n",
917 stats->os_lockless_truncates);
921 static ssize_t osc_stats_seq_write(struct file *file,
922 const char __user *buf,
923 size_t len, loff_t *off)
925 struct seq_file *seq = file->private_data;
926 struct obd_device *dev = seq->private;
927 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
929 memset(stats, 0, sizeof(*stats));
933 LPROC_SEQ_FOPS(osc_stats);
935 int lprocfs_osc_attach_seqstat(struct obd_device *dev)
939 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
940 &osc_stats_fops, dev);
942 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
943 &osc_rpc_stats_fops, dev);
947 #endif /* CONFIG_PROC_FS */
949 static struct attribute *osc_attrs[] = {
950 &lustre_attr_active.attr,
951 &lustre_attr_checksums.attr,
952 &lustre_attr_checksum_dump.attr,
953 &lustre_attr_contention_seconds.attr,
954 &lustre_attr_cur_dirty_bytes.attr,
955 &lustre_attr_cur_lost_grant_bytes.attr,
956 &lustre_attr_destroys_in_flight.attr,
957 &lustre_attr_grant_shrink_interval.attr,
958 &lustre_attr_lockless_truncate.attr,
959 &lustre_attr_max_dirty_mb.attr,
960 &lustre_attr_max_rpcs_in_flight.attr,
961 &lustre_attr_short_io_bytes.attr,
962 &lustre_attr_resend_count.attr,
963 &lustre_attr_ost_conn_uuid.attr,
964 &lustre_attr_conn_uuid.attr,
965 &lustre_attr_ping.attr,
966 &lustre_attr_idle_timeout.attr,
967 &lustre_attr_idle_connect.attr,
968 &lustre_attr_grant_shrink.attr,
972 int osc_tunables_init(struct obd_device *obd)
974 #if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
975 struct obd_type *type;
979 obd->obd_vars = lprocfs_osc_obd_vars;
980 #if defined(CONFIG_PROC_FS) && defined(HAVE_SERVER_SUPPORT)
981 /* If this is true then both client (osc) and server (osp) are on the
982 * same node. The osp layer if loaded first will register the osc proc
983 * directory. In that case this obd_device will be attached its proc
984 * tree to type->typ_procsym instead of obd->obd_type->typ_procroot.
986 type = class_search_type(LUSTRE_OSP_NAME);
987 if (type && type->typ_procsym) {
988 obd->obd_proc_entry = lprocfs_register(obd->obd_name,
991 if (IS_ERR(obd->obd_proc_entry)) {
992 rc = PTR_ERR(obd->obd_proc_entry);
993 CERROR("error %d setting up lprocfs for %s\n", rc,
995 obd->obd_proc_entry = NULL;
999 obd->obd_ktype.default_attrs = osc_attrs;
1000 rc = lprocfs_obd_setup(obd, false);
1003 #ifdef CONFIG_PROC_FS
1004 /* If the basic OSC proc tree construction succeeded then
1007 rc = lprocfs_osc_attach_seqstat(obd);
1011 #endif /* CONFIG_PROC_FS */
1012 rc = sptlrpc_lprocfs_cliobd_attach(obd);
1016 ptlrpc_lprocfs_register_obd(obd);
1019 lprocfs_obd_cleanup(obd);