Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / mdt / mdt_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2004-2006 Cluster File Systems, Inc.
5  *   Author: Lai Siyao <lsy@clusterfs.com>
6  *   Author: Fan Yong <fanyong@clusterfs.com>
7  *
8  *   This file is part of the Lustre file system, http://www.lustre.org
9  *   Lustre is a trademark of Cluster File Systems, Inc.
10  *
11  *   You may have signed or agreed to another license before downloading
12  *   this software.  If so, you are bound by the terms and conditions
13  *   of that agreement, and the following does not apply to you.  See the
14  *   LICENSE file included with this distribution for more information.
15  *
16  *   If you did not agree to a different license, then this copy of Lustre
17  *   is open source software; you can redistribute it and/or modify it
18  *   under the terms of version 2 of the GNU General Public License as
19  *   published by the Free Software Foundation.
20  *
21  *   In either case, Lustre is distributed in the hope that it will be
22  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
23  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  *   license text for more details.
25  *
26  */
27
28 #ifndef EXPORT_SYMTAB
29 # define EXPORT_SYMTAB
30 #endif
31 #define DEBUG_SUBSYSTEM S_MDS
32
33 #include <linux/version.h>
34 #include <asm/statfs.h>
35
36 #include <linux/module.h>
37
38 /* LUSTRE_VERSION_CODE */
39 #include <lustre_ver.h>
40 /*
41  * struct OBD_{ALLOC,FREE}*()
42  * MDT_FAIL_CHECK
43  */
44 #include <obd_support.h>
45 /* struct obd_export */
46 #include <lustre_export.h>
47 /* struct obd_device */
48 #include <obd.h>
49 #include <obd_class.h>
50 #include <lustre_mds.h>
51 #include <lustre_mdt.h>
52 #include <lprocfs_status.h>
53 #include <lu_time.h>
54 #include "mdt_internal.h"
55
56 static const char *mdt_proc_names[LPROC_MDT_NR] = {
57 };
58
59 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
60 {
61         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
62         int result;
63         ENTRY;
64
65         LASSERT(name != NULL);
66         mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry;
67         LASSERT(mdt->mdt_proc_entry != NULL);
68
69         result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
70                               mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
71         if (result == 0)
72                 result = lu_time_named_init(&ld->ld_site->ls_time_stats,
73                                             "site_time", mdt->mdt_proc_entry,
74                                             lu_time_names,
75                                             ARRAY_SIZE(lu_time_names));
76         RETURN(result);
77 }
78
79 int mdt_procfs_fini(struct mdt_device *mdt)
80 {
81         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
82         lu_time_fini(&ld->ld_site->ls_time_stats);
83         lu_time_fini(&mdt->mdt_stats);
84         mdt->mdt_proc_entry = NULL;
85         RETURN(0);
86 }
87
88 void mdt_time_start(const struct mdt_thread_info *info)
89 {
90         lu_lprocfs_time_start(info->mti_env);
91 }
92
93 void mdt_time_end(const struct mdt_thread_info *info, int idx)
94 {
95         lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
96 }
97
98 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
99                                       int count, int *eof, void *data)
100 {
101         struct obd_device *obd = data;
102         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
103
104         *eof = 1;
105         return snprintf(page, count, "%lu\n",
106                         mdt->mdt_identity_cache->uc_entry_expire / HZ);
107 }
108
109 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
110                                       unsigned long count, void *data)
111 {
112         struct obd_device *obd = data;
113         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
114         int rc, val;
115
116         rc = lprocfs_write_helper(buffer, count, &val);
117         if (rc)
118                 return rc;
119
120         mdt->mdt_identity_cache->uc_entry_expire = val * HZ;
121         return count;
122 }
123
124 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
125                                               off_t off, int count, int *eof,
126                                               void *data)
127 {
128         struct obd_device *obd = data;
129         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
130
131         *eof = 1;
132         return snprintf(page, count, "%lu\n",
133                         mdt->mdt_identity_cache->uc_acquire_expire / HZ);
134 }
135
136 static int lprocfs_wr_identity_acquire_expire(struct file *file,
137                                               const char *buffer,
138                                               unsigned long count,
139                                               void *data)
140 {
141         struct obd_device *obd = data;
142         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
143         int rc, val;
144
145         rc = lprocfs_write_helper(buffer, count, &val);
146         if (rc)
147                 return rc;
148
149         mdt->mdt_identity_cache->uc_acquire_expire = val * HZ;
150         return count;
151 }
152
153 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
154                                       int count, int *eof, void *data)
155 {
156         struct obd_device *obd = data;
157         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
158
159         *eof = 1;
160         return snprintf(page, count, "%s\n",
161                         mdt->mdt_identity_cache->uc_upcall);
162 }
163
164 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
165                                       unsigned long count, void *data)
166 {
167         struct obd_device *obd = data;
168         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
169         struct upcall_cache *hash = mdt->mdt_identity_cache;
170         char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
171
172         if (count >= UC_CACHE_UPCALL_MAXPATH) {
173                 CERROR("%s: identity upcall too long\n", obd->obd_name);
174                 return -EINVAL;
175         }
176
177         if (copy_from_user(kernbuf, buffer,
178                            min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
179                 return -EFAULT;
180
181         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
182         sscanf(kernbuf, "%s", hash->uc_upcall);
183
184         if (strcmp(hash->uc_name, obd->obd_name) != 0)
185                 CWARN("%s: write to upcall name %s\n",
186                       obd->obd_name, hash->uc_upcall);
187         CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
188
189         return count;
190 }
191
192 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
193                                      unsigned long count, void *data)
194 {
195         struct obd_device *obd = data;
196         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
197         int rc, uid;
198
199         rc = lprocfs_write_helper(buffer, count, &uid);
200         if (rc)
201                 return rc;
202
203         mdt_flush_identity(mdt->mdt_identity_cache, uid);
204         return count;
205 }
206
207 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
208                                     unsigned long count, void *data)
209 {
210         struct obd_device *obd = data;
211         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
212         struct identity_downcall_data sparam, *param = &sparam;
213         int size = 0, rc = 0;
214
215         if (count < sizeof(*param)) {
216                 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
217                 return count;
218         }
219
220         if (copy_from_user(&sparam, buffer, sizeof(sparam))) {
221                 CERROR("%s: bad identity data\n", obd->obd_name);
222                 GOTO(out, rc = -EFAULT);
223         }
224
225         if (sparam.idd_magic != IDENTITY_DOWNCALL_MAGIC) {
226                 CERROR("%s: MDS identity downcall bad params\n", obd->obd_name);
227                 GOTO(out, rc = -EINVAL);
228         }
229
230         if (sparam.idd_nperms > N_SETXID_PERMS_MAX) {
231                 CERROR("%s: perm count %d more than maximum %d\n",
232                        obd->obd_name, sparam.idd_nperms, N_SETXID_PERMS_MAX);
233                 GOTO(out, rc = -EINVAL);
234         }
235
236         if (sparam.idd_ngroups > NGROUPS_MAX) {
237                 CERROR("%s: group count %d more than maximum %d\n",
238                        obd->obd_name, sparam.idd_ngroups, NGROUPS_MAX);
239                 GOTO(out, rc = -EINVAL);
240         }
241
242         if (sparam.idd_ngroups) {
243                 size = offsetof(struct identity_downcall_data,
244                                 idd_groups[sparam.idd_ngroups]);
245                 OBD_ALLOC(param, size);
246                 if (!param) {
247                         CERROR("%s: fail to alloc %d bytes for uid %u"
248                                " with %d groups\n", obd->obd_name, size,
249                                sparam.idd_uid, sparam.idd_ngroups);
250                         param = &sparam;
251                         param->idd_ngroups = 0;
252                 } else if (copy_from_user(param, buffer, size)) {
253                         CERROR("%s: uid %u bad supplementary group data\n",
254                                obd->obd_name, sparam.idd_uid);
255                         OBD_FREE(param, size);
256                         param = &sparam;
257                         param->idd_ngroups = 0;
258                 }
259         }
260
261         rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
262                                    param->idd_uid, param);
263
264 out:
265         if (param && (param != &sparam))
266                 OBD_FREE(param, size);
267
268         return rc ?: count;
269 }
270
271 static int lprocfs_rd_rmtacl_expire(char *page, char **start, off_t off,
272                                     int count, int *eof, void *data)
273 {
274         struct obd_device *obd = data;
275         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
276
277         *eof = 1;
278         return snprintf(page, count, "%lu\n",
279                         mdt->mdt_rmtacl_cache->uc_entry_expire / HZ);
280 }
281
282 static int lprocfs_wr_rmtacl_expire(struct file *file, const char *buffer,
283                                     unsigned long count, void *data)
284 {
285         struct obd_device *obd = data;
286         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
287         int rc, val;
288
289         rc = lprocfs_write_helper(buffer, count, &val);
290         if (rc)
291                 return rc;
292
293         mdt->mdt_rmtacl_cache->uc_entry_expire = val * HZ;
294         return count;
295 }
296
297 static int lprocfs_rd_rmtacl_acquire_expire(char *page, char **start,
298                                             off_t off, int count, int *eof,
299                                             void *data)
300 {
301         struct obd_device *obd = data;
302         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
303
304         *eof = 1;
305         return snprintf(page, count, "%lu\n",
306                         mdt->mdt_rmtacl_cache->uc_acquire_expire / HZ);
307 }
308
309 static int lprocfs_wr_rmtacl_acquire_expire(struct file *file,
310                                             const char *buffer,
311                                             unsigned long count,
312                                             void *data)
313 {
314         struct obd_device *obd = data;
315         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
316         int rc, val;
317
318         rc = lprocfs_write_helper(buffer, count, &val);
319         if (rc)
320                 return rc;
321
322         mdt->mdt_rmtacl_cache->uc_acquire_expire = val * HZ;
323         return count;
324 }
325
326 static int lprocfs_rd_rmtacl_upcall(char *page, char **start, off_t off,
327                                       int count, int *eof, void *data)
328 {
329         struct obd_device *obd = data;
330         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
331
332         *eof = 1;
333         return snprintf(page, count, "%s\n",
334                         mdt->mdt_rmtacl_cache->uc_upcall);
335 }
336
337 static int lprocfs_wr_rmtacl_upcall(struct file *file, const char *buffer,
338                                       unsigned long count, void *data)
339 {
340         struct obd_device *obd = data;
341         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
342         struct upcall_cache *hash = mdt->mdt_rmtacl_cache;
343         char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
344
345         if (count >= UC_CACHE_UPCALL_MAXPATH) {
346                 CERROR("%s: remote ACL upcall too long\n", obd->obd_name);
347                 return -EINVAL;
348         }
349
350         if (copy_from_user(kernbuf, buffer,
351                            min(count, UC_CACHE_UPCALL_MAXPATH - 1)))
352                 return -EFAULT;
353
354         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
355         sscanf(kernbuf, "%s", hash->uc_upcall);
356
357         if (strcmp(hash->uc_name, obd->obd_name) != 0)
358                 CWARN("%s: write to upcall name %s\n",
359                       obd->obd_name, hash->uc_upcall);
360         CWARN("%s: remote ACL upcall set to %s\n", obd->obd_name, hash->uc_upcall);
361
362         return count;
363 }
364
365 static int lprocfs_wr_rmtacl_info(struct file *file, const char *buffer,
366                                   unsigned long count, void *data)
367 {
368         struct obd_device *obd = data;
369         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
370         struct rmtacl_downcall_data sparam, *param = &sparam;
371         int size = 0, rc = 0;
372
373         if (count < sizeof(*param)) {
374                 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
375                 return count;
376         }
377
378         if (copy_from_user(&sparam, buffer, sizeof(sparam))) {
379                 CERROR("%s: bad remote acl data\n", obd->obd_name);
380                 GOTO(out, rc = -EFAULT);
381         }
382
383         if (sparam.add_magic != RMTACL_DOWNCALL_MAGIC) {
384                 CERROR("%s: MDT remote acl downcall bad params\n", obd->obd_name);
385                 GOTO(out, rc = -EINVAL);
386         }
387
388         if (sparam.add_buflen) {
389                 size = offsetof(struct rmtacl_downcall_data,
390                                 add_buf[sparam.add_buflen]);
391                 OBD_ALLOC(param, size);
392                 if (!param) {
393                         CERROR("%s: fail to alloc %d bytes for ino "LPU64"\n",
394                                obd->obd_name, size, sparam.add_key);
395                         param = &sparam;
396                         param->add_buflen = 0;
397                 } else if (copy_from_user(param, buffer, size)) {
398                         CERROR("%s: ino "LPU64" bad remote acl data\n",
399                                obd->obd_name, sparam.add_key);
400                         OBD_FREE(param, size);
401                         param = &sparam;
402                         param->add_buflen = 0;
403                 }
404         }
405
406         rc = upcall_cache_downcall(mdt->mdt_rmtacl_cache, 0, param->add_key,
407                                    param);
408
409 out:
410         if (param && (param != &sparam))
411                 OBD_FREE(param, size);
412
413         return rc ?: count;
414 }
415
416 static int lprocfs_rd_rootsquash_uid(char *page, char **start, off_t off,
417                                  int count, int *eof, void *data)
418 {
419         struct obd_device *obd = data;
420         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
421         struct rootsquash_info *rsi = mdt->mdt_rootsquash_info;
422
423         *eof = 1;
424         return snprintf(page, count, "%u\n",
425                         rsi ? rsi->rsi_uid : 0);
426 }
427
428 static int lprocfs_wr_rootsquash_uid(struct file *file, const char *buffer,
429                                      unsigned long count, void *data)
430 {
431         struct obd_device *obd = data;
432         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
433         int val, rc;
434
435         rc = lprocfs_write_helper(buffer, count, &val);
436         if (rc)
437                 return rc;
438
439         if (!mdt->mdt_rootsquash_info)
440                 OBD_ALLOC_PTR(mdt->mdt_rootsquash_info);
441         if (!mdt->mdt_rootsquash_info)
442                 return -ENOMEM;
443
444         mdt->mdt_rootsquash_info->rsi_uid = val;
445         return count;
446 }
447
448 static int lprocfs_rd_rootsquash_gid(char *page, char **start, off_t off,
449                                  int count, int *eof, void *data)
450 {
451         struct obd_device *obd = data;
452         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
453         struct rootsquash_info *rsi = mdt->mdt_rootsquash_info;
454
455         *eof = 1;
456         return snprintf(page, count, "%u\n",
457                         rsi ? rsi->rsi_gid : 0);
458 }
459
460 static int lprocfs_wr_rootsquash_gid(struct file *file, const char *buffer,
461                                      unsigned long count, void *data)
462 {
463         struct obd_device *obd = data;
464         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
465         int val, rc;
466
467         rc = lprocfs_write_helper(buffer, count, &val);
468         if (rc)
469                 return rc;
470
471         if (!mdt->mdt_rootsquash_info)
472                 OBD_ALLOC_PTR(mdt->mdt_rootsquash_info);
473         if (!mdt->mdt_rootsquash_info)
474                 return -ENOMEM;
475
476         mdt->mdt_rootsquash_info->rsi_gid = val;
477         return count;
478 }
479
480 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
481                                        int count, int *eof, void *data)
482 {
483         struct obd_device *obd = data;
484         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
485         struct rootsquash_info *rsi = mdt->mdt_rootsquash_info;
486         int i, ret;
487
488         ret = snprintf(page, count, "rootsquash skip list:\n");
489         for (i = 0; rsi && (i < rsi->rsi_n_nosquash_nids); i++) {
490                 ret += snprintf(page + ret, count - ret, "%s\n",
491                                 libcfs_nid2str(rsi->rsi_nosquash_nids[i]));
492         }
493
494         *eof = 1;
495         return ret;
496 }
497
498 static inline void remove_newline(char *str)
499 {
500         int len = strlen(str);
501
502         if (str[len - 1] == '\n')
503                 str[len - 1] = '\0';
504 }
505
506 /* XXX: This macro is copied from lnet/libcfs/nidstring.c */
507 #define LNET_NIDSTR_SIZE   32      /* size of each one (see below for usage) */
508
509 static void do_process_nosquash_nids(struct mdt_device *m, char *buf)
510 {
511         struct rootsquash_info *rsi = m->mdt_rootsquash_info;
512         char str[LNET_NIDSTR_SIZE], *end;
513         lnet_nid_t nid;
514
515         LASSERT(rsi);
516         rsi->rsi_n_nosquash_nids = 0;
517         while (rsi->rsi_n_nosquash_nids < N_NOSQUASH_NIDS) {
518                 end = strchr(buf, ',');
519                 memset(str, 0, sizeof(str));
520                 if (end)
521                         strncpy(str, buf, min_t(int, sizeof(str), end - buf));
522                 else
523                         strncpy(str, buf, min_t(int, sizeof(str), strlen(buf)));
524
525                 if (!strcmp(str, "*")) {
526                         nid = LNET_NID_ANY;
527                 } else {
528                         nid = libcfs_str2nid(str);
529                         if (nid == LNET_NID_ANY)
530                                 goto ignore;
531                 }
532                 rsi->rsi_nosquash_nids[rsi->rsi_n_nosquash_nids++] = nid;
533 ignore:
534                 if (!end || (*(end + 1) == 0))
535                         return;
536                 buf = end + 1;
537         }
538 }
539
540 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
541                                        unsigned long count, void *data)
542 {
543         struct obd_device *obd = data;
544         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
545         char skips[LNET_NIDSTR_SIZE * N_NOSQUASH_NIDS] = "";
546         unsigned long size = sizeof(skips);
547
548         if (count > size) {
549                 CERROR("parameter exceeds max limit %lu\n", size);
550                 return -EINVAL;
551         }
552
553         if (copy_from_user(skips, buffer, min(size, count)))
554                 return -EFAULT;
555
556         if (!mdt->mdt_rootsquash_info)
557                 OBD_ALLOC_PTR(mdt->mdt_rootsquash_info);
558         if (!mdt->mdt_rootsquash_info)
559                 return -ENOMEM;
560
561         remove_newline(skips);
562         do_process_nosquash_nids(mdt, skips);
563         return count;
564 }
565
566 /* for debug only */
567 static int lprocfs_rd_capa(char *page, char **start, off_t off,
568                            int count, int *eof, void *data)
569 {
570         struct obd_device *obd = data;
571         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
572
573         return snprintf(page, count, "capability on: %s %s\n",
574                         mdt->mdt_opts.mo_oss_capa ? "oss" : "",
575                         mdt->mdt_opts.mo_mds_capa ? "mds" : "");
576 }
577
578 static int lprocfs_wr_capa(struct file *file, const char *buffer,
579                            unsigned long count, void *data)
580 {
581         struct obd_device *obd = data;
582         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
583         int val, rc;
584
585         rc = lprocfs_write_helper(buffer, count, &val);
586         if (rc)
587                 return rc;
588
589         if (val < 0 || val > 3) {
590                 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
591                        " 0:  disable fid capability\n"
592                        " 2:  enable MDS fid capability\n"
593                        " 3:  enable both MDS and OSS fid capability\n");
594                 return -EINVAL;
595         }
596
597         /* OSS fid capability needs enable both MDS and OSS fid capability on
598          * MDS */
599         if (val == 1) {
600                 CERROR("can't enable OSS fid capability only, you should use "
601                        "'3' to enable both MDS and OSS fid capability.\n");
602                 return -EINVAL;
603         }
604
605         mdt->mdt_opts.mo_oss_capa = (val & 0x1);
606         mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
607         mdt->mdt_capa_conf = 1;
608         LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
609                       obd->obd_name,
610                       mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
611         LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
612                       obd->obd_name,
613                       mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
614         return count;
615 }
616
617 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
618                                  int count, int *eof, void *data)
619 {
620         return snprintf(page, count, "%d %d\n",
621                         capa_count[CAPA_SITE_CLIENT],
622                         capa_count[CAPA_SITE_SERVER]);
623 }
624
625 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
626                                  int count, int *eof, void *data)
627 {
628         struct obd_device *obd = data;
629         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
630         struct lu_site    *s   = mdt->mdt_md_dev.md_lu_dev.ld_site;
631         int i;
632         int populated;
633
634         /*
635          * How many hash buckets are not-empty? Don't bother with locks: it's
636          * an estimation anyway.
637          */
638         for (i = 0, populated = 0; i < s->ls_hash_size; i++)
639                 populated += !hlist_empty(&s->ls_hash[i]);
640
641         return snprintf(page, count, "%d %d %d/%d %d %d %d %d %d %d\n",
642                         s->ls_total,
643                         s->ls_busy,
644                         populated,
645                         s->ls_hash_size,
646                         s->ls_stats.s_created,
647                         s->ls_stats.s_cache_hit,
648                         s->ls_stats.s_cache_miss,
649                         s->ls_stats.s_cache_check,
650                         s->ls_stats.s_cache_race,
651                         s->ls_stats.s_lru_purged);
652 }
653
654 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
655                                    int count, int *eof, void *data)
656 {
657         struct obd_device *obd = data;
658         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
659
660         return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
661 }
662
663 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
664                                    unsigned long count, void *data)
665 {
666         struct obd_device *obd = data;
667         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
668         int val, rc;
669
670         rc = lprocfs_write_helper(buffer, count, &val);
671         if (rc)
672                 return rc;
673
674         mdt->mdt_capa_timeout = (unsigned long)val;
675         mdt->mdt_capa_conf = 1;
676         return count;
677 }
678
679 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
680                                  int *eof, void *data)
681 {
682         struct obd_device *obd = data;
683         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
684
685         return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
686 }
687
688 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
689                                  unsigned long count, void *data)
690 {
691         struct obd_device *obd = data;
692         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
693         int val, rc;
694
695         rc = lprocfs_write_helper(buffer, count, &val);
696         if (rc)
697                 return rc;
698
699         mdt->mdt_ck_timeout = (unsigned long)val;
700         mdt->mdt_capa_conf = 1;
701         return count;
702 }
703
704 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
705                                        unsigned long count, void *data)
706 {
707         char tmpbuf[sizeof(struct obd_uuid)];
708
709         sscanf(buffer, "%40s", tmpbuf);
710
711         if (strncmp(tmpbuf, "nid:", 4) != 0)
712                 return lprocfs_wr_evict_client(file, buffer, count, data);
713
714         CERROR("NOT implement evict client by nid %s\n", tmpbuf);
715
716         return count;
717 }
718
719 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
720         { "uuid",                       lprocfs_rd_uuid,                 0, 0 },
721         { "recovery_status",            lprocfs_obd_rd_recovery_status,  0, 0 },
722         { "num_exports",                lprocfs_rd_num_exports,          0, 0 },
723         { "identity_expire",            lprocfs_rd_identity_expire,
724                                         lprocfs_wr_identity_expire,         0 },
725         { "identity_acquire_expire",    lprocfs_rd_identity_acquire_expire,
726                                         lprocfs_wr_identity_acquire_expire, 0 },
727         { "identity_upcall",            lprocfs_rd_identity_upcall,
728                                         lprocfs_wr_identity_upcall,         0 },
729         { "identity_flush",             0, lprocfs_wr_identity_flush,       0 },
730         { "identity_info",              0, lprocfs_wr_identity_info,        0 },
731         { "rmtacl_expire",              lprocfs_rd_rmtacl_expire,
732                                         lprocfs_wr_rmtacl_expire,           0 },
733         { "rmtacl_acquire_expire",      lprocfs_rd_rmtacl_acquire_expire,
734                                         lprocfs_wr_rmtacl_acquire_expire,   0 },
735         { "rmtacl_upcall",              lprocfs_rd_rmtacl_upcall,
736                                         lprocfs_wr_rmtacl_upcall,           0 },
737         { "rmtacl_info",                0, lprocfs_wr_rmtacl_info,          0 },
738         { "rootsquash_uid",             lprocfs_rd_rootsquash_uid,
739                                         lprocfs_wr_rootsquash_uid,          0 },
740         { "rootsquash_gid",             lprocfs_rd_rootsquash_gid,
741                                         lprocfs_wr_rootsquash_gid,          0 },
742         { "nosquash_nids",              lprocfs_rd_nosquash_nids,
743                                         lprocfs_wr_nosquash_nids,           0 },
744         { "capa",                       lprocfs_rd_capa,
745                                         lprocfs_wr_capa,                    0 },
746         { "capa_timeout",               lprocfs_rd_capa_timeout,
747                                         lprocfs_wr_capa_timeout,            0 },
748         { "capa_key_timeout",           lprocfs_rd_ck_timeout,
749                                         lprocfs_wr_ck_timeout,              0 },
750         { "capa_count",                 lprocfs_rd_capa_count,           0, 0 },
751         { "site_stats",                 lprocfs_rd_site_stats,           0, 0 },
752         { "evict_client",               0, lprocfs_mdt_wr_evict_client,     0 },
753         { 0 }
754 };
755
756 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
757         { "num_refs",                   lprocfs_rd_numrefs,              0, 0 },
758         { 0 }
759 };
760
761 LPROCFS_INIT_VARS(mdt, lprocfs_mdt_module_vars, lprocfs_mdt_obd_vars);