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>
49 #include <linux/seq_file.h>
51 #include <lustre/lustre_idl.h>
55 const struct file_operations *fops;
63 /* if we find more consumers this could be generalized */
64 #define OBD_HIST_MAX 32
65 struct obd_histogram {
67 unsigned long oh_buckets[OBD_HIST_MAX];
89 struct obd_histogram hist[BRW_LAST];
93 RENAME_SAMEDIR_SIZE = 0,
94 RENAME_CROSSDIR_SRC_SIZE,
95 RENAME_CROSSDIR_TGT_SIZE,
100 struct obd_histogram hist[RENAME_LAST];
103 /* An lprocfs counter can be configured using the enum bit masks below.
105 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
106 * protects this counter from concurrent updates. If not specified,
107 * lprocfs an internal per-counter lock variable. External locks are
108 * not used to protect counter increments, but are used to protect
109 * counter readout and resets.
111 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
112 * (i.e. counter can be incremented by more than "1"). When specified,
113 * the counter maintains min, max and sum in addition to a simple
114 * invocation count. This allows averages to be be computed.
115 * If not specified, the counter is an increment-by-1 counter.
116 * min, max, sum, etc. are not maintained.
118 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
119 * squares (for multi-valued counter samples only). This allows
120 * external computation of standard deviation, but involves a 64-bit
121 * multiply per counter increment.
125 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
126 LPROCFS_CNTR_AVGMINMAX = 0x0002,
127 LPROCFS_CNTR_STDDEV = 0x0004,
129 /* counter data type */
130 LPROCFS_TYPE_REGS = 0x0100,
131 LPROCFS_TYPE_BYTES = 0x0200,
132 LPROCFS_TYPE_PAGES = 0x0400,
133 LPROCFS_TYPE_CYCLE = 0x0800,
136 #define LC_MIN_INIT ((~(__u64)0) >> 1)
138 struct lprocfs_counter_header {
139 unsigned int lc_config;
140 const char *lc_name; /* must be static */
141 const char *lc_units; /* must be static */
144 struct lprocfs_counter {
150 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
151 * for irq context counter, i.e. stats with
152 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
155 __s64 lc_array_sum[1];
157 #define lc_sum lc_array_sum[0]
158 #define lc_sum_irq lc_array_sum[1]
160 struct lprocfs_percpu {
161 struct lprocfs_counter lp_cntr[0];
164 enum lprocfs_stats_lock_ops {
165 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
166 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
169 enum lprocfs_stats_flags {
170 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
171 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
172 * area and need locking */
173 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
176 enum lprocfs_fields_flags {
177 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
178 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
179 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
180 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
181 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
182 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
183 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
186 struct lprocfs_stats {
188 unsigned short ls_num;
189 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
190 unsigned short ls_biggest_alloc_num;
191 enum lprocfs_stats_flags ls_flags;
192 /* Lock used when there are no percpu stats areas; For percpu stats,
193 * it is used to protect ls_biggest_alloc_num change */
196 /* has ls_num of counter headers */
197 struct lprocfs_counter_header *ls_cnt_header;
198 struct lprocfs_percpu *ls_percpu[0];
201 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
203 /* Pack all opcodes down into a single monotonically increasing index */
204 static inline int opcode_offset(__u32 opc) {
205 if (opc < OST_LAST_OPC) {
207 return (opc - OST_FIRST_OPC);
208 } else if (opc < MDS_LAST_OPC) {
210 return (opc - MDS_FIRST_OPC +
212 } else if (opc < LDLM_LAST_OPC) {
214 return (opc - LDLM_FIRST_OPC +
217 } else if (opc < MGS_LAST_OPC) {
219 return (opc - MGS_FIRST_OPC +
223 } else if (opc < OBD_LAST_OPC) {
225 return (opc - OBD_FIRST_OPC +
230 } else if (opc < LLOG_LAST_OPC) {
232 return (opc - LLOG_FIRST_OPC +
238 } else if (opc < QUOTA_LAST_OPC) {
240 return (opc - QUOTA_FIRST_OPC +
247 } else if (opc < SEQ_LAST_OPC) {
249 return (opc - SEQ_FIRST_OPC +
257 } else if (opc < SEC_LAST_OPC) {
259 return (opc - SEC_FIRST_OPC +
268 } else if (opc < FLD_LAST_OPC) {
270 return (opc - FLD_FIRST_OPC +
280 } else if (opc < OUT_UPDATE_LAST_OPC) {
282 return (opc - OUT_UPDATE_FIRST_OPC +
293 } else if (opc < LFSCK_LAST_OPC) {
295 return (opc - LFSCK_FIRST_OPC +
296 OPC_RANGE(OUT_UPDATE) +
314 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
324 OPC_RANGE(OUT_UPDATE) + \
327 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
331 PTLRPC_REQWAIT_CNTR = 0,
332 PTLRPC_REQQDEPTH_CNTR,
333 PTLRPC_REQACTIVE_CNTR,
335 PTLRPC_REQBUF_AVAIL_CNTR,
339 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
341 enum lprocfs_extra_opc {
342 LDLM_GLIMPSE_ENQUEUE = 0,
359 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
361 extern struct proc_dir_entry *proc_lustre_root;
364 struct obd_histogram;
366 /* Days / hours / mins / seconds format */
370 static inline void s2dhms(struct dhms *ts, time_t secs)
372 ts->d = secs / 86400;
379 #define DHMS_FMT "%dd%dh%02dm%02ds"
380 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
382 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
383 #define JOBSTATS_DISABLE "disable"
384 #define JOBSTATS_PROCNAME_UID "procname_uid"
386 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
388 struct obd_job_stats {
389 struct cfs_hash *ojs_hash; /* hash of jobids */
390 struct list_head ojs_list; /* list of job_stat structs */
391 rwlock_t ojs_lock; /* protect ojs_list/js_list */
392 unsigned int ojs_cleanup_interval;/* seconds before expiry */
393 time_t ojs_last_cleanup; /* previous cleanup time */
394 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
395 unsigned short ojs_cntr_num; /* number of stats in struct */
396 bool ojs_cleaning; /* currently expiring stats */
399 #ifdef CONFIG_PROC_FS
401 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
405 * Lock statistics structure for access, possibly only on this CPU.
407 * The statistics struct may be allocated with per-CPU structures for
408 * efficient concurrent update (usually only on server-wide stats), or
409 * as a single global struct (e.g. for per-client or per-job statistics),
410 * so the required locking depends on the type of structure allocated.
412 * For per-CPU statistics, pin the thread to the current cpuid so that
413 * will only access the statistics for that CPU. If the stats structure
414 * for the current CPU has not been allocated (or previously freed),
415 * allocate it now. The per-CPU statistics do not need locking since
416 * the thread is pinned to the CPU during update.
418 * For global statistics, lock the stats structure to prevent concurrent update.
420 * \param[in] stats statistics structure to lock
421 * \param[in] opc type of operation:
422 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
423 * for incrementing statistics for that CPU
424 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
425 * CPU indices to iterate over all indices
426 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
428 * \retval cpuid of current thread or number of allocated structs
429 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
431 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats,
432 enum lprocfs_stats_lock_ops opc,
433 unsigned long *flags)
435 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
436 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
437 spin_lock_irqsave(&stats->ls_lock, *flags);
439 spin_lock(&stats->ls_lock);
440 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
444 case LPROCFS_GET_SMP_ID: {
445 unsigned int cpuid = get_cpu();
447 if (unlikely(stats->ls_percpu[cpuid] == NULL)) {
448 int rc = lprocfs_stats_alloc_one(stats, cpuid);
456 case LPROCFS_GET_NUM_CPU:
457 return stats->ls_biggest_alloc_num;
464 * Unlock statistics structure after access.
466 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
467 * or unpin this thread from the current cpuid for per-CPU statistics.
469 * This function must be called using the same arguments as used when calling
470 * lprocfs_stats_lock() so that the correct operation can be performed.
472 * \param[in] stats statistics structure to unlock
473 * \param[in] opc type of operation (current cpuid or number of structs)
474 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
476 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats,
477 enum lprocfs_stats_lock_ops opc,
478 unsigned long *flags)
480 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
481 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
482 spin_unlock_irqrestore(&stats->ls_lock, *flags);
484 spin_unlock(&stats->ls_lock);
485 } else if (opc == LPROCFS_GET_SMP_ID) {
490 static inline unsigned int
491 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
493 unsigned int percpusize;
495 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
497 /* irq safe stats need lc_array_sum[1] */
498 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
499 percpusize += stats->ls_num * sizeof(__s64);
501 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
502 percpusize = L1_CACHE_ALIGN(percpusize);
507 static inline struct lprocfs_counter *
508 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
511 struct lprocfs_counter *cntr;
513 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
515 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
516 cntr = (void *)cntr + index * sizeof(__s64);
521 /* Two optimized LPROCFS counter increment functions are provided:
522 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
523 * lprocfs_counter_add(cntr) - use for multi-valued counters
524 * Counter data layout allows config flag, counter lock and the
525 * count itself to reside within a single cache line.
528 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
530 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
533 #define lprocfs_counter_incr(stats, idx) \
534 lprocfs_counter_add(stats, idx, 1)
535 #define lprocfs_counter_decr(stats, idx) \
536 lprocfs_counter_sub(stats, idx, 1)
538 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
539 struct lprocfs_counter_header *header,
540 enum lprocfs_stats_flags flags,
541 enum lprocfs_fields_flags field);
542 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
544 enum lprocfs_fields_flags field)
547 unsigned int num_cpu;
548 unsigned long flags = 0;
551 LASSERT(stats != NULL);
553 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
554 for (i = 0; i < num_cpu; i++) {
555 if (stats->ls_percpu[i] == NULL)
557 ret += lprocfs_read_helper(
558 lprocfs_stats_counter_get(stats, i, idx),
559 &stats->ls_cnt_header[idx], stats->ls_flags,
562 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
566 extern struct lprocfs_stats *
567 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
568 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
569 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
570 extern void lprocfs_init_ops_stats(int num_private_stats,
571 struct lprocfs_stats *stats);
572 extern void lprocfs_init_mps_stats(int num_private_stats,
573 struct lprocfs_stats *stats);
574 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
575 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
576 unsigned int num_private_stats);
577 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
578 unsigned int num_private_stats);
579 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
580 unsigned conf, const char *name,
582 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
583 extern void lprocfs_free_md_stats(struct obd_device *obddev);
586 extern int lprocfs_add_clear_entry(struct obd_device * obd,
587 struct proc_dir_entry *entry);
588 #ifdef HAVE_SERVER_SUPPORT
589 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
590 extern int lprocfs_exp_cleanup(struct obd_export *exp);
592 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
595 extern struct proc_dir_entry *
596 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
597 void *data, const struct file_operations *fops);
598 extern struct proc_dir_entry *
599 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
600 const char *format, ...);
601 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
602 #ifdef HAVE_SERVER_SUPPORT
604 lprocfs_nid_stats_clear_seq_write(struct file *file, const char *buffer,
605 size_t count, loff_t *off);
606 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
608 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
609 struct lprocfs_stats *stats);
611 /* lprocfs_status.c */
612 extern int lprocfs_add_vars(struct proc_dir_entry *root,
613 struct lprocfs_vars *var, void *data);
614 extern struct proc_dir_entry *
615 lprocfs_register(const char *name, struct proc_dir_entry *parent,
616 struct lprocfs_vars *list, void *data);
617 extern void lprocfs_remove(struct proc_dir_entry **root);
618 extern void lprocfs_remove_proc_entry(const char *name,
619 struct proc_dir_entry *parent);
620 #ifndef HAVE_REMOVE_PROC_SUBTREE
621 extern int remove_proc_subtree(const char *name,
622 struct proc_dir_entry *parent);
623 #define PDE_DATA(inode) (PDE(inode)->data)
625 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
627 struct proc_dir_entry *dp = PDE(inode);
630 spin_lock(&(dp)->pde_unload_lock);
631 if (dp->proc_fops == NULL)
633 spin_unlock(&(dp)->pde_unload_lock);
639 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
642 extern int lprocfs_obd_setup(struct obd_device *dev);
643 extern int lprocfs_obd_cleanup(struct obd_device *obd);
644 #ifdef HAVE_SERVER_SUPPORT
645 extern const struct file_operations lprocfs_evict_client_fops;
647 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
649 const struct file_operations *seq_fops,
651 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
653 const struct file_operations *seq_fops,
656 /* Generic callbacks */
657 extern int lprocfs_u64_seq_show(struct seq_file *m, void *data);
658 extern int lprocfs_atomic_seq_show(struct seq_file *m, void *data);
659 extern ssize_t lprocfs_atomic_seq_write(struct file *file,
660 const char __user *buffer,
661 size_t count, loff_t *off);
662 extern int lprocfs_uint_seq_show(struct seq_file *m, void *data);
663 extern ssize_t lprocfs_uint_seq_write(struct file *file,
664 const char __user *buffer,
665 size_t count, loff_t *off);
666 extern int lprocfs_wr_uint(struct file *file, const char __user *buffer,
667 unsigned long count, void *data);
668 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
669 extern int lprocfs_name_seq_show(struct seq_file *m, void *data);
670 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
671 extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data);
672 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
673 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
674 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
675 #ifdef HAVE_SERVER_SUPPORT
676 extern int lprocfs_num_exports_seq_show(struct seq_file *m, void *data);
678 struct adaptive_timeout;
679 extern int lprocfs_at_hist_helper(struct seq_file *m,
680 struct adaptive_timeout *at);
681 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
683 lprocfs_timeouts_seq_write(struct file *file, const char *buffer,
684 size_t count, loff_t *off);
685 #ifdef HAVE_SERVER_SUPPORT
687 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
688 size_t count, loff_t *off);
691 lprocfs_ping_seq_write(struct file *file, const char *buffer,
692 size_t count, loff_t *off);
694 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
695 size_t count, loff_t *off);
696 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
698 lprocfs_pinger_recov_seq_write(struct file *file, const char *buffer,
699 size_t count, loff_t *off);
702 extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data);
703 extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data);
704 extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data);
705 extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data);
706 extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data);
707 extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data);
709 extern int lprocfs_write_helper(const char __user *buffer, unsigned long count,
711 extern int lprocfs_write_frac_helper(const char __user *buffer,
714 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
715 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
717 extern int lprocfs_write_u64_helper(const char __user *buffer,
718 unsigned long count, __u64 *val);
719 extern int lprocfs_write_frac_u64_helper(const char __user *buffer,
721 __u64 *val, int mult);
722 char *lprocfs_find_named_value(const char *buffer, const char *name,
724 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
725 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
726 void lprocfs_oh_clear(struct obd_histogram *oh);
727 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
729 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
730 struct lprocfs_counter *cnt);
732 #ifdef HAVE_SERVER_SUPPORT
733 /* lprocfs_status.c: recovery status */
734 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
736 /* lprocfs_status.c: hash statistics */
737 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
739 /* lprocfs_status.c: IR factor */
740 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
742 lprocfs_ir_factor_seq_write(struct file *file, const char *buffer,
743 size_t count, loff_t *off);
745 extern int lprocfs_single_release(struct inode *, struct file *);
746 extern int lprocfs_seq_release(struct inode *, struct file *);
748 /* You must use these macros when you want to refer to
749 * the import in a client obd_device for a lprocfs entry */
750 #define LPROCFS_CLIMP_CHECK(obd) do { \
751 typecheck(struct obd_device *, obd); \
752 down_read(&(obd)->u.cli.cl_sem); \
753 if ((obd)->u.cli.cl_import == NULL) { \
754 up_read(&(obd)->u.cli.cl_sem); \
758 #define LPROCFS_CLIMP_EXIT(obd) \
759 up_read(&(obd)->u.cli.cl_sem);
761 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
762 proc entries; otherwise, you will define name##_seq_write function also for
763 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
764 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
765 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
766 static int name##_single_open(struct inode *inode, struct file *file) \
770 rc = LPROCFS_ENTRY_CHECK(inode); \
774 return single_open(file, name##_seq_show, PDE_DATA(inode)); \
776 static const struct file_operations name##_fops = { \
777 .owner = THIS_MODULE, \
778 .open = name##_single_open, \
780 .write = custom_seq_write, \
781 .llseek = seq_lseek, \
782 .release = lprocfs_single_release, \
785 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
786 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
788 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
789 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
791 return lprocfs_##type##_seq_show(m, m->private); \
793 LPROC_SEQ_FOPS_RO(name##_##type)
795 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
796 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
798 return lprocfs_##type##_seq_show(m, m->private); \
800 static ssize_t name##_##type##_seq_write(struct file *file, \
801 const char __user *buffer, size_t count, \
804 struct seq_file *seq = file->private_data; \
805 return lprocfs_##type##_seq_write(file, buffer, \
806 count, seq->private); \
808 LPROC_SEQ_FOPS(name##_##type);
810 #define LPROC_SEQ_FOPS_WO_TYPE(name, type) \
811 static ssize_t name##_##type##_write(struct file *file, \
812 const char __user *buffer, size_t count, \
815 return lprocfs_##type##_seq_write(file, buffer, count, off);\
817 static int name##_##type##_open(struct inode *inode, struct file *file)\
819 return single_open(file, NULL, PDE_DATA(inode)); \
821 static const struct file_operations name##_##type##_fops = { \
822 .open = name##_##type##_open, \
823 .write = name##_##type##_write, \
824 .release = lprocfs_single_release, \
828 struct ptlrpc_request;
829 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
831 #ifdef HAVE_SERVER_SUPPORT
832 /* lprocfs_jobstats.c */
833 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
834 int event, long amount);
835 void lprocfs_job_stats_fini(struct obd_device *obd);
836 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
837 cntr_init_callback fn);
838 int lprocfs_job_interval_seq_show(struct seq_file *m, void *data);
840 lprocfs_job_interval_seq_write(struct file *file, const char *buffer,
841 size_t count, loff_t *off);
843 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data);
844 ssize_t lprocfs_recovery_time_soft_seq_write(struct file *file,
846 size_t count, loff_t *off);
847 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data);
849 lprocfs_recovery_time_hard_seq_write(struct file *file, const char *buffer,
850 size_t count, loff_t *off);
851 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data);
853 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
855 lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file, const char *buffer,
856 size_t count, loff_t *off);
858 struct root_squash_info;
859 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
860 struct root_squash_info *squash, char *name);
861 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
862 struct root_squash_info *squash, char *name);
864 /* all quota proc functions */
865 extern int lprocfs_quota_rd_bunit(char *page, char **start,
866 off_t off, int count,
867 int *eof, void *data);
868 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
869 unsigned long count, void *data);
870 extern int lprocfs_quota_rd_btune(char *page, char **start,
871 off_t off, int count,
872 int *eof, void *data);
873 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
874 unsigned long count, void *data);
875 extern int lprocfs_quota_rd_iunit(char *page, char **start,
876 off_t off, int count,
877 int *eof, void *data);
878 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
879 unsigned long count, void *data);
880 extern int lprocfs_quota_rd_itune(char *page, char **start,
881 off_t off, int count,
882 int *eof, void *data);
883 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
884 unsigned long count, void *data);
885 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
886 int *eof, void *data);
887 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
888 unsigned long count, void *data);
889 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
890 int count, int *eof, void *data);
891 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
893 unsigned long count, void *data);
894 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
895 int count, int *eof, void *data);
896 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
897 unsigned long count, void *data);
898 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
899 int count, int *eof, void *data);
900 extern int lprocfs_quota_wr_switch_qs(struct file *file,
902 unsigned long count, void *data);
903 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
904 int count, int *eof, void *data);
905 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
907 unsigned long count, void *data);
908 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
909 int count, int *eof, void *data);
910 extern int lprocfs_quota_wr_least_bunit(struct file *file,
912 unsigned long count, void *data);
913 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
914 int count, int *eof, void *data);
915 extern int lprocfs_quota_wr_least_iunit(struct file *file,
917 unsigned long count, void *data);
918 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
919 int count, int *eof, void *data);
920 extern int lprocfs_quota_wr_qs_factor(struct file *file,
922 unsigned long count, void *data);
923 #else /* !CONFIG_PROC_FS */
925 #define proc_lustre_root NULL
927 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
928 int index, long amount)
930 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
933 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
934 int index, long amount)
936 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
939 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
940 int index, unsigned conf,
941 const char *name, const char *units)
944 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
945 enum lprocfs_fields_flags field)
948 /* NB: we return !NULL to satisfy error checker */
949 static inline struct lprocfs_stats *
950 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
951 { return (struct lprocfs_stats *)1; }
952 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
954 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
956 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
958 struct lprocfs_stats *stats)
960 static inline void lprocfs_init_ops_stats(int num_private_stats,
961 struct lprocfs_stats *stats)
963 static inline void lprocfs_init_mps_stats(int num_private_stats,
964 struct lprocfs_stats *stats)
966 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
968 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
969 unsigned int num_private_stats)
971 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
972 unsigned int num_private_stats)
974 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
976 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
980 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
982 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
984 #ifdef HAVE_SERVER_SUPPORT
986 ssize_t lprocfs_nid_stats_seq_write(struct file *file, const char *buffer,
987 size_t count, loff_t *off)
990 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
992 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
995 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
997 static inline struct proc_dir_entry *
998 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
999 void *data, const struct file_operations *fops)
1001 static inline struct proc_dir_entry *
1002 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
1003 const char *format, ...)
1005 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
1006 struct lprocfs_vars *var, void *data)
1008 static inline struct proc_dir_entry *
1009 lprocfs_register(const char *name, struct proc_dir_entry *parent,
1010 struct lprocfs_vars *list, void *data)
1012 static inline void lprocfs_remove(struct proc_dir_entry **root)
1014 static inline void lprocfs_remove_proc_entry(const char *name,
1015 struct proc_dir_entry *parent)
1017 static inline int lprocfs_obd_setup(struct obd_device *dev)
1019 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
1021 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
1023 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
1025 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
1027 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
1029 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
1031 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
1033 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
1035 #ifdef HAVE_SERVER_SUPPORT
1036 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
1039 struct adaptive_timeout;
1040 static inline int lprocfs_at_hist_helper(struct seq_file *m,
1041 struct adaptive_timeout *at)
1043 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
1045 static inline ssize_t
1046 lprocfs_timeouts_seq_write(struct file *file, const char *buffer,
1047 size_t count, loff_t *off)
1049 #ifdef HAVE_SERVER_SUPPORT
1050 static inline ssize_t
1051 lprocfs_evict_client_seq_write(struct file *file, const char *buffer,
1052 size_t count, loff_t *off)
1055 static inline ssize_t
1056 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1057 size_t count, loff_t *off)
1059 static inline ssize_t
1060 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1061 size_t count, loff_t *off)
1064 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1066 static inline ssize_t
1067 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1068 size_t count, loff_t *off)
1071 /* Statfs helpers */
1073 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1076 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1079 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1082 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1085 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1088 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1091 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1094 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1097 void lprocfs_oh_clear(struct obd_histogram *oh)
1100 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1103 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1104 struct lprocfs_counter *cnt)
1107 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1108 enum lprocfs_fields_flags field)
1109 { return (__u64)0; }
1111 #define LPROC_SEQ_FOPS_RO(name)
1112 #define LPROC_SEQ_FOPS(name)
1113 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1114 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1115 #define LPROC_SEQ_FOPS_WO_TYPE(name, type)
1117 /* lprocfs_jobstats.c */
1119 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1123 void lprocfs_job_stats_fini(struct obd_device *obd)
1126 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1127 cntr_init_callback fn)
1131 /* lproc_ptlrpc.c */
1132 #define target_print_req NULL
1134 #endif /* CONFIG_PROC_FS */
1136 #endif /* LPROCFS_STATUS_H */