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