1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 * lustre/mdt/mdt_lproc.c
40 * Author: Lai Siyao <lsy@clusterfs.com>
41 * Author: Fan Yong <fanyong@clusterfs.com>
45 # define EXPORT_SYMTAB
47 #define DEBUG_SUBSYSTEM S_MDS
49 #include <linux/version.h>
50 #include <asm/statfs.h>
52 #include <linux/module.h>
54 /* LUSTRE_VERSION_CODE */
55 #include <lustre_ver.h>
57 * struct OBD_{ALLOC,FREE}*()
60 #include <obd_support.h>
61 /* struct obd_export */
62 #include <lustre_export.h>
63 /* struct obd_device */
65 #include <obd_class.h>
66 #include <lustre_mds.h>
67 #include <lustre_mdt.h>
68 #include <lprocfs_status.h>
70 #include "mdt_internal.h"
71 #include <lnet/lib-lnet.h>
76 static const char *mdt_proc_names[LPROC_MDT_NR] = {
80 * The rename stats output would be YAML formats, like
82 * - snapshot_time: 1234567890.123456
84 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
85 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
86 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
88 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
89 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
90 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
92 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
93 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
94 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
97 #define pct(a, b) (b ? a * 100 / b : 0)
99 static void display_rename_stats(struct seq_file *seq, char *name,
100 struct obd_histogram *hist)
102 unsigned long tot, t, cum = 0;
105 tot = lprocfs_oh_sum(hist);
107 seq_printf(seq, "- %-15s\n", name);
108 /* dir size start from 4K, start i from 10(2^10) here */
109 for (i = 0; i < OBD_HIST_MAX; i++) {
110 t = hist->oh_buckets[i];
116 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
118 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
120 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
122 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
123 t, pct(t, tot), pct(cum, tot));
130 static void rename_stats_show(struct seq_file *seq,
131 struct rename_stats *rename_stats)
135 /* this sampling races with updates */
136 do_gettimeofday(&now);
137 seq_printf(seq, "rename_stats:\n");
138 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
139 now.tv_sec, now.tv_usec);
141 display_rename_stats(seq, "same_dir",
142 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
143 display_rename_stats(seq, "crossdir_src",
144 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
145 display_rename_stats(seq, "crossdir_tgt",
146 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
151 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
153 struct mdt_device *mdt = seq->private;
155 rename_stats_show(seq, &mdt->mdt_rename_stats);
160 static ssize_t mdt_rename_stats_seq_write(struct file *file, const char *buf,
161 size_t len, loff_t *off)
163 struct seq_file *seq = file->private_data;
164 struct mdt_device *mdt = seq->private;
167 for (i = 0; i < RENAME_LAST; i++)
168 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
173 LPROC_SEQ_FOPS(mdt_rename_stats);
175 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
177 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
178 struct obd_device *obd = ld->ld_obd;
181 for (i = 0; i < RENAME_LAST; i++)
182 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
184 return lprocfs_obd_seq_create(obd, "rename_stats", 0444,
185 &mdt_rename_stats_fops, mdt);
188 void mdt_rename_counter_tally(struct mdt_thread_info *info,
189 struct mdt_device *mdt,
190 struct obd_export *exp,
191 struct mdt_object *src,
192 struct mdt_object *tgt)
194 struct md_attr *ma = &info->mti_attr;
195 struct rename_stats *rstats = &mdt->mdt_rename_stats;
198 ma->ma_need = MA_INODE;
200 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
202 CERROR("%s: "DFID" attr_get, rc = %d\n",
203 exp->exp_obd->obd_name, PFID(mdt_object_fid(src)), rc);
208 mdt_counter_incr(exp, LPROC_MDT_SAMEDIR_RENAME);
209 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
210 (unsigned int)ma->ma_attr.la_size);
214 mdt_counter_incr(exp, LPROC_MDT_CROSSDIR_RENAME);
215 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
216 (unsigned int)ma->ma_attr.la_size);
218 ma->ma_need = MA_INODE;
220 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
222 CERROR("%s: "DFID" attr_get, rc = %d\n",
223 exp->exp_obd->obd_name, PFID(mdt_object_fid(tgt)), rc);
227 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
228 (unsigned int)ma->ma_attr.la_size);
231 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
233 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
234 struct obd_device *obd = ld->ld_obd;
235 struct lprocfs_static_vars lvars;
239 LASSERT(name != NULL);
241 lprocfs_mdt_init_vars(&lvars);
242 rc = lprocfs_obd_setup(obd, lvars.obd_vars);
244 CERROR("Can't init lprocfs, rc %d\n", rc);
247 ptlrpc_lprocfs_register_obd(obd);
249 mdt->mdt_proc_entry = obd->obd_proc_entry;
250 LASSERT(mdt->mdt_proc_entry != NULL);
252 rc = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
253 mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
255 rc = lu_time_named_init(&ld->ld_site->ls_time_stats,
256 "site_time", mdt->mdt_proc_entry,
258 ARRAY_SIZE(lu_time_names));
262 obd->obd_proc_exports_entry = proc_mkdir("exports",
263 obd->obd_proc_entry);
264 if (obd->obd_proc_exports_entry)
265 lprocfs_add_simple(obd->obd_proc_exports_entry,
266 "clear", lprocfs_nid_stats_clear_read,
267 lprocfs_nid_stats_clear_write, obd, NULL);
268 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
270 mdt_stats_counter_init(obd->md_stats);
272 rc = lproc_mdt_attach_rename_seqstat(mdt);
274 CERROR("%s: MDT can not create rename stats rc = %d\n",
280 int mdt_procfs_fini(struct mdt_device *mdt)
282 struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
283 struct obd_device *obd = ld->ld_obd;
285 if (obd->obd_proc_exports_entry) {
286 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
287 obd->obd_proc_exports_entry = NULL;
289 lprocfs_free_per_client_stats(obd);
290 lprocfs_obd_cleanup(obd);
291 ptlrpc_lprocfs_unregister_obd(obd);
292 if (mdt->mdt_proc_entry) {
293 lu_time_fini(&ld->ld_site->ls_time_stats);
294 lu_time_fini(&mdt->mdt_stats);
295 mdt->mdt_proc_entry = NULL;
297 lprocfs_free_md_stats(obd);
298 lprocfs_free_obd_stats(obd);
303 void mdt_time_start(const struct mdt_thread_info *info)
305 lu_lprocfs_time_start(info->mti_env);
308 void mdt_time_end(const struct mdt_thread_info *info, int idx)
310 lu_lprocfs_time_end(info->mti_env, info->mti_mdt->mdt_stats, idx);
313 static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
314 int count, int *eof, void *data)
316 struct obd_device *obd = data;
317 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
320 return snprintf(page, count, "%u\n",
321 mdt->mdt_identity_cache->uc_entry_expire);
324 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
325 unsigned long count, void *data)
327 struct obd_device *obd = data;
328 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
331 rc = lprocfs_write_helper(buffer, count, &val);
335 mdt->mdt_identity_cache->uc_entry_expire = val;
339 static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
340 off_t off, int count, int *eof,
343 struct obd_device *obd = data;
344 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
347 return snprintf(page, count, "%u\n",
348 mdt->mdt_identity_cache->uc_acquire_expire);
351 static int lprocfs_wr_identity_acquire_expire(struct file *file,
356 struct obd_device *obd = data;
357 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
360 rc = lprocfs_write_helper(buffer, count, &val);
364 mdt->mdt_identity_cache->uc_acquire_expire = val;
368 static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
369 int count, int *eof, void *data)
371 struct obd_device *obd = data;
372 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
373 struct upcall_cache *hash = mdt->mdt_identity_cache;
377 cfs_read_lock(&hash->uc_upcall_rwlock);
378 len = snprintf(page, count, "%s\n", hash->uc_upcall);
379 cfs_read_unlock(&hash->uc_upcall_rwlock);
383 static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
384 unsigned long count, void *data)
386 struct obd_device *obd = data;
387 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
388 struct upcall_cache *hash = mdt->mdt_identity_cache;
392 if (count >= UC_CACHE_UPCALL_MAXPATH) {
393 CERROR("%s: identity upcall too long\n", obd->obd_name);
396 OBD_ALLOC(kernbuf, count + 1);
398 GOTO(failed, rc = -ENOMEM);
399 if (cfs_copy_from_user(kernbuf, buffer, count))
400 GOTO(failed, rc = -EFAULT);
402 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
403 cfs_write_lock(&hash->uc_upcall_rwlock);
404 sscanf(kernbuf, "%s", hash->uc_upcall);
405 cfs_write_unlock(&hash->uc_upcall_rwlock);
407 if (strcmp(hash->uc_name, obd->obd_name) != 0)
408 CWARN("%s: write to upcall name %s\n",
409 obd->obd_name, hash->uc_upcall);
411 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
412 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
413 "cause unexpected \"EACCESS\"\n", obd->obd_name);
415 CWARN("%s: identity upcall set to %s\n", obd->obd_name, hash->uc_upcall);
416 OBD_FREE(kernbuf, count + 1);
421 OBD_FREE(kernbuf, count + 1);
425 static int lprocfs_wr_identity_flush(struct file *file, const char *buffer,
426 unsigned long count, void *data)
428 struct obd_device *obd = data;
429 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
432 rc = lprocfs_write_helper(buffer, count, &uid);
436 mdt_flush_identity(mdt->mdt_identity_cache, uid);
440 static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
441 unsigned long count, void *data)
443 struct obd_device *obd = data;
444 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
445 struct identity_downcall_data *param;
446 int size = sizeof(*param), rc, checked = 0;
450 CERROR("%s: invalid data count = %lu, size = %d\n",
451 obd->obd_name, count, size);
455 OBD_ALLOC(param, size);
459 if (cfs_copy_from_user(param, buffer, size)) {
460 CERROR("%s: bad identity data\n", obd->obd_name);
461 GOTO(out, rc = -EFAULT);
466 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
467 CERROR("%s: MDS identity downcall bad params\n",
469 GOTO(out, rc = -EINVAL);
472 if (param->idd_nperms > N_PERMS_MAX) {
473 CERROR("%s: perm count %d more than maximum %d\n",
474 obd->obd_name, param->idd_nperms, N_PERMS_MAX);
475 GOTO(out, rc = -EINVAL);
478 if (param->idd_ngroups > NGROUPS_MAX) {
479 CERROR("%s: group count %d more than maximum %d\n",
480 obd->obd_name, param->idd_ngroups, NGROUPS_MAX);
481 GOTO(out, rc = -EINVAL);
484 if (param->idd_ngroups) {
485 rc = param->idd_ngroups; /* save idd_ngroups */
486 OBD_FREE(param, size);
487 size = offsetof(struct identity_downcall_data,
493 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
494 param->idd_uid, param);
498 OBD_FREE(param, size);
500 return rc ? rc : count;
504 static int lprocfs_rd_capa(char *page, char **start, off_t off,
505 int count, int *eof, void *data)
507 struct obd_device *obd = data;
508 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
510 return snprintf(page, count, "capability on: %s %s\n",
511 mdt->mdt_opts.mo_oss_capa ? "oss" : "",
512 mdt->mdt_opts.mo_mds_capa ? "mds" : "");
515 static int lprocfs_wr_capa(struct file *file, const char *buffer,
516 unsigned long count, void *data)
518 struct obd_device *obd = data;
519 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
522 rc = lprocfs_write_helper(buffer, count, &val);
526 if (val < 0 || val > 3) {
527 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
528 " 0: disable fid capability\n"
529 " 2: enable MDS fid capability\n"
530 " 3: enable both MDS and OSS fid capability\n");
534 /* OSS fid capability needs enable both MDS and OSS fid capability on
537 CERROR("can't enable OSS fid capability only, you should use "
538 "'3' to enable both MDS and OSS fid capability.\n");
542 mdt->mdt_opts.mo_oss_capa = (val & 0x1);
543 mdt->mdt_opts.mo_mds_capa = !!(val & 0x2);
544 mdt->mdt_capa_conf = 1;
545 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
547 mdt->mdt_opts.mo_mds_capa ? "enabled" : "disabled");
548 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
550 mdt->mdt_opts.mo_oss_capa ? "enabled" : "disabled");
554 static int lprocfs_rd_capa_count(char *page, char **start, off_t off,
555 int count, int *eof, void *data)
557 return snprintf(page, count, "%d %d\n",
558 capa_count[CAPA_SITE_CLIENT],
559 capa_count[CAPA_SITE_SERVER]);
562 static int lprocfs_rd_site_stats(char *page, char **start, off_t off,
563 int count, int *eof, void *data)
565 struct obd_device *obd = data;
566 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
568 return lu_site_stats_print(mdt_lu_site(mdt), page, count);
571 static int lprocfs_rd_capa_timeout(char *page, char **start, off_t off,
572 int count, int *eof, void *data)
574 struct obd_device *obd = data;
575 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
577 return snprintf(page, count, "%lu\n", mdt->mdt_capa_timeout);
580 static int lprocfs_wr_capa_timeout(struct file *file, const char *buffer,
581 unsigned long count, void *data)
583 struct obd_device *obd = data;
584 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
587 rc = lprocfs_write_helper(buffer, count, &val);
591 mdt->mdt_capa_timeout = (unsigned long)val;
592 mdt->mdt_capa_conf = 1;
596 static int lprocfs_rd_ck_timeout(char *page, char **start, off_t off, int count,
597 int *eof, void *data)
599 struct obd_device *obd = data;
600 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
602 return snprintf(page, count, "%lu\n", mdt->mdt_ck_timeout);
605 static int lprocfs_wr_ck_timeout(struct file *file, const char *buffer,
606 unsigned long count, void *data)
608 struct obd_device *obd = data;
609 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
612 rc = lprocfs_write_helper(buffer, count, &val);
616 mdt->mdt_ck_timeout = (unsigned long)val;
617 mdt->mdt_capa_conf = 1;
621 #define BUFLEN (UUID_MAX + 4)
623 static int lprocfs_mdt_wr_evict_client(struct file *file, const char *buffer,
624 unsigned long count, void *data)
629 OBD_ALLOC(kbuf, BUFLEN);
634 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
635 * bytes into kbuf, to ensure that the string is NUL-terminated.
636 * UUID_MAX should include a trailing NUL already.
638 if (cfs_copy_from_user(kbuf, buffer,
639 min_t(unsigned long, BUFLEN - 1, count))) {
643 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
645 if (strncmp(tmpbuf, "nid:", 4) != 0) {
646 count = lprocfs_wr_evict_client(file, buffer, count, data);
650 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
653 OBD_FREE(kbuf, BUFLEN);
659 static int lprocfs_rd_sec_level(char *page, char **start, off_t off,
660 int count, int *eof, void *data)
662 struct obd_device *obd = data;
663 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
665 return snprintf(page, count, "%d\n", mdt->mdt_sec_level);
668 static int lprocfs_wr_sec_level(struct file *file, const char *buffer,
669 unsigned long count, void *data)
671 struct obd_device *obd = data;
672 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
675 rc = lprocfs_write_helper(buffer, count, &val);
679 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
682 if (val == LUSTRE_SEC_SPECIFY) {
683 CWARN("security level %d will be supported in future.\n",
688 mdt->mdt_sec_level = val;
692 static int lprocfs_rd_cos(char *page, char **start, off_t off,
693 int count, int *eof, void *data)
695 struct obd_device *obd = data;
696 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
698 return snprintf(page, count, "%u\n", mdt_cos_is_enabled(mdt));
701 static int lprocfs_wr_cos(struct file *file, const char *buffer,
702 unsigned long count, void *data)
704 struct obd_device *obd = data;
705 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
708 rc = lprocfs_write_helper(buffer, count, &val);
711 mdt_enable_cos(mdt, val);
715 static int lprocfs_rd_root_squash(char *page, char **start, off_t off,
716 int count, int *eof, void *data)
718 struct obd_device *obd = data;
719 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
721 return snprintf(page, count, "%u:%u\n", mdt->mdt_squash_uid,
722 mdt->mdt_squash_gid);
725 static int safe_strtoul(const char *str, char **endp, unsigned long *res)
729 *res = simple_strtoul(str, endp, 0);
733 sprintf(n, "%lu", *res);
734 if (strncmp(n, str, *endp - str))
740 static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
741 unsigned long count, void *data)
743 struct obd_device *obd = data;
744 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
746 char kernbuf[50], *tmp, *end, *errmsg;
747 unsigned long uid, gid;
751 if (count >= sizeof(kernbuf)) {
752 errmsg = "string too long";
753 GOTO(failed, rc = -EINVAL);
755 if (cfs_copy_from_user(kernbuf, buffer, count)) {
756 errmsg = "bad address";
757 GOTO(failed, rc = -EFAULT);
759 kernbuf[count] = '\0';
762 if (safe_strtoul(buffer, &tmp, &uid)) {
763 uid = mdt->mdt_squash_uid;
770 if (safe_strtoul(tmp, &end, &gid)) {
771 gid = mdt->mdt_squash_gid;
775 gid = mdt->mdt_squash_gid;
779 mdt->mdt_squash_uid = uid;
780 mdt->mdt_squash_gid = gid;
782 if (nouid && nogid) {
783 errmsg = "needs uid:gid format";
784 GOTO(failed, rc = -EINVAL);
787 LCONSOLE_INFO("%s: root_squash is set to %u:%u\n",
789 mdt->mdt_squash_uid, mdt->mdt_squash_gid);
793 CWARN("%s: failed to set root_squash to \"%s\", %s: rc %d\n",
794 obd->obd_name, buffer, errmsg, rc);
798 static int lprocfs_rd_nosquash_nids(char *page, char **start, off_t off,
799 int count, int *eof, void *data)
801 struct obd_device *obd = data;
802 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
804 if (mdt->mdt_nosquash_str)
805 return snprintf(page, count, "%s\n", mdt->mdt_nosquash_str);
806 return snprintf(page, count, "NONE\n");
809 static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
810 unsigned long count, void *data)
812 struct obd_device *obd = data;
813 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
815 char *kernbuf, *errmsg;
819 OBD_ALLOC(kernbuf, count + 1);
820 if (kernbuf == NULL) {
821 errmsg = "no memory";
822 GOTO(failed, rc = -ENOMEM);
824 if (cfs_copy_from_user(kernbuf, buffer, count)) {
825 errmsg = "bad address";
826 GOTO(failed, rc = -EFAULT);
828 kernbuf[count] = '\0';
830 if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
831 /* empty string is special case */
832 cfs_down_write(&mdt->mdt_squash_sem);
833 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
834 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
835 OBD_FREE(mdt->mdt_nosquash_str,
836 mdt->mdt_nosquash_strlen);
837 mdt->mdt_nosquash_str = NULL;
838 mdt->mdt_nosquash_strlen = 0;
840 cfs_up_write(&mdt->mdt_squash_sem);
841 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
843 OBD_FREE(kernbuf, count + 1);
847 CFS_INIT_LIST_HEAD(&tmp);
848 if (cfs_parse_nidlist(kernbuf, count, &tmp) <= 0) {
849 errmsg = "can't parse";
850 GOTO(failed, rc = -EINVAL);
853 cfs_down_write(&mdt->mdt_squash_sem);
854 if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
855 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
856 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
858 mdt->mdt_nosquash_str = kernbuf;
859 mdt->mdt_nosquash_strlen = count + 1;
860 cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
862 LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
863 obd->obd_name, kernbuf);
864 cfs_up_write(&mdt->mdt_squash_sem);
868 CWARN("%s: failed to set nosquash_nids to \"%s\", %s: rc %d\n",
869 obd->obd_name, kernbuf, errmsg, rc);
871 OBD_FREE(kernbuf, count + 1);
875 static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
876 int count, int *eof, void *data)
878 struct obd_device *obd = data;
879 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
881 return snprintf(page, count, "%sabled\n",
882 mdt->mdt_som_conf ? "en" : "dis");
885 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
886 unsigned long count, void *data)
888 struct obd_export *exp;
889 struct obd_device *obd = data;
890 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
892 unsigned long val = 0;
894 if (count > (sizeof(kernbuf) - 1))
897 if (cfs_copy_from_user(kernbuf, buffer, count))
900 kernbuf[count] = '\0';
902 if (!strcmp(kernbuf, "enabled"))
904 else if (strcmp(kernbuf, "disabled"))
907 if (mdt->mdt_som_conf == val)
910 if (!obd->obd_process_conf) {
911 CERROR("Temporary SOM change is not supported, use lctl "
912 "conf_param for permanent setting\n");
916 /* 1 stands for self export. */
917 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
918 if (exp == obd->obd_self_export)
920 if (exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)
922 /* Some clients are already connected, skip the change */
923 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
924 "the next mount\n", exp->exp_client_uuid.uuid,
925 val ? "enabled" : "disabled");
929 mdt->mdt_som_conf = val;
930 LCONSOLE_INFO("Enabling SOM\n");
935 /* Temporary; for testing purposes only */
936 static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
937 unsigned long count, void *data)
939 struct obd_device *obd = data;
940 struct obd_export *exp = NULL;
941 struct obd_uuid *uuid;
945 OBD_ALLOC(kbuf, UUID_MAX);
950 * OBD_ALLOC() will zero kbuf, but we only copy UUID_MAX - 1
951 * bytes into kbuf, to ensure that the string is NUL-terminated.
952 * UUID_MAX should include a trailing NUL already.
954 if (cfs_copy_from_user(kbuf, buffer,
955 min_t(unsigned long, UUID_MAX - 1, count))) {
959 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, UUID_MAX - 1, count));
961 OBD_ALLOC(uuid, UUID_MAX);
967 obd_str2uuid(uuid, tmpbuf);
968 exp = cfs_hash_lookup(obd->obd_uuid_hash, uuid);
970 CERROR("%s: no export %s found\n",
971 obd->obd_name, obd_uuid2str(uuid));
973 mdt_hsm_copytool_send(exp);
974 class_export_put(exp);
977 OBD_FREE(uuid, UUID_MAX);
979 OBD_FREE(kbuf, UUID_MAX);
983 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
984 { "uuid", lprocfs_rd_uuid, 0, 0 },
985 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
986 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
987 { "identity_expire", lprocfs_rd_identity_expire,
988 lprocfs_wr_identity_expire, 0 },
989 { "identity_acquire_expire", lprocfs_rd_identity_acquire_expire,
990 lprocfs_wr_identity_acquire_expire, 0 },
991 { "identity_upcall", lprocfs_rd_identity_upcall,
992 lprocfs_wr_identity_upcall, 0 },
993 { "identity_flush", 0, lprocfs_wr_identity_flush, 0 },
994 { "identity_info", 0, lprocfs_wr_identity_info, 0 },
995 { "capa", lprocfs_rd_capa,
996 lprocfs_wr_capa, 0 },
997 { "capa_timeout", lprocfs_rd_capa_timeout,
998 lprocfs_wr_capa_timeout, 0 },
999 { "capa_key_timeout", lprocfs_rd_ck_timeout,
1000 lprocfs_wr_ck_timeout, 0 },
1001 { "capa_count", lprocfs_rd_capa_count, 0, 0 },
1002 { "site_stats", lprocfs_rd_site_stats, 0, 0 },
1003 { "evict_client", 0, lprocfs_mdt_wr_evict_client, 0 },
1004 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
1005 { "sec_level", lprocfs_rd_sec_level,
1006 lprocfs_wr_sec_level, 0 },
1007 { "commit_on_sharing", lprocfs_rd_cos, lprocfs_wr_cos, 0 },
1008 { "root_squash", lprocfs_rd_root_squash,
1009 lprocfs_wr_root_squash, 0 },
1010 { "nosquash_nids", lprocfs_rd_nosquash_nids,
1011 lprocfs_wr_nosquash_nids, 0 },
1012 { "som", lprocfs_rd_mdt_som,
1013 lprocfs_wr_mdt_som, 0 },
1014 { "mdccomm", 0, lprocfs_mdt_wr_mdc, 0 },
1015 { "instance", lprocfs_target_rd_instance, 0 },
1016 { "ir_factor", lprocfs_obd_rd_ir_factor,
1017 lprocfs_obd_wr_ir_factor, 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 void mdt_counter_incr(struct obd_export *exp, int opcode)
1034 if (exp->exp_obd && exp->exp_obd->md_stats)
1035 lprocfs_counter_incr(exp->exp_obd->md_stats, opcode);
1036 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1037 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1041 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1043 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
1044 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
1045 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
1046 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
1047 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
1048 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
1049 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
1050 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
1051 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
1052 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
1053 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
1054 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
1055 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
1056 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
1057 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
1058 "samedir_rename", "reqs");
1059 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
1060 "crossdir_rename", "reqs");