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 void 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 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 ptlrpc_lprocfs_unregister_obd(obd);
273 lprocfs_free_md_stats(obd);
274 lprocfs_free_obd_stats(obd);
275 lprocfs_job_stats_fini(obd);
278 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
279 int count, int *eof, void *data)
281 struct obd_device *obd = data;
282 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
285 return snprintf(page, count, "%u\n",
286 mdt->mdt_identity_cache->uc_entry_expire);
289 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
290 unsigned long count, void *data)
292 struct obd_device *obd = data;
293 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
296 rc = lprocfs_write_helper(buffer, count, &val);
300 mdt->mdt_identity_cache->uc_entry_expire = val;
304 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
305 off_t off, int count, int *eof,
308 struct obd_device *obd = data;
309 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
312 return snprintf(page, count, "%u\n",
313 mdt->mdt_identity_cache->uc_acquire_expire);
316 static int lprocfs_wr_identity_acquire_expire(struct file *file,
321 struct obd_device *obd = data;
322 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
325 rc = lprocfs_write_helper(buffer, count, &val);
329 mdt->mdt_identity_cache->uc_acquire_expire = val;
333 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
334 int count, int *eof, void *data)
336 struct obd_device *obd = data;
337 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
338 struct upcall_cache *hash = mdt->mdt_identity_cache;
342 read_lock(&hash->uc_upcall_rwlock);
343 len = snprintf(page, count, "%s\n", hash->uc_upcall);
344 read_unlock(&hash->uc_upcall_rwlock);
348 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
349 unsigned long count, void *data)
351 struct obd_device *obd = data;
352 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
353 struct upcall_cache *hash = mdt->mdt_identity_cache;
357 if (count >= UC_CACHE_UPCALL_MAXPATH) {
358 CERROR("%s: identity upcall too long\n", obd->obd_name);
361 OBD_ALLOC(kernbuf, count + 1);
363 GOTO(failed, rc = -ENOMEM);
364 if (cfs_copy_from_user(kernbuf, buffer, count))
365 GOTO(failed, rc = -EFAULT);
367 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
368 write_lock(&hash->uc_upcall_rwlock);
369 sscanf(kernbuf, "%s", hash->uc_upcall);
370 write_unlock(&hash->uc_upcall_rwlock);
372 if (strcmp(hash->uc_name, obd->obd_name) != 0)
373 CWARN("%s: write to upcall name %s\n",
374 obd->obd_name, hash->uc_upcall);
376 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
377 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
378 "cause unexpected \"EACCESS\"\n", obd->obd_name);
380 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
381 OBD_FREE(kernbuf, count + 1);
386 OBD_FREE(kernbuf, count + 1);
390 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
391 unsigned long count, void *data)
393 struct obd_device *obd = data;
394 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
397 rc = lprocfs_write_helper(buffer, count, &uid);
401 mdt_flush_identity(mdt->mdt_identity_cache, uid);
405 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
406 unsigned long count, void *data)
408 struct obd_device *obd = data;
409 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
410 struct identity_downcall_data *param;
411 int size = sizeof(*param), rc, checked = 0;
415 CERROR("%s: invalid data count = %lu, size = %d\n",
416 obd->obd_name, count, size);
420 OBD_ALLOC(param, size);
424 if (cfs_copy_from_user(param, buffer, size)) {
425 CERROR("%s: bad identity data\n", obd->obd_name);
426 GOTO(out, rc = -EFAULT);
431 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
432 CERROR("%s: MDS identity downcall bad params\n",
434 GOTO(out, rc = -EINVAL);
437 if (param->idd_nperms > N_PERMS_MAX) {
438 CERROR("%s: perm count %d more than maximum %d\n",
439 obd->obd_name, param->idd_nperms, N_PERMS_MAX);
440 GOTO(out, rc = -EINVAL);
443 if (param->idd_ngroups > NGROUPS_MAX) {
444 CERROR("%s: group count %d more than maximum %d\n",
445 obd->obd_name, param->idd_ngroups, NGROUPS_MAX);
446 GOTO(out, rc = -EINVAL);
449 if (param->idd_ngroups) {
450 rc = param->idd_ngroups; /* save idd_ngroups */
451 OBD_FREE(param, size);
452 size = offsetof(struct identity_downcall_data,
458 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
459 param->idd_uid, param);
463 OBD_FREE(param, size);
465 return rc ? rc : count;
469 static int lprocfs_rd_capa(char *page, char **start, off_t off,
470 int count, int *eof, void *data)
472 struct obd_device *obd = data;
473 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
475 return snprintf(page, count, "capability on: %s %s\n",
476 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
477 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
480 static int lprocfs_wr_capa(struct file *file, const char *buffer,
481 unsigned long count, void *data)
483 struct obd_device *obd = data;
484 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
487 rc = lprocfs_write_helper(buffer, count, &val);
491 if (val < 0 || val > 3) {
492 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
493 " 0: disable fid capability\n"
494 " 2: enable MDS fid capability\n"
495 " 3: enable both MDS and OSS fid capability\n");
499 /* OSS fid capability needs enable both MDS and OSS fid capability on
502 CERROR("can't enable OSS fid capability only, you should use "
503 "'3' to enable both MDS and OSS fid capability.\n");
507 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
508 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
509 mdt->mdt_capa_conf = 1;
510 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
512 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
513 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
515 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
519 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
520 int count, int *eof, void *data)
522 return snprintf(page, count, "%d %d\n",
523 capa_count[CAPA_SITE_CLIENT],
524 capa_count[CAPA_SITE_SERVER]);
527 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
528 int count, int *eof, void *data)
530 struct obd_device *obd = data;
531 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
533 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
536 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
537 int count, int *eof, void *data)
539 struct obd_device *obd = data;
540 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
542 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
545 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
546 unsigned long count, void *data)
548 struct obd_device *obd = data;
549 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
552 rc = lprocfs_write_helper(buffer, count, &val);
556 mdt->mdt_capa_timeout = (unsigned long)val;
557 mdt->mdt_capa_conf = 1;
561 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
562 int *eof, void *data)
564 struct obd_device *obd = data;
565 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
567 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
570 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
571 unsigned long count, void *data)
573 struct obd_device *obd = data;
574 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
577 rc = lprocfs_write_helper(buffer, count, &val);
581 mdt->mdt_ck_timeout = (unsigned long)val;
582 mdt->mdt_capa_conf = 1;
586 #define BUFLEN (UUID_MAX + 4)
588 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
589 unsigned long count, void *data)
594 OBD_ALLOC(kbuf, BUFLEN);
599 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
600 * bytes into kbuf, to ensure that the string is NUL-terminated.
601 * UUID_MAX should include a trailing NUL already.
603 if (cfs_copy_from_user(kbuf, buffer,
604 min_t(unsigned long, BUFLEN - 1, count))) {
608 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
610 if (strncmp(tmpbuf, "nid:", 4) != 0) {
611 count = lprocfs_wr_evict_client(file, buffer, count, data);
615 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
618 OBD_FREE(kbuf, BUFLEN);
624 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
625 int count, int *eof, void *data)
627 struct obd_device *obd = data;
628 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
630 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
633 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
634 unsigned long count, void *data)
636 struct obd_device *obd = data;
637 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
640 rc = lprocfs_write_helper(buffer, count, &val);
644 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
647 if (val == LUSTRE_SEC_SPECIFY) {
648 CWARN("security level %d will be supported in future.\n",
653 mdt->mdt_sec_level = val;
657 static int lprocfs_rd_cos(char *page, char **start, off_t off,
658 int count, int *eof, void *data)
660 struct obd_device *obd = data;
661 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
663 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
666 static int lprocfs_wr_cos(struct file *file, const char *buffer,
667 unsigned long count, void *data)
669 struct obd_device *obd = data;
670 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
673 rc = lprocfs_write_helper(buffer, count, &val);
676 mdt_enable_cos(mdt, val);
680 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
681 int count, int *eof, void *data)
683 struct obd_device *obd = data;
684 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
686 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
687 mdt->mdt_squash_gid);
690 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
694 *res = simple_strtoul(str, endp, 0);
698 sprintf(n, "%lu", *res);
699 if (strncmp(n, str, *endp - str))
705 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
706 unsigned long count, void *data)
708 struct obd_device *obd = data;
709 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
711 char kernbuf[50], *tmp, *end, *errmsg;
712 unsigned long uid, gid;
716 if (count >= sizeof(kernbuf)) {
717 errmsg = "string too long";
718 GOTO(failed, rc = -EINVAL);
720 if (cfs_copy_from_user(kernbuf, buffer, count)) {
721 errmsg = "bad address";
722 GOTO(failed, rc = -EFAULT);
724 kernbuf[count] = '\0';
727 if (safe_strtoul(buffer, &tmp, &uid)) {
728 uid = mdt->mdt_squash_uid;
735 if (safe_strtoul(tmp, &end, &gid)) {
736 gid = mdt->mdt_squash_gid;
740 gid = mdt->mdt_squash_gid;
744 mdt->mdt_squash_uid = uid;
745 mdt->mdt_squash_gid = gid;
747 if (nouid && nogid) {
748 errmsg = "needs uid:gid format";
749 GOTO(failed, rc = -EINVAL);
752 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
754 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
758 CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
759 obd->obd_name, buffer, errmsg, rc);
763 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
764 int count, int *eof, void *data)
766 struct obd_device *obd = data;
767 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
769 if (mdt->mdt_nosquash_str)
770 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
771 return snprintf(page, count, "NONE\n");
774 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
775 unsigned long count, void *data)
777 struct obd_device *obd = data;
778 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
780 char *kernbuf, *errmsg;
784 OBD_ALLOC(kernbuf, count + 1);
785 if (kernbuf == NULL) {
786 errmsg = "no memory";
787 GOTO(failed, rc = -ENOMEM);
789 if (cfs_copy_from_user(kernbuf, buffer, count)) {
790 errmsg = "bad address";
791 GOTO(failed, rc = -EFAULT);
793 kernbuf[count] = '\0';
795 if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
796 /* empty string is special case */
797 down_write(&mdt->mdt_squash_sem);
798 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
799 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
800 OBD_FREE(mdt->mdt_nosquash_str,
801 mdt->mdt_nosquash_strlen);
802 mdt->mdt_nosquash_str = NULL;
803 mdt->mdt_nosquash_strlen = 0;
805 up_write(&mdt->mdt_squash_sem);
806 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
808 OBD_FREE(kernbuf, count + 1);
812 CFS_INIT_LIST_HEAD(&tmp);
813 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
814 errmsg = "can't parse";
815 GOTO(failed, rc = -EINVAL);
818 down_write(&mdt->mdt_squash_sem);
819 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
820 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
821 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
823 mdt->mdt_nosquash_str = kernbuf;
824 mdt->mdt_nosquash_strlen = count + 1;
825 cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
827 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
828 obd->obd_name, kernbuf);
829 up_write(&mdt->mdt_squash_sem);
833 CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
834 obd->obd_name, kernbuf, errmsg, rc);
836 OBD_FREE(kernbuf, count + 1);
840 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
841 int count, int *eof, void *data)
843 struct obd_device *obd = data;
844 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
846 return snprintf(page, count, "%sabled\n",
847 mdt->mdt_som_conf ? "en" : "dis");
850 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
851 unsigned long count, void *data)
853 struct obd_export *exp;
854 struct obd_device *obd = data;
855 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
857 unsigned long val = 0;
859 if (count > (sizeof(kernbuf) - 1))
862 if (cfs_copy_from_user(kernbuf, buffer, count))
865 kernbuf[count] = '\0';
867 if (!strcmp(kernbuf, "enabled"))
869 else if (strcmp(kernbuf, "disabled"))
872 if (mdt->mdt_som_conf == val)
875 if (!obd->obd_process_conf) {
876 CERROR("Temporary SOM change is not supported, use lctl "
877 "conf_param for permanent setting\n");
881 /* 1 stands for self export. */
882 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
883 if (exp == obd->obd_self_export)
885 if (exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS)
887 /* Some clients are already connected, skip the change */
888 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
889 "the next mount\n", exp->exp_client_uuid.uuid,
890 val ? "enabled" : "disabled");
894 mdt->mdt_som_conf = val;
895 LCONSOLE_INFO("Enabling SOM\n");
900 /* Temporary; for testing purposes only */
901 static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
902 unsigned long count, void *data)
904 struct obd_device *obd = data;
905 struct obd_export *exp = NULL;
906 struct obd_uuid *uuid;
910 OBD_ALLOC(kbuf, UUID_MAX);
915 * OBD_ALLOC() will zero kbuf, but we only copy UUID_MAX - 1
916 * bytes into kbuf, to ensure that the string is NUL-terminated.
917 * UUID_MAX should include a trailing NUL already.
919 if (cfs_copy_from_user(kbuf, buffer,
920 min_t(unsigned long, UUID_MAX - 1, count))) {
924 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, UUID_MAX - 1, count));
926 OBD_ALLOC(uuid, UUID_MAX);
932 obd_str2uuid(uuid, tmpbuf);
933 exp = cfs_hash_lookup(obd->obd_uuid_hash, uuid);
935 CERROR("%s: no export %s found\n",
936 obd->obd_name, obd_uuid2str(uuid));
938 mdt_hsm_copytool_send(exp);
939 class_export_put(exp);
942 OBD_FREE(uuid, UUID_MAX);
944 OBD_FREE(kbuf, UUID_MAX);
948 static int lprocfs_rd_enable_remote_dir(char *page, char **start, off_t off,
949 int count, int *eof, void *data)
951 struct obd_device *obd = data;
952 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
954 return snprintf(page, count, "%u\n", mdt->mdt_enable_remote_dir);
957 static int lprocfs_wr_enable_remote_dir(struct file *file, const char *buffer,
958 unsigned long count, void *data)
960 struct obd_device *obd = data;
961 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
965 rc = lprocfs_write_helper(buffer, count, &val);
969 if (val < 0 || val > 1)
972 mdt->mdt_enable_remote_dir = val;
976 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
977 { "uuid", lprocfs_rd_uuid, 0, 0 },
978 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
979 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
980 { "identity_expire", lprocfs_rd_identity_expire,
981 lprocfs_wr_identity_expire, 0 },
982 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
983 lprocfs_wr_identity_acquire_expire, 0 },
984 { "identity_upcall", lprocfs_rd_identity_upcall,
985 lprocfs_wr_identity_upcall, 0 },
986 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
987 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
988 { "capa", lprocfs_rd_capa,
989 lprocfs_wr_capa, 0 },
990 { "capa_timeout", lprocfs_rd_capa_timeout,
991 lprocfs_wr_capa_timeout, 0 },
992 { "capa_key_timeout", lprocfs_rd_ck_timeout,
993 lprocfs_wr_ck_timeout, 0 },
994 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
995 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
996 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
997 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
998 { "sec_level", lprocfs_rd_sec_level,
999 lprocfs_wr_sec_level, 0 },
1000 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
1001 { "root_squash", lprocfs_rd_root_squash,
1002 lprocfs_wr_root_squash, 0 },
1003 { "nosquash_nids", lprocfs_rd_nosquash_nids,
1004 lprocfs_wr_nosquash_nids, 0 },
1005 { "som", lprocfs_rd_mdt_som,
1006 lprocfs_wr_mdt_som, 0 },
1007 { "mdccomm", 0, lprocfs_mdt_wr_mdc, 0 },
1008 { "instance", lprocfs_target_rd_instance, 0 },
1009 { "ir_factor", lprocfs_obd_rd_ir_factor,
1010 lprocfs_obd_wr_ir_factor, 0 },
1011 { "job_cleanup_interval", lprocfs_rd_job_interval,
1012 lprocfs_wr_job_interval, 0 },
1013 { "enable_remote_dir", lprocfs_rd_enable_remote_dir,
1014 lprocfs_wr_enable_remote_dir, 0},
1018 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
1019 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
1023 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
1025 lvars->module_vars = lprocfs_mdt_module_vars;
1026 lvars->obd_vars = lprocfs_mdt_obd_vars;
1029 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
1030 { "uuid", lprocfs_rd_uuid, 0, 0 },
1034 struct lprocfs_vars lprocfs_mds_module_vars[] = {
1035 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
1039 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1041 struct obd_export *exp = req->rq_export;
1043 if (exp->exp_obd && exp->exp_obd->md_stats)
1044 lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
1045 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1046 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1047 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1048 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1049 lprocfs_job_stats_log(exp->exp_obd,
1050 lustre_msg_get_jobid(req->rq_reqmsg),
1054 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1056 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
1057 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
1058 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
1059 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
1060 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
1061 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
1062 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
1063 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
1064 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
1065 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
1066 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
1067 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
1068 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
1069 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
1070 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
1071 "samedir_rename", "reqs");
1072 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
1073 "crossdir_rename", "reqs");