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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/include/lprocfs_status.h
34 * Top level header file for LProc
36 * Author: Hariharan Thantry thantry@users.sourceforge.net
38 #ifndef _LPROCFS_STATUS_H
39 #define _LPROCFS_STATUS_H
42 #include <linux/proc_fs.h>
43 #include <linux/rwsem.h>
44 #include <linux/spinlock.h>
45 #include <linux/seq_file.h>
47 #include <lustre/lustre_idl.h>
51 const struct file_operations *fops;
59 /* if we find more consumers this could be generalized */
60 #define OBD_HIST_MAX 32
61 struct obd_histogram {
63 unsigned long oh_buckets[OBD_HIST_MAX];
85 struct obd_histogram hist[BRW_LAST];
89 RENAME_SAMEDIR_SIZE = 0,
90 RENAME_CROSSDIR_SRC_SIZE,
91 RENAME_CROSSDIR_TGT_SIZE,
96 struct obd_histogram hist[RENAME_LAST];
99 /* An lprocfs counter can be configured using the enum bit masks below.
101 * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
102 * protects this counter from concurrent updates. If not specified,
103 * lprocfs an internal per-counter lock variable. External locks are
104 * not used to protect counter increments, but are used to protect
105 * counter readout and resets.
107 * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
108 * (i.e. counter can be incremented by more than "1"). When specified,
109 * the counter maintains min, max and sum in addition to a simple
110 * invocation count. This allows averages to be be computed.
111 * If not specified, the counter is an increment-by-1 counter.
112 * min, max, sum, etc. are not maintained.
114 * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
115 * squares (for multi-valued counter samples only). This allows
116 * external computation of standard deviation, but involves a 64-bit
117 * multiply per counter increment.
121 LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
122 LPROCFS_CNTR_AVGMINMAX = 0x0002,
123 LPROCFS_CNTR_STDDEV = 0x0004,
125 /* counter data type */
126 LPROCFS_TYPE_REGS = 0x0100,
127 LPROCFS_TYPE_BYTES = 0x0200,
128 LPROCFS_TYPE_PAGES = 0x0400,
129 LPROCFS_TYPE_CYCLE = 0x0800,
132 #define LC_MIN_INIT ((~(__u64)0) >> 1)
134 struct lprocfs_counter_header {
135 unsigned int lc_config;
136 const char *lc_name; /* must be static */
137 const char *lc_units; /* must be static */
140 struct lprocfs_counter {
146 * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
147 * for irq context counter, i.e. stats with
148 * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
151 __s64 lc_array_sum[1];
153 #define lc_sum lc_array_sum[0]
154 #define lc_sum_irq lc_array_sum[1]
156 struct lprocfs_percpu {
157 struct lprocfs_counter lp_cntr[0];
160 enum lprocfs_stats_lock_ops {
161 LPROCFS_GET_NUM_CPU = 0x0001, /* number allocated per-CPU stats */
162 LPROCFS_GET_SMP_ID = 0x0002, /* current stat to be updated */
165 enum lprocfs_stats_flags {
166 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
167 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
168 * area and need locking */
169 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
172 enum lprocfs_fields_flags {
173 LPROCFS_FIELDS_FLAGS_CONFIG = 0x0001,
174 LPROCFS_FIELDS_FLAGS_SUM = 0x0002,
175 LPROCFS_FIELDS_FLAGS_MIN = 0x0003,
176 LPROCFS_FIELDS_FLAGS_MAX = 0x0004,
177 LPROCFS_FIELDS_FLAGS_AVG = 0x0005,
178 LPROCFS_FIELDS_FLAGS_SUMSQUARE = 0x0006,
179 LPROCFS_FIELDS_FLAGS_COUNT = 0x0007,
182 struct lprocfs_stats {
184 unsigned short ls_num;
185 /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
186 unsigned short ls_biggest_alloc_num;
187 enum lprocfs_stats_flags ls_flags;
188 /* Lock used when there are no percpu stats areas; For percpu stats,
189 * it is used to protect ls_biggest_alloc_num change */
192 /* has ls_num of counter headers */
193 struct lprocfs_counter_header *ls_cnt_header;
194 struct lprocfs_percpu *ls_percpu[0];
197 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
199 /* Pack all opcodes down into a single monotonically increasing index */
200 static inline int opcode_offset(__u32 opc) {
201 if (opc < OST_LAST_OPC) {
203 return (opc - OST_FIRST_OPC);
204 } else if (opc < MDS_LAST_OPC) {
206 return (opc - MDS_FIRST_OPC +
208 } else if (opc < LDLM_LAST_OPC) {
210 return (opc - LDLM_FIRST_OPC +
213 } else if (opc < MGS_LAST_OPC) {
215 return (opc - MGS_FIRST_OPC +
219 } else if (opc < OBD_LAST_OPC) {
221 return (opc - OBD_FIRST_OPC +
226 } else if (opc < LLOG_LAST_OPC) {
228 return (opc - LLOG_FIRST_OPC +
234 } else if (opc < QUOTA_LAST_OPC) {
236 return (opc - QUOTA_FIRST_OPC +
243 } else if (opc < SEQ_LAST_OPC) {
245 return (opc - SEQ_FIRST_OPC +
253 } else if (opc < SEC_LAST_OPC) {
255 return (opc - SEC_FIRST_OPC +
264 } else if (opc < FLD_LAST_OPC) {
266 return (opc - FLD_FIRST_OPC +
276 } else if (opc < OUT_UPDATE_LAST_OPC) {
278 return (opc - OUT_UPDATE_FIRST_OPC +
289 } else if (opc < LFSCK_LAST_OPC) {
291 return (opc - LFSCK_FIRST_OPC +
292 OPC_RANGE(OUT_UPDATE) +
310 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST) + \
320 OPC_RANGE(OUT_UPDATE) + \
323 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
327 PTLRPC_REQWAIT_CNTR = 0,
328 PTLRPC_REQQDEPTH_CNTR,
329 PTLRPC_REQACTIVE_CNTR,
331 PTLRPC_REQBUF_AVAIL_CNTR,
335 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
337 enum lprocfs_extra_opc {
338 LDLM_GLIMPSE_ENQUEUE = 0,
355 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
357 extern struct proc_dir_entry *proc_lustre_root;
360 struct obd_histogram;
362 /* Days / hours / mins / seconds format */
366 static inline void s2dhms(struct dhms *ts, time_t secs)
368 ts->d = secs / 86400;
375 #define DHMS_FMT "%dd%dh%02dm%02ds"
376 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
378 #define JOBSTATS_JOBID_VAR_MAX_LEN 20
379 #define JOBSTATS_DISABLE "disable"
380 #define JOBSTATS_PROCNAME_UID "procname_uid"
381 #define JOBSTATS_NODELOCAL "nodelocal"
383 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
385 struct obd_job_stats {
386 struct cfs_hash *ojs_hash; /* hash of jobids */
387 struct list_head ojs_list; /* list of job_stat structs */
388 rwlock_t ojs_lock; /* protect ojs_list/js_list */
389 unsigned int ojs_cleanup_interval;/* seconds before expiry */
390 time_t ojs_last_cleanup; /* previous cleanup time */
391 cntr_init_callback ojs_cntr_init_fn;/* lprocfs_stats initializer */
392 unsigned short ojs_cntr_num; /* number of stats in struct */
393 bool ojs_cleaning; /* currently expiring stats */
396 #ifdef CONFIG_PROC_FS
398 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
402 * Lock statistics structure for access, possibly only on this CPU.
404 * The statistics struct may be allocated with per-CPU structures for
405 * efficient concurrent update (usually only on server-wide stats), or
406 * as a single global struct (e.g. for per-client or per-job statistics),
407 * so the required locking depends on the type of structure allocated.
409 * For per-CPU statistics, pin the thread to the current cpuid so that
410 * will only access the statistics for that CPU. If the stats structure
411 * for the current CPU has not been allocated (or previously freed),
412 * allocate it now. The per-CPU statistics do not need locking since
413 * the thread is pinned to the CPU during update.
415 * For global statistics, lock the stats structure to prevent concurrent update.
417 * \param[in] stats statistics structure to lock
418 * \param[in] opc type of operation:
419 * LPROCFS_GET_SMP_ID: "lock" and return current CPU index
420 * for incrementing statistics for that CPU
421 * LPROCFS_GET_NUM_CPU: "lock" and return number of used
422 * CPU indices to iterate over all indices
423 * \param[out] flags CPU interrupt saved state for IRQ-safe locking
425 * \retval cpuid of current thread or number of allocated structs
426 * \retval negative on error (only for opc LPROCFS_GET_SMP_ID + per-CPU stats)
428 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats,
429 enum lprocfs_stats_lock_ops opc,
430 unsigned long *flags)
432 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
433 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
434 spin_lock_irqsave(&stats->ls_lock, *flags);
436 spin_lock(&stats->ls_lock);
437 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
441 case LPROCFS_GET_SMP_ID: {
442 unsigned int cpuid = get_cpu();
444 if (unlikely(stats->ls_percpu[cpuid] == NULL)) {
445 int rc = lprocfs_stats_alloc_one(stats, cpuid);
453 case LPROCFS_GET_NUM_CPU:
454 return stats->ls_biggest_alloc_num;
461 * Unlock statistics structure after access.
463 * Unlock the lock acquired via lprocfs_stats_lock() for global statistics,
464 * or unpin this thread from the current cpuid for per-CPU statistics.
466 * This function must be called using the same arguments as used when calling
467 * lprocfs_stats_lock() so that the correct operation can be performed.
469 * \param[in] stats statistics structure to unlock
470 * \param[in] opc type of operation (current cpuid or number of structs)
471 * \param[in] flags CPU interrupt saved state for IRQ-safe locking
473 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats,
474 enum lprocfs_stats_lock_ops opc,
475 unsigned long *flags)
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, *flags);
481 spin_unlock(&stats->ls_lock);
482 } else if (opc == LPROCFS_GET_SMP_ID) {
487 static inline unsigned int
488 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
490 unsigned int percpusize;
492 percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
494 /* irq safe stats need lc_array_sum[1] */
495 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
496 percpusize += stats->ls_num * sizeof(__s64);
498 if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
499 percpusize = L1_CACHE_ALIGN(percpusize);
504 static inline struct lprocfs_counter *
505 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
508 struct lprocfs_counter *cntr;
510 cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
512 if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
513 cntr = (void *)cntr + index * sizeof(__s64);
518 /* Two optimized LPROCFS counter increment functions are provided:
519 * lprocfs_counter_incr(cntr, value) - optimized for by-one counters
520 * lprocfs_counter_add(cntr) - use for multi-valued counters
521 * Counter data layout allows config flag, counter lock and the
522 * count itself to reside within a single cache line.
525 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
527 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
530 #define lprocfs_counter_incr(stats, idx) \
531 lprocfs_counter_add(stats, idx, 1)
532 #define lprocfs_counter_decr(stats, idx) \
533 lprocfs_counter_sub(stats, idx, 1)
535 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
536 struct lprocfs_counter_header *header,
537 enum lprocfs_stats_flags flags,
538 enum lprocfs_fields_flags field);
539 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
541 enum lprocfs_fields_flags field)
544 unsigned int num_cpu;
545 unsigned long flags = 0;
548 LASSERT(stats != NULL);
550 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
551 for (i = 0; i < num_cpu; i++) {
552 if (stats->ls_percpu[i] == NULL)
554 ret += lprocfs_read_helper(
555 lprocfs_stats_counter_get(stats, i, idx),
556 &stats->ls_cnt_header[idx], stats->ls_flags,
559 lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
563 extern struct lprocfs_stats *
564 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
565 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
566 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
567 extern void lprocfs_init_ops_stats(int num_private_stats,
568 struct lprocfs_stats *stats);
569 extern void lprocfs_init_mps_stats(int num_private_stats,
570 struct lprocfs_stats *stats);
571 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
572 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
573 unsigned int num_private_stats);
574 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
575 unsigned int num_private_stats);
576 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
577 unsigned conf, const char *name,
579 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
580 extern void lprocfs_free_md_stats(struct obd_device *obddev);
583 extern int lprocfs_add_clear_entry(struct obd_device * obd,
584 struct proc_dir_entry *entry);
585 #ifdef HAVE_SERVER_SUPPORT
586 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
587 extern int lprocfs_exp_cleanup(struct obd_export *exp);
589 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
592 extern struct proc_dir_entry *
593 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
594 void *data, const struct file_operations *fops);
595 extern struct proc_dir_entry *
596 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
597 const char *format, ...);
598 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
599 #ifdef HAVE_SERVER_SUPPORT
601 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
602 size_t count, loff_t *off);
603 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
605 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
606 struct lprocfs_stats *stats);
608 /* lprocfs_status.c */
609 extern int lprocfs_add_vars(struct proc_dir_entry *root,
610 struct lprocfs_vars *var, void *data);
611 extern struct proc_dir_entry *
612 lprocfs_register(const char *name, struct proc_dir_entry *parent,
613 struct lprocfs_vars *list, void *data);
614 extern void lprocfs_remove(struct proc_dir_entry **root);
615 extern void lprocfs_remove_proc_entry(const char *name,
616 struct proc_dir_entry *parent);
617 #ifndef HAVE_REMOVE_PROC_SUBTREE
618 extern int remove_proc_subtree(const char *name,
619 struct proc_dir_entry *parent);
620 #define PDE_DATA(inode) (PDE(inode)->data)
622 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
624 struct proc_dir_entry *dp = PDE(inode);
627 spin_lock(&(dp)->pde_unload_lock);
628 if (dp->proc_fops == NULL)
630 spin_unlock(&(dp)->pde_unload_lock);
636 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
639 extern int lprocfs_obd_setup(struct obd_device *dev);
640 extern int lprocfs_obd_cleanup(struct obd_device *obd);
641 #ifdef HAVE_SERVER_SUPPORT
642 extern const struct file_operations lprocfs_evict_client_fops;
644 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
646 const struct file_operations *seq_fops,
648 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
650 const struct file_operations *seq_fops,
653 /* Generic callbacks */
654 extern int lprocfs_u64_seq_show(struct seq_file *m, void *data);
655 extern int lprocfs_atomic_seq_show(struct seq_file *m, void *data);
656 extern ssize_t lprocfs_atomic_seq_write(struct file *file,
657 const char __user *buffer,
658 size_t count, loff_t *off);
659 extern int lprocfs_uint_seq_show(struct seq_file *m, void *data);
660 extern ssize_t lprocfs_uint_seq_write(struct file *file,
661 const char __user *buffer,
662 size_t count, loff_t *off);
663 extern int lprocfs_wr_uint(struct file *file, const char __user *buffer,
664 unsigned long count, void *data);
665 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
666 extern int lprocfs_name_seq_show(struct seq_file *m, void *data);
667 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
668 extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data);
669 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
670 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
671 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
672 #ifdef HAVE_SERVER_SUPPORT
673 extern int lprocfs_num_exports_seq_show(struct seq_file *m, void *data);
675 struct adaptive_timeout;
676 extern int lprocfs_at_hist_helper(struct seq_file *m,
677 struct adaptive_timeout *at);
678 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
680 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
681 size_t count, loff_t *off);
682 #ifdef HAVE_SERVER_SUPPORT
684 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
685 size_t count, loff_t *off);
688 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
689 size_t count, loff_t *off);
691 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
692 size_t count, loff_t *off);
693 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
695 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
696 size_t count, loff_t *off);
699 extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data);
700 extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data);
701 extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data);
702 extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data);
703 extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data);
704 extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data);
706 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
707 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
709 extern int lprocfs_str_to_s64(const char __user *buffer, unsigned long count,
711 extern int lprocfs_str_with_units_to_s64(const char __user *buffer,
712 unsigned long count, __s64 *val,
714 char *lprocfs_find_named_value(const char *buffer, const char *name,
716 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
717 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
718 void lprocfs_oh_clear(struct obd_histogram *oh);
719 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
721 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
722 struct lprocfs_counter *cnt);
724 #ifdef HAVE_SERVER_SUPPORT
725 /* lprocfs_status.c: recovery status */
726 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
728 /* lprocfs_status.c: hash statistics */
729 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
731 /* lprocfs_status.c: IR factor */
732 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
734 lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
735 size_t count, loff_t *off);
737 extern int lprocfs_single_release(struct inode *, struct file *);
738 extern int lprocfs_seq_release(struct inode *, struct file *);
740 /* You must use these macros when you want to refer to
741 * the import in a client obd_device for a lprocfs entry */
742 #define LPROCFS_CLIMP_CHECK(obd) do { \
743 typecheck(struct obd_device *, obd); \
744 down_read(&(obd)->u.cli.cl_sem); \
745 if ((obd)->u.cli.cl_import == NULL) { \
746 up_read(&(obd)->u.cli.cl_sem); \
750 #define LPROCFS_CLIMP_EXIT(obd) \
751 up_read(&(obd)->u.cli.cl_sem);
753 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
754 proc entries; otherwise, you will define name##_seq_write function also for
755 a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
756 call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
757 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
758 static int name##_single_open(struct inode *inode, struct file *file) \
762 rc = LPROCFS_ENTRY_CHECK(inode); \
766 return single_open(file, name##_seq_show, PDE_DATA(inode)); \
768 static const struct file_operations name##_fops = { \
769 .owner = THIS_MODULE, \
770 .open = name##_single_open, \
772 .write = custom_seq_write, \
773 .llseek = seq_lseek, \
774 .release = lprocfs_single_release, \
777 #define LPROC_SEQ_FOPS_RO(name) __LPROC_SEQ_FOPS(name, NULL)
778 #define LPROC_SEQ_FOPS(name) __LPROC_SEQ_FOPS(name, name##_seq_write)
780 #define LPROC_SEQ_FOPS_RO_TYPE(name, type) \
781 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
783 return lprocfs_##type##_seq_show(m, m->private); \
785 LPROC_SEQ_FOPS_RO(name##_##type)
787 #define LPROC_SEQ_FOPS_RW_TYPE(name, type) \
788 static int name##_##type##_seq_show(struct seq_file *m, void *v)\
790 return lprocfs_##type##_seq_show(m, m->private); \
792 static ssize_t name##_##type##_seq_write(struct file *file, \
793 const char __user *buffer, size_t count, \
796 struct seq_file *seq = file->private_data; \
797 return lprocfs_##type##_seq_write(file, buffer, \
798 count, seq->private); \
800 LPROC_SEQ_FOPS(name##_##type);
802 #define LPROC_SEQ_FOPS_WO_TYPE(name, type) \
803 static ssize_t name##_##type##_write(struct file *file, \
804 const char __user *buffer, size_t count, \
807 return lprocfs_##type##_seq_write(file, buffer, count, off);\
809 static int name##_##type##_open(struct inode *inode, struct file *file)\
811 return single_open(file, NULL, PDE_DATA(inode)); \
813 static const struct file_operations name##_##type##_fops = { \
814 .open = name##_##type##_open, \
815 .write = name##_##type##_write, \
816 .release = lprocfs_single_release, \
820 struct ptlrpc_request;
821 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
823 #ifdef HAVE_SERVER_SUPPORT
824 /* lprocfs_jobstats.c */
825 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
826 int event, long amount);
827 void lprocfs_job_stats_fini(struct obd_device *obd);
828 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
829 cntr_init_callback fn);
830 int lprocfs_job_interval_seq_show(struct seq_file *m, void *data);
832 lprocfs_job_interval_seq_write(struct file *file, const char __user *buffer,
833 size_t count, loff_t *off);
835 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data);
836 ssize_t lprocfs_recovery_time_soft_seq_write(struct file *file,
837 const char __user *buffer,
838 size_t count, loff_t *off);
839 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data);
841 lprocfs_recovery_time_hard_seq_write(struct file *file,
842 const char __user *buffer,
843 size_t count, loff_t *off);
844 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data);
846 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
848 lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
849 const char __user *buffer,
850 size_t count, loff_t *off);
852 struct root_squash_info;
853 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
854 struct root_squash_info *squash, char *name);
855 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
856 struct root_squash_info *squash, char *name);
858 #else /* !CONFIG_PROC_FS */
860 #define proc_lustre_root NULL
862 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
863 int index, long amount)
865 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
868 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
869 int index, long amount)
871 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
874 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
875 int index, unsigned conf,
876 const char *name, const char *units)
879 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
880 enum lprocfs_fields_flags field)
883 /* NB: we return !NULL to satisfy error checker */
884 static inline struct lprocfs_stats *
885 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
886 { return (struct lprocfs_stats *)1; }
887 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
889 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
891 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
893 struct lprocfs_stats *stats)
895 static inline void lprocfs_init_ops_stats(int num_private_stats,
896 struct lprocfs_stats *stats)
898 static inline void lprocfs_init_mps_stats(int num_private_stats,
899 struct lprocfs_stats *stats)
901 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
903 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
904 unsigned int num_private_stats)
906 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
907 unsigned int num_private_stats)
909 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
911 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
915 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
917 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
919 #ifdef HAVE_SERVER_SUPPORT
921 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
922 const char __user *buffer,
923 size_t count, loff_t *off)
926 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
928 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
931 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
933 static inline struct proc_dir_entry *
934 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
935 void *data, const struct file_operations *fops)
937 static inline struct proc_dir_entry *
938 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
939 const char *format, ...)
941 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
942 struct lprocfs_vars *var, void *data)
944 static inline struct proc_dir_entry *
945 lprocfs_register(const char *name, struct proc_dir_entry *parent,
946 struct lprocfs_vars *list, void *data)
948 static inline void lprocfs_remove(struct proc_dir_entry **root)
950 static inline void lprocfs_remove_proc_entry(const char *name,
951 struct proc_dir_entry *parent)
953 static inline int lprocfs_obd_setup(struct obd_device *dev)
955 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
957 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
959 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
961 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
963 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
965 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
967 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
969 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
971 #ifdef HAVE_SERVER_SUPPORT
972 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
975 struct adaptive_timeout;
976 static inline int lprocfs_at_hist_helper(struct seq_file *m,
977 struct adaptive_timeout *at)
979 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
981 static inline ssize_t
982 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
983 size_t count, loff_t *off)
985 #ifdef HAVE_SERVER_SUPPORT
986 static inline ssize_t
987 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
988 size_t count, loff_t *off)
991 static inline ssize_t
992 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
993 size_t count, loff_t *off)
995 static inline ssize_t
996 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
997 size_t count, loff_t *off)
1000 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1002 static inline ssize_t
1003 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1004 size_t count, loff_t *off)
1007 /* Statfs helpers */
1009 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1012 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1015 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1018 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1021 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1024 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1027 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1030 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1033 void lprocfs_oh_clear(struct obd_histogram *oh)
1036 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1039 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1040 struct lprocfs_counter *cnt)
1043 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1044 enum lprocfs_fields_flags field)
1045 { return (__u64)0; }
1047 #define LPROC_SEQ_FOPS_RO(name)
1048 #define LPROC_SEQ_FOPS(name)
1049 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1050 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1051 #define LPROC_SEQ_FOPS_WO_TYPE(name, type)
1053 /* lprocfs_jobstats.c */
1055 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1059 void lprocfs_job_stats_fini(struct obd_device *obd)
1062 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1063 cntr_init_callback fn)
1067 /* lproc_ptlrpc.c */
1068 #define target_print_req NULL
1070 #endif /* CONFIG_PROC_FS */
1072 #endif /* LPROCFS_STATUS_H */