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 count, void *data)
183 struct obd_device *dev = data;
184 struct client_obd *cli = &dev->u.cli;
185 int pages_number, mult, rc;
187 mult = 1 << (20 - PAGE_CACHE_SHIFT);
188 buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
189 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
193 if (pages_number < 0)
196 rc = cfs_atomic_read(&cli->cl_lru_in_list) - pages_number;
201 env = cl_env_get(&refcheck);
203 (void)osc_lru_shrink(env, cli, rc, true);
204 cl_env_put(env, &refcheck);
211 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
212 int count, int *eof, void *data)
214 struct obd_device *dev = data;
215 struct client_obd *cli = &dev->u.cli;
218 client_obd_list_lock(&cli->cl_loi_list_lock);
219 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
220 client_obd_list_unlock(&cli->cl_loi_list_lock);
224 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
225 int count, int *eof, void *data)
227 struct obd_device *dev = data;
228 struct client_obd *cli = &dev->u.cli;
231 client_obd_list_lock(&cli->cl_loi_list_lock);
232 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
233 client_obd_list_unlock(&cli->cl_loi_list_lock);
237 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
238 unsigned long count, void *data)
240 struct obd_device *obd = data;
241 struct client_obd *cli = &obd->u.cli;
248 rc = lprocfs_write_u64_helper(buffer, count, &val);
252 /* this is only for shrinking grant */
253 client_obd_list_lock(&cli->cl_loi_list_lock);
254 if (val >= cli->cl_avail_grant) {
255 client_obd_list_unlock(&cli->cl_loi_list_lock);
258 client_obd_list_unlock(&cli->cl_loi_list_lock);
260 LPROCFS_CLIMP_CHECK(obd);
261 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
262 rc = osc_shrink_grant_to_target(cli, val);
263 LPROCFS_CLIMP_EXIT(obd);
269 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
270 int count, int *eof, void *data)
272 struct obd_device *dev = data;
273 struct client_obd *cli = &dev->u.cli;
276 client_obd_list_lock(&cli->cl_loi_list_lock);
277 rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
278 client_obd_list_unlock(&cli->cl_loi_list_lock);
282 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
283 int count, int *eof, void *data)
285 struct obd_device *obd = data;
289 return snprintf(page, count, "%d\n",
290 obd->u.cli.cl_grant_shrink_interval);
293 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
294 unsigned long count, void *data)
296 struct obd_device *obd = data;
302 rc = lprocfs_write_helper(buffer, count, &val);
309 obd->u.cli.cl_grant_shrink_interval = val;
314 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
315 int *eof, void *data)
317 struct obd_device *obd = data;
322 return snprintf(page, count, "%d\n",
323 obd->u.cli.cl_checksum ? 1 : 0);
326 static int osc_wr_checksum(struct file *file, const char *buffer,
327 unsigned long count, void *data)
329 struct obd_device *obd = data;
335 rc = lprocfs_write_helper(buffer, count, &val);
339 obd->u.cli.cl_checksum = (val ? 1 : 0);
344 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
345 int *eof, void *data)
347 struct obd_device *obd = data;
354 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
355 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
357 if (obd->u.cli.cl_cksum_type == (1 << i))
358 len += snprintf(page + len, count - len, "[%s] ",
361 len += snprintf(page + len, count - len, "%s ",
365 len += sprintf(page + len, "\n");
369 static int osc_wd_checksum_type(struct file *file, const char *buffer,
370 unsigned long count, void *data)
372 struct obd_device *obd = data;
380 if (count > sizeof(kernbuf) - 1)
382 if (copy_from_user(kernbuf, buffer, count))
384 if (count > 0 && kernbuf[count - 1] == '\n')
385 kernbuf[count - 1] = '\0';
387 kernbuf[count] = '\0';
389 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
390 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
392 if (!strcmp(kernbuf, cksum_name[i])) {
393 obd->u.cli.cl_cksum_type = 1 << i;
400 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
401 int *eof, void *data)
403 struct obd_device *obd = data;
405 return snprintf(page, count, "%u\n",
406 cfs_atomic_read(&obd->u.cli.cl_resends));
409 static int osc_wr_resend_count(struct file *file, const char *buffer,
410 unsigned long count, void *data)
412 struct obd_device *obd = data;
415 rc = lprocfs_write_helper(buffer, count, &val);
422 cfs_atomic_set(&obd->u.cli.cl_resends, val);
427 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
428 int count, int *eof, void *data)
430 struct obd_device *obd = data;
431 struct osc_device *od = obd2osc_dev(obd);
433 return snprintf(page, count, "%u\n", od->od_contention_time);
436 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
437 unsigned long count, void *data)
439 struct obd_device *obd = data;
440 struct osc_device *od = obd2osc_dev(obd);
442 return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
446 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
447 int count, int *eof, void *data)
449 struct obd_device *obd = data;
450 struct osc_device *od = obd2osc_dev(obd);
452 return snprintf(page, count, "%u\n", od->od_lockless_truncate);
455 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
456 unsigned long count, void *data)
458 struct obd_device *obd = data;
459 struct osc_device *od = obd2osc_dev(obd);
461 return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
465 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
466 int count, int *eof, void *data)
468 struct obd_device *obd = data;
469 return snprintf(page, count, "%u\n",
470 cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
473 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
474 const char *buffer, unsigned long count, void *data)
476 struct obd_device *dev = data;
477 struct client_obd *cli = &dev->u.cli;
478 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
482 rc = lprocfs_write_u64_helper(buffer, count, &val);
486 /* if the max_pages is specified in bytes, convert to pages */
487 if (val >= ONE_MB_BRW_SIZE)
488 val >>= PAGE_CACHE_SHIFT;
490 LPROCFS_CLIMP_CHECK(dev);
492 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
493 /* max_pages_per_rpc must be chunk aligned */
494 val = (val + ~chunk_mask) & chunk_mask;
495 if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
496 LPROCFS_CLIMP_EXIT(dev);
499 client_obd_list_lock(&cli->cl_loi_list_lock);
500 cli->cl_max_pages_per_rpc = val;
501 client_obd_list_unlock(&cli->cl_loi_list_lock);
503 LPROCFS_CLIMP_EXIT(dev);
507 static int osc_rd_unstable_stats(char *page, char **start, off_t off,
508 int count, int *eof, void *data)
510 struct obd_device *dev = data;
511 struct client_obd *cli = &dev->u.cli;
514 pages = cfs_atomic_read(&cli->cl_unstable_count);
515 mb = (pages * PAGE_CACHE_SIZE) >> 20;
517 return snprintf(page, count,
518 "unstable_pages: %8d\n"
519 "unstable_mb: %8d\n",
523 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
524 { "uuid", lprocfs_rd_uuid, 0, 0 },
525 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
526 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
527 { "blocksize", lprocfs_rd_blksize, 0, 0 },
528 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
529 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
530 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
531 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
532 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
533 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
534 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
535 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
536 { "active", osc_rd_active,
538 { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
539 lprocfs_osc_wr_max_pages_per_rpc, 0 },
540 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
541 osc_wr_max_rpcs_in_flight, 0 },
542 { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
543 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
544 { "osc_cached_mb", osc_rd_cached_mb, osc_wr_cached_mb, 0 },
545 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
546 { "cur_grant_bytes", osc_rd_cur_grant_bytes,
547 osc_wr_cur_grant_bytes, 0 },
548 { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
549 { "grant_shrink_interval", osc_rd_grant_shrink_interval,
550 osc_wr_grant_shrink_interval, 0 },
551 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
552 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
553 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
554 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
555 { "contention_seconds", osc_rd_contention_seconds,
556 osc_wr_contention_seconds, 0 },
557 { "lockless_truncate", osc_rd_lockless_truncate,
558 osc_wr_lockless_truncate, 0 },
559 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
560 { "state", lprocfs_rd_state, 0, 0 },
561 { "pinger_recov", lprocfs_rd_pinger_recov,
562 lprocfs_wr_pinger_recov, 0, 0 },
563 { "unstable_stats", osc_rd_unstable_stats, 0, 0},
568 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
569 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
573 #define pct(a,b) (b ? a * 100 / b : 0)
575 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
578 struct obd_device *dev = seq->private;
579 struct client_obd *cli = &dev->u.cli;
580 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
583 do_gettimeofday(&now);
585 client_obd_list_lock(&cli->cl_loi_list_lock);
587 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
588 now.tv_sec, now.tv_usec);
589 seq_printf(seq, "read RPCs in flight: %d\n",
590 cli->cl_r_in_flight);
591 seq_printf(seq, "write RPCs in flight: %d\n",
592 cli->cl_w_in_flight);
593 seq_printf(seq, "pending write pages: %d\n",
594 cfs_atomic_read(&cli->cl_pending_w_pages));
595 seq_printf(seq, "pending read pages: %d\n",
596 cfs_atomic_read(&cli->cl_pending_r_pages));
598 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
599 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
600 seq_printf(seq, " rpcs %% cum %%\n");
602 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
603 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
607 for (i = 0; i < OBD_HIST_MAX; i++) {
608 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
609 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
612 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
613 1 << i, r, pct(r, read_tot),
614 pct(read_cum, read_tot), w,
616 pct(write_cum, write_tot));
617 if (read_cum == read_tot && write_cum == write_tot)
621 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
622 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
623 seq_printf(seq, " rpcs %% cum %%\n");
625 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
626 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
630 for (i = 0; i < OBD_HIST_MAX; i++) {
631 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
632 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
635 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
636 i, r, pct(r, read_tot),
637 pct(read_cum, read_tot), w,
639 pct(write_cum, write_tot));
640 if (read_cum == read_tot && write_cum == write_tot)
644 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
645 seq_printf(seq, "offset rpcs %% cum %% |");
646 seq_printf(seq, " rpcs %% cum %%\n");
648 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
649 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
653 for (i = 0; i < OBD_HIST_MAX; i++) {
654 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
655 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
658 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
659 (i == 0) ? 0 : 1 << (i - 1),
660 r, pct(r, read_tot), pct(read_cum, read_tot),
661 w, pct(w, write_tot), pct(write_cum, write_tot));
662 if (read_cum == read_tot && write_cum == write_tot)
666 client_obd_list_unlock(&cli->cl_loi_list_lock);
672 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
673 size_t len, loff_t *off)
675 struct seq_file *seq = file->private_data;
676 struct obd_device *dev = seq->private;
677 struct client_obd *cli = &dev->u.cli;
679 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
680 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
681 lprocfs_oh_clear(&cli->cl_read_page_hist);
682 lprocfs_oh_clear(&cli->cl_write_page_hist);
683 lprocfs_oh_clear(&cli->cl_read_offset_hist);
684 lprocfs_oh_clear(&cli->cl_write_offset_hist);
689 LPROC_SEQ_FOPS(osc_rpc_stats);
691 static int osc_stats_seq_show(struct seq_file *seq, void *v)
694 struct obd_device *dev = seq->private;
695 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
697 do_gettimeofday(&now);
699 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
700 now.tv_sec, now.tv_usec);
701 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
702 stats->os_lockless_writes);
703 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
704 stats->os_lockless_reads);
705 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
706 stats->os_lockless_truncates);
710 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
711 size_t len, loff_t *off)
713 struct seq_file *seq = file->private_data;
714 struct obd_device *dev = seq->private;
715 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
717 memset(stats, 0, sizeof(*stats));
721 LPROC_SEQ_FOPS(osc_stats);
723 int lproc_osc_attach_seqstat(struct obd_device *dev)
727 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
728 &osc_stats_fops, dev);
730 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
731 &osc_rpc_stats_fops, dev);
736 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
738 lvars->module_vars = lprocfs_osc_module_vars;
739 lvars->obd_vars = lprocfs_osc_obd_vars;