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