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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * lustre/mdt/mdt_lproc.c
33 * Author: Lai Siyao <lsy@clusterfs.com>
34 * Author: Fan Yong <fanyong@clusterfs.com>
37 #define DEBUG_SUBSYSTEM S_MDS
39 #include <linux/version.h>
40 #include <asm/statfs.h>
42 #include <linux/module.h>
43 #include <uapi/linux/lnet/nidstr.h>
44 /* LUSTRE_VERSION_CODE */
45 #include <uapi/linux/lustre/lustre_ver.h>
47 * struct OBD_{ALLOC,FREE}*()
50 #include <obd_support.h>
51 /* struct obd_export */
52 #include <lustre_export.h>
53 /* struct obd_device */
55 #include <obd_class.h>
56 #include <lustre_mds.h>
57 #include <lprocfs_status.h>
58 #include "mdt_internal.h"
59 #include <obd_cksum.h>
62 * The rename stats output would be YAML formats, like
64 * - snapshot_time: 1234567890.123456789
65 * - start_time: 1234567880.987654321
66 * - elapsed_time: 9.135802468
68 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
69 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
70 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
72 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
73 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
74 * 16kB: { samples: 12, 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 }
81 static void display_rename_stats(struct seq_file *seq, char *name,
82 struct obd_histogram *rs_hist)
84 unsigned long tot, t, cum = 0;
87 tot = lprocfs_oh_sum(rs_hist);
89 seq_printf(seq, "- %s:\n", name);
91 for (i = 0; i < OBD_HIST_MAX; i++) {
92 t = rs_hist->oh_buckets[i];
98 seq_printf(seq, "%6s%d%s", " ", 1 << i, "bytes:");
100 seq_printf(seq, "%6s%d%s", " ", 1 << (i - 10), "KB:");
102 seq_printf(seq, "%6s%d%s", " ", 1 << (i - 20), "MB:");
104 seq_printf(seq, " { sample: %3lu, pct: %3u, cum_pct: %3u }\n",
105 t, pct(t, tot), pct(cum, tot));
112 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
114 struct mdt_device *mdt = seq->private;
115 struct rename_stats *rename_stats = &mdt->mdt_rename_stats;
117 /* this sampling races with updates */
118 seq_puts(seq, "rename_stats:\n");
119 lprocfs_stats_header(seq, ktime_get_real(), rename_stats->rs_init, 15,
122 display_rename_stats(seq, "same_dir",
123 &rename_stats->rs_hist[RENAME_SAMEDIR_SIZE]);
124 display_rename_stats(seq, "crossdir_src",
125 &rename_stats->rs_hist[RENAME_CROSSDIR_SRC_SIZE]);
126 display_rename_stats(seq, "crossdir_tgt",
127 &rename_stats->rs_hist[RENAME_CROSSDIR_TGT_SIZE]);
133 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
134 size_t len, loff_t *off)
136 struct seq_file *seq = file->private_data;
137 struct mdt_device *mdt = seq->private;
140 for (i = 0; i < RENAME_LAST; i++)
141 lprocfs_oh_clear(&mdt->mdt_rename_stats.rs_hist[i]);
142 mdt->mdt_rename_stats.rs_init = ktime_get_real();
146 LPROC_SEQ_FOPS(mdt_rename_stats);
148 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
152 for (i = 0; i < RENAME_LAST; i++)
153 spin_lock_init(&mdt->mdt_rename_stats.rs_hist[i].oh_lock);
154 mdt->mdt_rename_stats.rs_init = ktime_get_real();
156 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
157 &mdt_rename_stats_fops, mdt);
160 void mdt_rename_counter_tally(struct mdt_thread_info *info,
161 struct mdt_device *mdt,
162 struct ptlrpc_request *req,
163 struct mdt_object *src, struct mdt_object *tgt,
164 enum mdt_stat_idx msi, s64 ktime_delta)
166 struct md_attr *ma = &info->mti_attr;
167 struct rename_stats *rstats = &mdt->mdt_rename_stats;
170 mdt_counter_incr(req, LPROC_MDT_RENAME, ktime_delta);
172 ma->ma_need = MA_INODE;
174 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
176 CERROR("%s: "DFID" attr_get, rc = %d\n",
177 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
181 if (msi) /* parallel rename type */
182 mdt_counter_incr(req, msi, ktime_delta);
185 mdt_counter_incr(req, LPROC_MDT_RENAME_SAMEDIR, ktime_delta);
186 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_SAMEDIR_SIZE],
187 (unsigned int)ma->ma_attr.la_size);
191 mdt_counter_incr(req, LPROC_MDT_RENAME_CROSSDIR, ktime_delta);
192 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_SRC_SIZE],
193 (unsigned int)ma->ma_attr.la_size);
195 ma->ma_need = MA_INODE;
197 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
199 CERROR("%s: "DFID" attr_get, rc = %d\n",
200 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
204 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_TGT_SIZE],
205 (unsigned int)ma->ma_attr.la_size);
208 static ssize_t identity_expire_show(struct kobject *kobj,
209 struct attribute *attr, char *buf)
211 struct obd_device *obd = container_of(kobj, struct obd_device,
213 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
215 return scnprintf(buf, PAGE_SIZE, "%lld\n",
216 mdt->mdt_identity_cache->uc_entry_expire);
219 static ssize_t identity_expire_store(struct kobject *kobj,
220 struct attribute *attr,
221 const char *buffer, size_t count)
223 struct obd_device *obd = container_of(kobj, struct obd_device,
225 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
229 rc = kstrtoll(buffer, 10, &val);
236 mdt->mdt_identity_cache->uc_entry_expire = val;
240 LUSTRE_RW_ATTR(identity_expire);
242 static ssize_t identity_acquire_expire_show(struct kobject *kobj,
243 struct attribute *attr, char *buf)
245 struct obd_device *obd = container_of(kobj, struct obd_device,
247 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
249 return scnprintf(buf, PAGE_SIZE, "%lld\n",
250 mdt->mdt_identity_cache->uc_acquire_expire);
253 static ssize_t identity_acquire_expire_store(struct kobject *kobj,
254 struct attribute *attr,
255 const char *buffer, size_t count)
257 struct obd_device *obd = container_of(kobj, struct obd_device,
259 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
263 rc = kstrtoll(buffer, 0, &val);
267 if (val < 0 || val > INT_MAX)
270 mdt->mdt_identity_cache->uc_acquire_expire = val;
274 LUSTRE_RW_ATTR(identity_acquire_expire);
276 static ssize_t identity_upcall_show(struct kobject *kobj,
277 struct attribute *attr, char *buf)
279 struct obd_device *obd = container_of(kobj, struct obd_device,
281 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
282 struct upcall_cache *hash = mdt->mdt_identity_cache;
285 down_read(&hash->uc_upcall_rwsem);
286 rc = scnprintf(buf, PAGE_SIZE, "%s\n", hash->uc_upcall);
287 up_read(&hash->uc_upcall_rwsem);
291 static ssize_t identity_upcall_store(struct kobject *kobj,
292 struct attribute *attr,
293 const char *buffer, size_t count)
295 struct obd_device *obd = container_of(kobj, struct obd_device,
297 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
298 struct upcall_cache *hash = mdt->mdt_identity_cache;
301 rc = upcall_cache_set_upcall(hash, buffer, count, false);
303 CERROR("%s: incorrect identity upcall %.*s. Valid values for mdt.%s.identity_upcall are NONE, or an executable pathname: rc = %d\n",
304 mdt_obd_name(mdt), (int)count, buffer,
305 mdt_obd_name(mdt), rc);
309 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
310 CWARN("%s: write to upcall name %s\n",
311 mdt_obd_name(mdt), hash->uc_upcall);
313 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
314 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
315 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
317 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
321 LUSTRE_RW_ATTR(identity_upcall);
323 static ssize_t identity_flush_store(struct kobject *kobj,
324 struct attribute *attr,
325 const char *buffer, size_t count)
327 struct obd_device *obd = container_of(kobj, struct obd_device,
329 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
333 rc = kstrtoint(buffer, 0, &uid);
337 mdt_flush_identity(mdt->mdt_identity_cache, uid);
340 LUSTRE_WO_ATTR(identity_flush);
343 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
344 size_t count, void *data)
346 struct seq_file *m = file->private_data;
347 struct obd_device *obd = m->private;
348 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
349 struct identity_downcall_data *param;
350 int size = sizeof(*param), rc, checked = 0;
354 CERROR("%s: invalid data count = %lu, size = %d\n",
355 mdt_obd_name(mdt), (unsigned long) count, size);
359 OBD_ALLOC(param, size);
363 if (copy_from_user(param, buffer, size)) {
364 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
365 GOTO(out, rc = -EFAULT);
370 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
371 CERROR("%s: MDS identity downcall bad params\n",
373 GOTO(out, rc = -EINVAL);
376 if (param->idd_nperms > N_PERMS_MAX) {
377 CERROR("%s: perm count %d more than maximum %d\n",
378 mdt_obd_name(mdt), param->idd_nperms,
380 GOTO(out, rc = -EINVAL);
383 if (param->idd_ngroups > NGROUPS_MAX) {
384 CERROR("%s: group count %d more than maximum %d\n",
385 mdt_obd_name(mdt), param->idd_ngroups,
387 GOTO(out, rc = -EINVAL);
390 if (param->idd_ngroups) {
391 rc = param->idd_ngroups; /* save idd_ngroups */
392 OBD_FREE(param, size);
393 size = offsetof(struct identity_downcall_data,
399 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
400 param->idd_uid, param);
404 OBD_FREE(param, size);
406 return rc ? rc : count;
408 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info);
410 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
412 struct obd_device *obd = m->private;
413 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
415 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
417 LPROC_SEQ_FOPS_RO(mdt_site_stats);
419 #define BUFLEN (UUID_MAX + 4)
422 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
423 size_t count, loff_t *off)
425 struct seq_file *m = file->private_data;
426 struct obd_device *obd = m->private;
427 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
432 OBD_ALLOC(kbuf, BUFLEN);
437 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
438 * bytes into kbuf, to ensure that the string is NUL-terminated.
439 * UUID_MAX should include a trailing NUL already.
441 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
442 GOTO(out, rc = -EFAULT);
443 tmpbuf = skip_spaces(kbuf);
444 tmpbuf = strsep(&tmpbuf, " \t\n\f\v\r");
446 if (strncmp(tmpbuf, "nid:", 4) != 0) {
447 count = lprocfs_evict_client_seq_write(file, buf, count, off);
451 if (mdt->mdt_evict_tgt_nids) {
452 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
453 sizeof(KEY_EVICT_BY_NID),
455 strlen(tmpbuf + 4) + 1,
458 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
462 /* See the comments in function lprocfs_wr_evict_client()
463 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
464 class_incref(obd, __func__, current);
465 obd_export_evict_by_nid(obd, tmpbuf + 4);
466 class_decref(obd, __func__, current);
470 OBD_FREE(kbuf, BUFLEN);
471 return rc < 0 ? rc : count;
476 static ssize_t commit_on_sharing_show(struct kobject *kobj,
477 struct attribute *attr, char *buf)
479 struct obd_device *obd = container_of(kobj, struct obd_device,
481 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
483 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt_cos_is_enabled(mdt));
486 static ssize_t commit_on_sharing_store(struct kobject *kobj,
487 struct attribute *attr,
488 const char *buffer, size_t count)
490 struct obd_device *obd = container_of(kobj, struct obd_device,
492 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
496 rc = kstrtobool(buffer, &val);
500 mdt_enable_cos(mdt, val);
503 LUSTRE_RW_ATTR(commit_on_sharing);
505 static ssize_t local_recovery_show(struct kobject *kobj,
506 struct attribute *attr, char *buf)
508 struct obd_device *obd = container_of(kobj, struct obd_device,
511 return scnprintf(buf, PAGE_SIZE, "%u\n",
512 obd2obt(obd)->obt_lut->lut_local_recovery);
515 static ssize_t local_recovery_store(struct kobject *kobj,
516 struct attribute *attr,
517 const char *buffer, size_t count)
519 struct obd_device *obd = container_of(kobj, struct obd_device,
524 rc = kstrtobool(buffer, &val);
528 obd2obt(obd)->obt_lut->lut_local_recovery = !!val;
531 LUSTRE_RW_ATTR(local_recovery);
533 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
535 struct obd_device *obd = m->private;
536 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
537 struct root_squash_info *squash = &mdt->mdt_squash;
539 seq_printf(m, "%u:%u\n", squash->rsi_uid,
545 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
546 size_t count, loff_t *off)
548 struct seq_file *m = file->private_data;
549 struct obd_device *obd = m->private;
550 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
551 struct root_squash_info *squash = &mdt->mdt_squash;
553 return lprocfs_wr_root_squash(buffer, count, squash,
556 LPROC_SEQ_FOPS(mdt_root_squash);
558 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
560 struct obd_device *obd = m->private;
561 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
562 struct root_squash_info *squash = &mdt->mdt_squash;
565 spin_lock(&squash->rsi_lock);
566 if (!list_empty(&squash->rsi_nosquash_nids)) {
567 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
568 &squash->rsi_nosquash_nids);
572 seq_puts(m, "NONE\n");
573 spin_unlock(&squash->rsi_lock);
579 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
580 size_t count, loff_t *off)
582 struct seq_file *m = file->private_data;
583 struct obd_device *obd = m->private;
584 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
585 struct root_squash_info *squash = &mdt->mdt_squash;
587 return lprocfs_wr_nosquash_nids(buffer, count, squash,
590 LPROC_SEQ_FOPS(mdt_nosquash_nids);
592 static const char *mdt_cap2str(int cap)
594 /* We don't allow using all capabilities, but the fields must exist.
595 * The supported capabilities are CAP_FS_SET and CAP_NFSD_SET, plus
596 * CAP_SYS_ADMIN for a bunch of HSM operations (that should be fixed).
598 static const char *const capability_names[] = {
600 "cap_dac_override", /* 1 */
601 "cap_dac_read_search", /* 2 */
602 "cap_fowner", /* 3 */
603 "cap_fsetid", /* 4 */
608 "cap_linux_immutable", /* 9 */
620 /* we should use more precise capabilities than this */
621 "cap_sys_admin", /* 21 */
624 "cap_sys_resource", /* 24 */
627 "cap_mknod", /* 27 */
632 "cap_mac_override", /* 32 */
635 if (cap >= ARRAY_SIZE(capability_names))
638 return capability_names[cap];
641 static ssize_t enable_cap_mask_show(struct kobject *kobj,
642 struct attribute *attr, char *buf)
644 struct obd_device *obd = container_of(kobj, struct obd_device,
646 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
647 u64 mask = mdt_cap2num(mdt->mdt_enable_cap_mask);
649 return cfs_mask2str(buf, PAGE_SIZE, mask, mdt_cap2str, ',');
652 static ssize_t enable_cap_mask_store(struct kobject *kobj,
653 struct attribute *attr,
654 const char *buffer, size_t count)
656 struct obd_device *obd = container_of(kobj, struct obd_device,
658 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
659 static kernel_cap_t allowed_cap = CAP_EMPTY_SET;
660 unsigned long long val;
663 rc = kstrtoull(buffer, 0, &val);
665 u64 cap = mdt_cap2num(mdt->mdt_enable_cap_mask);
667 /* the "allmask" is filtered by allowed_mask below */
668 rc = cfs_str2mask(buffer, mdt_cap2str, &cap, 0, ~0ULL, 0);
674 /* All of the capabilities that we currently allow/check */
675 if (unlikely(cap_isclear(allowed_cap))) {
676 allowed_cap = CAP_FS_SET;
677 cap_raise(allowed_cap, CAP_SYS_RESOURCE);
680 mdt->mdt_enable_cap_mask = cap_intersect(mdt_num2cap(val), allowed_cap);
684 LUSTRE_RW_ATTR(enable_cap_mask);
686 static ssize_t enable_remote_dir_gid_show(struct kobject *kobj,
687 struct attribute *attr, char *buf)
689 struct obd_device *obd = container_of(kobj, struct obd_device,
691 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
693 return scnprintf(buf, PAGE_SIZE, "%d\n",
694 (int)mdt->mdt_enable_remote_dir_gid);
697 static ssize_t enable_remote_dir_gid_store(struct kobject *kobj,
698 struct attribute *attr,
699 const char *buffer, size_t count)
701 struct obd_device *obd = container_of(kobj, struct obd_device,
703 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
707 rc = kstrtoint(buffer, 0, &val);
711 mdt->mdt_enable_remote_dir_gid = val;
714 LUSTRE_RW_ATTR(enable_remote_dir_gid);
716 static ssize_t enable_chprojid_gid_show(struct kobject *kobj,
717 struct attribute *attr, char *buf)
719 struct obd_device *obd = container_of(kobj, struct obd_device,
721 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
723 return scnprintf(buf, PAGE_SIZE, "%d\n",
724 (int)mdt->mdt_enable_chprojid_gid);
727 static ssize_t enable_chprojid_gid_store(struct kobject *kobj,
728 struct attribute *attr,
729 const char *buffer, size_t count)
731 struct obd_device *obd = container_of(kobj, struct obd_device,
733 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
737 rc = kstrtoint(buffer, 0, &val);
741 mdt->mdt_enable_chprojid_gid = val;
744 LUSTRE_RW_ATTR(enable_chprojid_gid);
746 #define MDT_BOOL_RW_ATTR(name) \
747 static ssize_t name##_show(struct kobject *kobj, struct attribute *attr,\
750 struct obd_device *obd = container_of(kobj, struct obd_device, \
752 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); \
753 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_##name); \
755 static ssize_t name##_store(struct kobject *kobj, struct attribute *attr,\
756 const char *buffer, size_t count) \
758 struct obd_device *obd = container_of(kobj, struct obd_device, \
760 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); \
763 rc = kstrtobool(buffer, &val); \
766 mdt->mdt_##name = val; \
771 MDT_BOOL_RW_ATTR(readonly);
772 MDT_BOOL_RW_ATTR(evict_tgt_nids);
773 MDT_BOOL_RW_ATTR(dom_read_open);
774 MDT_BOOL_RW_ATTR(enable_remote_dir);
775 MDT_BOOL_RW_ATTR(enable_remote_rename);
776 MDT_BOOL_RW_ATTR(enable_parallel_rename_dir);
777 MDT_BOOL_RW_ATTR(enable_parallel_rename_file);
778 MDT_BOOL_RW_ATTR(enable_parallel_rename_crossdir);
779 MDT_BOOL_RW_ATTR(enable_striped_dir);
780 MDT_BOOL_RW_ATTR(enable_dir_migration);
781 MDT_BOOL_RW_ATTR(enable_dir_restripe);
782 MDT_BOOL_RW_ATTR(enable_dir_auto_split);
783 MDT_BOOL_RW_ATTR(dir_restripe_nsonly);
784 MDT_BOOL_RW_ATTR(migrate_hsm_allowed);
785 MDT_BOOL_RW_ATTR(enable_strict_som);
786 MDT_BOOL_RW_ATTR(enable_dmv_implicit_inherit);
787 MDT_BOOL_RW_ATTR(enable_dmv_xattr);
790 * Show if the MDT is in no create mode.
792 * This means MDT has been adminstratively disabled to prevent it
793 * from creating any new directories on the MDT, though existing files
794 * and directories can still be read, written, and unlinked.
796 * \retval number of bytes written
798 static ssize_t no_create_show(struct kobject *kobj, struct attribute *attr,
801 struct obd_device *obd = container_of(kobj, struct obd_device,
803 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
805 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_lut.lut_no_create);
809 * Set MDT to no create mode.
811 * This is used to interface to userspace administrative tools to
812 * disable new directory creation on the MDT.
814 * \param[in] count \a buffer length
816 * \retval \a count on success
817 * \retval negative number on error
819 static ssize_t no_create_store(struct kobject *kobj, struct attribute *attr,
820 const char *buffer, size_t count)
822 struct obd_device *obd = container_of(kobj, struct obd_device,
824 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
828 rc = kstrtobool(buffer, &val);
832 mdt->mdt_lut.lut_no_create = val;
836 LUSTRE_RW_ATTR(no_create);
839 * Show MDT async commit count.
842 * @data unused for single entry
844 * Return: 0 on success
845 * negative value on error
847 static ssize_t async_commit_count_show(struct kobject *kobj,
848 struct attribute *attr, char *buf)
850 struct obd_device *obd = container_of(kobj, struct obd_device,
852 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
854 return scnprintf(buf, PAGE_SIZE, "%d\n",
855 atomic_read(&mdt->mdt_async_commit_count));
858 static ssize_t async_commit_count_store(struct kobject *kobj,
859 struct attribute *attr,
860 const char *buffer, size_t count)
862 struct obd_device *obd = container_of(kobj, struct obd_device,
864 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
868 rc = kstrtoint(buffer, 10, &val);
872 atomic_set(&mdt->mdt_async_commit_count, val);
876 LUSTRE_RW_ATTR(async_commit_count);
879 * Show MDT sync count.
881 * \param[in] m seq_file handle
882 * \param[in] data unused for single entry
884 * \retval 0 on success
885 * \retval negative value on error
887 static ssize_t sync_count_show(struct kobject *kobj, struct attribute *attr,
890 struct obd_device *obd = container_of(kobj, struct obd_device,
892 struct lu_target *tgt = obd2obt(obd)->obt_lut;
894 return scnprintf(buf, PAGE_SIZE, "%d\n",
895 atomic_read(&tgt->lut_sync_count));
898 static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
899 const char *buffer, size_t count)
901 struct obd_device *obd = container_of(kobj, struct obd_device,
903 struct lu_target *tgt = obd2obt(obd)->obt_lut;
907 rc = kstrtoint(buffer, 0, &val);
911 atomic_set(&tgt->lut_sync_count, val);
915 LUSTRE_RW_ATTR(sync_count);
917 static const char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
918 [NO_DOM_LOCK_ON_OPEN] = "never",
919 [TRYLOCK_DOM_ON_OPEN] = "trylock",
920 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
923 /* This must be longer than the longest string above */
924 #define DOM_LOCK_MODES_MAXLEN 16
927 * Show MDT policy for data prefetch on open for DoM files..
929 * \param[in] m seq_file handle
930 * \param[in] data unused
932 * \retval 0 on success
933 * \retval negative value on error
935 static ssize_t dom_lock_show(struct kobject *kobj, struct attribute *attr,
938 struct obd_device *obd = container_of(kobj, struct obd_device,
940 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
942 return scnprintf(buf, PAGE_SIZE, "%s\n",
943 dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
947 * Change MDT policy for data prefetch on open for DoM files.
949 * This variable defines how DOM lock is taken at open enqueue.
950 * There are three possible modes:
951 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
952 * IO lock with own enqueue.
953 * 2) trylock - DoM lock will be taken only if non-blocked.
954 * 3) always - DoM lock will be taken always even if it is blocking lock.
956 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
957 * is paired with LAYOUT lock when possible.
959 * \param[in] file proc file
960 * \param[in] buffer string which represents policy
961 * \param[in] count \a buffer length
962 * \param[in] off unused for single entry
964 * \retval \a count on success
965 * \retval negative number on error
967 static ssize_t dom_lock_store(struct kobject *kobj, struct attribute *attr,
968 const char *buffer, size_t count)
970 struct obd_device *obd = container_of(kobj, struct obd_device,
972 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
976 if (count == 0 || count >= DOM_LOCK_MODES_MAXLEN)
979 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
980 /* buffer might have '\n' but using strlen() avoids it */
981 if (strncmp(buffer, dom_open_lock_modes[i],
982 strlen(dom_open_lock_modes[i])) == 0) {
988 /* Legacy numeric codes */
990 rc = kstrtoint(buffer, 0, &val);
995 if (val == ALWAYS_DOM_LOCK_ON_OPEN)
996 val = TRYLOCK_DOM_ON_OPEN;
998 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
1001 mdt->mdt_opts.mo_dom_lock = val;
1004 LUSTRE_RW_ATTR(dom_lock);
1006 static ssize_t dir_split_count_show(struct kobject *kobj,
1007 struct attribute *attr,
1010 struct obd_device *obd = container_of(kobj, struct obd_device,
1012 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1014 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1015 mdt->mdt_restriper.mdr_dir_split_count);
1018 static ssize_t dir_split_count_store(struct kobject *kobj,
1019 struct attribute *attr,
1020 const char *buffer, size_t count)
1022 struct obd_device *obd = container_of(kobj, struct obd_device,
1024 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1028 rc = sysfs_memparse(buffer, count, &val, "B");
1035 mdt->mdt_restriper.mdr_dir_split_count = val;
1039 LUSTRE_RW_ATTR(dir_split_count);
1041 static ssize_t dir_split_delta_show(struct kobject *kobj,
1042 struct attribute *attr,
1045 struct obd_device *obd = container_of(kobj, struct obd_device,
1047 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1049 return scnprintf(buf, PAGE_SIZE, "%u\n",
1050 mdt->mdt_restriper.mdr_dir_split_delta);
1053 static ssize_t dir_split_delta_store(struct kobject *kobj,
1054 struct attribute *attr,
1055 const char *buffer, size_t count)
1057 struct obd_device *obd = container_of(kobj, struct obd_device,
1059 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1063 rc = kstrtouint(buffer, 0, &val);
1067 mdt->mdt_restriper.mdr_dir_split_delta = val;
1071 LUSTRE_RW_ATTR(dir_split_delta);
1073 static ssize_t enable_remote_subdir_mount_show(struct kobject *kobj,
1074 struct attribute *attr,
1077 return scnprintf(buf, PAGE_SIZE, "%u\n", 1);
1080 static ssize_t enable_remote_subdir_mount_store(struct kobject *kobj,
1081 struct attribute *attr,
1085 LCONSOLE_WARN("enable_remote_subdir_mount is deprecated, it's always enabled.\n");
1088 LUSTRE_RW_ATTR(enable_remote_subdir_mount);
1091 * Show if the OFD enforces T10PI checksum.
1093 * \param[in] m seq_file handle
1094 * \param[in] data unused for single entry
1096 * \retval 0 on success
1097 * \retval negative value on error
1099 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
1100 struct attribute *attr,
1103 struct obd_device *obd = container_of(kobj, struct obd_device,
1105 struct lu_target *lut = obd2obt(obd)->obt_lut;
1107 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
1111 * Force specific T10PI checksum modes to be enabled
1113 * If T10PI *is* supported in hardware, allow only the supported T10PI type
1114 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
1115 * parameter forces all T10PI types to be enabled (even if slower) for
1118 * The final determination of which algorithm to be used depends whether
1119 * the client supports T10PI or not, and is handled at client connect time.
1121 * \param[in] file proc file
1122 * \param[in] buffer string which represents mode
1123 * 1: set T10PI checksums enforced
1124 * 0: unset T10PI checksums enforced
1125 * \param[in] count \a buffer length
1126 * \param[in] off unused for single entry
1128 * \retval \a count on success
1129 * \retval negative number on error
1131 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
1132 struct attribute *attr,
1133 const char *buffer, size_t count)
1135 struct obd_device *obd = container_of(kobj, struct obd_device,
1137 struct lu_target *lut = obd2obt(obd)->obt_lut;
1141 rc = kstrtobool(buffer, &enforce);
1145 spin_lock(&lut->lut_flags_lock);
1146 lut->lut_cksum_t10pi_enforce = enforce;
1147 spin_unlock(&lut->lut_flags_lock);
1150 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
1153 * Show MDT Maximum modify RPCs in flight.
1155 * @m seq_file handle
1156 * @data unused for single entry
1158 * Return: value on success or negative number on error
1160 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
1161 struct attribute *attr, char *buf)
1163 struct obd_device *obd = container_of(kobj, struct obd_device,
1165 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1167 return scnprintf(buf, PAGE_SIZE, "%u\n",
1168 mdt->mdt_max_mod_rpcs_in_flight);
1171 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
1172 struct attribute *attr,
1173 const char *buffer, size_t count)
1175 struct obd_device *obd = container_of(kobj, struct obd_device,
1177 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1181 rc = kstrtouint(buffer, 0, &val);
1185 if (val < 1 || val > OBD_MAX_RIF_MAX)
1188 if (mdt_max_mod_rpcs_changed(mdt)) {
1189 CWARN("%s: deprecated 'max_mod_rpcs_in_flight' module parameter has also been modified\n",
1191 max_mod_rpcs_per_client = val;
1193 mdt->mdt_max_mod_rpcs_in_flight = val;
1197 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
1200 * mdt_checksum_type(server) proc handling
1204 static int mdt_checksum_type_seq_show(struct seq_file *m, void *data)
1206 struct obd_device *obd = m->private;
1207 struct lu_target *lut;
1208 enum cksum_types pref;
1214 lut = obd2obt(obd)->obt_lut;
1215 /* select fastest checksum type on the server */
1216 pref = obd_cksum_type_select(obd->obd_name,
1217 lut->lut_cksum_types_supported,
1218 lut->lut_dt_conf.ddp_t10_cksum_type);
1220 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
1221 if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
1225 seq_printf(m, "[%s] ", cksum_name[i]);
1227 seq_printf(m, "%s ", cksum_name[i]);
1234 static ssize_t job_xattr_show(struct kobject *kobj, struct attribute *attr,
1237 struct obd_device *obd = container_of(kobj, struct obd_device,
1239 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1241 if (mdt->mdt_job_xattr[0] == '\0')
1242 return scnprintf(buf, PAGE_SIZE, "NONE\n");
1244 return scnprintf(buf, PAGE_SIZE, "%s\n", mdt->mdt_job_xattr);
1248 * Read in a name for the jobid xattr and validate it.
1249 * The only valid names are "trusted.job" or "user.*" where the name portion
1250 * is <= 7 bytes in the user namespace. Only alphanumeric characters are
1251 * allowed, aside from the namespace separator '.'.
1253 * "none" is a valid value to turn this feature off.
1255 * @return -EINVAL if the name is invalid, else count
1257 static ssize_t job_xattr_store(struct kobject *kobj, struct attribute *attr,
1258 const char *buffer, size_t count)
1260 struct obd_device *obd = container_of(kobj, struct obd_device,
1262 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1263 char name[XATTR_JOB_MAX_LEN] = { 0 };
1267 /* writing "none" turns this off by leaving the name empty */
1268 if (!strncmp(buffer, "none", 4) ||
1269 !strncmp(buffer, "NONE", 4)) {
1270 memset(mdt->mdt_job_xattr, 0, sizeof(mdt->mdt_job_xattr));
1274 /* account for stripping \n before rejecting name for being too long */
1275 if (count > XATTR_JOB_MAX_LEN - 1 &&
1276 buffer[XATTR_JOB_MAX_LEN - 1] != '\n')
1279 strncpy(name, buffer, XATTR_JOB_MAX_LEN - 1);
1281 /* reject if not in namespace.name format */
1282 p = strchr(name, '.');
1287 for (; *p != '\0'; p++) {
1289 * if there are any non-alphanumeric characters, the name is
1290 * invalid unless it's a newline, in which case overwrite it
1291 * with '\0' and that's the end of the name.
1300 /* trusted.job is only valid name in trusted namespace */
1301 if (!strncmp(name, "trusted.job", 12)) {
1302 strncpy(mdt->mdt_job_xattr, name, XATTR_JOB_MAX_LEN);
1306 /* only other valid namespace is user */
1307 if (strncmp(name, XATTR_USER_PREFIX, sizeof(XATTR_USER_PREFIX) - 1))
1310 /* ensure that a name was specified */
1311 if (name[sizeof(XATTR_USER_PREFIX) - 1] == '\0')
1314 strncpy(mdt->mdt_job_xattr, name, XATTR_JOB_MAX_LEN);
1319 LPROC_SEQ_FOPS_RO(mdt_checksum_type);
1321 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1322 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1323 LPROC_SEQ_FOPS_RW_TYPE(mdt, checksum_dump);
1324 LUSTRE_RW_ATTR(job_cleanup_interval);
1325 LUSTRE_RW_ATTR(job_xattr);
1326 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1327 LUSTRE_RW_ATTR(hsm_control);
1329 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1330 LUSTRE_RW_ATTR(recovery_time_hard);
1331 LUSTRE_RW_ATTR(recovery_time_soft);
1332 LUSTRE_RW_ATTR(ir_factor);
1334 LUSTRE_RO_ATTR(tot_dirty);
1335 LUSTRE_RO_ATTR(tot_granted);
1336 LUSTRE_RO_ATTR(tot_pending);
1337 LUSTRE_RW_ATTR(grant_compat_disable);
1338 LUSTRE_RO_ATTR(instance);
1340 LUSTRE_RO_ATTR(num_exports);
1341 LUSTRE_RW_ATTR(grant_check_threshold);
1342 LUSTRE_RO_ATTR(eviction_count);
1344 /* per-device at parameters */
1345 LUSTRE_OBD_UINT_PARAM_ATTR(at_min);
1346 LUSTRE_OBD_UINT_PARAM_ATTR(at_max);
1347 LUSTRE_OBD_UINT_PARAM_ATTR(at_history);
1349 static struct attribute *mdt_attrs[] = {
1350 &lustre_attr_tot_dirty.attr,
1351 &lustre_attr_tot_granted.attr,
1352 &lustre_attr_tot_pending.attr,
1353 &lustre_attr_grant_compat_disable.attr,
1354 &lustre_attr_instance.attr,
1355 &lustre_attr_recovery_time_hard.attr,
1356 &lustre_attr_recovery_time_soft.attr,
1357 &lustre_attr_ir_factor.attr,
1358 &lustre_attr_num_exports.attr,
1359 &lustre_attr_grant_check_threshold.attr,
1360 &lustre_attr_eviction_count.attr,
1361 &lustre_attr_identity_expire.attr,
1362 &lustre_attr_identity_acquire_expire.attr,
1363 &lustre_attr_identity_upcall.attr,
1364 &lustre_attr_identity_flush.attr,
1365 &lustre_attr_evict_tgt_nids.attr,
1366 &lustre_attr_enable_cap_mask.attr,
1367 &lustre_attr_enable_chprojid_gid.attr,
1368 &lustre_attr_enable_dir_migration.attr,
1369 &lustre_attr_enable_dir_restripe.attr,
1370 &lustre_attr_enable_dir_auto_split.attr,
1371 &lustre_attr_enable_parallel_rename_dir.attr,
1372 &lustre_attr_enable_parallel_rename_file.attr,
1373 &lustre_attr_enable_parallel_rename_crossdir.attr,
1374 &lustre_attr_enable_remote_dir.attr,
1375 &lustre_attr_enable_remote_dir_gid.attr,
1376 &lustre_attr_enable_remote_rename.attr,
1377 &lustre_attr_enable_striped_dir.attr,
1378 &lustre_attr_commit_on_sharing.attr,
1379 &lustre_attr_local_recovery.attr,
1380 &lustre_attr_no_create.attr,
1381 &lustre_attr_async_commit_count.attr,
1382 &lustre_attr_sync_count.attr,
1383 &lustre_attr_dom_lock.attr,
1384 &lustre_attr_dom_read_open.attr,
1385 &lustre_attr_enable_strict_som.attr,
1386 &lustre_attr_migrate_hsm_allowed.attr,
1387 &lustre_attr_hsm_control.attr,
1388 &lustre_attr_job_cleanup_interval.attr,
1389 &lustre_attr_job_xattr.attr,
1390 &lustre_attr_readonly.attr,
1391 &lustre_attr_dir_split_count.attr,
1392 &lustre_attr_dir_split_delta.attr,
1393 &lustre_attr_dir_restripe_nsonly.attr,
1394 &lustre_attr_checksum_t10pi_enforce.attr,
1395 &lustre_attr_enable_remote_subdir_mount.attr,
1396 &lustre_attr_max_mod_rpcs_in_flight.attr,
1397 &lustre_attr_enable_dmv_implicit_inherit.attr,
1398 &lustre_attr_at_min.attr,
1399 &lustre_attr_at_max.attr,
1400 &lustre_attr_at_history.attr,
1401 &lustre_attr_enable_dmv_xattr.attr,
1405 KOBJ_ATTRIBUTE_GROUPS(mdt); /* creates mdt_groups from mdt_attrs */
1407 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1408 { .name = "recovery_status",
1409 .fops = &mdt_recovery_status_fops },
1410 { .name = "identity_info",
1411 .fops = &mdt_identity_info_fops },
1412 { .name = "site_stats",
1413 .fops = &mdt_site_stats_fops },
1414 { .name = "evict_client",
1415 .fops = &mdt_mds_evict_client_fops },
1416 { .name = "checksum_dump",
1417 .fops = &mdt_checksum_dump_fops },
1418 { .name = "hash_stats",
1419 .fops = &mdt_hash_fops },
1420 { .name = "root_squash",
1421 .fops = &mdt_root_squash_fops },
1422 { .name = "nosquash_nids",
1423 .fops = &mdt_nosquash_nids_fops },
1424 { .name = "checksum_type",
1425 .fops = &mdt_checksum_type_fops },
1429 LDEBUGFS_SEQ_FOPS_RO_TYPE(mdt, recovery_stale_clients);
1431 static struct ldebugfs_vars ldebugfs_mdt_obd_vars[] = {
1432 { .name = "recovery_stale_clients",
1433 .fops = &mdt_recovery_stale_clients_fops },
1437 LDEBUGFS_SEQ_FOPS_RO_TYPE(mdt, srpc_serverctx);
1439 static struct ldebugfs_vars ldebugfs_mdt_gss_vars[] = {
1440 { .name = "srpc_serverctx",
1441 .fops = &mdt_srpc_serverctx_fops },
1446 lprocfs_mdt_print_open_files(struct obd_export *exp, void *v)
1448 struct seq_file *seq = v;
1450 if (exp->exp_lock_hash != NULL) {
1451 struct mdt_export_data *med = &exp->exp_mdt_data;
1452 struct mdt_file_data *mfd;
1454 spin_lock(&med->med_open_lock);
1455 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1456 seq_printf(seq, DFID"\n",
1457 PFID(mdt_object_fid(mfd->mfd_object)));
1459 spin_unlock(&med->med_open_lock);
1465 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1467 struct nid_stat *stats = seq->private;
1469 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
1470 lprocfs_mdt_print_open_files, seq);
1473 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1475 struct seq_file *seq;
1478 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1482 seq = file->private_data;
1483 seq->private = pde_data(inode);
1488 void mdt_counter_incr(struct ptlrpc_request *req, int opcode, long amount)
1490 struct obd_export *exp = req->rq_export;
1492 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1493 lprocfs_counter_add(exp->exp_obd->obd_md_stats,
1494 opcode + LPROC_MD_LAST_OPC, amount);
1495 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1496 lprocfs_counter_add(exp->exp_nid_stats->nid_stats, opcode,
1498 if (exp->exp_obd && obd2obt(exp->exp_obd)->obt_jobstats.ojs_hash &&
1499 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1500 lprocfs_job_stats_log(exp->exp_obd,
1501 lustre_msg_get_jobid(req->rq_reqmsg),
1505 static const char * const mdt_stats[] = {
1506 [LPROC_MDT_OPEN] = "open",
1507 [LPROC_MDT_CLOSE] = "close",
1508 [LPROC_MDT_MKNOD] = "mknod",
1509 [LPROC_MDT_LINK] = "link",
1510 [LPROC_MDT_UNLINK] = "unlink",
1511 [LPROC_MDT_MKDIR] = "mkdir",
1512 [LPROC_MDT_RMDIR] = "rmdir",
1513 [LPROC_MDT_RENAME] = "rename",
1514 [LPROC_MDT_GETATTR] = "getattr",
1515 [LPROC_MDT_SETATTR] = "setattr",
1516 [LPROC_MDT_GETXATTR] = "getxattr",
1517 [LPROC_MDT_SETXATTR] = "setxattr",
1518 [LPROC_MDT_STATFS] = "statfs",
1519 [LPROC_MDT_SYNC] = "sync",
1520 [LPROC_MDT_RENAME_SAMEDIR] = "samedir_rename",
1521 [LPROC_MDT_RENAME_PAR_FILE] = "parallel_rename_file",
1522 [LPROC_MDT_RENAME_PAR_DIR] = "parallel_rename_dir",
1523 [LPROC_MDT_RENAME_CROSSDIR] = "crossdir_rename",
1524 [LPROC_MDT_IO_READ_BYTES] = "read_bytes",
1525 [LPROC_MDT_IO_WRITE_BYTES] = "write_bytes",
1526 [LPROC_MDT_IO_READ] = "read",
1527 [LPROC_MDT_IO_WRITE] = "write",
1528 [LPROC_MDT_IO_PUNCH] = "punch",
1529 [LPROC_MDT_MIGRATE] = "migrate",
1530 [LPROC_MDT_FALLOCATE] = "fallocate",
1533 void mdt_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset,
1534 enum lprocfs_counter_config cntr_umask)
1536 int array_size = ARRAY_SIZE(mdt_stats);
1537 int oidx; /* obd_md_stats index */
1538 int midx; /* mdt_stats index */
1540 LASSERT(stats && stats->ls_num >= offset + array_size);
1542 for (midx = 0; midx < array_size; midx++) {
1543 oidx = midx + offset;
1544 if (midx == LPROC_MDT_IO_READ_BYTES ||
1545 midx == LPROC_MDT_IO_WRITE_BYTES)
1546 lprocfs_counter_init(stats, oidx,
1547 LPROCFS_TYPE_BYTES_FULL_HISTOGRAM &
1551 lprocfs_counter_init(stats, oidx,
1552 LPROCFS_TYPE_LATENCY &
1558 int mdt_tunables_init(struct mdt_device *mdt, const char *name)
1560 struct obd_device *obd = mdt2obd_dev(mdt);
1564 LASSERT(name != NULL);
1566 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdt);
1567 obd->obd_vars = lprocfs_mdt_obd_vars;
1568 rc = lprocfs_obd_setup(obd, true);
1570 CERROR("%s: cannot create proc entries: rc = %d\n",
1571 mdt_obd_name(mdt), rc);
1574 ldebugfs_add_vars(obd->obd_debugfs_entry, ldebugfs_mdt_obd_vars, obd);
1576 rc = tgt_tunables_init(&mdt->mdt_lut);
1578 CERROR("%s: failed to init target tunables: rc = %d\n",
1579 mdt_obd_name(mdt), rc);
1583 rc = hsm_cdt_tunables_init(mdt);
1585 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1586 mdt_obd_name(mdt), rc);
1590 obd->obd_debugfs_gss_dir = debugfs_create_dir("gss",
1591 obd->obd_debugfs_entry);
1592 if (obd->obd_debugfs_gss_dir)
1593 ldebugfs_add_vars(obd->obd_debugfs_gss_dir,
1594 ldebugfs_mdt_gss_vars, obd);
1596 obd->obd_proc_exports_entry = proc_mkdir("exports",
1597 obd->obd_proc_entry);
1598 if (obd->obd_proc_exports_entry)
1599 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1600 obd, &mdt_nid_stats_clear_fops);
1602 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1606 /* add additional MDT md_stats after the default ones */
1607 mdt_stats_counter_init(obd->obd_md_stats, LPROC_MD_LAST_OPC,
1608 LPROCFS_CNTR_HISTOGRAM);
1609 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1610 mdt_stats_counter_init);
1612 rc = lproc_mdt_attach_rename_seqstat(mdt);
1614 CERROR("%s: MDT can not create rename stats rc = %d\n",
1615 mdt_obd_name(mdt), rc);
1620 void mdt_tunables_fini(struct mdt_device *mdt)
1622 struct obd_device *obd = mdt2obd_dev(mdt);
1624 if (obd->obd_proc_exports_entry != NULL) {
1625 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1626 obd->obd_proc_exports_entry = NULL;
1629 lprocfs_free_per_client_stats(obd);
1630 /* hsm_cdt_tunables is disabled earlier than this to avoid
1631 * coordinator restart.
1633 hsm_cdt_tunables_fini(mdt);
1634 tgt_tunables_fini(&mdt->mdt_lut);
1635 lprocfs_obd_cleanup(obd);
1636 lprocfs_free_md_stats(obd);
1637 lprocfs_free_obd_stats(obd);
1638 lprocfs_job_stats_fini(obd);