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