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