Whamcloud - gitweb
Merge b_md into HEAD
[fs/lustre-release.git] / lustre / include / linux / lprocfs_status.h
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  *   Top level header file for LProc SNMP
22  *   Author: Hariharan Thantry thantry@users.sourceforge.net
23  */
24 #ifndef _LPROCFS_SNMP_H
25 #define _LPROCFS_SNMP_H
26
27 #include <linux/autoconf.h>
28 #include <linux/proc_fs.h>
29
30 #ifndef LPROCFS
31 #ifdef  CONFIG_PROC_FS  /* Ensure that /proc is configured */
32 #define LPROCFS
33 #endif
34 #endif
35
36 struct lprocfs_vars {
37         char *name;
38         read_proc_t *read_fptr;
39         write_proc_t *write_fptr;
40         void *data;
41 };
42
43 struct lprocfs_static_vars {
44         struct lprocfs_vars *module_vars;
45         struct lprocfs_vars *obd_vars;
46 };
47
48 /* class_obd.c */
49 extern struct proc_dir_entry *proc_lustre_root;
50
51 extern void lprocfs_init_vars(struct lprocfs_static_vars *var);
52 extern void lprocfs_init_multi_vars(unsigned int idx, 
53                                     struct lprocfs_static_vars *var);
54
55 #define LPROCFS_INIT_MULTI_VARS(array, size)                              \
56 void lprocfs_init_multi_vars(unsigned int idx,                            \
57                              struct lprocfs_static_vars *x)               \
58 {                                                                         \
59    struct lprocfs_static_vars *glob = (struct lprocfs_static_vars*)array; \
60    LASSERT(glob != 0);                                                    \
61    LASSERT(idx < (unsigned int)(size));                                   \
62    x->module_vars = glob[idx].module_vars;                                \
63    x->obd_vars = glob[idx].obd_vars;                                      \
64 }                                                                         \
65
66 #define LPROCFS_INIT_VARS(vclass, vinstance)           \
67 void lprocfs_init_vars(struct lprocfs_static_vars *x)  \
68 {                                                      \
69         x->module_vars = vclass;                       \
70         x->obd_vars = vinstance;                       \
71 }                                                      \
72
73 #ifdef LPROCFS
74 /* lprocfs_status.c */
75 extern int lprocfs_add_vars(struct proc_dir_entry *root,
76                             struct lprocfs_vars *var,
77                             void *data);
78
79 extern struct proc_dir_entry *lprocfs_register(const char *name,
80                                                struct proc_dir_entry *parent,
81                                                struct lprocfs_vars *list,
82                                                void *data);
83
84 extern void lprocfs_remove(struct proc_dir_entry *root);
85
86 struct obd_device;
87 extern int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list);
88 extern int lprocfs_obd_detach(struct obd_device *dev);
89
90 /* Generic callbacks */
91
92 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
93                           int count, int *eof, void *data);
94 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
95                            int count, int *eof, void *data);
96 extern int lprocfs_rd_name(char *page, char **start, off_t off,
97                            int count, int *eof, void *data);
98 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
99                                   int count, int *eof, void *data);
100 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
101                                 int count, int *eof, void *data);
102 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
103                               int count, int *eof, void *data);
104
105 /* Statfs helpers */
106 struct statfs;
107 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
108                               int count, int *eof, struct statfs *sfs);
109 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
110                                   int count, int *eof, struct statfs *sfs);
111 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
112                                  int count, int *eof, struct statfs *sfs);
113 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
114                                  int count, int *eof, struct statfs *sfs);
115 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
116                                 int count, int *eof, struct statfs *sfs);
117 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
118                                  int count, int *eof, struct statfs *sfs);
119
120 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)      \
121 int fct_name(char *page, char **start, off_t off,                \
122              int count, int *eof, void *data)                    \
123 {                                                                \
124         struct statfs sfs;                                       \
125         int rc = get_statfs_fct((struct obd_device*)data, &sfs); \
126         return (rc==0                                            \
127                 ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
128                 : rc);                                       \
129 }
130
131 #else
132
133 static inline struct proc_dir_entry *
134 lprocfs_register(const char *name, struct proc_dir_entry *parent,
135                  struct lprocfs_vars *list, void *data) { return NULL; }
136 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
137                                    struct lprocfs_vars *var,
138                                    void *data) { return 0; }
139 static inline void lprocfs_remove(struct proc_dir_entry *root) {};
140 struct obd_device;
141 static inline int lprocfs_obd_attach(struct obd_device *dev,
142                                      struct lprocfs_vars *list) { return 0; }
143 static inline int lprocfs_obd_detach(struct obd_device *dev)  { return 0; }
144 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
145                                  int count, int *eof, void *data) { return 0; }
146 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
147                                   int count, int *eof, void *data) { return 0; }
148 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
149                                   int count, int *eof, void *data) { return 0; }
150 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
151                                          int count, int *eof, void *data) { return 0; }
152 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
153                                        int count, int *eof, void *data) { return 0; }
154 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
155                                      int count, int *eof, void *data) { return 0; }
156
157 /* Statfs helpers */
158 struct statfs;
159 static inline
160 int lprocfs_rd_blksize(char *page, char **start, off_t off,
161                        int count, int *eof, struct statfs *sfs) { return 0; }
162 static inline
163 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
164                            int count, int *eof, struct statfs *sfs) { return 0; }
165 static inline
166 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
167                           int count, int *eof, struct statfs *sfs) { return 0; }
168 static inline
169 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
170                           int count, int *eof, struct statfs *sfs) { return 0; }
171 static inline
172 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
173                          int count, int *eof, struct statfs *sfs)  { return 0; }
174 static inline
175 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
176                           int count, int *eof, struct statfs *sfs) { return 0; }
177
178 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)  \
179 int fct_name(char *page, char **start, off_t off,            \
180              int count, int *eof, void *data) { *eof = 1; return 0; }
181
182 #endif /* LPROCFS */
183
184 #endif /* LPROCFS_SNMP_H */