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_cur_dirty_bytes(char *page, char **start, off_t off,
164 int count, int *eof, void *data)
166 struct obd_device *dev = data;
167 struct client_obd *cli = &dev->u.cli;
170 client_obd_list_lock(&cli->cl_loi_list_lock);
171 rc = snprintf(page, count, "%lu\n", cli->cl_dirty);
172 client_obd_list_unlock(&cli->cl_loi_list_lock);
176 static int osc_rd_cur_grant_bytes(char *page, char **start, off_t off,
177 int count, int *eof, void *data)
179 struct obd_device *dev = data;
180 struct client_obd *cli = &dev->u.cli;
183 client_obd_list_lock(&cli->cl_loi_list_lock);
184 rc = snprintf(page, count, "%lu\n", cli->cl_avail_grant);
185 client_obd_list_unlock(&cli->cl_loi_list_lock);
189 static int osc_wr_cur_grant_bytes(struct file *file, const char *buffer,
190 unsigned long count, void *data)
192 struct obd_device *obd = data;
193 struct client_obd *cli = &obd->u.cli;
200 rc = lprocfs_write_u64_helper(buffer, count, &val);
204 /* this is only for shrinking grant */
205 client_obd_list_lock(&cli->cl_loi_list_lock);
206 if (val >= cli->cl_avail_grant) {
207 client_obd_list_unlock(&cli->cl_loi_list_lock);
210 client_obd_list_unlock(&cli->cl_loi_list_lock);
212 LPROCFS_CLIMP_CHECK(obd);
213 if (cli->cl_import->imp_state == LUSTRE_IMP_FULL)
214 rc = osc_shrink_grant_to_target(cli, val);
215 LPROCFS_CLIMP_EXIT(obd);
221 static int osc_rd_cur_lost_grant_bytes(char *page, char **start, off_t off,
222 int count, int *eof, void *data)
224 struct obd_device *dev = data;
225 struct client_obd *cli = &dev->u.cli;
228 client_obd_list_lock(&cli->cl_loi_list_lock);
229 rc = snprintf(page, count, "%lu\n", cli->cl_lost_grant);
230 client_obd_list_unlock(&cli->cl_loi_list_lock);
234 static int osc_rd_grant_shrink_interval(char *page, char **start, off_t off,
235 int count, int *eof, void *data)
237 struct obd_device *obd = data;
241 return snprintf(page, count, "%d\n",
242 obd->u.cli.cl_grant_shrink_interval);
245 static int osc_wr_grant_shrink_interval(struct file *file, const char *buffer,
246 unsigned long count, void *data)
248 struct obd_device *obd = data;
254 rc = lprocfs_write_helper(buffer, count, &val);
261 obd->u.cli.cl_grant_shrink_interval = val;
266 static int osc_rd_create_count(char *page, char **start, off_t off, int count,
267 int *eof, void *data)
269 struct obd_device *obd = data;
274 return snprintf(page, count, "%d\n",
275 obd->u.cli.cl_oscc.oscc_grow_count);
279 * Set OSC creator's osc_creator::oscc_grow_count
281 * \param file proc file
282 * \param buffer buffer containing the value
283 * \param count buffer size
284 * \param data obd device
288 static int osc_wr_create_count(struct file *file, const char *buffer,
289 unsigned long count, void *data)
291 struct obd_device *obd = data;
297 rc = lprocfs_write_helper(buffer, count, &val);
301 /* The MDT ALWAYS needs to limit the precreate count to
302 * OST_MAX_PRECREATE, and the constant cannot be changed
303 * because it is a value shared between the OSC and OST
304 * that is the maximum possible number of objects that will
305 * ever be handled by MDT->OST recovery processing.
307 * If the OST ever gets a request to delete more orphans,
308 * this implies that something has gone badly on the MDT
309 * and the OST will refuse to delete so much data from the
310 * filesystem as a safety measure. */
311 if (val < OST_MIN_PRECREATE || val > OST_MAX_PRECREATE)
313 if (val > obd->u.cli.cl_oscc.oscc_max_grow_count)
316 for (i = 1; (i << 1) <= val; i <<= 1)
318 obd->u.cli.cl_oscc.oscc_grow_count = i;
324 * Read OSC creator's osc_creator::oscc_max_grow_count
326 * \param page buffer to hold the returning string
331 * proc read function parameters, please refer to kernel
332 * code fs/proc/generic.c proc_file_read()
333 * \param data obd device
335 * \retval number of characters printed.
337 static int osc_rd_max_create_count(char *page, char **start, off_t off,
338 int count, int *eof, void *data)
340 struct obd_device *obd = data;
345 return snprintf(page, count, "%d\n",
346 obd->u.cli.cl_oscc.oscc_max_grow_count);
350 * Set OSC creator's osc_creator::oscc_max_grow_count
352 * \param file proc file
353 * \param buffer buffer containing the value
354 * \param count buffer size
355 * \param data obd device
359 static int osc_wr_max_create_count(struct file *file, const char *buffer,
360 unsigned long count, void *data)
362 struct obd_device *obd = data;
368 rc = lprocfs_write_helper(buffer, count, &val);
374 if (val > OST_MAX_PRECREATE)
377 if (obd->u.cli.cl_oscc.oscc_grow_count > val)
378 obd->u.cli.cl_oscc.oscc_grow_count = val;
380 obd->u.cli.cl_oscc.oscc_max_grow_count = val;
385 static int osc_rd_prealloc_next_id(char *page, char **start, off_t off,
386 int count, int *eof, void *data)
388 struct obd_device *obd = data;
393 return snprintf(page, count, LPU64"\n",
394 obd->u.cli.cl_oscc.oscc_next_id);
397 static int osc_rd_prealloc_last_id(char *page, char **start, off_t off,
398 int count, int *eof, void *data)
400 struct obd_device *obd = data;
405 return snprintf(page, count, LPU64"\n",
406 obd->u.cli.cl_oscc.oscc_last_id);
409 static int osc_rd_checksum(char *page, char **start, off_t off, int count,
410 int *eof, void *data)
412 struct obd_device *obd = data;
417 return snprintf(page, count, "%d\n",
418 obd->u.cli.cl_checksum ? 1 : 0);
421 static int osc_wr_checksum(struct file *file, const char *buffer,
422 unsigned long count, void *data)
424 struct obd_device *obd = data;
430 rc = lprocfs_write_helper(buffer, count, &val);
434 obd->u.cli.cl_checksum = (val ? 1 : 0);
439 static int osc_rd_checksum_type(char *page, char **start, off_t off, int count,
440 int *eof, void *data)
442 struct obd_device *obd = data;
449 for (i = 0; i < ARRAY_SIZE(cksum_name) && len < count; i++) {
450 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
452 if (obd->u.cli.cl_cksum_type == (1 << i))
453 len += snprintf(page + len, count - len, "[%s] ",
456 len += snprintf(page + len, count - len, "%s ",
460 len += sprintf(page + len, "\n");
464 static int osc_wd_checksum_type(struct file *file, const char *buffer,
465 unsigned long count, void *data)
467 struct obd_device *obd = data;
475 if (count > sizeof(kernbuf) - 1)
477 if (cfs_copy_from_user(kernbuf, buffer, count))
479 if (count > 0 && kernbuf[count - 1] == '\n')
480 kernbuf[count - 1] = '\0';
482 kernbuf[count] = '\0';
484 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
485 if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
487 if (!strcmp(kernbuf, cksum_name[i])) {
488 obd->u.cli.cl_cksum_type = 1 << i;
495 static int osc_rd_resend_count(char *page, char **start, off_t off, int count,
496 int *eof, void *data)
498 struct obd_device *obd = data;
500 return snprintf(page, count, "%u\n",
501 cfs_atomic_read(&obd->u.cli.cl_resends));
504 static int osc_wr_resend_count(struct file *file, const char *buffer,
505 unsigned long count, void *data)
507 struct obd_device *obd = data;
510 rc = lprocfs_write_helper(buffer, count, &val);
517 cfs_atomic_set(&obd->u.cli.cl_resends, val);
522 static int osc_rd_contention_seconds(char *page, char **start, off_t off,
523 int count, int *eof, void *data)
525 struct obd_device *obd = data;
526 struct osc_device *od = obd2osc_dev(obd);
528 return snprintf(page, count, "%u\n", od->od_contention_time);
531 static int osc_wr_contention_seconds(struct file *file, const char *buffer,
532 unsigned long count, void *data)
534 struct obd_device *obd = data;
535 struct osc_device *od = obd2osc_dev(obd);
537 return lprocfs_write_helper(buffer, count, &od->od_contention_time) ?:
541 static int osc_rd_lockless_truncate(char *page, char **start, off_t off,
542 int count, int *eof, void *data)
544 struct obd_device *obd = data;
545 struct osc_device *od = obd2osc_dev(obd);
547 return snprintf(page, count, "%u\n", od->od_lockless_truncate);
550 static int osc_wr_lockless_truncate(struct file *file, const char *buffer,
551 unsigned long count, void *data)
553 struct obd_device *obd = data;
554 struct osc_device *od = obd2osc_dev(obd);
556 return lprocfs_write_helper(buffer, count, &od->od_lockless_truncate) ?:
560 static int osc_rd_destroys_in_flight(char *page, char **start, off_t off,
561 int count, int *eof, void *data)
563 struct obd_device *obd = data;
564 return snprintf(page, count, "%u\n",
565 cfs_atomic_read(&obd->u.cli.cl_destroy_in_flight));
568 static struct lprocfs_vars lprocfs_osc_obd_vars[] = {
569 { "uuid", lprocfs_rd_uuid, 0, 0 },
570 { "ping", 0, lprocfs_wr_ping, 0, 0, 0222 },
571 { "connect_flags", lprocfs_rd_connect_flags, 0, 0 },
572 { "blocksize", lprocfs_rd_blksize, 0, 0 },
573 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
574 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
575 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
576 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
577 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
578 //{ "filegroups", lprocfs_rd_filegroups, 0, 0 },
579 { "ost_server_uuid", lprocfs_rd_server_uuid, 0, 0 },
580 { "ost_conn_uuid", lprocfs_rd_conn_uuid, 0, 0 },
581 { "active", osc_rd_active,
583 { "max_pages_per_rpc", lprocfs_obd_rd_max_pages_per_rpc,
584 lprocfs_obd_wr_max_pages_per_rpc, 0 },
585 { "max_rpcs_in_flight", osc_rd_max_rpcs_in_flight,
586 osc_wr_max_rpcs_in_flight, 0 },
587 { "destroys_in_flight", osc_rd_destroys_in_flight, 0, 0 },
588 { "max_dirty_mb", osc_rd_max_dirty_mb, osc_wr_max_dirty_mb, 0 },
589 { "cur_dirty_bytes", osc_rd_cur_dirty_bytes, 0, 0 },
590 { "cur_grant_bytes", osc_rd_cur_grant_bytes,
591 osc_wr_cur_grant_bytes, 0 },
592 { "cur_lost_grant_bytes", osc_rd_cur_lost_grant_bytes, 0, 0},
593 { "grant_shrink_interval", osc_rd_grant_shrink_interval,
594 osc_wr_grant_shrink_interval, 0 },
595 { "create_count", osc_rd_create_count, osc_wr_create_count, 0 },
596 { "max_create_count", osc_rd_max_create_count,
597 osc_wr_max_create_count, 0},
598 { "prealloc_next_id", osc_rd_prealloc_next_id, 0, 0 },
599 { "prealloc_last_id", osc_rd_prealloc_last_id, 0, 0 },
600 { "checksums", osc_rd_checksum, osc_wr_checksum, 0 },
601 { "checksum_type", osc_rd_checksum_type, osc_wd_checksum_type, 0 },
602 { "resend_count", osc_rd_resend_count, osc_wr_resend_count, 0},
603 { "timeouts", lprocfs_rd_timeouts, 0, 0 },
604 { "contention_seconds", osc_rd_contention_seconds,
605 osc_wr_contention_seconds, 0 },
606 { "lockless_truncate", osc_rd_lockless_truncate,
607 osc_wr_lockless_truncate, 0 },
608 { "import", lprocfs_rd_import, lprocfs_wr_import, 0 },
609 { "state", lprocfs_rd_state, 0, 0 },
610 { "pinger_recov", lprocfs_rd_pinger_recov,
611 lprocfs_wr_pinger_recov, 0, 0 },
615 static struct lprocfs_vars lprocfs_osc_module_vars[] = {
616 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
620 #define pct(a,b) (b ? a * 100 / b : 0)
622 static int osc_rpc_stats_seq_show(struct seq_file *seq, void *v)
625 struct obd_device *dev = seq->private;
626 struct client_obd *cli = &dev->u.cli;
627 unsigned long read_tot = 0, write_tot = 0, read_cum, write_cum;
630 cfs_gettimeofday(&now);
632 client_obd_list_lock(&cli->cl_loi_list_lock);
634 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
635 now.tv_sec, now.tv_usec);
636 seq_printf(seq, "read RPCs in flight: %d\n",
637 cli->cl_r_in_flight);
638 seq_printf(seq, "write RPCs in flight: %d\n",
639 cli->cl_w_in_flight);
640 seq_printf(seq, "pending write pages: %d\n",
641 cli->cl_pending_w_pages);
642 seq_printf(seq, "pending read pages: %d\n",
643 cli->cl_pending_r_pages);
645 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
646 seq_printf(seq, "pages per rpc rpcs %% cum %% |");
647 seq_printf(seq, " rpcs %% cum %%\n");
649 read_tot = lprocfs_oh_sum(&cli->cl_read_page_hist);
650 write_tot = lprocfs_oh_sum(&cli->cl_write_page_hist);
654 for (i = 0; i < OBD_HIST_MAX; i++) {
655 unsigned long r = cli->cl_read_page_hist.oh_buckets[i];
656 unsigned long w = cli->cl_write_page_hist.oh_buckets[i];
659 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
660 1 << i, r, pct(r, read_tot),
661 pct(read_cum, read_tot), w,
663 pct(write_cum, write_tot));
664 if (read_cum == read_tot && write_cum == write_tot)
668 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
669 seq_printf(seq, "rpcs in flight rpcs %% cum %% |");
670 seq_printf(seq, " rpcs %% cum %%\n");
672 read_tot = lprocfs_oh_sum(&cli->cl_read_rpc_hist);
673 write_tot = lprocfs_oh_sum(&cli->cl_write_rpc_hist);
677 for (i = 0; i < OBD_HIST_MAX; i++) {
678 unsigned long r = cli->cl_read_rpc_hist.oh_buckets[i];
679 unsigned long w = cli->cl_write_rpc_hist.oh_buckets[i];
682 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
683 i, r, pct(r, read_tot),
684 pct(read_cum, read_tot), w,
686 pct(write_cum, write_tot));
687 if (read_cum == read_tot && write_cum == write_tot)
691 seq_printf(seq, "\n\t\t\tread\t\t\twrite\n");
692 seq_printf(seq, "offset rpcs %% cum %% |");
693 seq_printf(seq, " rpcs %% cum %%\n");
695 read_tot = lprocfs_oh_sum(&cli->cl_read_offset_hist);
696 write_tot = lprocfs_oh_sum(&cli->cl_write_offset_hist);
700 for (i = 0; i < OBD_HIST_MAX; i++) {
701 unsigned long r = cli->cl_read_offset_hist.oh_buckets[i];
702 unsigned long w = cli->cl_write_offset_hist.oh_buckets[i];
705 seq_printf(seq, "%d:\t\t%10lu %3lu %3lu | %10lu %3lu %3lu\n",
706 (i == 0) ? 0 : 1 << (i - 1),
707 r, pct(r, read_tot), pct(read_cum, read_tot),
708 w, pct(w, write_tot), pct(write_cum, write_tot));
709 if (read_cum == read_tot && write_cum == write_tot)
713 client_obd_list_unlock(&cli->cl_loi_list_lock);
719 static ssize_t osc_rpc_stats_seq_write(struct file *file, const char *buf,
720 size_t len, loff_t *off)
722 struct seq_file *seq = file->private_data;
723 struct obd_device *dev = seq->private;
724 struct client_obd *cli = &dev->u.cli;
726 lprocfs_oh_clear(&cli->cl_read_rpc_hist);
727 lprocfs_oh_clear(&cli->cl_write_rpc_hist);
728 lprocfs_oh_clear(&cli->cl_read_page_hist);
729 lprocfs_oh_clear(&cli->cl_write_page_hist);
730 lprocfs_oh_clear(&cli->cl_read_offset_hist);
731 lprocfs_oh_clear(&cli->cl_write_offset_hist);
736 LPROC_SEQ_FOPS(osc_rpc_stats);
738 static int osc_stats_seq_show(struct seq_file *seq, void *v)
741 struct obd_device *dev = seq->private;
742 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
744 cfs_gettimeofday(&now);
746 seq_printf(seq, "snapshot_time: %lu.%lu (secs.usecs)\n",
747 now.tv_sec, now.tv_usec);
748 seq_printf(seq, "lockless_write_bytes\t\t"LPU64"\n",
749 stats->os_lockless_writes);
750 seq_printf(seq, "lockless_read_bytes\t\t"LPU64"\n",
751 stats->os_lockless_reads);
752 seq_printf(seq, "lockless_truncate\t\t"LPU64"\n",
753 stats->os_lockless_truncates);
757 static ssize_t osc_stats_seq_write(struct file *file, const char *buf,
758 size_t len, loff_t *off)
760 struct seq_file *seq = file->private_data;
761 struct obd_device *dev = seq->private;
762 struct osc_stats *stats = &obd2osc_dev(dev)->od_stats;
764 memset(stats, 0, sizeof(*stats));
768 LPROC_SEQ_FOPS(osc_stats);
770 int lproc_osc_attach_seqstat(struct obd_device *dev)
774 rc = lprocfs_seq_create(dev->obd_proc_entry, "osc_stats", 0444,
775 &osc_stats_fops, dev);
777 rc = lprocfs_obd_seq_create(dev, "rpc_stats", 0444,
778 &osc_rpc_stats_fops, dev);
782 void lprocfs_osc_init_vars(struct lprocfs_static_vars *lvars)
784 lvars->module_vars = lprocfs_osc_module_vars;
785 lvars->obd_vars = lprocfs_osc_obd_vars;