Whamcloud - gitweb
merge b_devel into HEAD. Includes:
[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 #ifdef __KERNEL__
28 #include <linux/autoconf.h>
29 #include <linux/proc_fs.h>
30 #endif
31
32 #ifndef LPROCFS
33 #ifdef  CONFIG_PROC_FS  /* Ensure that /proc is configured */
34 #define LPROCFS
35 #endif
36 #endif
37
38 struct lprocfs_vars {
39         char *name;
40         read_proc_t *read_fptr;
41         write_proc_t *write_fptr;
42         void *data;
43 };
44
45 struct lprocfs_static_vars {
46         struct lprocfs_vars *module_vars;
47         struct lprocfs_vars *obd_vars;
48 };
49
50 /* class_obd.c */
51 extern struct proc_dir_entry *proc_lustre_root;
52
53
54 #ifdef LPROCFS
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 extern void lprocfs_init_vars(struct lprocfs_static_vars *var);
74 extern void lprocfs_init_multi_vars(unsigned int idx, 
75                                     struct lprocfs_static_vars *var);
76 /* lprocfs_status.c */
77 extern int lprocfs_add_vars(struct proc_dir_entry *root,
78                             struct lprocfs_vars *var,
79                             void *data);
80
81 extern struct proc_dir_entry *lprocfs_register(const char *name,
82                                                struct proc_dir_entry *parent,
83                                                struct lprocfs_vars *list,
84                                                void *data);
85
86 extern void lprocfs_remove(struct proc_dir_entry *root);
87
88 struct obd_device;
89 extern int lprocfs_obd_attach(struct obd_device *dev, struct lprocfs_vars *list);
90 extern int lprocfs_obd_detach(struct obd_device *dev);
91
92 /* Generic callbacks */
93
94 extern int lprocfs_rd_u64(char *page, char **start, off_t off,
95                           int count, int *eof, void *data);
96 extern int lprocfs_rd_uuid(char *page, char **start, off_t off,
97                            int count, int *eof, void *data);
98 extern int lprocfs_rd_name(char *page, char **start, off_t off,
99                            int count, int *eof, void *data);
100 extern int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
101                                   int count, int *eof, void *data);
102 extern int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
103                                 int count, int *eof, void *data);
104 extern int lprocfs_rd_numrefs(char *page, char **start, off_t off,
105                               int count, int *eof, void *data);
106
107 /* Statfs helpers */
108 struct statfs;
109 extern int lprocfs_rd_blksize(char *page, char **start, off_t off,
110                               int count, int *eof, struct statfs *sfs);
111 extern int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
112                                   int count, int *eof, struct statfs *sfs);
113 extern int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
114                                  int count, int *eof, struct statfs *sfs);
115 extern int lprocfs_rd_filestotal(char *page, char **start, off_t off,
116                                  int count, int *eof, struct statfs *sfs);
117 extern int lprocfs_rd_filesfree(char *page, char **start, off_t off,
118                                 int count, int *eof, struct statfs *sfs);
119 extern int lprocfs_rd_filegroups(char *page, char **start, off_t off,
120                                  int count, int *eof, struct statfs *sfs);
121
122 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)      \
123 int fct_name(char *page, char **start, off_t off,                \
124              int count, int *eof, void *data)                    \
125 {                                                                \
126         struct statfs sfs;                                       \
127         int rc = get_statfs_fct((struct obd_device*)data, &sfs); \
128         return (rc==0                                            \
129                 ? lprocfs_##fct_name (page, start, off, count, eof, &sfs) \
130                 : rc);                                       \
131 }
132
133 #else
134
135 static inline struct proc_dir_entry *
136 lprocfs_register(const char *name, struct proc_dir_entry *parent,
137                  struct lprocfs_vars *list, void *data) { return NULL; }
138 #define LPROCFS_INIT_MULTI_VARS(array, size)
139 static inline void lprocfs_init_multi_vars(unsigned int idx,
140                                            struct lprocfs_static_vars *x) { return; }
141 #define LPROCFS_INIT_VARS(vclass, vinstance)
142 static inline void lprocfs_init_vars(struct lprocfs_static_vars *x) { return; }
143 static inline int lprocfs_add_vars(struct proc_dir_entry *root,
144                                    struct lprocfs_vars *var,
145                                    void *data) { return 0; }
146 static inline void lprocfs_remove(struct proc_dir_entry *root) {};
147 struct obd_device;
148 static inline int lprocfs_obd_attach(struct obd_device *dev,
149                                      struct lprocfs_vars *list) { return 0; }
150 static inline int lprocfs_obd_detach(struct obd_device *dev)  { return 0; }
151 static inline int lprocfs_rd_u64(char *page, char **start, off_t off,
152                                  int count, int *eof, void *data) { return 0; }
153 static inline int lprocfs_rd_uuid(char *page, char **start, off_t off,
154                                   int count, int *eof, void *data) { return 0; }
155 static inline int lprocfs_rd_name(char *page, char **start, off_t off,
156                                   int count, int *eof, void *data) { return 0; }
157 static inline int lprocfs_rd_server_uuid(char *page, char **start, off_t off,
158                                          int count, int *eof, void *data) { return 0; }
159 static inline int lprocfs_rd_conn_uuid(char *page, char **start, off_t off,
160                                        int count, int *eof, void *data) { return 0; }
161 static inline int lprocfs_rd_numrefs(char *page, char **start, off_t off,
162                                      int count, int *eof, void *data) { return 0; }
163
164 /* Statfs helpers */
165 struct statfs;
166 static inline
167 int lprocfs_rd_blksize(char *page, char **start, off_t off,
168                        int count, int *eof, struct statfs *sfs) { return 0; }
169 static inline
170 int lprocfs_rd_kbytestotal(char *page, char **start, off_t off,
171                            int count, int *eof, struct statfs *sfs) { return 0; }
172 static inline
173 int lprocfs_rd_kbytesfree(char *page, char **start, off_t off,
174                           int count, int *eof, struct statfs *sfs) { return 0; }
175 static inline
176 int lprocfs_rd_filestotal(char *page, char **start, off_t off,
177                           int count, int *eof, struct statfs *sfs) { return 0; }
178 static inline
179 int lprocfs_rd_filesfree(char *page, char **start, off_t off,
180                          int count, int *eof, struct statfs *sfs)  { return 0; }
181 static inline
182 int lprocfs_rd_filegroups(char *page, char **start, off_t off,
183                           int count, int *eof, struct statfs *sfs) { return 0; }
184
185 #define DEFINE_LPROCFS_STATFS_FCT(fct_name, get_statfs_fct)  \
186 int fct_name(char *page, char **start, off_t off,            \
187              int count, int *eof, void *data) { *eof = 1; return 0; }
188
189 #endif /* LPROCFS */
190
191 #endif /* LPROCFS_SNMP_H */