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_adjust_max_dirty(cli);
115 client_obd_list_unlock(&cli->cl_loi_list_lock);
117 LPROCFS_CLIMP_EXIT(dev);
121 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
122 int *eof, void *data)
124 struct obd_device *dev = data;
125 struct client_obd *cli = &dev->u.cli;
129 client_obd_list_lock(&cli->cl_loi_list_lock);
130 val = cli->cl_dirty_max_pages;
131 client_obd_list_unlock(&cli->cl_loi_list_lock);
133 mult = 1 << (20 - PAGE_CACHE_SHIFT);
134 return lprocfs_read_frac_helper(page, count, val, mult);
137 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
138 unsigned long count, void *data)
140 struct obd_device *dev = data;
141 struct client_obd *cli = &dev->u.cli;
142 int pages_number, mult, rc;
144 mult = 1 << (20 - PAGE_CACHE_SHIFT);
145 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
149 if (pages_number <= 0 ||
150 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - PAGE_CACHE_SHIFT) ||
151 pages_number > totalram_pages / 4) /* 1/4 of RAM */
154 client_obd_list_lock(&cli->cl_loi_list_lock);
155 cli->cl_dirty_max_pages = pages_number;
156 osc_wake_cache_waiters(cli);
157 client_obd_list_unlock(&cli->cl_loi_list_lock);
162 static int osc_rd_cached_mb(char *page, char **start, off_t off, int count,
163 int *eof, void *data)
165 struct obd_device *dev = data;
166 struct client_obd *cli = &dev->u.cli;
167 int shift = 20 - PAGE_CACHE_SHIFT;
170 rc = snprintf(page, count,
173 (cfs_atomic_read(&cli->cl_lru_in_list) +
174 cfs_atomic_read(&cli->cl_lru_busy)) >> shift,
175 cfs_atomic_read(&cli->cl_lru_busy));
180 /* shrink the number of caching pages to a specific number */
181 static int osc_wr_cached_mb(struct file *file, const char *buffer,
182 unsigned long count, void *data)
184 struct obd_device *dev = data;
185 struct client_obd *cli = &dev->u.cli;
186 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;
199 (void)osc_lru_shrink(cli, rc);
204 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
205 int count, int *eof, void *data)
207 struct obd_device *dev = data;
208 struct client_obd *cli = &dev->u.cli;
211 client_obd_list_lock(&cli->cl_loi_list_lock);
212 rc = snprintf(page, count, "%lu\n",
213 cli->cl_dirty_pages << PAGE_CACHE_SHIFT);
214 client_obd_list_unlock(&cli->cl_loi_list_lock);
218 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
219 int count, int *eof, void *data)
221 struct obd_device *dev = data;
222 struct client_obd *cli = &dev->u.cli;
225 client_obd_list_lock(&cli->cl_loi_list_lock);
226 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
227 client_obd_list_unlock(&cli->cl_loi_list_lock);
231 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
232 unsigned long count, void *data)
234 struct obd_device *obd = data;
235 struct client_obd *cli = &obd->u.cli;
242 rc = lprocfs_write_u64_helper(buffer, count, &val);
246 /* this is only for shrinking grant */
247 client_obd_list_lock(&cli->cl_loi_list_lock);
248 if (val >= cli->cl_avail_grant) {
249 client_obd_list_unlock(&cli->cl_loi_list_lock);
252 client_obd_list_unlock(&cli->cl_loi_list_lock);
254 LPROCFS_CLIMP_CHECK(obd);
255 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
256 rc = osc_shrink_grant_to_target(cli, val);
257 LPROCFS_CLIMP_EXIT(obd);
263 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
264 int count, int *eof, void *data)
266 struct obd_device *dev = data;
267 struct client_obd *cli = &dev->u.cli;
270 client_obd_list_lock(&cli->cl_loi_list_lock);
271 rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
272 client_obd_list_unlock(&cli->cl_loi_list_lock);
276 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
277 int count, int *eof, void *data)
279 struct obd_device *obd = data;
283 return snprintf(page, count, "%d\n",
284 obd->u.cli.cl_grant_shrink_interval);
287 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
288 unsigned long count, void *data)
290 struct obd_device *obd = data;
296 rc = lprocfs_write_helper(buffer, count, &val);
303 obd->u.cli.cl_grant_shrink_interval = val;
308 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
309 int *eof, void *data)
311 struct obd_device *obd = data;
316 return snprintf(page, count, "%d\n",
317 obd->u.cli.cl_checksum ? 1 : 0);
320 static int osc_wr_checksum(struct file *file, const char *buffer,
321 unsigned long count, void *data)
323 struct obd_device *obd = data;
329 rc = lprocfs_write_helper(buffer, count, &val);
333 obd->u.cli.cl_checksum = (val ? 1 : 0);
338 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
339 int *eof, void *data)
341 struct obd_device *obd = data;
348 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
349 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
351 if (obd->u.cli.cl_cksum_type == (1 << i))
352 len += snprintf(page + len, count - len, "[%s] ",
355 len += snprintf(page + len, count - len, "%s ",
359 len += sprintf(page + len, "\n");
363 static int osc_wd_checksum_type(struct file *file, const char *buffer,
364 unsigned long count, void *data)
366 struct obd_device *obd = data;
374 if (count > sizeof(kernbuf) - 1)
376 if (copy_from_user(kernbuf, buffer, count))
378 if (count > 0 && kernbuf[count - 1] == '\n')
379 kernbuf[count - 1] = '\0';
381 kernbuf[count] = '\0';
383 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
384 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
386 if (!strcmp(kernbuf, cksum_name[i])) {
387 obd->u.cli.cl_cksum_type = 1 << i;
394 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
395 int *eof, void *data)
397 struct obd_device *obd = data;
399 return snprintf(page, count, "%u\n",
400 cfs_atomic_read(&obd->u.cli.cl_resends));
403 static int osc_wr_resend_count(struct file *file, const char *buffer,
404 unsigned long count, void *data)
406 struct obd_device *obd = data;
409 rc = lprocfs_write_helper(buffer, count, &val);
416 cfs_atomic_set(&obd->u.cli.cl_resends, val);
421 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
422 int count, int *eof, void *data)
424 struct obd_device *obd = data;
425 struct osc_device *od = obd2osc_dev(obd);
427 return snprintf(page, count, "%u\n", od->od_contention_time);
430 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
431 unsigned long count, void *data)
433 struct obd_device *obd = data;
434 struct osc_device *od = obd2osc_dev(obd);
436 return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
440 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
441 int count, int *eof, void *data)
443 struct obd_device *obd = data;
444 struct osc_device *od = obd2osc_dev(obd);
446 return snprintf(page, count, "%u\n", od->od_lockless_truncate);
449 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
450 unsigned long count, void *data)
452 struct obd_device *obd = data;
453 struct osc_device *od = obd2osc_dev(obd);
455 return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
459 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
460 int count, int *eof, void *data)
462 struct obd_device *obd = data;
463 return snprintf(page, count, "%u\n",
464 cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
467 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
468 const char *buffer, unsigned long count, void *data)
470 struct obd_device *dev = data;
471 struct client_obd *cli = &dev->u.cli;
472 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
476 rc = lprocfs_write_u64_helper(buffer, count, &val);
480 /* if the max_pages is specified in bytes, convert to pages */
481 if (val >= ONE_MB_BRW_SIZE)
482 val >>= PAGE_CACHE_SHIFT;
484 LPROCFS_CLIMP_CHECK(dev);
486 chunk_mask = ~((1 << (cli->cl_chunkbits - PAGE_CACHE_SHIFT)) - 1);
487 /* max_pages_per_rpc must be chunk aligned */
488 val = (val + ~chunk_mask) & chunk_mask;
489 if (val == 0 || val > ocd->ocd_brw_size >> PAGE_CACHE_SHIFT) {
490 LPROCFS_CLIMP_EXIT(dev);
493 client_obd_list_lock(&cli->cl_loi_list_lock);
494 cli->cl_max_pages_per_rpc = val;
495 client_adjust_max_dirty(cli);
496 client_obd_list_unlock(&cli->cl_loi_list_lock);
498 LPROCFS_CLIMP_EXIT(dev);
502 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
503 { "uuid", lprocfs_rd_uuid, 0, 0 },
504 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
505 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
506 { "blocksize", lprocfs_rd_blksize, 0, 0 },
507 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
508 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
509 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
510 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
511 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
512 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
513 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
514 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
515 { "active", osc_rd_active,
517 { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
518 lprocfs_osc_wr_max_pages_per_rpc, 0 },
519 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
520 osc_wr_max_rpcs_in_flight, 0 },
521 { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
522 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
523 { "osc_cached_mb", osc_rd_cached_mb, osc_wr_cached_mb, 0 },
524 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
525 { "cur_grant_bytes", osc_rd_cur_grant_bytes,
526 osc_wr_cur_grant_bytes, 0 },
527 { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
528 { "grant_shrink_interval", osc_rd_grant_shrink_interval,
529 osc_wr_grant_shrink_interval, 0 },
530 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
531 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
532 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
533 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
534 { "contention_seconds", osc_rd_contention_seconds,
535 osc_wr_contention_seconds, 0 },
536 { "lockless_truncate", osc_rd_lockless_truncate,
537 osc_wr_lockless_truncate, 0 },
538 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
539 { "state", lprocfs_rd_state, 0, 0 },
540 { "pinger_recov", lprocfs_rd_pinger_recov,
541 lprocfs_wr_pinger_recov, 0, 0 },
545 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
546 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
550 #define pct(a,b) (b ? a * 100 / b : 0)
552 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
555 struct obd_device *dev = seq->private;
556 struct client_obd *cli = &dev->u.cli;
557 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
560 do_gettimeofday(&now);
562 client_obd_list_lock(&cli->cl_loi_list_lock);
564 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
565 now.tv_sec, now.tv_usec);
566 seq_printf(seq, "read RPCs in flight: %d\n",
567 cli->cl_r_in_flight);
568 seq_printf(seq, "write RPCs in flight: %d\n",
569 cli->cl_w_in_flight);
570 seq_printf(seq, "pending write pages: %d\n",
571 cfs_atomic_read(&cli->cl_pending_w_pages));
572 seq_printf(seq, "pending read pages: %d\n",
573 cfs_atomic_read(&cli->cl_pending_r_pages));
575 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
576 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
577 seq_printf(seq, " rpcs %% cum %%\n");
579 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
580 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
584 for (i = 0; i < OBD_HIST_MAX; i++) {
585 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
586 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
589 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
590 1 << i, r, pct(r, read_tot),
591 pct(read_cum, read_tot), w,
593 pct(write_cum, write_tot));
594 if (read_cum == read_tot && write_cum == write_tot)
598 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
599 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
600 seq_printf(seq, " rpcs %% cum %%\n");
602 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
603 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
607 for (i = 0; i < OBD_HIST_MAX; i++) {
608 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
609 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
612 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
613 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, "offset rpcs %% cum %% |");
623 seq_printf(seq, " rpcs %% cum %%\n");
625 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
626 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
630 for (i = 0; i < OBD_HIST_MAX; i++) {
631 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
632 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
635 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
636 (i == 0) ? 0 : 1 << (i - 1),
637 r, pct(r, read_tot), pct(read_cum, read_tot),
638 w, pct(w, write_tot), pct(write_cum, write_tot));
639 if (read_cum == read_tot && write_cum == write_tot)
643 client_obd_list_unlock(&cli->cl_loi_list_lock);
649 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
650 size_t len, loff_t *off)
652 struct seq_file *seq = file->private_data;
653 struct obd_device *dev = seq->private;
654 struct client_obd *cli = &dev->u.cli;
656 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
657 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
658 lprocfs_oh_clear(&cli->cl_read_page_hist);
659 lprocfs_oh_clear(&cli->cl_write_page_hist);
660 lprocfs_oh_clear(&cli->cl_read_offset_hist);
661 lprocfs_oh_clear(&cli->cl_write_offset_hist);
666 LPROC_SEQ_FOPS(osc_rpc_stats);
668 static int osc_stats_seq_show(struct seq_file *seq, void *v)
671 struct obd_device *dev = seq->private;
672 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
674 do_gettimeofday(&now);
676 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
677 now.tv_sec, now.tv_usec);
678 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
679 stats->os_lockless_writes);
680 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
681 stats->os_lockless_reads);
682 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
683 stats->os_lockless_truncates);
687 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
688 size_t len, loff_t *off)
690 struct seq_file *seq = file->private_data;
691 struct obd_device *dev = seq->private;
692 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
694 memset(stats, 0, sizeof(*stats));
698 LPROC_SEQ_FOPS(osc_stats);
700 int lproc_osc_attach_seqstat(struct obd_device *dev)
704 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
705 &osc_stats_fops, dev);
707 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
708 &osc_rpc_stats_fops, dev);
713 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
715 lvars->module_vars = lprocfs_osc_module_vars;
716 lvars->obd_vars = lprocfs_osc_obd_vars;