x86/microcode/intel: Fix initrd loading with CONFIG_RANDOMIZE_MEMORY=y
[cascardo/linux.git] / drivers / staging / lustre / 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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/include/lprocfs_status.h
37  *
38  * Top level header file for LProc SNMP
39  *
40  * Author: Hariharan Thantry thantry@users.sourceforge.net
41  */
42 #ifndef _LPROCFS_SNMP_H
43 #define _LPROCFS_SNMP_H
44
45 #include <linux/debugfs.h>
46 #include <linux/seq_file.h>
47 #include <linux/spinlock.h>
48 #include <linux/types.h>
49
50 #include "lustre/lustre_idl.h"
51
52 struct lprocfs_vars {
53         const char              *name;
54         struct file_operations  *fops;
55         void                    *data;
56         /**
57          * sysfs file mode.
58          */
59         umode_t                 proc_mode;
60 };
61
62 struct lprocfs_static_vars {
63         struct lprocfs_vars *obd_vars;
64         struct attribute_group *sysfs_vars;
65 };
66
67 /* if we find more consumers this could be generalized */
68 #define OBD_HIST_MAX 32
69 struct obd_histogram {
70         spinlock_t      oh_lock;
71         unsigned long   oh_buckets[OBD_HIST_MAX];
72 };
73
74 enum {
75         BRW_R_PAGES = 0,
76         BRW_W_PAGES,
77         BRW_R_RPC_HIST,
78         BRW_W_RPC_HIST,
79         BRW_R_IO_TIME,
80         BRW_W_IO_TIME,
81         BRW_R_DISCONT_PAGES,
82         BRW_W_DISCONT_PAGES,
83         BRW_R_DISCONT_BLOCKS,
84         BRW_W_DISCONT_BLOCKS,
85         BRW_R_DISK_IOSIZE,
86         BRW_W_DISK_IOSIZE,
87         BRW_R_DIO_FRAGS,
88         BRW_W_DIO_FRAGS,
89         BRW_LAST,
90 };
91
92 struct brw_stats {
93         struct obd_histogram hist[BRW_LAST];
94 };
95
96 enum {
97         RENAME_SAMEDIR_SIZE = 0,
98         RENAME_CROSSDIR_SRC_SIZE,
99         RENAME_CROSSDIR_TGT_SIZE,
100         RENAME_LAST,
101 };
102
103 struct rename_stats {
104         struct obd_histogram hist[RENAME_LAST];
105 };
106
107 /* An lprocfs counter can be configured using the enum bit masks below.
108  *
109  * LPROCFS_CNTR_EXTERNALLOCK indicates that an external lock already
110  * protects this counter from concurrent updates. If not specified,
111  * lprocfs an internal per-counter lock variable. External locks are
112  * not used to protect counter increments, but are used to protect
113  * counter readout and resets.
114  *
115  * LPROCFS_CNTR_AVGMINMAX indicates a multi-valued counter samples,
116  * (i.e. counter can be incremented by more than "1"). When specified,
117  * the counter maintains min, max and sum in addition to a simple
118  * invocation count. This allows averages to be be computed.
119  * If not specified, the counter is an increment-by-1 counter.
120  * min, max, sum, etc. are not maintained.
121  *
122  * LPROCFS_CNTR_STDDEV indicates that the counter should track sum of
123  * squares (for multi-valued counter samples only). This allows
124  * external computation of standard deviation, but involves a 64-bit
125  * multiply per counter increment.
126  */
127
128 enum {
129         LPROCFS_CNTR_EXTERNALLOCK = 0x0001,
130         LPROCFS_CNTR_AVGMINMAX    = 0x0002,
131         LPROCFS_CNTR_STDDEV       = 0x0004,
132
133         /* counter data type */
134         LPROCFS_TYPE_REGS        = 0x0100,
135         LPROCFS_TYPE_BYTES      = 0x0200,
136         LPROCFS_TYPE_PAGES      = 0x0400,
137         LPROCFS_TYPE_CYCLE      = 0x0800,
138 };
139
140 #define LC_MIN_INIT ((~(__u64)0) >> 1)
141
142 struct lprocfs_counter_header {
143         unsigned int            lc_config;
144         const char              *lc_name;   /* must be static */
145         const char              *lc_units;  /* must be static */
146 };
147
148 struct lprocfs_counter {
149         __s64   lc_count;
150         __s64   lc_min;
151         __s64   lc_max;
152         __s64   lc_sumsquare;
153         /*
154          * Every counter has lc_array_sum[0], while lc_array_sum[1] is only
155          * for irq context counter, i.e. stats with
156          * LPROCFS_STATS_FLAG_IRQ_SAFE flag, its counter need
157          * lc_array_sum[1]
158          */
159         __s64   lc_array_sum[1];
160 };
161
162 #define lc_sum          lc_array_sum[0]
163 #define lc_sum_irq      lc_array_sum[1]
164
165 struct lprocfs_percpu {
166 #ifndef __GNUC__
167         __s64                   pad;
168 #endif
169         struct lprocfs_counter lp_cntr[0];
170 };
171
172 #define LPROCFS_GET_NUM_CPU 0x0001
173 #define LPROCFS_GET_SMP_ID  0x0002
174
175 enum lprocfs_stats_flags {
176         LPROCFS_STATS_FLAG_NONE     = 0x0000, /* per cpu counter */
177         LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
178                                                * area and need locking
179                                                */
180         LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
181 };
182
183 enum lprocfs_fields_flags {
184         LPROCFS_FIELDS_FLAGS_CONFIG     = 0x0001,
185         LPROCFS_FIELDS_FLAGS_SUM        = 0x0002,
186         LPROCFS_FIELDS_FLAGS_MIN        = 0x0003,
187         LPROCFS_FIELDS_FLAGS_MAX        = 0x0004,
188         LPROCFS_FIELDS_FLAGS_AVG        = 0x0005,
189         LPROCFS_FIELDS_FLAGS_SUMSQUARE  = 0x0006,
190         LPROCFS_FIELDS_FLAGS_COUNT      = 0x0007,
191 };
192
193 struct lprocfs_stats {
194         /* # of counters */
195         unsigned short                  ls_num;
196         /* 1 + the biggest cpu # whose ls_percpu slot has been allocated */
197         unsigned short                  ls_biggest_alloc_num;
198         enum lprocfs_stats_flags        ls_flags;
199         /* Lock used when there are no percpu stats areas; For percpu stats,
200          * it is used to protect ls_biggest_alloc_num change
201          */
202         spinlock_t                      ls_lock;
203
204         /* has ls_num of counter headers */
205         struct lprocfs_counter_header   *ls_cnt_header;
206         struct lprocfs_percpu           *ls_percpu[0];
207 };
208
209 #define OPC_RANGE(seg) (seg ## _LAST_OPC - seg ## _FIRST_OPC)
210
211 /* Pack all opcodes down into a single monotonically increasing index */
212 static inline int opcode_offset(__u32 opc)
213 {
214         if (opc < OST_LAST_OPC) {
215                  /* OST opcode */
216                 return (opc - OST_FIRST_OPC);
217         } else if (opc < MDS_LAST_OPC) {
218                 /* MDS opcode */
219                 return (opc - MDS_FIRST_OPC +
220                         OPC_RANGE(OST));
221         } else if (opc < LDLM_LAST_OPC) {
222                 /* LDLM Opcode */
223                 return (opc - LDLM_FIRST_OPC +
224                         OPC_RANGE(MDS) +
225                         OPC_RANGE(OST));
226         } else if (opc < MGS_LAST_OPC) {
227                 /* MGS Opcode */
228                 return (opc - MGS_FIRST_OPC +
229                         OPC_RANGE(LDLM) +
230                         OPC_RANGE(MDS) +
231                         OPC_RANGE(OST));
232         } else if (opc < OBD_LAST_OPC) {
233                 /* OBD Ping */
234                 return (opc - OBD_FIRST_OPC +
235                         OPC_RANGE(MGS) +
236                         OPC_RANGE(LDLM) +
237                         OPC_RANGE(MDS) +
238                         OPC_RANGE(OST));
239         } else if (opc < LLOG_LAST_OPC) {
240                 /* LLOG Opcode */
241                 return (opc - LLOG_FIRST_OPC +
242                         OPC_RANGE(OBD) +
243                         OPC_RANGE(MGS) +
244                         OPC_RANGE(LDLM) +
245                         OPC_RANGE(MDS) +
246                         OPC_RANGE(OST));
247         } else if (opc < QUOTA_LAST_OPC) {
248                 /* LQUOTA Opcode */
249                 return (opc - QUOTA_FIRST_OPC +
250                         OPC_RANGE(LLOG) +
251                         OPC_RANGE(OBD) +
252                         OPC_RANGE(MGS) +
253                         OPC_RANGE(LDLM) +
254                         OPC_RANGE(MDS) +
255                         OPC_RANGE(OST));
256         } else if (opc < SEQ_LAST_OPC) {
257                 /* SEQ opcode */
258                 return (opc - SEQ_FIRST_OPC +
259                         OPC_RANGE(QUOTA) +
260                         OPC_RANGE(LLOG) +
261                         OPC_RANGE(OBD) +
262                         OPC_RANGE(MGS) +
263                         OPC_RANGE(LDLM) +
264                         OPC_RANGE(MDS) +
265                         OPC_RANGE(OST));
266         } else if (opc < SEC_LAST_OPC) {
267                 /* SEC opcode */
268                 return (opc - SEC_FIRST_OPC +
269                         OPC_RANGE(SEQ) +
270                         OPC_RANGE(QUOTA) +
271                         OPC_RANGE(LLOG) +
272                         OPC_RANGE(OBD) +
273                         OPC_RANGE(MGS) +
274                         OPC_RANGE(LDLM) +
275                         OPC_RANGE(MDS) +
276                         OPC_RANGE(OST));
277         } else if (opc < FLD_LAST_OPC) {
278                 /* FLD opcode */
279                 return (opc - FLD_FIRST_OPC +
280                         OPC_RANGE(SEC) +
281                         OPC_RANGE(SEQ) +
282                         OPC_RANGE(QUOTA) +
283                         OPC_RANGE(LLOG) +
284                         OPC_RANGE(OBD) +
285                         OPC_RANGE(MGS) +
286                         OPC_RANGE(LDLM) +
287                         OPC_RANGE(MDS) +
288                         OPC_RANGE(OST));
289         } else {
290                 /* Unknown Opcode */
291                 return -1;
292         }
293 }
294
295 #define LUSTRE_MAX_OPCODES (OPC_RANGE(OST)  + \
296                             OPC_RANGE(MDS)  + \
297                             OPC_RANGE(LDLM) + \
298                             OPC_RANGE(MGS)  + \
299                             OPC_RANGE(OBD)  + \
300                             OPC_RANGE(LLOG) + \
301                             OPC_RANGE(SEC)  + \
302                             OPC_RANGE(SEQ)  + \
303                             OPC_RANGE(SEC)  + \
304                             OPC_RANGE(FLD))
305
306 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR)  + \
307                             OPC_RANGE(EXTRA))
308
309 enum {
310         PTLRPC_REQWAIT_CNTR = 0,
311         PTLRPC_REQQDEPTH_CNTR,
312         PTLRPC_REQACTIVE_CNTR,
313         PTLRPC_TIMEOUT,
314         PTLRPC_REQBUF_AVAIL_CNTR,
315         PTLRPC_LAST_CNTR
316 };
317
318 #define PTLRPC_FIRST_CNTR PTLRPC_REQWAIT_CNTR
319
320 enum {
321         LDLM_GLIMPSE_ENQUEUE = 0,
322         LDLM_PLAIN_ENQUEUE,
323         LDLM_EXTENT_ENQUEUE,
324         LDLM_FLOCK_ENQUEUE,
325         LDLM_IBITS_ENQUEUE,
326         MDS_REINT_SETATTR,
327         MDS_REINT_CREATE,
328         MDS_REINT_LINK,
329         MDS_REINT_UNLINK,
330         MDS_REINT_RENAME,
331         MDS_REINT_OPEN,
332         MDS_REINT_SETXATTR,
333         BRW_READ_BYTES,
334         BRW_WRITE_BYTES,
335         EXTRA_LAST_OPC
336 };
337
338 #define EXTRA_FIRST_OPC LDLM_GLIMPSE_ENQUEUE
339 /* class_obd.c */
340 extern struct dentry *debugfs_lustre_root;
341 extern struct kobject *lustre_kobj;
342
343 struct obd_device;
344 struct obd_histogram;
345
346 /* Days / hours / mins / seconds format */
347 struct dhms {
348         int d, h, m, s;
349 };
350
351 static inline void s2dhms(struct dhms *ts, time64_t secs64)
352 {
353         unsigned int secs;
354
355         ts->d = div_u64_rem(secs64, 86400, &secs);
356         ts->h = secs / 3600;
357         secs = secs % 3600;
358         ts->m = secs / 60;
359         ts->s = secs % 60;
360 }
361
362 #define DHMS_FMT "%dd%dh%02dm%02ds"
363 #define DHMS_VARS(x) (x)->d, (x)->h, (x)->m, (x)->s
364
365 #define JOBSTATS_JOBID_VAR_MAX_LEN      20
366 #define JOBSTATS_DISABLE                "disable"
367 #define JOBSTATS_PROCNAME_UID           "procname_uid"
368 #define JOBSTATS_NODELOCAL              "nodelocal"
369
370 int lprocfs_write_frac_helper(const char __user *buffer,
371                               unsigned long count, int *val, int mult);
372 int lprocfs_read_frac_helper(char *buffer, unsigned long count,
373                              long val, int mult);
374 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid);
375 /*
376  * \return value
377  *      < 0     : on error (only possible for opc as LPROCFS_GET_SMP_ID)
378  */
379 static inline int lprocfs_stats_lock(struct lprocfs_stats *stats, int opc,
380                                      unsigned long *flags)
381 {
382         int             rc = 0;
383
384         switch (opc) {
385         default:
386                 LBUG();
387
388         case LPROCFS_GET_SMP_ID:
389                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
390                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
391                                 spin_lock_irqsave(&stats->ls_lock, *flags);
392                         else
393                                 spin_lock(&stats->ls_lock);
394                         return 0;
395                 } else {
396                         unsigned int cpuid = get_cpu();
397
398                         if (unlikely(!stats->ls_percpu[cpuid])) {
399                                 rc = lprocfs_stats_alloc_one(stats, cpuid);
400                                 if (rc < 0) {
401                                         put_cpu();
402                                         return rc;
403                                 }
404                         }
405                         return cpuid;
406                 }
407
408         case LPROCFS_GET_NUM_CPU:
409                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
410                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
411                                 spin_lock_irqsave(&stats->ls_lock, *flags);
412                         else
413                                 spin_lock(&stats->ls_lock);
414                         return 1;
415                 }
416                 return stats->ls_biggest_alloc_num;
417         }
418 }
419
420 static inline void lprocfs_stats_unlock(struct lprocfs_stats *stats, int opc,
421                                         unsigned long *flags)
422 {
423         switch (opc) {
424         default:
425                 LBUG();
426
427         case LPROCFS_GET_SMP_ID:
428                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
429                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
430                                 spin_unlock_irqrestore(&stats->ls_lock, *flags);
431                         else
432                                 spin_unlock(&stats->ls_lock);
433                 } else {
434                         put_cpu();
435                 }
436                 return;
437
438         case LPROCFS_GET_NUM_CPU:
439                 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
440                         if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
441                                 spin_unlock_irqrestore(&stats->ls_lock, *flags);
442                         else
443                                 spin_unlock(&stats->ls_lock);
444                 }
445                 return;
446         }
447 }
448
449 static inline unsigned int
450 lprocfs_stats_counter_size(struct lprocfs_stats *stats)
451 {
452         unsigned int percpusize;
453
454         percpusize = offsetof(struct lprocfs_percpu, lp_cntr[stats->ls_num]);
455
456         /* irq safe stats need lc_array_sum[1] */
457         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
458                 percpusize += stats->ls_num * sizeof(__s64);
459
460         if ((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0)
461                 percpusize = L1_CACHE_ALIGN(percpusize);
462
463         return percpusize;
464 }
465
466 static inline struct lprocfs_counter *
467 lprocfs_stats_counter_get(struct lprocfs_stats *stats, unsigned int cpuid,
468                           int index)
469 {
470         struct lprocfs_counter *cntr;
471
472         cntr = &stats->ls_percpu[cpuid]->lp_cntr[index];
473
474         if ((stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
475                 cntr = (void *)cntr + index * sizeof(__s64);
476
477         return cntr;
478 }
479
480 /* Two optimized LPROCFS counter increment functions are provided:
481  *     lprocfs_counter_incr(cntr, value) - optimized for by-one counters
482  *     lprocfs_counter_add(cntr) - use for multi-valued counters
483  * Counter data layout allows config flag, counter lock and the
484  * count itself to reside within a single cache line.
485  */
486
487 void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount);
488 void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount);
489
490 #define lprocfs_counter_incr(stats, idx) \
491         lprocfs_counter_add(stats, idx, 1)
492 #define lprocfs_counter_decr(stats, idx) \
493         lprocfs_counter_sub(stats, idx, 1)
494
495 __s64 lprocfs_read_helper(struct lprocfs_counter *lc,
496                           struct lprocfs_counter_header *header,
497                           enum lprocfs_stats_flags flags,
498                           enum lprocfs_fields_flags field);
499 static inline __u64 lprocfs_stats_collector(struct lprocfs_stats *stats,
500                                             int idx,
501                                             enum lprocfs_fields_flags field)
502 {
503         int           i;
504         unsigned int  num_cpu;
505         unsigned long flags     = 0;
506         __u64         ret       = 0;
507
508         LASSERT(stats);
509
510         num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
511         for (i = 0; i < num_cpu; i++) {
512                 if (!stats->ls_percpu[i])
513                         continue;
514                 ret += lprocfs_read_helper(
515                                 lprocfs_stats_counter_get(stats, i, idx),
516                                 &stats->ls_cnt_header[idx], stats->ls_flags,
517                                 field);
518         }
519         lprocfs_stats_unlock(stats, LPROCFS_GET_NUM_CPU, &flags);
520         return ret;
521 }
522
523 extern struct lprocfs_stats *
524 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
525 void lprocfs_clear_stats(struct lprocfs_stats *stats);
526 void lprocfs_free_stats(struct lprocfs_stats **stats);
527 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
528                           unsigned conf, const char *name, const char *units);
529 struct obd_export;
530 int lprocfs_exp_cleanup(struct obd_export *exp);
531 struct dentry *ldebugfs_add_simple(struct dentry *root,
532                                    char *name,
533                                    void *data,
534                                    struct file_operations *fops);
535
536 int ldebugfs_register_stats(struct dentry *parent,
537                             const char *name,
538                             struct lprocfs_stats *stats);
539
540 /* lprocfs_status.c */
541 int ldebugfs_add_vars(struct dentry *parent,
542                       struct lprocfs_vars *var,
543                       void *data);
544
545 struct dentry *ldebugfs_register(const char *name,
546                                  struct dentry *parent,
547                                  struct lprocfs_vars *list,
548                                  void *data);
549
550 void ldebugfs_remove(struct dentry **entryp);
551
552 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list,
553                       struct attribute_group *attrs);
554 int lprocfs_obd_cleanup(struct obd_device *obd);
555
556 int ldebugfs_seq_create(struct dentry *parent,
557                         const char *name,
558                         umode_t mode,
559                         const struct file_operations *seq_fops,
560                         void *data);
561 int ldebugfs_obd_seq_create(struct obd_device *dev,
562                             const char *name,
563                             umode_t mode,
564                             const struct file_operations *seq_fops,
565                             void *data);
566
567 /* Generic callbacks */
568
569 int lprocfs_rd_uint(struct seq_file *m, void *data);
570 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
571                     unsigned long count, void *data);
572 int lprocfs_rd_server_uuid(struct seq_file *m, void *data);
573 int lprocfs_rd_conn_uuid(struct seq_file *m, void *data);
574 int lprocfs_rd_import(struct seq_file *m, void *data);
575 int lprocfs_rd_state(struct seq_file *m, void *data);
576 int lprocfs_rd_connect_flags(struct seq_file *m, void *data);
577
578 struct adaptive_timeout;
579 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at);
580 int lprocfs_rd_timeouts(struct seq_file *m, void *data);
581 int lprocfs_wr_ping(struct file *file, const char __user *buffer,
582                     size_t count, loff_t *off);
583 int lprocfs_wr_import(struct file *file, const char __user *buffer,
584                       size_t count, loff_t *off);
585 int lprocfs_rd_pinger_recov(struct seq_file *m, void *n);
586 int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
587                             size_t count, loff_t *off);
588
589 /* Statfs helpers */
590
591 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
592                          int *val);
593 int lprocfs_write_u64_helper(const char __user *buffer,
594                              unsigned long count, __u64 *val);
595 int lprocfs_write_frac_u64_helper(const char __user *buffer,
596                                   unsigned long count,
597                                   __u64 *val, int mult);
598 char *lprocfs_find_named_value(const char *buffer, const char *name,
599                                size_t *count);
600 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
601 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
602 void lprocfs_oh_clear(struct obd_histogram *oh);
603 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
604
605 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
606                            struct lprocfs_counter *cnt);
607
608 int lprocfs_single_release(struct inode *, struct file *);
609 int lprocfs_seq_release(struct inode *, struct file *);
610
611 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
612  * proc entries; otherwise, you will define name##_seq_write function also for
613  * a read-write proc entry, and then call LPROC_SEQ_SEQ instead. Finally,
614  * call ldebugfs_obd_seq_create(obd, filename, 0444, &name#_fops, data);
615  */
616 #define __LPROC_SEQ_FOPS(name, custom_seq_write)                        \
617 static int name##_single_open(struct inode *inode, struct file *file)   \
618 {                                                                       \
619         return single_open(file, name##_seq_show, inode->i_private);    \
620 }                                                                       \
621 static struct file_operations name##_fops = {                           \
622         .owner   = THIS_MODULE,                                     \
623         .open    = name##_single_open,                               \
624         .read    = seq_read,                                           \
625         .write   = custom_seq_write,                                   \
626         .llseek  = seq_lseek,                                         \
627         .release = lprocfs_single_release,                               \
628 }
629
630 #define LPROC_SEQ_FOPS_RO(name)  __LPROC_SEQ_FOPS(name, NULL)
631 #define LPROC_SEQ_FOPS(name)        __LPROC_SEQ_FOPS(name, name##_seq_write)
632
633 #define LPROC_SEQ_FOPS_RO_TYPE(name, type)                              \
634         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
635         {                                                               \
636                 return lprocfs_rd_##type(m, m->private);                \
637         }                                                               \
638         LPROC_SEQ_FOPS_RO(name##_##type)
639
640 #define LPROC_SEQ_FOPS_RW_TYPE(name, type)                              \
641         static int name##_##type##_seq_show(struct seq_file *m, void *v)\
642         {                                                               \
643                 return lprocfs_rd_##type(m, m->private);                \
644         }                                                               \
645         static ssize_t name##_##type##_seq_write(struct file *file,     \
646                         const char __user *buffer, size_t count,        \
647                                                 loff_t *off)            \
648         {                                                               \
649                 struct seq_file *seq = file->private_data;              \
650                 return lprocfs_wr_##type(file, buffer,                  \
651                                          count, seq->private);          \
652         }                                                               \
653         LPROC_SEQ_FOPS(name##_##type)
654
655 #define LPROC_SEQ_FOPS_WR_ONLY(name, type)                              \
656         static ssize_t name##_##type##_write(struct file *file,         \
657                         const char __user *buffer, size_t count,        \
658                                                 loff_t *off)            \
659         {                                                               \
660                 return lprocfs_wr_##type(file, buffer, count, off);     \
661         }                                                               \
662         static int name##_##type##_open(struct inode *inode, struct file *file) \
663         {                                                               \
664                 return single_open(file, NULL, inode->i_private);       \
665         }                                                               \
666         static struct file_operations name##_##type##_fops = {  \
667                 .open   = name##_##type##_open,                         \
668                 .write  = name##_##type##_write,                        \
669                 .release = lprocfs_single_release,                      \
670         }
671
672 struct lustre_attr {
673         struct attribute attr;
674         ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
675                         char *buf);
676         ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
677                          const char *buf, size_t len);
678 };
679
680 #define LUSTRE_ATTR(name, mode, show, store) \
681 static struct lustre_attr lustre_attr_##name = __ATTR(name, mode, show, store)
682
683 #define LUSTRE_RO_ATTR(name) LUSTRE_ATTR(name, 0444, name##_show, NULL)
684 #define LUSTRE_RW_ATTR(name) LUSTRE_ATTR(name, 0644, name##_show, name##_store)
685
686 extern const struct sysfs_ops lustre_sysfs_ops;
687
688 /* all quota proc functions */
689 int lprocfs_quota_rd_bunit(char *page, char **start,
690                            loff_t off, int count,
691                            int *eof, void *data);
692 int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
693                            unsigned long count, void *data);
694 int lprocfs_quota_rd_btune(char *page, char **start,
695                            loff_t off, int count,
696                            int *eof, void *data);
697 int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
698                            unsigned long count, void *data);
699 int lprocfs_quota_rd_iunit(char *page, char **start,
700                            loff_t off, int count,
701                            int *eof, void *data);
702 int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
703                            unsigned long count, void *data);
704 int lprocfs_quota_rd_itune(char *page, char **start,
705                            loff_t off, int count,
706                            int *eof, void *data);
707 int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
708                            unsigned long count, void *data);
709 int lprocfs_quota_rd_type(char *page, char **start, loff_t off, int count,
710                           int *eof, void *data);
711 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
712                           unsigned long count, void *data);
713 int lprocfs_quota_rd_switch_seconds(char *page, char **start, loff_t off,
714                                     int count, int *eof, void *data);
715 int lprocfs_quota_wr_switch_seconds(struct file *file,
716                                     const char *buffer,
717                                     unsigned long count, void *data);
718 int lprocfs_quota_rd_sync_blk(char *page, char **start, loff_t off,
719                               int count, int *eof, void *data);
720 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
721                               unsigned long count, void *data);
722 int lprocfs_quota_rd_switch_qs(char *page, char **start, loff_t off,
723                                int count, int *eof, void *data);
724 int lprocfs_quota_wr_switch_qs(struct file *file,
725                                const char *buffer, unsigned long count,
726                                void *data);
727 int lprocfs_quota_rd_boundary_factor(char *page, char **start, loff_t off,
728                                      int count, int *eof, void *data);
729 int lprocfs_quota_wr_boundary_factor(struct file *file,
730                                      const char *buffer, unsigned long count,
731                                      void *data);
732 int lprocfs_quota_rd_least_bunit(char *page, char **start, loff_t off,
733                                  int count, int *eof, void *data);
734 int lprocfs_quota_wr_least_bunit(struct file *file,
735                                  const char *buffer, unsigned long count,
736                                  void *data);
737 int lprocfs_quota_rd_least_iunit(char *page, char **start, loff_t off,
738                                  int count, int *eof, void *data);
739 int lprocfs_quota_wr_least_iunit(struct file *file,
740                                  const char *buffer, unsigned long count,
741                                  void *data);
742 int lprocfs_quota_rd_qs_factor(char *page, char **start, loff_t off,
743                                int count, int *eof, void *data);
744 int lprocfs_quota_wr_qs_factor(struct file *file,
745                                const char *buffer, unsigned long count,
746                                void *data);
747 #endif /* LPROCFS_SNMP_H */