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