4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_lproc.c
38 * Author: Lai Siyao <lsy@clusterfs.com>
39 * Author: Fan Yong <fanyong@clusterfs.com>
42 #define DEBUG_SUBSYSTEM S_MDS
44 #include <linux/version.h>
45 #include <asm/statfs.h>
47 #include <linux/module.h>
49 /* LUSTRE_VERSION_CODE */
50 #include <lustre_ver.h>
52 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct obd_export */
57 #include <lustre_export.h>
58 /* struct obd_device */
60 #include <obd_class.h>
61 #include <lustre_mds.h>
62 #include <lprocfs_status.h>
63 #include "mdt_internal.h"
64 #include <lnet/lib-lnet.h>
67 * The rename stats output would be YAML formats, like
69 * - snapshot_time: 1234567890.123456
71 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
72 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
73 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
75 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
76 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
77 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
79 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
80 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
81 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
84 #define pct(a, b) (b ? a * 100 / b : 0)
86 static void display_rename_stats(struct seq_file *seq, char *name,
87 struct obd_histogram *hist)
89 unsigned long tot, t, cum = 0;
92 tot = lprocfs_oh_sum(hist);
94 seq_printf(seq, "- %-15s\n", name);
95 /* dir size start from 4K, start i from 10(2^10) here */
96 for (i = 0; i < OBD_HIST_MAX; i++) {
97 t = hist->oh_buckets[i];
103 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
105 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
107 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
109 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
110 t, pct(t, tot), pct(cum, tot));
117 static void rename_stats_show(struct seq_file *seq,
118 struct rename_stats *rename_stats)
122 /* this sampling races with updates */
123 do_gettimeofday(&now);
124 seq_printf(seq, "rename_stats:\n");
125 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
126 now.tv_sec, now.tv_usec);
128 display_rename_stats(seq, "same_dir",
129 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
130 display_rename_stats(seq, "crossdir_src",
131 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
132 display_rename_stats(seq, "crossdir_tgt",
133 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
138 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
140 struct mdt_device *mdt = seq->private;
142 rename_stats_show(seq, &mdt->mdt_rename_stats);
147 static ssize_t mdt_rename_stats_seq_write(struct file *file, const char *buf,
148 size_t len, loff_t *off)
150 struct seq_file *seq = file->private_data;
151 struct mdt_device *mdt = seq->private;
154 for (i = 0; i < RENAME_LAST; i++)
155 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
160 LPROC_SEQ_FOPS(mdt_rename_stats);
162 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
166 for (i = 0; i < RENAME_LAST; i++)
167 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
169 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
170 &mdt_rename_stats_fops, mdt);
173 void mdt_rename_counter_tally(struct mdt_thread_info *info,
174 struct mdt_device *mdt,
175 struct ptlrpc_request *req,
176 struct mdt_object *src,
177 struct mdt_object *tgt)
179 struct md_attr *ma = &info->mti_attr;
180 struct rename_stats *rstats = &mdt->mdt_rename_stats;
183 ma->ma_need = MA_INODE;
185 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
187 CERROR("%s: "DFID" attr_get, rc = %d\n",
188 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
193 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
194 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
195 (unsigned int)ma->ma_attr.la_size);
199 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
200 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
201 (unsigned int)ma->ma_attr.la_size);
203 ma->ma_need = MA_INODE;
205 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
207 CERROR("%s: "DFID" attr_get, rc = %d\n",
208 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
212 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
213 (unsigned int)ma->ma_attr.la_size);
216 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
218 struct obd_device *obd = mdt2obd_dev(mdt);
219 struct lprocfs_static_vars lvars;
223 LASSERT(name != NULL);
225 lprocfs_mdt_init_vars(&lvars);
226 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
228 CERROR("%s: cannot create proc entries: rc = %d\n",
229 mdt_obd_name(mdt), rc);
232 rc = hsm_cdt_procfs_init(mdt);
234 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
235 mdt_obd_name(mdt), rc);
238 ptlrpc_lprocfs_register_obd(obd);
240 obd->obd_proc_exports_entry = proc_mkdir("exports",
241 obd->obd_proc_entry);
242 if (obd->obd_proc_exports_entry)
243 lprocfs_add_simple(obd->obd_proc_exports_entry,
244 "clear", lprocfs_nid_stats_clear_read,
245 lprocfs_nid_stats_clear_write, obd, NULL);
246 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
249 mdt_stats_counter_init(obd->obd_md_stats);
251 rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
252 mdt_stats_counter_init);
254 rc = lproc_mdt_attach_rename_seqstat(mdt);
256 CERROR("%s: MDT can not create rename stats rc = %d\n",
257 mdt_obd_name(mdt), rc);
262 void mdt_procfs_fini(struct mdt_device *mdt)
264 struct obd_device *obd = mdt2obd_dev(mdt);
266 if (obd->obd_proc_exports_entry) {
267 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
268 obd->obd_proc_exports_entry = NULL;
270 lprocfs_free_per_client_stats(obd);
271 lprocfs_obd_cleanup(obd);
272 hsm_cdt_procfs_fini(mdt);
273 ptlrpc_lprocfs_unregister_obd(obd);
274 lprocfs_free_md_stats(obd);
275 lprocfs_free_obd_stats(obd);
276 lprocfs_job_stats_fini(obd);
279 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
280 int count, int *eof, void *data)
282 struct obd_device *obd = data;
283 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
286 return snprintf(page, count, "%u\n",
287 mdt->mdt_identity_cache->uc_entry_expire);
290 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
291 unsigned long count, void *data)
293 struct obd_device *obd = data;
294 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
297 rc = lprocfs_write_helper(buffer, count, &val);
301 mdt->mdt_identity_cache->uc_entry_expire = val;
305 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
306 off_t off, int count, int *eof,
309 struct obd_device *obd = data;
310 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
313 return snprintf(page, count, "%u\n",
314 mdt->mdt_identity_cache->uc_acquire_expire);
317 static int lprocfs_wr_identity_acquire_expire(struct file *file,
322 struct obd_device *obd = data;
323 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
326 rc = lprocfs_write_helper(buffer, count, &val);
330 mdt->mdt_identity_cache->uc_acquire_expire = val;
334 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
335 int count, int *eof, void *data)
337 struct obd_device *obd = data;
338 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
339 struct upcall_cache *hash = mdt->mdt_identity_cache;
343 read_lock(&hash->uc_upcall_rwlock);
344 len = snprintf(page, count, "%s\n", hash->uc_upcall);
345 read_unlock(&hash->uc_upcall_rwlock);
349 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
350 unsigned long count, void *data)
352 struct obd_device *obd = data;
353 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
354 struct upcall_cache *hash = mdt->mdt_identity_cache;
358 if (count >= UC_CACHE_UPCALL_MAXPATH) {
359 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
362 OBD_ALLOC(kernbuf, count + 1);
364 GOTO(failed, rc = -ENOMEM);
365 if (copy_from_user(kernbuf, buffer, count))
366 GOTO(failed, rc = -EFAULT);
368 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
369 write_lock(&hash->uc_upcall_rwlock);
370 sscanf(kernbuf, "%s", hash->uc_upcall);
371 write_unlock(&hash->uc_upcall_rwlock);
373 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
374 CWARN("%s: write to upcall name %s\n",
375 mdt_obd_name(mdt), hash->uc_upcall);
377 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
378 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
379 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
381 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
383 OBD_FREE(kernbuf, count + 1);
388 OBD_FREE(kernbuf, count + 1);
392 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
393 unsigned long count, void *data)
395 struct obd_device *obd = data;
396 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
399 rc = lprocfs_write_helper(buffer, count, &uid);
403 mdt_flush_identity(mdt->mdt_identity_cache, uid);
407 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
408 unsigned long count, void *data)
410 struct obd_device *obd = data;
411 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
412 struct identity_downcall_data *param;
413 int size = sizeof(*param), rc, checked = 0;
417 CERROR("%s: invalid data count = %lu, size = %d\n",
418 mdt_obd_name(mdt), count, size);
422 OBD_ALLOC(param, size);
426 if (copy_from_user(param, buffer, size)) {
427 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
428 GOTO(out, rc = -EFAULT);
433 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
434 CERROR("%s: MDS identity downcall bad params\n",
436 GOTO(out, rc = -EINVAL);
439 if (param->idd_nperms > N_PERMS_MAX) {
440 CERROR("%s: perm count %d more than maximum %d\n",
441 mdt_obd_name(mdt), param->idd_nperms,
443 GOTO(out, rc = -EINVAL);
446 if (param->idd_ngroups > NGROUPS_MAX) {
447 CERROR("%s: group count %d more than maximum %d\n",
448 mdt_obd_name(mdt), param->idd_ngroups,
450 GOTO(out, rc = -EINVAL);
453 if (param->idd_ngroups) {
454 rc = param->idd_ngroups; /* save idd_ngroups */
455 OBD_FREE(param, size);
456 size = offsetof(struct identity_downcall_data,
462 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
463 param->idd_uid, param);
467 OBD_FREE(param, size);
469 return rc ? rc : count;
473 static int lprocfs_rd_capa(char *page, char **start, off_t off,
474 int count, int *eof, void *data)
476 struct obd_device *obd = data;
477 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
479 return snprintf(page, count, "capability on: %s %s\n",
480 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
481 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
484 static int lprocfs_wr_capa(struct file *file, const char *buffer,
485 unsigned long count, void *data)
487 struct obd_device *obd = data;
488 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
491 rc = lprocfs_write_helper(buffer, count, &val);
495 if (val < 0 || val > 3) {
496 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
497 " 0: disable fid capability\n"
498 " 2: enable MDS fid capability\n"
499 " 3: enable both MDS and OSS fid capability\n");
503 /* OSS fid capability needs enable both MDS and OSS fid capability on
506 CERROR("can't enable OSS fid capability only, you should use "
507 "'3' to enable both MDS and OSS fid capability.\n");
511 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
512 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
513 mdt->mdt_capa_conf = 1;
514 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
516 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
517 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
519 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
523 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
524 int count, int *eof, void *data)
526 return snprintf(page, count, "%d %d\n",
527 capa_count[CAPA_SITE_CLIENT],
528 capa_count[CAPA_SITE_SERVER]);
531 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
532 int count, int *eof, void *data)
534 struct obd_device *obd = data;
535 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
537 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
540 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
541 int count, int *eof, void *data)
543 struct obd_device *obd = data;
544 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
546 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
549 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
550 unsigned long count, void *data)
552 struct obd_device *obd = data;
553 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
556 rc = lprocfs_write_helper(buffer, count, &val);
560 mdt->mdt_capa_timeout = (unsigned long)val;
561 mdt->mdt_capa_conf = 1;
565 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
566 int *eof, void *data)
568 struct obd_device *obd = data;
569 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
571 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
574 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
575 unsigned long count, void *data)
577 struct obd_device *obd = data;
578 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
581 rc = lprocfs_write_helper(buffer, count, &val);
585 mdt->mdt_ck_timeout = (unsigned long)val;
586 mdt->mdt_capa_conf = 1;
590 #define BUFLEN (UUID_MAX + 4)
592 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
593 unsigned long count, void *data)
598 OBD_ALLOC(kbuf, BUFLEN);
603 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
604 * bytes into kbuf, to ensure that the string is NUL-terminated.
605 * UUID_MAX should include a trailing NUL already.
607 if (copy_from_user(kbuf, buffer,
608 min_t(unsigned long, BUFLEN - 1, count))) {
612 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
614 if (strncmp(tmpbuf, "nid:", 4) != 0) {
615 count = lprocfs_wr_evict_client(file, buffer, count, data);
619 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
622 OBD_FREE(kbuf, BUFLEN);
628 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
629 int count, int *eof, void *data)
631 struct obd_device *obd = data;
632 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
634 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
637 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
638 unsigned long count, void *data)
640 struct obd_device *obd = data;
641 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
644 rc = lprocfs_write_helper(buffer, count, &val);
648 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
651 if (val == LUSTRE_SEC_SPECIFY) {
652 CWARN("security level %d will be supported in future.\n",
657 mdt->mdt_sec_level = val;
661 static int lprocfs_rd_cos(char *page, char **start, off_t off,
662 int count, int *eof, void *data)
664 struct obd_device *obd = data;
665 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
667 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
670 static int lprocfs_wr_cos(struct file *file, const char *buffer,
671 unsigned long count, void *data)
673 struct obd_device *obd = data;
674 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
677 rc = lprocfs_write_helper(buffer, count, &val);
680 mdt_enable_cos(mdt, val);
684 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
685 int count, int *eof, void *data)
687 struct obd_device *obd = data;
688 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
690 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
691 mdt->mdt_squash_gid);
694 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
698 *res = simple_strtoul(str, endp, 0);
702 sprintf(n, "%lu", *res);
703 if (strncmp(n, str, *endp - str))
709 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
710 unsigned long count, void *data)
712 struct obd_device *obd = data;
713 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
715 char kernbuf[50], *tmp, *end, *errmsg;
716 unsigned long uid, gid;
720 if (count >= sizeof(kernbuf)) {
721 errmsg = "string too long";
722 GOTO(failed, rc = -EINVAL);
724 if (copy_from_user(kernbuf, buffer, count)) {
725 errmsg = "bad address";
726 GOTO(failed, rc = -EFAULT);
728 kernbuf[count] = '\0';
731 if (safe_strtoul(buffer, &tmp, &uid)) {
732 uid = mdt->mdt_squash_uid;
739 if (safe_strtoul(tmp, &end, &gid)) {
740 gid = mdt->mdt_squash_gid;
744 gid = mdt->mdt_squash_gid;
748 mdt->mdt_squash_uid = uid;
749 mdt->mdt_squash_gid = gid;
751 if (nouid && nogid) {
752 errmsg = "needs uid:gid format";
753 GOTO(failed, rc = -EINVAL);
756 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
758 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
762 CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
763 mdt_obd_name(mdt), buffer, errmsg, rc);
767 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
768 int count, int *eof, void *data)
770 struct obd_device *obd = data;
771 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
773 if (mdt->mdt_nosquash_str)
774 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
775 return snprintf(page, count, "NONE\n");
778 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
779 unsigned long count, void *data)
781 struct obd_device *obd = data;
782 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
784 char *kernbuf, *errmsg;
788 OBD_ALLOC(kernbuf, count + 1);
789 if (kernbuf == NULL) {
790 errmsg = "no memory";
791 GOTO(failed, rc = -ENOMEM);
793 if (copy_from_user(kernbuf, buffer, count)) {
794 errmsg = "bad address";
795 GOTO(failed, rc = -EFAULT);
797 kernbuf[count] = '\0';
799 if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
800 /* empty string is special case */
801 down_write(&mdt->mdt_squash_sem);
802 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
803 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
804 OBD_FREE(mdt->mdt_nosquash_str,
805 mdt->mdt_nosquash_strlen);
806 mdt->mdt_nosquash_str = NULL;
807 mdt->mdt_nosquash_strlen = 0;
809 up_write(&mdt->mdt_squash_sem);
810 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
812 OBD_FREE(kernbuf, count + 1);
816 CFS_INIT_LIST_HEAD(&tmp);
817 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
818 errmsg = "can't parse";
819 GOTO(failed, rc = -EINVAL);
822 down_write(&mdt->mdt_squash_sem);
823 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
824 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
825 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
827 mdt->mdt_nosquash_str = kernbuf;
828 mdt->mdt_nosquash_strlen = count + 1;
829 cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
831 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
832 mdt_obd_name(mdt), kernbuf);
833 up_write(&mdt->mdt_squash_sem);
837 CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
838 mdt_obd_name(mdt), kernbuf, errmsg, rc);
840 OBD_FREE(kernbuf, count + 1);
844 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
845 int count, int *eof, void *data)
847 struct obd_device *obd = data;
848 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
850 return snprintf(page, count, "%sabled\n",
851 mdt->mdt_som_conf ? "en" : "dis");
854 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
855 unsigned long count, void *data)
857 struct obd_export *exp;
858 struct obd_device *obd = data;
859 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
861 unsigned long val = 0;
863 if (count > (sizeof(kernbuf) - 1))
866 if (copy_from_user(kernbuf, buffer, count))
869 kernbuf[count] = '\0';
871 if (!strcmp(kernbuf, "enabled"))
873 else if (strcmp(kernbuf, "disabled"))
876 if (mdt->mdt_som_conf == val)
879 if (!obd->obd_process_conf) {
880 CERROR("Temporary SOM change is not supported, use lctl "
881 "conf_param for permanent setting\n");
885 /* 1 stands for self export. */
886 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
887 if (exp == obd->obd_self_export)
889 if (exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS)
891 /* Some clients are already connected, skip the change */
892 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
893 "the next mount\n", exp->exp_client_uuid.uuid,
894 val ? "enabled" : "disabled");
898 mdt->mdt_som_conf = val;
899 LCONSOLE_INFO("Enabling SOM\n");
904 static int lprocfs_rd_enable_remote_dir(char *page, char **start, off_t off,
905 int count, int *eof, void *data)
907 struct obd_device *obd = data;
908 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
910 return snprintf(page, count, "%u\n", mdt->mdt_enable_remote_dir);
913 static int lprocfs_wr_enable_remote_dir(struct file *file, const char *buffer,
914 unsigned long count, void *data)
916 struct obd_device *obd = data;
917 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
921 rc = lprocfs_write_helper(buffer, count, &val);
928 mdt->mdt_enable_remote_dir = val;
932 static int lprocfs_rd_enable_remote_dir_gid(char *page, char **start, off_t off,
933 int count, int *eof, void *data)
935 struct obd_device *obd = data;
936 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
938 return snprintf(page, count, "%d\n",
939 (int)mdt->mdt_enable_remote_dir_gid);
942 static int lprocfs_wr_enable_remote_dir_gid(struct file *file,
944 unsigned long count, void *data)
946 struct obd_device *obd = data;
947 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
951 rc = lprocfs_write_helper(buffer, count, &val);
955 mdt->mdt_enable_remote_dir_gid = val;
959 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
960 { "uuid", lprocfs_rd_uuid, NULL,
962 { "recovery_status", lprocfs_obd_rd_recovery_status, NULL,
964 { "num_exports", lprocfs_rd_num_exports, NULL,
966 { "identity_expire", lprocfs_rd_identity_expire,
967 lprocfs_wr_identity_expire,
969 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
970 lprocfs_wr_identity_acquire_expire,
972 { "identity_upcall", lprocfs_rd_identity_upcall,
973 lprocfs_wr_identity_upcall,
975 { "identity_flush", NULL, lprocfs_wr_identity_flush,
977 { "identity_info", NULL, lprocfs_wr_identity_info,
979 { "capa", lprocfs_rd_capa,
982 { "capa_timeout", lprocfs_rd_capa_timeout,
983 lprocfs_wr_capa_timeout,
985 { "capa_key_timeout", lprocfs_rd_ck_timeout,
986 lprocfs_wr_ck_timeout,
988 { "capa_count", lprocfs_rd_capa_count, NULL,
990 { "site_stats", lprocfs_rd_site_stats, NULL,
992 { "evict_client", NULL, lprocfs_mdt_wr_evict_client,
994 { "hash_stats", lprocfs_obd_rd_hash, NULL,
996 { "sec_level", lprocfs_rd_sec_level,
997 lprocfs_wr_sec_level,
999 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos,
1001 { "root_squash", lprocfs_rd_root_squash,
1002 lprocfs_wr_root_squash,
1004 { "nosquash_nids", lprocfs_rd_nosquash_nids,
1005 lprocfs_wr_nosquash_nids,
1007 { "som", lprocfs_rd_mdt_som,
1010 { "instance", lprocfs_target_rd_instance, NULL,
1012 { "ir_factor", lprocfs_obd_rd_ir_factor,
1013 lprocfs_obd_wr_ir_factor,
1015 { "job_cleanup_interval", lprocfs_rd_job_interval,
1016 lprocfs_wr_job_interval,
1018 { "enable_remote_dir", lprocfs_rd_enable_remote_dir,
1019 lprocfs_wr_enable_remote_dir,
1021 { "enable_remote_dir_gid", lprocfs_rd_enable_remote_dir_gid,
1022 lprocfs_wr_enable_remote_dir_gid,
1024 { "hsm_control", lprocfs_rd_hsm_cdt_control,
1025 lprocfs_wr_hsm_cdt_control,
1030 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
1031 { "num_refs", lprocfs_rd_numrefs, NULL,
1036 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
1038 lvars->module_vars = lprocfs_mdt_module_vars;
1039 lvars->obd_vars = lprocfs_mdt_obd_vars;
1042 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
1043 { "uuid", lprocfs_rd_uuid, NULL, NULL, NULL, 0 },
1047 struct lprocfs_vars lprocfs_mds_module_vars[] = {
1048 { "num_refs", lprocfs_rd_numrefs, NULL, NULL, NULL, 0 },
1052 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1054 struct obd_export *exp = req->rq_export;
1056 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1057 lprocfs_counter_incr(exp->exp_obd->obd_md_stats, opcode);
1058 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1059 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1060 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1061 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1062 lprocfs_job_stats_log(exp->exp_obd,
1063 lustre_msg_get_jobid(req->rq_reqmsg),
1067 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1069 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
1070 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
1071 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
1072 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
1073 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
1074 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
1075 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
1076 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
1077 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
1078 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
1079 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
1080 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
1081 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
1082 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
1083 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
1084 "samedir_rename", "reqs");
1085 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
1086 "crossdir_rename", "reqs");