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, 2012, 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 - CFS_PAGE_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 - CFS_PAGE_SHIFT) ||
150 pages_number > cfs_num_physpages / 4) /* 1/4 of RAM */
153 client_obd_list_lock(&cli->cl_loi_list_lock);
154 cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_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 - CFS_PAGE_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 - CFS_PAGE_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;
198 (void)osc_lru_shrink(cli, rc);
203 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
204 int count, int *eof, void *data)
206 struct obd_device *dev = data;
207 struct client_obd *cli = &dev->u.cli;
210 client_obd_list_lock(&cli->cl_loi_list_lock);
211 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
212 client_obd_list_unlock(&cli->cl_loi_list_lock);
216 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
217 int count, int *eof, void *data)
219 struct obd_device *dev = data;
220 struct client_obd *cli = &dev->u.cli;
223 client_obd_list_lock(&cli->cl_loi_list_lock);
224 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
225 client_obd_list_unlock(&cli->cl_loi_list_lock);
229 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
230 unsigned long count, void *data)
232 struct obd_device *obd = data;
233 struct client_obd *cli = &obd->u.cli;
240 rc = lprocfs_write_u64_helper(buffer, count, &val);
244 /* this is only for shrinking grant */
245 client_obd_list_lock(&cli->cl_loi_list_lock);
246 if (val >= cli->cl_avail_grant) {
247 client_obd_list_unlock(&cli->cl_loi_list_lock);
250 client_obd_list_unlock(&cli->cl_loi_list_lock);
252 LPROCFS_CLIMP_CHECK(obd);
253 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
254 rc = osc_shrink_grant_to_target(cli, val);
255 LPROCFS_CLIMP_EXIT(obd);
261 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
262 int count, int *eof, void *data)
264 struct obd_device *dev = data;
265 struct client_obd *cli = &dev->u.cli;
268 client_obd_list_lock(&cli->cl_loi_list_lock);
269 rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
270 client_obd_list_unlock(&cli->cl_loi_list_lock);
274 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
275 int count, int *eof, void *data)
277 struct obd_device *obd = data;
281 return snprintf(page, count, "%d\n",
282 obd->u.cli.cl_grant_shrink_interval);
285 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
286 unsigned long count, void *data)
288 struct obd_device *obd = data;
294 rc = lprocfs_write_helper(buffer, count, &val);
301 obd->u.cli.cl_grant_shrink_interval = val;
306 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
307 int *eof, void *data)
309 struct obd_device *obd = data;
314 return snprintf(page, count, "%d\n",
315 obd->u.cli.cl_checksum ? 1 : 0);
318 static int osc_wr_checksum(struct file *file, const char *buffer,
319 unsigned long count, void *data)
321 struct obd_device *obd = data;
327 rc = lprocfs_write_helper(buffer, count, &val);
331 obd->u.cli.cl_checksum = (val ? 1 : 0);
336 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
337 int *eof, void *data)
339 struct obd_device *obd = data;
346 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
347 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
349 if (obd->u.cli.cl_cksum_type == (1 << i))
350 len += snprintf(page + len, count - len, "[%s] ",
353 len += snprintf(page + len, count - len, "%s ",
357 len += sprintf(page + len, "\n");
361 static int osc_wd_checksum_type(struct file *file, const char *buffer,
362 unsigned long count, void *data)
364 struct obd_device *obd = data;
372 if (count > sizeof(kernbuf) - 1)
374 if (cfs_copy_from_user(kernbuf, buffer, count))
376 if (count > 0 && kernbuf[count - 1] == '\n')
377 kernbuf[count - 1] = '\0';
379 kernbuf[count] = '\0';
381 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
382 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
384 if (!strcmp(kernbuf, cksum_name[i])) {
385 obd->u.cli.cl_cksum_type = 1 << i;
392 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
393 int *eof, void *data)
395 struct obd_device *obd = data;
397 return snprintf(page, count, "%u\n",
398 cfs_atomic_read(&obd->u.cli.cl_resends));
401 static int osc_wr_resend_count(struct file *file, const char *buffer,
402 unsigned long count, void *data)
404 struct obd_device *obd = data;
407 rc = lprocfs_write_helper(buffer, count, &val);
414 cfs_atomic_set(&obd->u.cli.cl_resends, val);
419 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
420 int count, int *eof, void *data)
422 struct obd_device *obd = data;
423 struct osc_device *od = obd2osc_dev(obd);
425 return snprintf(page, count, "%u\n", od->od_contention_time);
428 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
429 unsigned long count, void *data)
431 struct obd_device *obd = data;
432 struct osc_device *od = obd2osc_dev(obd);
434 return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
438 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
439 int count, int *eof, void *data)
441 struct obd_device *obd = data;
442 struct osc_device *od = obd2osc_dev(obd);
444 return snprintf(page, count, "%u\n", od->od_lockless_truncate);
447 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
448 unsigned long count, void *data)
450 struct obd_device *obd = data;
451 struct osc_device *od = obd2osc_dev(obd);
453 return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
457 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
458 int count, int *eof, void *data)
460 struct obd_device *obd = data;
461 return snprintf(page, count, "%u\n",
462 cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
465 static int lprocfs_osc_wr_max_pages_per_rpc(struct file *file,
466 const char *buffer, unsigned long count, void *data)
468 struct obd_device *dev = data;
469 struct client_obd *cli = &dev->u.cli;
470 struct obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
474 rc = lprocfs_write_u64_helper(buffer, count, &val);
478 /* if the max_pages is specified in bytes, convert to pages */
479 if (val >= ONE_MB_BRW_SIZE)
480 val >>= CFS_PAGE_SHIFT;
482 LPROCFS_CLIMP_CHECK(dev);
484 chunk_mask = ~((1 << (cli->cl_chunkbits - CFS_PAGE_SHIFT)) - 1);
485 /* max_pages_per_rpc must be chunk aligned */
486 val = (val + ~chunk_mask) & chunk_mask;
487 if (val == 0 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
488 LPROCFS_CLIMP_EXIT(dev);
491 client_obd_list_lock(&cli->cl_loi_list_lock);
492 cli->cl_max_pages_per_rpc = val;
493 client_obd_list_unlock(&cli->cl_loi_list_lock);
495 LPROCFS_CLIMP_EXIT(dev);
499 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
500 { "uuid", lprocfs_rd_uuid, 0, 0 },
501 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
502 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
503 { "blocksize", lprocfs_rd_blksize, 0, 0 },
504 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
505 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
506 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
507 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
508 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
509 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
510 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
511 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
512 { "active", osc_rd_active,
514 { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
515 lprocfs_osc_wr_max_pages_per_rpc, 0 },
516 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
517 osc_wr_max_rpcs_in_flight, 0 },
518 { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
519 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
520 { "osc_cached_mb", osc_rd_cached_mb, osc_wr_cached_mb, 0 },
521 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
522 { "cur_grant_bytes", osc_rd_cur_grant_bytes,
523 osc_wr_cur_grant_bytes, 0 },
524 { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
525 { "grant_shrink_interval", osc_rd_grant_shrink_interval,
526 osc_wr_grant_shrink_interval, 0 },
527 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
528 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
529 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
530 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
531 { "contention_seconds", osc_rd_contention_seconds,
532 osc_wr_contention_seconds, 0 },
533 { "lockless_truncate", osc_rd_lockless_truncate,
534 osc_wr_lockless_truncate, 0 },
535 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
536 { "state", lprocfs_rd_state, 0, 0 },
537 { "pinger_recov", lprocfs_rd_pinger_recov,
538 lprocfs_wr_pinger_recov, 0, 0 },
542 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
543 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
547 #define pct(a,b) (b ? a * 100 / b : 0)
549 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
552 struct obd_device *dev = seq->private;
553 struct client_obd *cli = &dev->u.cli;
554 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
557 cfs_gettimeofday(&now);
559 client_obd_list_lock(&cli->cl_loi_list_lock);
561 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
562 now.tv_sec, now.tv_usec);
563 seq_printf(seq, "read RPCs in flight: %d\n",
564 cli->cl_r_in_flight);
565 seq_printf(seq, "write RPCs in flight: %d\n",
566 cli->cl_w_in_flight);
567 seq_printf(seq, "pending write pages: %d\n",
568 cfs_atomic_read(&cli->cl_pending_w_pages));
569 seq_printf(seq, "pending read pages: %d\n",
570 cfs_atomic_read(&cli->cl_pending_r_pages));
572 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
573 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
574 seq_printf(seq, " rpcs %% cum %%\n");
576 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
577 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
581 for (i = 0; i < OBD_HIST_MAX; i++) {
582 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
583 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
586 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
587 1 << i, r, pct(r, read_tot),
588 pct(read_cum, read_tot), w,
590 pct(write_cum, write_tot));
591 if (read_cum == read_tot && write_cum == write_tot)
595 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
596 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
597 seq_printf(seq, " rpcs %% cum %%\n");
599 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
600 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
604 for (i = 0; i < OBD_HIST_MAX; i++) {
605 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
606 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
609 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
610 i, r, pct(r, read_tot),
611 pct(read_cum, read_tot), w,
613 pct(write_cum, write_tot));
614 if (read_cum == read_tot && write_cum == write_tot)
618 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
619 seq_printf(seq, "offset rpcs %% cum %% |");
620 seq_printf(seq, " rpcs %% cum %%\n");
622 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
623 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
627 for (i = 0; i < OBD_HIST_MAX; i++) {
628 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
629 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
632 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
633 (i == 0) ? 0 : 1 << (i - 1),
634 r, pct(r, read_tot), pct(read_cum, read_tot),
635 w, pct(w, write_tot), pct(write_cum, write_tot));
636 if (read_cum == read_tot && write_cum == write_tot)
640 client_obd_list_unlock(&cli->cl_loi_list_lock);
646 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
647 size_t len, loff_t *off)
649 struct seq_file *seq = file->private_data;
650 struct obd_device *dev = seq->private;
651 struct client_obd *cli = &dev->u.cli;
653 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
654 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
655 lprocfs_oh_clear(&cli->cl_read_page_hist);
656 lprocfs_oh_clear(&cli->cl_write_page_hist);
657 lprocfs_oh_clear(&cli->cl_read_offset_hist);
658 lprocfs_oh_clear(&cli->cl_write_offset_hist);
663 LPROC_SEQ_FOPS(osc_rpc_stats);
665 static int osc_stats_seq_show(struct seq_file *seq, void *v)
668 struct obd_device *dev = seq->private;
669 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
671 cfs_gettimeofday(&now);
673 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
674 now.tv_sec, now.tv_usec);
675 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
676 stats->os_lockless_writes);
677 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
678 stats->os_lockless_reads);
679 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
680 stats->os_lockless_truncates);
684 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
685 size_t len, loff_t *off)
687 struct seq_file *seq = file->private_data;
688 struct obd_device *dev = seq->private;
689 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
691 memset(stats, 0, sizeof(*stats));
695 LPROC_SEQ_FOPS(osc_stats);
697 int lproc_osc_attach_seqstat(struct obd_device *dev)
701 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0644,
702 &osc_stats_fops, dev);
704 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0644,
705 &osc_rpc_stats_fops, dev);
710 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
712 lvars->module_vars = lprocfs_osc_module_vars;
713 lvars->obd_vars = lprocfs_osc_obd_vars;