1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
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_pages_per_rpc(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, "%d\n", cli->cl_max_pages_per_rpc);
91 client_obd_list_unlock(&cli->cl_loi_list_lock);
95 static int osc_wr_max_pages_per_rpc(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 obd_connect_data *ocd = &cli->cl_import->imp_connect_data;
103 rc = lprocfs_write_helper(buffer, count, &val);
107 LPROCFS_CLIMP_CHECK(dev);
108 if (val < 1 || val > ocd->ocd_brw_size >> CFS_PAGE_SHIFT) {
109 LPROCFS_CLIMP_EXIT(dev);
112 client_obd_list_lock(&cli->cl_loi_list_lock);
113 cli->cl_max_pages_per_rpc = val;
114 client_obd_list_unlock(&cli->cl_loi_list_lock);
116 LPROCFS_CLIMP_EXIT(dev);
120 static int osc_rd_max_rpcs_in_flight(char *page, char **start, off_t off,
121 int count, int *eof, void *data)
123 struct obd_device *dev = data;
124 struct client_obd *cli = &dev->u.cli;
127 client_obd_list_lock(&cli->cl_loi_list_lock);
128 rc = snprintf(page, count, "%u\n", cli->cl_max_rpcs_in_flight);
129 client_obd_list_unlock(&cli->cl_loi_list_lock);
133 static int osc_wr_max_rpcs_in_flight(struct file *file, const char *buffer,
134 unsigned long count, void *data)
136 struct obd_device *dev = data;
137 struct client_obd *cli = &dev->u.cli;
138 struct ptlrpc_request_pool *pool = cli->cl_import->imp_rq_pool;
141 rc = lprocfs_write_helper(buffer, count, &val);
145 if (val < 1 || val > OSC_MAX_RIF_MAX)
148 LPROCFS_CLIMP_CHECK(dev);
149 if (pool && val > cli->cl_max_rpcs_in_flight)
150 pool->prp_populate(pool, val-cli->cl_max_rpcs_in_flight);
152 client_obd_list_lock(&cli->cl_loi_list_lock);
153 cli->cl_max_rpcs_in_flight = val;
154 client_obd_list_unlock(&cli->cl_loi_list_lock);
156 LPROCFS_CLIMP_EXIT(dev);
160 static int osc_rd_max_dirty_mb(char *page, char **start, off_t off, int count,
161 int *eof, void *data)
163 struct obd_device *dev = data;
164 struct client_obd *cli = &dev->u.cli;
168 client_obd_list_lock(&cli->cl_loi_list_lock);
169 val = cli->cl_dirty_max;
170 client_obd_list_unlock(&cli->cl_loi_list_lock);
173 return lprocfs_read_frac_helper(page, count, val, mult);
176 static int osc_wr_max_dirty_mb(struct file *file, const char *buffer,
177 unsigned long count, void *data)
179 struct obd_device *dev = data;
180 struct client_obd *cli = &dev->u.cli;
181 int pages_number, mult, rc;
183 mult = 1 << (20 - CFS_PAGE_SHIFT);
184 rc = lprocfs_write_frac_helper(buffer, count, &pages_number, mult);
188 if (pages_number < 0 ||
189 pages_number > OSC_MAX_DIRTY_MB_MAX << (20 - CFS_PAGE_SHIFT) ||
190 pages_number > num_physpages / 4) /* 1/4 of RAM */
193 client_obd_list_lock(&cli->cl_loi_list_lock);
194 cli->cl_dirty_max = (obd_count)(pages_number << CFS_PAGE_SHIFT);
195 osc_wake_cache_waiters(cli);
196 client_obd_list_unlock(&cli->cl_loi_list_lock);
201 static int osc_rd_cur_dirty_bytes(char *page, char **start, off_t off,
202 int count, int *eof, void *data)
204 struct obd_device *dev = data;
205 struct client_obd *cli = &dev->u.cli;
208 client_obd_list_lock(&cli->cl_loi_list_lock);
209 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
210 client_obd_list_unlock(&cli->cl_loi_list_lock);
214 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
215 int count, int *eof, void *data)
217 struct obd_device *dev = data;
218 struct client_obd *cli = &dev->u.cli;
221 client_obd_list_lock(&cli->cl_loi_list_lock);
222 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
223 client_obd_list_unlock(&cli->cl_loi_list_lock);
227 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
228 int *eof, void *data)
230 struct obd_device *obd = data;
235 return snprintf(page, count, "%d\n",
236 obd->u.cli.cl_oscc.oscc_grow_count);
240 * Set OSC creator's osc_creator::oscc_grow_count
242 * \param file proc file
243 * \param buffer buffer containing the value
244 * \param count buffer size
245 * \param data obd device
249 static int osc_wr_create_count(struct file *file, const char *buffer,
250 unsigned long count, void *data)
252 struct obd_device *obd = data;
258 rc = lprocfs_write_helper(buffer, count, &val);
262 /* The MDT ALWAYS needs to limit the precreate count to
263 * OST_MAX_PRECREATE, and the constant cannot be changed
264 * because it is a value shared between the OSC and OST
265 * that is the maximum possible number of objects that will
266 * ever be handled by MDT->OST recovery processing.
268 * If the OST ever gets a request to delete more orphans,
269 * this implies that something has gone badly on the MDT
270 * and the OST will refuse to delete so much data from the
271 * filesystem as a safety measure. */
272 if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
274 if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
277 for (i = 1; (i << 1) <= val; i <<= 1)
279 obd->u.cli.cl_oscc.oscc_grow_count = i;
285 * Read OSC creator's osc_creator::oscc_max_grow_count
287 * \param page buffer to hold the returning string
292 * proc read function parameters, please refer to kernel
293 * code fs/proc/generic.c proc_file_read()
294 * \param data obd device
296 * \retval number of characters printed.
298 static int osc_rd_max_create_count(char *page, char **start, off_t off,
299 int count, int *eof, void *data)
301 struct obd_device *obd = data;
306 return snprintf(page, count, "%d\n",
307 obd->u.cli.cl_oscc.oscc_max_grow_count);
311 * Set OSC creator's osc_creator::oscc_max_grow_count
313 * \param file proc file
314 * \param buffer buffer containing the value
315 * \param count buffer size
316 * \param data obd device
320 static int osc_wr_max_create_count(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);
335 if (val > OST_MAX_PRECREATE)
338 if (obd->u.cli.cl_oscc.oscc_grow_count > val)
339 obd->u.cli.cl_oscc.oscc_grow_count = val;
341 obd->u.cli.cl_oscc.oscc_max_grow_count = val;
346 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
347 int count, int *eof, void *data)
349 struct obd_device *obd = data;
354 return snprintf(page, count, LPU64"\n",
355 obd->u.cli.cl_oscc.oscc_next_id);
358 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
359 int count, int *eof, void *data)
361 struct obd_device *obd = data;
366 return snprintf(page, count, LPU64"\n",
367 obd->u.cli.cl_oscc.oscc_last_id);
370 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
371 int *eof, void *data)
373 struct obd_device *obd = data;
378 return snprintf(page, count, "%d\n",
379 obd->u.cli.cl_checksum ? 1 : 0);
382 static int osc_wr_checksum(struct file *file, const char *buffer,
383 unsigned long count, void *data)
385 struct obd_device *obd = data;
391 rc = lprocfs_write_helper(buffer, count, &val);
395 obd->u.cli.cl_checksum = (val ? 1 : 0);
400 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
401 int *eof, void *data)
403 struct obd_device *obd = data;
410 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
411 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
413 if (obd->u.cli.cl_cksum_type == (1 << i))
414 len += snprintf(page + len, count - len, "[%s] ",
417 len += snprintf(page + len, count - len, "%s ",
421 len += sprintf(page + len, "\n");
425 static int osc_wd_checksum_type(struct file *file, const char *buffer,
426 unsigned long count, void *data)
428 struct obd_device *obd = data;
436 if (count > sizeof(kernbuf) - 1)
438 if (copy_from_user(kernbuf, buffer, count))
440 if (count > 0 && kernbuf[count - 1] == '\n')
441 kernbuf[count - 1] = '\0';
443 kernbuf[count] = '\0';
445 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
446 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
448 if (!strcmp(kernbuf, cksum_name[i])) {
449 obd->u.cli.cl_cksum_type = 1 << i;
456 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
457 int *eof, void *data)
459 struct obd_device *obd = data;
461 return snprintf(page, count, "%u\n", atomic_read(&obd->u.cli.cl_resends));
464 static int osc_wr_resend_count(struct file *file, const char *buffer,
465 unsigned long count, void *data)
467 struct obd_device *obd = data;
470 rc = lprocfs_write_helper(buffer, count, &val);
477 atomic_set(&obd->u.cli.cl_resends, val);
482 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
483 int count, int *eof, void *data)
485 struct obd_device *obd = data;
486 struct osc_device *od = obd2osc_dev(obd);
488 return snprintf(page, count, "%u\n", od->od_contention_time);
491 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
492 unsigned long count, void *data)
494 struct obd_device *obd = data;
495 struct osc_device *od = obd2osc_dev(obd);
497 return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
501 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
502 int count, int *eof, void *data)
504 struct obd_device *obd = data;
505 struct osc_device *od = obd2osc_dev(obd);
507 return snprintf(page, count, "%u\n", od->od_lockless_truncate);
510 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
511 unsigned long count, void *data)
513 struct obd_device *obd = data;
514 struct osc_device *od = obd2osc_dev(obd);
516 return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
520 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
521 { "uuid", lprocfs_rd_uuid, 0, 0 },
522 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
523 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
524 { "blocksize", lprocfs_rd_blksize, 0, 0 },
525 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
526 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
527 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
528 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
529 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
530 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
531 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
532 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
533 { "active", osc_rd_active,
535 { "max_pages_per_rpc", osc_rd_max_pages_per_rpc,
536 osc_wr_max_pages_per_rpc, 0 },
537 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
538 osc_wr_max_rpcs_in_flight, 0 },
539 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
540 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
541 { "cur_grant_bytes", osc_rd_cur_grant_bytes, 0, 0 },
542 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
543 { "max_create_count", osc_rd_max_create_count,
544 osc_wr_max_create_count, 0},
545 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
546 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
547 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
548 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
549 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
550 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
551 { "contention_seconds", osc_rd_contention_seconds,
552 osc_wr_contention_seconds, 0 },
553 { "lockless_truncate", osc_rd_lockless_truncate,
554 osc_wr_lockless_truncate, 0 },
555 { "import", lprocfs_rd_import, 0, 0 },
556 { "state", lprocfs_rd_state, 0, 0 },
560 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
561 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
565 #define pct(a,b) (b ? a * 100 / b : 0)
567 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
570 struct obd_device *dev = seq->private;
571 struct client_obd *cli = &dev->u.cli;
572 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
575 do_gettimeofday(&now);
577 client_obd_list_lock(&cli->cl_loi_list_lock);
579 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
580 now.tv_sec, now.tv_usec);
581 seq_printf(seq, "read RPCs in flight: %d\n",
582 cli->cl_r_in_flight);
583 seq_printf(seq, "write RPCs in flight: %d\n",
584 cli->cl_w_in_flight);
585 seq_printf(seq, "pending write pages: %d\n",
586 cli->cl_pending_w_pages);
587 seq_printf(seq, "pending read pages: %d\n",
588 cli->cl_pending_r_pages);
590 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
591 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
592 seq_printf(seq, " rpcs %% cum %%\n");
594 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
595 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
599 for (i = 0; i < OBD_HIST_MAX; i++) {
600 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
601 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
604 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
605 1 << i, r, pct(r, read_tot),
606 pct(read_cum, read_tot), w,
608 pct(write_cum, write_tot));
609 if (read_cum == read_tot && write_cum == write_tot)
613 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
614 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
615 seq_printf(seq, " rpcs %% cum %%\n");
617 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
618 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
622 for (i = 0; i < OBD_HIST_MAX; i++) {
623 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
624 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
627 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
628 i, r, pct(r, read_tot),
629 pct(read_cum, read_tot), w,
631 pct(write_cum, write_tot));
632 if (read_cum == read_tot && write_cum == write_tot)
636 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
637 seq_printf(seq, "offset rpcs %% cum %% |");
638 seq_printf(seq, " rpcs %% cum %%\n");
640 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
641 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
645 for (i = 0; i < OBD_HIST_MAX; i++) {
646 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
647 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
650 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
651 (i == 0) ? 0 : 1 << (i - 1),
652 r, pct(r, read_tot), pct(read_cum, read_tot),
653 w, pct(w, write_tot), pct(write_cum, write_tot));
654 if (read_cum == read_tot && write_cum == write_tot)
658 client_obd_list_unlock(&cli->cl_loi_list_lock);
664 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
665 size_t len, loff_t *off)
667 struct seq_file *seq = file->private_data;
668 struct obd_device *dev = seq->private;
669 struct client_obd *cli = &dev->u.cli;
671 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
672 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
673 lprocfs_oh_clear(&cli->cl_read_page_hist);
674 lprocfs_oh_clear(&cli->cl_write_page_hist);
675 lprocfs_oh_clear(&cli->cl_read_offset_hist);
676 lprocfs_oh_clear(&cli->cl_write_offset_hist);
681 LPROC_SEQ_FOPS(osc_rpc_stats);
683 static int osc_stats_seq_show(struct seq_file *seq, void *v)
686 struct obd_device *dev = seq->private;
687 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
689 do_gettimeofday(&now);
691 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
692 now.tv_sec, now.tv_usec);
693 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
694 stats->os_lockless_writes);
695 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
696 stats->os_lockless_reads);
697 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
698 stats->os_lockless_truncates);
702 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
703 size_t len, loff_t *off)
705 struct seq_file *seq = file->private_data;
706 struct obd_device *dev = seq->private;
707 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
709 memset(stats, 0, sizeof(*stats));
713 LPROC_SEQ_FOPS(osc_stats);
715 int lproc_osc_attach_seqstat(struct obd_device *dev)
719 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0444,
720 &osc_stats_fops, dev);
722 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
723 &osc_rpc_stats_fops, dev);
727 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
729 lvars->module_vars = lprocfs_osc_module_vars;
730 lvars->obd_vars = lprocfs_osc_obd_vars;