Whamcloud - gitweb
b=19955
[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  * 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
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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  * lustre/mdt/mdt_lproc.c
37  *
38  * Author: Lai Siyao <lsy@clusterfs.com>
39  * Author: Fan Yong <fanyong@clusterfs.com>
40  */
41
42 #ifndef EXPORT_SYMTAB
43 # define EXPORT_SYMTAB
44 #endif
45 #define DEBUG_SUBSYSTEM S_MDS
46
47 #include <linux/version.h>
48 #include <asm/statfs.h>
49
50 #include <linux/module.h>
51
52 /* LUSTRE_VERSION_CODE */
53 #include <lustre_ver.h>
54 /*
55  * struct OBD_{ALLOC,FREE}*()
56  * MDT_FAIL_CHECK
57  */
58 #include <obd_support.h>
59 /* struct obd_export */
60 #include <lustre_export.h>
61 /* struct obd_device */
62 #include <obd.h>
63 #include <obd_class.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include <lprocfs_status.h>
67 #include <lu_time.h>
68 #include "mdt_internal.h"
69 #include <lnet/lib-lnet.h>
70
71 static const char *mdt_proc_names[LPROC_MDT_NR] = {
72 };
73
74 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
75 {
76         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
77         int result;
78         ENTRY;
79
80         LASSERT(name != NULL);
81         mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry;
82         LASSERT(mdt->mdt_proc_entry != NULL);
83
84         result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
85                               mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
86         if (result == 0)
87                 result = lu_time_named_init(&ld->ld_site->ls_time_stats,
88                                             "site_time", mdt->mdt_proc_entry,
89                                             lu_time_names,
90                                             ARRAY_SIZE(lu_time_names));
91         RETURN(result);
92 }
93
94 int mdt_procfs_fini(struct mdt_device *mdt)
95 {
96         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
97         if (mdt->mdt_proc_entry) {
98                 lu_time_fini(&ld->ld_site->ls_time_stats);
99                 lu_time_fini(&mdt->mdt_stats);
100                 mdt->mdt_proc_entry = NULL;
101         }
102         RETURN(0);
103 }
104
105 void mdt_time_start(const struct mdt_thread_info *info)
106 {
107         lu_lprocfs_time_start(info->mti_env);
108 }
109
110 void mdt_time_end(const struct mdt_thread_info *info, int idx)
111 {
112         lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
113 }
114
115 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
116                                       int count, int *eof, void *data)
117 {
118         struct obd_device *obd = data;
119         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
120
121         *eof = 1;
122         return snprintf(page, count, "%lu\n",
123                         mdt->mdt_identity_cache->uc_entry_expire / HZ);
124 }
125
126 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
127                                       unsigned long count, void *data)
128 {
129         struct obd_device *obd = data;
130         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
131         int rc, val;
132
133         rc = lprocfs_write_helper(buffer, count, &val);
134         if (rc)
135                 return rc;
136
137         mdt->mdt_identity_cache->uc_entry_expire = val * HZ;
138         return count;
139 }
140
141 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
142                                               off_t off, int count, int *eof,
143                                               void *data)
144 {
145         struct obd_device *obd = data;
146         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
147
148         *eof = 1;
149         return snprintf(page, count, "%lu\n",
150                         mdt->mdt_identity_cache->uc_acquire_expire / HZ);
151 }
152
153 static int lprocfs_wr_identity_acquire_expire(struct file *file,
154                                               const char *buffer,
155                                               unsigned long count,
156                                               void *data)
157 {
158         struct obd_device *obd = data;
159         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
160         int rc, val;
161
162         rc = lprocfs_write_helper(buffer, count, &val);
163         if (rc)
164                 return rc;
165
166         mdt->mdt_identity_cache->uc_acquire_expire = val * HZ;
167         return count;
168 }
169
170 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
171                                       int count, int *eof, void *data)
172 {
173         struct obd_device *obd = data;
174         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
175         struct upcall_cache *hash = mdt->mdt_identity_cache;
176         int len;
177
178         *eof = 1;
179         read_lock(&hash->uc_upcall_rwlock);
180         len = snprintf(page, count, "%s\n", hash->uc_upcall);
181         read_unlock(&hash->uc_upcall_rwlock);
182         return len;
183 }
184
185 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
186                                       unsigned long count, void *data)
187 {
188         struct obd_device *obd = data;
189         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
190         struct upcall_cache *hash = mdt->mdt_identity_cache;
191         char kernbuf[UC_CACHE_UPCALL_MAXPATH] = { '\0' };
192
193         if (count >= UC_CACHE_UPCALL_MAXPATH) {
194                 CERROR("%s: identity upcall too long\n", obd->obd_name);
195                 return -EINVAL;
196         }
197
198         if (copy_from_user(kernbuf, buffer, min_t(unsigned long, count,
199                                                   UC_CACHE_UPCALL_MAXPATH - 1)))
200                 return -EFAULT;
201
202         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
203         write_lock(&hash->uc_upcall_rwlock);
204         sscanf(kernbuf, "%s", hash->uc_upcall);
205         write_unlock(&hash->uc_upcall_rwlock);
206
207         if (strcmp(hash->uc_name, obd->obd_name) != 0)
208                 CWARN("%s: write to upcall name %s\n",
209                       obd->obd_name, hash->uc_upcall);
210
211         if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
212                 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
213                       "cause unexpected \"EACCESS\"\n", obd->obd_name);
214
215         CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
216         return count;
217 }
218
219 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
220                                      unsigned long count, void *data)
221 {
222         struct obd_device *obd = data;
223         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
224         int rc, uid;
225
226         rc = lprocfs_write_helper(buffer, count, &uid);
227         if (rc)
228                 return rc;
229
230         mdt_flush_identity(mdt->mdt_identity_cache, uid);
231         return count;
232 }
233
234 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
235                                     unsigned long count, void *data)
236 {
237         struct obd_device *obd = data;
238         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
239         struct identity_downcall_data sparam, *param = &sparam;
240         int size = 0, rc = 0;
241
242         if (count < sizeof(*param)) {
243                 CERROR("%s: invalid data size %lu\n", obd->obd_name, count);
244                 return count;
245         }
246
247         if (copy_from_user(&sparam, buffer, sizeof(sparam))) {
248                 CERROR("%s: bad identity data\n", obd->obd_name);
249                 GOTO(out, rc = -EFAULT);
250         }
251
252         if (sparam.idd_magic != IDENTITY_DOWNCALL_MAGIC) {
253                 CERROR("%s: MDS identity downcall bad params\n", obd->obd_name);
254                 GOTO(out, rc = -EINVAL);
255         }
256
257         if (sparam.idd_nperms > N_PERMS_MAX) {
258                 CERROR("%s: perm count %d more than maximum %d\n",
259                        obd->obd_name, sparam.idd_nperms, N_PERMS_MAX);
260                 GOTO(out, rc = -EINVAL);
261         }
262
263         if (sparam.idd_ngroups > NGROUPS_MAX) {
264                 CERROR("%s: group count %d more than maximum %d\n",
265                        obd->obd_name, sparam.idd_ngroups, NGROUPS_MAX);
266                 GOTO(out, rc = -EINVAL);
267         }
268
269         if (sparam.idd_ngroups) {
270                 size = offsetof(struct identity_downcall_data,
271                                 idd_groups[sparam.idd_ngroups]);
272                 OBD_ALLOC(param, size);
273                 if (!param) {
274                         CERROR("%s: fail to alloc %d bytes for uid %u"
275                                " with %d groups\n", obd->obd_name, size,
276                                sparam.idd_uid, sparam.idd_ngroups);
277                         param = &sparam;
278                         param->idd_ngroups = 0;
279                 } else if (copy_from_user(param, buffer, size)) {
280                         CERROR("%s: uid %u bad supplementary group data\n",
281                                obd->obd_name, sparam.idd_uid);
282                         OBD_FREE(param, size);
283                         param = &sparam;
284                         param->idd_ngroups = 0;
285                 }
286         }
287
288         rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
289                                    param->idd_uid, param);
290
291 out:
292         if (param && (param != &sparam))
293                 OBD_FREE(param, size);
294
295         return rc ?: count;
296 }
297
298 /* for debug only */
299 static int lprocfs_rd_capa(char *page, char **start, off_t off,
300                            int count, int *eof, void *data)
301 {
302         struct obd_device *obd = data;
303         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
304
305         return snprintf(page, count, "capability on: %s %s\n",
306                         mdt->mdt_opts.mo_oss_capa ? "oss" : "",
307                         mdt->mdt_opts.mo_mds_capa ? "mds" : "");
308 }
309
310 static int lprocfs_wr_capa(struct file *file, const char *buffer,
311                            unsigned long count, void *data)
312 {
313         struct obd_device *obd = data;
314         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
315         int val, rc;
316
317         rc = lprocfs_write_helper(buffer, count, &val);
318         if (rc)
319                 return rc;
320
321         if (val < 0 || val > 3) {
322                 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
323                        " 0:  disable fid capability\n"
324                        " 2:  enable MDS fid capability\n"
325                        " 3:  enable both MDS and OSS fid capability\n");
326                 return -EINVAL;
327         }
328
329         /* OSS fid capability needs enable both MDS and OSS fid capability on
330          * MDS */
331         if (val == 1) {
332                 CERROR("can't enable OSS fid capability only, you should use "
333                        "'3' to enable both MDS and OSS fid capability.\n");
334                 return -EINVAL;
335         }
336
337         mdt->mdt_opts.mo_oss_capa = (val & 0x1);
338         mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
339         mdt->mdt_capa_conf = 1;
340         LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
341                       obd->obd_name,
342                       mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
343         LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
344                       obd->obd_name,
345                       mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
346         return count;
347 }
348
349 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
350                                  int count, int *eof, void *data)
351 {
352         return snprintf(page, count, "%d %d\n",
353                         capa_count[CAPA_SITE_CLIENT],
354                         capa_count[CAPA_SITE_SERVER]);
355 }
356
357 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
358                                  int count, int *eof, void *data)
359 {
360         struct obd_device *obd = data;
361         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
362
363         return lu_site_stats_print(mdt_lu_site(mdt), page, count);
364 }
365
366 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
367                                    int count, int *eof, void *data)
368 {
369         struct obd_device *obd = data;
370         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
371
372         return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
373 }
374
375 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
376                                    unsigned long count, void *data)
377 {
378         struct obd_device *obd = data;
379         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
380         int val, rc;
381
382         rc = lprocfs_write_helper(buffer, count, &val);
383         if (rc)
384                 return rc;
385
386         mdt->mdt_capa_timeout = (unsigned long)val;
387         mdt->mdt_capa_conf = 1;
388         return count;
389 }
390
391 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
392                                  int *eof, void *data)
393 {
394         struct obd_device *obd = data;
395         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
396
397         return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
398 }
399
400 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
401                                  unsigned long count, void *data)
402 {
403         struct obd_device *obd = data;
404         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
405         int val, rc;
406
407         rc = lprocfs_write_helper(buffer, count, &val);
408         if (rc)
409                 return rc;
410
411         mdt->mdt_ck_timeout = (unsigned long)val;
412         mdt->mdt_capa_conf = 1;
413         return count;
414 }
415
416 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
417                                        unsigned long count, void *data)
418 {
419         char tmpbuf[sizeof(struct obd_uuid)];
420
421         sscanf(buffer, "%40s", tmpbuf);
422
423         if (strncmp(tmpbuf, "nid:", 4) != 0)
424                 return lprocfs_wr_evict_client(file, buffer, count, data);
425
426         CERROR("NOT implement evict client by nid %s\n", tmpbuf);
427
428         return count;
429 }
430
431 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
432                                 int count, int *eof, void *data)
433 {
434         struct obd_device *obd = data;
435         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
436
437         return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
438 }
439
440 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
441                                 unsigned long count, void *data)
442 {
443         struct obd_device *obd = data;
444         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
445         int val, rc;
446
447         rc = lprocfs_write_helper(buffer, count, &val);
448         if (rc)
449                 return rc;
450
451         if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
452                 return -EINVAL;
453
454         if (val == LUSTRE_SEC_SPECIFY) {
455                 CWARN("security level %d will be supported in future.\n",
456                       LUSTRE_SEC_SPECIFY);
457                 return -EINVAL;
458         }
459
460         mdt->mdt_sec_level = val;
461         return count;
462 }
463
464 static int lprocfs_rd_cos(char *page, char **start, off_t off,
465                               int count, int *eof, void *data)
466 {
467         struct obd_device *obd = data;
468         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
469
470         return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
471 }
472
473 static int lprocfs_wr_cos(struct file *file, const char *buffer,
474                                   unsigned long count, void *data)
475 {
476         struct obd_device *obd = data;
477         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
478         int val, rc;
479
480         rc = lprocfs_write_helper(buffer, count, &val);
481         if (rc)
482                 return rc;
483         mdt_enable_cos(mdt, val);
484         return count;
485 }
486
487 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
488                                   int count, int *eof, void *data)
489 {
490         struct obd_device *obd = data;
491         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
492         ENTRY;
493
494         return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
495                         mdt->mdt_squash_gid);
496 }
497
498 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
499 {
500         char n[24];
501
502         *res = simple_strtoul(str, endp, 0);
503         if (str == *endp)
504                 return 1;
505
506         sprintf(n, "%lu", *res);
507         if (strncmp(n, str, *endp - str))
508                 /* overflow */
509                 return 1;
510         return 0;
511 }
512
513 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
514                                   unsigned long count, void *data)
515 {
516         struct obd_device *obd = data;
517         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
518         int rc;
519         char kernbuf[50], *tmp, *end, *errmsg;
520         unsigned long uid, gid;
521         int nouid, nogid;
522         ENTRY;
523
524         if (count >= sizeof(kernbuf)) {
525                 errmsg = "string too long";
526                 GOTO(failed, rc = -EINVAL);
527         }
528         if (copy_from_user(kernbuf, buffer, count)) {
529                 errmsg = "bad address";
530                 GOTO(failed, rc = -EFAULT);
531         }
532         kernbuf[count] = '\0';
533
534         nouid = nogid = 0;
535         if (safe_strtoul(buffer, &tmp, &uid)) {
536                 uid = mdt->mdt_squash_uid;
537                 nouid = 1;
538         }
539
540         /* skip ':' */
541         if (*tmp == ':') {
542                 tmp++;
543                 if (safe_strtoul(tmp, &end, &gid)) {
544                         gid = mdt->mdt_squash_gid;
545                         nogid = 1;
546                 }
547         } else {
548                 gid = mdt->mdt_squash_gid;
549                 nogid = 1;
550         }
551
552         mdt->mdt_squash_uid = uid;
553         mdt->mdt_squash_gid = gid;
554
555         if (nouid && nogid) {
556                 errmsg = "needs uid:gid format";
557                 GOTO(failed, rc = -EINVAL);
558         }
559
560         LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
561                       obd->obd_name,
562                       mdt->mdt_squash_uid,  mdt->mdt_squash_gid);
563         RETURN(count);
564
565  failed:
566         CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
567               obd->obd_name, buffer, errmsg, rc);
568         RETURN(rc);
569 }
570
571 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
572                                     int count, int *eof, void *data)
573 {
574         struct obd_device *obd = data;
575         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
576
577         if (mdt->mdt_nosquash_str)
578                 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
579         return snprintf(page, count, "NONE\n");
580 }
581
582 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
583                                     unsigned long count, void *data)
584 {
585         struct obd_device *obd = data;
586         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
587         int rc;
588         char *kernbuf, *errmsg;
589         struct list_head tmp;
590         ENTRY;
591
592         OBD_ALLOC(kernbuf, count + 1);
593         if (kernbuf == NULL) {
594                 errmsg = "no memory";
595                 GOTO(failed, rc = -ENOMEM);
596         }
597         if (copy_from_user(kernbuf, buffer, count)) {
598                 errmsg = "bad address";
599                 GOTO(failed, rc = -EFAULT);
600         }
601         kernbuf[count] = '\0';
602
603         if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
604                 /* empty string is special case */
605                 down_write(&mdt->mdt_squash_sem);
606                 if (!list_empty(&mdt->mdt_nosquash_nids)) {
607                         cfs_free_nidlist(&mdt->mdt_nosquash_nids);
608                         OBD_FREE(mdt->mdt_nosquash_str,
609                                  mdt->mdt_nosquash_strlen);
610                         mdt->mdt_nosquash_str = NULL;
611                         mdt->mdt_nosquash_strlen = 0;
612                 }
613                 up_write(&mdt->mdt_squash_sem);
614                 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
615                               obd->obd_name);
616                 OBD_FREE(kernbuf, count + 1);
617                 RETURN(count);
618         }
619
620         CFS_INIT_LIST_HEAD(&tmp);
621         if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
622                 errmsg = "can't parse";
623                 GOTO(failed, rc = -EINVAL);
624         }
625
626         down_write(&mdt->mdt_squash_sem);
627         if (!list_empty(&mdt->mdt_nosquash_nids)) {
628                 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
629                 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
630         }
631         mdt->mdt_nosquash_str = kernbuf;
632         mdt->mdt_nosquash_strlen = count + 1;
633         list_splice(&tmp, &mdt->mdt_nosquash_nids);
634
635         LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
636                       obd->obd_name, kernbuf);
637         up_write(&mdt->mdt_squash_sem);
638         RETURN(count);
639
640  failed:
641         CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
642               obd->obd_name, kernbuf, errmsg, rc);
643         if (kernbuf)
644                 OBD_FREE(kernbuf, count + 1);
645         RETURN(rc);
646 }
647
648 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
649                               int count, int *eof, void *data)
650 {
651         struct obd_device *obd = data;
652         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
653
654         return snprintf(page, count, "%sabled\n",
655                         mdt->mdt_som_conf ? "en" : "dis");
656 }
657
658 static int mdt_quota_off(struct mdt_device *mdt)
659 {
660         struct md_device *next = mdt->mdt_child;
661         const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
662         struct lu_env env;
663         int rc;
664
665         lu_env_init(&env, LCT_MD_THREAD);
666         rc = mqo->mqo_off(&env, next, UGQUOTA | IMMQUOTA);
667         lu_env_fini(&env);
668         return rc;
669 }
670
671 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
672                               unsigned long count, void *data)
673 {
674         struct obd_export *exp;
675         struct obd_device *obd = data;
676         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
677         char kernbuf[16];
678         unsigned long val = 0;
679         int rc;
680
681         if (count > (sizeof(kernbuf) - 1))
682                 return -EINVAL;
683
684         if (copy_from_user(kernbuf, buffer, count))
685                 return -EFAULT;
686
687         kernbuf[count] = '\0';
688
689         if (!strcmp(kernbuf, "enabled"))
690                 val = 1;
691         else if (strcmp(kernbuf, "disabled"))
692                 return -EINVAL;
693
694         if (mdt->mdt_som_conf == val)
695                 return count;
696
697         if (!obd->obd_process_conf) {
698                 CERROR("Temporary SOM change is not supported, use lctl "
699                        "conf_param for permanent setting\n");
700                 return count;
701         }
702
703         /* 1 stands for self export. */
704         list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
705                 if (exp == obd->obd_self_export)
706                         continue;
707                 if (exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)
708                         continue;
709                 /* Some clients are already connected, skip the change */
710                 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
711                               "the next mount\n", exp->exp_client_uuid.uuid,
712                               val ? "enabled" : "disabled");
713                 return count;
714         }
715
716         if ((rc = mdt_quota_off(mdt))) {
717                 if (rc == -EALREADY)
718                         rc = 0;
719                 else
720                         return rc;
721         }
722
723         mdt->mdt_som_conf = val;
724         LCONSOLE_INFO("Enabling SOM\n");
725
726         return count;
727 }
728
729 /* Temporary; for testing purposes only */
730 static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
731                               unsigned long count, void *data)
732 {
733         struct obd_device *obd = data;
734         struct obd_export *exp = NULL;
735         struct obd_uuid uuid;
736         char tmpbuf[sizeof(struct obd_uuid)];
737
738         sscanf(buffer, "%40s", tmpbuf);
739
740         obd_str2uuid(&uuid, tmpbuf);
741         exp = lustre_hash_lookup(obd->obd_uuid_hash, &uuid);
742         if (exp == NULL) {
743                 CERROR("%s: no export %s found\n",
744                        obd->obd_name, obd_uuid2str(&uuid));
745         } else {
746                 mdt_hsm_copytool_send(exp);
747                 class_export_put(exp);
748         }
749
750         return count;
751 }
752
753 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
754         { "uuid",                       lprocfs_rd_uuid,                 0, 0 },
755         { "recovery_status",            lprocfs_obd_rd_recovery_status,  0, 0 },
756         { "num_exports",                lprocfs_rd_num_exports,          0, 0 },
757         { "identity_expire",            lprocfs_rd_identity_expire,
758                                         lprocfs_wr_identity_expire,         0 },
759         { "identity_acquire_expire",    lprocfs_rd_identity_acquire_expire,
760                                         lprocfs_wr_identity_acquire_expire, 0 },
761         { "identity_upcall",            lprocfs_rd_identity_upcall,
762                                         lprocfs_wr_identity_upcall,         0 },
763         { "identity_flush",             0, lprocfs_wr_identity_flush,       0 },
764         { "identity_info",              0, lprocfs_wr_identity_info,        0 },
765         { "capa",                       lprocfs_rd_capa,
766                                         lprocfs_wr_capa,                    0 },
767         { "capa_timeout",               lprocfs_rd_capa_timeout,
768                                         lprocfs_wr_capa_timeout,            0 },
769         { "capa_key_timeout",           lprocfs_rd_ck_timeout,
770                                         lprocfs_wr_ck_timeout,              0 },
771         { "capa_count",                 lprocfs_rd_capa_count,           0, 0 },
772         { "site_stats",                 lprocfs_rd_site_stats,           0, 0 },
773         { "evict_client",               0, lprocfs_mdt_wr_evict_client,     0 },
774         { "hash_stats",                 lprocfs_obd_rd_hash,    0, 0 },
775         { "sec_level",                  lprocfs_rd_sec_level,
776                                         lprocfs_wr_sec_level,               0 },
777         { "commit_on_sharing",          lprocfs_rd_cos, lprocfs_wr_cos, 0 },
778         { "root_squash",                lprocfs_rd_root_squash,
779                                         lprocfs_wr_root_squash,             0 },
780         { "nosquash_nids",              lprocfs_rd_nosquash_nids,
781                                         lprocfs_wr_nosquash_nids,           0 },
782         { "som",                        lprocfs_rd_mdt_som,
783                                         lprocfs_wr_mdt_som, 0 },
784         { "mdccomm",                    0, lprocfs_mdt_wr_mdc,              0 },
785         { 0 }
786 };
787
788 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
789         { "num_refs",                   lprocfs_rd_numrefs,              0, 0 },
790         { 0 }
791 };
792
793 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
794 {
795     lvars->module_vars  = lprocfs_mdt_module_vars;
796     lvars->obd_vars     = lprocfs_mdt_obd_vars;
797 }