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, 2012, 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 <lustre_mdt.h>
63 #include <lprocfs_status.h>
64 #include "mdt_internal.h"
65 #include <lnet/lib-lnet.h>
68 * The rename stats output would be YAML formats, like
70 * - snapshot_time: 1234567890.123456
72 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
73 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
74 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
76 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
77 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
78 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
80 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
81 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
82 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
85 #define pct(a, b) (b ? a * 100 / b : 0)
87 static void display_rename_stats(struct seq_file *seq, char *name,
88 struct obd_histogram *hist)
90 unsigned long tot, t, cum = 0;
93 tot = lprocfs_oh_sum(hist);
95 seq_printf(seq, "- %-15s\n", name);
96 /* dir size start from 4K, start i from 10(2^10) here */
97 for (i = 0; i < OBD_HIST_MAX; i++) {
98 t = hist->oh_buckets[i];
104 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
106 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
108 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
110 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
111 t, pct(t, tot), pct(cum, tot));
118 static void rename_stats_show(struct seq_file *seq,
119 struct rename_stats *rename_stats)
123 /* this sampling races with updates */
124 do_gettimeofday(&now);
125 seq_printf(seq, "rename_stats:\n");
126 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
127 now.tv_sec, now.tv_usec);
129 display_rename_stats(seq, "same_dir",
130 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
131 display_rename_stats(seq, "crossdir_src",
132 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
133 display_rename_stats(seq, "crossdir_tgt",
134 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
139 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
141 struct mdt_device *mdt = seq->private;
143 rename_stats_show(seq, &mdt->mdt_rename_stats);
148 static ssize_t mdt_rename_stats_seq_write(struct file *file, const char *buf,
149 size_t len, loff_t *off)
151 struct seq_file *seq = file->private_data;
152 struct mdt_device *mdt = seq->private;
155 for (i = 0; i < RENAME_LAST; i++)
156 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
161 LPROC_SEQ_FOPS(mdt_rename_stats);
163 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
165 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
166 struct obd_device *obd = ld->ld_obd;
169 for (i = 0; i < RENAME_LAST; i++)
170 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
172 return lprocfs_obd_seq_create(obd, "rename_stats", 0644,
173 &mdt_rename_stats_fops, mdt);
176 void mdt_rename_counter_tally(struct mdt_thread_info *info,
177 struct mdt_device *mdt,
178 struct ptlrpc_request *req,
179 struct mdt_object *src,
180 struct mdt_object *tgt)
182 struct md_attr *ma = &info->mti_attr;
183 struct rename_stats *rstats = &mdt->mdt_rename_stats;
186 ma->ma_need = MA_INODE;
188 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
190 CERROR("%s: "DFID" attr_get, rc = %d\n",
191 req->rq_export->exp_obd->obd_name,
192 PFID(mdt_object_fid(src)), rc);
197 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
198 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
199 (unsigned int)ma->ma_attr.la_size);
203 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
204 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
205 (unsigned int)ma->ma_attr.la_size);
207 ma->ma_need = MA_INODE;
209 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
211 CERROR("%s: "DFID" attr_get, rc = %d\n",
212 req->rq_export->exp_obd->obd_name,
213 PFID(mdt_object_fid(tgt)), rc);
217 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
218 (unsigned int)ma->ma_attr.la_size);
221 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
223 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
224 struct obd_device *obd = ld->ld_obd;
225 struct lprocfs_static_vars lvars;
229 LASSERT(name != NULL);
231 lprocfs_mdt_init_vars(&lvars);
232 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
234 CERROR("Can't init lprocfs, rc %d\n", rc);
237 ptlrpc_lprocfs_register_obd(obd);
239 obd->obd_proc_exports_entry = proc_mkdir("exports",
240 obd->obd_proc_entry);
241 if (obd->obd_proc_exports_entry)
242 lprocfs_add_simple(obd->obd_proc_exports_entry,
243 "clear", lprocfs_nid_stats_clear_read,
244 lprocfs_nid_stats_clear_write, obd, NULL);
245 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
248 mdt_stats_counter_init(obd->md_stats);
250 rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
251 mdt_stats_counter_init);
253 rc = lproc_mdt_attach_rename_seqstat(mdt);
255 CERROR("%s: MDT can not create rename stats rc = %d\n",
261 int mdt_procfs_fini(struct mdt_device *mdt)
263 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
264 struct obd_device *obd = ld->ld_obd;
266 lprocfs_job_stats_fini(obd);
268 if (obd->obd_proc_exports_entry) {
269 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
270 obd->obd_proc_exports_entry = NULL;
272 lprocfs_free_per_client_stats(obd);
273 lprocfs_obd_cleanup(obd);
274 ptlrpc_lprocfs_unregister_obd(obd);
275 lprocfs_free_md_stats(obd);
276 lprocfs_free_obd_stats(obd);
281 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
282 int count, int *eof, void *data)
284 struct obd_device *obd = data;
285 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
288 return snprintf(page, count, "%u\n",
289 mdt->mdt_identity_cache->uc_entry_expire);
292 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
293 unsigned long count, void *data)
295 struct obd_device *obd = data;
296 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
299 rc = lprocfs_write_helper(buffer, count, &val);
303 mdt->mdt_identity_cache->uc_entry_expire = val;
307 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
308 off_t off, int count, int *eof,
311 struct obd_device *obd = data;
312 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
315 return snprintf(page, count, "%u\n",
316 mdt->mdt_identity_cache->uc_acquire_expire);
319 static int lprocfs_wr_identity_acquire_expire(struct file *file,
324 struct obd_device *obd = data;
325 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
328 rc = lprocfs_write_helper(buffer, count, &val);
332 mdt->mdt_identity_cache->uc_acquire_expire = val;
336 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
337 int count, int *eof, void *data)
339 struct obd_device *obd = data;
340 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
341 struct upcall_cache *hash = mdt->mdt_identity_cache;
345 read_lock(&hash->uc_upcall_rwlock);
346 len = snprintf(page, count, "%s\n", hash->uc_upcall);
347 read_unlock(&hash->uc_upcall_rwlock);
351 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
352 unsigned long count, void *data)
354 struct obd_device *obd = data;
355 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
356 struct upcall_cache *hash = mdt->mdt_identity_cache;
360 if (count >= UC_CACHE_UPCALL_MAXPATH) {
361 CERROR("%s: identity upcall too long\n", obd->obd_name);
364 OBD_ALLOC(kernbuf, count + 1);
366 GOTO(failed, rc = -ENOMEM);
367 if (cfs_copy_from_user(kernbuf, buffer, count))
368 GOTO(failed, rc = -EFAULT);
370 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
371 write_lock(&hash->uc_upcall_rwlock);
372 sscanf(kernbuf, "%s", hash->uc_upcall);
373 write_unlock(&hash->uc_upcall_rwlock);
375 if (strcmp(hash->uc_name, obd->obd_name) != 0)
376 CWARN("%s: write to upcall name %s\n",
377 obd->obd_name, hash->uc_upcall);
379 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
380 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
381 "cause unexpected \"EACCESS\"\n", obd->obd_name);
383 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
384 OBD_FREE(kernbuf, count + 1);
389 OBD_FREE(kernbuf, count + 1);
393 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
394 unsigned long count, void *data)
396 struct obd_device *obd = data;
397 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
400 rc = lprocfs_write_helper(buffer, count, &uid);
404 mdt_flush_identity(mdt->mdt_identity_cache, uid);
408 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
409 unsigned long count, void *data)
411 struct obd_device *obd = data;
412 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
413 struct identity_downcall_data *param;
414 int size = sizeof(*param), rc, checked = 0;
418 CERROR("%s: invalid data count = %lu, size = %d\n",
419 obd->obd_name, count, size);
423 OBD_ALLOC(param, size);
427 if (cfs_copy_from_user(param, buffer, size)) {
428 CERROR("%s: bad identity data\n", obd->obd_name);
429 GOTO(out, rc = -EFAULT);
434 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
435 CERROR("%s: MDS identity downcall bad params\n",
437 GOTO(out, rc = -EINVAL);
440 if (param->idd_nperms > N_PERMS_MAX) {
441 CERROR("%s: perm count %d more than maximum %d\n",
442 obd->obd_name, param->idd_nperms, N_PERMS_MAX);
443 GOTO(out, rc = -EINVAL);
446 if (param->idd_ngroups > NGROUPS_MAX) {
447 CERROR("%s: group count %d more than maximum %d\n",
448 obd->obd_name, param->idd_ngroups, NGROUPS_MAX);
449 GOTO(out, rc = -EINVAL);
452 if (param->idd_ngroups) {
453 rc = param->idd_ngroups; /* save idd_ngroups */
454 OBD_FREE(param, size);
455 size = offsetof(struct identity_downcall_data,
461 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
462 param->idd_uid, param);
466 OBD_FREE(param, size);
468 return rc ? rc : count;
472 static int lprocfs_rd_capa(char *page, char **start, off_t off,
473 int count, int *eof, void *data)
475 struct obd_device *obd = data;
476 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
478 return snprintf(page, count, "capability on: %s %s\n",
479 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
480 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
483 static int lprocfs_wr_capa(struct file *file, const char *buffer,
484 unsigned long count, void *data)
486 struct obd_device *obd = data;
487 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
490 rc = lprocfs_write_helper(buffer, count, &val);
494 if (val < 0 || val > 3) {
495 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
496 " 0: disable fid capability\n"
497 " 2: enable MDS fid capability\n"
498 " 3: enable both MDS and OSS fid capability\n");
502 /* OSS fid capability needs enable both MDS and OSS fid capability on
505 CERROR("can't enable OSS fid capability only, you should use "
506 "'3' to enable both MDS and OSS fid capability.\n");
510 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
511 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
512 mdt->mdt_capa_conf = 1;
513 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
515 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
516 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
518 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
522 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
523 int count, int *eof, void *data)
525 return snprintf(page, count, "%d %d\n",
526 capa_count[CAPA_SITE_CLIENT],
527 capa_count[CAPA_SITE_SERVER]);
530 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
531 int count, int *eof, void *data)
533 struct obd_device *obd = data;
534 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
536 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
539 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
540 int count, int *eof, void *data)
542 struct obd_device *obd = data;
543 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
545 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
548 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
549 unsigned long count, void *data)
551 struct obd_device *obd = data;
552 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
555 rc = lprocfs_write_helper(buffer, count, &val);
559 mdt->mdt_capa_timeout = (unsigned long)val;
560 mdt->mdt_capa_conf = 1;
564 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
565 int *eof, void *data)
567 struct obd_device *obd = data;
568 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
570 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
573 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
574 unsigned long count, void *data)
576 struct obd_device *obd = data;
577 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
580 rc = lprocfs_write_helper(buffer, count, &val);
584 mdt->mdt_ck_timeout = (unsigned long)val;
585 mdt->mdt_capa_conf = 1;
589 #define BUFLEN (UUID_MAX + 4)
591 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
592 unsigned long count, void *data)
597 OBD_ALLOC(kbuf, BUFLEN);
602 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
603 * bytes into kbuf, to ensure that the string is NUL-terminated.
604 * UUID_MAX should include a trailing NUL already.
606 if (cfs_copy_from_user(kbuf, buffer,
607 min_t(unsigned long, BUFLEN - 1, count))) {
611 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
613 if (strncmp(tmpbuf, "nid:", 4) != 0) {
614 count = lprocfs_wr_evict_client(file, buffer, count, data);
618 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
621 OBD_FREE(kbuf, BUFLEN);
627 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
628 int count, int *eof, void *data)
630 struct obd_device *obd = data;
631 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
633 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
636 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
637 unsigned long count, void *data)
639 struct obd_device *obd = data;
640 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
643 rc = lprocfs_write_helper(buffer, count, &val);
647 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
650 if (val == LUSTRE_SEC_SPECIFY) {
651 CWARN("security level %d will be supported in future.\n",
656 mdt->mdt_sec_level = val;
660 static int lprocfs_rd_cos(char *page, char **start, off_t off,
661 int count, int *eof, void *data)
663 struct obd_device *obd = data;
664 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
666 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
669 static int lprocfs_wr_cos(struct file *file, const char *buffer,
670 unsigned long count, void *data)
672 struct obd_device *obd = data;
673 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
676 rc = lprocfs_write_helper(buffer, count, &val);
679 mdt_enable_cos(mdt, val);
683 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
684 int count, int *eof, void *data)
686 struct obd_device *obd = data;
687 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
689 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
690 mdt->mdt_squash_gid);
693 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
697 *res = simple_strtoul(str, endp, 0);
701 sprintf(n, "%lu", *res);
702 if (strncmp(n, str, *endp - str))
708 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
709 unsigned long count, void *data)
711 struct obd_device *obd = data;
712 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
714 char kernbuf[50], *tmp, *end, *errmsg;
715 unsigned long uid, gid;
719 if (count >= sizeof(kernbuf)) {
720 errmsg = "string too long";
721 GOTO(failed, rc = -EINVAL);
723 if (cfs_copy_from_user(kernbuf, buffer, count)) {
724 errmsg = "bad address";
725 GOTO(failed, rc = -EFAULT);
727 kernbuf[count] = '\0';
730 if (safe_strtoul(buffer, &tmp, &uid)) {
731 uid = mdt->mdt_squash_uid;
738 if (safe_strtoul(tmp, &end, &gid)) {
739 gid = mdt->mdt_squash_gid;
743 gid = mdt->mdt_squash_gid;
747 mdt->mdt_squash_uid = uid;
748 mdt->mdt_squash_gid = gid;
750 if (nouid && nogid) {
751 errmsg = "needs uid:gid format";
752 GOTO(failed, rc = -EINVAL);
755 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
757 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
761 CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
762 obd->obd_name, buffer, errmsg, rc);
766 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
767 int count, int *eof, void *data)
769 struct obd_device *obd = data;
770 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
772 if (mdt->mdt_nosquash_str)
773 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
774 return snprintf(page, count, "NONE\n");
777 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
778 unsigned long count, void *data)
780 struct obd_device *obd = data;
781 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
783 char *kernbuf, *errmsg;
787 OBD_ALLOC(kernbuf, count + 1);
788 if (kernbuf == NULL) {
789 errmsg = "no memory";
790 GOTO(failed, rc = -ENOMEM);
792 if (cfs_copy_from_user(kernbuf, buffer, count)) {
793 errmsg = "bad address";
794 GOTO(failed, rc = -EFAULT);
796 kernbuf[count] = '\0';
798 if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
799 /* empty string is special case */
800 down_write(&mdt->mdt_squash_sem);
801 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
802 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
803 OBD_FREE(mdt->mdt_nosquash_str,
804 mdt->mdt_nosquash_strlen);
805 mdt->mdt_nosquash_str = NULL;
806 mdt->mdt_nosquash_strlen = 0;
808 up_write(&mdt->mdt_squash_sem);
809 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
811 OBD_FREE(kernbuf, count + 1);
815 CFS_INIT_LIST_HEAD(&tmp);
816 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
817 errmsg = "can't parse";
818 GOTO(failed, rc = -EINVAL);
821 down_write(&mdt->mdt_squash_sem);
822 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
823 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
824 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
826 mdt->mdt_nosquash_str = kernbuf;
827 mdt->mdt_nosquash_strlen = count + 1;
828 cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
830 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
831 obd->obd_name, kernbuf);
832 up_write(&mdt->mdt_squash_sem);
836 CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
837 obd->obd_name, kernbuf, errmsg, rc);
839 OBD_FREE(kernbuf, count + 1);
843 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
844 int count, int *eof, void *data)
846 struct obd_device *obd = data;
847 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
849 return snprintf(page, count, "%sabled\n",
850 mdt->mdt_som_conf ? "en" : "dis");
853 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
854 unsigned long count, void *data)
856 struct obd_export *exp;
857 struct obd_device *obd = data;
858 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
860 unsigned long val = 0;
862 if (count > (sizeof(kernbuf) - 1))
865 if (cfs_copy_from_user(kernbuf, buffer, count))
868 kernbuf[count] = '\0';
870 if (!strcmp(kernbuf, "enabled"))
872 else if (strcmp(kernbuf, "disabled"))
875 if (mdt->mdt_som_conf == val)
878 if (!obd->obd_process_conf) {
879 CERROR("Temporary SOM change is not supported, use lctl "
880 "conf_param for permanent setting\n");
884 /* 1 stands for self export. */
885 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
886 if (exp == obd->obd_self_export)
888 if (exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS)
890 /* Some clients are already connected, skip the change */
891 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
892 "the next mount\n", exp->exp_client_uuid.uuid,
893 val ? "enabled" : "disabled");
897 mdt->mdt_som_conf = val;
898 LCONSOLE_INFO("Enabling SOM\n");
903 /* Temporary; for testing purposes only */
904 static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
905 unsigned long count, void *data)
907 struct obd_device *obd = data;
908 struct obd_export *exp = NULL;
909 struct obd_uuid *uuid;
913 OBD_ALLOC(kbuf, UUID_MAX);
918 * OBD_ALLOC() will zero kbuf, but we only copy UUID_MAX - 1
919 * bytes into kbuf, to ensure that the string is NUL-terminated.
920 * UUID_MAX should include a trailing NUL already.
922 if (cfs_copy_from_user(kbuf, buffer,
923 min_t(unsigned long, UUID_MAX - 1, count))) {
927 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, UUID_MAX - 1, count));
929 OBD_ALLOC(uuid, UUID_MAX);
935 obd_str2uuid(uuid, tmpbuf);
936 exp = cfs_hash_lookup(obd->obd_uuid_hash, uuid);
938 CERROR("%s: no export %s found\n",
939 obd->obd_name, obd_uuid2str(uuid));
941 mdt_hsm_copytool_send(exp);
942 class_export_put(exp);
945 OBD_FREE(uuid, UUID_MAX);
947 OBD_FREE(kbuf, UUID_MAX);
951 static int lprocfs_rd_enable_remote_dir(char *page, char **start, off_t off,
952 int count, int *eof, void *data)
954 struct obd_device *obd = data;
955 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
957 return snprintf(page, count, "%u\n", mdt->mdt_enable_remote_dir);
960 static int lprocfs_wr_enable_remote_dir(struct file *file, const char *buffer,
961 unsigned long count, void *data)
963 struct obd_device *obd = data;
964 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
968 rc = lprocfs_write_helper(buffer, count, &val);
972 if (val < 0 || val > 1)
975 mdt->mdt_enable_remote_dir = val;
979 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
980 { "uuid", lprocfs_rd_uuid, 0, 0 },
981 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
982 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
983 { "identity_expire", lprocfs_rd_identity_expire,
984 lprocfs_wr_identity_expire, 0 },
985 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
986 lprocfs_wr_identity_acquire_expire, 0 },
987 { "identity_upcall", lprocfs_rd_identity_upcall,
988 lprocfs_wr_identity_upcall, 0 },
989 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
990 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
991 { "capa", lprocfs_rd_capa,
992 lprocfs_wr_capa, 0 },
993 { "capa_timeout", lprocfs_rd_capa_timeout,
994 lprocfs_wr_capa_timeout, 0 },
995 { "capa_key_timeout", lprocfs_rd_ck_timeout,
996 lprocfs_wr_ck_timeout, 0 },
997 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
998 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
999 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
1000 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
1001 { "sec_level", lprocfs_rd_sec_level,
1002 lprocfs_wr_sec_level, 0 },
1003 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
1004 { "root_squash", lprocfs_rd_root_squash,
1005 lprocfs_wr_root_squash, 0 },
1006 { "nosquash_nids", lprocfs_rd_nosquash_nids,
1007 lprocfs_wr_nosquash_nids, 0 },
1008 { "som", lprocfs_rd_mdt_som,
1009 lprocfs_wr_mdt_som, 0 },
1010 { "mdccomm", 0, lprocfs_mdt_wr_mdc, 0 },
1011 { "instance", lprocfs_target_rd_instance, 0 },
1012 { "ir_factor", lprocfs_obd_rd_ir_factor,
1013 lprocfs_obd_wr_ir_factor, 0 },
1014 { "job_cleanup_interval", lprocfs_rd_job_interval,
1015 lprocfs_wr_job_interval, 0 },
1016 { "enable_remote_dir", lprocfs_rd_enable_remote_dir,
1017 lprocfs_wr_enable_remote_dir, 0},
1021 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
1022 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
1026 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
1028 lvars->module_vars = lprocfs_mdt_module_vars;
1029 lvars->obd_vars = lprocfs_mdt_obd_vars;
1032 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
1033 { "uuid", lprocfs_rd_uuid, 0, 0 },
1037 struct lprocfs_vars lprocfs_mds_module_vars[] = {
1038 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
1042 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1044 struct obd_export *exp = req->rq_export;
1046 if (exp->exp_obd && exp->exp_obd->md_stats)
1047 lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
1048 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1049 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1050 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1051 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1052 lprocfs_job_stats_log(exp->exp_obd,
1053 lustre_msg_get_jobid(req->rq_reqmsg),
1057 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1059 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
1060 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
1061 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
1062 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
1063 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
1064 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
1065 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
1066 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
1067 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
1068 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
1069 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
1070 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
1071 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
1072 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
1073 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
1074 "samedir_rename", "reqs");
1075 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
1076 "crossdir_rename", "reqs");