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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <obd_cksum.h>
41 #include <obd_class.h>
42 #include <lprocfs_status.h>
43 #include <linux/seq_file.h>
44 #include "osc_internal.h"
47 static int osc_rd_active(char *page, char **start, off_t off,
48 int count, int *eof, void *data)
50 struct obd_device *dev = data;
53 LPROCFS_CLIMP_CHECK(dev);
54 rc = snprintf(page, count, "%d\n", !dev->u.cli.cl_import->imp_deactive);
55 LPROCFS_CLIMP_EXIT(dev);
59 static int osc_wr_active(struct file *file, const char *buffer,
60 unsigned long count, void *data)
62 struct obd_device *dev = data;
65 rc = lprocfs_write_helper(buffer, count, &val);
68 if (val < 0 || val > 1)
72 if (dev->u.cli.cl_import->imp_deactive == val)
73 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
75 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
80 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
81 int count, int *eof, void *data)
83 struct obd_device *dev = data;
84 struct client_obd *cli = &dev->u.cli;
87 client_obd_list_lock(&cli->cl_loi_list_lock);
88 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
89 client_obd_list_unlock(&cli->cl_loi_list_lock);
93 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
94 unsigned long count, void *data)
96 struct obd_device *dev = data;
97 struct client_obd *cli = &dev->u.cli;
98 struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
101 rc = lprocfs_write_helper(buffer, count, &val);
105 if (val < 1 || val > OSC_MAX_RIF_MAX)
108 LPROCFS_CLIMP_CHECK(dev);
109 if (pool && val > cli->cl_max_rpcs_in_flight)
110 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
112 client_obd_list_lock(&cli->cl_loi_list_lock);
113 cli->cl_max_rpcs_in_flight = val;
114 client_obd_list_unlock(&cli->cl_loi_list_lock);
116 LPROCFS_CLIMP_EXIT(dev);
120 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
121 int *eof, void *data)
123 struct obd_device *dev = data;
124 struct client_obd *cli = &dev->u.cli;
128 client_obd_list_lock(&cli->cl_loi_list_lock);
129 val = cli->cl_dirty_max;
130 client_obd_list_unlock(&cli->cl_loi_list_lock);
133 return lprocfs_read_frac_helper(page, count, val, mult);
136 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
137 unsigned long count, void *data)
139 struct obd_device *dev = data;
140 struct client_obd *cli = &dev->u.cli;
141 int pages_number, mult, rc;
143 mult = 1 << (20 - PAGE_CACHE_SHIFT);
144 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
148 if (pages_number <= 0 ||
149 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) ||
150 pages_number > totalram_pages / 4) /* 1/4 of RAM */
153 client_obd_list_lock(&cli->cl_loi_list_lock);
154 cli->cl_dirty_max = (obd_count)(pages_number << PAGE_CACHE_SHIFT);
155 osc_wake_cache_waiters(cli);
156 client_obd_list_unlock(&cli->cl_loi_list_lock);
161 static int osc_rd_cached_mb(char *page, char **start, off_t off, int count,
162 int *eof, void *data)
164 struct obd_device *dev = data;
165 struct client_obd *cli = &dev->u.cli;
166 int shift = 20 - PAGE_CACHE_SHIFT;
169 rc = snprintf(page, count,
172 (cfs_atomic_read(&cli->cl_lru_in_list) +
173 cfs_atomic_read(&cli->cl_lru_busy)) >> shift,
174 cfs_atomic_read(&cli->cl_lru_busy));
179 /* shrink the number of caching pages to a specific number */
180 static int osc_wr_cached_mb(struct file *file, const char *buffer,
181 unsigned long nob, void *data)
183 struct obd_device *dev = data;
184 struct client_obd *cli = &dev->u.cli;
185 int pages_number, mult, rc;
188 mult = 1 << (20 - PAGE_CACHE_SHIFT);
189 buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
190 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
194 if (pages_number < 0)
197 rc = cfs_atomic_read(&cli->cl_lru_in_list) - pages_number;
202 env = cl_env_get(&refcheck);
204 (void)osc_lru_shrink(env, cli, rc, true);
205 cl_env_put(env, &refcheck);
212 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
213 int count, int *eof, void *data)
215 struct obd_device *dev = data;
216 struct client_obd *cli = &dev->u.cli;
219 client_obd_list_lock(&cli->cl_loi_list_lock);
220 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
221 client_obd_list_unlock(&cli->cl_loi_list_lock);
225 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
226 int count, int *eof, void *data)
228 struct obd_device *dev = data;
229 struct client_obd *cli = &dev->u.cli;
232 client_obd_list_lock(&cli->cl_loi_list_lock);
233 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
234 client_obd_list_unlock(&cli->cl_loi_list_lock);
238 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
239 unsigned long count, void *data)
241 struct obd_device *obd = data;
242 struct client_obd *cli = &obd->u.cli;
249 rc = lprocfs_write_u64_helper(buffer, count, &val);
253 /* this is only for shrinking grant */
254 client_obd_list_lock(&cli->cl_loi_list_lock);
255 if (val >= cli->cl_avail_grant) {
256 client_obd_list_unlock(&cli->cl_loi_list_lock);
259 client_obd_list_unlock(&cli->cl_loi_list_lock);
261 LPROCFS_CLIMP_CHECK(obd);
262 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
263 rc = osc_shrink_grant_to_target(cli, val);
264 LPROCFS_CLIMP_EXIT(obd);
270 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
271 int count, int *eof, void *data)
273 struct obd_device *dev = data;
274 struct client_obd *cli = &dev->u.cli;
277 client_obd_list_lock(&cli->cl_loi_list_lock);
278 rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
279 client_obd_list_unlock(&cli->cl_loi_list_lock);
283 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
284 int count, int *eof, void *data)
286 struct obd_device *obd = data;
290 return snprintf(page, count, "%d\n",
291 obd->u.cli.cl_grant_shrink_interval);
294 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
295 unsigned long count, void *data)
297 struct obd_device *obd = data;
303 rc = lprocfs_write_helper(buffer, count, &val);
310 obd->u.cli.cl_grant_shrink_interval = val;
315 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
316 int *eof, void *data)
318 struct obd_device *obd = data;
323 return snprintf(page, count, "%d\n",
324 obd->u.cli.cl_checksum ? 1 : 0);
327 static int osc_wr_checksum(struct file *file, const char *buffer,
328 unsigned long count, void *data)
330 struct obd_device *obd = data;
336 rc = lprocfs_write_helper(buffer, count, &val);
340 obd->u.cli.cl_checksum = (val ? 1 : 0);
345 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
346 int *eof, void *data)
348 struct obd_device *obd = data;
355 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
356 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
358 if (obd->u.cli.cl_cksum_type == (1 << i))
359 len += snprintf(page + len, count - len, "[%s] ",
362 len += snprintf(page + len, count - len, "%s ",
366 len += sprintf(page + len, "\n");
370 static int osc_wd_checksum_type(struct file *file, const char *buffer,
371 unsigned long count, void *data)
373 struct obd_device *obd = data;
381 if (count > sizeof(kernbuf) - 1)
383 if (copy_from_user(kernbuf, buffer, count))
385 if (count > 0 && kernbuf[count - 1] == '\n')
386 kernbuf[count - 1] = '\0';
388 kernbuf[count] = '\0';
390 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
391 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
393 if (!strcmp(kernbuf, cksum_name[i])) {
394 obd->u.cli.cl_cksum_type = 1 << i;
401 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
402 int *eof, void *data)
404 struct obd_device *obd = data;
406 return snprintf(page, count, "%u\n",
407 cfs_atomic_read(&obd->u.cli.cl_resends));
410 static int osc_wr_resend_count(struct file *file, const char *buffer,
411 unsigned long count, void *data)
413 struct obd_device *obd = data;
416 rc = lprocfs_write_helper(buffer, count, &val);
423 cfs_atomic_set(&obd->u.cli.cl_resends, val);
428 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
429 int count, int *eof, void *data)
431 struct obd_device *obd = data;
432 struct osc_device *od = obd2osc_dev(obd);
434 return snprintf(page, count, "%u\n", od->od_contention_time);
437 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
438 unsigned long count, void *data)
440 struct obd_device *obd = data;
441 struct osc_device *od = obd2osc_dev(obd);
443 return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
447 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
448 int count, int *eof, void *data)
450 struct obd_device *obd = data;
451 struct osc_device *od = obd2osc_dev(obd);
453 return snprintf(page, count, "%u\n", od->od_lockless_truncate);
456 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
457 unsigned long count, void *data)
459 struct obd_device *obd = data;
460 struct osc_device *od = obd2osc_dev(obd);
462 return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
466 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
467 int count, int *eof, void *data)
469 struct obd_device *obd = data;
470 return snprintf(page, count, "%u\n",
471 cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
474 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
475 const char *buffer, unsigned long count, void *data)
477 struct obd_device *dev = data;
478 struct client_obd *cli = &dev->u.cli;
479 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
483 rc = lprocfs_write_u64_helper(buffer, count, &val);
487 /* if the max_pages is specified in bytes, convert to pages */
488 if (val >= ONE_MB_BRW_SIZE)
489 val >>= PAGE_CACHE_SHIFT;
491 LPROCFS_CLIMP_CHECK(dev);
493 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
494 /* max_pages_per_rpc must be chunk aligned */
495 val = (val + ~chunk_mask) & chunk_mask;
496 if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
497 LPROCFS_CLIMP_EXIT(dev);
500 client_obd_list_lock(&cli->cl_loi_list_lock);
501 cli->cl_max_pages_per_rpc = val;
502 client_obd_list_unlock(&cli->cl_loi_list_lock);
504 LPROCFS_CLIMP_EXIT(dev);
508 static int osc_rd_unstable_stats(char *page, char **start, off_t off,
509 int count, int *eof, void *data)
511 struct obd_device *dev = data;
512 struct client_obd *cli = &dev->u.cli;
515 pages = cfs_atomic_read(&cli->cl_unstable_count);
516 mb = (pages * PAGE_CACHE_SIZE) >> 20;
518 return snprintf(page, count,
519 "unstable_pages: %8d\n"
520 "unstable_mb: %8d\n",
524 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
525 { "uuid", lprocfs_rd_uuid, 0, 0 },
526 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
527 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
528 { "blocksize", lprocfs_rd_blksize, 0, 0 },
529 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
530 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
531 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
532 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
533 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
534 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
535 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
536 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
537 { "active", osc_rd_active,
539 { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
540 lprocfs_osc_wr_max_pages_per_rpc, 0 },
541 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
542 osc_wr_max_rpcs_in_flight, 0 },
543 { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
544 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
545 { "osc_cached_mb", osc_rd_cached_mb, osc_wr_cached_mb, 0 },
546 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
547 { "cur_grant_bytes", osc_rd_cur_grant_bytes,
548 osc_wr_cur_grant_bytes, 0 },
549 { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
550 { "grant_shrink_interval", osc_rd_grant_shrink_interval,
551 osc_wr_grant_shrink_interval, 0 },
552 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
553 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
554 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
555 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
556 { "contention_seconds", osc_rd_contention_seconds,
557 osc_wr_contention_seconds, 0 },
558 { "lockless_truncate", osc_rd_lockless_truncate,
559 osc_wr_lockless_truncate, 0 },
560 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
561 { "state", lprocfs_rd_state, 0, 0 },
562 { "pinger_recov", lprocfs_rd_pinger_recov,
563 lprocfs_wr_pinger_recov, 0, 0 },
564 { "unstable_stats", osc_rd_unstable_stats, 0, 0},
569 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
570 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
574 #define pct(a,b) (b ? a * 100 / b : 0)
576 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
579 struct obd_device *dev = seq->private;
580 struct client_obd *cli = &dev->u.cli;
581 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
584 do_gettimeofday(&now);
586 client_obd_list_lock(&cli->cl_loi_list_lock);
588 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
589 now.tv_sec, now.tv_usec);
590 seq_printf(seq, "read RPCs in flight: %d\n",
591 cli->cl_r_in_flight);
592 seq_printf(seq, "write RPCs in flight: %d\n",
593 cli->cl_w_in_flight);
594 seq_printf(seq, "pending write pages: %d\n",
595 cfs_atomic_read(&cli->cl_pending_w_pages));
596 seq_printf(seq, "pending read pages: %d\n",
597 cfs_atomic_read(&cli->cl_pending_r_pages));
599 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
600 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
601 seq_printf(seq, " rpcs %% cum %%\n");
603 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
604 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
608 for (i = 0; i < OBD_HIST_MAX; i++) {
609 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
610 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
613 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
614 1 << i, r, pct(r, read_tot),
615 pct(read_cum, read_tot), w,
617 pct(write_cum, write_tot));
618 if (read_cum == read_tot && write_cum == write_tot)
622 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
623 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
624 seq_printf(seq, " rpcs %% cum %%\n");
626 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
627 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
631 for (i = 0; i < OBD_HIST_MAX; i++) {
632 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
633 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
636 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
637 i, r, pct(r, read_tot),
638 pct(read_cum, read_tot), w,
640 pct(write_cum, write_tot));
641 if (read_cum == read_tot && write_cum == write_tot)
645 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
646 seq_printf(seq, "offset rpcs %% cum %% |");
647 seq_printf(seq, " rpcs %% cum %%\n");
649 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
650 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
654 for (i = 0; i < OBD_HIST_MAX; i++) {
655 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
656 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
659 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
660 (i == 0) ? 0 : 1 << (i - 1),
661 r, pct(r, read_tot), pct(read_cum, read_tot),
662 w, pct(w, write_tot), pct(write_cum, write_tot));
663 if (read_cum == read_tot && write_cum == write_tot)
667 client_obd_list_unlock(&cli->cl_loi_list_lock);
673 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
674 size_t len, loff_t *off)
676 struct seq_file *seq = file->private_data;
677 struct obd_device *dev = seq->private;
678 struct client_obd *cli = &dev->u.cli;
680 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
681 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
682 lprocfs_oh_clear(&cli->cl_read_page_hist);
683 lprocfs_oh_clear(&cli->cl_write_page_hist);
684 lprocfs_oh_clear(&cli->cl_read_offset_hist);
685 lprocfs_oh_clear(&cli->cl_write_offset_hist);
690 LPROC_SEQ_FOPS(osc_rpc_stats);
692 static int osc_stats_seq_show(struct seq_file *seq, void *v)
695 struct obd_device *dev = seq->private;
696 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
698 do_gettimeofday(&now);
700 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
701 now.tv_sec, now.tv_usec);
702 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
703 stats->os_lockless_writes);
704 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
705 stats->os_lockless_reads);
706 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
707 stats->os_lockless_truncates);
711 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
712 size_t len, loff_t *off)
714 struct seq_file *seq = file->private_data;
715 struct obd_device *dev = seq->private;
716 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
718 memset(stats, 0, sizeof(*stats));
722 LPROC_SEQ_FOPS(osc_stats);
724 int lproc_osc_attach_seqstat(struct obd_device *dev)
728 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
729 &osc_stats_fops, dev);
731 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
732 &osc_rpc_stats_fops, dev);
737 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
739 lvars->module_vars = lprocfs_osc_module_vars;
740 lvars->obd_vars = lprocfs_osc_obd_vars;