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, Whamcloud, Inc.
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>
65 #include "mdt_internal.h"
66 #include <lnet/lib-lnet.h>
71 static const char *mdt_proc_names[LPROC_MDT_NR] = {
75 * The rename stats output would be YAML formats, like
77 * - snapshot_time: 1234567890.123456
79 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
80 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
81 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
83 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
84 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
85 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
87 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
88 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
89 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
92 #define pct(a, b) (b ? a * 100 / b : 0)
94 static void display_rename_stats(struct seq_file *seq, char *name,
95 struct obd_histogram *hist)
97 unsigned long tot, t, cum = 0;
100 tot = lprocfs_oh_sum(hist);
102 seq_printf(seq, "- %-15s\n", name);
103 /* dir size start from 4K, start i from 10(2^10) here */
104 for (i = 0; i < OBD_HIST_MAX; i++) {
105 t = hist->oh_buckets[i];
111 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
113 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
115 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
117 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
118 t, pct(t, tot), pct(cum, tot));
125 static void rename_stats_show(struct seq_file *seq,
126 struct rename_stats *rename_stats)
130 /* this sampling races with updates */
131 do_gettimeofday(&now);
132 seq_printf(seq, "rename_stats:\n");
133 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
134 now.tv_sec, now.tv_usec);
136 display_rename_stats(seq, "same_dir",
137 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
138 display_rename_stats(seq, "crossdir_src",
139 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
140 display_rename_stats(seq, "crossdir_tgt",
141 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
146 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
148 struct mdt_device *mdt = seq->private;
150 rename_stats_show(seq, &mdt->mdt_rename_stats);
155 static ssize_t mdt_rename_stats_seq_write(struct file *file, const char *buf,
156 size_t len, loff_t *off)
158 struct seq_file *seq = file->private_data;
159 struct mdt_device *mdt = seq->private;
162 for (i = 0; i < RENAME_LAST; i++)
163 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
168 LPROC_SEQ_FOPS(mdt_rename_stats);
170 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
172 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
173 struct obd_device *obd = ld->ld_obd;
176 for (i = 0; i < RENAME_LAST; i++)
177 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
179 return lprocfs_obd_seq_create(obd, "rename_stats", 0444,
180 &mdt_rename_stats_fops, mdt);
183 void mdt_rename_counter_tally(struct mdt_thread_info *info,
184 struct mdt_device *mdt,
185 struct ptlrpc_request *req,
186 struct mdt_object *src,
187 struct mdt_object *tgt)
189 struct md_attr *ma = &info->mti_attr;
190 struct rename_stats *rstats = &mdt->mdt_rename_stats;
193 ma->ma_need = MA_INODE;
195 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
197 CERROR("%s: "DFID" attr_get, rc = %d\n",
198 req->rq_export->exp_obd->obd_name,
199 PFID(mdt_object_fid(src)), rc);
204 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
205 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
206 (unsigned int)ma->ma_attr.la_size);
210 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
211 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
212 (unsigned int)ma->ma_attr.la_size);
214 ma->ma_need = MA_INODE;
216 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
218 CERROR("%s: "DFID" attr_get, rc = %d\n",
219 req->rq_export->exp_obd->obd_name,
220 PFID(mdt_object_fid(tgt)), rc);
224 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
225 (unsigned int)ma->ma_attr.la_size);
228 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
230 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
231 struct obd_device *obd = ld->ld_obd;
232 struct lprocfs_static_vars lvars;
236 LASSERT(name != NULL);
238 lprocfs_mdt_init_vars(&lvars);
239 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
241 CERROR("Can't init lprocfs, rc %d\n", rc);
244 ptlrpc_lprocfs_register_obd(obd);
246 mdt->mdt_proc_entry = obd->obd_proc_entry;
247 LASSERT(mdt->mdt_proc_entry != NULL);
249 rc = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
250 mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
252 rc = lu_time_named_init(&ld->ld_site->ls_time_stats,
253 "site_time", mdt->mdt_proc_entry,
255 ARRAY_SIZE(lu_time_names));
259 obd->obd_proc_exports_entry = proc_mkdir("exports",
260 obd->obd_proc_entry);
261 if (obd->obd_proc_exports_entry)
262 lprocfs_add_simple(obd->obd_proc_exports_entry,
263 "clear", lprocfs_nid_stats_clear_read,
264 lprocfs_nid_stats_clear_write, obd, NULL);
265 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
268 mdt_stats_counter_init(obd->md_stats);
270 rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
271 mdt_stats_counter_init);
273 rc = lproc_mdt_attach_rename_seqstat(mdt);
275 CERROR("%s: MDT can not create rename stats rc = %d\n",
281 int mdt_procfs_fini(struct mdt_device *mdt)
283 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
284 struct obd_device *obd = ld->ld_obd;
286 lprocfs_job_stats_fini(obd);
288 if (obd->obd_proc_exports_entry) {
289 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
290 obd->obd_proc_exports_entry = NULL;
292 lprocfs_free_per_client_stats(obd);
293 lprocfs_obd_cleanup(obd);
294 ptlrpc_lprocfs_unregister_obd(obd);
295 if (mdt->mdt_proc_entry) {
296 lu_time_fini(&ld->ld_site->ls_time_stats);
297 lu_time_fini(&mdt->mdt_stats);
298 mdt->mdt_proc_entry = NULL;
300 lprocfs_free_md_stats(obd);
301 lprocfs_free_obd_stats(obd);
306 void mdt_time_start(const struct mdt_thread_info *info)
308 lu_lprocfs_time_start(info->mti_env);
311 void mdt_time_end(const struct mdt_thread_info *info, int idx)
313 lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
316 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
317 int count, int *eof, void *data)
319 struct obd_device *obd = data;
320 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
323 return snprintf(page, count, "%u\n",
324 mdt->mdt_identity_cache->uc_entry_expire);
327 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
328 unsigned long count, void *data)
330 struct obd_device *obd = data;
331 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
334 rc = lprocfs_write_helper(buffer, count, &val);
338 mdt->mdt_identity_cache->uc_entry_expire = val;
342 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
343 off_t off, int count, int *eof,
346 struct obd_device *obd = data;
347 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
350 return snprintf(page, count, "%u\n",
351 mdt->mdt_identity_cache->uc_acquire_expire);
354 static int lprocfs_wr_identity_acquire_expire(struct file *file,
359 struct obd_device *obd = data;
360 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
363 rc = lprocfs_write_helper(buffer, count, &val);
367 mdt->mdt_identity_cache->uc_acquire_expire = val;
371 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
372 int count, int *eof, void *data)
374 struct obd_device *obd = data;
375 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
376 struct upcall_cache *hash = mdt->mdt_identity_cache;
380 read_lock(&hash->uc_upcall_rwlock);
381 len = snprintf(page, count, "%s\n", hash->uc_upcall);
382 read_unlock(&hash->uc_upcall_rwlock);
386 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
387 unsigned long count, void *data)
389 struct obd_device *obd = data;
390 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
391 struct upcall_cache *hash = mdt->mdt_identity_cache;
395 if (count >= UC_CACHE_UPCALL_MAXPATH) {
396 CERROR("%s: identity upcall too long\n", obd->obd_name);
399 OBD_ALLOC(kernbuf, count + 1);
401 GOTO(failed, rc = -ENOMEM);
402 if (cfs_copy_from_user(kernbuf, buffer, count))
403 GOTO(failed, rc = -EFAULT);
405 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
406 write_lock(&hash->uc_upcall_rwlock);
407 sscanf(kernbuf, "%s", hash->uc_upcall);
408 write_unlock(&hash->uc_upcall_rwlock);
410 if (strcmp(hash->uc_name, obd->obd_name) != 0)
411 CWARN("%s: write to upcall name %s\n",
412 obd->obd_name, hash->uc_upcall);
414 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
415 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
416 "cause unexpected \"EACCESS\"\n", obd->obd_name);
418 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
419 OBD_FREE(kernbuf, count + 1);
424 OBD_FREE(kernbuf, count + 1);
428 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
429 unsigned long count, void *data)
431 struct obd_device *obd = data;
432 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
435 rc = lprocfs_write_helper(buffer, count, &uid);
439 mdt_flush_identity(mdt->mdt_identity_cache, uid);
443 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
444 unsigned long count, void *data)
446 struct obd_device *obd = data;
447 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
448 struct identity_downcall_data *param;
449 int size = sizeof(*param), rc, checked = 0;
453 CERROR("%s: invalid data count = %lu, size = %d\n",
454 obd->obd_name, count, size);
458 OBD_ALLOC(param, size);
462 if (cfs_copy_from_user(param, buffer, size)) {
463 CERROR("%s: bad identity data\n", obd->obd_name);
464 GOTO(out, rc = -EFAULT);
469 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
470 CERROR("%s: MDS identity downcall bad params\n",
472 GOTO(out, rc = -EINVAL);
475 if (param->idd_nperms > N_PERMS_MAX) {
476 CERROR("%s: perm count %d more than maximum %d\n",
477 obd->obd_name, param->idd_nperms, N_PERMS_MAX);
478 GOTO(out, rc = -EINVAL);
481 if (param->idd_ngroups > NGROUPS_MAX) {
482 CERROR("%s: group count %d more than maximum %d\n",
483 obd->obd_name, param->idd_ngroups, NGROUPS_MAX);
484 GOTO(out, rc = -EINVAL);
487 if (param->idd_ngroups) {
488 rc = param->idd_ngroups; /* save idd_ngroups */
489 OBD_FREE(param, size);
490 size = offsetof(struct identity_downcall_data,
496 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
497 param->idd_uid, param);
501 OBD_FREE(param, size);
503 return rc ? rc : count;
507 static int lprocfs_rd_capa(char *page, char **start, off_t off,
508 int count, int *eof, void *data)
510 struct obd_device *obd = data;
511 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
513 return snprintf(page, count, "capability on: %s %s\n",
514 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
515 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
518 static int lprocfs_wr_capa(struct file *file, const char *buffer,
519 unsigned long count, void *data)
521 struct obd_device *obd = data;
522 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
525 rc = lprocfs_write_helper(buffer, count, &val);
529 if (val < 0 || val > 3) {
530 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
531 " 0: disable fid capability\n"
532 " 2: enable MDS fid capability\n"
533 " 3: enable both MDS and OSS fid capability\n");
537 /* OSS fid capability needs enable both MDS and OSS fid capability on
540 CERROR("can't enable OSS fid capability only, you should use "
541 "'3' to enable both MDS and OSS fid capability.\n");
545 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
546 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
547 mdt->mdt_capa_conf = 1;
548 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
550 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
551 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
553 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
557 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
558 int count, int *eof, void *data)
560 return snprintf(page, count, "%d %d\n",
561 capa_count[CAPA_SITE_CLIENT],
562 capa_count[CAPA_SITE_SERVER]);
565 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
566 int count, int *eof, void *data)
568 struct obd_device *obd = data;
569 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
571 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
574 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
575 int count, int *eof, void *data)
577 struct obd_device *obd = data;
578 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
580 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
583 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
584 unsigned long count, void *data)
586 struct obd_device *obd = data;
587 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
590 rc = lprocfs_write_helper(buffer, count, &val);
594 mdt->mdt_capa_timeout = (unsigned long)val;
595 mdt->mdt_capa_conf = 1;
599 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
600 int *eof, void *data)
602 struct obd_device *obd = data;
603 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
605 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
608 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
609 unsigned long count, void *data)
611 struct obd_device *obd = data;
612 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
615 rc = lprocfs_write_helper(buffer, count, &val);
619 mdt->mdt_ck_timeout = (unsigned long)val;
620 mdt->mdt_capa_conf = 1;
624 #define BUFLEN (UUID_MAX + 4)
626 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
627 unsigned long count, void *data)
632 OBD_ALLOC(kbuf, BUFLEN);
637 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
638 * bytes into kbuf, to ensure that the string is NUL-terminated.
639 * UUID_MAX should include a trailing NUL already.
641 if (cfs_copy_from_user(kbuf, buffer,
642 min_t(unsigned long, BUFLEN - 1, count))) {
646 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
648 if (strncmp(tmpbuf, "nid:", 4) != 0) {
649 count = lprocfs_wr_evict_client(file, buffer, count, data);
653 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
656 OBD_FREE(kbuf, BUFLEN);
662 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
663 int count, int *eof, void *data)
665 struct obd_device *obd = data;
666 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
668 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
671 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
672 unsigned long count, void *data)
674 struct obd_device *obd = data;
675 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
678 rc = lprocfs_write_helper(buffer, count, &val);
682 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
685 if (val == LUSTRE_SEC_SPECIFY) {
686 CWARN("security level %d will be supported in future.\n",
691 mdt->mdt_sec_level = val;
695 static int lprocfs_rd_cos(char *page, char **start, off_t off,
696 int count, int *eof, void *data)
698 struct obd_device *obd = data;
699 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
701 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
704 static int lprocfs_wr_cos(struct file *file, const char *buffer,
705 unsigned long count, void *data)
707 struct obd_device *obd = data;
708 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
711 rc = lprocfs_write_helper(buffer, count, &val);
714 mdt_enable_cos(mdt, val);
718 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
719 int count, int *eof, void *data)
721 struct obd_device *obd = data;
722 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
724 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
725 mdt->mdt_squash_gid);
728 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
732 *res = simple_strtoul(str, endp, 0);
736 sprintf(n, "%lu", *res);
737 if (strncmp(n, str, *endp - str))
743 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
744 unsigned long count, void *data)
746 struct obd_device *obd = data;
747 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
749 char kernbuf[50], *tmp, *end, *errmsg;
750 unsigned long uid, gid;
754 if (count >= sizeof(kernbuf)) {
755 errmsg = "string too long";
756 GOTO(failed, rc = -EINVAL);
758 if (cfs_copy_from_user(kernbuf, buffer, count)) {
759 errmsg = "bad address";
760 GOTO(failed, rc = -EFAULT);
762 kernbuf[count] = '\0';
765 if (safe_strtoul(buffer, &tmp, &uid)) {
766 uid = mdt->mdt_squash_uid;
773 if (safe_strtoul(tmp, &end, &gid)) {
774 gid = mdt->mdt_squash_gid;
778 gid = mdt->mdt_squash_gid;
782 mdt->mdt_squash_uid = uid;
783 mdt->mdt_squash_gid = gid;
785 if (nouid && nogid) {
786 errmsg = "needs uid:gid format";
787 GOTO(failed, rc = -EINVAL);
790 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
792 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
796 CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
797 obd->obd_name, buffer, errmsg, rc);
801 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
802 int count, int *eof, void *data)
804 struct obd_device *obd = data;
805 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
807 if (mdt->mdt_nosquash_str)
808 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
809 return snprintf(page, count, "NONE\n");
812 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
813 unsigned long count, void *data)
815 struct obd_device *obd = data;
816 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
818 char *kernbuf, *errmsg;
822 OBD_ALLOC(kernbuf, count + 1);
823 if (kernbuf == NULL) {
824 errmsg = "no memory";
825 GOTO(failed, rc = -ENOMEM);
827 if (cfs_copy_from_user(kernbuf, buffer, count)) {
828 errmsg = "bad address";
829 GOTO(failed, rc = -EFAULT);
831 kernbuf[count] = '\0';
833 if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
834 /* empty string is special case */
835 down_write(&mdt->mdt_squash_sem);
836 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
837 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
838 OBD_FREE(mdt->mdt_nosquash_str,
839 mdt->mdt_nosquash_strlen);
840 mdt->mdt_nosquash_str = NULL;
841 mdt->mdt_nosquash_strlen = 0;
843 up_write(&mdt->mdt_squash_sem);
844 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
846 OBD_FREE(kernbuf, count + 1);
850 CFS_INIT_LIST_HEAD(&tmp);
851 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
852 errmsg = "can't parse";
853 GOTO(failed, rc = -EINVAL);
856 down_write(&mdt->mdt_squash_sem);
857 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
858 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
859 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
861 mdt->mdt_nosquash_str = kernbuf;
862 mdt->mdt_nosquash_strlen = count + 1;
863 cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
865 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
866 obd->obd_name, kernbuf);
867 up_write(&mdt->mdt_squash_sem);
871 CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
872 obd->obd_name, kernbuf, errmsg, rc);
874 OBD_FREE(kernbuf, count + 1);
878 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
879 int count, int *eof, void *data)
881 struct obd_device *obd = data;
882 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
884 return snprintf(page, count, "%sabled\n",
885 mdt->mdt_som_conf ? "en" : "dis");
888 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
889 unsigned long count, void *data)
891 struct obd_export *exp;
892 struct obd_device *obd = data;
893 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
895 unsigned long val = 0;
897 if (count > (sizeof(kernbuf) - 1))
900 if (cfs_copy_from_user(kernbuf, buffer, count))
903 kernbuf[count] = '\0';
905 if (!strcmp(kernbuf, "enabled"))
907 else if (strcmp(kernbuf, "disabled"))
910 if (mdt->mdt_som_conf == val)
913 if (!obd->obd_process_conf) {
914 CERROR("Temporary SOM change is not supported, use lctl "
915 "conf_param for permanent setting\n");
919 /* 1 stands for self export. */
920 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
921 if (exp == obd->obd_self_export)
923 if (exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)
925 /* Some clients are already connected, skip the change */
926 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
927 "the next mount\n", exp->exp_client_uuid.uuid,
928 val ? "enabled" : "disabled");
932 mdt->mdt_som_conf = val;
933 LCONSOLE_INFO("Enabling SOM\n");
938 /* Temporary; for testing purposes only */
939 static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
940 unsigned long count, void *data)
942 struct obd_device *obd = data;
943 struct obd_export *exp = NULL;
944 struct obd_uuid *uuid;
948 OBD_ALLOC(kbuf, UUID_MAX);
953 * OBD_ALLOC() will zero kbuf, but we only copy UUID_MAX - 1
954 * bytes into kbuf, to ensure that the string is NUL-terminated.
955 * UUID_MAX should include a trailing NUL already.
957 if (cfs_copy_from_user(kbuf, buffer,
958 min_t(unsigned long, UUID_MAX - 1, count))) {
962 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, UUID_MAX - 1, count));
964 OBD_ALLOC(uuid, UUID_MAX);
970 obd_str2uuid(uuid, tmpbuf);
971 exp = cfs_hash_lookup(obd->obd_uuid_hash, uuid);
973 CERROR("%s: no export %s found\n",
974 obd->obd_name, obd_uuid2str(uuid));
976 mdt_hsm_copytool_send(exp);
977 class_export_put(exp);
980 OBD_FREE(uuid, UUID_MAX);
982 OBD_FREE(kbuf, UUID_MAX);
986 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
987 { "uuid", lprocfs_rd_uuid, 0, 0 },
988 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
989 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
990 { "identity_expire", lprocfs_rd_identity_expire,
991 lprocfs_wr_identity_expire, 0 },
992 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
993 lprocfs_wr_identity_acquire_expire, 0 },
994 { "identity_upcall", lprocfs_rd_identity_upcall,
995 lprocfs_wr_identity_upcall, 0 },
996 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
997 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
998 { "capa", lprocfs_rd_capa,
999 lprocfs_wr_capa, 0 },
1000 { "capa_timeout", lprocfs_rd_capa_timeout,
1001 lprocfs_wr_capa_timeout, 0 },
1002 { "capa_key_timeout", lprocfs_rd_ck_timeout,
1003 lprocfs_wr_ck_timeout, 0 },
1004 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
1005 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
1006 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
1007 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
1008 { "sec_level", lprocfs_rd_sec_level,
1009 lprocfs_wr_sec_level, 0 },
1010 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
1011 { "root_squash", lprocfs_rd_root_squash,
1012 lprocfs_wr_root_squash, 0 },
1013 { "nosquash_nids", lprocfs_rd_nosquash_nids,
1014 lprocfs_wr_nosquash_nids, 0 },
1015 { "som", lprocfs_rd_mdt_som,
1016 lprocfs_wr_mdt_som, 0 },
1017 { "mdccomm", 0, lprocfs_mdt_wr_mdc, 0 },
1018 { "instance", lprocfs_target_rd_instance, 0 },
1019 { "ir_factor", lprocfs_obd_rd_ir_factor,
1020 lprocfs_obd_wr_ir_factor, 0 },
1021 { "job_cleanup_interval", lprocfs_rd_job_interval,
1022 lprocfs_wr_job_interval, 0 },
1026 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
1027 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
1031 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
1033 lvars->module_vars = lprocfs_mdt_module_vars;
1034 lvars->obd_vars = lprocfs_mdt_obd_vars;
1037 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1039 struct obd_export *exp = req->rq_export;
1041 if (exp->exp_obd && exp->exp_obd->md_stats)
1042 lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
1043 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1044 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1045 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1046 (exp->exp_connect_flags & OBD_CONNECT_JOBSTATS))
1047 lprocfs_job_stats_log(exp->exp_obd,
1048 lustre_msg_get_jobid(req->rq_reqmsg),
1052 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1054 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
1055 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
1056 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
1057 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
1058 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
1059 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
1060 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
1061 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
1062 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
1063 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
1064 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
1065 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
1066 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
1067 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
1068 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
1069 "samedir_rename", "reqs");
1070 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
1071 "crossdir_rename", "reqs");