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, 2014, 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
40 * Author: Hariharan Thantry thantry@users.sourceforge.net
42 #ifndef _LPROCFS_STATUS_H
43 #define _LPROCFS_STATUS_H
46 #include <linux/proc_fs.h>
47 #include <linux/rwsem.h>
48 #include <linux/spinlock.h>
50 #include <lustre/lustre_idl.h>
54 const struct file_operations *fops;
62 /* if we find more consumers this could be generalized */
63 #define OBD_HIST_MAX 32
64 struct obd_histogram {
66 unsigned long oh_buckets[OBD_HIST_MAX];
88 struct obd_histogram hist[BRW_LAST];
92 RENAME_SAMEDIR_SIZE = 0,
93 RENAME_CROSSDIR_SRC_SIZE,
94 RENAME_CROSSDIR_TGT_SIZE,
99 struct obd_histogram hist[RENAME_LAST];
102 /* An lprocfs counter can be configured using the enum bit masks below.
104 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
105 * protects this counter from concurrent updates. If not specified,
106 * lprocfs an internal per-counter lock variable. External locks are
107 * not used to protect counter increments, but are used to protect
108 * counter readout and resets.
110 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
111 * (i.e. counter can be incremented by more than "1"). When specified,
112 * the counter maintains min, max and sum in addition to a simple
113 * invocation count. This allows averages to be be computed.
114 * If not specified, the counter is an increment-by-1 counter.
115 * min, max, sum, etc. are not maintained.
117 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
118 * squares (for multi-valued counter samples only). This allows
119 * external computation of standard deviation, but involves a 64-bit
120 * multiply per counter increment.
124 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
125 LPROCFS_CNTR_AVGMINMAX = 0x0002,
126 LPROCFS_CNTR_STDDEV = 0x0004,
128 /* counter data type */
129 LPROCFS_TYPE_REGS = 0x0100,
130 LPROCFS_TYPE_BYTES = 0x0200,
131 LPROCFS_TYPE_PAGES = 0x0400,
132 LPROCFS_TYPE_CYCLE = 0x0800,
135 #define LC_MIN_INIT ((~(__u64)0) >> 1)
137 struct lprocfs_counter_header {
138 unsigned int lc_config;
139 const char *lc_name; /* must be static */
140 const char *lc_units; /* must be static */
143 struct lprocfs_counter {
149 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
150 * for irq context counter, i.e. stats with
151 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
154 __s64 lc_array_sum[1];
156 #define lc_sum lc_array_sum[0]
157 #define lc_sum_irq lc_array_sum[1]
159 struct lprocfs_percpu {
160 struct lprocfs_counter lp_cntr[0];
163 enum lprocfs_stats_lock_ops {
164 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
165 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
168 enum lprocfs_stats_flags {
169 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
170 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
171 * area and need locking */
172 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
175 enum lprocfs_fields_flags {
176 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
177 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
178 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
179 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
180 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
181 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
182 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
185 struct lprocfs_stats {
187 unsigned short ls_num;
188 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
189 unsigned short ls_biggest_alloc_num;
190 enum lprocfs_stats_flags ls_flags;
191 /* Lock used when there are no percpu stats areas; For percpu stats,
192 * it is used to protect ls_biggest_alloc_num change */
195 /* has ls_num of counter headers */
196 struct lprocfs_counter_header *ls_cnt_header;
197 struct lprocfs_percpu *ls_percpu[0];
200 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
202 /* Pack all opcodes down into a single monotonically increasing index */
203 static inline int opcode_offset(__u32 opc) {
204 if (opc < OST_LAST_OPC) {
206 return (opc - OST_FIRST_OPC);
207 } else if (opc < MDS_LAST_OPC) {
209 return (opc - MDS_FIRST_OPC +
211 } else if (opc < LDLM_LAST_OPC) {
213 return (opc - LDLM_FIRST_OPC +
216 } else if (opc < MGS_LAST_OPC) {
218 return (opc - MGS_FIRST_OPC +
222 } else if (opc < OBD_LAST_OPC) {
224 return (opc - OBD_FIRST_OPC +
229 } else if (opc < LLOG_LAST_OPC) {
231 return (opc - LLOG_FIRST_OPC +
237 } else if (opc < QUOTA_LAST_OPC) {
239 return (opc - QUOTA_FIRST_OPC +
246 } else if (opc < SEQ_LAST_OPC) {
248 return (opc - SEQ_FIRST_OPC +
256 } else if (opc < SEC_LAST_OPC) {
258 return (opc - SEC_FIRST_OPC +
267 } else if (opc < FLD_LAST_OPC) {
269 return (opc - FLD_FIRST_OPC +
279 } else if (opc < OUT_UPDATE_LAST_OPC) {
281 return (opc - OUT_UPDATE_FIRST_OPC +
292 } else if (opc < LFSCK_LAST_OPC) {
294 return (opc - LFSCK_FIRST_OPC +
295 OPC_RANGE(OUT_UPDATE) +
313 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
323 OPC_RANGE(OUT_UPDATE) + \
326 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
330 PTLRPC_REQWAIT_CNTR = 0,
331 PTLRPC_REQQDEPTH_CNTR,
332 PTLRPC_REQACTIVE_CNTR,
334 PTLRPC_REQBUF_AVAIL_CNTR,
338 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
340 enum lprocfs_extra_opc {
341 LDLM_GLIMPSE_ENQUEUE = 0,
358 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
360 extern struct proc_dir_entry *proc_lustre_root;
363 struct obd_histogram;
365 /* Days / hours / mins / seconds format */
369 static inline void s2dhms(struct dhms *ts, time_t secs)
371 ts->d = secs / 86400;
378 #define DHMS_FMT "%dd%dh%02dm%02ds"
379 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
381 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
382 #define JOBSTATS_DISABLE "disable"
383 #define JOBSTATS_PROCNAME_UID "procname_uid"
385 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
387 struct obd_job_stats {
388 cfs_hash_t *ojs_hash;
389 struct list_head ojs_list;
390 rwlock_t ojs_lock; /* protect the obj_list */
391 cntr_init_callback ojs_cntr_init_fn;
393 int ojs_cleanup_interval;
394 time_t ojs_last_cleanup;
397 #ifdef CONFIG_PROC_FS
399 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
403 * Lock statistics structure for access, possibly only on this CPU.
405 * The statistics struct may be allocated with per-CPU structures for
406 * efficient concurrent update (usually only on server-wide stats), or
407 * as a single global struct (e.g. for per-client or per-job statistics),
408 * so the required locking depends on the type of structure allocated.
410 * For per-CPU statistics, pin the thread to the current cpuid so that
411 * will only access the statistics for that CPU. If the stats structure
412 * for the current CPU has not been allocated (or previously freed),
413 * allocate it now. The per-CPU statistics do not need locking since
414 * the thread is pinned to the CPU during update.
416 * For global statistics, lock the stats structure to prevent concurrent update.
418 * \param[in] stats statistics structure to lock
419 * \param[in] opc type of operation:
420 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
421 * for incrementing statistics for that CPU
422 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
423 * CPU indices to iterate over all indices
424 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
426 * \retval cpuid of current thread or number of allocated structs
427 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
429 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats,
430 enum lprocfs_stats_lock_ops opc,
431 unsigned long *flags)
433 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
434 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
435 spin_lock_irqsave(&stats->ls_lock, *flags);
437 spin_lock(&stats->ls_lock);
438 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
442 case LPROCFS_GET_SMP_ID: {
443 unsigned int cpuid = get_cpu();
445 if (unlikely(stats->ls_percpu[cpuid] == NULL)) {
446 int rc = lprocfs_stats_alloc_one(stats, cpuid);
454 case LPROCFS_GET_NUM_CPU:
455 return stats->ls_biggest_alloc_num;
462 * Unlock statistics structure after access.
464 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
465 * or unpin this thread from the current cpuid for per-CPU statistics.
467 * This function must be called using the same arguments as used when calling
468 * lprocfs_stats_lock() so that the correct operation can be performed.
470 * \param[in] stats statistics structure to unlock
471 * \param[in] opc type of operation (current cpuid or number of structs)
472 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
474 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats,
475 enum lprocfs_stats_lock_ops opc,
476 unsigned long *flags)
478 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
479 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
480 spin_unlock_irqrestore(&stats->ls_lock, *flags);
482 spin_unlock(&stats->ls_lock);
483 } else if (opc == LPROCFS_GET_SMP_ID) {
488 static inline unsigned int
489 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
491 unsigned int percpusize;
493 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
495 /* irq safe stats need lc_array_sum[1] */
496 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
497 percpusize += stats->ls_num * sizeof(__s64);
499 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
500 percpusize = L1_CACHE_ALIGN(percpusize);
505 static inline struct lprocfs_counter *
506 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
509 struct lprocfs_counter *cntr;
511 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
513 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
514 cntr = (void *)cntr + index * sizeof(__s64);
519 /* Two optimized LPROCFS counter increment functions are provided:
520 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
521 * lprocfs_counter_add(cntr) - use for multi-valued counters
522 * Counter data layout allows config flag, counter lock and the
523 * count itself to reside within a single cache line.
526 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
528 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
531 #define lprocfs_counter_incr(stats, idx) \
532 lprocfs_counter_add(stats, idx, 1)
533 #define lprocfs_counter_decr(stats, idx) \
534 lprocfs_counter_sub(stats, idx, 1)
536 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
537 struct lprocfs_counter_header *header,
538 enum lprocfs_stats_flags flags,
539 enum lprocfs_fields_flags field);
540 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
542 enum lprocfs_fields_flags field)
545 unsigned int num_cpu;
546 unsigned long flags = 0;
549 LASSERT(stats != NULL);
551 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
552 for (i = 0; i < num_cpu; i++) {
553 if (stats->ls_percpu[i] == NULL)
555 ret += lprocfs_read_helper(
556 lprocfs_stats_counter_get(stats, i, idx),
557 &stats->ls_cnt_header[idx], stats->ls_flags,
560 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
564 extern struct lprocfs_stats *
565 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
566 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
567 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
568 extern void lprocfs_init_ops_stats(int num_private_stats,
569 struct lprocfs_stats *stats);
570 extern void lprocfs_init_mps_stats(int num_private_stats,
571 struct lprocfs_stats *stats);
572 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
573 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
574 unsigned int num_private_stats);
575 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
576 unsigned int num_private_stats);
577 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
578 unsigned conf, const char *name,
580 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
581 extern void lprocfs_free_md_stats(struct obd_device *obddev);
584 extern int lprocfs_add_clear_entry(struct obd_device * obd,
585 struct proc_dir_entry *entry);
586 #ifdef HAVE_SERVER_SUPPORT
587 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
588 extern int lprocfs_exp_cleanup(struct obd_export *exp);
590 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
593 extern struct proc_dir_entry *
594 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
595 void *data, const struct file_operations *fops);
596 extern struct proc_dir_entry *
597 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
598 const char *format, ...);
599 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
600 #ifdef HAVE_SERVER_SUPPORT
602 lprocfs_nid_stats_clear_seq_write(struct file *file, const char *buffer,
603 size_t count, loff_t *off);
604 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
606 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
607 struct lprocfs_stats *stats);
609 /* lprocfs_status.c */
610 extern int lprocfs_add_vars(struct proc_dir_entry *root,
611 struct lprocfs_vars *var, void *data);
612 extern struct proc_dir_entry *
613 lprocfs_register(const char *name, struct proc_dir_entry *parent,
614 struct lprocfs_vars *list, void *data);
615 extern void lprocfs_remove(struct proc_dir_entry **root);
616 extern void lprocfs_remove_proc_entry(const char *name,
617 struct proc_dir_entry *parent);
618 #ifndef HAVE_REMOVE_PROC_SUBTREE
619 extern int remove_proc_subtree(const char *name,
620 struct proc_dir_entry *parent);
621 #define PDE_DATA(inode) (PDE(inode)->data)
623 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
625 struct proc_dir_entry *dp = PDE(inode);
628 spin_lock(&(dp)->pde_unload_lock);
629 if (dp->proc_fops == NULL)
631 spin_unlock(&(dp)->pde_unload_lock);
637 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
640 extern int lprocfs_obd_setup(struct obd_device *dev);
641 extern int lprocfs_obd_cleanup(struct obd_device *obd);
642 #ifdef HAVE_SERVER_SUPPORT
643 extern const struct file_operations lprocfs_evict_client_fops;
645 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
647 const struct file_operations *seq_fops,
649 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
651 const struct file_operations *seq_fops,
654 /* Generic callbacks */
655 extern int lprocfs_u64_seq_show(struct seq_file *m, void *data);
656 extern int lprocfs_atomic_seq_show(struct seq_file *m, void *data);
657 extern ssize_t lprocfs_atomic_seq_write(struct file *file,
658 const char __user *buffer,
659 size_t count, loff_t *off);
660 extern int lprocfs_uint_seq_show(struct seq_file *m, void *data);
661 extern ssize_t lprocfs_uint_seq_write(struct file *file,
662 const char __user *buffer,
663 size_t count, loff_t *off);
664 extern int lprocfs_wr_uint(struct file *file, const char __user *buffer,
665 unsigned long count, void *data);
666 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
667 extern int lprocfs_name_seq_show(struct seq_file *m, void *data);
668 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
669 extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data);
670 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
671 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
672 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
673 #ifdef HAVE_SERVER_SUPPORT
674 extern int lprocfs_num_exports_seq_show(struct seq_file *m, void *data);
676 struct adaptive_timeout;
677 extern int lprocfs_at_hist_helper(struct seq_file *m,
678 struct adaptive_timeout *at);
679 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
681 lprocfs_timeouts_seq_write(struct file *file, const char *buffer,
682 size_t count, loff_t *off);
683 #ifdef HAVE_SERVER_SUPPORT
685 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
686 size_t count, loff_t *off);
689 lprocfs_ping_seq_write(struct file *file, const char *buffer,
690 size_t count, loff_t *off);
692 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
693 size_t count, loff_t *off);
694 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
696 lprocfs_pinger_recov_seq_write(struct file *file, const char *buffer,
697 size_t count, loff_t *off);
700 extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data);
701 extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data);
702 extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data);
703 extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data);
704 extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data);
705 extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data);
707 extern int lprocfs_write_helper(const char __user *buffer, unsigned long count,
709 extern int lprocfs_write_frac_helper(const char __user *buffer,
712 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
713 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
715 extern int lprocfs_write_u64_helper(const char __user *buffer,
716 unsigned long count, __u64 *val);
717 extern int lprocfs_write_frac_u64_helper(const char __user *buffer,
719 __u64 *val, int mult);
720 char *lprocfs_find_named_value(const char *buffer, const char *name,
722 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
723 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
724 void lprocfs_oh_clear(struct obd_histogram *oh);
725 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
727 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
728 struct lprocfs_counter *cnt);
730 #ifdef HAVE_SERVER_SUPPORT
731 /* lprocfs_status.c: recovery status */
732 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
734 /* lprocfs_status.c: hash statistics */
735 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
737 /* lprocfs_status.c: IR factor */
738 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
740 lprocfs_ir_factor_seq_write(struct file *file, const char *buffer,
741 size_t count, loff_t *off);
743 extern int lprocfs_single_release(struct inode *, struct file *);
744 extern int lprocfs_seq_release(struct inode *, struct file *);
746 /* You must use these macros when you want to refer to
747 * the import in a client obd_device for a lprocfs entry */
748 #define LPROCFS_CLIMP_CHECK(obd) do { \
749 typecheck(struct obd_device *, obd); \
750 down_read(&(obd)->u.cli.cl_sem); \
751 if ((obd)->u.cli.cl_import == NULL) { \
752 up_read(&(obd)->u.cli.cl_sem); \
756 #define LPROCFS_CLIMP_EXIT(obd) \
757 up_read(&(obd)->u.cli.cl_sem);
759 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
760 proc entries; otherwise, you will define name##_seq_write function also for
761 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
762 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
763 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
764 static int name##_single_open(struct inode *inode, struct file *file) \
768 rc = LPROCFS_ENTRY_CHECK(inode); \
772 return single_open(file, name##_seq_show, PDE_DATA(inode)); \
774 static const struct file_operations name##_fops = { \
775 .owner = THIS_MODULE, \
776 .open = name##_single_open, \
778 .write = custom_seq_write, \
779 .llseek = seq_lseek, \
780 .release = lprocfs_single_release, \
783 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
784 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
786 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
787 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
789 return lprocfs_##type##_seq_show(m, m->private); \
791 LPROC_SEQ_FOPS_RO(name##_##type)
793 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
794 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
796 return lprocfs_##type##_seq_show(m, m->private); \
798 static ssize_t name##_##type##_seq_write(struct file *file, \
799 const char __user *buffer, size_t count, \
802 struct seq_file *seq = file->private_data; \
803 return lprocfs_##type##_seq_write(file, buffer, \
804 count, seq->private); \
806 LPROC_SEQ_FOPS(name##_##type);
808 #define LPROC_SEQ_FOPS_WO_TYPE(name, type) \
809 static ssize_t name##_##type##_write(struct file *file, \
810 const char __user *buffer, size_t count, \
813 return lprocfs_##type##_seq_write(file, buffer, count, off);\
815 static int name##_##type##_open(struct inode *inode, struct file *file)\
817 return single_open(file, NULL, PDE_DATA(inode)); \
819 static const struct file_operations name##_##type##_fops = { \
820 .open = name##_##type##_open, \
821 .write = name##_##type##_write, \
822 .release = lprocfs_single_release, \
826 struct ptlrpc_request;
827 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
829 #ifdef HAVE_SERVER_SUPPORT
830 /* lprocfs_jobstats.c */
831 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
832 int event, long amount);
833 void lprocfs_job_stats_fini(struct obd_device *obd);
834 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
835 cntr_init_callback fn);
836 int lprocfs_job_interval_seq_show(struct seq_file *m, void *data);
838 lprocfs_job_interval_seq_write(struct file *file, const char *buffer,
839 size_t count, loff_t *off);
841 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data);
842 ssize_t lprocfs_recovery_time_soft_seq_write(struct file *file,
844 size_t count, loff_t *off);
845 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data);
847 lprocfs_recovery_time_hard_seq_write(struct file *file, const char *buffer,
848 size_t count, loff_t *off);
849 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data);
851 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
853 lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file, const char *buffer,
854 size_t count, loff_t *off);
856 struct root_squash_info;
857 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
858 struct root_squash_info *squash, char *name);
859 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
860 struct root_squash_info *squash, char *name);
862 /* all quota proc functions */
863 extern int lprocfs_quota_rd_bunit(char *page, char **start,
864 off_t off, int count,
865 int *eof, void *data);
866 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
867 unsigned long count, void *data);
868 extern int lprocfs_quota_rd_btune(char *page, char **start,
869 off_t off, int count,
870 int *eof, void *data);
871 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
872 unsigned long count, void *data);
873 extern int lprocfs_quota_rd_iunit(char *page, char **start,
874 off_t off, int count,
875 int *eof, void *data);
876 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
877 unsigned long count, void *data);
878 extern int lprocfs_quota_rd_itune(char *page, char **start,
879 off_t off, int count,
880 int *eof, void *data);
881 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
882 unsigned long count, void *data);
883 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
884 int *eof, void *data);
885 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
886 unsigned long count, void *data);
887 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
888 int count, int *eof, void *data);
889 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
891 unsigned long count, void *data);
892 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
893 int count, int *eof, void *data);
894 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
895 unsigned long count, void *data);
896 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
897 int count, int *eof, void *data);
898 extern int lprocfs_quota_wr_switch_qs(struct file *file,
900 unsigned long count, void *data);
901 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
902 int count, int *eof, void *data);
903 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
905 unsigned long count, void *data);
906 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
907 int count, int *eof, void *data);
908 extern int lprocfs_quota_wr_least_bunit(struct file *file,
910 unsigned long count, void *data);
911 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
912 int count, int *eof, void *data);
913 extern int lprocfs_quota_wr_least_iunit(struct file *file,
915 unsigned long count, void *data);
916 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
917 int count, int *eof, void *data);
918 extern int lprocfs_quota_wr_qs_factor(struct file *file,
920 unsigned long count, void *data);
921 #else /* !CONFIG_PROC_FS */
923 #define proc_lustre_root NULL
925 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
926 int index, long amount)
928 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
931 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
932 int index, long amount)
934 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
937 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
938 int index, unsigned conf,
939 const char *name, const char *units)
942 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
943 enum lprocfs_fields_flags field)
946 /* NB: we return !NULL to satisfy error checker */
947 static inline struct lprocfs_stats *
948 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
949 { return (struct lprocfs_stats *)1; }
950 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
952 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
954 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
956 struct lprocfs_stats *stats)
958 static inline void lprocfs_init_ops_stats(int num_private_stats,
959 struct lprocfs_stats *stats)
961 static inline void lprocfs_init_mps_stats(int num_private_stats,
962 struct lprocfs_stats *stats)
964 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
966 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
967 unsigned int num_private_stats)
969 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
970 unsigned int num_private_stats)
972 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
974 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
978 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
980 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
982 #ifdef HAVE_SERVER_SUPPORT
984 ssize_t lprocfs_nid_stats_seq_write(struct file *file, const char *buffer,
985 size_t count, loff_t *off)
988 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
990 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
993 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
995 static inline struct proc_dir_entry *
996 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
997 void *data, const struct file_operations *fops)
999 static inline struct proc_dir_entry *
1000 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
1001 const char *format, ...)
1003 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
1004 struct lprocfs_vars *var, void *data)
1006 static inline struct proc_dir_entry *
1007 lprocfs_register(const char *name, struct proc_dir_entry *parent,
1008 struct lprocfs_vars *list, void *data)
1010 static inline void lprocfs_remove(struct proc_dir_entry **root)
1012 static inline void lprocfs_remove_proc_entry(const char *name,
1013 struct proc_dir_entry *parent)
1015 static inline int lprocfs_obd_setup(struct obd_device *dev)
1017 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
1019 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
1021 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
1023 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
1025 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
1027 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
1029 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
1031 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1033 #ifdef HAVE_SERVER_SUPPORT
1034 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
1037 struct adaptive_timeout;
1038 static inline int lprocfs_at_hist_helper(struct seq_file *m,
1039 struct adaptive_timeout *at)
1041 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1043 static inline ssize_t
1044 lprocfs_timeouts_seq_write(struct file *file, const char *buffer,
1045 size_t count, loff_t *off)
1047 #ifdef HAVE_SERVER_SUPPORT
1048 static inline ssize_t
1049 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
1050 size_t count, loff_t *off)
1053 static inline ssize_t
1054 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1055 size_t count, loff_t *off)
1057 static inline ssize_t
1058 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1059 size_t count, loff_t *off)
1062 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1064 static inline ssize_t
1065 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1066 size_t count, loff_t *off)
1069 /* Statfs helpers */
1071 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1074 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1077 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1080 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1083 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1086 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1089 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1092 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1095 void lprocfs_oh_clear(struct obd_histogram *oh)
1098 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1101 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1102 struct lprocfs_counter *cnt)
1105 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1106 enum lprocfs_fields_flags field)
1107 { return (__u64)0; }
1109 #define LPROC_SEQ_FOPS_RO(name)
1110 #define LPROC_SEQ_FOPS(name)
1111 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1112 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1113 #define LPROC_SEQ_FOPS_WO_TYPE(name, type)
1115 /* lprocfs_jobstats.c */
1117 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1121 void lprocfs_job_stats_fini(struct obd_device *obd)
1124 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1125 cntr_init_callback fn)
1129 /* lproc_ptlrpc.c */
1130 #define target_print_req NULL
1132 #endif /* CONFIG_PROC_FS */
1134 #endif /* LPROCFS_STATUS_H */