Whamcloud - gitweb
LU-9019 libcfs: remove the remaining cfs_time wrappers
[fs/lustre-release.git] / lustre / include / lprocfs_status.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/include/lprocfs_status.h
33  *
34  * Top level header file for LProc
35  *
36  * Author: Hariharan Thantry thantry@users.sourceforge.net
37  */
38 #ifndef _LPROCFS_STATUS_H
39 #define _LPROCFS_STATUS_H
40
41 #include <linux/fs.h>
42 #include <linux/proc_fs.h>
43 #include <linux/debugfs.h>
44 #include <linux/rwsem.h>
45 #include <linux/spinlock.h>
46 #include <linux/seq_file.h>
47
48 #include <libcfs/libcfs.h>
49 #include <uapi/linux/lustre/lustre_idl.h>
50
51 struct lprocfs_vars {
52         const char                      *name;
53         const struct file_operations    *fops;
54         void                            *data;
55         /**
56          * /proc file mode.
57          */
58         mode_t                           proc_mode;
59 };
60
61 /**
62  * Append a space separated list of current set flags to str.
63  */
64 #define flag2str(port, flag)                                            \
65         do {                                                            \
66                 if ((port)->port##_##flag) {                            \
67                         seq_printf(m, "%s" #flag, first ? "" : ", ");   \
68                         first = false;                                  \
69                 }                                                       \
70         } while (0)
71
72 void obd_connect_seq_flags2str(struct seq_file *m, __u64 flags, __u64 flags2,
73                                const char *sep);
74 void obd_connect_data_seqprint(struct seq_file *m,
75                                struct obd_connect_data *ocd);
76
77 /* if we find more consumers this could be generalized */
78 #define OBD_HIST_MAX 32
79 struct obd_histogram {
80         spinlock_t      oh_lock;
81         unsigned long   oh_buckets[OBD_HIST_MAX];
82 };
83
84 enum {
85         BRW_R_PAGES = 0,
86         BRW_W_PAGES,
87         BRW_R_RPC_HIST,
88         BRW_W_RPC_HIST,
89         BRW_R_IO_TIME,
90         BRW_W_IO_TIME,
91         BRW_R_DISCONT_PAGES,
92         BRW_W_DISCONT_PAGES,
93         BRW_R_DISCONT_BLOCKS,
94         BRW_W_DISCONT_BLOCKS,
95         BRW_R_DISK_IOSIZE,
96         BRW_W_DISK_IOSIZE,
97         BRW_R_DIO_FRAGS,
98         BRW_W_DIO_FRAGS,
99         BRW_LAST,
100 };
101
102 struct brw_stats {
103         struct obd_histogram hist[BRW_LAST];
104 };
105
106 enum {
107         RENAME_SAMEDIR_SIZE = 0,
108         RENAME_CROSSDIR_SRC_SIZE,
109         RENAME_CROSSDIR_TGT_SIZE,
110         RENAME_LAST,
111 };
112
113 struct rename_stats {
114         struct obd_histogram hist[RENAME_LAST];
115 };
116
117 /* An lprocfs counter can be configured using the enum bit masks below.
118  *
119  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
120  * protects this counter from concurrent updates. If not specified,
121  * lprocfs an internal per-counter lock variable. External locks are
122  * not used to protect counter increments, but are used to protect
123  * counter readout and resets.
124  *
125  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
126  * (i.e. counter can be incremented by more than "1"). When specified,
127  * the counter maintains min, max and sum in addition to a simple
128  * invocation count. This allows averages to be be computed.
129  * If not specified, the counter is an increment-by-1 counter.
130  * min, max, sum, etc. are not maintained.
131  *
132  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
133  * squares (for multi-valued counter samples only). This allows
134  * external computation of standard deviation, but involves a 64-bit
135  * multiply per counter increment.
136  */
137
138 enum {
139         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
140         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
141         LPROCFS_CNTR_STDDEV       = 0x0004,
142
143         /* counter data type */
144         LPROCFS_TYPE_REGS         = 0x0100,
145         LPROCFS_TYPE_BYTES        = 0x0200,
146         LPROCFS_TYPE_PAGES        = 0x0400,
147         LPROCFS_TYPE_CYCLE        = 0x0800,
148 };
149
150 #define LC_MIN_INIT ((~(__u64)0) >> 1)
151
152 struct lprocfs_counter_header {
153         unsigned int            lc_config;
154         const char              *lc_name;   /* must be static */
155         const char              *lc_units;  /* must be static */
156 };
157
158 struct lprocfs_counter {
159         __s64   lc_count;
160         __s64   lc_min;
161         __s64   lc_max;
162         __s64   lc_sumsquare;
163         /*
164          * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
165          * for irq context counter, i.e. stats with
166          * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
167          * lc_array_sum[1]
168          */
169         __s64   lc_array_sum[1];
170 };
171 #define lc_sum          lc_array_sum[0]
172 #define lc_sum_irq      lc_array_sum[1]
173
174 struct lprocfs_percpu {
175         struct lprocfs_counter lp_cntr[0];
176 };
177
178 enum lprocfs_stats_lock_ops {
179         LPROCFS_GET_NUM_CPU     = 0x0001, /* number allocated per-CPU stats */
180         LPROCFS_GET_SMP_ID      = 0x0002, /* current stat to be updated */
181 };
182
183 enum lprocfs_stats_flags {
184         LPROCFS_STATS_FLAG_NONE     = 0x0000, /* per cpu counter */
185         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
186                                                * area and need locking */
187         LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
188 };
189
190 enum lprocfs_fields_flags {
191         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
192         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
193         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
194         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
195         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
196         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
197         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
198 };
199
200 struct lprocfs_stats {
201         /* # of counters */
202         unsigned short                  ls_num;
203         /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
204         unsigned short                  ls_biggest_alloc_num;
205         enum lprocfs_stats_flags        ls_flags;
206         /* Lock used when there are no percpu stats areas; For percpu stats,
207          * it is used to protect ls_biggest_alloc_num change */
208         spinlock_t                      ls_lock;
209
210         /* has ls_num of counter headers */
211         struct lprocfs_counter_header   *ls_cnt_header;
212         struct lprocfs_percpu           *ls_percpu[0];
213 };
214
215 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
216
217 /* Pack all opcodes down into a single monotonically increasing index */
218 static inline int opcode_offset(__u32 opc) {
219         if (opc < OST_LAST_OPC) {
220                  /* OST opcode */
221                 return (opc - OST_FIRST_OPC);
222         } else if (opc < MDS_LAST_OPC) {
223                 /* MDS opcode */
224                 return (opc - MDS_FIRST_OPC +
225                         OPC_RANGE(OST));
226         } else if (opc < LDLM_LAST_OPC) {
227                 /* LDLM Opcode */
228                 return (opc - LDLM_FIRST_OPC +
229                         OPC_RANGE(MDS) +
230                         OPC_RANGE(OST));
231         } else if (opc < MGS_LAST_OPC) {
232                 /* MGS Opcode */
233                 return (opc - MGS_FIRST_OPC +
234                         OPC_RANGE(LDLM) +
235                         OPC_RANGE(MDS) +
236                         OPC_RANGE(OST));
237         } else if (opc < OBD_LAST_OPC) {
238                 /* OBD Ping */
239                 return (opc - OBD_FIRST_OPC +
240                         OPC_RANGE(MGS) +
241                         OPC_RANGE(LDLM) +
242                         OPC_RANGE(MDS) +
243                         OPC_RANGE(OST));
244         } else if (opc < LLOG_LAST_OPC) {
245                 /* LLOG Opcode */
246                 return (opc - LLOG_FIRST_OPC +
247                         OPC_RANGE(OBD) +
248                         OPC_RANGE(MGS) +
249                         OPC_RANGE(LDLM) +
250                         OPC_RANGE(MDS) +
251                         OPC_RANGE(OST));
252         } else if (opc < QUOTA_LAST_OPC) {
253                 /* LQUOTA Opcode */
254                 return (opc - QUOTA_FIRST_OPC +
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 < SEQ_LAST_OPC) {
262                 /* SEQ opcode */
263                 return (opc - SEQ_FIRST_OPC +
264                         OPC_RANGE(QUOTA) +
265                         OPC_RANGE(LLOG) +
266                         OPC_RANGE(OBD) +
267                         OPC_RANGE(MGS) +
268                         OPC_RANGE(LDLM) +
269                         OPC_RANGE(MDS) +
270                         OPC_RANGE(OST));
271         } else if (opc < SEC_LAST_OPC) {
272                 /* SEC opcode */
273                 return (opc - SEC_FIRST_OPC +
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 if (opc < FLD_LAST_OPC) {
283                 /* FLD opcode */
284                  return (opc - FLD_FIRST_OPC +
285                         OPC_RANGE(SEC) +
286                         OPC_RANGE(SEQ) +
287                         OPC_RANGE(QUOTA) +
288                         OPC_RANGE(LLOG) +
289                         OPC_RANGE(OBD) +
290                         OPC_RANGE(MGS) +
291                         OPC_RANGE(LDLM) +
292                         OPC_RANGE(MDS) +
293                         OPC_RANGE(OST));
294         } else if (opc < OUT_UPDATE_LAST_OPC) {
295                 /* update opcode */
296                 return (opc - OUT_UPDATE_FIRST_OPC +
297                         OPC_RANGE(FLD) +
298                         OPC_RANGE(SEC) +
299                         OPC_RANGE(SEQ) +
300                         OPC_RANGE(QUOTA) +
301                         OPC_RANGE(LLOG) +
302                         OPC_RANGE(OBD) +
303                         OPC_RANGE(MGS) +
304                         OPC_RANGE(LDLM) +
305                         OPC_RANGE(MDS) +
306                         OPC_RANGE(OST));
307         } else if (opc < LFSCK_LAST_OPC) {
308                 /* LFSCK opcode */
309                 return (opc - LFSCK_FIRST_OPC +
310                         OPC_RANGE(OUT_UPDATE) +
311                         OPC_RANGE(FLD) +
312                         OPC_RANGE(SEC) +
313                         OPC_RANGE(SEQ) +
314                         OPC_RANGE(QUOTA) +
315                         OPC_RANGE(LLOG) +
316                         OPC_RANGE(OBD) +
317                         OPC_RANGE(MGS) +
318                         OPC_RANGE(LDLM) +
319                         OPC_RANGE(MDS) +
320                         OPC_RANGE(OST));
321         } else {
322                 /* Unknown Opcode */
323                 return -1;
324         }
325 }
326
327
328 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
329                             OPC_RANGE(MDS)  + \
330                             OPC_RANGE(LDLM) + \
331                             OPC_RANGE(MGS)  + \
332                             OPC_RANGE(OBD)  + \
333                             OPC_RANGE(LLOG) + \
334                             OPC_RANGE(SEC)  + \
335                             OPC_RANGE(SEQ)  + \
336                             OPC_RANGE(SEC)  + \
337                             OPC_RANGE(FLD)  + \
338                             OPC_RANGE(OUT_UPDATE) + \
339                             OPC_RANGE(LFSCK))
340
341 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
342                             OPC_RANGE(EXTRA))
343
344 enum {
345         PTLRPC_REQWAIT_CNTR = 0,
346         PTLRPC_REQQDEPTH_CNTR,
347         PTLRPC_REQACTIVE_CNTR,
348         PTLRPC_TIMEOUT,
349         PTLRPC_REQBUF_AVAIL_CNTR,
350         PTLRPC_LAST_CNTR
351 };
352
353 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
354
355 enum lprocfs_extra_opc {
356         LDLM_GLIMPSE_ENQUEUE = 0,
357         LDLM_PLAIN_ENQUEUE,
358         LDLM_EXTENT_ENQUEUE,
359         LDLM_FLOCK_ENQUEUE,
360         LDLM_IBITS_ENQUEUE,
361         MDS_REINT_SETATTR,
362         MDS_REINT_CREATE,
363         MDS_REINT_LINK,
364         MDS_REINT_UNLINK,
365         MDS_REINT_RENAME,
366         MDS_REINT_OPEN,
367         MDS_REINT_SETXATTR,
368         MDS_REINT_RESYNC,
369         BRW_READ_BYTES,
370         BRW_WRITE_BYTES,
371         EXTRA_LAST_OPC
372 };
373
374 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
375 /* class_obd.c */
376 extern struct proc_dir_entry *proc_lustre_root;
377 extern struct dentry *debugfs_lustre_root;
378 extern struct kset *lustre_kset;
379
380 struct obd_device;
381 struct obd_histogram;
382
383 #define JOBSTATS_JOBID_VAR_MAX_LEN      20
384 #define JOBSTATS_DISABLE                "disable"
385 #define JOBSTATS_PROCNAME_UID           "procname_uid"
386 #define JOBSTATS_NODELOCAL              "nodelocal"
387
388 typedef void (*cntr_init_callback)(struct lprocfs_stats *stats);
389
390 struct obd_job_stats {
391         struct cfs_hash        *ojs_hash;       /* hash of jobids */
392         struct list_head        ojs_list;       /* list of job_stat structs */
393         rwlock_t                ojs_lock;       /* protect ojs_list/js_list */
394         unsigned int            ojs_cleanup_interval;/* seconds before expiry */
395         time64_t                ojs_last_cleanup; /* previous cleanup time */
396         cntr_init_callback      ojs_cntr_init_fn;/* lprocfs_stats initializer */
397         unsigned short          ojs_cntr_num;   /* number of stats in struct */
398         bool                    ojs_cleaning;   /* currently expiring stats */
399 };
400
401 #ifdef CONFIG_PROC_FS
402
403 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats,
404                             unsigned int cpuid);
405 int lprocfs_stats_lock(struct lprocfs_stats *stats,
406                        enum lprocfs_stats_lock_ops opc,
407                        unsigned long *flags);
408 void lprocfs_stats_unlock(struct lprocfs_stats *stats,
409                           enum lprocfs_stats_lock_ops opc,
410                           unsigned long *flags);
411
412 static inline unsigned int
413 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
414 {
415         unsigned int percpusize;
416
417         percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
418
419         /* irq safe stats need lc_array_sum[1] */
420         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
421                 percpusize += stats->ls_num * sizeof(__s64);
422
423         if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
424                 percpusize = L1_CACHE_ALIGN(percpusize);
425
426         return percpusize;
427 }
428
429 static inline struct lprocfs_counter *
430 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
431                           int index)
432 {
433         struct lprocfs_counter *cntr;
434
435         cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
436
437         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
438                 cntr = (void *)cntr + index * sizeof(__s64);
439
440         return cntr;
441 }
442
443 /* Two optimized LPROCFS counter increment functions are provided:
444  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
445  *     lprocfs_counter_add(cntr) - use for multi-valued counters
446  * Counter data layout allows config flag, counter lock and the
447  * count itself to reside within a single cache line.
448  */
449
450 extern void lprocfs_counter_add(struct lprocfs_stats *stats, int idx,
451                                 long amount);
452 extern void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx,
453                                 long amount);
454
455 #define lprocfs_counter_incr(stats, idx) \
456         lprocfs_counter_add(stats, idx, 1)
457 #define lprocfs_counter_decr(stats, idx) \
458         lprocfs_counter_sub(stats, idx, 1)
459
460 extern __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
461                                  struct lprocfs_counter_header *header,
462                                  enum lprocfs_stats_flags flags,
463                                  enum lprocfs_fields_flags field);
464 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
465                             enum lprocfs_fields_flags field);
466
467 extern struct lprocfs_stats *
468 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
469 extern void lprocfs_clear_stats(struct lprocfs_stats *stats);
470 extern void lprocfs_free_stats(struct lprocfs_stats **stats);
471 extern void lprocfs_init_ops_stats(int num_private_stats,
472                                    struct lprocfs_stats *stats);
473 extern void lprocfs_init_mps_stats(int num_private_stats,
474                                    struct lprocfs_stats *stats);
475 extern void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats);
476 extern int lprocfs_alloc_obd_stats(struct obd_device *obddev,
477                                    unsigned int num_private_stats);
478 extern int lprocfs_alloc_md_stats(struct obd_device *obddev,
479                                   unsigned int num_private_stats);
480 extern void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
481                                  unsigned conf, const char *name,
482                                  const char *units);
483 extern void lprocfs_free_obd_stats(struct obd_device *obddev);
484 extern void lprocfs_free_md_stats(struct obd_device *obddev);
485 struct obd_export;
486 struct nid_stat;
487 extern int lprocfs_add_clear_entry(struct obd_device * obd,
488                                    struct proc_dir_entry *entry);
489 #ifdef HAVE_SERVER_SUPPORT
490 extern int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *peer_nid);
491 extern int lprocfs_exp_cleanup(struct obd_export *exp);
492 struct dentry *ldebugfs_add_symlink(const char *name, const char *target,
493                                     const char *format, ...);
494 #else
495 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
496 { return 0; }
497 #endif
498 struct dentry *ldebugfs_add_simple(struct dentry *root, char *name, void *data,
499                                    const struct file_operations *fops);
500 extern struct proc_dir_entry *
501 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
502                    void *data, const struct file_operations *fops);
503 extern struct proc_dir_entry *
504 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
505                     const char *format, ...);
506 extern void lprocfs_free_per_client_stats(struct obd_device *obd);
507 #ifdef HAVE_SERVER_SUPPORT
508 extern ssize_t
509 lprocfs_nid_stats_clear_seq_write(struct file *file, const char __user *buffer,
510                                         size_t count, loff_t *off);
511 extern int lprocfs_nid_stats_clear_seq_show(struct seq_file *file, void *data);
512 #endif
513 extern int ldebugfs_register_stats(struct dentry *parent, const char *name,
514                                    struct lprocfs_stats *stats);
515 extern int lprocfs_register_stats(struct proc_dir_entry *root, const char *name,
516                                   struct lprocfs_stats *stats);
517
518 /* lprocfs_status.c */
519 extern int ldebugfs_add_vars(struct dentry *parent, struct lprocfs_vars *var,
520                              void *data);
521 extern int lprocfs_add_vars(struct proc_dir_entry *root,
522                             struct lprocfs_vars *var, void *data);
523
524 extern struct dentry *ldebugfs_register(const char *name,
525                                         struct dentry *parent,
526                                         struct lprocfs_vars *list,
527                                         void *data);
528 extern struct proc_dir_entry *
529 lprocfs_register(const char *name, struct proc_dir_entry *parent,
530                  struct lprocfs_vars *list, void *data);
531
532 extern void ldebugfs_remove(struct dentry **entryp);
533 extern void lprocfs_remove(struct proc_dir_entry **root);
534 extern void lprocfs_remove_proc_entry(const char *name,
535                                       struct proc_dir_entry *parent);
536 #ifndef HAVE_REMOVE_PROC_SUBTREE
537 extern int remove_proc_subtree(const char *name,
538                                struct proc_dir_entry *parent);
539 #define PDE_DATA(inode)         (PDE(inode)->data)
540
541 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
542 {
543         struct proc_dir_entry *dp = PDE(inode);
544         int deleted = 0;
545
546         spin_lock(&(dp)->pde_unload_lock);
547         if (dp->proc_fops == NULL)
548                 deleted = 1;
549         spin_unlock(&(dp)->pde_unload_lock);
550         if (deleted)
551                 return -ENODEV;
552         return 0;
553 }
554 #else
555 static inline int LPROCFS_ENTRY_CHECK(struct inode *inode)
556 { return 0; }
557 #endif
558
559 extern int lprocfs_obd_setup(struct obd_device *obd, bool uuid_only);
560 extern int lprocfs_obd_cleanup(struct obd_device *obd);
561 #ifdef HAVE_SERVER_SUPPORT
562 extern const struct file_operations lprocfs_evict_client_fops;
563 #endif
564
565 int ldebugfs_seq_create(struct dentry *parent, const char *name, umode_t mode,
566                         const struct file_operations *seq_fops, void *data);
567 extern int lprocfs_seq_create(struct proc_dir_entry *parent, const char *name,
568                               mode_t mode,
569                               const struct file_operations *seq_fops,
570                               void *data);
571 extern int lprocfs_obd_seq_create(struct obd_device *dev, const char *name,
572                                   mode_t mode,
573                                   const struct file_operations *seq_fops,
574                                   void *data);
575
576 /* Generic callbacks */
577 extern int lprocfs_uuid_seq_show(struct seq_file *m, void *data);
578 extern int lprocfs_name_seq_show(struct seq_file *m, void *data);
579 extern int lprocfs_server_uuid_seq_show(struct seq_file *m, void *data);
580 extern int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data);
581 ssize_t conn_uuid_show(struct kobject *kobj, struct attribute *attr, char *buf);
582 extern int lprocfs_import_seq_show(struct seq_file *m, void *data);
583 extern int lprocfs_state_seq_show(struct seq_file *m, void *data);
584 extern int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data);
585 #ifdef HAVE_SERVER_SUPPORT
586 extern int lprocfs_num_exports_seq_show(struct seq_file *m, void *data);
587 #endif
588 struct adaptive_timeout;
589 extern int lprocfs_at_hist_helper(struct seq_file *m,
590                                   struct adaptive_timeout *at);
591 extern int lprocfs_timeouts_seq_show(struct seq_file *m, void *data);
592 extern ssize_t
593 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
594                            size_t count, loff_t *off);
595 #ifdef HAVE_SERVER_SUPPORT
596 extern ssize_t
597 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
598                                 size_t count, loff_t *off);
599 #endif
600 ssize_t ping_store(struct kobject *kobj, struct attribute *attr,
601                    const char *buffer, size_t count);
602 extern ssize_t
603 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
604                        size_t count, loff_t *off);
605 extern ssize_t
606 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
607                          size_t count, loff_t *off);
608 extern int lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data);
609 extern ssize_t
610 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
611                                size_t count, loff_t *off);
612
613 extern int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult);
614 extern int lprocfs_read_frac_helper(char *buffer, unsigned long count,
615                                     long val, int mult);
616 extern int lprocfs_str_with_units_to_s64(const char __user *buffer,
617                                          unsigned long count, __s64 *val,
618                                          char defunit);
619
620 char *lprocfs_strnstr(const char *s1, const char *s2, size_t len);
621 char *lprocfs_find_named_value(const char *buffer, const char *name,
622                                 size_t *count);
623 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
624 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
625 void lprocfs_oh_clear(struct obd_histogram *oh);
626 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
627
628 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
629                            struct lprocfs_counter *cnt);
630
631 #ifdef HAVE_SERVER_SUPPORT
632 /* lprocfs_status.c: recovery status */
633 int lprocfs_recovery_status_seq_show(struct seq_file *m, void *data);
634
635 /* lprocfs_status.c: hash statistics */
636 int lprocfs_hash_seq_show(struct seq_file *m, void *data);
637
638 /* lprocfs_status.c: IR factor */
639 int lprocfs_ir_factor_seq_show(struct seq_file *m, void *data);
640 ssize_t
641 lprocfs_ir_factor_seq_write(struct file *file, const char __user *buffer,
642                                 size_t count, loff_t *off);
643 #endif
644
645 /* lprocfs_status.c: dump pages on cksum error */
646 int lprocfs_checksum_dump_seq_show(struct seq_file *m, void *data);
647 ssize_t
648 lprocfs_checksum_dump_seq_write(struct file *file, const char __user *buffer,
649                                 size_t count, loff_t *off);
650
651 extern int lprocfs_single_release(struct inode *, struct file *);
652 extern int lprocfs_seq_release(struct inode *, struct file *);
653
654 /* You must use these macros when you want to refer to
655  * the import in a client obd_device for a lprocfs entry */
656 #define LPROCFS_CLIMP_CHECK(obd) do {           \
657         typecheck(struct obd_device *, obd);    \
658         down_read(&(obd)->u.cli.cl_sem);    \
659         if ((obd)->u.cli.cl_import == NULL) {   \
660              up_read(&(obd)->u.cli.cl_sem); \
661              return -ENODEV;                    \
662         }                                       \
663 } while(0)
664 #define LPROCFS_CLIMP_EXIT(obd)                 \
665         up_read(&(obd)->u.cli.cl_sem);
666
667 /* write the name##_seq_show function, call LDEBUGFS_SEQ_FOPS_RO for read-only
668  * debugfs entries; otherwise, you will define name##_seq_write function also
669  * for a read-write debugfs entry, and then call LDEBUGFS_SEQ_FOPS instead.
670  * Finally, call ldebugfs_seq_create(obd, filename, 0444, &name#_fops, data);
671  */
672 #define __LDEBUGFS_SEQ_FOPS(name, custom_seq_write)                     \
673 static int name##_single_open(struct inode *inode, struct file *file)   \
674 {                                                                       \
675         return single_open(file, name##_seq_show, inode->i_private);    \
676 }                                                                       \
677 static const struct file_operations name##_fops = {                     \
678         .owner   = THIS_MODULE,                                         \
679         .open    = name##_single_open,                                  \
680         .read    = seq_read,                                            \
681         .write   = custom_seq_write,                                    \
682         .llseek  = seq_lseek,                                           \
683         .release = single_release,                                      \
684 }
685
686 #define LDEBUGFS_SEQ_FOPS_RO(name)      __LDEBUGFS_SEQ_FOPS(name, NULL)
687 #define LDEBUGFS_SEQ_FOPS(name)         __LDEBUGFS_SEQ_FOPS(name, \
688                                                             name##_seq_write)
689
690 #define LDEBUGFS_SEQ_FOPS_RO_TYPE(name, type)                           \
691         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
692         {                                                               \
693                 return lprocfs_##type##_seq_show(m, m->private);        \
694         }                                                               \
695         LDEBUGFS_SEQ_FOPS_RO(name##_##type)
696
697 #define LDEBUGFS_SEQ_FOPS_RW_TYPE(name, type)                           \
698         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
699         {                                                               \
700                 return lprocfs_##type##_seq_show(m, m->private);        \
701         }                                                               \
702         static ssize_t name##_##type##_seq_write(struct file *file,     \
703                         const char __user *buffer, size_t count,        \
704                         loff_t *off)                                    \
705         {                                                               \
706                 struct seq_file *seq = file->private_data;              \
707                 return ldebugfs_##type##_seq_write(file, buffer, count, \
708                                                    seq->private);       \
709         }                                                               \
710         LDEBUGFS_SEQ_FOPS(name##_##type);
711
712 #define LDEBUGFS_FOPS_WR_ONLY(name, type)                               \
713         static ssize_t name##_##type##_write(struct file *file,         \
714                         const char __user *buffer, size_t count,        \
715                         loff_t *off)                                    \
716         {                                                               \
717                 return ldebugfs_##type##_seq_write(file, buffer, count, \
718                                                    off);                \
719         }                                                               \
720         static int name##_##type##_open(struct inode *inode,            \
721                                         struct file *file)              \
722         {                                                               \
723                 return single_open(file, NULL, inode->i_private);       \
724         }                                                               \
725         static const struct file_operations name##_##type##_fops = {    \
726                 .open    = name##_##type##_open,                        \
727                 .write   = name##_##type##_write,                       \
728                 .release = single_release,                              \
729         };
730
731 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
732  * proc entries; otherwise, you will define name##_seq_write function also for
733  * a read-write proc entry, and then call LPROC_SEQ_FOPS instead. Finally,
734  * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
735  */
736 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                        \
737 static int name##_single_open(struct inode *inode, struct file *file)   \
738 {                                                                       \
739         int rc;                                                         \
740                                                                         \
741         rc = LPROCFS_ENTRY_CHECK(inode);                                \
742         if (rc < 0)                                                     \
743                 return rc;                                              \
744                                                                         \
745         return single_open(file, name##_seq_show,                       \
746                            inode->i_private ? inode->i_private :        \
747                                               PDE_DATA(inode));         \
748 }                                                                       \
749 static const struct file_operations name##_fops = {                     \
750         .owner   = THIS_MODULE,                                         \
751         .open    = name##_single_open,                                  \
752         .read    = seq_read,                                            \
753         .write   = custom_seq_write,                                    \
754         .llseek  = seq_lseek,                                           \
755         .release = lprocfs_single_release,                              \
756 }
757
758 #define LPROC_SEQ_FOPS_RO(name)         __LPROC_SEQ_FOPS(name, NULL)
759 #define LPROC_SEQ_FOPS(name)            __LPROC_SEQ_FOPS(name, name##_seq_write)
760
761 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)                              \
762         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
763         {                                                               \
764                 return lprocfs_##type##_seq_show(m, m->private);        \
765         }                                                               \
766         LPROC_SEQ_FOPS_RO(name##_##type)
767
768 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)                              \
769         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
770         {                                                               \
771                 return lprocfs_##type##_seq_show(m, m->private);        \
772         }                                                               \
773         static ssize_t name##_##type##_seq_write(struct file *file,     \
774                         const char __user *buffer, size_t count,        \
775                         loff_t *off)                                    \
776         {                                                               \
777                 struct seq_file *seq = file->private_data;              \
778                 return lprocfs_##type##_seq_write(file, buffer,         \
779                                                   count, seq->private); \
780         }                                                               \
781         LPROC_SEQ_FOPS(name##_##type);
782
783 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)                              \
784         static ssize_t name##_##type##_write(struct file *file,         \
785                         const char __user *buffer, size_t count,        \
786                         loff_t *off)                                    \
787         {                                                               \
788                 return lprocfs_##type##_seq_write(file, buffer, count, off);\
789         }                                                               \
790         static int name##_##type##_open(struct inode *inode, struct file *file)\
791         {                                                               \
792                 return single_open(file, NULL,                          \
793                                    inode->i_private ? inode->i_private : \
794                                    PDE_DATA(inode));                    \
795         }                                                               \
796         static const struct file_operations name##_##type##_fops = {    \
797                 .open    = name##_##type##_open,                        \
798                 .write   = name##_##type##_write,                       \
799                 .release = lprocfs_single_release,                      \
800         };
801
802 struct lustre_attr {
803         struct attribute attr;
804         ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
805                         char *buf);
806         ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
807                          const char *buf, size_t len);
808 };
809
810 #define LUSTRE_ATTR(name, mode, show, store) \
811 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
812
813 #define LUSTRE_WO_ATTR(name) LUSTRE_ATTR(name, 0200, NULL, name##_store)
814 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
815 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
816
817 ssize_t lustre_attr_show(struct kobject *kobj, struct attribute *attr,
818                          char *buf);
819 ssize_t lustre_attr_store(struct kobject *kobj, struct attribute *attr,
820                           const char *buf, size_t len);
821
822 extern const struct sysfs_ops lustre_sysfs_ops;
823
824 /* lproc_ptlrpc.c */
825 struct ptlrpc_request;
826 extern void target_print_req(void *seq_file, struct ptlrpc_request *req);
827
828 #ifdef HAVE_SERVER_SUPPORT
829 /* lprocfs_jobstats.c */
830 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid,
831                           int event, long amount);
832 void lprocfs_job_stats_fini(struct obd_device *obd);
833 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
834                            cntr_init_callback fn);
835 int lprocfs_job_interval_seq_show(struct seq_file *m, void *data);
836 ssize_t
837 lprocfs_job_interval_seq_write(struct file *file, const char __user *buffer,
838                                 size_t count, loff_t *off);
839 /* lproc_status.c */
840 int lprocfs_recovery_time_soft_seq_show(struct seq_file *m, void *data);
841 ssize_t lprocfs_recovery_time_soft_seq_write(struct file *file,
842                                                 const char __user *buffer,
843                                                 size_t count, loff_t *off);
844 int lprocfs_recovery_time_hard_seq_show(struct seq_file *m, void *data);
845 ssize_t
846 lprocfs_recovery_time_hard_seq_write(struct file *file,
847                                      const char __user *buffer,
848                                      size_t count, loff_t *off);
849 int lprocfs_target_instance_seq_show(struct seq_file *m, void *data);
850 #endif
851 int lprocfs_obd_max_pages_per_rpc_seq_show(struct seq_file *m, void *data);
852 ssize_t lprocfs_obd_max_pages_per_rpc_seq_write(struct file *file,
853                                                 const char __user *buffer,
854                                                 size_t count, loff_t *off);
855 int lprocfs_obd_short_io_bytes_seq_show(struct seq_file *m, void *data);
856 ssize_t lprocfs_obd_short_io_bytes_seq_write(struct file *file,
857                                              const char __user *buffer,
858                                              size_t count, loff_t *off);
859 ssize_t short_io_bytes_show(struct kobject *kobj, struct attribute *attr,
860                             char *buf);
861 ssize_t short_io_bytes_store(struct kobject *kobj, struct attribute *attr,
862                              const char *buffer, size_t count);
863
864 struct root_squash_info;
865 int lprocfs_wr_root_squash(const char __user *buffer, unsigned long count,
866                            struct root_squash_info *squash, char *name);
867 int lprocfs_wr_nosquash_nids(const char __user *buffer, unsigned long count,
868                              struct root_squash_info *squash, char *name);
869
870 #else /* !CONFIG_PROC_FS */
871
872 #define proc_lustre_root NULL
873
874 static inline void lprocfs_counter_add(struct lprocfs_stats *stats,
875                                        int index, long amount)
876 { return; }
877 static inline void lprocfs_counter_incr(struct lprocfs_stats *stats,
878                                         int index)
879 { return; }
880 static inline void lprocfs_counter_sub(struct lprocfs_stats *stats,
881                                        int index, long amount)
882 { return; }
883 static inline void lprocfs_counter_decr(struct lprocfs_stats *stats,
884                                         int index)
885 { return; }
886 static inline void lprocfs_counter_init(struct lprocfs_stats *stats,
887                                         int index, unsigned conf,
888                                         const char *name, const char *units)
889 { return; }
890
891 static inline __u64 lc_read_helper(struct lprocfs_counter *lc,
892                                    enum lprocfs_fields_flags field)
893 { return 0; }
894
895 /* NB: we return !NULL to satisfy error checker */
896 static inline struct lprocfs_stats *
897 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags)
898 { return (struct lprocfs_stats *)1; }
899 static inline void lprocfs_clear_stats(struct lprocfs_stats *stats)
900 { return; }
901 static inline void lprocfs_free_stats(struct lprocfs_stats **stats)
902 { return; }
903 static inline int lprocfs_register_stats(struct proc_dir_entry *root,
904                                          const char *name,
905                                          struct lprocfs_stats *stats)
906 { return 0; }
907 static inline void lprocfs_init_ops_stats(int num_private_stats,
908                                           struct lprocfs_stats *stats)
909 { return; }
910 static inline void lprocfs_init_mps_stats(int num_private_stats,
911                                           struct lprocfs_stats *stats)
912 { return; }
913 static inline void lprocfs_init_ldlm_stats(struct lprocfs_stats *ldlm_stats)
914 { return; }
915 static inline int lprocfs_alloc_obd_stats(struct obd_device *obddev,
916                                           unsigned int num_private_stats)
917 { return 0; }
918 static inline int lprocfs_alloc_md_stats(struct obd_device *obddev,
919                                          unsigned int num_private_stats)
920 { return 0; }
921 static inline void lprocfs_free_obd_stats(struct obd_device *obddev)
922 { return; }
923 static inline void lprocfs_free_md_stats(struct obd_device *obddev)
924 { return; }
925
926 struct obd_export;
927 static inline int lprocfs_add_clear_entry(struct obd_export *exp)
928 { return 0; }
929 static inline void lprocfs_free_per_client_stats(struct obd_device *obd)
930 { return; }
931 #ifdef HAVE_SERVER_SUPPORT
932 static inline
933 ssize_t lprocfs_nid_stats_seq_write(struct file *file,
934                                     const char __user *buffer,
935                                     size_t count, loff_t *off)
936 {return 0;}
937 static inline
938 int lprocfs_nid_stats_clear_seq_show(struct seq_file *m, void *data)
939 {return 0;}
940 static inline int lprocfs_exp_setup(struct obd_export *exp,lnet_nid_t *peer_nid)
941 { return 0; }
942 #endif
943 static inline int lprocfs_exp_cleanup(struct obd_export *exp)
944 { return 0; }
945 static inline struct proc_dir_entry *
946 lprocfs_add_simple(struct proc_dir_entry *root, char *name,
947                    void *data, const struct file_operations *fops)
948 {return 0; }
949 static inline struct proc_dir_entry *
950 lprocfs_add_symlink(const char *name, struct proc_dir_entry *parent,
951                     const char *format, ...)
952 {return NULL; }
953 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
954                                    struct lprocfs_vars *var, void *data)
955 { return 0; }
956 static inline struct proc_dir_entry *
957 lprocfs_register(const char *name, struct proc_dir_entry *parent,
958                  struct lprocfs_vars *list, void *data)
959 { return NULL; }
960 static inline void lprocfs_remove(struct proc_dir_entry **root)
961 { return; }
962 static inline void lprocfs_remove_proc_entry(const char *name,
963                                              struct proc_dir_entry *parent)
964 { return; }
965 static inline int lprocfs_obd_setup(struct obd_device *dev, bool uuid_only)
966 { return 0; }
967 static inline int lprocfs_obd_cleanup(struct obd_device *dev)
968 { return 0; }
969 static inline int lprocfs_uuid_seq_show(struct seq_file *m, void *data)
970 { return 0; }
971 static inline int lprocfs_name_seq_show(struct seq_file *m, void *data)
972 { return 0; }
973 static inline int lprocfs_server_seq_show(struct seq_file *m, void *data)
974 { return 0; }
975 static inline int lprocfs_conn_uuid_seq_show(struct seq_file *m, void *data)
976 { return 0; }
977 static inline int lprocfs_import_seq_show(struct seq_file *m, void *data)
978 { return 0; }
979 static inline int lprocfs_state_seq_show(struct seq_file *m, void *data)
980 { return 0; }
981 static inline int lprocfs_connect_flags_seq_show(struct seq_file *m, void *data)
982 { return 0; }
983 #ifdef HAVE_SERVER_SUPPORT
984 static inline int lprocfs_num_exports_seq_show(struct seq_file *m, void *data)
985 { return 0; }
986 #endif
987 struct adaptive_timeout;
988 static inline int lprocfs_at_hist_helper(struct seq_file *m,
989                                          struct adaptive_timeout *at)
990 { return 0; }
991 static inline int lprocfs_timeouts_seq_show(struct seq_file *m, void *data)
992 { return 0; }
993 static inline ssize_t
994 lprocfs_timeouts_seq_write(struct file *file, const char __user *buffer,
995                            size_t count, loff_t *off)
996 { return 0; }
997 #ifdef HAVE_SERVER_SUPPORT
998 static inline ssize_t
999 lprocfs_evict_client_seq_write(struct file *file, const char __user *buffer,
1000                                size_t count, loff_t *off)
1001 { return 0; }
1002 #endif
1003 static inline ssize_t
1004 lprocfs_ping_seq_write(struct file *file, const char __user *buffer,
1005                        size_t count, loff_t *off)
1006 { return 0; }
1007 static inline ssize_t
1008 lprocfs_import_seq_write(struct file *file, const char __user *buffer,
1009                          size_t count, loff_t *off)
1010 { return 0; }
1011 static inline int
1012 lprocfs_pinger_recov_seq_show(struct seq_file *m, void *data)
1013 { return 0; }
1014 static inline ssize_t
1015 lprocfs_pinger_recov_seq_write(struct file *file, const char __user *buffer,
1016                                size_t count, loff_t *off)
1017 { return 0; }
1018
1019 /* Statfs helpers */
1020 static inline
1021 int lprocfs_blksize_seq_show(struct seq_file *m, void *data)
1022 { return 0; }
1023 static inline
1024 int lprocfs_kbytestotal_seq_show(struct seq_file *m, void *data)
1025 { return 0; }
1026 static inline
1027 int lprocfs_kbytesfree_seq_show(struct seq_file *m, void *data)
1028 { return 0; }
1029 static inline
1030 int lprocfs_kbytesavail_seq_show(struct seq_file *m, void *data)
1031 { return 0; }
1032 static inline
1033 int lprocfs_filestotal_seq_show(struct seq_file *m, void *data)
1034 { return 0; }
1035 static inline
1036 int lprocfs_filesfree_seq_show(struct seq_file *m, void *data)
1037 { return 0; }
1038 static inline
1039 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value)
1040 { return; }
1041 static inline
1042 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value)
1043 { return; }
1044 static inline
1045 void lprocfs_oh_clear(struct obd_histogram *oh)
1046 { return; }
1047 static inline
1048 unsigned long lprocfs_oh_sum(struct obd_histogram *oh)
1049 { return 0; }
1050 static inline
1051 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
1052                            struct lprocfs_counter *cnt)
1053 { return; }
1054 static inline
1055 u64 lprocfs_stats_collector(struct lprocfs_stats *stats, int idx,
1056                             enum lprocfs_fields_flags field)
1057 { return (__u64)0; }
1058
1059 #define LPROC_SEQ_FOPS_RO(name)
1060 #define LPROC_SEQ_FOPS(name)
1061 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)
1062 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)
1063 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)
1064
1065 /* lprocfs_jobstats.c */
1066 static inline
1067 int lprocfs_job_stats_log(struct obd_device *obd, char *jobid, int event,
1068                           long amount)
1069 { return 0; }
1070 static inline
1071 void lprocfs_job_stats_fini(struct obd_device *obd)
1072 { return; }
1073 static inline
1074 int lprocfs_job_stats_init(struct obd_device *obd, int cntr_num,
1075                            cntr_init_callback fn)
1076 { return 0; }
1077
1078
1079 /* lproc_ptlrpc.c */
1080 #define target_print_req NULL
1081
1082 #endif /* CONFIG_PROC_FS */
1083
1084 #endif /* LPROCFS_STATUS_H */