]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/lustre/lustre/include/lprocfs_status.h
d68e60e7fef73250993ead48bec64201e38b4075
[mirror_ubuntu-artful-kernel.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.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, 2015, 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 SNMP
35 *
36 * Author: Hariharan Thantry thantry@users.sourceforge.net
37 */
38 #ifndef _LPROCFS_SNMP_H
39 #define _LPROCFS_SNMP_H
40
41 #include <linux/debugfs.h>
42 #include <linux/seq_file.h>
43 #include <linux/spinlock.h>
44 #include <linux/types.h>
45
46 #include "lustre/lustre_idl.h"
47
48 struct lprocfs_vars {
49 const char *name;
50 struct file_operations *fops;
51 void *data;
52 /**
53 * sysfs file mode.
54 */
55 umode_t proc_mode;
56 };
57
58 struct lprocfs_static_vars {
59 struct lprocfs_vars *obd_vars;
60 struct attribute_group *sysfs_vars;
61 };
62
63 /* if we find more consumers this could be generalized */
64 #define OBD_HIST_MAX 32
65 struct obd_histogram {
66 spinlock_t oh_lock;
67 unsigned long oh_buckets[OBD_HIST_MAX];
68 };
69
70 enum {
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
88 struct brw_stats {
89 struct obd_histogram hist[BRW_LAST];
90 };
91
92 enum {
93 RENAME_SAMEDIR_SIZE = 0,
94 RENAME_CROSSDIR_SRC_SIZE,
95 RENAME_CROSSDIR_TGT_SIZE,
96 RENAME_LAST,
97 };
98
99 struct 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
124 enum {
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
138 struct 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
144 struct 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 };
157
158 #define lc_sum lc_array_sum[0]
159 #define lc_sum_irq lc_array_sum[1]
160
161 struct 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
171 enum lprocfs_stats_flags {
172 LPROCFS_STATS_FLAG_NONE = 0x0000, /* per cpu counter */
173 LPROCFS_STATS_FLAG_NOPERCPU = 0x0001, /* stats have no percpu
174 * area and need locking
175 */
176 LPROCFS_STATS_FLAG_IRQ_SAFE = 0x0002, /* alloc need irq safe */
177 };
178
179 enum 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
189 struct 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,
196 * it is used to protect ls_biggest_alloc_num change
197 */
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 */
208 static inline int opcode_offset(__u32 opc)
209 {
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 */
275 return (opc - FLD_FIRST_OPC +
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));
285 } else {
286 /* Unknown Opcode */
287 return -1;
288 }
289 }
290
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) + \
300 OPC_RANGE(FLD))
301
302 #define EXTRA_MAX_OPCODES ((PTLRPC_LAST_CNTR - PTLRPC_FIRST_CNTR) + \
303 OPC_RANGE(EXTRA))
304
305 enum {
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
316 enum {
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 */
336 extern struct dentry *debugfs_lustre_root;
337 extern struct kobject *lustre_kobj;
338
339 struct obd_device;
340 struct obd_histogram;
341
342 /* Days / hours / mins / seconds format */
343 struct dhms {
344 int d, h, m, s;
345 };
346
347 static inline void s2dhms(struct dhms *ts, time64_t secs64)
348 {
349 unsigned int secs;
350
351 ts->d = div_u64_rem(secs64, 86400, &secs);
352 ts->h = secs / 3600;
353 secs = secs % 3600;
354 ts->m = secs / 60;
355 ts->s = secs % 60;
356 }
357
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"
364 #define JOBSTATS_NODELOCAL "nodelocal"
365
366 int lprocfs_write_frac_helper(const char __user *buffer,
367 unsigned long count, int *val, int mult);
368 int lprocfs_read_frac_helper(char *buffer, unsigned long count,
369 long val, int mult);
370 int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid);
371 /*
372 * \return value
373 * < 0 : on error (only possible for opc as LPROCFS_GET_SMP_ID)
374 */
375 static 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
394 if (unlikely(!stats->ls_percpu[cpuid])) {
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;
411 }
412 return stats->ls_biggest_alloc_num;
413 }
414 }
415
416 static 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) {
425 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
426 spin_unlock_irqrestore(&stats->ls_lock, *flags);
427 else
428 spin_unlock(&stats->ls_lock);
429 } else {
430 put_cpu();
431 }
432 return;
433
434 case LPROCFS_GET_NUM_CPU:
435 if (stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) {
436 if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
437 spin_unlock_irqrestore(&stats->ls_lock, *flags);
438 else
439 spin_unlock(&stats->ls_lock);
440 }
441 return;
442 }
443 }
444
445 static inline unsigned int
446 lprocfs_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
462 static inline struct lprocfs_counter *
463 lprocfs_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
483 void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount);
484 void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount);
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
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);
495 static 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
504 LASSERT(stats);
505
506 num_cpu = lprocfs_stats_lock(stats, LPROCFS_GET_NUM_CPU, &flags);
507 for (i = 0; i < num_cpu; i++) {
508 if (!stats->ls_percpu[i])
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
519 extern struct lprocfs_stats *
520 lprocfs_alloc_stats(unsigned int num, enum lprocfs_stats_flags flags);
521 void lprocfs_clear_stats(struct lprocfs_stats *stats);
522 void lprocfs_free_stats(struct lprocfs_stats **stats);
523 void lprocfs_counter_init(struct lprocfs_stats *stats, int index,
524 unsigned conf, const char *name, const char *units);
525 struct obd_export;
526 int lprocfs_exp_cleanup(struct obd_export *exp);
527 struct dentry *ldebugfs_add_simple(struct dentry *root,
528 char *name,
529 void *data,
530 struct file_operations *fops);
531
532 int ldebugfs_register_stats(struct dentry *parent,
533 const char *name,
534 struct lprocfs_stats *stats);
535
536 /* lprocfs_status.c */
537 int ldebugfs_add_vars(struct dentry *parent,
538 struct lprocfs_vars *var,
539 void *data);
540
541 struct dentry *ldebugfs_register(const char *name,
542 struct dentry *parent,
543 struct lprocfs_vars *list,
544 void *data);
545
546 void ldebugfs_remove(struct dentry **entryp);
547
548 int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list,
549 struct attribute_group *attrs);
550 int lprocfs_obd_cleanup(struct obd_device *obd);
551
552 int ldebugfs_seq_create(struct dentry *parent,
553 const char *name,
554 umode_t mode,
555 const struct file_operations *seq_fops,
556 void *data);
557 int 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);
562
563 /* Generic callbacks */
564
565 int lprocfs_rd_uint(struct seq_file *m, void *data);
566 int lprocfs_wr_uint(struct file *file, const char __user *buffer,
567 unsigned long count, void *data);
568 int lprocfs_rd_server_uuid(struct seq_file *m, void *data);
569 int lprocfs_rd_conn_uuid(struct seq_file *m, void *data);
570 int lprocfs_rd_import(struct seq_file *m, void *data);
571 int lprocfs_rd_state(struct seq_file *m, void *data);
572 int lprocfs_rd_connect_flags(struct seq_file *m, void *data);
573
574 struct adaptive_timeout;
575 int lprocfs_at_hist_helper(struct seq_file *m, struct adaptive_timeout *at);
576 int lprocfs_rd_timeouts(struct seq_file *m, void *data);
577 int lprocfs_wr_ping(struct file *file, const char __user *buffer,
578 size_t count, loff_t *off);
579 int lprocfs_wr_import(struct file *file, const char __user *buffer,
580 size_t count, loff_t *off);
581 int lprocfs_rd_pinger_recov(struct seq_file *m, void *n);
582 int lprocfs_wr_pinger_recov(struct file *file, const char __user *buffer,
583 size_t count, loff_t *off);
584
585 /* Statfs helpers */
586
587 int lprocfs_write_helper(const char __user *buffer, unsigned long count,
588 int *val);
589 int lprocfs_write_u64_helper(const char __user *buffer,
590 unsigned long count, __u64 *val);
591 int lprocfs_write_frac_u64_helper(const char __user *buffer,
592 unsigned long count,
593 __u64 *val, int mult);
594 char *lprocfs_find_named_value(const char *buffer, const char *name,
595 size_t *count);
596 void lprocfs_oh_tally(struct obd_histogram *oh, unsigned int value);
597 void lprocfs_oh_tally_log2(struct obd_histogram *oh, unsigned int value);
598 void lprocfs_oh_clear(struct obd_histogram *oh);
599 unsigned long lprocfs_oh_sum(struct obd_histogram *oh);
600
601 void lprocfs_stats_collect(struct lprocfs_stats *stats, int idx,
602 struct lprocfs_counter *cnt);
603
604 int lprocfs_single_release(struct inode *, struct file *);
605 int lprocfs_seq_release(struct inode *, struct file *);
606
607 /* write the name##_seq_show function, call LPROC_SEQ_FOPS_RO for read-only
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 */
612 #define __LPROC_SEQ_FOPS(name, custom_seq_write) \
613 static int name##_single_open(struct inode *inode, struct file *file) \
614 { \
615 return single_open(file, name##_seq_show, inode->i_private); \
616 } \
617 static struct file_operations name##_fops = { \
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
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, \
642 const char __user *buffer, size_t count, \
643 loff_t *off) \
644 { \
645 struct seq_file *seq = file->private_data; \
646 return lprocfs_wr_##type(file, buffer, \
647 count, seq->private); \
648 } \
649 LPROC_SEQ_FOPS(name##_##type)
650
651 #define LPROC_SEQ_FOPS_WR_ONLY(name, type) \
652 static ssize_t name##_##type##_write(struct file *file, \
653 const char __user *buffer, size_t count, \
654 loff_t *off) \
655 { \
656 return lprocfs_wr_##type(file, buffer, count, off); \
657 } \
658 static int name##_##type##_open(struct inode *inode, struct file *file) \
659 { \
660 return single_open(file, NULL, inode->i_private); \
661 } \
662 static struct file_operations name##_##type##_fops = { \
663 .open = name##_##type##_open, \
664 .write = name##_##type##_write, \
665 .release = lprocfs_single_release, \
666 }
667
668 struct 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) \
677 static 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
682 extern const struct sysfs_ops lustre_sysfs_ops;
683
684 /* all quota proc functions */
685 int lprocfs_quota_rd_bunit(char *page, char **start,
686 loff_t off, int count,
687 int *eof, void *data);
688 int lprocfs_quota_wr_bunit(struct file *file, const char *buffer,
689 unsigned long count, void *data);
690 int lprocfs_quota_rd_btune(char *page, char **start,
691 loff_t off, int count,
692 int *eof, void *data);
693 int lprocfs_quota_wr_btune(struct file *file, const char *buffer,
694 unsigned long count, void *data);
695 int lprocfs_quota_rd_iunit(char *page, char **start,
696 loff_t off, int count,
697 int *eof, void *data);
698 int lprocfs_quota_wr_iunit(struct file *file, const char *buffer,
699 unsigned long count, void *data);
700 int lprocfs_quota_rd_itune(char *page, char **start,
701 loff_t off, int count,
702 int *eof, void *data);
703 int lprocfs_quota_wr_itune(struct file *file, const char *buffer,
704 unsigned long count, void *data);
705 int lprocfs_quota_rd_type(char *page, char **start, loff_t off, int count,
706 int *eof, void *data);
707 int lprocfs_quota_wr_type(struct file *file, const char *buffer,
708 unsigned long count, void *data);
709 int lprocfs_quota_rd_switch_seconds(char *page, char **start, loff_t off,
710 int count, int *eof, void *data);
711 int lprocfs_quota_wr_switch_seconds(struct file *file,
712 const char *buffer,
713 unsigned long count, void *data);
714 int lprocfs_quota_rd_sync_blk(char *page, char **start, loff_t off,
715 int count, int *eof, void *data);
716 int lprocfs_quota_wr_sync_blk(struct file *file, const char *buffer,
717 unsigned long count, void *data);
718 int lprocfs_quota_rd_switch_qs(char *page, char **start, loff_t off,
719 int count, int *eof, void *data);
720 int lprocfs_quota_wr_switch_qs(struct file *file,
721 const char *buffer, unsigned long count,
722 void *data);
723 int lprocfs_quota_rd_boundary_factor(char *page, char **start, loff_t off,
724 int count, int *eof, void *data);
725 int lprocfs_quota_wr_boundary_factor(struct file *file,
726 const char *buffer, unsigned long count,
727 void *data);
728 int lprocfs_quota_rd_least_bunit(char *page, char **start, loff_t off,
729 int count, int *eof, void *data);
730 int lprocfs_quota_wr_least_bunit(struct file *file,
731 const char *buffer, unsigned long count,
732 void *data);
733 int lprocfs_quota_rd_least_iunit(char *page, char **start, loff_t off,
734 int count, int *eof, void *data);
735 int lprocfs_quota_wr_least_iunit(struct file *file,
736 const char *buffer, unsigned long count,
737 void *data);
738 int lprocfs_quota_rd_qs_factor(char *page, char **start, loff_t off,
739 int count, int *eof, void *data);
740 int lprocfs_quota_wr_qs_factor(struct file *file,
741 const char *buffer, unsigned long count,
742 void *data);
743 #endif /* LPROCFS_SNMP_H */