Whamcloud - gitweb
LU-8648 all: remove all Sun license and URL references
[fs/lustre-release.git] / lustre / include / lprocfs_status.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2015, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/include/lprocfs_status.h
33  *
34  * Top level header file for LProc
35  *
36  * Author: Hariharan Thantry thantry@users.sourceforge.net
37  */
38 #ifndef _LPROCFS_STATUS_H
39 #define _LPROCFS_STATUS_H
40
41 #include <linux/fs.h>
42 #include <linux/proc_fs.h>
43 #include <linux/rwsem.h>
44 #include <linux/spinlock.h>
45 #include <linux/seq_file.h>
46
47 #include <lustre/lustre_idl.h>
48
49 struct lprocfs_vars {
50         const char                      *name;
51         const struct file_operations    *fops;
52         void                            *data;
53         /**
54          * /proc file mode.
55          */
56         mode_t                           proc_mode;
57 };
58
59 /* if we find more consumers this could be generalized */
60 #define OBD_HIST_MAX 32
61 struct obd_histogram {
62         spinlock_t      oh_lock;
63         unsigned long   oh_buckets[OBD_HIST_MAX];
64 };
65
66 enum {
67         BRW_R_PAGES = 0,
68         BRW_W_PAGES,
69         BRW_R_RPC_HIST,
70         BRW_W_RPC_HIST,
71         BRW_R_IO_TIME,
72         BRW_W_IO_TIME,
73         BRW_R_DISCONT_PAGES,
74         BRW_W_DISCONT_PAGES,
75         BRW_R_DISCONT_BLOCKS,
76         BRW_W_DISCONT_BLOCKS,
77         BRW_R_DISK_IOSIZE,
78         BRW_W_DISK_IOSIZE,
79         BRW_R_DIO_FRAGS,
80         BRW_W_DIO_FRAGS,
81         BRW_LAST,
82 };
83
84 struct brw_stats {
85         struct obd_histogram hist[BRW_LAST];
86 };
87
88 enum {
89         RENAME_SAMEDIR_SIZE = 0,
90         RENAME_CROSSDIR_SRC_SIZE,
91         RENAME_CROSSDIR_TGT_SIZE,
92         RENAME_LAST,
93 };
94
95 struct rename_stats {
96         struct obd_histogram hist[RENAME_LAST];
97 };
98
99 /* An lprocfs counter can be configured using the enum bit masks below.
100  *
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.
106  *
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.
113  *
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.
118  */
119
120 enum {
121         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
122         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
123         LPROCFS_CNTR_STDDEV       = 0x0004,
124
125         /* counter data type */
126         LPROCFS_TYPE_REGS         = 0x0100,
127         LPROCFS_TYPE_BYTES        = 0x0200,
128         LPROCFS_TYPE_PAGES        = 0x0400,
129         LPROCFS_TYPE_CYCLE        = 0x0800,
130 };
131
132 #define LC_MIN_INIT ((~(__u64)0) >> 1)
133
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 */
138 };
139
140 struct lprocfs_counter {
141         __s64   lc_count;
142         __s64   lc_min;
143         __s64   lc_max;
144         __s64   lc_sumsquare;
145         /*
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
149          * lc_array_sum[1]
150          */
151         __s64   lc_array_sum[1];
152 };
153 #define lc_sum          lc_array_sum[0]
154 #define lc_sum_irq      lc_array_sum[1]
155
156 struct lprocfs_percpu {
157         struct lprocfs_counter lp_cntr[0];
158 };
159
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 */
163 };
164
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 */
170 };
171
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,
180 };
181
182 struct lprocfs_stats {
183         /* # of counters */
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 */
190         spinlock_t                      ls_lock;
191
192         /* has ls_num of counter headers */
193         struct lprocfs_counter_header   *ls_cnt_header;
194         struct lprocfs_percpu           *ls_percpu[0];
195 };
196
197 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
198
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) {
202                  /* OST opcode */
203                 return (opc - OST_FIRST_OPC);
204         } else if (opc < MDS_LAST_OPC) {
205                 /* MDS opcode */
206                 return (opc - MDS_FIRST_OPC +
207                         OPC_RANGE(OST));
208         } else if (opc < LDLM_LAST_OPC) {
209                 /* LDLM Opcode */
210                 return (opc - LDLM_FIRST_OPC +
211                         OPC_RANGE(MDS) +
212                         OPC_RANGE(OST));
213         } else if (opc < MGS_LAST_OPC) {
214                 /* MGS Opcode */
215                 return (opc - MGS_FIRST_OPC +
216                         OPC_RANGE(LDLM) +
217                         OPC_RANGE(MDS) +
218                         OPC_RANGE(OST));
219         } else if (opc < OBD_LAST_OPC) {
220                 /* OBD Ping */
221                 return (opc - OBD_FIRST_OPC +
222                         OPC_RANGE(MGS) +
223                         OPC_RANGE(LDLM) +
224                         OPC_RANGE(MDS) +
225                         OPC_RANGE(OST));
226         } else if (opc < LLOG_LAST_OPC) {
227                 /* LLOG Opcode */
228                 return (opc - LLOG_FIRST_OPC +
229                         OPC_RANGE(OBD) +
230                         OPC_RANGE(MGS) +
231                         OPC_RANGE(LDLM) +
232                         OPC_RANGE(MDS) +
233                         OPC_RANGE(OST));
234         } else if (opc < QUOTA_LAST_OPC) {
235                 /* LQUOTA Opcode */
236                 return (opc - QUOTA_FIRST_OPC +
237                         OPC_RANGE(LLOG) +
238                         OPC_RANGE(OBD) +
239                         OPC_RANGE(MGS) +
240                         OPC_RANGE(LDLM) +
241                         OPC_RANGE(MDS) +
242                         OPC_RANGE(OST));
243         } else if (opc < SEQ_LAST_OPC) {
244                 /* SEQ opcode */
245                 return (opc - SEQ_FIRST_OPC +
246                         OPC_RANGE(QUOTA) +
247                         OPC_RANGE(LLOG) +
248                         OPC_RANGE(OBD) +
249                         OPC_RANGE(MGS) +
250                         OPC_RANGE(LDLM) +
251                         OPC_RANGE(MDS) +
252                         OPC_RANGE(OST));
253         } else if (opc < SEC_LAST_OPC) {
254                 /* SEC opcode */
255                 return (opc - SEC_FIRST_OPC +
256                         OPC_RANGE(SEQ) +
257                         OPC_RANGE(QUOTA) +
258                         OPC_RANGE(LLOG) +
259                         OPC_RANGE(OBD) +
260                         OPC_RANGE(MGS) +
261                         OPC_RANGE(LDLM) +
262                         OPC_RANGE(MDS) +
263                         OPC_RANGE(OST));
264         } else if (opc < FLD_LAST_OPC) {
265                 /* FLD opcode */
266                  return (opc - FLD_FIRST_OPC +
267                         OPC_RANGE(SEC) +
268                         OPC_RANGE(SEQ) +
269                         OPC_RANGE(QUOTA) +
270                         OPC_RANGE(LLOG) +
271                         OPC_RANGE(OBD) +
272                         OPC_RANGE(MGS) +
273                         OPC_RANGE(LDLM) +
274                         OPC_RANGE(MDS) +
275                         OPC_RANGE(OST));
276         } else if (opc < OUT_UPDATE_LAST_OPC) {
277                 /* update opcode */
278                 return (opc - OUT_UPDATE_FIRST_OPC +
279                         OPC_RANGE(FLD) +
280                         OPC_RANGE(SEC) +
281                         OPC_RANGE(SEQ) +
282                         OPC_RANGE(QUOTA) +
283                         OPC_RANGE(LLOG) +
284                         OPC_RANGE(OBD) +
285                         OPC_RANGE(MGS) +
286                         OPC_RANGE(LDLM) +
287                         OPC_RANGE(MDS) +
288                         OPC_RANGE(OST));
289         } else if (opc < LFSCK_LAST_OPC) {
290                 /* LFSCK opcode */
291                 return (opc - LFSCK_FIRST_OPC +
292                         OPC_RANGE(OUT_UPDATE) +
293                         OPC_RANGE(FLD) +
294                         OPC_RANGE(SEC) +
295                         OPC_RANGE(SEQ) +
296                         OPC_RANGE(QUOTA) +
297                         OPC_RANGE(LLOG) +
298                         OPC_RANGE(OBD) +
299                         OPC_RANGE(MGS) +
300                         OPC_RANGE(LDLM) +
301                         OPC_RANGE(MDS) +
302                         OPC_RANGE(OST));
303         } else {
304                 /* Unknown Opcode */
305                 return -1;
306         }
307 }
308
309
310 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
311                             OPC_RANGE(MDS)  + \
312                             OPC_RANGE(LDLM) + \
313                             OPC_RANGE(MGS)  + \
314                             OPC_RANGE(OBD)  + \
315                             OPC_RANGE(LLOG) + \
316                             OPC_RANGE(SEC)  + \
317                             OPC_RANGE(SEQ)  + \
318                             OPC_RANGE(SEC)  + \
319                             OPC_RANGE(FLD)  + \
320                             OPC_RANGE(OUT_UPDATE) + \
321                             OPC_RANGE(LFSCK))
322
323 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
324                             OPC_RANGE(EXTRA))
325
326 enum {
327         PTLRPC_REQWAIT_CNTR = 0,
328         PTLRPC_REQQDEPTH_CNTR,
329         PTLRPC_REQACTIVE_CNTR,
330         PTLRPC_TIMEOUT,
331         PTLRPC_REQBUF_AVAIL_CNTR,
332         PTLRPC_LAST_CNTR
333 };
334
335 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
336
337 enum lprocfs_extra_opc {
338         LDLM_GLIMPSE_ENQUEUE = 0,
339         LDLM_PLAIN_ENQUEUE,
340         LDLM_EXTENT_ENQUEUE,
341         LDLM_FLOCK_ENQUEUE,
342         LDLM_IBITS_ENQUEUE,
343         MDS_REINT_SETATTR,
344         MDS_REINT_CREATE,
345         MDS_REINT_LINK,
346         MDS_REINT_UNLINK,
347         MDS_REINT_RENAME,
348         MDS_REINT_OPEN,
349         MDS_REINT_SETXATTR,
350         BRW_READ_BYTES,
351         BRW_WRITE_BYTES,
352         EXTRA_LAST_OPC
353 };
354
355 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
356 /* class_obd.c */
357 extern struct proc_dir_entry *proc_lustre_root;
358
359 struct obd_device;
360 struct obd_histogram;
361
362 /* Days / hours / mins / seconds format */
363 struct dhms {
364         int d,h,m,s;
365 };
366 static inline void s2dhms(struct dhms *ts, time_t secs)
367 {
368         ts->d = secs / 86400;
369         secs = secs % 86400;
370         ts->h = secs / 3600;
371         secs = secs % 3600;
372         ts->m = secs / 60;
373         ts->s = secs % 60;
374 }
375 #define DHMS_FMT "%dd%dh%02dm%02ds"
376 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
377
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"
382
383 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
384
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 */
394 };
395
396 #ifdef CONFIG_PROC_FS
397
398 extern int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
399                                    unsigned int cpuid);
400
401 /**
402  * Lock statistics structure for access, possibly only on this CPU.
403  *
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.
408  *
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.
414  *
415  * For global statistics, lock the stats structure to prevent concurrent update.
416  *
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
424  *
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)
427  */
428 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats,
429                                      enum lprocfs_stats_lock_ops opc,
430                                      unsigned long *flags)
431 {
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);
435                 else
436                         spin_lock(&stats->ls_lock);
437                 return opc == LPROCFS_GET_NUM_CPU ? 1 : 0;
438         }
439
440         switch (opc) {
441         case LPROCFS_GET_SMP_ID: {
442                 unsigned int cpuid = get_cpu();
443
444                 if (unlikely(stats->ls_percpu[cpuid] == NULL)) {
445                         int rc = lprocfs_stats_alloc_one(stats, cpuid);
446                         if (rc < 0) {
447                                 put_cpu();
448                                 return rc;
449                         }
450                 }
451                 return cpuid;
452         }
453         case LPROCFS_GET_NUM_CPU:
454                 return stats->ls_biggest_alloc_num;
455         default:
456                 LBUG();
457         }
458 }
459
460 /**
461  * Unlock statistics structure after access.
462  *
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.
465  *
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.
468  *
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
472  */
473 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats,
474                                         enum lprocfs_stats_lock_ops opc,
475                                         unsigned long *flags)
476 {
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);
480                 else
481                         spin_unlock(&stats->ls_lock);
482         } else if (opc == LPROCFS_GET_SMP_ID) {
483                 put_cpu();
484         }
485 }
486
487 static inline unsigned int
488 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
489 {
490         unsigned int percpusize;
491
492         percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
493
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);
497
498         if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
499                 percpusize = L1_CACHE_ALIGN(percpusize);
500
501         return percpusize;
502 }
503
504 static inline struct lprocfs_counter *
505 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
506                           int index)
507 {
508         struct lprocfs_counter *cntr;
509
510         cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
511
512         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
513                 cntr = (void *)cntr + index * sizeof(__s64);
514
515         return cntr;
516 }
517
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.
523  */
524
525 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
526                                 long amount);
527 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
528                                 long amount);
529
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)
534
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,
540                                             int idx,
541                                             enum lprocfs_fields_flags field)
542 {
543         unsigned int  i;
544         unsigned int  num_cpu;
545         unsigned long flags     = 0;
546         __u64         ret       = 0;
547
548         LASSERT(stats != NULL);
549
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)
553                         continue;
554                 ret += lprocfs_read_helper(
555                                 lprocfs_stats_counter_get(stats, i, idx),
556                                 &stats->ls_cnt_header[idx], stats->ls_flags,
557                                 field);
558         }
559         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
560         return ret;
561 }
562
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,
578                                  const char *units);
579 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
580 extern void lprocfs_free_md_stats(struct obd_device *obddev);
581 struct obd_export;
582 struct nid_stat;
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);
588 #else
589 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
590 { return 0; }
591 #endif
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
600 extern ssize_t
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);
604 #endif
605 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
606                                   struct lprocfs_stats *stats);
607
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)
621
622 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
623 {
624         struct proc_dir_entry *dp = PDE(inode);
625         int deleted = 0;
626
627         spin_lock(&(dp)->pde_unload_lock);
628         if (dp->proc_fops == NULL)
629                 deleted = 1;
630         spin_unlock(&(dp)->pde_unload_lock);
631         if (deleted)
632                 return -ENODEV;
633         return 0;
634 }
635 #else
636 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
637 { return 0; }
638 #endif
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;
643 #endif
644 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
645                               mode_t mode,
646                               const struct file_operations *seq_fops,
647                               void *data);
648 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
649                                   mode_t mode,
650                                   const struct file_operations *seq_fops,
651                                   void *data);
652
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);
674 #endif
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);
679 extern ssize_t
680 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
681                            size_t count, loff_t *off);
682 #ifdef HAVE_SERVER_SUPPORT
683 extern ssize_t
684 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
685                                 size_t count, loff_t *off);
686 #endif
687 extern ssize_t
688 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
689                        size_t count, loff_t *off);
690 extern ssize_t
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);
694 extern ssize_t
695 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
696                                size_t count, loff_t *off);
697
698 /* Statfs helpers */
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);
705
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,
708                                     long val, int mult);
709 extern int lprocfs_str_to_s64(const char __user *buffer, unsigned long count,
710                               __s64 *val);
711 extern int lprocfs_str_with_units_to_s64(const char __user *buffer,
712                                          unsigned long count, __s64 *val,
713                                          char defunit);
714 char *lprocfs_find_named_value(const char *buffer, const char *name,
715                                 size_t *count);
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);
720
721 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
722                            struct lprocfs_counter *cnt);
723
724 #ifdef HAVE_SERVER_SUPPORT
725 /* lprocfs_status.c: recovery status */
726 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
727
728 /* lprocfs_status.c: hash statistics */
729 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
730
731 /* lprocfs_status.c: IR factor */
732 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
733 ssize_t
734 lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
735                                 size_t count, loff_t *off);
736 #endif
737 extern int lprocfs_single_release(struct inode *, struct file *);
738 extern int lprocfs_seq_release(struct inode *, struct file *);
739
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); \
747              return -ENODEV;                    \
748         }                                       \
749 } while(0)
750 #define LPROCFS_CLIMP_EXIT(obd)                 \
751         up_read(&(obd)->u.cli.cl_sem);
752
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)   \
759 {                                                                       \
760         int rc;                                                         \
761                                                                         \
762         rc = LPROCFS_ENTRY_CHECK(inode);                                \
763         if (rc < 0)                                                     \
764                 return rc;                                              \
765                                                                         \
766         return single_open(file, name##_seq_show, PDE_DATA(inode));     \
767 }                                                                       \
768 static const struct file_operations name##_fops = {                     \
769         .owner   = THIS_MODULE,                                         \
770         .open    = name##_single_open,                                  \
771         .read    = seq_read,                                            \
772         .write   = custom_seq_write,                                    \
773         .llseek  = seq_lseek,                                           \
774         .release = lprocfs_single_release,                              \
775 }
776
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)
779
780 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)                              \
781         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
782         {                                                               \
783                 return lprocfs_##type##_seq_show(m, m->private);        \
784         }                                                               \
785         LPROC_SEQ_FOPS_RO(name##_##type)
786
787 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)                              \
788         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
789         {                                                               \
790                 return lprocfs_##type##_seq_show(m, m->private);        \
791         }                                                               \
792         static ssize_t name##_##type##_seq_write(struct file *file,     \
793                         const char __user *buffer, size_t count,        \
794                         loff_t *off)                                    \
795         {                                                               \
796                 struct seq_file *seq = file->private_data;              \
797                 return lprocfs_##type##_seq_write(file, buffer,         \
798                                                 count, seq->private);   \
799         }                                                               \
800         LPROC_SEQ_FOPS(name##_##type);
801
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,        \
805                         loff_t *off)                                    \
806         {                                                               \
807                 return lprocfs_##type##_seq_write(file, buffer, count, off);\
808         }                                                               \
809         static int name##_##type##_open(struct inode *inode, struct file *file)\
810         {                                                               \
811                 return single_open(file, NULL, PDE_DATA(inode));        \
812         }                                                               \
813         static const struct file_operations name##_##type##_fops = {    \
814                 .open    = name##_##type##_open,                        \
815                 .write   = name##_##type##_write,                       \
816                 .release = lprocfs_single_release,                      \
817         };
818
819 /* lproc_ptlrpc.c */
820 struct ptlrpc_request;
821 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
822
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);
831 ssize_t
832 lprocfs_job_interval_seq_write(struct file *file, const char __user *buffer,
833                                 size_t count, loff_t *off);
834 /* lproc_status.c */
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);
840 ssize_t
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);
845 #endif
846 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
847 ssize_t
848 lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
849                                         const char __user *buffer,
850                                         size_t count, loff_t *off);
851
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);
857
858 #else /* !CONFIG_PROC_FS */
859
860 #define proc_lustre_root NULL
861
862 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
863                                        int index, long amount)
864 { return; }
865 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
866                                         int index)
867 { return; }
868 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
869                                        int index, long amount)
870 { return; }
871 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
872                                         int index)
873 { return; }
874 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
875                                         int index, unsigned conf,
876                                         const char *name, const char *units)
877 { return; }
878
879 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
880                                    enum lprocfs_fields_flags field)
881 { return 0; }
882
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)
888 { return; }
889 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
890 { return; }
891 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
892                                          const char *name,
893                                          struct lprocfs_stats *stats)
894 { return 0; }
895 static inline void lprocfs_init_ops_stats(int num_private_stats,
896                                           struct lprocfs_stats *stats)
897 { return; }
898 static inline void lprocfs_init_mps_stats(int num_private_stats,
899                                           struct lprocfs_stats *stats)
900 { return; }
901 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
902 { return; }
903 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
904                                           unsigned int num_private_stats)
905 { return 0; }
906 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
907                                          unsigned int num_private_stats)
908 { return 0; }
909 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
910 { return; }
911 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
912 { return; }
913
914 struct obd_export;
915 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
916 { return 0; }
917 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
918 { return; }
919 #ifdef HAVE_SERVER_SUPPORT
920 static inline
921 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
922                                     const char __user *buffer,
923                                     size_t count, loff_t *off)
924 {return 0;}
925 static inline
926 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
927 {return 0;}
928 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
929 { return 0; }
930 #endif
931 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
932 { return 0; }
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)
936 {return 0; }
937 static inline struct proc_dir_entry *
938 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
939                     const char *format, ...)
940 {return NULL; }
941 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
942                                    struct lprocfs_vars *var, void *data)
943 { return 0; }
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)
947 { return NULL; }
948 static inline void lprocfs_remove(struct proc_dir_entry **root)
949 { return; }
950 static inline void lprocfs_remove_proc_entry(const char *name,
951                                              struct proc_dir_entry *parent)
952 { return; }
953 static inline int lprocfs_obd_setup(struct obd_device *dev)
954 { return 0; }
955 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
956 { return 0; }
957 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
958 { return 0; }
959 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
960 { return 0; }
961 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
962 { return 0; }
963 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
964 { return 0; }
965 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
966 { return 0; }
967 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
968 { return 0; }
969 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
970 { return 0; }
971 #ifdef HAVE_SERVER_SUPPORT
972 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
973 { return 0; }
974 #endif
975 struct adaptive_timeout;
976 static inline int lprocfs_at_hist_helper(struct seq_file *m,
977                                          struct adaptive_timeout *at)
978 { return 0; }
979 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
980 { return 0; }
981 static inline ssize_t
982 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
983                            size_t count, loff_t *off)
984 { return 0; }
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)
989 { return 0; }
990 #endif
991 static inline ssize_t
992 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
993                        size_t count, loff_t *off)
994 { return 0; }
995 static inline ssize_t
996 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
997                          size_t count, loff_t *off)
998 { return 0; }
999 static inline int
1000 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1001 { return 0; }
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)
1005 { return 0; }
1006
1007 /* Statfs helpers */
1008 static inline
1009 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1010 { return 0; }
1011 static inline
1012 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1013 { return 0; }
1014 static inline
1015 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1016 { return 0; }
1017 static inline
1018 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1019 { return 0; }
1020 static inline
1021 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1022 { return 0; }
1023 static inline
1024 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1025 { return 0; }
1026 static inline
1027 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1028 { return; }
1029 static inline
1030 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1031 { return; }
1032 static inline
1033 void lprocfs_oh_clear(struct obd_histogram *oh)
1034 { return; }
1035 static inline
1036 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1037 { return 0; }
1038 static inline
1039 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1040                            struct lprocfs_counter *cnt)
1041 { return; }
1042 static inline
1043 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1044                                enum lprocfs_fields_flags field)
1045 { return (__u64)0; }
1046
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)
1052
1053 /* lprocfs_jobstats.c */
1054 static inline
1055 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1056                           long amount)
1057 { return 0; }
1058 static inline
1059 void lprocfs_job_stats_fini(struct obd_device *obd)
1060 { return; }
1061 static inline
1062 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1063                            cntr_init_callback fn)
1064 { return 0; }
1065
1066
1067 /* lproc_ptlrpc.c */
1068 #define target_print_req NULL
1069
1070 #endif /* CONFIG_PROC_FS */
1071
1072 #endif /* LPROCFS_STATUS_H */