Whamcloud - gitweb
Land b_head_quota onto HEAD (20081116_0105)
[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 #include <lustre/lustre_idl.h>
46 #if defined(__linux__)
47 #include <linux/lprocfs_status.h>
48 #elif defined(__APPLE__)
49 #include <darwin/lprocfs_status.h>
50 #elif defined(__WINNT__)
51 #include <winnt/lprocfs_status.h>
52 #else
53 #error Unsupported operating system.
54 #endif
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_PERCPU   = 0x0000, /* per cpu counter */
169         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
170                                                * area and need locking */
171 };
172
173 enum lprocfs_fields_flags {
174         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
175         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
176         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
177         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
178         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
179         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
180         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
181 };
182
183 struct lprocfs_stats {
184         unsigned int           ls_num;     /* # of counters */
185         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
186         spinlock_t             ls_lock;  /* Lock used only when there are
187                                           * no percpu stats areas */
188         struct lprocfs_percpu *ls_percpu[0];
189 };
190
191 static inline int opcode_offset(__u32 opc) {
192         if (opc < OST_LAST_OPC) {
193                  /* OST opcode */
194                 return (opc - OST_FIRST_OPC);
195         } else if (opc < MDS_LAST_OPC) {
196                 /* MDS opcode */
197                 return (opc - MDS_FIRST_OPC +
198                         (OST_LAST_OPC - OST_FIRST_OPC));
199         } else if (opc < LDLM_LAST_OPC) {
200                 /* LDLM Opcode */
201                 return (opc - LDLM_FIRST_OPC +
202                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
203                         (OST_LAST_OPC - OST_FIRST_OPC));
204         } else if (opc < MGS_LAST_OPC) {
205                 /* MGS Opcode */
206                 return (opc - MGS_FIRST_OPC +
207                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
208                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
209                         (OST_LAST_OPC - OST_FIRST_OPC));
210         } else if (opc < OBD_LAST_OPC) {
211                 /* OBD Ping */
212                 return (opc - OBD_FIRST_OPC +
213                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
214                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
215                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
216                         (OST_LAST_OPC - OST_FIRST_OPC));
217         } else if (opc < LLOG_LAST_OPC) {
218                 /* LLOG Opcode */
219                 return (opc - LLOG_FIRST_OPC +
220                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
221                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
222                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
223                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
224                         (OST_LAST_OPC - OST_FIRST_OPC));
225         } else if (opc < FLD_LAST_OPC) {
226                 /* FLD opcode */
227                 return (opc - FLD_FIRST_OPC +
228                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
229                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
230                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
231                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
232                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
233                         (OST_LAST_OPC - OST_FIRST_OPC));
234         } else if (opc < SEQ_LAST_OPC) {
235                 /* SEQ opcode */
236                 return (opc - SEQ_FIRST_OPC +
237                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
238                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
239                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
240                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
241                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
242                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
243                         (OST_LAST_OPC - OST_FIRST_OPC));
244         } else if (opc < SEC_LAST_OPC) {
245                 /* SEC opcode */
246                 return (opc - SEC_FIRST_OPC +
247                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
248                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
249                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
250                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
251                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
252                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
253                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
254                         (OST_LAST_OPC - OST_FIRST_OPC));
255         } else if (opc < QUOTA_LAST_OPC) {
256                 /* LQUOTA Opcode */
257                 return (opc - QUOTA_FIRST_OPC +
258                         (SEC_LAST_OPC - SEC_FIRST_OPC) +
259                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
260                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
261                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
262                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
263                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
264                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
265                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
266                         (OST_LAST_OPC - OST_FIRST_OPC));
267         } else {
268                 /* Unknown Opcode */
269                 return -1;
270         }
271 }
272
273 #define LUSTRE_MAX_OPCODES ((LDLM_LAST_OPC - LDLM_FIRST_OPC)   + \
274                             (MDS_LAST_OPC - MDS_FIRST_OPC)     + \
275                             (OST_LAST_OPC - OST_FIRST_OPC)     + \
276                             (OBD_LAST_OPC - OBD_FIRST_OPC)     + \
277                             (FLD_LAST_OPC - FLD_FIRST_OPC)     + \
278                             (SEQ_LAST_OPC - SEQ_FIRST_OPC)     + \
279                             (MGS_LAST_OPC - MGS_FIRST_OPC)     + \
280                             (LLOG_LAST_OPC - LLOG_FIRST_OPC)   + \
281                             (SEC_LAST_OPC - SEC_FIRST_OPC)     + \
282                             (QUOTA_LAST_OPC - QUOTA_FIRST_OPC))
283
284 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
285                            (EXTRA_LAST_OPC - EXTRA_FIRST_OPC))
286
287 enum {
288         PTLRPC_REQWAIT_CNTR = 0,
289         PTLRPC_REQQDEPTH_CNTR,
290         PTLRPC_REQACTIVE_CNTR,
291         PTLRPC_TIMEOUT,
292         PTLRPC_REQBUF_AVAIL_CNTR,
293         PTLRPC_LAST_CNTR
294 };
295
296 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
297
298 enum {
299         LDLM_GLIMPSE_ENQUEUE = 0,
300         LDLM_PLAIN_ENQUEUE,
301         LDLM_EXTENT_ENQUEUE,
302         LDLM_FLOCK_ENQUEUE,
303         LDLM_IBITS_ENQUEUE,
304         MDS_REINT_SETATTR,
305         MDS_REINT_CREATE,
306         MDS_REINT_LINK,
307         MDS_REINT_UNLINK,
308         MDS_REINT_RENAME,
309         MDS_REINT_OPEN,
310         MDS_REINT_SETXATTR,
311         BRW_READ_BYTES,
312         BRW_WRITE_BYTES,
313         EXTRA_LAST_OPC
314 };
315
316 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
317 /* class_obd.c */
318 extern cfs_proc_dir_entry_t *proc_lustre_root;
319
320 struct obd_device;
321 struct file;
322 struct obd_histogram;
323
324 /* Days / hours / mins / seconds format */
325 struct dhms {
326         int d,h,m,s;
327 };
328 static inline void s2dhms(struct dhms *ts, time_t secs)
329 {
330         ts->d = secs / 86400;
331         secs = secs % 86400;
332         ts->h = secs / 3600;
333         secs = secs % 3600;
334         ts->m = secs / 60;
335         ts->s = secs % 60;
336 }
337 #define DHMS_FMT "%dd%dh%02dm%02ds"
338 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
339
340
341 #ifdef LPROCFS
342
343 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int type)
344 {
345         int rc = 0;
346
347         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
348                 if (type & LPROCFS_GET_NUM_CPU)
349                         rc = 1;
350                 if (type & LPROCFS_GET_SMP_ID)
351                         rc = 0;
352                 spin_lock(&stats->ls_lock);
353         } else {
354                 if (type & LPROCFS_GET_NUM_CPU)
355                         rc = num_possible_cpus();
356                 if (type & LPROCFS_GET_SMP_ID)
357                         rc = smp_processor_id();
358         }
359         return rc;
360 }
361
362 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats)
363 {
364         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
365                 spin_unlock(&stats->ls_lock);
366 }
367
368 /* Two optimized LPROCFS counter increment functions are provided:
369  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
370  *     lprocfs_counter_add(cntr) - use for multi-valued counters
371  * Counter data layout allows config flag, counter lock and the
372  * count itself to reside within a single cache line.
373  */
374
375 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
376                                 long amount);
377 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
378                                 long amount);
379
380 #define lprocfs_counter_incr(stats, idx) \
381         lprocfs_counter_add(stats, idx, 1)
382 #define lprocfs_counter_decr(stats, idx) \
383         lprocfs_counter_sub(stats, idx, 1)
384
385 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
386                                  enum lprocfs_fields_flags field);
387 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
388                                             int idx,
389                                             enum lprocfs_fields_flags field)
390 {
391         __u64 ret = 0;
392         int i;
393
394         LASSERT(stats != NULL);
395         for (i = 0; i < num_possible_cpus(); i++)
396                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
397                                            field);
398         return ret;
399 }
400
401 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
402                                                  enum lprocfs_stats_flags flags);
403 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
404 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
405 extern void lprocfs_init_ops_stats(int num_private_stats,
406                                    struct lprocfs_stats *stats);
407 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
408 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
409                                    unsigned int num_private_stats);
410 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
411                                   unsigned int num_private_stats);
412 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
413                                  unsigned conf, const char *name,
414                                  const char *units);
415 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
416 struct obd_export;
417 struct nid_stat;
418 extern int lprocfs_add_clear_entry(struct obd_device * obd,
419                                    cfs_proc_dir_entry_t *entry);
420 extern int lprocfs_exp_setup(struct obd_export *exp,
421                              lnet_nid_t *peer_nid, int *newnid);
422 extern int lprocfs_exp_cleanup(struct obd_export *exp);
423 extern cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
424                                                 char *name,
425                                                 cfs_read_proc_t *read_proc,
426                                                 cfs_write_proc_t *write_proc,
427                                                 void *data,
428                                                 struct file_operations *fops);
429 extern struct proc_dir_entry *lprocfs_add_symlink(const char *name,
430                         struct proc_dir_entry *parent, const char *dest);
431 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
432 extern int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
433                                          unsigned long count, void *data);
434 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
435                                         int count, int *eof,  void *data);
436
437 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
438                                   struct lprocfs_stats *stats);
439
440 /* lprocfs_status.c */
441 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
442                             struct lprocfs_vars *var,
443                             void *data);
444
445 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
446                                                cfs_proc_dir_entry_t *parent,
447                                                struct lprocfs_vars *list,
448                                                void *data);
449
450 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
451 extern void lprocfs_remove_proc_entry(const char *name,
452                                       struct proc_dir_entry *parent);
453
454 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
455                                            const char *name);
456
457 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
458 extern int lprocfs_obd_cleanup(struct obd_device *obd);
459 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
460 extern struct file_operations lprocfs_evict_client_fops;
461
462 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
463                               mode_t mode, struct file_operations *seq_fops,
464                               void *data);
465 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
466                                   mode_t mode, struct file_operations *seq_fops,
467                                   void *data);
468
469 /* Generic callbacks */
470
471 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
472                           int count, int *eof, void *data);
473 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
474                              int count, int *eof, void *data);
475 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
476                              unsigned long count, void *data);
477 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
478                            int count, int *eof, void *data);
479 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
480                            unsigned long count, void *data);
481 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
482                            int count, int *eof, void *data);
483 extern int lprocfs_rd_name(char *page, char **start, off_t off,
484                            int count, int *eof, void *data);
485 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
486                              int count, int *eof, void *data);
487 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
488                                   int count, int *eof, void *data);
489 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
490                                 int count, int *eof, void *data);
491 extern int lprocfs_rd_import(char *page, char **start, off_t off, int count,
492                              int *eof, void *data);
493 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
494                                     int count, int *eof, void *data);
495 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
496                                   int count, int *eof, void *data);
497 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
498                               int count, int *eof, void *data);
499 struct adaptive_timeout;
500 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
501                                   struct adaptive_timeout *at);
502 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
503                                int count, int *eof, void *data);
504 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
505                                unsigned long count, void *data);
506 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
507                                    unsigned long count, void *data);
508 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
509                            unsigned long count, void *data);
510
511 /* Statfs helpers */
512 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
513                               int count, int *eof, void *data);
514 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
515                                   int count, int *eof, void *data);
516 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
517                                  int count, int *eof, void *data);
518 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
519                                  int count, int *eof, void *data);
520 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
521                                  int count, int *eof, void *data);
522 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
523                                 int count, int *eof, void *data);
524 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
525                                  int count, int *eof, void *data);
526
527 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
528                                 int *val);
529 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
530                                      int *val, int mult);
531 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
532                                     long val, int mult);
533 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
534                                     __u64 *val);
535 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
536                                          __u64 *val, int mult);
537 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
538 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
539 void lprocfs_oh_clear(struct obd_histogram *oh);
540 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
541
542 /* lprocfs_status.c: counter read/write functions */
543 extern int lprocfs_counter_read(char *page, char **start, off_t off,
544                                 int count, int *eof, void *data);
545 extern int lprocfs_counter_write(struct file *file, const char *buffer,
546                                  unsigned long count, void *data);
547
548 /* lprocfs_status.c: recovery status */
549 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
550                                    int count, int *eof, void *data);
551
552 /* lprocfs_statuc.c: hash statistics */
553 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
554                         int count, int *eof, void *data);
555
556 extern int lprocfs_seq_release(struct inode *, struct file *);
557
558 /* in lprocfs_stat.c, to protect the private data for proc entries */
559 extern struct rw_semaphore _lprocfs_lock;
560 #define LPROCFS_ENTRY()           do {  \
561         down_read(&_lprocfs_lock);      \
562 } while(0)
563 #define LPROCFS_EXIT()            do {  \
564         up_read(&_lprocfs_lock);        \
565 } while(0)
566 #define LPROCFS_ENTRY_AND_CHECK(dp) do {        \
567         typecheck(struct proc_dir_entry *, dp); \
568         LPROCFS_ENTRY();                        \
569         if ((dp)->deleted) {                    \
570                 LPROCFS_EXIT();                 \
571                 return -ENODEV;                 \
572         }                                       \
573 } while(0)
574 #define LPROCFS_WRITE_ENTRY()     do {  \
575         down_write(&_lprocfs_lock);     \
576 } while(0)
577 #define LPROCFS_WRITE_EXIT()      do {  \
578         up_write(&_lprocfs_lock);       \
579 } while(0)
580
581 /* You must use these macros when you want to refer to
582  * the import in a client obd_device for a lprocfs entry */
583 #define LPROCFS_CLIMP_CHECK(obd) do {           \
584         typecheck(struct obd_device *, obd);    \
585         down_read(&(obd)->u.cli.cl_sem);        \
586         if ((obd)->u.cli.cl_import == NULL) {   \
587              up_read(&(obd)->u.cli.cl_sem);     \
588              return -ENODEV;                    \
589         }                                       \
590 } while(0)
591 #define LPROCFS_CLIMP_EXIT(obd)                 \
592         up_read(&(obd)->u.cli.cl_sem);
593
594
595 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
596   proc entries; otherwise, you will define name##_seq_write function also for
597   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
598   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
599 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
600 static int name##_seq_open(struct inode *inode, struct file *file) {       \
601         struct proc_dir_entry *dp = PDE(inode);                            \
602         int rc;                                                            \
603         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
604         rc = single_open(file, name##_seq_show, dp->data);                 \
605         if (rc) {                                                          \
606                 LPROCFS_EXIT();                                            \
607                 return rc;                                                 \
608         }                                                                  \
609         return 0;                                                          \
610 }                                                                          \
611 struct file_operations name##_fops = {                                     \
612         .owner   = THIS_MODULE,                                            \
613         .open    = name##_seq_open,                                        \
614         .read    = seq_read,                                               \
615         .write   = custom_seq_write,                                       \
616         .llseek  = seq_lseek,                                              \
617         .release = lprocfs_seq_release,                                    \
618 }
619
620 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
621 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
622
623 /* lproc_ptlrpc.c */
624 struct ptlrpc_request;
625 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
626
627 /* lprocfs_status.c: read recovery max time bz13079 */
628 int lprocfs_obd_rd_recovery_maxtime(char *page, char **start, off_t off,
629                                     int count, int *eof, void *data);
630
631 /* lprocfs_status.c: write recovery max time bz13079 */
632 int lprocfs_obd_wr_recovery_maxtime(struct file *file, const char *buffer,
633                                     unsigned long count, void *data);
634
635 /* all quota proc functions */
636 extern int lprocfs_quota_rd_bunit(char *page, char **start, off_t off, int count,
637                                   int *eof, void *data);
638 extern int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
639                                   unsigned long count, void *data);
640 extern int lprocfs_quota_rd_btune(char *page, char **start, off_t off, int count,
641                                   int *eof, void *data);
642 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
643                                   unsigned long count, void *data);
644 extern int lprocfs_quota_rd_iunit(char *page, char **start, off_t off, int count,
645                                   int *eof, void *data);
646 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
647                                   unsigned long count, void *data);
648 extern int lprocfs_quota_rd_itune(char *page, char **start, off_t off, int count,
649                                   int *eof, void *data);
650 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
651                                   unsigned long count, void *data);
652 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
653                                  int *eof, void *data);
654 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
655                                  unsigned long count, void *data);
656 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
657                                            int count, int *eof, void *data);
658 extern int lprocfs_quota_wr_switch_seconds(struct file *file, const char *buffer,
659                                            unsigned long count, void *data);
660 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
661                                      int count, int *eof, void *data);
662 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
663                                      unsigned long count, void *data);
664 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
665                                       int count, int *eof, void *data);
666 extern int lprocfs_quota_wr_switch_qs(struct file *file, const char *buffer,
667                                       unsigned long count, void *data);
668 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
669                                             int count, int *eof, void *data);
670 extern int lprocfs_quota_wr_boundary_factor(struct file *file, const char *buffer,
671                                             unsigned long count, void *data);
672 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
673                                         int count, int *eof, void *data);
674 extern int lprocfs_quota_wr_least_bunit(struct file *file, const char *buffer,
675                                         unsigned long count, void *data);
676 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
677                                         int count, int *eof, void *data);
678 extern int lprocfs_quota_wr_least_iunit(struct file *file, const char *buffer,
679                                         unsigned long count, void *data);
680 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
681                                       int count, int *eof, void *data);
682 extern int lprocfs_quota_wr_qs_factor(struct file *file, const char *buffer,
683                                       unsigned long count, void *data);
684 #else
685 /* LPROCFS is not defined */
686 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
687                                        int index, long amount) { return; }
688 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
689                                         int index) { return; }
690 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
691                                        int index, long amount) { return; }
692 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
693                                         int index, unsigned conf,
694                                         const char *name, const char *units)
695 { return; }
696
697 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
698                                    enum lprocfs_fields_flags field)
699 { return 0; }
700
701 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num,
702                                                         enum lprocfs_stats_flags flags)
703 { return NULL; }
704 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
705 { return; }
706 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
707 { return; }
708 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
709                                             const char *name,
710                                             struct lprocfs_stats *stats)
711 { return 0; }
712 static inline void lprocfs_init_ops_stats(int num_private_stats,
713                                           struct lprocfs_stats *stats)
714 { return; }
715 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
716 { return; }
717 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
718                                           unsigned int num_private_stats)
719 { return 0; }
720 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
721                                          unsigned int num_private_stats)
722 { return 0; }
723 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
724 { return; }
725
726 struct obd_export;
727 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
728 { return 0; }
729 static inline int lprocfs_exp_setup(struct obd_export *exp,
730                                     lnet_nid_t *peer_nid, int *newnid)
731 { return 0; }
732 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
733 { return 0; }
734 static inline cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
735                                      char *name,
736                                      cfs_read_proc_t *read_proc,
737                                      cfs_write_proc_t *write_proc,
738                                      void *data,
739                                      struct file_operations *fops)
740 {return 0; }
741 static inline struct proc_dir_entry *lprocfs_add_symlink(const char *name,
742                         struct proc_dir_entry *parent, const char *dest)
743 {return NULL; }
744 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
745 {}
746 static inline
747 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
748                                   unsigned long count, void *data)
749 {return count;}
750 static inline
751 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
752                                  int count, int *eof,  void *data)
753 {return count;}
754
755 static inline cfs_proc_dir_entry_t *
756 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
757                  struct lprocfs_vars *list, void *data) { return NULL; }
758 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
759                                    struct lprocfs_vars *var,
760                                    void *data) { return 0; }
761 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
762 static inline void lprocfs_remove_proc_entry(const char *name,
763                                              struct proc_dir_entry *parent) {};
764 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
765                                     const char *name) {return 0;}
766 static inline int lprocfs_obd_setup(struct obd_device *dev,
767                                     struct lprocfs_vars *list) { return 0; }
768 static inline int lprocfs_obd_cleanup(struct obd_device *dev)  { return 0; }
769 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
770                                  int count, int *eof, void *data) { return 0; }
771 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
772                                   int count, int *eof, void *data) { return 0; }
773 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
774                                   int count, int *eof, void *data) { return 0; }
775 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
776                                          int count, int *eof, void *data)
777 { return 0; }
778 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
779                                        int count, int *eof, void *data)
780 { return 0; }
781 static inline int lprocfs_rd_import(char *page, char **start, off_t off, int count,
782                                     int *eof, void *data) { return 0; }
783 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
784                                            int count, int *eof, void *data)
785 { return 0; }
786 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
787                                          int count, int *eof, void *data)
788 { return 0; }
789 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
790                                      int count, int *eof, void *data)
791 { return 0; }
792 struct adaptive_timeout;
793 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
794                                          struct adaptive_timeout *at)
795 { return 0; }
796 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
797                                       int count, int *eof, void *data)
798 { return 0; }
799 static inline int lprocfs_wr_timeouts(struct file *file, const char *buffer,
800                                       unsigned long count, void *data)
801 { return 0; }
802 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
803                                           unsigned long count, void *data)
804 { return 0; }
805 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
806                                   unsigned long count, void *data)
807 { return 0; }
808
809
810 /* Statfs helpers */
811 static inline
812 int lprocfs_rd_blksize(char *page, char **start, off_t off,
813                        int count, int *eof, void *data) { return 0; }
814 static inline
815 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
816                            int count, int *eof, void *data) { return 0; }
817 static inline
818 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
819                           int count, int *eof, void *data) { return 0; }
820 static inline
821 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
822                            int count, int *eof, void *data) { return 0; }
823 static inline
824 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
825                           int count, int *eof, void *data) { return 0; }
826 static inline
827 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
828                          int count, int *eof, void *data)  { return 0; }
829 static inline
830 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
831                           int count, int *eof, void *data) { return 0; }
832 static inline
833 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
834 static inline
835 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
836 static inline
837 void lprocfs_oh_clear(struct obd_histogram *oh) {}
838 static inline
839 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
840 static inline
841 int lprocfs_counter_read(char *page, char **start, off_t off,
842                          int count, int *eof, void *data) { return 0; }
843 static inline
844 int lprocfs_counter_write(struct file *file, const char *buffer,
845                           unsigned long count, void *data) { return 0; }
846
847 static inline
848 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
849                                enum lprocfs_fields_flags field)
850 { return (__u64)0; }
851
852 #define LPROCFS_ENTRY()
853 #define LPROCFS_EXIT()
854 #define LPROCFS_ENTRY_AND_CHECK(dp)
855 #define LPROC_SEQ_FOPS_RO(name)
856 #define LPROC_SEQ_FOPS(name)
857
858 /* lproc_ptlrpc.c */
859 #define target_print_req NULL
860
861 #endif /* LPROCFS */
862
863 #endif /* LPROCFS_SNMP_H */