Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / mds / lproc_mds.c
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 the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
29 #include <asm/statfs.h>
30 #endif
31 #include <obd.h>
32 #include <obd_class.h>
33 #include <lprocfs_status.h>
34 #include "mds_internal.h"
35
36 #ifdef LPROCFS
37 static int lprocfs_mds_rd_mntdev(char *page, char **start, off_t off, int count,
38                                  int *eof, void *data)
39 {
40         struct obd_device* obd = (struct obd_device *)data;
41
42         LASSERT(obd != NULL);
43         LASSERT(obd->u.mds.mds_vfsmnt->mnt_devname);
44         *eof = 1;
45
46         return snprintf(page, count, "%s\n",obd->u.mds.mds_vfsmnt->mnt_devname);
47 }
48
49 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
50                                        unsigned long count, void *data)
51 {
52         struct obd_device *obd = data;
53         struct mds_obd *mds = &obd->u.mds;
54         char tmpbuf[sizeof(struct obd_uuid)];
55         struct ptlrpc_request_set *set;
56         int rc;
57
58         sscanf(buffer, "%40s", tmpbuf);
59
60         if (strncmp(tmpbuf, "nid:", 4) != 0)
61                 return lprocfs_wr_evict_client(file, buffer, count, data);
62
63         set = ptlrpc_prep_set();
64         if (!set)
65                 return -ENOMEM;
66
67         rc = obd_set_info_async(mds->mds_osc_exp, strlen("evict_by_nid"),
68                                 "evict_by_nid", strlen(tmpbuf + 4) + 1,
69                                  tmpbuf + 4, set);
70         if (rc)
71                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
72                        rc);
73
74         ptlrpc_check_set(set);
75
76         /* See the comments in function lprocfs_wr_evict_client() 
77          * in ptlrpc/lproc_ptlrpc.c for details. - jay */
78         class_incref(obd);
79         LPROCFS_EXIT();
80
81         obd_export_evict_by_nid(obd, tmpbuf+4);
82
83         LPROCFS_ENTRY();
84         class_decref(obd);
85
86         rc = ptlrpc_set_wait(set);
87         if (rc)
88                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
89                        rc);
90         ptlrpc_set_destroy(set);
91         return count;
92 }
93
94 #if 0
95 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
96                                  unsigned long count, void *data)
97 {
98         struct obd_device *obd = data;
99         struct mds_obd *mds = &obd->u.mds;
100         struct mds_grp_downcall_data sparam, *param = &sparam;
101         int size = 0, rc = count;
102
103         if (count < sizeof(param)) {
104                 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
105                 return count;
106         }
107
108         if (copy_from_user(param, buffer, sizeof(*param)) ||
109             param->mgd_magic != MDS_GRP_DOWNCALL_MAGIC) {
110                 CERROR("%s: MDS group downcall bad params\n", obd->obd_name);
111                 return count;
112         }
113
114         if (param->mgd_ngroups > NGROUPS_MAX) {
115                 CWARN("%s: uid %u groups %d more than maximum %d\n",
116                       obd->obd_name, param->mgd_uid, param->mgd_ngroups,
117                       NGROUPS_MAX);
118                 param->mgd_ngroups = NGROUPS_MAX;
119         }
120
121         if (param->mgd_ngroups > 0) {
122                 size = offsetof(struct mds_grp_downcall_data,
123                                 mgd_groups[param->mgd_ngroups]);
124                 OBD_ALLOC(param, size);
125                 if (!param) {
126                         CERROR("%s: fail to alloc %d bytes for uid %u"
127                                " with %d groups\n", obd->obd_name, size,
128                                sparam.mgd_uid, sparam.mgd_ngroups);
129                         param = &sparam;
130                         param->mgd_ngroups = 0;
131                 } else if (copy_from_user(param, buffer, size)) {
132                         CERROR("%s: uid %u bad supplementary group data\n",
133                                obd->obd_name, sparam.mgd_uid);
134                         OBD_FREE(param, size);
135                         param = &sparam;
136                         param->mgd_ngroups = 0;
137                 }
138         }
139         rc = upcall_cache_downcall(mds->mds_group_hash, param->mgd_err,
140                                    param->mgd_uid, param->mgd_gid,
141                                    param->mgd_ngroups, param->mgd_groups);
142
143         if (param && param != &sparam)
144                 OBD_FREE(param, size);
145
146         return rc;
147 }
148
149 static int lprocfs_rd_group_expire(char *page, char **start, off_t off,
150                                    int count, int *eof, void *data)
151 {
152         struct obd_device *obd = data;
153
154         *eof = 1;
155         return snprintf(page, count, "%lu\n",
156                         obd->u.mds.mds_group_hash->uc_entry_expire / HZ);
157 }
158
159 static int lprocfs_wr_group_expire(struct file *file, const char *buffer,
160                                    unsigned long count, void *data)
161 {
162         struct obd_device *obd = data;
163         int val, rc;
164
165         rc = lprocfs_write_helper(buffer, count, &val);
166         if (rc)
167                 return rc;
168
169         if (val > 5)
170                 obd->u.mds.mds_group_hash->uc_entry_expire = val * HZ;
171         else
172                 CERROR("invalid expire time %u for group cache\n", val);
173
174         return count;
175 }
176
177 static int lprocfs_rd_group_acquire_expire(char *page, char **start, off_t off,
178                                            int count, int *eof, void *data)
179 {
180         struct obd_device *obd = data;
181
182         *eof = 1;
183         return snprintf(page, count, "%lu\n",
184                         obd->u.mds.mds_group_hash->uc_acquire_expire / HZ);
185 }
186
187 static int lprocfs_wr_group_acquire_expire(struct file *file,const char *buffer,
188                                            unsigned long count, void *data)
189 {
190         struct obd_device *obd = data;
191         int val, rc = 0;
192
193         rc = lprocfs_write_helper(buffer, count, &val);
194         if (rc)
195                 return rc;
196
197         if (val > 2)
198                 obd->u.mds.mds_group_hash->uc_acquire_expire = val * HZ;
199
200         return count;
201 }
202
203 static int lprocfs_rd_group_upcall(char *page, char **start, off_t off,
204                                    int count, int *eof, void *data)
205 {
206         struct obd_device *obd = data;
207
208         *eof = 1;
209         return snprintf(page, count, "%s\n",
210                         obd->u.mds.mds_group_hash->uc_upcall);
211 }
212
213 static int lprocfs_wr_group_upcall(struct file *file, const char *buffer,
214                                    unsigned long count, void *data)
215 {
216         struct obd_device *obd = data;
217         struct upcall_cache *hash = obd->u.mds.mds_group_hash;
218         char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
219
220         if (count >= UC_CACHE_UPCALL_MAXPATH) {
221                 CERROR("%s: group upcall too long\n", obd->obd_name);
222                 return -EINVAL;
223         }
224
225         if (copy_from_user(kernbuf, buffer,
226                            min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
227                 return -EFAULT;
228
229         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
230         sscanf(kernbuf, "%s", hash->uc_upcall);
231
232         if (strcmp(hash->uc_name, obd->obd_name) != 0)
233                 CWARN("%s: write to upcall name %s for MDS %s\n",
234                       obd->obd_name, hash->uc_upcall, obd->obd_name);
235         CWARN("%s: group upcall set to %s\n", obd->obd_name, hash->uc_upcall);
236
237         return count;
238 }
239
240 static int lprocfs_wr_group_flush(struct file *file, const char *buffer,
241                                   unsigned long count, void *data)
242 {
243         struct obd_device *obd = data;
244
245         upcall_cache_flush_idle(obd->u.mds.mds_group_hash);
246         return count;
247 }
248 #endif
249
250 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
251                                  unsigned long count, void *data)
252 {
253         struct obd_device *obd = data;
254         struct mds_obd *mds = &obd->u.mds;
255         char kernbuf[20], *end;
256         unsigned long diff = 0;
257
258         if (count > (sizeof(kernbuf) - 1))
259                 return -EINVAL;
260
261         if (copy_from_user(kernbuf, buffer, count))
262                 return -EFAULT;
263
264         kernbuf[count] = '\0';
265
266         diff = simple_strtoul(kernbuf, &end, 0);
267         if (kernbuf == end)
268                 return -EINVAL;
269
270         mds->mds_atime_diff = diff;
271         return count;
272 }
273
274 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
275                                  int count, int *eof, void *data)
276 {
277         struct obd_device *obd = data;
278         struct mds_obd *mds = &obd->u.mds;
279
280         *eof = 1;
281         return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
282 }
283
284 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
285         { "uuid",            lprocfs_rd_uuid,        0, 0 },
286         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
287         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
288         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
289         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
290         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
291         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
292         { "fstype",          lprocfs_rd_fstype,      0, 0 },
293         { "mntdev",          lprocfs_mds_rd_mntdev,  0, 0 },
294         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
295         { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
296         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
297 #ifdef HAVE_QUOTA_SUPPORT
298         { "quota_bunit_sz",  lprocfs_rd_bunit, lprocfs_wr_bunit, 0 },
299         { "quota_btune_sz",  lprocfs_rd_btune, lprocfs_wr_btune, 0 },
300         { "quota_iunit_sz",  lprocfs_rd_iunit, lprocfs_wr_iunit, 0 },
301         { "quota_itune_sz",  lprocfs_rd_itune, lprocfs_wr_itune, 0 },
302         { "quota_type",      lprocfs_rd_type, lprocfs_wr_type, 0 },
303 #endif
304 #if 0
305         { "group_expire_interval", lprocfs_rd_group_expire,
306                              lprocfs_wr_group_expire, 0},
307         { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
308                              lprocfs_wr_group_acquire_expire, 0},
309         { "group_upcall",    lprocfs_rd_group_upcall,
310                              lprocfs_wr_group_upcall, 0},
311         { "group_flush",     0, lprocfs_wr_group_flush, 0},
312         { "group_info",      0, lprocfs_wr_group_info, 0 },
313 #endif
314         { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
315         { 0 }
316 };
317
318 struct lprocfs_vars lprocfs_mds_module_vars[] = {
319         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
320         { 0 }
321 };
322
323 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
324         { "uuid",         lprocfs_rd_uuid,        0, 0 },
325         { 0 }
326 };
327
328 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
329         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
330         { 0 }
331 };
332
333 void mds_counter_incr(struct obd_export *exp, int opcode)
334 {
335         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
336         lprocfs_counter_incr(exp->exp_ops_stats, opcode);
337 }
338
339 void mds_stats_counter_init(struct lprocfs_stats *stats)
340 {
341         lprocfs_counter_init(stats, LPROC_MDS_OPEN, 0, "open", "reqs");
342         lprocfs_counter_init(stats, LPROC_MDS_CLOSE, 0, "close", "reqs");
343         lprocfs_counter_init(stats, LPROC_MDS_MKNOD, 0, "mknod", "reqs");
344         lprocfs_counter_init(stats, LPROC_MDS_LINK, 0, "link", "reqs");
345         lprocfs_counter_init(stats, LPROC_MDS_UNLINK, 0, "unlink", "reqs");
346         lprocfs_counter_init(stats, LPROC_MDS_MKDIR, 0, "mkdir", "reqs");
347         lprocfs_counter_init(stats, LPROC_MDS_RMDIR, 0, "rmdir", "reqs");
348         lprocfs_counter_init(stats, LPROC_MDS_RENAME, 0, "rename", "reqs");
349         lprocfs_counter_init(stats, LPROC_MDS_GETXATTR, 0, "getxattr", "reqs");
350         lprocfs_counter_init(stats, LPROC_MDS_SETXATTR, 0, "setxattr", "reqs");
351 }
352
353 LPROCFS_INIT_VARS(mds, lprocfs_mds_module_vars, lprocfs_mds_obd_vars);
354 LPROCFS_INIT_VARS(mdt, lprocfs_mdt_module_vars, lprocfs_mdt_obd_vars);
355 #endif