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) 2007, 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 * lustre/include/lprocfs_status.h
38 * Top level header file for LProc SNMP
40 * Author: Hariharan Thantry thantry@users.sourceforge.net
42 #ifndef _LPROCFS_SNMP_H
43 #define _LPROCFS_SNMP_H
45 #if defined(__linux__)
46 #include <linux/lprocfs_status.h>
48 #error Unsupported operating system.
50 #include <lustre/lustre_idl.h>
51 #include <libcfs/params_tree.h>
53 #ifndef HAVE_ONLY_PROCFS_SEQ
56 read_proc_t *read_fptr;
57 write_proc_t *write_fptr;
59 const struct file_operations *fops;
66 struct lprocfs_static_vars {
67 struct lprocfs_vars *module_vars;
68 struct lprocfs_vars *obd_vars;
73 struct lprocfs_seq_vars {
75 const struct file_operations *fops;
83 /* if we find more consumers this could be generalized */
84 #define OBD_HIST_MAX 32
85 struct obd_histogram {
87 unsigned long oh_buckets[OBD_HIST_MAX];
100 BRW_W_DISCONT_BLOCKS,
109 struct obd_histogram hist[BRW_LAST];
113 RENAME_SAMEDIR_SIZE = 0,
114 RENAME_CROSSDIR_SRC_SIZE,
115 RENAME_CROSSDIR_TGT_SIZE,
119 struct rename_stats {
120 struct obd_histogram hist[RENAME_LAST];
123 /* An lprocfs counter can be configured using the enum bit masks below.
125 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
126 * protects this counter from concurrent updates. If not specified,
127 * lprocfs an internal per-counter lock variable. External locks are
128 * not used to protect counter increments, but are used to protect
129 * counter readout and resets.
131 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
132 * (i.e. counter can be incremented by more than "1"). When specified,
133 * the counter maintains min, max and sum in addition to a simple
134 * invocation count. This allows averages to be be computed.
135 * If not specified, the counter is an increment-by-1 counter.
136 * min, max, sum, etc. are not maintained.
138 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
139 * squares (for multi-valued counter samples only). This allows
140 * external computation of standard deviation, but involves a 64-bit
141 * multiply per counter increment.
145 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
146 LPROCFS_CNTR_AVGMINMAX = 0x0002,
147 LPROCFS_CNTR_STDDEV = 0x0004,
149 /* counter data type */
150 LPROCFS_TYPE_REGS = 0x0100,
151 LPROCFS_TYPE_BYTES = 0x0200,
152 LPROCFS_TYPE_PAGES = 0x0400,
153 LPROCFS_TYPE_CYCLE = 0x0800,
156 #define LC_MIN_INIT ((~(__u64)0) >> 1)
158 struct lprocfs_counter_header {
159 unsigned int lc_config;
160 const char *lc_name; /* must be static */
161 const char *lc_units; /* must be static */
164 struct lprocfs_counter {
170 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
171 * for irq context counter, i.e. stats with
172 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
175 __s64 lc_array_sum[1];
177 #define lc_sum lc_array_sum[0]
178 #define lc_sum_irq lc_array_sum[1]
180 struct lprocfs_percpu {
184 struct lprocfs_counter lp_cntr[0];
187 #define LPROCFS_GET_NUM_CPU 0x0001
188 #define LPROCFS_GET_SMP_ID 0x0002
190 enum lprocfs_stats_flags {
191 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
192 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
193 * area and need locking */
194 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
197 enum lprocfs_fields_flags {
198 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
199 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
200 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
201 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
202 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
203 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
204 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
207 struct lprocfs_stats {
209 unsigned short ls_num;
210 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
211 unsigned short ls_biggest_alloc_num;
212 enum lprocfs_stats_flags ls_flags;
213 /* Lock used when there are no percpu stats areas; For percpu stats,
214 * it is used to protect ls_biggest_alloc_num change */
217 /* has ls_num of counter headers */
218 struct lprocfs_counter_header *ls_cnt_header;
219 struct lprocfs_percpu *ls_percpu[0];
222 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
224 /* Pack all opcodes down into a single monotonically increasing index */
225 static inline int opcode_offset(__u32 opc) {
226 if (opc < OST_LAST_OPC) {
228 return (opc - OST_FIRST_OPC);
229 } else if (opc < MDS_LAST_OPC) {
231 return (opc - MDS_FIRST_OPC +
233 } else if (opc < LDLM_LAST_OPC) {
235 return (opc - LDLM_FIRST_OPC +
238 } else if (opc < MGS_LAST_OPC) {
240 return (opc - MGS_FIRST_OPC +
244 } else if (opc < OBD_LAST_OPC) {
246 return (opc - OBD_FIRST_OPC +
251 } else if (opc < LLOG_LAST_OPC) {
253 return (opc - LLOG_FIRST_OPC +
259 } else if (opc < QUOTA_LAST_OPC) {
261 return (opc - QUOTA_FIRST_OPC +
268 } else if (opc < SEQ_LAST_OPC) {
270 return (opc - SEQ_FIRST_OPC +
278 } else if (opc < SEC_LAST_OPC) {
280 return (opc - SEC_FIRST_OPC +
289 } else if (opc < FLD_LAST_OPC) {
291 return (opc - FLD_FIRST_OPC +
301 } else if (opc < OUT_UPDATE_LAST_OPC) {
303 return (opc - OUT_UPDATE_FIRST_OPC +
314 } else if (opc < LFSCK_LAST_OPC) {
316 return (opc - LFSCK_FIRST_OPC +
317 OPC_RANGE(OUT_UPDATE) +
335 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
345 OPC_RANGE(OUT_UPDATE) + \
348 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
352 PTLRPC_REQWAIT_CNTR = 0,
353 PTLRPC_REQQDEPTH_CNTR,
354 PTLRPC_REQACTIVE_CNTR,
356 PTLRPC_REQBUF_AVAIL_CNTR,
360 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
363 LDLM_GLIMPSE_ENQUEUE = 0,
380 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
382 extern cfs_proc_dir_entry_t *proc_lustre_root;
385 struct obd_histogram;
387 /* Days / hours / mins / seconds format */
391 static inline void s2dhms(struct dhms *ts, time_t secs)
393 ts->d = secs / 86400;
400 #define DHMS_FMT "%dd%dh%02dm%02ds"
401 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
403 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
404 #define JOBSTATS_DISABLE "disable"
405 #define JOBSTATS_PROCNAME_UID "procname_uid"
407 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
409 struct obd_job_stats {
410 cfs_hash_t *ojs_hash;
411 struct list_head ojs_list;
412 rwlock_t ojs_lock; /* protect the obj_list */
413 cntr_init_callback ojs_cntr_init_fn;
415 int ojs_cleanup_interval;
416 time_t ojs_last_cleanup;
421 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
425 * < 0 : on error (only possible for opc as LPROCFS_GET_SMP_ID)
427 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int opc,
428 unsigned long *flags)
436 case LPROCFS_GET_SMP_ID:
437 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
438 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
439 spin_lock_irqsave(&stats->ls_lock, *flags);
441 spin_lock(&stats->ls_lock);
444 unsigned int cpuid = get_cpu();
446 if (unlikely(stats->ls_percpu[cpuid] == NULL)) {
447 rc = lprocfs_stats_alloc_one(stats, cpuid);
456 case LPROCFS_GET_NUM_CPU:
457 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
458 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
459 spin_lock_irqsave(&stats->ls_lock, *flags);
461 spin_lock(&stats->ls_lock);
464 return stats->ls_biggest_alloc_num;
469 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc,
470 unsigned long *flags)
476 case LPROCFS_GET_SMP_ID:
477 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
478 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
479 spin_unlock_irqrestore(&stats->ls_lock,
482 spin_unlock(&stats->ls_lock);
489 case LPROCFS_GET_NUM_CPU:
490 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
491 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) {
492 spin_unlock_irqrestore(&stats->ls_lock,
495 spin_unlock(&stats->ls_lock);
502 static inline unsigned int
503 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
505 unsigned int percpusize;
507 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
509 /* irq safe stats need lc_array_sum[1] */
510 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
511 percpusize += stats->ls_num * sizeof(__s64);
513 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
514 percpusize = L1_CACHE_ALIGN(percpusize);
519 static inline struct lprocfs_counter *
520 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
523 struct lprocfs_counter *cntr;
525 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
527 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
528 cntr = (void *)cntr + index * sizeof(__s64);
533 /* Two optimized LPROCFS counter increment functions are provided:
534 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
535 * lprocfs_counter_add(cntr) - use for multi-valued counters
536 * Counter data layout allows config flag, counter lock and the
537 * count itself to reside within a single cache line.
540 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
542 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
545 #define lprocfs_counter_incr(stats, idx) \
546 lprocfs_counter_add(stats, idx, 1)
547 #define lprocfs_counter_decr(stats, idx) \
548 lprocfs_counter_sub(stats, idx, 1)
550 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
551 struct lprocfs_counter_header *header,
552 enum lprocfs_stats_flags flags,
553 enum lprocfs_fields_flags field);
554 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
556 enum lprocfs_fields_flags field)
559 unsigned int num_cpu;
560 unsigned long flags = 0;
563 LASSERT(stats != NULL);
565 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
566 for (i = 0; i < num_cpu; i++) {
567 if (stats->ls_percpu[i] == NULL)
569 ret += lprocfs_read_helper(
570 lprocfs_stats_counter_get(stats, i, idx),
571 &stats->ls_cnt_header[idx], stats->ls_flags,
574 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
578 extern struct lprocfs_stats *
579 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
580 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
581 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
582 extern void lprocfs_init_ops_stats(int num_private_stats,
583 struct lprocfs_stats *stats);
584 extern void lprocfs_init_mps_stats(int num_private_stats,
585 struct lprocfs_stats *stats);
586 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
587 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
588 unsigned int num_private_stats);
589 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
590 unsigned int num_private_stats);
591 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
592 unsigned conf, const char *name,
594 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
595 extern void lprocfs_free_md_stats(struct obd_device *obddev);
598 extern int lprocfs_add_clear_entry(struct obd_device * obd,
599 cfs_proc_dir_entry_t *entry);
600 #ifdef HAVE_SERVER_SUPPORT
601 extern int lprocfs_exp_setup(struct obd_export *exp,
602 lnet_nid_t *peer_nid, int *newnid);
603 extern int lprocfs_exp_cleanup(struct obd_export *exp);
605 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
608 extern struct proc_dir_entry *
609 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
610 #ifndef HAVE_ONLY_PROCFS_SEQ
611 read_proc_t *read_proc, write_proc_t *write_proc,
613 void *data, const struct file_operations *fops);
614 extern struct proc_dir_entry *
615 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
616 const char *format, ...);
617 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
618 #ifdef HAVE_SERVER_SUPPORT
619 #ifndef HAVE_ONLY_PROCFS_SEQ
621 lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
622 unsigned long count, void *data);
623 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
624 int count, int *eof, void *data);
627 lprocfs_nid_stats_clear_seq_write(struct file *file, const char *buffer,
628 size_t count, loff_t *off);
629 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
631 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
632 struct lprocfs_stats *stats);
634 /* lprocfs_status.c */
635 #ifndef HAVE_ONLY_PROCFS_SEQ
636 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
637 struct lprocfs_vars *var,
640 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
641 cfs_proc_dir_entry_t *parent,
642 struct lprocfs_vars *list,
645 extern int lprocfs_seq_add_vars(cfs_proc_dir_entry_t *root,
646 struct lprocfs_seq_vars *var,
649 extern cfs_proc_dir_entry_t *
650 lprocfs_seq_register(const char *name, cfs_proc_dir_entry_t *parent,
651 struct lprocfs_seq_vars *list, void *data);
652 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
653 extern void lprocfs_remove_proc_entry(const char *name,
654 struct proc_dir_entry *parent);
655 #ifndef HAVE_ONLY_PROCFS_SEQ
656 extern void lprocfs_try_remove_proc_entry(const char *name,
657 struct proc_dir_entry *parent);
659 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
661 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
663 extern int lprocfs_seq_obd_setup(struct obd_device *dev);
664 extern int lprocfs_obd_cleanup(struct obd_device *obd);
665 #ifdef HAVE_SERVER_SUPPORT
666 extern const struct file_operations lprocfs_evict_client_fops;
668 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
670 const struct file_operations *seq_fops,
672 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
674 const struct file_operations *seq_fops,
677 /* Generic callbacks */
678 #ifndef HAVE_ONLY_PROCFS_SEQ
679 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
680 int count, int *eof, void *data);
681 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
682 int count, int *eof, void *data);
683 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
684 unsigned long count, void *data);
685 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
686 int count, int *eof, void *data);
687 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
688 int count, int *eof, void *data);
689 extern int lprocfs_rd_name(char *page, char **start, off_t off,
690 int count, int *eof, void *data);
691 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
692 int count, int *eof, void *data);
693 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
694 int count, int *eof, void *data);
695 extern int lprocfs_rd_import(char *page, char **start, off_t off, int count,
696 int *eof, void *data);
697 extern int lprocfs_rd_state(char *page, char **start, off_t off, int count,
698 int *eof, void *data);
699 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
700 int count, int *eof, void *data);
701 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
702 int count, int *eof, void *data);
703 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
704 int count, int *eof, void *data);
706 extern int lprocfs_u64_seq_show(struct seq_file *m, void *data);
707 extern int lprocfs_atomic_seq_show(struct seq_file *m, void *data);
708 extern ssize_t lprocfs_atomic_seq_write(struct file *file, const char *buffer,
709 size_t count, loff_t *off);
710 extern int lprocfs_uint_seq_show(struct seq_file *m, void *data);
711 extern ssize_t lprocfs_uint_seq_write(struct file *file, const char *buffer,
712 size_t count, loff_t *off);
713 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
714 unsigned long count, void *data);
715 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
716 extern int lprocfs_name_seq_show(struct seq_file *m, void *data);
717 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
718 extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data);
719 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
720 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
721 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
722 #ifdef HAVE_SERVER_SUPPORT
723 extern int lprocfs_num_exports_seq_show(struct seq_file *m, void *data);
725 struct adaptive_timeout;
726 #ifndef HAVE_ONLY_PROCFS_SEQ
727 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
728 struct adaptive_timeout *at);
729 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
730 int count, int *eof, void *data);
731 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
732 unsigned long count, void *data);
734 extern int lprocfs_seq_at_hist_helper(struct seq_file *m,
735 struct adaptive_timeout *at);
736 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
738 lprocfs_timeouts_seq_write(struct file *file, const char *buffer,
739 size_t count, loff_t *off);
740 #ifndef HAVE_ONLY_PROCFS_SEQ
741 #ifdef HAVE_SERVER_SUPPORT
742 extern ssize_t lprocfs_fops_read(struct file *f, char __user *buf,
743 size_t size, loff_t *ppos);
744 extern ssize_t lprocfs_fops_write(struct file *f, const char __user *buf,
745 size_t size, loff_t *ppos);
746 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
747 unsigned long count, void *data);
749 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
750 unsigned long count, void *data);
751 extern int lprocfs_wr_import(struct file *file, const char *buffer,
752 unsigned long count, void *data);
753 extern int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
754 int count, int *eof, void *data);
755 extern int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
756 unsigned long count, void *data);
758 #ifdef HAVE_SERVER_SUPPORT
760 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
761 size_t count, loff_t *off);
764 lprocfs_ping_seq_write(struct file *file, const char *buffer,
765 size_t count, loff_t *off);
767 lprocfs_import_seq_write(struct file *file, const char *buffer,
768 size_t count, loff_t *off);
769 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
771 lprocfs_pinger_recov_seq_write(struct file *file, const char *buffer,
772 size_t count, loff_t *off);
775 #ifndef HAVE_ONLY_PROCFS_SEQ
776 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
777 int count, int *eof, void *data);
778 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
779 int count, int *eof, void *data);
780 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
781 int count, int *eof, void *data);
782 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
783 int count, int *eof, void *data);
784 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
785 int count, int *eof, void *data);
786 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
787 int count, int *eof, void *data);
788 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
789 int count, int *eof, void *data);
791 extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data);
792 extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data);
793 extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data);
794 extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data);
795 extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data);
796 extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data);
798 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
800 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
802 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
803 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
805 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
807 extern int lprocfs_write_frac_u64_helper(const char *buffer,
809 __u64 *val, int mult);
810 char *lprocfs_find_named_value(const char *buffer, const char *name,
812 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
813 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
814 void lprocfs_oh_clear(struct obd_histogram *oh);
815 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
817 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
818 struct lprocfs_counter *cnt);
820 #ifdef HAVE_SERVER_SUPPORT
821 #ifndef HAVE_ONLY_PROCFS_SEQ
822 /* lprocfs_status.c: recovery status */
823 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
824 int count, int *eof, void *data);
825 /* lprocfs_statuc.c: hash statistics */
826 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
827 int count, int *eof, void *data);
829 /* lprocfs_status.c: IR factor */
830 int lprocfs_obd_rd_ir_factor(char *page, char **start, off_t off,
831 int count, int *eof, void *data);
832 int lprocfs_obd_wr_ir_factor(struct file *file, const char *buffer,
833 unsigned long count, void *data);
835 /* lprocfs_status.c: recovery status */
836 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
838 /* lprocfs_status.c: hash statistics */
839 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
841 /* lprocfs_status.c: IR factor */
842 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
844 lprocfs_ir_factor_seq_write(struct file *file, const char *buffer,
845 size_t count, loff_t *off);
847 extern int lprocfs_single_release(cfs_inode_t *, struct file *);
848 extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
850 /* You must use these macros when you want to refer to
851 * the import in a client obd_device for a lprocfs entry */
852 #define LPROCFS_CLIMP_CHECK(obd) do { \
853 typecheck(struct obd_device *, obd); \
854 down_read(&(obd)->u.cli.cl_sem); \
855 if ((obd)->u.cli.cl_import == NULL) { \
856 up_read(&(obd)->u.cli.cl_sem); \
860 #define LPROCFS_CLIMP_EXIT(obd) \
861 up_read(&(obd)->u.cli.cl_sem);
863 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
864 proc entries; otherwise, you will define name##_seq_write function also for
865 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
866 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
867 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
868 static int name##_single_open(cfs_inode_t *inode, struct file *file) \
870 LPROCFS_ENTRY_CHECK(PDE(inode)); \
871 return single_open(file, name##_seq_show, PDE_DATA(inode)); \
873 struct file_operations name##_fops = { \
874 .owner = THIS_MODULE, \
875 .open = name##_single_open, \
877 .write = custom_seq_write, \
878 .llseek = seq_lseek, \
879 .release = lprocfs_single_release, \
882 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
883 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
885 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
886 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
888 return lprocfs_##type##_seq_show(m, m->private); \
890 LPROC_SEQ_FOPS_RO(name##_##type)
892 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
893 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
895 return lprocfs_##type##_seq_show(m, m->private); \
897 static ssize_t name##_##type##_seq_write(struct file *file, \
898 const char *buffer, size_t count, loff_t *off) \
900 struct seq_file *seq = file->private_data; \
901 return lprocfs_##type##_seq_write(file, buffer, \
902 count, seq->private); \
904 LPROC_SEQ_FOPS(name##_##type);
906 #define LPROC_SEQ_FOPS_WO_TYPE(name, type) \
907 static ssize_t name##_##type##_write(struct file *file, \
908 const char *buffer, size_t count, loff_t *off) \
910 return lprocfs_##type##_seq_write(file, buffer, count, off); \
912 static int name##_##type##_open(cfs_inode_t *inode, struct file *file) \
914 return single_open(file, NULL, PDE_DATA(inode)); \
916 struct file_operations name##_##type##_fops = { \
917 .open = name##_##type##_open, \
918 .write = name##_##type##_write, \
919 .release = lprocfs_single_release, \
923 struct ptlrpc_request;
924 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
926 #ifdef HAVE_SERVER_SUPPORT
927 /* lprocfs_jobstats.c */
928 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
929 int event, long amount);
930 void lprocfs_job_stats_fini(struct obd_device *obd);
931 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
932 cntr_init_callback fn);
933 #ifndef HAVE_ONLY_PROCFS_SEQ
934 int lprocfs_rd_job_interval(char *page, char **start, off_t off,
935 int count, int *eof, void *data);
936 int lprocfs_wr_job_interval(struct file *file, const char *buffer,
937 unsigned long count, void *data);
940 int lprocfs_obd_rd_recovery_time_soft(char *page, char **start, off_t off,
941 int count, int *eof, void *data);
942 int lprocfs_obd_wr_recovery_time_soft(struct file *file,
944 unsigned long count, void *data);
945 int lprocfs_obd_rd_recovery_time_hard(char *page, char **start, off_t off,
946 int count, int *eof, void *data);
947 int lprocfs_obd_wr_recovery_time_hard(struct file *file,
949 unsigned long count, void *data);
950 int lprocfs_target_rd_instance(char *page, char **start, off_t off,
951 int count, int *eof, void *data);
953 int lprocfs_job_interval_seq_show(struct seq_file *m, void *data);
955 lprocfs_job_interval_seq_write(struct file *file, const char *buffer,
956 size_t count, loff_t *off);
958 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data);
959 ssize_t lprocfs_recovery_time_soft_seq_write(struct file *file,
961 size_t count, loff_t *off);
962 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data);
964 lprocfs_recovery_time_hard_seq_write(struct file *file, const char *buffer,
965 size_t count, loff_t *off);
966 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data);
968 #ifndef HAVE_ONLY_PROCFS_SEQ
969 int lprocfs_obd_rd_max_pages_per_rpc(char *page, char **start, off_t off,
970 int count, int *eof, void *data);
971 int lprocfs_obd_wr_max_pages_per_rpc(struct file *file, const char *buffer,
972 unsigned long count, void *data);
974 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
976 lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file, const char *buffer,
977 size_t count, loff_t *off);
979 struct root_squash_info;
980 int lprocfs_wr_root_squash(const char *buffer, unsigned long count,
981 struct root_squash_info *squash, char *name);
982 int lprocfs_wr_nosquash_nids(const char *buffer, unsigned long count,
983 struct root_squash_info *squash, char *name);
985 /* all quota proc functions */
986 extern int lprocfs_quota_rd_bunit(char *page, char **start,
987 off_t off, int count,
988 int *eof, void *data);
989 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
990 unsigned long count, void *data);
991 extern int lprocfs_quota_rd_btune(char *page, char **start,
992 off_t off, int count,
993 int *eof, void *data);
994 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
995 unsigned long count, void *data);
996 extern int lprocfs_quota_rd_iunit(char *page, char **start,
997 off_t off, int count,
998 int *eof, void *data);
999 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
1000 unsigned long count, void *data);
1001 extern int lprocfs_quota_rd_itune(char *page, char **start,
1002 off_t off, int count,
1003 int *eof, void *data);
1004 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
1005 unsigned long count, void *data);
1006 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
1007 int *eof, void *data);
1008 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
1009 unsigned long count, void *data);
1010 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
1011 int count, int *eof, void *data);
1012 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
1014 unsigned long count, void *data);
1015 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
1016 int count, int *eof, void *data);
1017 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
1018 unsigned long count, void *data);
1019 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
1020 int count, int *eof, void *data);
1021 extern int lprocfs_quota_wr_switch_qs(struct file *file,
1023 unsigned long count, void *data);
1024 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
1025 int count, int *eof, void *data);
1026 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
1028 unsigned long count, void *data);
1029 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
1030 int count, int *eof, void *data);
1031 extern int lprocfs_quota_wr_least_bunit(struct file *file,
1033 unsigned long count, void *data);
1034 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
1035 int count, int *eof, void *data);
1036 extern int lprocfs_quota_wr_least_iunit(struct file *file,
1038 unsigned long count, void *data);
1039 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
1040 int count, int *eof, void *data);
1041 extern int lprocfs_quota_wr_qs_factor(struct file *file,
1043 unsigned long count, void *data);
1045 /* LPROCFS is not defined */
1047 #define proc_lustre_root NULL
1049 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
1050 int index, long amount)
1052 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
1055 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
1056 int index, long amount)
1058 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
1061 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
1062 int index, unsigned conf,
1063 const char *name, const char *units)
1066 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
1067 enum lprocfs_fields_flags field)
1070 /* NB: we return !NULL to satisfy error checker */
1071 static inline struct lprocfs_stats *
1072 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
1073 { return (struct lprocfs_stats *)1; }
1074 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
1076 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
1078 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
1080 struct lprocfs_stats *stats)
1082 static inline void lprocfs_init_ops_stats(int num_private_stats,
1083 struct lprocfs_stats *stats)
1085 static inline void lprocfs_init_mps_stats(int num_private_stats,
1086 struct lprocfs_stats *stats)
1088 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
1090 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
1091 unsigned int num_private_stats)
1093 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
1094 unsigned int num_private_stats)
1096 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
1098 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
1102 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
1104 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
1106 #ifdef HAVE_SERVER_SUPPORT
1107 #ifndef HAVE_ONLY_PROCFS_SEQ
1109 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
1110 unsigned long count, void *data)
1113 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
1114 int count, int *eof, void *data)
1118 ssize_t lprocfs_nid_stats_seq_write(struct file *file, const char *buffer,
1119 size_t count, loff_t *off)
1122 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
1124 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid,
1128 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
1130 static inline struct proc_dir_entry *
1131 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
1132 #ifndef HAVE_ONLY_PROCFS_SEQ
1133 read_proc_t *read_proc, write_proc_t *write_proc,
1135 void *data, const struct file_operations *fops)
1137 static inline struct proc_dir_entry *
1138 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
1139 const char *format, ...)
1141 #ifndef HAVE_ONLY_PROCFS_SEQ
1142 static inline cfs_proc_dir_entry_t *
1143 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
1144 struct lprocfs_vars *list, void *data)
1146 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
1147 struct lprocfs_vars *var,
1151 static inline int lprocfs_seq_add_vars(cfs_proc_dir_entry_t *root,
1152 struct lprocfs_seq_vars *var,
1155 static inline cfs_proc_dir_entry_t *
1156 lprocfs_seq_register(const char *name, cfs_proc_dir_entry_t *parent,
1157 struct lprocfs_seq_vars *list, void *data)
1159 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root)
1161 static inline void lprocfs_remove_proc_entry(const char *name,
1162 struct proc_dir_entry *parent)
1164 #ifndef HAVE_ONLY_PROCFS_SEQ
1165 static inline void lprocfs_try_remove_proc_entry(const char *name,
1166 struct proc_dir_entry *parent)
1168 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
1171 static inline int lprocfs_obd_setup(struct obd_device *dev,
1172 struct lprocfs_vars *list)
1175 static inline int lprocfs_seq_obd_setup(struct obd_device *dev)
1177 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
1179 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
1180 int count, int *eof, void *data)
1182 #ifndef HAVE_ONLY_PROCFS_SEQ
1183 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
1184 int count, int *eof, void *data)
1186 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
1187 int count, int *eof, void *data)
1189 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
1190 int count, int *eof, void *data)
1192 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
1193 int count, int *eof, void *data)
1195 static inline int lprocfs_rd_import(char *page, char **start, off_t off,
1196 int count, int *eof, void *data)
1198 static inline int lprocfs_rd_pinger_recov(char *page, char **start, off_t off,
1199 int count, int *eof, void *data)
1201 static inline int lprocfs_rd_state(char *page, char **start, off_t off,
1202 int count, int *eof, void *data)
1204 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
1205 int count, int *eof, void *data)
1207 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
1208 int count, int *eof, void *data)
1210 static inline int lprocfs_rd_numrefs(struct seq_file *m, void *data)
1212 struct adaptive_timeout;
1213 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
1214 struct adaptive_timeout *at)
1216 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
1217 int count, int *eof, void *data)
1219 static inline int lprocfs_wr_timeouts(struct file *file,
1221 unsigned long count, void *data)
1223 #ifdef HAVE_SERVER_SUPPORT
1224 static inline int lprocfs_wr_evict_client(struct file *file,
1226 unsigned long count, void *data)
1229 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
1230 unsigned long count, void *data)
1232 static inline int lprocfs_wr_import(struct file *file, const char *buffer,
1233 unsigned long count, void *data)
1235 static inline int lprocfs_wr_pinger_recov(struct file *file, const char *buffer,
1236 unsigned long count, void *data)
1239 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
1241 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
1243 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
1245 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
1247 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
1249 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
1251 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1253 #ifdef HAVE_SERVER_SUPPORT
1254 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
1257 struct adaptive_timeout;
1258 static inline int lprocfs_seq_at_hist_helper(struct seq_file *m,
1259 struct adaptive_timeout *at)
1261 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1263 static inline ssize_t
1264 lprocfs_timeouts_seq_write(struct file *file, const char *buffer,
1265 size_t count, loff_t *off)
1267 #ifdef HAVE_SERVER_SUPPORT
1268 static inline ssize_t
1269 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
1270 size_t count, loff_t *off)
1273 static inline ssize_t
1274 lprocfs_ping_seq_write(struct file *file, const char *buffer,
1275 size_t count, loff_t *off)
1277 static inline ssize_t
1278 lprocfs_import_seq_write(struct file *file, const char *buffer,
1279 size_t count, loff_t *off)
1282 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1284 static inline ssize_t
1285 lprocfs_pinger_recov_seq_write(struct file *file, const char *buffer,
1286 size_t count, loff_t *off)
1289 /* Statfs helpers */
1290 #ifndef HAVE_ONLY_PROCFS_SEQ
1292 int lprocfs_rd_blksize(char *page, char **start, off_t off,
1293 int count, int *eof, void *data)
1296 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
1297 int count, int *eof, void *data)
1300 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
1301 int count, int *eof, void *data)
1304 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
1305 int count, int *eof, void *data)
1308 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
1309 int count, int *eof, void *data)
1312 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
1313 int count, int *eof, void *data)
1317 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1320 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1323 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1326 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1329 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1332 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1335 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1338 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1341 void lprocfs_oh_clear(struct obd_histogram *oh)
1344 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1347 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1348 struct lprocfs_counter *cnt)
1351 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1352 enum lprocfs_fields_flags field)
1353 { return (__u64)0; }
1355 #define LPROC_SEQ_FOPS_RO(name)
1356 #define LPROC_SEQ_FOPS(name)
1357 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1358 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1359 #define LPROC_SEQ_FOPS_WO_TYPE(name, type)
1361 /* lprocfs_jobstats.c */
1363 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1367 void lprocfs_job_stats_fini(struct obd_device *obd)
1370 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1371 cntr_init_callback fn)
1375 /* lproc_ptlrpc.c */
1376 #define target_print_req NULL
1378 #endif /* LPROCFS */
1380 #endif /* LPROCFS_SNMP_H */