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