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, Whamcloud, Inc.
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)
71 LPROCFS_CLIMP_CHECK(dev);
73 if (dev->u.cli.cl_import->imp_deactive == val)
74 rc = ptlrpc_set_import_active(dev->u.cli.cl_import, val);
76 CDEBUG(D_CONFIG, "activate %d: ignoring repeat request\n", val);
78 LPROCFS_CLIMP_EXIT(dev);
82 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
83 int count, int *eof, void *data)
85 struct obd_device *dev = data;
86 struct client_obd *cli = &dev->u.cli;
89 client_obd_list_lock(&cli->cl_loi_list_lock);
90 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
91 client_obd_list_unlock(&cli->cl_loi_list_lock);
95 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
96 unsigned long count, void *data)
98 struct obd_device *dev = data;
99 struct client_obd *cli = &dev->u.cli;
100 struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
103 rc = lprocfs_write_helper(buffer, count, &val);
107 if (val < 1 || val > OSC_MAX_RIF_MAX)
110 LPROCFS_CLIMP_CHECK(dev);
111 if (pool && val > cli->cl_max_rpcs_in_flight)
112 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
114 client_obd_list_lock(&cli->cl_loi_list_lock);
115 cli->cl_max_rpcs_in_flight = val;
116 client_obd_list_unlock(&cli->cl_loi_list_lock);
118 LPROCFS_CLIMP_EXIT(dev);
122 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
123 int *eof, void *data)
125 struct obd_device *dev = data;
126 struct client_obd *cli = &dev->u.cli;
130 client_obd_list_lock(&cli->cl_loi_list_lock);
131 val = cli->cl_dirty_max;
132 client_obd_list_unlock(&cli->cl_loi_list_lock);
135 return lprocfs_read_frac_helper(page, count, val, mult);
138 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
139 unsigned long count, void *data)
141 struct obd_device *dev = data;
142 struct client_obd *cli = &dev->u.cli;
143 int pages_number, mult, rc;
145 mult = 1 << (20 - CFS_PAGE_SHIFT);
146 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
150 if (pages_number < 0 ||
151 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
152 pages_number > cfs_num_physpages / 4) /* 1/4 of RAM */
155 client_obd_list_lock(&cli->cl_loi_list_lock);
156 cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
157 osc_wake_cache_waiters(cli);
158 client_obd_list_unlock(&cli->cl_loi_list_lock);
163 static int osc_rd_cached_mb(char *page, char **start, off_t off, int count,
164 int *eof, void *data)
166 struct obd_device *dev = data;
167 struct client_obd *cli = &dev->u.cli;
168 int shift = 20 - CFS_PAGE_SHIFT;
171 rc = snprintf(page, count,
174 (cfs_atomic_read(&cli->cl_lru_in_list) +
175 cfs_atomic_read(&cli->cl_lru_busy)) >> shift,
176 cfs_atomic_read(&cli->cl_lru_busy));
181 /* shrink the number of caching pages to a specific number */
182 static int osc_wr_cached_mb(struct file *file, const char *buffer,
183 unsigned long count, void *data)
185 struct obd_device *dev = data;
186 struct client_obd *cli = &dev->u.cli;
187 int pages_number, mult, rc;
189 mult = 1 << (20 - CFS_PAGE_SHIFT);
190 buffer = lprocfs_find_named_value(buffer, "used_mb:", &count);
191 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
195 if (pages_number < 0)
198 rc = cfs_atomic_read(&cli->cl_lru_in_list) - pages_number;
200 (void)osc_lru_shrink(cli, rc);
205 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
206 int count, int *eof, void *data)
208 struct obd_device *dev = data;
209 struct client_obd *cli = &dev->u.cli;
212 client_obd_list_lock(&cli->cl_loi_list_lock);
213 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
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 (cfs_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;
473 int chunk_mask, val, rc;
475 rc = lprocfs_write_helper(buffer, count, &val);
479 LPROCFS_CLIMP_CHECK(dev);
481 chunk_mask = ~((1 << (cli->cl_chunkbits - CFS_PAGE_SHIFT)) - 1);
482 /* max_pages_per_rpc must be chunk aligned */
483 val = (val + ~chunk_mask) & chunk_mask;
484 if (val == 0 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
485 LPROCFS_CLIMP_EXIT(dev);
488 client_obd_list_lock(&cli->cl_loi_list_lock);
489 cli->cl_max_pages_per_rpc = val;
490 client_obd_list_unlock(&cli->cl_loi_list_lock);
492 LPROCFS_CLIMP_EXIT(dev);
496 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
497 { "uuid", lprocfs_rd_uuid, 0, 0 },
498 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
499 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
500 { "blocksize", lprocfs_rd_blksize, 0, 0 },
501 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
502 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
503 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
504 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
505 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
506 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
507 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
508 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
509 { "active", osc_rd_active,
511 { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
512 lprocfs_osc_wr_max_pages_per_rpc, 0 },
513 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
514 osc_wr_max_rpcs_in_flight, 0 },
515 { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
516 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
517 { "osc_cached_mb", osc_rd_cached_mb, osc_wr_cached_mb, 0 },
518 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
519 { "cur_grant_bytes", osc_rd_cur_grant_bytes,
520 osc_wr_cur_grant_bytes, 0 },
521 { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
522 { "grant_shrink_interval", osc_rd_grant_shrink_interval,
523 osc_wr_grant_shrink_interval, 0 },
524 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
525 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
526 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
527 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
528 { "contention_seconds", osc_rd_contention_seconds,
529 osc_wr_contention_seconds, 0 },
530 { "lockless_truncate", osc_rd_lockless_truncate,
531 osc_wr_lockless_truncate, 0 },
532 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
533 { "state", lprocfs_rd_state, 0, 0 },
534 { "pinger_recov", lprocfs_rd_pinger_recov,
535 lprocfs_wr_pinger_recov, 0, 0 },
539 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
540 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
544 #define pct(a,b) (b ? a * 100 / b : 0)
546 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
549 struct obd_device *dev = seq->private;
550 struct client_obd *cli = &dev->u.cli;
551 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
554 cfs_gettimeofday(&now);
556 client_obd_list_lock(&cli->cl_loi_list_lock);
558 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
559 now.tv_sec, now.tv_usec);
560 seq_printf(seq, "read RPCs in flight: %d\n",
561 cli->cl_r_in_flight);
562 seq_printf(seq, "write RPCs in flight: %d\n",
563 cli->cl_w_in_flight);
564 seq_printf(seq, "pending write pages: %d\n",
565 cfs_atomic_read(&cli->cl_pending_w_pages));
566 seq_printf(seq, "pending read pages: %d\n",
567 cfs_atomic_read(&cli->cl_pending_r_pages));
569 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
570 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
571 seq_printf(seq, " rpcs %% cum %%\n");
573 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
574 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
578 for (i = 0; i < OBD_HIST_MAX; i++) {
579 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
580 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
583 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
584 1 << i, r, pct(r, read_tot),
585 pct(read_cum, read_tot), w,
587 pct(write_cum, write_tot));
588 if (read_cum == read_tot && write_cum == write_tot)
592 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
593 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
594 seq_printf(seq, " rpcs %% cum %%\n");
596 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
597 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
601 for (i = 0; i < OBD_HIST_MAX; i++) {
602 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
603 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
606 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
607 i, r, pct(r, read_tot),
608 pct(read_cum, read_tot), w,
610 pct(write_cum, write_tot));
611 if (read_cum == read_tot && write_cum == write_tot)
615 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
616 seq_printf(seq, "offset rpcs %% cum %% |");
617 seq_printf(seq, " rpcs %% cum %%\n");
619 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
620 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
624 for (i = 0; i < OBD_HIST_MAX; i++) {
625 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
626 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
629 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
630 (i == 0) ? 0 : 1 << (i - 1),
631 r, pct(r, read_tot), pct(read_cum, read_tot),
632 w, pct(w, write_tot), pct(write_cum, write_tot));
633 if (read_cum == read_tot && write_cum == write_tot)
637 client_obd_list_unlock(&cli->cl_loi_list_lock);
643 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
644 size_t len, loff_t *off)
646 struct seq_file *seq = file->private_data;
647 struct obd_device *dev = seq->private;
648 struct client_obd *cli = &dev->u.cli;
650 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
651 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
652 lprocfs_oh_clear(&cli->cl_read_page_hist);
653 lprocfs_oh_clear(&cli->cl_write_page_hist);
654 lprocfs_oh_clear(&cli->cl_read_offset_hist);
655 lprocfs_oh_clear(&cli->cl_write_offset_hist);
660 LPROC_SEQ_FOPS(osc_rpc_stats);
662 static int osc_stats_seq_show(struct seq_file *seq, void *v)
665 struct obd_device *dev = seq->private;
666 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
668 cfs_gettimeofday(&now);
670 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
671 now.tv_sec, now.tv_usec);
672 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
673 stats->os_lockless_writes);
674 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
675 stats->os_lockless_reads);
676 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
677 stats->os_lockless_truncates);
681 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
682 size_t len, loff_t *off)
684 struct seq_file *seq = file->private_data;
685 struct obd_device *dev = seq->private;
686 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
688 memset(stats, 0, sizeof(*stats));
692 LPROC_SEQ_FOPS(osc_stats);
694 int lproc_osc_attach_seqstat(struct obd_device *dev)
698 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0444,
699 &osc_stats_fops, dev);
701 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
702 &osc_rpc_stats_fops, dev);
706 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
708 lvars->module_vars = lprocfs_osc_module_vars;
709 lvars->obd_vars = lprocfs_osc_obd_vars;