Whamcloud - gitweb
Branch: b_new_cmd
[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 <linux/obd.h>
32 #include <linux/obd_class.h>
33 #include <linux/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         int rc;
56
57         sscanf(buffer, "%40s", tmpbuf);
58
59         if (strncmp(tmpbuf, "nid:", 4) != 0)
60                 return lprocfs_wr_evict_client(file, buffer, count, data);
61
62         obd_export_evict_by_nid(obd, tmpbuf+4);
63
64         rc = obd_set_info(mds->mds_osc_exp, strlen("evict_by_nid"),
65                           "evict_by_nid", strlen(tmpbuf + 4) + 1, tmpbuf + 4);
66         if (rc)
67                 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
68                        rc);
69
70         return count;
71 }
72
73 static int lprocfs_wr_group_info(struct file *file, const char *buffer,
74                                  unsigned long count, void *data)
75 {
76         struct obd_device *obd = data;
77         struct mds_obd *mds = &obd->u.mds;
78         struct mds_grp_downcall_data sparam, *param = &sparam;
79         int size = 0, rc = count;
80
81         if (count < sizeof(param)) {
82                 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
83                 return count;
84         }
85
86         if (copy_from_user(param, buffer, sizeof(*param)) ||
87             param->mgd_magic != MDS_GRP_DOWNCALL_MAGIC) {
88                 CERROR("%s: MDS group downcall bad params\n", obd->obd_name);
89                 return count;
90         }
91
92         if (param->mgd_ngroups > NGROUPS_MAX) {
93                 CWARN("%s: uid %u groups %d more than maximum %d\n",
94                       obd->obd_name, param->mgd_uid, param->mgd_ngroups,
95                       NGROUPS_MAX);
96                 param->mgd_ngroups = NGROUPS_MAX;
97         }
98
99         if (param->mgd_ngroups > 0) {
100                 size = offsetof(struct mds_grp_downcall_data,
101                                 mgd_groups[param->mgd_ngroups]);
102                 OBD_ALLOC(param, size);
103                 if (!param) {
104                         CERROR("%s: fail to alloc %d bytes for uid %u"
105                                " with %d groups\n", obd->obd_name, size,
106                                sparam.mgd_uid, sparam.mgd_ngroups);
107                         param = &sparam;
108                         param->mgd_ngroups = 0;
109                 } else if (copy_from_user(param, buffer, size)) {
110                         CERROR("%s: uid %u bad supplementary group data\n",
111                                obd->obd_name, sparam.mgd_uid);
112                         OBD_FREE(param, size);
113                         param = &sparam;
114                         param->mgd_ngroups = 0;
115                 }
116         }
117         rc = upcall_cache_downcall(mds->mds_group_hash, param->mgd_err,
118                                    param->mgd_uid, param->mgd_gid,
119                                    param->mgd_ngroups, param->mgd_groups);
120
121         if (param && param != &sparam)
122                 OBD_FREE(param, size);
123
124         return rc;
125 }
126
127 static int lprocfs_rd_group_expire(char *page, char **start, off_t off,
128                                    int count, int *eof, void *data)
129 {
130         struct obd_device *obd = data;
131
132         *eof = 1;
133         return snprintf(page, count, "%lu\n",
134                         obd->u.mds.mds_group_hash->uc_entry_expire / HZ);
135 }
136
137 static int lprocfs_wr_group_expire(struct file *file, const char *buffer,
138                                    unsigned long count, void *data)
139 {
140         struct obd_device *obd = data;
141         int val, rc;
142
143         rc = lprocfs_write_helper(buffer, count, &val);
144         if (rc)
145                 return rc;
146
147         if (val > 5)
148                 obd->u.mds.mds_group_hash->uc_entry_expire = val * HZ;
149         else
150                 CERROR("invalid expire time %u for group cache\n", val);
151
152         return count;
153 }
154
155 static int lprocfs_rd_group_acquire_expire(char *page, char **start, off_t off,
156                                            int count, int *eof, void *data)
157 {
158         struct obd_device *obd = data;
159
160         *eof = 1;
161         return snprintf(page, count, "%lu\n",
162                         obd->u.mds.mds_group_hash->uc_acquire_expire / HZ);
163 }
164
165 static int lprocfs_wr_group_acquire_expire(struct file *file,const char *buffer,
166                                            unsigned long count, void *data)
167 {
168         struct obd_device *obd = data;
169         int val, rc = 0;
170
171         rc = lprocfs_write_helper(buffer, count, &val);
172         if (rc)
173                 return rc;
174
175         if (val > 2)
176                 obd->u.mds.mds_group_hash->uc_acquire_expire = val * HZ;
177
178         return count;
179 }
180
181 static int lprocfs_rd_group_upcall(char *page, char **start, off_t off,
182                                    int count, int *eof, void *data)
183 {
184         struct obd_device *obd = data;
185
186         *eof = 1;
187         return snprintf(page, count, "%s\n",
188                         obd->u.mds.mds_group_hash->uc_upcall);
189 }
190
191 static int lprocfs_wr_group_upcall(struct file *file, const char *buffer,
192                                    unsigned long count, void *data)
193 {
194         struct obd_device *obd = data;
195         struct upcall_cache *hash = obd->u.mds.mds_group_hash;
196         char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
197
198         if (count >= UC_CACHE_UPCALL_MAXPATH) {
199                 CERROR("%s: group upcall too long\n", obd->obd_name);
200                 return -EINVAL;
201         }
202
203         if (copy_from_user(kernbuf, buffer,
204                            min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
205                 return -EFAULT;
206
207         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
208         sscanf(kernbuf, "%s", hash->uc_upcall);
209
210         if (strcmp(hash->uc_name, obd->obd_name) != 0)
211                 CWARN("%s: write to upcall name %s for MDS %s\n",
212                       obd->obd_name, hash->uc_upcall, obd->obd_name);
213         CWARN("%s: group upcall set to %s\n", obd->obd_name, hash->uc_upcall);
214
215         return count;
216 }
217
218 static int lprocfs_wr_group_flush(struct file *file, const char *buffer,
219                                   unsigned long count, void *data)
220 {
221         struct obd_device *obd = data;
222
223         upcall_cache_flush_idle(obd->u.mds.mds_group_hash);
224         return count;
225 }
226
227 #ifdef HAVE_QUOTA_SUPPORT        
228 static int lprocfs_mds_rd_bunit(char *page, char **start, off_t off, int count, 
229                                 int *eof, void *data)
230 {
231         struct obd_device *obd = (struct obd_device *)data;
232         LASSERT(obd != NULL);
233
234         return snprintf(page, count, "%lu\n", 
235                         obd->u.obt.obt_qctxt.lqc_bunit_sz);
236 }
237
238 static int lprocfs_mds_rd_iunit(char *page, char **start, off_t off, int count, 
239                                 int *eof, void *data)
240 {
241         struct obd_device *obd = (struct obd_device *)data;
242         LASSERT(obd != NULL);
243
244         return snprintf(page, count, "%lu\n", 
245                         obd->u.obt.obt_qctxt.lqc_iunit_sz);
246 }
247
248 static int lprocfs_mds_wr_bunit(struct file *file, const char *buffer,
249                                 unsigned long count, void *data)
250 {
251         struct obd_device *obd = (struct obd_device *)data;
252         int val, rc;
253         LASSERT(obd != NULL);
254
255         rc = lprocfs_write_helper(buffer, count, &val);
256         if (rc)
257                 return rc;
258
259         if (val % QUOTABLOCK_SIZE ||
260             val <= obd->u.obt.obt_qctxt.lqc_btune_sz)
261                 return -EINVAL;
262
263         obd->u.obt.obt_qctxt.lqc_bunit_sz = val;
264         return count;
265 }
266
267 static int lprocfs_mds_wr_iunit(struct file *file, const char *buffer,
268                                 unsigned long count, void *data)
269 {
270         struct obd_device *obd = (struct obd_device *)data;
271         int val, rc;
272         LASSERT(obd != NULL);
273
274         rc = lprocfs_write_helper(buffer, count, &val);
275         if (rc)
276                 return rc;
277
278         if (val <= obd->u.obt.obt_qctxt.lqc_itune_sz)
279                 return -EINVAL;
280
281         obd->u.obt.obt_qctxt.lqc_iunit_sz = val;
282         return count;
283 }
284
285 static int lprocfs_mds_rd_btune(char *page, char **start, off_t off, int count, 
286                                 int *eof, void *data)
287 {
288         struct obd_device *obd = (struct obd_device *)data;
289         LASSERT(obd != NULL);
290
291         return snprintf(page, count, "%lu\n", 
292                         obd->u.obt.obt_qctxt.lqc_btune_sz);
293 }
294
295 static int lprocfs_mds_rd_itune(char *page, char **start, off_t off, int count, 
296                                 int *eof, void *data)
297 {
298         struct obd_device *obd = (struct obd_device *)data;
299         LASSERT(obd != NULL);
300
301         return snprintf(page, count, "%lu\n", 
302                         obd->u.obt.obt_qctxt.lqc_itune_sz);
303 }
304
305 static int lprocfs_mds_wr_btune(struct file *file, const char *buffer,
306                                 unsigned long count, void *data)
307 {
308         struct obd_device *obd = (struct obd_device *)data;
309         int val, rc;
310         LASSERT(obd != NULL);
311
312         rc = lprocfs_write_helper(buffer, count, &val);
313         if (rc)
314                 return rc;
315         
316         if (val <= QUOTABLOCK_SIZE * MIN_QLIMIT || val % QUOTABLOCK_SIZE || 
317             val >= obd->u.obt.obt_qctxt.lqc_bunit_sz)
318                 return -EINVAL;
319
320         obd->u.obt.obt_qctxt.lqc_btune_sz = val;
321         return count;
322 }
323
324 static int lprocfs_mds_wr_itune(struct file *file, const char *buffer,
325                                 unsigned long count, void *data)
326 {
327         struct obd_device *obd = (struct obd_device *)data;
328         int val, rc;
329         LASSERT(obd != NULL);
330
331         rc = lprocfs_write_helper(buffer, count, &val);
332         if (rc)
333                 return rc;
334         
335         if (val <= MIN_QLIMIT || 
336             val >= obd->u.obt.obt_qctxt.lqc_iunit_sz)
337                 return -EINVAL;
338
339         obd->u.obt.obt_qctxt.lqc_itune_sz = val;
340         return count;
341 }
342 #endif
343
344 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
345                                  unsigned long count, void *data)
346 {
347         struct obd_device *obd = data;
348         struct mds_obd *mds = &obd->u.mds;
349         char kernbuf[20], *end;
350         unsigned long diff = 0;
351
352         if (count > (sizeof(kernbuf) - 1))
353                 return -EINVAL;
354
355         if (copy_from_user(kernbuf, buffer, count))
356                 return -EFAULT;
357
358         kernbuf[count] = '\0';
359
360         diff = simple_strtoul(kernbuf, &end, 0);
361         if (kernbuf == end)
362                 return -EINVAL;
363
364         mds->mds_atime_diff = diff;
365         return count;
366 }
367
368 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
369                                  int count, int *eof, void *data)
370 {
371         struct obd_device *obd = data;
372         struct mds_obd *mds = &obd->u.mds;
373
374         *eof = 1;
375         return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
376 }
377
378 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
379         { "uuid",            lprocfs_rd_uuid,        0, 0 },
380         { "blocksize",       lprocfs_rd_blksize,     0, 0 },
381         { "kbytestotal",     lprocfs_rd_kbytestotal, 0, 0 },
382         { "kbytesfree",      lprocfs_rd_kbytesfree,  0, 0 },
383         { "kbytesavail",     lprocfs_rd_kbytesavail, 0, 0 },
384         { "filestotal",      lprocfs_rd_filestotal,  0, 0 },
385         { "filesfree",       lprocfs_rd_filesfree,   0, 0 },
386         { "fstype",          lprocfs_rd_fstype,      0, 0 },
387         { "mntdev",          lprocfs_mds_rd_mntdev,  0, 0 },
388         { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
389         { "evict_client",    0,                lprocfs_mds_wr_evict_client, 0 },
390         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
391 #ifdef HAVE_QUOTA_SUPPORT
392         { "quota_bunit_sz",  lprocfs_mds_rd_bunit, lprocfs_mds_wr_bunit, 0 },
393         { "quota_btune_sz",  lprocfs_mds_rd_btune, lprocfs_mds_wr_btune, 0 },
394         { "quota_iunit_sz",  lprocfs_mds_rd_iunit, lprocfs_mds_wr_iunit, 0 },
395         { "quota_itune_sz",  lprocfs_mds_rd_itune, lprocfs_mds_wr_itune, 0 },
396 #endif
397         { "group_expire_interval", lprocfs_rd_group_expire,
398                              lprocfs_wr_group_expire, 0},
399         { "group_acquire_expire", lprocfs_rd_group_acquire_expire,
400                              lprocfs_wr_group_acquire_expire, 0},
401         { "group_upcall",    lprocfs_rd_group_upcall,
402                              lprocfs_wr_group_upcall, 0},
403         { "group_flush",     0, lprocfs_wr_group_flush, 0},
404         { "group_info",      0, lprocfs_wr_group_info, 0 },
405         { "atime_diff",      lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
406         { 0 }
407 };
408
409 struct lprocfs_vars lprocfs_mds_module_vars[] = {
410         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
411         { 0 }
412 };
413
414 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
415         { "uuid",         lprocfs_rd_uuid,        0, 0 },
416         { 0 }
417 };
418
419 struct lprocfs_vars lprocfs_mdt_module_vars[] = {
420         { "num_refs",     lprocfs_rd_numrefs,     0, 0 },
421         { 0 }
422 };
423
424 LPROCFS_INIT_VARS(mds, lprocfs_mds_module_vars, lprocfs_mds_obd_vars);
425 LPROCFS_INIT_VARS(mdt, lprocfs_mdt_module_vars, lprocfs_mdt_obd_vars);
426 #endif