Whamcloud - gitweb
b=18364
[fs/lustre-release.git] / lustre / include / lprocfs_status.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/lprocfs_status.h
37  *
38  * Top level header file for LProc SNMP
39  *
40  * Author: Hariharan Thantry thantry@users.sourceforge.net
41  */
42 #ifndef _LPROCFS_SNMP_H
43 #define _LPROCFS_SNMP_H
44
45 #if defined(__linux__)
46 #include <linux/lprocfs_status.h>
47 #elif defined(__APPLE__)
48 #include <darwin/lprocfs_status.h>
49 #elif defined(__WINNT__)
50 #include <winnt/lprocfs_status.h>
51 #else
52 #error Unsupported operating system.
53 #endif
54 #include <lustre/lustre_idl.h>
55
56 #undef LPROCFS
57 #if (defined(__KERNEL__) && defined(CONFIG_PROC_FS))
58 # define LPROCFS
59 #endif
60
61 struct lprocfs_vars {
62         const char   *name;
63         cfs_read_proc_t *read_fptr;
64         cfs_write_proc_t *write_fptr;
65         void *data;
66         struct file_operations *fops;
67         /**
68          * /proc file mode.
69          */
70         mode_t proc_mode;
71 };
72
73 struct lprocfs_static_vars {
74         struct lprocfs_vars *module_vars;
75         struct lprocfs_vars *obd_vars;
76 };
77
78 /* if we find more consumers this could be generalized */
79 #define OBD_HIST_MAX 32
80 struct obd_histogram {
81         spinlock_t      oh_lock;
82         unsigned long   oh_buckets[OBD_HIST_MAX];
83 };
84
85 enum {
86         BRW_R_PAGES = 0,
87         BRW_W_PAGES,
88         BRW_R_RPC_HIST,
89         BRW_W_RPC_HIST,
90         BRW_R_IO_TIME,
91         BRW_W_IO_TIME,
92         BRW_R_DISCONT_PAGES,
93         BRW_W_DISCONT_PAGES,
94         BRW_R_DISCONT_BLOCKS,
95         BRW_W_DISCONT_BLOCKS,
96         BRW_R_DISK_IOSIZE,
97         BRW_W_DISK_IOSIZE,
98         BRW_R_DIO_FRAGS,
99         BRW_W_DIO_FRAGS,
100         BRW_LAST,
101 };
102
103 struct brw_stats {
104         struct obd_histogram hist[BRW_LAST];
105 };
106
107
108 /* An lprocfs counter can be configured using the enum bit masks below.
109  *
110  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
111  * protects this counter from concurrent updates. If not specified,
112  * lprocfs an internal per-counter lock variable. External locks are
113  * not used to protect counter increments, but are used to protect
114  * counter readout and resets.
115  *
116  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
117  * (i.e. counter can be incremented by more than "1"). When specified,
118  * the counter maintains min, max and sum in addition to a simple
119  * invocation count. This allows averages to be be computed.
120  * If not specified, the counter is an increment-by-1 counter.
121  * min, max, sum, etc. are not maintained.
122  *
123  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
124  * squares (for multi-valued counter samples only). This allows
125  * external computation of standard deviation, but involves a 64-bit
126  * multiply per counter increment.
127  */
128
129 enum {
130         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
131         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
132         LPROCFS_CNTR_STDDEV       = 0x0004,
133
134         /* counter data type */
135         LPROCFS_TYPE_REGS         = 0x0100,
136         LPROCFS_TYPE_BYTES        = 0x0200,
137         LPROCFS_TYPE_PAGES        = 0x0400,
138         LPROCFS_TYPE_CYCLE        = 0x0800,
139 };
140
141 struct lprocfs_atomic {
142         atomic_t               la_entry;
143         atomic_t               la_exit;
144 };
145
146 #define LC_MIN_INIT ((~(__u64)0) >> 1)
147
148 struct lprocfs_counter {
149         struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
150         unsigned int           lc_config;
151         __s64                  lc_count;
152         __s64                  lc_sum;
153         __s64                  lc_min;
154         __s64                  lc_max;
155         __s64                  lc_sumsquare;
156         const char            *lc_name;   /* must be static */
157         const char            *lc_units;  /* must be static */
158 };
159
160 struct lprocfs_percpu {
161         struct lprocfs_counter lp_cntr[0];
162 };
163
164 #define LPROCFS_GET_NUM_CPU 0x0001
165 #define LPROCFS_GET_SMP_ID  0x0002
166
167 enum lprocfs_stats_flags {
168         LPROCFS_STATS_FLAG_NONE     = 0x0000, /* per cpu counter */
169         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
170                                                * area and need locking */
171         LPROCFS_STATS_GET_SMP_ID    = 0x0002, /* just record locking with
172                                                * LPROCFS_GET_SMP_ID flag */
173 };
174
175 enum lprocfs_fields_flags {
176         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
177         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
178         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
179         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
180         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
181         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
182         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
183 };
184
185 struct lprocfs_stats {
186         unsigned int           ls_num;     /* # of counters */
187         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
188         spinlock_t             ls_lock;  /* Lock used only when there are
189                                           * no percpu stats areas */
190         struct lprocfs_percpu *ls_percpu[0];
191 };
192
193 static inline int opcode_offset(__u32 opc) {
194         if (opc < OST_LAST_OPC) {
195                  /* OST opcode */
196                 return (opc - OST_FIRST_OPC);
197         } else if (opc < MDS_LAST_OPC) {
198                 /* MDS opcode */
199                 return (opc - MDS_FIRST_OPC +
200                         (OST_LAST_OPC - OST_FIRST_OPC));
201         } else if (opc < LDLM_LAST_OPC) {
202                 /* LDLM Opcode */
203                 return (opc - LDLM_FIRST_OPC +
204                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
205                         (OST_LAST_OPC - OST_FIRST_OPC));
206         } else if (opc < MGS_LAST_OPC) {
207                 /* MGS Opcode */
208                 return (opc - MGS_FIRST_OPC +
209                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
210                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
211                         (OST_LAST_OPC - OST_FIRST_OPC));
212         } else if (opc < OBD_LAST_OPC) {
213                 /* OBD Ping */
214                 return (opc - OBD_FIRST_OPC +
215                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
216                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
217                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
218                         (OST_LAST_OPC - OST_FIRST_OPC));
219         } else if (opc < LLOG_LAST_OPC) {
220                 /* LLOG Opcode */
221                 return (opc - LLOG_FIRST_OPC +
222                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
223                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
224                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
225                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
226                         (OST_LAST_OPC - OST_FIRST_OPC));
227         } else if (opc < QUOTA_LAST_OPC) {
228                 /* LQUOTA Opcode */
229                 return (opc - QUOTA_FIRST_OPC +
230                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
231                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
232                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
233                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
234                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
235                         (OST_LAST_OPC - OST_FIRST_OPC));
236         } else if (opc < SEQ_LAST_OPC) {
237                 /* SEQ opcode */
238                 return (opc - SEQ_FIRST_OPC +
239                         (QUOTA_LAST_OPC- QUOTA_FIRST_OPC) +
240                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
241                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
242                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
243                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
244                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
245                         (OST_LAST_OPC - OST_FIRST_OPC));
246         } else if (opc < SEC_LAST_OPC) {
247                 /* SEC opcode */
248                 return (opc - SEC_FIRST_OPC +
249                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
250                         (QUOTA_LAST_OPC- QUOTA_FIRST_OPC) +
251                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
252                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
253                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
254                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
255                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
256                         (OST_LAST_OPC - OST_FIRST_OPC));
257         } else if (opc < FLD_LAST_OPC) {
258                 /* FLD opcode */
259                  return (opc - FLD_FIRST_OPC +
260                         (SEC_LAST_OPC - SEC_FIRST_OPC) +
261                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
262                         (QUOTA_LAST_OPC- QUOTA_FIRST_OPC) +
263                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
264                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
265                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
266                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
267                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
268                         (OST_LAST_OPC - OST_FIRST_OPC));
269         } else {
270                 /* Unknown Opcode */
271                 return -1;
272         }
273 }
274
275
276 #define LUSTRE_MAX_OPCODES ((OST_LAST_OPC - OST_FIRST_OPC)     + \
277                             (MDS_LAST_OPC - MDS_FIRST_OPC)     + \
278                             (LDLM_LAST_OPC - LDLM_FIRST_OPC)   + \
279                             (MGS_LAST_OPC - MGS_FIRST_OPC)     + \
280                             (OBD_LAST_OPC - OBD_FIRST_OPC)     + \
281                             (LLOG_LAST_OPC - LLOG_FIRST_OPC)   + \
282                             (QUOTA_LAST_OPC - QUOTA_FIRST_OPC) + \
283                             (SEQ_LAST_OPC - SEQ_FIRST_OPC)     + \
284                             (SEC_LAST_OPC - SEC_FIRST_OPC)     + \
285                             (FLD_LAST_OPC - FLD_FIRST_OPC))
286
287 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
288                            (EXTRA_LAST_OPC - EXTRA_FIRST_OPC))
289
290 enum {
291         PTLRPC_REQWAIT_CNTR = 0,
292         PTLRPC_REQQDEPTH_CNTR,
293         PTLRPC_REQACTIVE_CNTR,
294         PTLRPC_TIMEOUT,
295         PTLRPC_REQBUF_AVAIL_CNTR,
296         PTLRPC_LAST_CNTR
297 };
298
299 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
300
301 enum {
302         LDLM_GLIMPSE_ENQUEUE = 0,
303         LDLM_PLAIN_ENQUEUE,
304         LDLM_EXTENT_ENQUEUE,
305         LDLM_FLOCK_ENQUEUE,
306         LDLM_IBITS_ENQUEUE,
307         MDS_REINT_SETATTR,
308         MDS_REINT_CREATE,
309         MDS_REINT_LINK,
310         MDS_REINT_UNLINK,
311         MDS_REINT_RENAME,
312         MDS_REINT_OPEN,
313         MDS_REINT_SETXATTR,
314         BRW_READ_BYTES,
315         BRW_WRITE_BYTES,
316         EXTRA_LAST_OPC
317 };
318
319 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
320 /* class_obd.c */
321 extern cfs_proc_dir_entry_t *proc_lustre_root;
322
323 struct obd_device;
324 struct file;
325 struct obd_histogram;
326
327 /* Days / hours / mins / seconds format */
328 struct dhms {
329         int d,h,m,s;
330 };
331 static inline void s2dhms(struct dhms *ts, time_t secs)
332 {
333         ts->d = secs / 86400;
334         secs = secs % 86400;
335         ts->h = secs / 3600;
336         secs = secs % 3600;
337         ts->m = secs / 60;
338         ts->s = secs % 60;
339 }
340 #define DHMS_FMT "%dd%dh%02dm%02ds"
341 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
342
343
344 #ifdef LPROCFS
345
346 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int type)
347 {
348         int rc = 0;
349
350         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
351                 if (type & LPROCFS_GET_NUM_CPU)
352                         rc = 1;
353                 if (type & LPROCFS_GET_SMP_ID)
354                         rc = 0;
355                 spin_lock(&stats->ls_lock);
356         } else {
357                 if (type & LPROCFS_GET_NUM_CPU)
358                         rc = num_possible_cpus();
359                 if (type & LPROCFS_GET_SMP_ID) {
360                         stats->ls_flags |= LPROCFS_STATS_GET_SMP_ID;
361                         rc = cfs_get_cpu();
362                 }
363         }
364         return rc;
365 }
366
367 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats)
368 {
369         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
370                 spin_unlock(&stats->ls_lock);
371         else if (stats->ls_flags & LPROCFS_STATS_GET_SMP_ID)
372                 cfs_put_cpu();
373 }
374
375 /* Two optimized LPROCFS counter increment functions are provided:
376  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
377  *     lprocfs_counter_add(cntr) - use for multi-valued counters
378  * Counter data layout allows config flag, counter lock and the
379  * count itself to reside within a single cache line.
380  */
381
382 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
383                                 long amount);
384 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
385                                 long amount);
386
387 #define lprocfs_counter_incr(stats, idx) \
388         lprocfs_counter_add(stats, idx, 1)
389 #define lprocfs_counter_decr(stats, idx) \
390         lprocfs_counter_sub(stats, idx, 1)
391
392 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
393                                  enum lprocfs_fields_flags field);
394 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
395                                             int idx,
396                                             enum lprocfs_fields_flags field)
397 {
398         __u64 ret = 0;
399         int i;
400
401         LASSERT(stats != NULL);
402         for (i = 0; i < num_possible_cpus(); i++)
403                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
404                                            field);
405         return ret;
406 }
407
408 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
409                                                  enum lprocfs_stats_flags flags);
410 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
411 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
412 extern void lprocfs_init_ops_stats(int num_private_stats,
413                                    struct lprocfs_stats *stats);
414 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
415 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
416                                    unsigned int num_private_stats);
417 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
418                                   unsigned int num_private_stats);
419 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
420                                  unsigned conf, const char *name,
421                                  const char *units);
422 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
423 struct obd_export;
424 struct nid_stat;
425 extern int lprocfs_add_clear_entry(struct obd_device * obd,
426                                    cfs_proc_dir_entry_t *entry);
427 extern int lprocfs_exp_setup(struct obd_export *exp,
428                              lnet_nid_t *peer_nid, int *newnid);
429 extern int lprocfs_exp_cleanup(struct obd_export *exp);
430 extern cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
431                                                 char *name,
432                                                 cfs_read_proc_t *read_proc,
433                                                 cfs_write_proc_t *write_proc,
434                                                 void *data,
435                                                 struct file_operations *fops);
436 extern struct proc_dir_entry *lprocfs_add_symlink(const char *name,
437                         struct proc_dir_entry *parent, const char *dest);
438 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
439 extern int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
440                                          unsigned long count, void *data);
441 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
442                                         int count, int *eof,  void *data);
443
444 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
445                                   struct lprocfs_stats *stats);
446
447 /* lprocfs_status.c */
448 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
449                             struct lprocfs_vars *var,
450                             void *data);
451
452 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
453                                                cfs_proc_dir_entry_t *parent,
454                                                struct lprocfs_vars *list,
455                                                void *data);
456
457 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
458 extern void lprocfs_remove_proc_entry(const char *name,
459                                       struct proc_dir_entry *parent);
460
461 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
462                                            const char *name);
463
464 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
465 extern int lprocfs_obd_cleanup(struct obd_device *obd);
466 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
467 extern struct file_operations lprocfs_evict_client_fops;
468
469 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
470                               mode_t mode, struct file_operations *seq_fops,
471                               void *data);
472 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
473                                   mode_t mode, struct file_operations *seq_fops,
474                                   void *data);
475
476 /* Generic callbacks */
477
478 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
479                           int count, int *eof, void *data);
480 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
481                              int count, int *eof, void *data);
482 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
483                              unsigned long count, void *data);
484 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
485                            int count, int *eof, void *data);
486 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
487                            unsigned long count, void *data);
488 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
489                            int count, int *eof, void *data);
490 extern int lprocfs_rd_name(char *page, char **start, off_t off,
491                            int count, int *eof, void *data);
492 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
493                              int count, int *eof, void *data);
494 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
495                                   int count, int *eof, void *data);
496 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
497                                 int count, int *eof, void *data);
498 extern int lprocfs_rd_import(char *page, char **start, off_t off, int count,
499                              int *eof, void *data);
500 extern int lprocfs_rd_state(char *page, char **start, off_t off, int count,
501                             int *eof, void *data);
502 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
503                                     int count, int *eof, void *data);
504 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
505                                   int count, int *eof, void *data);
506 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
507                               int count, int *eof, void *data);
508 struct adaptive_timeout;
509 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
510                                   struct adaptive_timeout *at);
511 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
512                                int count, int *eof, void *data);
513 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
514                                unsigned long count, void *data);
515 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
516                                    unsigned long count, void *data);
517 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
518                            unsigned long count, void *data);
519
520 /* Statfs helpers */
521 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
522                               int count, int *eof, void *data);
523 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
524                                   int count, int *eof, void *data);
525 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
526                                  int count, int *eof, void *data);
527 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
528                                  int count, int *eof, void *data);
529 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
530                                  int count, int *eof, void *data);
531 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
532                                 int count, int *eof, void *data);
533 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
534                                  int count, int *eof, void *data);
535
536 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
537                                 int *val);
538 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
539                                      int *val, int mult);
540 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
541                                     long val, int mult);
542 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
543                                     __u64 *val);
544 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
545                                          __u64 *val, int mult);
546 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
547 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
548 void lprocfs_oh_clear(struct obd_histogram *oh);
549 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
550
551 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
552                            struct lprocfs_counter *cnt);
553
554
555 /* lprocfs_status.c: recovery status */
556 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
557                                    int count, int *eof, void *data);
558
559 /* lprocfs_statuc.c: hash statistics */
560 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
561                         int count, int *eof, void *data);
562
563 extern int lprocfs_seq_release(struct inode *, struct file *);
564
565 /* in lprocfs_stat.c, to protect the private data for proc entries */
566 extern struct rw_semaphore _lprocfs_lock;
567 #define LPROCFS_ENTRY()           do {  \
568         down_read(&_lprocfs_lock);      \
569 } while(0)
570 #define LPROCFS_EXIT()            do {  \
571         up_read(&_lprocfs_lock);        \
572 } while(0)
573 #define LPROCFS_ENTRY_AND_CHECK(dp) do {        \
574         typecheck(struct proc_dir_entry *, dp); \
575         LPROCFS_ENTRY();                        \
576         if ((dp)->deleted) {                    \
577                 LPROCFS_EXIT();                 \
578                 return -ENODEV;                 \
579         }                                       \
580 } while(0)
581 #define LPROCFS_WRITE_ENTRY()     do {  \
582         down_write(&_lprocfs_lock);     \
583 } while(0)
584 #define LPROCFS_WRITE_EXIT()      do {  \
585         up_write(&_lprocfs_lock);       \
586 } while(0)
587
588 /* You must use these macros when you want to refer to
589  * the import in a client obd_device for a lprocfs entry */
590 #define LPROCFS_CLIMP_CHECK(obd) do {           \
591         typecheck(struct obd_device *, obd);    \
592         down_read(&(obd)->u.cli.cl_sem);        \
593         if ((obd)->u.cli.cl_import == NULL) {   \
594              up_read(&(obd)->u.cli.cl_sem);     \
595              return -ENODEV;                    \
596         }                                       \
597 } while(0)
598 #define LPROCFS_CLIMP_EXIT(obd)                 \
599         up_read(&(obd)->u.cli.cl_sem);
600
601
602 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
603   proc entries; otherwise, you will define name##_seq_write function also for
604   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
605   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
606 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
607 static int name##_seq_open(struct inode *inode, struct file *file) {       \
608         struct proc_dir_entry *dp = PDE(inode);                            \
609         int rc;                                                            \
610         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
611         rc = single_open(file, name##_seq_show, dp->data);                 \
612         if (rc) {                                                          \
613                 LPROCFS_EXIT();                                            \
614                 return rc;                                                 \
615         }                                                                  \
616         return 0;                                                          \
617 }                                                                          \
618 struct file_operations name##_fops = {                                     \
619         .owner   = THIS_MODULE,                                            \
620         .open    = name##_seq_open,                                        \
621         .read    = seq_read,                                               \
622         .write   = custom_seq_write,                                       \
623         .llseek  = seq_lseek,                                              \
624         .release = lprocfs_seq_release,                                    \
625 }
626
627 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
628 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
629
630 /* lproc_ptlrpc.c */
631 struct ptlrpc_request;
632 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
633
634 /* lprocfs_status.c: read recovery max time bz13079 */
635 int lprocfs_obd_rd_recovery_maxtime(char *page, char **start, off_t off,
636                                     int count, int *eof, void *data);
637
638 /* lprocfs_status.c: write recovery max time bz13079 */
639 int lprocfs_obd_wr_recovery_maxtime(struct file *file, const char *buffer,
640                                     unsigned long count, void *data);
641
642 /* all quota proc functions */
643 extern int lprocfs_quota_rd_bunit(char *page, char **start, off_t off, int count,
644                                   int *eof, void *data);
645 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
646                                   unsigned long count, void *data);
647 extern int lprocfs_quota_rd_btune(char *page, char **start, off_t off, int count,
648                                   int *eof, void *data);
649 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
650                                   unsigned long count, void *data);
651 extern int lprocfs_quota_rd_iunit(char *page, char **start, off_t off, int count,
652                                   int *eof, void *data);
653 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
654                                   unsigned long count, void *data);
655 extern int lprocfs_quota_rd_itune(char *page, char **start, off_t off, int count,
656                                   int *eof, void *data);
657 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
658                                   unsigned long count, void *data);
659 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
660                                  int *eof, void *data);
661 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
662                                  unsigned long count, void *data);
663 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
664                                            int count, int *eof, void *data);
665 extern int lprocfs_quota_wr_switch_seconds(struct file *file, const char *buffer,
666                                            unsigned long count, void *data);
667 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
668                                      int count, int *eof, void *data);
669 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
670                                      unsigned long count, void *data);
671 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
672                                       int count, int *eof, void *data);
673 extern int lprocfs_quota_wr_switch_qs(struct file *file, const char *buffer,
674                                       unsigned long count, void *data);
675 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
676                                             int count, int *eof, void *data);
677 extern int lprocfs_quota_wr_boundary_factor(struct file *file, const char *buffer,
678                                             unsigned long count, void *data);
679 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
680                                         int count, int *eof, void *data);
681 extern int lprocfs_quota_wr_least_bunit(struct file *file, const char *buffer,
682                                         unsigned long count, void *data);
683 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
684                                         int count, int *eof, void *data);
685 extern int lprocfs_quota_wr_least_iunit(struct file *file, const char *buffer,
686                                         unsigned long count, void *data);
687 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
688                                       int count, int *eof, void *data);
689 extern int lprocfs_quota_wr_qs_factor(struct file *file, const char *buffer,
690                                       unsigned long count, void *data);
691
692 /** struct for holding changelog data for seq_file processing */
693 struct changelog_seq_iter {
694         void *csi_dev;
695         struct llog_ctxt *csi_ctxt;
696         struct llog_handle *csi_llh;
697         __u64 csi_startrec;
698         __u64 csi_endrec;
699         loff_t csi_pos;
700         int csi_wrote;
701         int csi_startcat;
702         int csi_startidx;
703         int csi_fill:1;
704         int csi_done:1;
705 };
706 int changelog_seq_open(struct inode *inode, struct file *file,
707                        struct changelog_seq_iter **csih);
708 int changelog_seq_release(struct inode *inode, struct file *file);
709 loff_t changelog_seq_lseek(struct file *file, loff_t offset, int origin);
710
711
712
713 #else
714 /* LPROCFS is not defined */
715
716
717
718 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
719                                        int index, long amount) { return; }
720 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
721                                         int index) { return; }
722 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
723                                        int index, long amount) { return; }
724 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
725                                         int index, unsigned conf,
726                                         const char *name, const char *units)
727 { return; }
728
729 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
730                                    enum lprocfs_fields_flags field)
731 { return 0; }
732
733 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num,
734                                                         enum lprocfs_stats_flags flags)
735 { return NULL; }
736 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
737 { return; }
738 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
739 { return; }
740 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
741                                             const char *name,
742                                             struct lprocfs_stats *stats)
743 { return 0; }
744 static inline void lprocfs_init_ops_stats(int num_private_stats,
745                                           struct lprocfs_stats *stats)
746 { return; }
747 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
748 { return; }
749 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
750                                           unsigned int num_private_stats)
751 { return 0; }
752 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
753                                          unsigned int num_private_stats)
754 { return 0; }
755 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
756 { return; }
757
758 struct obd_export;
759 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
760 { return 0; }
761 static inline int lprocfs_exp_setup(struct obd_export *exp,
762                                     lnet_nid_t *peer_nid, int *newnid)
763 { return 0; }
764 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
765 { return 0; }
766 static inline cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
767                                      char *name,
768                                      cfs_read_proc_t *read_proc,
769                                      cfs_write_proc_t *write_proc,
770                                      void *data,
771                                      struct file_operations *fops)
772 {return 0; }
773 static inline struct proc_dir_entry *lprocfs_add_symlink(const char *name,
774                         struct proc_dir_entry *parent, const char *dest)
775 {return NULL; }
776 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
777 {}
778 static inline
779 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
780                                   unsigned long count, void *data)
781 {return count;}
782 static inline
783 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
784                                  int count, int *eof,  void *data)
785 {return count;}
786
787 static inline cfs_proc_dir_entry_t *
788 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
789                  struct lprocfs_vars *list, void *data) { return NULL; }
790 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
791                                    struct lprocfs_vars *var,
792                                    void *data) { return 0; }
793 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
794 static inline void lprocfs_remove_proc_entry(const char *name,
795                                              struct proc_dir_entry *parent) {};
796 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
797                                     const char *name) {return 0;}
798 static inline int lprocfs_obd_setup(struct obd_device *dev,
799                                     struct lprocfs_vars *list) { return 0; }
800 static inline int lprocfs_obd_cleanup(struct obd_device *dev)  { return 0; }
801 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
802                                  int count, int *eof, void *data) { return 0; }
803 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
804                                   int count, int *eof, void *data) { return 0; }
805 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
806                                   int count, int *eof, void *data) { return 0; }
807 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
808                                          int count, int *eof, void *data)
809 { return 0; }
810 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
811                                        int count, int *eof, void *data)
812 { return 0; }
813 static inline int lprocfs_rd_import(char *page, char **start, off_t off,
814                                     int count, int *eof, void *data)
815 { return 0; }
816 static inline int lprocfs_rd_state(char *page, char **start, off_t off,
817                                    int count, int *eof, void *data)
818 { return 0; }
819 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
820                                            int count, int *eof, void *data)
821 { return 0; }
822 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
823                                          int count, int *eof, void *data)
824 { return 0; }
825 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
826                                      int count, int *eof, void *data)
827 { return 0; }
828 struct adaptive_timeout;
829 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
830                                          struct adaptive_timeout *at)
831 { return 0; }
832 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
833                                       int count, int *eof, void *data)
834 { return 0; }
835 static inline int lprocfs_wr_timeouts(struct file *file, const char *buffer,
836                                       unsigned long count, void *data)
837 { return 0; }
838 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
839                                           unsigned long count, void *data)
840 { return 0; }
841 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
842                                   unsigned long count, void *data)
843 { return 0; }
844
845
846 /* Statfs helpers */
847 static inline
848 int lprocfs_rd_blksize(char *page, char **start, off_t off,
849                        int count, int *eof, void *data) { return 0; }
850 static inline
851 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
852                            int count, int *eof, void *data) { return 0; }
853 static inline
854 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
855                           int count, int *eof, void *data) { return 0; }
856 static inline
857 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
858                            int count, int *eof, void *data) { return 0; }
859 static inline
860 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
861                           int count, int *eof, void *data) { return 0; }
862 static inline
863 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
864                          int count, int *eof, void *data)  { return 0; }
865 static inline
866 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
867                           int count, int *eof, void *data) { return 0; }
868 static inline
869 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
870 static inline
871 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
872 static inline
873 void lprocfs_oh_clear(struct obd_histogram *oh) {}
874 static inline
875 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
876 static inline
877 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
878                            struct lprocfs_counter *cnt) {}
879
880 static inline
881 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
882                                enum lprocfs_fields_flags field)
883 { return (__u64)0; }
884
885 #define LPROCFS_ENTRY()
886 #define LPROCFS_EXIT()
887 #define LPROCFS_ENTRY_AND_CHECK(dp)
888 #define LPROC_SEQ_FOPS_RO(name)
889 #define LPROC_SEQ_FOPS(name)
890
891 /* lproc_ptlrpc.c */
892 #define target_print_req NULL
893
894 #endif /* LPROCFS */
895
896 #endif /* LPROCFS_SNMP_H */