Whamcloud - gitweb
b3eb9d612eb19ebfe717d7c950291329b8755c4f
[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, 2016, 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 extern struct kobject *lustre_kobj;
360
361 struct obd_device;
362 struct obd_histogram;
363
364 /* Days / hours / mins / seconds format */
365 struct dhms {
366         int d,h,m,s;
367 };
368 static inline void s2dhms(struct dhms *ts, time_t secs)
369 {
370         ts->d = secs / 86400;
371         secs = secs % 86400;
372         ts->h = secs / 3600;
373         secs = secs % 3600;
374         ts->m = secs / 60;
375         ts->s = secs % 60;
376 }
377 #define DHMS_FMT "%dd%dh%02dm%02ds"
378 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
379
380 #define JOBSTATS_JOBID_VAR_MAX_LEN      20
381 #define JOBSTATS_DISABLE                "disable"
382 #define JOBSTATS_PROCNAME_UID           "procname_uid"
383 #define JOBSTATS_NODELOCAL              "nodelocal"
384
385 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
386
387 struct obd_job_stats {
388         struct cfs_hash        *ojs_hash;       /* hash of jobids */
389         struct list_head        ojs_list;       /* list of job_stat structs */
390         rwlock_t                ojs_lock;       /* protect ojs_list/js_list */
391         unsigned int            ojs_cleanup_interval;/* seconds before expiry */
392         time_t                  ojs_last_cleanup; /* previous cleanup time */
393         cntr_init_callback      ojs_cntr_init_fn;/* lprocfs_stats initializer */
394         unsigned short          ojs_cntr_num;   /* number of stats in struct */
395         bool                    ojs_cleaning;   /* currently expiring stats */
396 };
397
398 #ifdef CONFIG_PROC_FS
399
400 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
401                             unsigned int cpuid);
402 int lprocfs_stats_lock(struct lprocfs_stats *stats,
403                        enum lprocfs_stats_lock_ops opc,
404                        unsigned long *flags);
405 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
406                           enum lprocfs_stats_lock_ops opc,
407                           unsigned long *flags);
408
409 static inline unsigned int
410 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
411 {
412         unsigned int percpusize;
413
414         percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
415
416         /* irq safe stats need lc_array_sum[1] */
417         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
418                 percpusize += stats->ls_num * sizeof(__s64);
419
420         if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
421                 percpusize = L1_CACHE_ALIGN(percpusize);
422
423         return percpusize;
424 }
425
426 static inline struct lprocfs_counter *
427 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
428                           int index)
429 {
430         struct lprocfs_counter *cntr;
431
432         cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
433
434         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
435                 cntr = (void *)cntr + index * sizeof(__s64);
436
437         return cntr;
438 }
439
440 /* Two optimized LPROCFS counter increment functions are provided:
441  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
442  *     lprocfs_counter_add(cntr) - use for multi-valued counters
443  * Counter data layout allows config flag, counter lock and the
444  * count itself to reside within a single cache line.
445  */
446
447 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
448                                 long amount);
449 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
450                                 long amount);
451
452 #define lprocfs_counter_incr(stats, idx) \
453         lprocfs_counter_add(stats, idx, 1)
454 #define lprocfs_counter_decr(stats, idx) \
455         lprocfs_counter_sub(stats, idx, 1)
456
457 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
458                                  struct lprocfs_counter_header *header,
459                                  enum lprocfs_stats_flags flags,
460                                  enum lprocfs_fields_flags field);
461 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
462                             enum lprocfs_fields_flags field);
463
464 extern struct lprocfs_stats *
465 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
466 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
467 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
468 extern void lprocfs_init_ops_stats(int num_private_stats,
469                                    struct lprocfs_stats *stats);
470 extern void lprocfs_init_mps_stats(int num_private_stats,
471                                    struct lprocfs_stats *stats);
472 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
473 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
474                                    unsigned int num_private_stats);
475 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
476                                   unsigned int num_private_stats);
477 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
478                                  unsigned conf, const char *name,
479                                  const char *units);
480 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
481 extern void lprocfs_free_md_stats(struct obd_device *obddev);
482 struct obd_export;
483 struct nid_stat;
484 extern int lprocfs_add_clear_entry(struct obd_device * obd,
485                                    struct proc_dir_entry *entry);
486 #ifdef HAVE_SERVER_SUPPORT
487 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
488 extern int lprocfs_exp_cleanup(struct obd_export *exp);
489 #else
490 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
491 { return 0; }
492 #endif
493 extern struct proc_dir_entry *
494 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
495                    void *data, const struct file_operations *fops);
496 extern struct proc_dir_entry *
497 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
498                     const char *format, ...);
499 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
500 #ifdef HAVE_SERVER_SUPPORT
501 extern ssize_t
502 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
503                                         size_t count, loff_t *off);
504 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
505 #endif
506 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
507                                   struct lprocfs_stats *stats);
508
509 /* lprocfs_status.c */
510 extern int lprocfs_add_vars(struct proc_dir_entry *root,
511                             struct lprocfs_vars *var, void *data);
512 extern struct proc_dir_entry *
513 lprocfs_register(const char *name, struct proc_dir_entry *parent,
514                  struct lprocfs_vars *list, void *data);
515 extern void lprocfs_remove(struct proc_dir_entry **root);
516 extern void lprocfs_remove_proc_entry(const char *name,
517                                       struct proc_dir_entry *parent);
518 #ifndef HAVE_REMOVE_PROC_SUBTREE
519 extern int remove_proc_subtree(const char *name,
520                                struct proc_dir_entry *parent);
521 #define PDE_DATA(inode)         (PDE(inode)->data)
522
523 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
524 {
525         struct proc_dir_entry *dp = PDE(inode);
526         int deleted = 0;
527
528         spin_lock(&(dp)->pde_unload_lock);
529         if (dp->proc_fops == NULL)
530                 deleted = 1;
531         spin_unlock(&(dp)->pde_unload_lock);
532         if (deleted)
533                 return -ENODEV;
534         return 0;
535 }
536 #else
537 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
538 { return 0; }
539 #endif
540 extern int lprocfs_obd_setup(struct obd_device *dev);
541 extern int lprocfs_obd_cleanup(struct obd_device *obd);
542 #ifdef HAVE_SERVER_SUPPORT
543 extern const struct file_operations lprocfs_evict_client_fops;
544 #endif
545 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
546                               mode_t mode,
547                               const struct file_operations *seq_fops,
548                               void *data);
549 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
550                                   mode_t mode,
551                                   const struct file_operations *seq_fops,
552                                   void *data);
553
554 /* Generic callbacks */
555 extern int lprocfs_u64_seq_show(struct seq_file *m, void *data);
556 extern int lprocfs_atomic_seq_show(struct seq_file *m, void *data);
557 extern ssize_t lprocfs_atomic_seq_write(struct file *file,
558                                         const char __user *buffer,
559                                         size_t count, loff_t *off);
560 extern int lprocfs_uint_seq_show(struct seq_file *m, void *data);
561 extern ssize_t lprocfs_uint_seq_write(struct file *file,
562                                       const char __user *buffer,
563                                       size_t count, loff_t *off);
564 extern int lprocfs_wr_uint(struct file *file, const char __user *buffer,
565                            unsigned long count, void *data);
566 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
567 extern int lprocfs_name_seq_show(struct seq_file *m, void *data);
568 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
569 extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data);
570 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
571 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
572 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
573 #ifdef HAVE_SERVER_SUPPORT
574 extern int lprocfs_num_exports_seq_show(struct seq_file *m, void *data);
575 #endif
576 struct adaptive_timeout;
577 extern int lprocfs_at_hist_helper(struct seq_file *m,
578                                   struct adaptive_timeout *at);
579 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
580 extern ssize_t
581 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
582                            size_t count, loff_t *off);
583 #ifdef HAVE_SERVER_SUPPORT
584 extern ssize_t
585 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
586                                 size_t count, loff_t *off);
587 #endif
588 extern ssize_t
589 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
590                        size_t count, loff_t *off);
591 extern ssize_t
592 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
593                          size_t count, loff_t *off);
594 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
595 extern ssize_t
596 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
597                                size_t count, loff_t *off);
598
599 /* Statfs helpers */
600 extern int lprocfs_blksize_seq_show(struct seq_file *m, void *data);
601 extern int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data);
602 extern int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data);
603 extern int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data);
604 extern int lprocfs_filestotal_seq_show(struct seq_file *m, void *data);
605 extern int lprocfs_filesfree_seq_show(struct seq_file *m, void *data);
606
607 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
608 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
609                                     long val, int mult);
610 extern int lprocfs_str_to_s64(const char __user *buffer, unsigned long count,
611                               __s64 *val);
612 extern int lprocfs_str_with_units_to_s64(const char __user *buffer,
613                                          unsigned long count, __s64 *val,
614                                          char defunit);
615 char *lprocfs_find_named_value(const char *buffer, const char *name,
616                                 size_t *count);
617 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
618 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
619 void lprocfs_oh_clear(struct obd_histogram *oh);
620 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
621
622 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
623                            struct lprocfs_counter *cnt);
624
625 #ifdef HAVE_SERVER_SUPPORT
626 /* lprocfs_status.c: recovery status */
627 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
628
629 /* lprocfs_status.c: hash statistics */
630 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
631
632 /* lprocfs_status.c: IR factor */
633 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
634 ssize_t
635 lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
636                                 size_t count, loff_t *off);
637 #endif
638 extern int lprocfs_single_release(struct inode *, struct file *);
639 extern int lprocfs_seq_release(struct inode *, struct file *);
640
641 /* You must use these macros when you want to refer to
642  * the import in a client obd_device for a lprocfs entry */
643 #define LPROCFS_CLIMP_CHECK(obd) do {           \
644         typecheck(struct obd_device *, obd);    \
645         down_read(&(obd)->u.cli.cl_sem);    \
646         if ((obd)->u.cli.cl_import == NULL) {   \
647              up_read(&(obd)->u.cli.cl_sem); \
648              return -ENODEV;                    \
649         }                                       \
650 } while(0)
651 #define LPROCFS_CLIMP_EXIT(obd)                 \
652         up_read(&(obd)->u.cli.cl_sem);
653
654 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
655   proc entries; otherwise, you will define name##_seq_write function also for
656   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
657   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
658 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                        \
659 static int name##_single_open(struct inode *inode, struct file *file)   \
660 {                                                                       \
661         int rc;                                                         \
662                                                                         \
663         rc = LPROCFS_ENTRY_CHECK(inode);                                \
664         if (rc < 0)                                                     \
665                 return rc;                                              \
666                                                                         \
667         return single_open(file, name##_seq_show, PDE_DATA(inode));     \
668 }                                                                       \
669 static const struct file_operations name##_fops = {                     \
670         .owner   = THIS_MODULE,                                         \
671         .open    = name##_single_open,                                  \
672         .read    = seq_read,                                            \
673         .write   = custom_seq_write,                                    \
674         .llseek  = seq_lseek,                                           \
675         .release = lprocfs_single_release,                              \
676 }
677
678 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
679 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
680
681 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)                              \
682         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
683         {                                                               \
684                 return lprocfs_##type##_seq_show(m, m->private);        \
685         }                                                               \
686         LPROC_SEQ_FOPS_RO(name##_##type)
687
688 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)                              \
689         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
690         {                                                               \
691                 return lprocfs_##type##_seq_show(m, m->private);        \
692         }                                                               \
693         static ssize_t name##_##type##_seq_write(struct file *file,     \
694                         const char __user *buffer, size_t count,        \
695                         loff_t *off)                                    \
696         {                                                               \
697                 struct seq_file *seq = file->private_data;              \
698                 return lprocfs_##type##_seq_write(file, buffer,         \
699                                                 count, seq->private);   \
700         }                                                               \
701         LPROC_SEQ_FOPS(name##_##type);
702
703 #define LPROC_SEQ_FOPS_WO_TYPE(name, type)                              \
704         static ssize_t name##_##type##_write(struct file *file,         \
705                         const char __user *buffer, size_t count,        \
706                         loff_t *off)                                    \
707         {                                                               \
708                 return lprocfs_##type##_seq_write(file, buffer, count, off);\
709         }                                                               \
710         static int name##_##type##_open(struct inode *inode, struct file *file)\
711         {                                                               \
712                 return single_open(file, NULL, PDE_DATA(inode));        \
713         }                                                               \
714         static const struct file_operations name##_##type##_fops = {    \
715                 .open    = name##_##type##_open,                        \
716                 .write   = name##_##type##_write,                       \
717                 .release = lprocfs_single_release,                      \
718         };
719
720 struct lustre_attr {
721         struct attribute attr;
722         ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
723                         char *buf);
724         ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
725                          const char *buf, size_t len);
726 };
727
728 #define LUSTRE_ATTR(name, mode, show, store) \
729 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
730
731 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
732 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
733
734 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
735                          char *buf);
736 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
737                           const char *buf, size_t len);
738
739 extern const struct sysfs_ops lustre_sysfs_ops;
740
741 /* lproc_ptlrpc.c */
742 struct ptlrpc_request;
743 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
744
745 #ifdef HAVE_SERVER_SUPPORT
746 /* lprocfs_jobstats.c */
747 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
748                           int event, long amount);
749 void lprocfs_job_stats_fini(struct obd_device *obd);
750 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
751                            cntr_init_callback fn);
752 int lprocfs_job_interval_seq_show(struct seq_file *m, void *data);
753 ssize_t
754 lprocfs_job_interval_seq_write(struct file *file, const char __user *buffer,
755                                 size_t count, loff_t *off);
756 /* lproc_status.c */
757 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data);
758 ssize_t lprocfs_recovery_time_soft_seq_write(struct file *file,
759                                                 const char __user *buffer,
760                                                 size_t count, loff_t *off);
761 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data);
762 ssize_t
763 lprocfs_recovery_time_hard_seq_write(struct file *file,
764                                      const char __user *buffer,
765                                      size_t count, loff_t *off);
766 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data);
767 #endif
768 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
769 ssize_t
770 lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
771                                         const char __user *buffer,
772                                         size_t count, loff_t *off);
773
774 struct root_squash_info;
775 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
776                            struct root_squash_info *squash, char *name);
777 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
778                              struct root_squash_info *squash, char *name);
779
780 #else /* !CONFIG_PROC_FS */
781
782 #define proc_lustre_root NULL
783
784 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
785                                        int index, long amount)
786 { return; }
787 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
788                                         int index)
789 { return; }
790 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
791                                        int index, long amount)
792 { return; }
793 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
794                                         int index)
795 { return; }
796 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
797                                         int index, unsigned conf,
798                                         const char *name, const char *units)
799 { return; }
800
801 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
802                                    enum lprocfs_fields_flags field)
803 { return 0; }
804
805 /* NB: we return !NULL to satisfy error checker */
806 static inline struct lprocfs_stats *
807 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
808 { return (struct lprocfs_stats *)1; }
809 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
810 { return; }
811 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
812 { return; }
813 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
814                                          const char *name,
815                                          struct lprocfs_stats *stats)
816 { return 0; }
817 static inline void lprocfs_init_ops_stats(int num_private_stats,
818                                           struct lprocfs_stats *stats)
819 { return; }
820 static inline void lprocfs_init_mps_stats(int num_private_stats,
821                                           struct lprocfs_stats *stats)
822 { return; }
823 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
824 { return; }
825 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
826                                           unsigned int num_private_stats)
827 { return 0; }
828 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
829                                          unsigned int num_private_stats)
830 { return 0; }
831 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
832 { return; }
833 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
834 { return; }
835
836 struct obd_export;
837 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
838 { return 0; }
839 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
840 { return; }
841 #ifdef HAVE_SERVER_SUPPORT
842 static inline
843 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
844                                     const char __user *buffer,
845                                     size_t count, loff_t *off)
846 {return 0;}
847 static inline
848 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
849 {return 0;}
850 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
851 { return 0; }
852 #endif
853 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
854 { return 0; }
855 static inline struct proc_dir_entry *
856 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
857                    void *data, const struct file_operations *fops)
858 {return 0; }
859 static inline struct proc_dir_entry *
860 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
861                     const char *format, ...)
862 {return NULL; }
863 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
864                                    struct lprocfs_vars *var, void *data)
865 { return 0; }
866 static inline struct proc_dir_entry *
867 lprocfs_register(const char *name, struct proc_dir_entry *parent,
868                  struct lprocfs_vars *list, void *data)
869 { return NULL; }
870 static inline void lprocfs_remove(struct proc_dir_entry **root)
871 { return; }
872 static inline void lprocfs_remove_proc_entry(const char *name,
873                                              struct proc_dir_entry *parent)
874 { return; }
875 static inline int lprocfs_obd_setup(struct obd_device *dev)
876 { return 0; }
877 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
878 { return 0; }
879 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
880 { return 0; }
881 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
882 { return 0; }
883 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
884 { return 0; }
885 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
886 { return 0; }
887 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
888 { return 0; }
889 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
890 { return 0; }
891 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
892 { return 0; }
893 #ifdef HAVE_SERVER_SUPPORT
894 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
895 { return 0; }
896 #endif
897 struct adaptive_timeout;
898 static inline int lprocfs_at_hist_helper(struct seq_file *m,
899                                          struct adaptive_timeout *at)
900 { return 0; }
901 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
902 { return 0; }
903 static inline ssize_t
904 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
905                            size_t count, loff_t *off)
906 { return 0; }
907 #ifdef HAVE_SERVER_SUPPORT
908 static inline ssize_t
909 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
910                                size_t count, loff_t *off)
911 { return 0; }
912 #endif
913 static inline ssize_t
914 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
915                        size_t count, loff_t *off)
916 { return 0; }
917 static inline ssize_t
918 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
919                          size_t count, loff_t *off)
920 { return 0; }
921 static inline int
922 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
923 { return 0; }
924 static inline ssize_t
925 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
926                                size_t count, loff_t *off)
927 { return 0; }
928
929 /* Statfs helpers */
930 static inline
931 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
932 { return 0; }
933 static inline
934 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
935 { return 0; }
936 static inline
937 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
938 { return 0; }
939 static inline
940 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
941 { return 0; }
942 static inline
943 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
944 { return 0; }
945 static inline
946 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
947 { return 0; }
948 static inline
949 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
950 { return; }
951 static inline
952 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
953 { return; }
954 static inline
955 void lprocfs_oh_clear(struct obd_histogram *oh)
956 { return; }
957 static inline
958 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
959 { return 0; }
960 static inline
961 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
962                            struct lprocfs_counter *cnt)
963 { return; }
964 static inline
965 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
966                             enum lprocfs_fields_flags field)
967 { return (__u64)0; }
968
969 #define LPROC_SEQ_FOPS_RO(name)
970 #define LPROC_SEQ_FOPS(name)
971 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
972 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
973 #define LPROC_SEQ_FOPS_WO_TYPE(name, type)
974
975 /* lprocfs_jobstats.c */
976 static inline
977 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
978                           long amount)
979 { return 0; }
980 static inline
981 void lprocfs_job_stats_fini(struct obd_device *obd)
982 { return; }
983 static inline
984 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
985                            cntr_init_callback fn)
986 { return 0; }
987
988
989 /* lproc_ptlrpc.c */
990 #define target_print_req NULL
991
992 #endif /* CONFIG_PROC_FS */
993
994 #endif /* LPROCFS_STATUS_H */