Whamcloud - gitweb
b=16776
[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
69 struct lprocfs_static_vars {
70         struct lprocfs_vars *module_vars;
71         struct lprocfs_vars *obd_vars;
72 };
73
74 /* if we find more consumers this could be generalized */
75 #define OBD_HIST_MAX 32
76 struct obd_histogram {
77         spinlock_t      oh_lock;
78         unsigned long   oh_buckets[OBD_HIST_MAX];
79 };
80
81 enum {
82         BRW_R_PAGES = 0,
83         BRW_W_PAGES,
84         BRW_R_RPC_HIST,
85         BRW_W_RPC_HIST,
86         BRW_R_IO_TIME,
87         BRW_W_IO_TIME,
88         BRW_R_DISCONT_PAGES,
89         BRW_W_DISCONT_PAGES,
90         BRW_R_DISCONT_BLOCKS,
91         BRW_W_DISCONT_BLOCKS,
92         BRW_R_DISK_IOSIZE,
93         BRW_W_DISK_IOSIZE,
94         BRW_R_DIO_FRAGS,
95         BRW_W_DIO_FRAGS,
96         BRW_LAST,
97 };
98
99 struct brw_stats {
100         struct obd_histogram hist[BRW_LAST];
101 };
102
103
104 /* An lprocfs counter can be configured using the enum bit masks below.
105  *
106  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
107  * protects this counter from concurrent updates. If not specified,
108  * lprocfs an internal per-counter lock variable. External locks are
109  * not used to protect counter increments, but are used to protect
110  * counter readout and resets.
111  *
112  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
113  * (i.e. counter can be incremented by more than "1"). When specified,
114  * the counter maintains min, max and sum in addition to a simple
115  * invocation count. This allows averages to be be computed.
116  * If not specified, the counter is an increment-by-1 counter.
117  * min, max, sum, etc. are not maintained.
118  *
119  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
120  * squares (for multi-valued counter samples only). This allows
121  * external computation of standard deviation, but involves a 64-bit
122  * multiply per counter increment.
123  */
124
125 enum {
126         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
127         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
128         LPROCFS_CNTR_STDDEV       = 0x0004,
129
130         /* counter data type */
131         LPROCFS_TYPE_REGS         = 0x0100,
132         LPROCFS_TYPE_BYTES        = 0x0200,
133         LPROCFS_TYPE_PAGES        = 0x0400,
134         LPROCFS_TYPE_CYCLE        = 0x0800,
135 };
136
137 struct lprocfs_atomic {
138         atomic_t               la_entry;
139         atomic_t               la_exit;
140 };
141
142 #define LC_MIN_INIT ((~(__u64)0) >> 1)
143
144 struct lprocfs_counter {
145         struct lprocfs_atomic  lc_cntl;  /* may need to move to per set */
146         unsigned int           lc_config;
147         __s64                  lc_count;
148         __s64                  lc_sum;
149         __s64                  lc_min;
150         __s64                  lc_max;
151         __s64                  lc_sumsquare;
152         const char            *lc_name;   /* must be static */
153         const char            *lc_units;  /* must be static */
154 };
155
156 struct lprocfs_percpu {
157         struct lprocfs_counter lp_cntr[0];
158 };
159
160 #define LPROCFS_GET_NUM_CPU 0x0001
161 #define LPROCFS_GET_SMP_ID  0x0002
162
163 enum lprocfs_stats_flags {
164         LPROCFS_STATS_FLAG_PERCPU   = 0x0000, /* per cpu counter */
165         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
166                                                * area and need locking */
167 };
168
169 enum lprocfs_fields_flags {
170         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
171         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
172         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
173         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
174         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
175         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
176         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
177 };
178
179 struct lprocfs_stats {
180         unsigned int           ls_num;     /* # of counters */
181         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
182         spinlock_t             ls_lock;  /* Lock used only when there are
183                                           * no percpu stats areas */
184         struct lprocfs_percpu *ls_percpu[0];
185 };
186
187 static inline int opcode_offset(__u32 opc) {
188         if (opc < OST_LAST_OPC) {
189                  /* OST opcode */
190                 return (opc - OST_FIRST_OPC);
191         } else if (opc < MDS_LAST_OPC) {
192                 /* MDS opcode */
193                 return (opc - MDS_FIRST_OPC +
194                         (OST_LAST_OPC - OST_FIRST_OPC));
195         } else if (opc < LDLM_LAST_OPC) {
196                 /* LDLM Opcode */
197                 return (opc - LDLM_FIRST_OPC +
198                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
199                         (OST_LAST_OPC - OST_FIRST_OPC));
200         } else if (opc < MGS_LAST_OPC) {
201                 /* MGS Opcode */
202                 return (opc - MGS_FIRST_OPC +
203                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
204                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
205                         (OST_LAST_OPC - OST_FIRST_OPC));
206         } else if (opc < OBD_LAST_OPC) {
207                 /* OBD Ping */
208                 return (opc - OBD_FIRST_OPC +
209                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
210                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
211                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
212                         (OST_LAST_OPC - OST_FIRST_OPC));
213         } else if (opc < LLOG_LAST_OPC) {
214                 /* LLOG Opcode */
215                 return (opc - LLOG_FIRST_OPC +
216                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
217                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
218                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
219                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
220                         (OST_LAST_OPC - OST_FIRST_OPC));
221 } else if (opc < FLD_LAST_OPC) {
222                 /* FLD opcode */
223                 return (opc - FLD_FIRST_OPC +
224                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
225                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
226                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
227                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
228                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
229                         (OST_LAST_OPC - OST_FIRST_OPC));
230         } else if (opc < SEQ_LAST_OPC) {
231                 /* SEQ opcode */
232                 return (opc - SEQ_FIRST_OPC +
233                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
234                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
235                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
236                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
237                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
238                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
239                         (OST_LAST_OPC - OST_FIRST_OPC));
240         } else if (opc < SEC_LAST_OPC) {
241                 /* SEC opcode */
242                 return (opc - SEC_FIRST_OPC +
243                         (SEQ_LAST_OPC - SEQ_FIRST_OPC) +
244                         (FLD_LAST_OPC - FLD_FIRST_OPC) +
245                         (LLOG_LAST_OPC - LLOG_FIRST_OPC) +
246                         (OBD_LAST_OPC - OBD_FIRST_OPC) +
247                         (MGS_LAST_OPC - MGS_FIRST_OPC) +
248                         (LDLM_LAST_OPC - LDLM_FIRST_OPC) +
249                         (MDS_LAST_OPC - MDS_FIRST_OPC) +
250                         (OST_LAST_OPC - OST_FIRST_OPC));
251         } else {
252                 /* Unknown Opcode */
253                 return -1;
254         }
255 }
256
257 #define LUSTRE_MAX_OPCODES ((LDLM_LAST_OPC - LDLM_FIRST_OPC)   + \
258                             (MDS_LAST_OPC - MDS_FIRST_OPC)     + \
259                             (OST_LAST_OPC - OST_FIRST_OPC)     + \
260                             (OBD_LAST_OPC - OBD_FIRST_OPC)     + \
261                             (FLD_LAST_OPC - FLD_FIRST_OPC)     + \
262                             (SEQ_LAST_OPC - SEQ_FIRST_OPC)     + \
263                             (MGS_LAST_OPC - MGS_FIRST_OPC)     + \
264                             (LLOG_LAST_OPC - LLOG_FIRST_OPC)   + \
265                             (SEC_LAST_OPC - SEC_FIRST_OPC))
266
267 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
268                            (EXTRA_LAST_OPC - EXTRA_FIRST_OPC))
269
270 enum {
271         PTLRPC_REQWAIT_CNTR = 0,
272         PTLRPC_REQQDEPTH_CNTR,
273         PTLRPC_REQACTIVE_CNTR,
274         PTLRPC_TIMEOUT,
275         PTLRPC_REQBUF_AVAIL_CNTR,
276         PTLRPC_LAST_CNTR
277 };
278
279 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
280
281 enum {
282         LDLM_GLIMPSE_ENQUEUE = 0,
283         LDLM_PLAIN_ENQUEUE,
284         LDLM_EXTENT_ENQUEUE,
285         LDLM_FLOCK_ENQUEUE,
286         LDLM_IBITS_ENQUEUE,
287         MDS_REINT_CREATE,
288         MDS_REINT_LINK,
289         MDS_REINT_OPEN,
290         MDS_REINT_SETATTR,
291         MDS_REINT_RENAME,
292         MDS_REINT_UNLINK,
293         BRW_READ_BYTES,
294         BRW_WRITE_BYTES,
295         EXTRA_LAST_OPC
296 };
297
298 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
299 /* class_obd.c */
300 extern cfs_proc_dir_entry_t *proc_lustre_root;
301
302 struct obd_device;
303 struct file;
304 struct obd_histogram;
305
306 /* Days / hours / mins / seconds format */
307 struct dhms {
308         int d,h,m,s;
309 };
310 static inline void s2dhms(struct dhms *ts, time_t secs)
311 {
312         ts->d = secs / 86400;
313         secs = secs % 86400;
314         ts->h = secs / 3600;
315         secs = secs % 3600;
316         ts->m = secs / 60;
317         ts->s = secs % 60;
318 }
319 #define DHMS_FMT "%dd%dh%02dm%02ds"
320 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
321
322
323 #ifdef LPROCFS
324
325 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int type)
326 {
327         int rc = 0;
328
329         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
330                 if (type & LPROCFS_GET_NUM_CPU)
331                         rc = 1;
332                 if (type & LPROCFS_GET_SMP_ID)
333                         rc = 0;
334                 spin_lock(&stats->ls_lock);
335         } else {
336                 if (type & LPROCFS_GET_NUM_CPU)
337                         rc = num_possible_cpus();
338                 if (type & LPROCFS_GET_SMP_ID)
339                         rc = smp_processor_id();
340         }
341         return rc;
342 }
343
344 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats)
345 {
346         if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
347                 spin_unlock(&stats->ls_lock);
348 }
349
350 /* Two optimized LPROCFS counter increment functions are provided:
351  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
352  *     lprocfs_counter_add(cntr) - use for multi-valued counters
353  * Counter data layout allows config flag, counter lock and the
354  * count itself to reside within a single cache line.
355  */
356
357 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
358                                 long amount);
359 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
360                                 long amount);
361
362 #define lprocfs_counter_incr(stats, idx) \
363         lprocfs_counter_add(stats, idx, 1)
364 #define lprocfs_counter_decr(stats, idx) \
365         lprocfs_counter_sub(stats, idx, 1)
366
367 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
368                                  enum lprocfs_fields_flags field);
369 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
370                                             int idx,
371                                             enum lprocfs_fields_flags field)
372 {
373         __u64 ret = 0;
374         int i;
375
376         LASSERT(stats != NULL);
377         for (i = 0; i < num_possible_cpus(); i++)
378                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
379                                            field);
380         return ret;
381 }
382
383 extern struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
384                                                  enum lprocfs_stats_flags flags);
385 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
386 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
387 extern void lprocfs_init_ops_stats(int num_private_stats,
388                                    struct lprocfs_stats *stats);
389 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
390                                    unsigned int num_private_stats);
391 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
392                                  unsigned conf, const char *name,
393                                  const char *units);
394 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
395 struct obd_export;
396 struct nid_stat;
397 extern int lprocfs_add_clear_entry(struct obd_device * obd,
398                                    cfs_proc_dir_entry_t *entry);
399 extern int lprocfs_exp_setup(struct obd_export *exp,
400                              lnet_nid_t *peer_nid, int *newnid);
401 extern int lprocfs_exp_cleanup(struct obd_export *exp);
402 extern int lprocfs_add_simple(struct proc_dir_entry *root,
403                               char *name, cfs_read_proc_t *read_proc,
404                               cfs_write_proc_t *write_proc, void *data);
405 extern struct proc_dir_entry *lprocfs_add_symlink(const char *name,
406                         struct proc_dir_entry *parent, const char *dest);
407 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
408 extern int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
409                                          unsigned long count, void *data);
410 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
411                                         int count, int *eof,  void *data);
412
413 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
414                                   struct lprocfs_stats *stats);
415
416 /* lprocfs_status.c */
417 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
418                             struct lprocfs_vars *var,
419                             void *data);
420
421 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
422                                                cfs_proc_dir_entry_t *parent,
423                                                struct lprocfs_vars *list,
424                                                void *data);
425
426 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
427 extern void lprocfs_remove_proc_entry(const char *name,
428                                       struct proc_dir_entry *parent);
429
430 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
431                                            const char *name);
432
433 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
434 extern int lprocfs_obd_cleanup(struct obd_device *obd);
435 extern int lprocfs_add_simple(struct proc_dir_entry *root, char *name,
436                               cfs_read_proc_t *read_proc,
437                               cfs_write_proc_t *write_proc,
438                               void *data);
439 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
440 extern struct file_operations lprocfs_evict_client_fops;
441
442 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
443                               mode_t mode, struct file_operations *seq_fops,
444                               void *data);
445 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
446                                   mode_t mode, struct file_operations *seq_fops,
447                                   void *data);
448
449 /* Generic callbacks */
450
451 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
452                           int count, int *eof, void *data);
453 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
454                              int count, int *eof, void *data);
455 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
456                              unsigned long count, void *data);
457 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
458                            int count, int *eof, void *data);
459 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
460                            unsigned long count, void *data);
461 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
462                            int count, int *eof, void *data);
463 extern int lprocfs_rd_name(char *page, char **start, off_t off,
464                            int count, int *eof, void *data);
465 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
466                              int count, int *eof, void *data);
467 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
468                                   int count, int *eof, void *data);
469 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
470                                 int count, int *eof, void *data);
471 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
472                                     int count, int *eof, void *data);
473 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
474                                   int count, int *eof, void *data);
475 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
476                               int count, int *eof, void *data);
477 struct adaptive_timeout;
478 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
479                                   struct adaptive_timeout *at);
480 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
481                                int count, int *eof, void *data);
482 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
483                                unsigned long count, void *data);
484 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
485                                    unsigned long count, void *data);
486 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
487                            unsigned long count, void *data);
488
489 /* Statfs helpers */
490 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
491                               int count, int *eof, void *data);
492 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
493                                   int count, int *eof, void *data);
494 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
495                                  int count, int *eof, void *data);
496 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
497                                  int count, int *eof, void *data);
498 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
499                                  int count, int *eof, void *data);
500 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
501                                 int count, int *eof, void *data);
502 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
503                                  int count, int *eof, void *data);
504
505 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
506                                 int *val);
507 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
508                                      int *val, int mult);
509 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
510                                     long val, int mult);
511 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
512                                     __u64 *val);
513 extern int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
514                                          __u64 *val, int mult);
515 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
516 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
517 void lprocfs_oh_clear(struct obd_histogram *oh);
518 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
519
520 /* lprocfs_status.c: counter read/write functions */
521 extern int lprocfs_counter_read(char *page, char **start, off_t off,
522                                 int count, int *eof, void *data);
523 extern int lprocfs_counter_write(struct file *file, const char *buffer,
524                                  unsigned long count, void *data);
525
526 /* lprocfs_status.c: recovery status */
527 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
528                                    int count, int *eof, void *data);
529
530 /* lprocfs_statuc.c: hash statistics */
531 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
532                         int count, int *eof, void *data);
533
534 extern int lprocfs_seq_release(struct inode *, struct file *);
535
536 /* in lprocfs_stat.c, to protect the private data for proc entries */
537 extern struct rw_semaphore _lprocfs_lock;
538 #define LPROCFS_ENTRY()           do {  \
539         down_read(&_lprocfs_lock);      \
540 } while(0)
541 #define LPROCFS_EXIT()            do {  \
542         up_read(&_lprocfs_lock);        \
543 } while(0)
544 #define LPROCFS_ENTRY_AND_CHECK(dp) do {        \
545         typecheck(struct proc_dir_entry *, dp); \
546         LPROCFS_ENTRY();                        \
547         if ((dp)->deleted) {                    \
548                 LPROCFS_EXIT();                 \
549                 return -ENODEV;                 \
550         }                                       \
551 } while(0)
552 #define LPROCFS_WRITE_ENTRY()     do {  \
553         down_write(&_lprocfs_lock);     \
554 } while(0)
555 #define LPROCFS_WRITE_EXIT()      do {  \
556         up_write(&_lprocfs_lock);       \
557 } while(0)
558
559 /* You must use these macros when you want to refer to
560  * the import in a client obd_device for a lprocfs entry */
561 #define LPROCFS_CLIMP_CHECK(obd) do {           \
562         typecheck(struct obd_device *, obd);    \
563         down_read(&(obd)->u.cli.cl_sem);        \
564         if ((obd)->u.cli.cl_import == NULL) {   \
565              up_read(&(obd)->u.cli.cl_sem);     \
566              return -ENODEV;                    \
567         }                                       \
568 } while(0)
569 #define LPROCFS_CLIMP_EXIT(obd)                 \
570         up_read(&(obd)->u.cli.cl_sem);
571
572
573 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
574   proc entries; otherwise, you will define name##_seq_write function also for
575   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
576   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
577 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
578 static int name##_seq_open(struct inode *inode, struct file *file) {       \
579         struct proc_dir_entry *dp = PDE(inode);                            \
580         int rc;                                                            \
581         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
582         rc = single_open(file, name##_seq_show, dp->data);                 \
583         if (rc) {                                                          \
584                 LPROCFS_EXIT();                                            \
585                 return rc;                                                 \
586         }                                                                  \
587         return 0;                                                          \
588 }                                                                          \
589 struct file_operations name##_fops = {                                     \
590         .owner   = THIS_MODULE,                                            \
591         .open    = name##_seq_open,                                        \
592         .read    = seq_read,                                               \
593         .write   = custom_seq_write,                                       \
594         .llseek  = seq_lseek,                                              \
595         .release = lprocfs_seq_release,                                    \
596 }
597
598 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
599 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
600
601 /* lproc_ptlrpc.c */
602 struct ptlrpc_request;
603 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
604
605 /* lprocfs_status.c: read recovery max time bz13079 */
606 int lprocfs_obd_rd_recovery_maxtime(char *page, char **start, off_t off,
607                                     int count, int *eof, void *data);
608
609 /* lprocfs_status.c: write recovery max time bz13079 */
610 int lprocfs_obd_wr_recovery_maxtime(struct file *file, const char *buffer,
611                                     unsigned long count, void *data);
612 #else
613 /* LPROCFS is not defined */
614 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
615                                        int index, long amount) { return; }
616 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
617                                         int index) { return; }
618 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
619                                        int index, long amount) { return; }
620 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
621                                         int index, unsigned conf,
622                                         const char *name, const char *units)
623 { return; }
624
625 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
626                                    enum lprocfs_fields_flags field)
627 { return 0; }
628
629 static inline struct lprocfs_stats* lprocfs_alloc_stats(unsigned int num,
630                                                         enum lprocfs_stats_flags flags)
631 { return NULL; }
632 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
633 { return; }
634 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
635 { return; }
636 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
637                                             const char *name,
638                                             struct lprocfs_stats *stats)
639 { return 0; }
640 static inline void lprocfs_init_ops_stats(int num_private_stats,
641                                           struct lprocfs_stats *stats)
642 { return; }
643 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
644                                              unsigned int num_private_stats)
645 { return 0; }
646 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
647 { return; }
648
649 struct obd_export;
650 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
651 { return 0; }
652 static inline int lprocfs_exp_setup(struct obd_export *exp,
653                                     lnet_nid_t *peer_nid, int *newnid)
654 { return 0; }
655 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
656 { return 0; }
657 static inline int lprocfs_add_simple(struct proc_dir_entry *root,
658                                      char *name,
659                                      cfs_read_proc_t *read_proc,
660                                      cfs_write_proc_t *write_proc,
661                                      void *data)
662 {return 0; }
663 static inline struct proc_dir_entry *lprocfs_add_symlink(const char *name,
664                         struct proc_dir_entry *parent, const char *dest)
665 {return NULL; }
666 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
667 {}
668 static inline
669 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
670                                   unsigned long count, void *data)
671 {return count;}
672 static inline
673 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
674                                  int count, int *eof,  void *data)
675 {return count;}
676
677 static inline cfs_proc_dir_entry_t *
678 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
679                  struct lprocfs_vars *list, void *data) { return NULL; }
680 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
681                                    struct lprocfs_vars *var,
682                                    void *data) { return 0; }
683 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root) {};
684 static inline void lprocfs_remove_proc_entry(const char *name,
685                                              struct proc_dir_entry *parent) {};
686 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
687                                     const char *name) {return 0;}
688 static inline int lprocfs_obd_setup(struct obd_device *dev,
689                                     struct lprocfs_vars *list) { return 0; }
690 static inline int lprocfs_obd_cleanup(struct obd_device *dev)  { return 0; }
691 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
692                                  int count, int *eof, void *data) { return 0; }
693 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
694                                   int count, int *eof, void *data) { return 0; }
695 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
696                                   int count, int *eof, void *data) { return 0; }
697 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
698                                          int count, int *eof, void *data)
699 { return 0; }
700 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
701                                        int count, int *eof, void *data)
702 { return 0; }
703 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
704                                            int count, int *eof, void *data)
705 { return 0; }
706 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
707                                          int count, int *eof, void *data)
708 { return 0; }
709 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
710                                      int count, int *eof, void *data)
711 { return 0; }
712 struct adaptive_timeout;
713 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
714                                          struct adaptive_timeout *at)
715 { return 0; }
716 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
717                                       int count, int *eof, void *data)
718 { return 0; }
719 static inline int lprocfs_wr_timeouts(struct file *file, const char *buffer,
720                                       unsigned long count, void *data)
721 { return 0; }
722 static inline int lprocfs_wr_evict_client(struct file *file, const char *buffer,
723                                           unsigned long count, void *data)
724 { return 0; }
725 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
726                                   unsigned long count, void *data)
727 { return 0; }
728
729
730 /* Statfs helpers */
731 static inline
732 int lprocfs_rd_blksize(char *page, char **start, off_t off,
733                        int count, int *eof, void *data) { return 0; }
734 static inline
735 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
736                            int count, int *eof, void *data) { return 0; }
737 static inline
738 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
739                           int count, int *eof, void *data) { return 0; }
740 static inline
741 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
742                            int count, int *eof, void *data) { return 0; }
743 static inline
744 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
745                           int count, int *eof, void *data) { return 0; }
746 static inline
747 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
748                          int count, int *eof, void *data)  { return 0; }
749 static inline
750 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
751                           int count, int *eof, void *data) { return 0; }
752 static inline
753 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value) {}
754 static inline
755 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value) {}
756 static inline
757 void lprocfs_oh_clear(struct obd_histogram *oh) {}
758 static inline
759 unsigned long lprocfs_oh_sum(struct obd_histogram *oh) { return 0; }
760 static inline
761 int lprocfs_counter_read(char *page, char **start, off_t off,
762                          int count, int *eof, void *data) { return 0; }
763 static inline
764 int lprocfs_counter_write(struct file *file, const char *buffer,
765                           unsigned long count, void *data) { return 0; }
766
767 static inline
768 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
769                                enum lprocfs_fields_flags field)
770 { return (__u64)0; }
771
772 #define LPROCFS_ENTRY()
773 #define LPROCFS_EXIT()
774 #define LPROCFS_ENTRY_AND_CHECK(dp)
775 #define LPROC_SEQ_FOPS_RO(name)
776 #define LPROC_SEQ_FOPS(name)
777
778 /* lproc_ptlrpc.c */
779 #define target_print_req NULL
780
781 #endif /* LPROCFS */
782
783 #endif /* LPROCFS_SNMP_H */