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>
43 # define EXPORT_SYMTAB
45 #define DEBUG_SUBSYSTEM S_MDS
47 #include <linux/version.h>
48 #include <asm/statfs.h>
50 #include <linux/module.h>
52 /* LUSTRE_VERSION_CODE */
53 #include <lustre_ver.h>
55 * struct OBD_{ALLOC,FREE}*()
58 #include <obd_support.h>
59 /* struct obd_export */
60 #include <lustre_export.h>
61 /* struct obd_device */
63 #include <obd_class.h>
64 #include <lustre_mds.h>
65 #include <lustre_mdt.h>
66 #include <lprocfs_status.h>
68 #include "mdt_internal.h"
69 #include <lnet/lib-lnet.h>
74 static const char *mdt_proc_names[LPROC_MDT_NR] = {
78 * The rename stats output would be YAML formats, like
80 * - snapshot_time: 1234567890.123456
82 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
83 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
84 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
86 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
87 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
88 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
90 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
91 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
92 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
95 #define pct(a, b) (b ? a * 100 / b : 0)
97 static void display_rename_stats(struct seq_file *seq, char *name,
98 struct obd_histogram *hist)
100 unsigned long tot, t, cum = 0;
103 tot = lprocfs_oh_sum(hist);
105 seq_printf(seq, "- %-15s\n", name);
106 /* dir size start from 4K, start i from 10(2^10) here */
107 for (i = 0; i < OBD_HIST_MAX; i++) {
108 t = hist->oh_buckets[i];
114 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
116 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
118 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
120 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
121 t, pct(t, tot), pct(cum, tot));
128 static void rename_stats_show(struct seq_file *seq,
129 struct rename_stats *rename_stats)
133 /* this sampling races with updates */
134 do_gettimeofday(&now);
135 seq_printf(seq, "rename_stats:\n");
136 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
137 now.tv_sec, now.tv_usec);
139 display_rename_stats(seq, "same_dir",
140 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
141 display_rename_stats(seq, "crossdir_src",
142 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
143 display_rename_stats(seq, "crossdir_tgt",
144 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
149 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
151 struct mdt_device *mdt = seq->private;
153 rename_stats_show(seq, &mdt->mdt_rename_stats);
158 static ssize_t mdt_rename_stats_seq_write(struct file *file, const char *buf,
159 size_t len, loff_t *off)
161 struct seq_file *seq = file->private_data;
162 struct mdt_device *mdt = seq->private;
165 for (i = 0; i < RENAME_LAST; i++)
166 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
171 LPROC_SEQ_FOPS(mdt_rename_stats);
173 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
175 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
176 struct obd_device *obd = ld->ld_obd;
179 for (i = 0; i < RENAME_LAST; i++)
180 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
182 return lprocfs_obd_seq_create(obd, "rename_stats", 0444,
183 &mdt_rename_stats_fops, mdt);
186 void mdt_rename_counter_tally(struct mdt_thread_info *info,
187 struct mdt_device *mdt,
188 struct obd_export *exp,
189 struct mdt_object *src,
190 struct mdt_object *tgt)
192 struct md_attr *ma = &info->mti_attr;
193 struct rename_stats *rstats = &mdt->mdt_rename_stats;
196 ma->ma_need = MA_INODE;
198 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
200 CERROR("%s: "DFID" attr_get, rc = %d\n",
201 exp->exp_obd->obd_name, PFID(mdt_object_fid(src)), rc);
206 mdt_counter_incr(exp, LPROC_MDT_SAMEDIR_RENAME);
207 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
208 (unsigned int)ma->ma_attr.la_size);
212 mdt_counter_incr(exp, LPROC_MDT_CROSSDIR_RENAME);
213 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
214 (unsigned int)ma->ma_attr.la_size);
216 ma->ma_need = MA_INODE;
218 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
220 CERROR("%s: "DFID" attr_get, rc = %d\n",
221 exp->exp_obd->obd_name, PFID(mdt_object_fid(tgt)), rc);
225 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
226 (unsigned int)ma->ma_attr.la_size);
229 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
231 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
232 struct obd_device *obd = ld->ld_obd;
233 struct lprocfs_static_vars lvars;
237 LASSERT(name != NULL);
239 lprocfs_mdt_init_vars(&lvars);
240 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
242 CERROR("Can't init lprocfs, rc %d\n", rc);
245 ptlrpc_lprocfs_register_obd(obd);
247 mdt->mdt_proc_entry = obd->obd_proc_entry;
248 LASSERT(mdt->mdt_proc_entry != NULL);
250 rc = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
251 mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
253 rc = lu_time_named_init(&ld->ld_site->ls_time_stats,
254 "site_time", mdt->mdt_proc_entry,
256 ARRAY_SIZE(lu_time_names));
260 obd->obd_proc_exports_entry = proc_mkdir("exports",
261 obd->obd_proc_entry);
262 if (obd->obd_proc_exports_entry)
263 lprocfs_add_simple(obd->obd_proc_exports_entry,
264 "clear", lprocfs_nid_stats_clear_read,
265 lprocfs_nid_stats_clear_write, obd, NULL);
266 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
268 mdt_stats_counter_init(obd->md_stats);
270 rc = lproc_mdt_attach_rename_seqstat(mdt);
272 CERROR("%s: MDT can not create rename stats rc = %d\n",
278 int mdt_procfs_fini(struct mdt_device *mdt)
280 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
281 struct obd_device *obd = ld->ld_obd;
283 if (obd->obd_proc_exports_entry) {
284 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
285 obd->obd_proc_exports_entry = NULL;
287 lprocfs_free_per_client_stats(obd);
288 lprocfs_obd_cleanup(obd);
289 ptlrpc_lprocfs_unregister_obd(obd);
290 if (mdt->mdt_proc_entry) {
291 lu_time_fini(&ld->ld_site->ls_time_stats);
292 lu_time_fini(&mdt->mdt_stats);
293 mdt->mdt_proc_entry = NULL;
295 lprocfs_free_md_stats(obd);
296 lprocfs_free_obd_stats(obd);
301 void mdt_time_start(const struct mdt_thread_info *info)
303 lu_lprocfs_time_start(info->mti_env);
306 void mdt_time_end(const struct mdt_thread_info *info, int idx)
308 lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
311 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
312 int count, int *eof, void *data)
314 struct obd_device *obd = data;
315 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
318 return snprintf(page, count, "%u\n",
319 mdt->mdt_identity_cache->uc_entry_expire);
322 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
323 unsigned long count, void *data)
325 struct obd_device *obd = data;
326 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
329 rc = lprocfs_write_helper(buffer, count, &val);
333 mdt->mdt_identity_cache->uc_entry_expire = val;
337 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
338 off_t off, int count, int *eof,
341 struct obd_device *obd = data;
342 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
345 return snprintf(page, count, "%u\n",
346 mdt->mdt_identity_cache->uc_acquire_expire);
349 static int lprocfs_wr_identity_acquire_expire(struct file *file,
354 struct obd_device *obd = data;
355 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
358 rc = lprocfs_write_helper(buffer, count, &val);
362 mdt->mdt_identity_cache->uc_acquire_expire = val;
366 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
367 int count, int *eof, void *data)
369 struct obd_device *obd = data;
370 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
371 struct upcall_cache *hash = mdt->mdt_identity_cache;
375 cfs_read_lock(&hash->uc_upcall_rwlock);
376 len = snprintf(page, count, "%s\n", hash->uc_upcall);
377 cfs_read_unlock(&hash->uc_upcall_rwlock);
381 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
382 unsigned long count, void *data)
384 struct obd_device *obd = data;
385 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
386 struct upcall_cache *hash = mdt->mdt_identity_cache;
390 if (count >= UC_CACHE_UPCALL_MAXPATH) {
391 CERROR("%s: identity upcall too long\n", obd->obd_name);
394 OBD_ALLOC(kernbuf, count + 1);
396 GOTO(failed, rc = -ENOMEM);
397 if (cfs_copy_from_user(kernbuf, buffer, count))
398 GOTO(failed, rc = -EFAULT);
400 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
401 cfs_write_lock(&hash->uc_upcall_rwlock);
402 sscanf(kernbuf, "%s", hash->uc_upcall);
403 cfs_write_unlock(&hash->uc_upcall_rwlock);
405 if (strcmp(hash->uc_name, obd->obd_name) != 0)
406 CWARN("%s: write to upcall name %s\n",
407 obd->obd_name, hash->uc_upcall);
409 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
410 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
411 "cause unexpected \"EACCESS\"\n", obd->obd_name);
413 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
414 OBD_FREE(kernbuf, count + 1);
419 OBD_FREE(kernbuf, count + 1);
423 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
424 unsigned long count, void *data)
426 struct obd_device *obd = data;
427 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
430 rc = lprocfs_write_helper(buffer, count, &uid);
434 mdt_flush_identity(mdt->mdt_identity_cache, uid);
438 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
439 unsigned long count, void *data)
441 struct obd_device *obd = data;
442 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
443 struct identity_downcall_data *param;
444 int size = sizeof(*param), rc, checked = 0;
448 CERROR("%s: invalid data count = %lu, size = %d\n",
449 obd->obd_name, count, size);
453 OBD_ALLOC(param, size);
457 if (cfs_copy_from_user(param, buffer, size)) {
458 CERROR("%s: bad identity data\n", obd->obd_name);
459 GOTO(out, rc = -EFAULT);
464 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
465 CERROR("%s: MDS identity downcall bad params\n",
467 GOTO(out, rc = -EINVAL);
470 if (param->idd_nperms > N_PERMS_MAX) {
471 CERROR("%s: perm count %d more than maximum %d\n",
472 obd->obd_name, param->idd_nperms, N_PERMS_MAX);
473 GOTO(out, rc = -EINVAL);
476 if (param->idd_ngroups > NGROUPS_MAX) {
477 CERROR("%s: group count %d more than maximum %d\n",
478 obd->obd_name, param->idd_ngroups, NGROUPS_MAX);
479 GOTO(out, rc = -EINVAL);
482 if (param->idd_ngroups) {
483 rc = param->idd_ngroups; /* save idd_ngroups */
484 OBD_FREE(param, size);
485 size = offsetof(struct identity_downcall_data,
491 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
492 param->idd_uid, param);
496 OBD_FREE(param, size);
498 return rc ? rc : count;
502 static int lprocfs_rd_capa(char *page, char **start, off_t off,
503 int count, int *eof, void *data)
505 struct obd_device *obd = data;
506 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
508 return snprintf(page, count, "capability on: %s %s\n",
509 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
510 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
513 static int lprocfs_wr_capa(struct file *file, const char *buffer,
514 unsigned long count, void *data)
516 struct obd_device *obd = data;
517 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
520 rc = lprocfs_write_helper(buffer, count, &val);
524 if (val < 0 || val > 3) {
525 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
526 " 0: disable fid capability\n"
527 " 2: enable MDS fid capability\n"
528 " 3: enable both MDS and OSS fid capability\n");
532 /* OSS fid capability needs enable both MDS and OSS fid capability on
535 CERROR("can't enable OSS fid capability only, you should use "
536 "'3' to enable both MDS and OSS fid capability.\n");
540 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
541 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
542 mdt->mdt_capa_conf = 1;
543 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
545 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
546 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
548 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
552 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
553 int count, int *eof, void *data)
555 return snprintf(page, count, "%d %d\n",
556 capa_count[CAPA_SITE_CLIENT],
557 capa_count[CAPA_SITE_SERVER]);
560 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
561 int count, int *eof, void *data)
563 struct obd_device *obd = data;
564 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
566 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
569 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
570 int count, int *eof, void *data)
572 struct obd_device *obd = data;
573 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
575 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
578 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
579 unsigned long count, void *data)
581 struct obd_device *obd = data;
582 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
585 rc = lprocfs_write_helper(buffer, count, &val);
589 mdt->mdt_capa_timeout = (unsigned long)val;
590 mdt->mdt_capa_conf = 1;
594 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
595 int *eof, void *data)
597 struct obd_device *obd = data;
598 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
600 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
603 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
604 unsigned long count, void *data)
606 struct obd_device *obd = data;
607 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
610 rc = lprocfs_write_helper(buffer, count, &val);
614 mdt->mdt_ck_timeout = (unsigned long)val;
615 mdt->mdt_capa_conf = 1;
619 #define BUFLEN (UUID_MAX + 4)
621 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
622 unsigned long count, void *data)
627 OBD_ALLOC(kbuf, BUFLEN);
632 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
633 * bytes into kbuf, to ensure that the string is NUL-terminated.
634 * UUID_MAX should include a trailing NUL already.
636 if (cfs_copy_from_user(kbuf, buffer,
637 min_t(unsigned long, BUFLEN - 1, count))) {
641 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
643 if (strncmp(tmpbuf, "nid:", 4) != 0) {
644 count = lprocfs_wr_evict_client(file, buffer, count, data);
648 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
651 OBD_FREE(kbuf, BUFLEN);
657 static int lprocfs_rd_sec_level(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, "%d\n", mdt->mdt_sec_level);
666 static int lprocfs_wr_sec_level(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);
677 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
680 if (val == LUSTRE_SEC_SPECIFY) {
681 CWARN("security level %d will be supported in future.\n",
686 mdt->mdt_sec_level = val;
690 static int lprocfs_rd_cos(char *page, char **start, off_t off,
691 int count, int *eof, void *data)
693 struct obd_device *obd = data;
694 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
696 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
699 static int lprocfs_wr_cos(struct file *file, const char *buffer,
700 unsigned long count, void *data)
702 struct obd_device *obd = data;
703 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
706 rc = lprocfs_write_helper(buffer, count, &val);
709 mdt_enable_cos(mdt, val);
713 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
714 int count, int *eof, void *data)
716 struct obd_device *obd = data;
717 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
719 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
720 mdt->mdt_squash_gid);
723 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
727 *res = simple_strtoul(str, endp, 0);
731 sprintf(n, "%lu", *res);
732 if (strncmp(n, str, *endp - str))
738 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
739 unsigned long count, void *data)
741 struct obd_device *obd = data;
742 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
744 char kernbuf[50], *tmp, *end, *errmsg;
745 unsigned long uid, gid;
749 if (count >= sizeof(kernbuf)) {
750 errmsg = "string too long";
751 GOTO(failed, rc = -EINVAL);
753 if (cfs_copy_from_user(kernbuf, buffer, count)) {
754 errmsg = "bad address";
755 GOTO(failed, rc = -EFAULT);
757 kernbuf[count] = '\0';
760 if (safe_strtoul(buffer, &tmp, &uid)) {
761 uid = mdt->mdt_squash_uid;
768 if (safe_strtoul(tmp, &end, &gid)) {
769 gid = mdt->mdt_squash_gid;
773 gid = mdt->mdt_squash_gid;
777 mdt->mdt_squash_uid = uid;
778 mdt->mdt_squash_gid = gid;
780 if (nouid && nogid) {
781 errmsg = "needs uid:gid format";
782 GOTO(failed, rc = -EINVAL);
785 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
787 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
791 CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
792 obd->obd_name, buffer, errmsg, rc);
796 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
797 int count, int *eof, void *data)
799 struct obd_device *obd = data;
800 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
802 if (mdt->mdt_nosquash_str)
803 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
804 return snprintf(page, count, "NONE\n");
807 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
808 unsigned long count, void *data)
810 struct obd_device *obd = data;
811 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
813 char *kernbuf, *errmsg;
817 OBD_ALLOC(kernbuf, count + 1);
818 if (kernbuf == NULL) {
819 errmsg = "no memory";
820 GOTO(failed, rc = -ENOMEM);
822 if (cfs_copy_from_user(kernbuf, buffer, count)) {
823 errmsg = "bad address";
824 GOTO(failed, rc = -EFAULT);
826 kernbuf[count] = '\0';
828 if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
829 /* empty string is special case */
830 cfs_down_write(&mdt->mdt_squash_sem);
831 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
832 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
833 OBD_FREE(mdt->mdt_nosquash_str,
834 mdt->mdt_nosquash_strlen);
835 mdt->mdt_nosquash_str = NULL;
836 mdt->mdt_nosquash_strlen = 0;
838 cfs_up_write(&mdt->mdt_squash_sem);
839 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
841 OBD_FREE(kernbuf, count + 1);
845 CFS_INIT_LIST_HEAD(&tmp);
846 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
847 errmsg = "can't parse";
848 GOTO(failed, rc = -EINVAL);
851 cfs_down_write(&mdt->mdt_squash_sem);
852 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
853 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
854 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
856 mdt->mdt_nosquash_str = kernbuf;
857 mdt->mdt_nosquash_strlen = count + 1;
858 cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
860 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
861 obd->obd_name, kernbuf);
862 cfs_up_write(&mdt->mdt_squash_sem);
866 CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
867 obd->obd_name, kernbuf, errmsg, rc);
869 OBD_FREE(kernbuf, count + 1);
873 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
874 int count, int *eof, void *data)
876 struct obd_device *obd = data;
877 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
879 return snprintf(page, count, "%sabled\n",
880 mdt->mdt_som_conf ? "en" : "dis");
883 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
884 unsigned long count, void *data)
886 struct obd_export *exp;
887 struct obd_device *obd = data;
888 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
890 unsigned long val = 0;
892 if (count > (sizeof(kernbuf) - 1))
895 if (cfs_copy_from_user(kernbuf, buffer, count))
898 kernbuf[count] = '\0';
900 if (!strcmp(kernbuf, "enabled"))
902 else if (strcmp(kernbuf, "disabled"))
905 if (mdt->mdt_som_conf == val)
908 if (!obd->obd_process_conf) {
909 CERROR("Temporary SOM change is not supported, use lctl "
910 "conf_param for permanent setting\n");
914 /* 1 stands for self export. */
915 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
916 if (exp == obd->obd_self_export)
918 if (exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)
920 /* Some clients are already connected, skip the change */
921 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
922 "the next mount\n", exp->exp_client_uuid.uuid,
923 val ? "enabled" : "disabled");
927 mdt->mdt_som_conf = val;
928 LCONSOLE_INFO("Enabling SOM\n");
933 /* Temporary; for testing purposes only */
934 static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
935 unsigned long count, void *data)
937 struct obd_device *obd = data;
938 struct obd_export *exp = NULL;
939 struct obd_uuid *uuid;
943 OBD_ALLOC(kbuf, UUID_MAX);
948 * OBD_ALLOC() will zero kbuf, but we only copy UUID_MAX - 1
949 * bytes into kbuf, to ensure that the string is NUL-terminated.
950 * UUID_MAX should include a trailing NUL already.
952 if (cfs_copy_from_user(kbuf, buffer,
953 min_t(unsigned long, UUID_MAX - 1, count))) {
957 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, UUID_MAX - 1, count));
959 OBD_ALLOC(uuid, UUID_MAX);
965 obd_str2uuid(uuid, tmpbuf);
966 exp = cfs_hash_lookup(obd->obd_uuid_hash, uuid);
968 CERROR("%s: no export %s found\n",
969 obd->obd_name, obd_uuid2str(uuid));
971 mdt_hsm_copytool_send(exp);
972 class_export_put(exp);
975 OBD_FREE(uuid, UUID_MAX);
977 OBD_FREE(kbuf, UUID_MAX);
981 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
982 { "uuid", lprocfs_rd_uuid, 0, 0 },
983 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
984 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
985 { "identity_expire", lprocfs_rd_identity_expire,
986 lprocfs_wr_identity_expire, 0 },
987 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
988 lprocfs_wr_identity_acquire_expire, 0 },
989 { "identity_upcall", lprocfs_rd_identity_upcall,
990 lprocfs_wr_identity_upcall, 0 },
991 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
992 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
993 { "capa", lprocfs_rd_capa,
994 lprocfs_wr_capa, 0 },
995 { "capa_timeout", lprocfs_rd_capa_timeout,
996 lprocfs_wr_capa_timeout, 0 },
997 { "capa_key_timeout", lprocfs_rd_ck_timeout,
998 lprocfs_wr_ck_timeout, 0 },
999 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
1000 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
1001 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
1002 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
1003 { "sec_level", lprocfs_rd_sec_level,
1004 lprocfs_wr_sec_level, 0 },
1005 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
1006 { "root_squash", lprocfs_rd_root_squash,
1007 lprocfs_wr_root_squash, 0 },
1008 { "nosquash_nids", lprocfs_rd_nosquash_nids,
1009 lprocfs_wr_nosquash_nids, 0 },
1010 { "som", lprocfs_rd_mdt_som,
1011 lprocfs_wr_mdt_som, 0 },
1012 { "mdccomm", 0, lprocfs_mdt_wr_mdc, 0 },
1013 { "instance", lprocfs_target_rd_instance, 0 },
1014 { "ir_factor", lprocfs_obd_rd_ir_factor,
1015 lprocfs_obd_wr_ir_factor, 0 },
1019 static struct lprocfs_vars lprocfs_mdt_module_vars[] = {
1020 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
1024 void lprocfs_mdt_init_vars(struct lprocfs_static_vars *lvars)
1026 lvars->module_vars = lprocfs_mdt_module_vars;
1027 lvars->obd_vars = lprocfs_mdt_obd_vars;
1030 void mdt_counter_incr(struct obd_export *exp, int opcode)
1032 if (exp->exp_obd && exp->exp_obd->md_stats)
1033 lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
1034 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1035 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1039 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1041 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
1042 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
1043 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
1044 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
1045 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
1046 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
1047 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
1048 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
1049 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
1050 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
1051 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
1052 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
1053 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
1054 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
1055 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
1056 "samedir_rename", "reqs");
1057 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
1058 "crossdir_rename", "reqs");