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