Whamcloud - gitweb
7c55f20533c7f7adcef84d443dd56be3d3f9eab6
[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 (c) 2007, 2010, Oracle and/or its affiliates. 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 #include <libcfs/params_tree.h>
56
57 struct lprocfs_vars {
58         const char             *name;
59         cfs_read_proc_t        *read_fptr;
60         cfs_write_proc_t       *write_fptr;
61         void                   *data;
62         struct file_operations *fops;
63         /**
64          * /proc file mode.
65          */
66         mode_t                  proc_mode;
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         cfs_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         cfs_atomic_t               la_entry;
139         cfs_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_sum_irq;
150         __s64                  lc_min;
151         __s64                  lc_max;
152         __s64                  lc_sumsquare;
153         const char            *lc_name;   /* must be static */
154         const char            *lc_units;  /* must be static */
155 };
156
157 struct lprocfs_percpu {
158         struct lprocfs_counter lp_cntr[0];
159 };
160
161 #define LPROCFS_GET_NUM_CPU 0x0001
162 #define LPROCFS_GET_SMP_ID  0x0002
163
164 enum lprocfs_stats_flags {
165         LPROCFS_STATS_FLAG_NONE     = 0x0000, /* per cpu counter */
166         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
167                                                * area and need locking */
168 };
169
170 enum lprocfs_fields_flags {
171         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
172         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
173         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
174         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
175         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
176         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
177         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
178 };
179
180 struct lprocfs_stats {
181         unsigned int           ls_num;     /* # of counters */
182         int                    ls_flags; /* See LPROCFS_STATS_FLAG_* */
183         cfs_spinlock_t         ls_lock;  /* Lock used only when there are
184                                           * no percpu stats areas */
185         struct lprocfs_percpu *ls_percpu[0];
186 };
187
188 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
189
190 /* Pack all opcodes down into a single monotonically increasing index */
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                         OPC_RANGE(OST));
199         } else if (opc < LDLM_LAST_OPC) {
200                 /* LDLM Opcode */
201                 return (opc - LDLM_FIRST_OPC +
202                         OPC_RANGE(MDS) +
203                         OPC_RANGE(OST));
204         } else if (opc < MGS_LAST_OPC) {
205                 /* MGS Opcode */
206                 return (opc - MGS_FIRST_OPC +
207                         OPC_RANGE(LDLM) +
208                         OPC_RANGE(MDS) +
209                         OPC_RANGE(OST));
210         } else if (opc < OBD_LAST_OPC) {
211                 /* OBD Ping */
212                 return (opc - OBD_FIRST_OPC +
213                         OPC_RANGE(MGS) +
214                         OPC_RANGE(LDLM) +
215                         OPC_RANGE(MDS) +
216                         OPC_RANGE(OST));
217         } else if (opc < LLOG_LAST_OPC) {
218                 /* LLOG Opcode */
219                 return (opc - LLOG_FIRST_OPC +
220                         OPC_RANGE(OBD) +
221                         OPC_RANGE(MGS) +
222                         OPC_RANGE(LDLM) +
223                         OPC_RANGE(MDS) +
224                         OPC_RANGE(OST));
225         } else if (opc < QUOTA_LAST_OPC) {
226                 /* LQUOTA Opcode */
227                 return (opc - QUOTA_FIRST_OPC +
228                         OPC_RANGE(LLOG) +
229                         OPC_RANGE(OBD) +
230                         OPC_RANGE(MGS) +
231                         OPC_RANGE(LDLM) +
232                         OPC_RANGE(MDS) +
233                         OPC_RANGE(OST));
234         } else if (opc < SEQ_LAST_OPC) {
235                 /* SEQ opcode */
236                 return (opc - SEQ_FIRST_OPC +
237                         OPC_RANGE(QUOTA) +
238                         OPC_RANGE(LLOG) +
239                         OPC_RANGE(OBD) +
240                         OPC_RANGE(MGS) +
241                         OPC_RANGE(LDLM) +
242                         OPC_RANGE(MDS) +
243                         OPC_RANGE(OST));
244         } else if (opc < SEC_LAST_OPC) {
245                 /* SEC opcode */
246                 return (opc - SEC_FIRST_OPC +
247                         OPC_RANGE(SEQ) +
248                         OPC_RANGE(QUOTA) +
249                         OPC_RANGE(LLOG) +
250                         OPC_RANGE(OBD) +
251                         OPC_RANGE(MGS) +
252                         OPC_RANGE(LDLM) +
253                         OPC_RANGE(MDS) +
254                         OPC_RANGE(OST));
255         } else if (opc < FLD_LAST_OPC) {
256                 /* FLD opcode */
257                  return (opc - FLD_FIRST_OPC +
258                         OPC_RANGE(SEC) +
259                         OPC_RANGE(SEQ) +
260                         OPC_RANGE(QUOTA) +
261                         OPC_RANGE(LLOG) +
262                         OPC_RANGE(OBD) +
263                         OPC_RANGE(MGS) +
264                         OPC_RANGE(LDLM) +
265                         OPC_RANGE(MDS) +
266                         OPC_RANGE(OST));
267         } else {
268                 /* Unknown Opcode */
269                 return -1;
270         }
271 }
272
273
274 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
275                             OPC_RANGE(MDS)  + \
276                             OPC_RANGE(LDLM) + \
277                             OPC_RANGE(MGS)  + \
278                             OPC_RANGE(OBD)  + \
279                             OPC_RANGE(LLOG) + \
280                             OPC_RANGE(SEC)  + \
281                             OPC_RANGE(SEQ)  + \
282                             OPC_RANGE(SEC)  + \
283                             OPC_RANGE(FLD)  )
284
285 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
286                             OPC_RANGE(EXTRA))
287
288 enum {
289         PTLRPC_REQWAIT_CNTR = 0,
290         PTLRPC_REQQDEPTH_CNTR,
291         PTLRPC_REQACTIVE_CNTR,
292         PTLRPC_TIMEOUT,
293         PTLRPC_REQBUF_AVAIL_CNTR,
294         PTLRPC_LAST_CNTR
295 };
296
297 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
298
299 enum {
300         LDLM_GLIMPSE_ENQUEUE = 0,
301         LDLM_PLAIN_ENQUEUE,
302         LDLM_EXTENT_ENQUEUE,
303         LDLM_FLOCK_ENQUEUE,
304         LDLM_IBITS_ENQUEUE,
305         MDS_REINT_SETATTR,
306         MDS_REINT_CREATE,
307         MDS_REINT_LINK,
308         MDS_REINT_UNLINK,
309         MDS_REINT_RENAME,
310         MDS_REINT_OPEN,
311         MDS_REINT_SETXATTR,
312         BRW_READ_BYTES,
313         BRW_WRITE_BYTES,
314         EXTRA_LAST_OPC
315 };
316
317 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
318 /* class_obd.c */
319 extern cfs_proc_dir_entry_t *proc_lustre_root;
320
321 struct obd_device;
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 opc)
344 {
345         switch (opc) {
346         default:
347                 LBUG();
348
349         case LPROCFS_GET_SMP_ID:
350                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
351                         cfs_spin_lock(&stats->ls_lock);
352                         return 0;
353                 } else {
354                         return cfs_get_cpu();
355                 }
356
357         case LPROCFS_GET_NUM_CPU:
358                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
359                         cfs_spin_lock(&stats->ls_lock);
360                         return 1;
361                 } else {
362                         return cfs_num_possible_cpus();
363                 }
364         }
365 }
366
367 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc)
368 {
369         switch (opc) {
370         default:
371                 LBUG();
372
373         case LPROCFS_GET_SMP_ID:
374                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
375                         cfs_spin_unlock(&stats->ls_lock);
376                 else
377                         cfs_put_cpu();
378                 return;
379
380         case LPROCFS_GET_NUM_CPU:
381                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU)
382                         cfs_spin_unlock(&stats->ls_lock);
383                 return;
384         }
385 }
386
387 /* Two optimized LPROCFS counter increment functions are provided:
388  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
389  *     lprocfs_counter_add(cntr) - use for multi-valued counters
390  * Counter data layout allows config flag, counter lock and the
391  * count itself to reside within a single cache line.
392  */
393
394 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
395                                 long amount);
396 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
397                                 long amount);
398
399 #define lprocfs_counter_incr(stats, idx) \
400         lprocfs_counter_add(stats, idx, 1)
401 #define lprocfs_counter_decr(stats, idx) \
402         lprocfs_counter_sub(stats, idx, 1)
403
404 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
405                                  enum lprocfs_fields_flags field);
406 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
407                                             int idx,
408                                             enum lprocfs_fields_flags field)
409 {
410         __u64 ret = 0;
411         int i;
412
413         LASSERT(stats != NULL);
414         for (i = 0; i < cfs_num_possible_cpus(); i++)
415                 ret += lprocfs_read_helper(&(stats->ls_percpu[i]->lp_cntr[idx]),
416                                            field);
417         return ret;
418 }
419
420 extern struct lprocfs_stats *
421 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
422 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
423 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
424 extern void lprocfs_init_ops_stats(int num_private_stats,
425                                    struct lprocfs_stats *stats);
426 extern void lprocfs_init_mps_stats(int num_private_stats,
427                                    struct lprocfs_stats *stats);
428 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
429 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
430                                    unsigned int num_private_stats);
431 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
432                                   unsigned int num_private_stats);
433 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
434                                  unsigned conf, const char *name,
435                                  const char *units);
436 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
437 extern void lprocfs_free_md_stats(struct obd_device *obddev);
438 struct obd_export;
439 struct nid_stat;
440 extern int lprocfs_add_clear_entry(struct obd_device * obd,
441                                    cfs_proc_dir_entry_t *entry);
442 extern int lprocfs_exp_setup(struct obd_export *exp,
443                              lnet_nid_t *peer_nid, int reconnect, int *newnid);
444 extern int lprocfs_exp_cleanup(struct obd_export *exp);
445 extern cfs_proc_dir_entry_t *lprocfs_add_simple(struct proc_dir_entry *root,
446                                                 char *name,
447                                                 cfs_read_proc_t *read_proc,
448                                                 cfs_write_proc_t *write_proc,
449                                                 void *data,
450                                                 struct file_operations *fops);
451 extern struct proc_dir_entry *
452 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
453                     const char *format, ...);
454 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
455 extern int
456 lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
457                               unsigned long count, void *data);
458 extern int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
459                                         int count, int *eof,  void *data);
460
461 extern int lprocfs_register_stats(cfs_proc_dir_entry_t *root, const char *name,
462                                   struct lprocfs_stats *stats);
463
464 /* lprocfs_status.c */
465 extern int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
466                             struct lprocfs_vars *var,
467                             void *data);
468
469 extern cfs_proc_dir_entry_t *lprocfs_register(const char *name,
470                                               cfs_proc_dir_entry_t *parent,
471                                               struct lprocfs_vars *list,
472                                               void *data);
473
474 extern void lprocfs_remove(cfs_proc_dir_entry_t **root);
475 extern void lprocfs_remove_proc_entry(const char *name,
476                                       struct proc_dir_entry *parent);
477
478 extern cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *root,
479                                           const char *name);
480
481 extern int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list);
482 extern int lprocfs_obd_cleanup(struct obd_device *obd);
483 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
484 extern struct file_operations lprocfs_evict_client_fops;
485
486 extern int lprocfs_seq_create(cfs_proc_dir_entry_t *parent, char *name,
487                               mode_t mode, struct file_operations *seq_fops,
488                               void *data);
489 extern int lprocfs_obd_seq_create(struct obd_device *dev, char *name,
490                                   mode_t mode, struct file_operations *seq_fops,
491                                   void *data);
492
493 /* Generic callbacks */
494
495 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
496                           int count, int *eof, void *data);
497 extern int lprocfs_rd_atomic(char *page, char **start, off_t off,
498                              int count, int *eof, void *data);
499 extern int lprocfs_wr_atomic(struct file *file, const char *buffer,
500                              unsigned long count, void *data);
501 extern int lprocfs_rd_uint(char *page, char **start, off_t off,
502                            int count, int *eof, void *data);
503 extern int lprocfs_wr_uint(struct file *file, const char *buffer,
504                            unsigned long count, void *data);
505 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
506                            int count, int *eof, void *data);
507 extern int lprocfs_rd_name(char *page, char **start, off_t off,
508                            int count, int *eof, void *data);
509 extern int lprocfs_rd_fstype(char *page, char **start, off_t off,
510                              int count, int *eof, void *data);
511 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
512                                   int count, int *eof, void *data);
513 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
514                                 int count, int *eof, void *data);
515 extern int lprocfs_rd_import(char *page, char **start, off_t off, int count,
516                              int *eof, void *data);
517 extern int lprocfs_rd_state(char *page, char **start, off_t off, int count,
518                             int *eof, void *data);
519 extern int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
520                                     int count, int *eof, void *data);
521 extern int lprocfs_rd_num_exports(char *page, char **start, off_t off,
522                                   int count, int *eof, void *data);
523 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
524                               int count, int *eof, void *data);
525 struct adaptive_timeout;
526 extern int lprocfs_at_hist_helper(char *page, int count, int rc,
527                                   struct adaptive_timeout *at);
528 extern int lprocfs_rd_timeouts(char *page, char **start, off_t off,
529                                int count, int *eof, void *data);
530 extern int lprocfs_wr_timeouts(struct file *file, const char *buffer,
531                                unsigned long count, void *data);
532 extern int lprocfs_wr_evict_client(struct file *file, const char *buffer,
533                                    unsigned long count, void *data);
534 extern int lprocfs_wr_ping(struct file *file, const char *buffer,
535                            unsigned long count, void *data);
536
537 /* Statfs helpers */
538 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
539                               int count, int *eof, void *data);
540 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
541                                   int count, int *eof, void *data);
542 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
543                                  int count, int *eof, void *data);
544 extern int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
545                                  int count, int *eof, void *data);
546 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
547                                  int count, int *eof, void *data);
548 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
549                                 int count, int *eof, void *data);
550 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
551                                  int count, int *eof, void *data);
552
553 extern int lprocfs_write_helper(const char *buffer, unsigned long count,
554                                 int *val);
555 extern int lprocfs_write_frac_helper(const char *buffer, unsigned long count,
556                                      int *val, int mult);
557 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
558                                     long val, int mult);
559 extern int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
560                                     __u64 *val);
561 extern int lprocfs_write_frac_u64_helper(const char *buffer,
562                                          unsigned long count,
563                                          __u64 *val, int mult);
564 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
565 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
566 void lprocfs_oh_clear(struct obd_histogram *oh);
567 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
568
569 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
570                            struct lprocfs_counter *cnt);
571
572 /* lprocfs_status.c: recovery status */
573 int lprocfs_obd_rd_recovery_status(char *page, char **start, off_t off,
574                                    int count, int *eof, void *data);
575
576 /* lprocfs_statuc.c: hash statistics */
577 int lprocfs_obd_rd_hash(char *page, char **start, off_t off,
578                         int count, int *eof, void *data);
579
580 extern int lprocfs_seq_release(cfs_inode_t *, struct file *);
581
582 /* You must use these macros when you want to refer to
583  * the import in a client obd_device for a lprocfs entry */
584 #define LPROCFS_CLIMP_CHECK(obd) do {           \
585         typecheck(struct obd_device *, obd);    \
586         cfs_down_read(&(obd)->u.cli.cl_sem);    \
587         if ((obd)->u.cli.cl_import == NULL) {   \
588              cfs_up_read(&(obd)->u.cli.cl_sem); \
589              return -ENODEV;                    \
590         }                                       \
591 } while(0)
592 #define LPROCFS_CLIMP_EXIT(obd)                 \
593         cfs_up_read(&(obd)->u.cli.cl_sem);
594
595
596 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
597   proc entries; otherwise, you will define name##_seq_write function also for
598   a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
599   call lprocfs_obd_seq_create(obd, filename, 0444, &name#_fops, data); */
600 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                           \
601 static int name##_seq_open(cfs_inode_t *inode, struct file *file) {        \
602         struct proc_dir_entry *dp = PDE(inode);                            \
603         int rc;                                                            \
604         LPROCFS_ENTRY_AND_CHECK(dp);                                       \
605         rc = single_open(file, name##_seq_show, dp->data);                 \
606         if (rc) {                                                          \
607                 LPROCFS_EXIT();                                            \
608                 return rc;                                                 \
609         }                                                                  \
610         return 0;                                                          \
611 }                                                                          \
612 struct file_operations name##_fops = {                                     \
613         .owner   = THIS_MODULE,                                            \
614         .open    = name##_seq_open,                                        \
615         .read    = seq_read,                                               \
616         .write   = custom_seq_write,                                       \
617         .llseek  = seq_lseek,                                              \
618         .release = lprocfs_seq_release,                                    \
619 }
620
621 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
622 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
623
624 /* lproc_ptlrpc.c */
625 struct ptlrpc_request;
626 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
627
628 /* lproc_status.c */
629 int lprocfs_obd_rd_recovery_time_soft(char *page, char **start, off_t off,
630                                       int count, int *eof, void *data);
631 int lprocfs_obd_wr_recovery_time_soft(struct file *file,
632                                       const char *buffer,
633                                       unsigned long count, void *data);
634 int lprocfs_obd_rd_recovery_time_hard(char *page, char **start, off_t off,
635                                       int count, int *eof, void *data);
636 int lprocfs_obd_wr_recovery_time_hard(struct file *file,
637                                       const char *buffer,
638                                       unsigned long count, void *data);
639 int lprocfs_obd_rd_mntdev(char *page, char **start, off_t off,
640                           int count, int *eof, void *data);
641 /* all quota proc functions */
642 extern int lprocfs_quota_rd_bunit(char *page, char **start,
643                                   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,
648                                   off_t off, int count,
649                                   int *eof, void *data);
650 extern int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
651                                   unsigned long count, void *data);
652 extern int lprocfs_quota_rd_iunit(char *page, char **start,
653                                   off_t off, int count,
654                                   int *eof, void *data);
655 extern int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
656                                   unsigned long count, void *data);
657 extern int lprocfs_quota_rd_itune(char *page, char **start,
658                                   off_t off, int count,
659                                   int *eof, void *data);
660 extern int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
661                                   unsigned long count, void *data);
662 extern int lprocfs_quota_rd_type(char *page, char **start, off_t off, int count,
663                                  int *eof, void *data);
664 extern int lprocfs_quota_wr_type(struct file *file, const char *buffer,
665                                  unsigned long count, void *data);
666 extern int lprocfs_quota_rd_switch_seconds(char *page, char **start, off_t off,
667                                            int count, int *eof, void *data);
668 extern int lprocfs_quota_wr_switch_seconds(struct file *file,
669                                            const char *buffer,
670                                            unsigned long count, void *data);
671 extern int lprocfs_quota_rd_sync_blk(char *page, char **start, off_t off,
672                                      int count, int *eof, void *data);
673 extern int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
674                                      unsigned long count, void *data);
675 extern int lprocfs_quota_rd_switch_qs(char *page, char **start, off_t off,
676                                       int count, int *eof, void *data);
677 extern int lprocfs_quota_wr_switch_qs(struct file *file,
678                                       const char *buffer,
679                                       unsigned long count, void *data);
680 extern int lprocfs_quota_rd_boundary_factor(char *page, char **start, off_t off,
681                                             int count, int *eof, void *data);
682 extern int lprocfs_quota_wr_boundary_factor(struct file *file,
683                                             const char *buffer,
684                                             unsigned long count, void *data);
685 extern int lprocfs_quota_rd_least_bunit(char *page, char **start, off_t off,
686                                         int count, int *eof, void *data);
687 extern int lprocfs_quota_wr_least_bunit(struct file *file,
688                                         const char *buffer,
689                                         unsigned long count, void *data);
690 extern int lprocfs_quota_rd_least_iunit(char *page, char **start, off_t off,
691                                         int count, int *eof, void *data);
692 extern int lprocfs_quota_wr_least_iunit(struct file *file,
693                                         const char *buffer,
694                                         unsigned long count, void *data);
695 extern int lprocfs_quota_rd_qs_factor(char *page, char **start, off_t off,
696                                       int count, int *eof, void *data);
697 extern int lprocfs_quota_wr_qs_factor(struct file *file,
698                                       const char *buffer,
699                                       unsigned long count, void *data);
700
701
702
703 #else
704 /* LPROCFS is not defined */
705
706
707
708 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
709                                        int index, long amount)
710 { return; }
711 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
712                                         int index)
713 { return; }
714 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
715                                        int index, long amount)
716 { return; }
717 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
718                                         int index)
719 { return; }
720 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
721                                         int index, unsigned conf,
722                                         const char *name, const char *units)
723 { return; }
724
725 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
726                                    enum lprocfs_fields_flags field)
727 { return 0; }
728
729 /* NB: we return !NULL to satisfy error checker */
730 static inline struct lprocfs_stats *
731 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
732 { return (struct lprocfs_stats *)1; }
733 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
734 { return; }
735 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
736 { return; }
737 static inline int lprocfs_register_stats(cfs_proc_dir_entry_t *root,
738                                          const char *name,
739                                          struct lprocfs_stats *stats)
740 { return 0; }
741 static inline void lprocfs_init_ops_stats(int num_private_stats,
742                                           struct lprocfs_stats *stats)
743 { return; }
744 static inline void lprocfs_init_mps_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 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
758 { return; }
759
760 struct obd_export;
761 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
762 { return 0; }
763 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid,
764                                     int reconnect, int *newnid)
765 { return 0; }
766 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
767 { return 0; }
768 static inline cfs_proc_dir_entry_t *
769 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
770                    cfs_read_proc_t *read_proc, cfs_write_proc_t *write_proc,
771                    void *data, struct file_operations *fops)
772 {return 0; }
773 static inline struct proc_dir_entry *
774 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
775                     const char *format, ...)
776 {return NULL; }
777 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
778 { return; }
779 static inline
780 int lprocfs_nid_stats_clear_write(struct file *file, const char *buffer,
781                                   unsigned long count, void *data)
782 {return count;}
783 static inline
784 int lprocfs_nid_stats_clear_read(char *page, char **start, off_t off,
785                                  int count, int *eof,  void *data)
786 {return count;}
787
788 static inline cfs_proc_dir_entry_t *
789 lprocfs_register(const char *name, cfs_proc_dir_entry_t *parent,
790                  struct lprocfs_vars *list, void *data)
791 { return NULL; }
792 static inline int lprocfs_add_vars(cfs_proc_dir_entry_t *root,
793                                    struct lprocfs_vars *var,
794                                    void *data)
795 { return 0; }
796 static inline void lprocfs_remove(cfs_proc_dir_entry_t **root)
797 { return; }
798 static inline void lprocfs_remove_proc_entry(const char *name,
799                                              struct proc_dir_entry *parent)
800 { return; }
801 static inline cfs_proc_dir_entry_t *lprocfs_srch(cfs_proc_dir_entry_t *head,
802                                                  const char *name)
803 { return 0; }
804 static inline int lprocfs_obd_setup(struct obd_device *dev,
805                                     struct lprocfs_vars *list)
806 { return 0; }
807 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
808 { return 0; }
809 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
810                                  int count, int *eof, void *data)
811 { return 0; }
812 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
813                                   int count, int *eof, void *data)
814 { return 0; }
815 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
816                                   int count, int *eof, void *data)
817 { return 0; }
818 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
819                                          int count, int *eof, void *data)
820 { return 0; }
821 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
822                                        int count, int *eof, void *data)
823 { return 0; }
824 static inline int lprocfs_rd_import(char *page, char **start, off_t off,
825                                     int count, int *eof, void *data)
826 { return 0; }
827 static inline int lprocfs_rd_state(char *page, char **start, off_t off,
828                                    int count, int *eof, void *data)
829 { return 0; }
830 static inline int lprocfs_rd_connect_flags(char *page, char **start, off_t off,
831                                            int count, int *eof, void *data)
832 { return 0; }
833 static inline int lprocfs_rd_num_exports(char *page, char **start, off_t off,
834                                          int count, int *eof, void *data)
835 { return 0; }
836 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
837                                      int count, int *eof, void *data)
838 { return 0; }
839 struct adaptive_timeout;
840 static inline int lprocfs_at_hist_helper(char *page, int count, int rc,
841                                          struct adaptive_timeout *at)
842 { return 0; }
843 static inline int lprocfs_rd_timeouts(char *page, char **start, off_t off,
844                                       int count, int *eof, void *data)
845 { return 0; }
846 static inline int lprocfs_wr_timeouts(struct file *file,
847                                       const char *buffer,
848                                       unsigned long count, void *data)
849 { return 0; }
850 static inline int lprocfs_wr_evict_client(struct file *file,
851                                           const char *buffer,
852                                           unsigned long count, void *data)
853 { return 0; }
854 static inline int lprocfs_wr_ping(struct file *file, const char *buffer,
855                                   unsigned long count, void *data)
856 { return 0; }
857
858
859 /* Statfs helpers */
860 static inline
861 int lprocfs_rd_blksize(char *page, char **start, off_t off,
862                        int count, int *eof, void *data)
863 { return 0; }
864 static inline
865 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
866                            int count, int *eof, void *data)
867 { return 0; }
868 static inline
869 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
870                           int count, int *eof, void *data)
871 { return 0; }
872 static inline
873 int lprocfs_rd_kbytesavail(char *page, char **start, off_t off,
874                            int count, int *eof, void *data)
875 { return 0; }
876 static inline
877 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
878                           int count, int *eof, void *data)
879 { return 0; }
880 static inline
881 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
882                          int count, int *eof, void *data)
883 { return 0; }
884 static inline
885 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
886                           int count, int *eof, void *data)
887 { return 0; }
888 static inline
889 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
890 { return; }
891 static inline
892 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
893 { return; }
894 static inline
895 void lprocfs_oh_clear(struct obd_histogram *oh)
896 { return; }
897 static inline
898 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
899 { return 0; }
900 static inline
901 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
902                            struct lprocfs_counter *cnt)
903 { return; }
904 static inline
905 __u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
906                                enum lprocfs_fields_flags field)
907 { return (__u64)0; }
908
909 #define LPROC_SEQ_FOPS_RO(name)
910 #define LPROC_SEQ_FOPS(name)
911
912 /* lproc_ptlrpc.c */
913 #define target_print_req NULL
914
915 #endif /* LPROCFS */
916
917 #endif /* LPROCFS_SNMP_H */