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;
300 if (count >= UC_CACHE_UPCALL_MAXPATH) {
301 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
305 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
306 down_write(&hash->uc_upcall_rwsem);
307 sscanf(buffer, "%s", hash->uc_upcall);
308 up_write(&hash->uc_upcall_rwsem);
310 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
311 CWARN("%s: write to upcall name %s\n",
312 mdt_obd_name(mdt), hash->uc_upcall);
314 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
315 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
316 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
318 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
322 LUSTRE_RW_ATTR(identity_upcall);
324 static ssize_t identity_flush_store(struct kobject *kobj,
325 struct attribute *attr,
326 const char *buffer, size_t count)
328 struct obd_device *obd = container_of(kobj, struct obd_device,
330 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
334 rc = kstrtoint(buffer, 0, &uid);
338 mdt_flush_identity(mdt->mdt_identity_cache, uid);
341 LUSTRE_WO_ATTR(identity_flush);
344 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
345 size_t count, void *data)
347 struct seq_file *m = file->private_data;
348 struct obd_device *obd = m->private;
349 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
350 struct identity_downcall_data *param;
351 int size = sizeof(*param), rc, checked = 0;
355 CERROR("%s: invalid data count = %lu, size = %d\n",
356 mdt_obd_name(mdt), (unsigned long) count, size);
360 OBD_ALLOC(param, size);
364 if (copy_from_user(param, buffer, size)) {
365 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
366 GOTO(out, rc = -EFAULT);
371 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
372 CERROR("%s: MDS identity downcall bad params\n",
374 GOTO(out, rc = -EINVAL);
377 if (param->idd_nperms > N_PERMS_MAX) {
378 CERROR("%s: perm count %d more than maximum %d\n",
379 mdt_obd_name(mdt), param->idd_nperms,
381 GOTO(out, rc = -EINVAL);
384 if (param->idd_ngroups > NGROUPS_MAX) {
385 CERROR("%s: group count %d more than maximum %d\n",
386 mdt_obd_name(mdt), param->idd_ngroups,
388 GOTO(out, rc = -EINVAL);
391 if (param->idd_ngroups) {
392 rc = param->idd_ngroups; /* save idd_ngroups */
393 OBD_FREE(param, size);
394 size = offsetof(struct identity_downcall_data,
400 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
401 param->idd_uid, param);
405 OBD_FREE(param, size);
407 return rc ? rc : count;
409 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info);
411 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
413 struct obd_device *obd = m->private;
414 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
416 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
418 LPROC_SEQ_FOPS_RO(mdt_site_stats);
420 #define BUFLEN (UUID_MAX + 4)
423 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
424 size_t count, loff_t *off)
426 struct seq_file *m = file->private_data;
427 struct obd_device *obd = m->private;
428 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
433 OBD_ALLOC(kbuf, BUFLEN);
438 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
439 * bytes into kbuf, to ensure that the string is NUL-terminated.
440 * UUID_MAX should include a trailing NUL already.
442 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
443 GOTO(out, rc = -EFAULT);
444 tmpbuf = skip_spaces(kbuf);
445 tmpbuf = strsep(&tmpbuf, " \t\n\f\v\r");
447 if (strncmp(tmpbuf, "nid:", 4) != 0) {
448 count = lprocfs_evict_client_seq_write(file, buf, count, off);
452 if (mdt->mdt_evict_tgt_nids) {
453 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
454 sizeof(KEY_EVICT_BY_NID),
456 strlen(tmpbuf + 4) + 1,
459 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
463 /* See the comments in function lprocfs_wr_evict_client()
464 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
465 class_incref(obd, __func__, current);
466 obd_export_evict_by_nid(obd, tmpbuf + 4);
467 class_decref(obd, __func__, current);
471 OBD_FREE(kbuf, BUFLEN);
472 return rc < 0 ? rc : count;
477 static ssize_t commit_on_sharing_show(struct kobject *kobj,
478 struct attribute *attr, char *buf)
480 struct obd_device *obd = container_of(kobj, struct obd_device,
482 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
484 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt_cos_is_enabled(mdt));
487 static ssize_t commit_on_sharing_store(struct kobject *kobj,
488 struct attribute *attr,
489 const char *buffer, size_t count)
491 struct obd_device *obd = container_of(kobj, struct obd_device,
493 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
497 rc = kstrtobool(buffer, &val);
501 mdt_enable_cos(mdt, val);
504 LUSTRE_RW_ATTR(commit_on_sharing);
506 static ssize_t local_recovery_show(struct kobject *kobj,
507 struct attribute *attr, char *buf)
509 struct obd_device *obd = container_of(kobj, struct obd_device,
512 return scnprintf(buf, PAGE_SIZE, "%u\n",
513 obd2obt(obd)->obt_lut->lut_local_recovery);
516 static ssize_t local_recovery_store(struct kobject *kobj,
517 struct attribute *attr,
518 const char *buffer, size_t count)
520 struct obd_device *obd = container_of(kobj, struct obd_device,
525 rc = kstrtobool(buffer, &val);
529 obd2obt(obd)->obt_lut->lut_local_recovery = !!val;
532 LUSTRE_RW_ATTR(local_recovery);
534 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
536 struct obd_device *obd = m->private;
537 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
538 struct root_squash_info *squash = &mdt->mdt_squash;
540 seq_printf(m, "%u:%u\n", squash->rsi_uid,
546 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
547 size_t count, loff_t *off)
549 struct seq_file *m = file->private_data;
550 struct obd_device *obd = m->private;
551 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
552 struct root_squash_info *squash = &mdt->mdt_squash;
554 return lprocfs_wr_root_squash(buffer, count, squash,
557 LPROC_SEQ_FOPS(mdt_root_squash);
559 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
561 struct obd_device *obd = m->private;
562 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
563 struct root_squash_info *squash = &mdt->mdt_squash;
566 spin_lock(&squash->rsi_lock);
567 if (!list_empty(&squash->rsi_nosquash_nids)) {
568 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
569 &squash->rsi_nosquash_nids);
573 seq_puts(m, "NONE\n");
574 spin_unlock(&squash->rsi_lock);
580 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
581 size_t count, loff_t *off)
583 struct seq_file *m = file->private_data;
584 struct obd_device *obd = m->private;
585 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
586 struct root_squash_info *squash = &mdt->mdt_squash;
588 return lprocfs_wr_nosquash_nids(buffer, count, squash,
591 LPROC_SEQ_FOPS(mdt_nosquash_nids);
593 static ssize_t enable_cap_mask_show(struct kobject *kobj,
594 struct attribute *attr, char *buf)
596 struct obd_device *obd = container_of(kobj, struct obd_device,
598 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
601 BUILD_BUG_ON(_KERNEL_CAP_T_SIZE != sizeof(u64));
603 #ifdef CAP_FOR_EACH_U32 /* kernels before v6.2-13111-gf122a08b197d */
604 cap = ((u64)mdt->mdt_enable_cap_mask.cap[1] << 32) |
605 mdt->mdt_enable_cap_mask.cap[0];
607 cap = mdt->mdt_enable_cap_mask.val;
609 return scnprintf(buf, PAGE_SIZE, "%#0llx\n", cap);
612 static ssize_t enable_cap_mask_store(struct kobject *kobj,
613 struct attribute *attr,
614 const char *buffer, size_t count)
616 struct obd_device *obd = container_of(kobj, struct obd_device,
618 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
619 unsigned long long val;
622 rc = kstrtoull(buffer, 0, &val);
624 /* should also accept symbolic names via cfs_str2mask() */
627 #ifdef CAP_FOR_EACH_U32
628 mdt->mdt_enable_cap_mask.cap[0] = val &
629 (CAP_FS_MASK_B0 | CAP_TO_MASK(CAP_SYS_RESOURCE) |
630 CAP_TO_MASK(CAP_LINUX_IMMUTABLE));
631 mdt->mdt_enable_cap_mask.cap[1] = (val >> 32) & CAP_FS_MASK_B1;
633 mdt->mdt_enable_cap_mask.val = val &
634 (CAP_FS_MASK | BIT_ULL(CAP_SYS_RESOURCE) |
635 BIT_ULL(CAP_LINUX_IMMUTABLE));
640 LUSTRE_RW_ATTR(enable_cap_mask);
642 static ssize_t enable_remote_dir_gid_show(struct kobject *kobj,
643 struct attribute *attr, char *buf)
645 struct obd_device *obd = container_of(kobj, struct obd_device,
647 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
649 return scnprintf(buf, PAGE_SIZE, "%d\n",
650 (int)mdt->mdt_enable_remote_dir_gid);
653 static ssize_t enable_remote_dir_gid_store(struct kobject *kobj,
654 struct attribute *attr,
655 const char *buffer, size_t count)
657 struct obd_device *obd = container_of(kobj, struct obd_device,
659 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
663 rc = kstrtoint(buffer, 0, &val);
667 mdt->mdt_enable_remote_dir_gid = val;
670 LUSTRE_RW_ATTR(enable_remote_dir_gid);
672 static ssize_t enable_chprojid_gid_show(struct kobject *kobj,
673 struct attribute *attr, char *buf)
675 struct obd_device *obd = container_of(kobj, struct obd_device,
677 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
679 return scnprintf(buf, PAGE_SIZE, "%d\n",
680 (int)mdt->mdt_enable_chprojid_gid);
683 static ssize_t enable_chprojid_gid_store(struct kobject *kobj,
684 struct attribute *attr,
685 const char *buffer, size_t count)
687 struct obd_device *obd = container_of(kobj, struct obd_device,
689 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
693 rc = kstrtoint(buffer, 0, &val);
697 mdt->mdt_enable_chprojid_gid = val;
700 LUSTRE_RW_ATTR(enable_chprojid_gid);
702 #define MDT_BOOL_RW_ATTR(name) \
703 static ssize_t name##_show(struct kobject *kobj, struct attribute *attr,\
706 struct obd_device *obd = container_of(kobj, struct obd_device, \
708 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); \
709 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_##name); \
711 static ssize_t name##_store(struct kobject *kobj, struct attribute *attr,\
712 const char *buffer, size_t count) \
714 struct obd_device *obd = container_of(kobj, struct obd_device, \
716 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); \
719 rc = kstrtobool(buffer, &val); \
722 mdt->mdt_##name = val; \
727 MDT_BOOL_RW_ATTR(readonly);
728 MDT_BOOL_RW_ATTR(evict_tgt_nids);
729 MDT_BOOL_RW_ATTR(dom_read_open);
730 MDT_BOOL_RW_ATTR(enable_remote_dir);
731 MDT_BOOL_RW_ATTR(enable_remote_rename);
732 MDT_BOOL_RW_ATTR(enable_parallel_rename_dir);
733 MDT_BOOL_RW_ATTR(enable_parallel_rename_file);
734 MDT_BOOL_RW_ATTR(enable_parallel_rename_crossdir);
735 MDT_BOOL_RW_ATTR(enable_striped_dir);
736 MDT_BOOL_RW_ATTR(enable_dir_migration);
737 MDT_BOOL_RW_ATTR(enable_dir_restripe);
738 MDT_BOOL_RW_ATTR(enable_dir_auto_split);
739 MDT_BOOL_RW_ATTR(dir_restripe_nsonly);
740 MDT_BOOL_RW_ATTR(migrate_hsm_allowed);
741 MDT_BOOL_RW_ATTR(enable_strict_som);
742 MDT_BOOL_RW_ATTR(enable_dmv_implicit_inherit);
743 MDT_BOOL_RW_ATTR(enable_dmv_xattr);
746 * Show if the MDT is in no create mode.
748 * This means MDT has been adminstratively disabled to prevent it
749 * from creating any new directories on the MDT, though existing files
750 * and directories can still be read, written, and unlinked.
752 * \retval number of bytes written
754 static ssize_t no_create_show(struct kobject *kobj, struct attribute *attr,
757 struct obd_device *obd = container_of(kobj, struct obd_device,
759 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
761 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_lut.lut_no_create);
765 * Set MDT to no create mode.
767 * This is used to interface to userspace administrative tools to
768 * disable new directory creation on the MDT.
770 * \param[in] count \a buffer length
772 * \retval \a count on success
773 * \retval negative number on error
775 static ssize_t no_create_store(struct kobject *kobj, struct attribute *attr,
776 const char *buffer, size_t count)
778 struct obd_device *obd = container_of(kobj, struct obd_device,
780 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
784 rc = kstrtobool(buffer, &val);
788 mdt->mdt_lut.lut_no_create = val;
792 LUSTRE_RW_ATTR(no_create);
795 * Show MDT async commit count.
798 * @data unused for single entry
800 * Return: 0 on success
801 * negative value on error
803 static ssize_t async_commit_count_show(struct kobject *kobj,
804 struct attribute *attr, char *buf)
806 struct obd_device *obd = container_of(kobj, struct obd_device,
808 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
810 return scnprintf(buf, PAGE_SIZE, "%d\n",
811 atomic_read(&mdt->mdt_async_commit_count));
814 static ssize_t async_commit_count_store(struct kobject *kobj,
815 struct attribute *attr,
816 const char *buffer, size_t count)
818 struct obd_device *obd = container_of(kobj, struct obd_device,
820 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
824 rc = kstrtoint(buffer, 10, &val);
828 atomic_set(&mdt->mdt_async_commit_count, val);
832 LUSTRE_RW_ATTR(async_commit_count);
835 * Show MDT sync count.
837 * \param[in] m seq_file handle
838 * \param[in] data unused for single entry
840 * \retval 0 on success
841 * \retval negative value on error
843 static ssize_t sync_count_show(struct kobject *kobj, struct attribute *attr,
846 struct obd_device *obd = container_of(kobj, struct obd_device,
848 struct lu_target *tgt = obd2obt(obd)->obt_lut;
850 return scnprintf(buf, PAGE_SIZE, "%d\n",
851 atomic_read(&tgt->lut_sync_count));
854 static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
855 const char *buffer, size_t count)
857 struct obd_device *obd = container_of(kobj, struct obd_device,
859 struct lu_target *tgt = obd2obt(obd)->obt_lut;
863 rc = kstrtoint(buffer, 0, &val);
867 atomic_set(&tgt->lut_sync_count, val);
871 LUSTRE_RW_ATTR(sync_count);
873 static const char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
874 [NO_DOM_LOCK_ON_OPEN] = "never",
875 [TRYLOCK_DOM_ON_OPEN] = "trylock",
876 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
879 /* This must be longer than the longest string above */
880 #define DOM_LOCK_MODES_MAXLEN 16
883 * Show MDT policy for data prefetch on open for DoM files..
885 * \param[in] m seq_file handle
886 * \param[in] data unused
888 * \retval 0 on success
889 * \retval negative value on error
891 static ssize_t dom_lock_show(struct kobject *kobj, struct attribute *attr,
894 struct obd_device *obd = container_of(kobj, struct obd_device,
896 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
898 return scnprintf(buf, PAGE_SIZE, "%s\n",
899 dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
903 * Change MDT policy for data prefetch on open for DoM files.
905 * This variable defines how DOM lock is taken at open enqueue.
906 * There are three possible modes:
907 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
908 * IO lock with own enqueue.
909 * 2) trylock - DoM lock will be taken only if non-blocked.
910 * 3) always - DoM lock will be taken always even if it is blocking lock.
912 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
913 * is paired with LAYOUT lock when possible.
915 * \param[in] file proc file
916 * \param[in] buffer string which represents policy
917 * \param[in] count \a buffer length
918 * \param[in] off unused for single entry
920 * \retval \a count on success
921 * \retval negative number on error
923 static ssize_t dom_lock_store(struct kobject *kobj, struct attribute *attr,
924 const char *buffer, size_t count)
926 struct obd_device *obd = container_of(kobj, struct obd_device,
928 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
932 if (count == 0 || count >= DOM_LOCK_MODES_MAXLEN)
935 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
936 /* buffer might have '\n' but using strlen() avoids it */
937 if (strncmp(buffer, dom_open_lock_modes[i],
938 strlen(dom_open_lock_modes[i])) == 0) {
944 /* Legacy numeric codes */
946 rc = kstrtoint(buffer, 0, &val);
951 if (val == ALWAYS_DOM_LOCK_ON_OPEN)
952 val = TRYLOCK_DOM_ON_OPEN;
954 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
957 mdt->mdt_opts.mo_dom_lock = val;
960 LUSTRE_RW_ATTR(dom_lock);
962 static ssize_t dir_split_count_show(struct kobject *kobj,
963 struct attribute *attr,
966 struct obd_device *obd = container_of(kobj, struct obd_device,
968 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
970 return scnprintf(buf, PAGE_SIZE, "%llu\n",
971 mdt->mdt_restriper.mdr_dir_split_count);
974 static ssize_t dir_split_count_store(struct kobject *kobj,
975 struct attribute *attr,
976 const char *buffer, size_t count)
978 struct obd_device *obd = container_of(kobj, struct obd_device,
980 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
984 rc = sysfs_memparse(buffer, count, &val, "B");
991 mdt->mdt_restriper.mdr_dir_split_count = val;
995 LUSTRE_RW_ATTR(dir_split_count);
997 static ssize_t dir_split_delta_show(struct kobject *kobj,
998 struct attribute *attr,
1001 struct obd_device *obd = container_of(kobj, struct obd_device,
1003 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1005 return scnprintf(buf, PAGE_SIZE, "%u\n",
1006 mdt->mdt_restriper.mdr_dir_split_delta);
1009 static ssize_t dir_split_delta_store(struct kobject *kobj,
1010 struct attribute *attr,
1011 const char *buffer, size_t count)
1013 struct obd_device *obd = container_of(kobj, struct obd_device,
1015 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1019 rc = kstrtouint(buffer, 0, &val);
1023 mdt->mdt_restriper.mdr_dir_split_delta = val;
1027 LUSTRE_RW_ATTR(dir_split_delta);
1029 static ssize_t enable_remote_subdir_mount_show(struct kobject *kobj,
1030 struct attribute *attr,
1033 return scnprintf(buf, PAGE_SIZE, "%u\n", 1);
1036 static ssize_t enable_remote_subdir_mount_store(struct kobject *kobj,
1037 struct attribute *attr,
1041 LCONSOLE_WARN("enable_remote_subdir_mount is deprecated, it's always enabled.\n");
1044 LUSTRE_RW_ATTR(enable_remote_subdir_mount);
1047 * Show if the OFD enforces T10PI checksum.
1049 * \param[in] m seq_file handle
1050 * \param[in] data unused for single entry
1052 * \retval 0 on success
1053 * \retval negative value on error
1055 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
1056 struct attribute *attr,
1059 struct obd_device *obd = container_of(kobj, struct obd_device,
1061 struct lu_target *lut = obd2obt(obd)->obt_lut;
1063 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
1067 * Force specific T10PI checksum modes to be enabled
1069 * If T10PI *is* supported in hardware, allow only the supported T10PI type
1070 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
1071 * parameter forces all T10PI types to be enabled (even if slower) for
1074 * The final determination of which algorithm to be used depends whether
1075 * the client supports T10PI or not, and is handled at client connect time.
1077 * \param[in] file proc file
1078 * \param[in] buffer string which represents mode
1079 * 1: set T10PI checksums enforced
1080 * 0: unset T10PI checksums enforced
1081 * \param[in] count \a buffer length
1082 * \param[in] off unused for single entry
1084 * \retval \a count on success
1085 * \retval negative number on error
1087 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
1088 struct attribute *attr,
1089 const char *buffer, size_t count)
1091 struct obd_device *obd = container_of(kobj, struct obd_device,
1093 struct lu_target *lut = obd2obt(obd)->obt_lut;
1097 rc = kstrtobool(buffer, &enforce);
1101 spin_lock(&lut->lut_flags_lock);
1102 lut->lut_cksum_t10pi_enforce = enforce;
1103 spin_unlock(&lut->lut_flags_lock);
1106 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
1109 * Show MDT Maximum modify RPCs in flight.
1111 * @m seq_file handle
1112 * @data unused for single entry
1114 * Return: value on success or negative number on error
1116 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
1117 struct attribute *attr, char *buf)
1119 struct obd_device *obd = container_of(kobj, struct obd_device,
1121 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1123 return scnprintf(buf, PAGE_SIZE, "%u\n",
1124 mdt->mdt_max_mod_rpcs_in_flight);
1127 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
1128 struct attribute *attr,
1129 const char *buffer, size_t count)
1131 struct obd_device *obd = container_of(kobj, struct obd_device,
1133 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1137 rc = kstrtouint(buffer, 0, &val);
1141 if (val < 1 || val > OBD_MAX_RIF_MAX)
1144 if (mdt_max_mod_rpcs_changed(mdt)) {
1145 CWARN("%s: deprecated 'max_mod_rpcs_in_flight' module parameter has also been modified\n",
1147 max_mod_rpcs_per_client = val;
1149 mdt->mdt_max_mod_rpcs_in_flight = val;
1153 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
1156 * mdt_checksum_type(server) proc handling
1160 static int mdt_checksum_type_seq_show(struct seq_file *m, void *data)
1162 struct obd_device *obd = m->private;
1163 struct lu_target *lut;
1164 enum cksum_types pref;
1170 lut = obd2obt(obd)->obt_lut;
1171 /* select fastest checksum type on the server */
1172 pref = obd_cksum_type_select(obd->obd_name,
1173 lut->lut_cksum_types_supported,
1174 lut->lut_dt_conf.ddp_t10_cksum_type);
1176 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
1177 if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
1181 seq_printf(m, "[%s] ", cksum_name[i]);
1183 seq_printf(m, "%s ", cksum_name[i]);
1190 ssize_t job_xattr_show(struct kobject *kobj, struct attribute *attr, char *buf)
1192 struct obd_device *obd = container_of(kobj, struct obd_device,
1194 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1196 if (mdt->mdt_job_xattr[0] == '\0')
1197 return scnprintf(buf, PAGE_SIZE, "NONE\n");
1199 return scnprintf(buf, PAGE_SIZE, "%s\n", mdt->mdt_job_xattr);
1203 * Read in a name for the jobid xattr and validate it.
1204 * The only valid names are "trusted.job" or "user.*" where the name portion
1205 * is <= 7 bytes in the user namespace. Only alphanumeric characters are
1206 * allowed, aside from the namespace separator '.'.
1208 * "none" is a valid value to turn this feature off.
1210 * @return -EINVAL if the name is invalid, else count
1212 ssize_t job_xattr_store(struct kobject *kobj, struct attribute *attr,
1213 const char *buffer, size_t count)
1215 struct obd_device *obd = container_of(kobj, struct obd_device,
1217 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1218 char name[XATTR_JOB_MAX_LEN] = { 0 };
1222 /* writing "none" turns this off by leaving the name empty */
1223 if (!strncmp(buffer, "none", 4) ||
1224 !strncmp(buffer, "NONE", 4)) {
1225 memset(mdt->mdt_job_xattr, 0, sizeof(mdt->mdt_job_xattr));
1229 /* account for stripping \n before rejecting name for being too long */
1230 if (count > XATTR_JOB_MAX_LEN - 1 &&
1231 buffer[XATTR_JOB_MAX_LEN - 1] != '\n')
1234 strncpy(name, buffer, XATTR_JOB_MAX_LEN - 1);
1236 /* reject if not in namespace.name format */
1237 p = strchr(name, '.');
1242 for (; *p != '\0'; p++) {
1244 * if there are any non-alphanumeric characters, the name is
1245 * invalid unless it's a newline, in which case overwrite it
1246 * with '\0' and that's the end of the name.
1255 /* trusted.job is only valid name in trusted namespace */
1256 if (!strncmp(name, "trusted.job", 12)) {
1257 strncpy(mdt->mdt_job_xattr, name, XATTR_JOB_MAX_LEN);
1261 /* only other valid namespace is user */
1262 if (strncmp(name, XATTR_USER_PREFIX, sizeof(XATTR_USER_PREFIX) - 1))
1265 /* ensure that a name was specified */
1266 if (name[sizeof(XATTR_USER_PREFIX) - 1] == '\0')
1269 strncpy(mdt->mdt_job_xattr, name, XATTR_JOB_MAX_LEN);
1274 LPROC_SEQ_FOPS_RO(mdt_checksum_type);
1276 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1277 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1278 LPROC_SEQ_FOPS_RW_TYPE(mdt, checksum_dump);
1279 LUSTRE_RW_ATTR(job_cleanup_interval);
1280 LUSTRE_RW_ATTR(job_xattr);
1281 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1282 LUSTRE_RW_ATTR(hsm_control);
1284 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1285 LUSTRE_RW_ATTR(recovery_time_hard);
1286 LUSTRE_RW_ATTR(recovery_time_soft);
1287 LUSTRE_RW_ATTR(ir_factor);
1289 LUSTRE_RO_ATTR(tot_dirty);
1290 LUSTRE_RO_ATTR(tot_granted);
1291 LUSTRE_RO_ATTR(tot_pending);
1292 LUSTRE_RW_ATTR(grant_compat_disable);
1293 LUSTRE_RO_ATTR(instance);
1295 LUSTRE_RO_ATTR(num_exports);
1296 LUSTRE_RW_ATTR(grant_check_threshold);
1297 LUSTRE_RO_ATTR(eviction_count);
1299 /* per-device at parameters */
1300 LUSTRE_OBD_UINT_PARAM_ATTR(at_min);
1301 LUSTRE_OBD_UINT_PARAM_ATTR(at_max);
1302 LUSTRE_OBD_UINT_PARAM_ATTR(at_history);
1304 static struct attribute *mdt_attrs[] = {
1305 &lustre_attr_tot_dirty.attr,
1306 &lustre_attr_tot_granted.attr,
1307 &lustre_attr_tot_pending.attr,
1308 &lustre_attr_grant_compat_disable.attr,
1309 &lustre_attr_instance.attr,
1310 &lustre_attr_recovery_time_hard.attr,
1311 &lustre_attr_recovery_time_soft.attr,
1312 &lustre_attr_ir_factor.attr,
1313 &lustre_attr_num_exports.attr,
1314 &lustre_attr_grant_check_threshold.attr,
1315 &lustre_attr_eviction_count.attr,
1316 &lustre_attr_identity_expire.attr,
1317 &lustre_attr_identity_acquire_expire.attr,
1318 &lustre_attr_identity_upcall.attr,
1319 &lustre_attr_identity_flush.attr,
1320 &lustre_attr_evict_tgt_nids.attr,
1321 &lustre_attr_enable_cap_mask.attr,
1322 &lustre_attr_enable_chprojid_gid.attr,
1323 &lustre_attr_enable_dir_migration.attr,
1324 &lustre_attr_enable_dir_restripe.attr,
1325 &lustre_attr_enable_dir_auto_split.attr,
1326 &lustre_attr_enable_parallel_rename_dir.attr,
1327 &lustre_attr_enable_parallel_rename_file.attr,
1328 &lustre_attr_enable_parallel_rename_crossdir.attr,
1329 &lustre_attr_enable_remote_dir.attr,
1330 &lustre_attr_enable_remote_dir_gid.attr,
1331 &lustre_attr_enable_remote_rename.attr,
1332 &lustre_attr_enable_striped_dir.attr,
1333 &lustre_attr_commit_on_sharing.attr,
1334 &lustre_attr_local_recovery.attr,
1335 &lustre_attr_no_create.attr,
1336 &lustre_attr_async_commit_count.attr,
1337 &lustre_attr_sync_count.attr,
1338 &lustre_attr_dom_lock.attr,
1339 &lustre_attr_dom_read_open.attr,
1340 &lustre_attr_enable_strict_som.attr,
1341 &lustre_attr_migrate_hsm_allowed.attr,
1342 &lustre_attr_hsm_control.attr,
1343 &lustre_attr_job_cleanup_interval.attr,
1344 &lustre_attr_job_xattr.attr,
1345 &lustre_attr_readonly.attr,
1346 &lustre_attr_dir_split_count.attr,
1347 &lustre_attr_dir_split_delta.attr,
1348 &lustre_attr_dir_restripe_nsonly.attr,
1349 &lustre_attr_checksum_t10pi_enforce.attr,
1350 &lustre_attr_enable_remote_subdir_mount.attr,
1351 &lustre_attr_max_mod_rpcs_in_flight.attr,
1352 &lustre_attr_enable_dmv_implicit_inherit.attr,
1353 &lustre_attr_at_min.attr,
1354 &lustre_attr_at_max.attr,
1355 &lustre_attr_at_history.attr,
1356 &lustre_attr_enable_dmv_xattr.attr,
1360 KOBJ_ATTRIBUTE_GROUPS(mdt); /* creates mdt_groups from mdt_attrs */
1362 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1363 { .name = "recovery_status",
1364 .fops = &mdt_recovery_status_fops },
1365 { .name = "identity_info",
1366 .fops = &mdt_identity_info_fops },
1367 { .name = "site_stats",
1368 .fops = &mdt_site_stats_fops },
1369 { .name = "evict_client",
1370 .fops = &mdt_mds_evict_client_fops },
1371 { .name = "checksum_dump",
1372 .fops = &mdt_checksum_dump_fops },
1373 { .name = "hash_stats",
1374 .fops = &mdt_hash_fops },
1375 { .name = "root_squash",
1376 .fops = &mdt_root_squash_fops },
1377 { .name = "nosquash_nids",
1378 .fops = &mdt_nosquash_nids_fops },
1379 { .name = "checksum_type",
1380 .fops = &mdt_checksum_type_fops },
1384 LDEBUGFS_SEQ_FOPS_RO_TYPE(mdt, recovery_stale_clients);
1386 static struct ldebugfs_vars ldebugfs_mdt_obd_vars[] = {
1387 { .name = "recovery_stale_clients",
1388 .fops = &mdt_recovery_stale_clients_fops },
1392 LDEBUGFS_SEQ_FOPS_RO_TYPE(mdt, srpc_serverctx);
1394 static struct ldebugfs_vars ldebugfs_mdt_gss_vars[] = {
1395 { .name = "srpc_serverctx",
1396 .fops = &mdt_srpc_serverctx_fops },
1401 lprocfs_mdt_print_open_files(struct obd_export *exp, void *v)
1403 struct seq_file *seq = v;
1405 if (exp->exp_lock_hash != NULL) {
1406 struct mdt_export_data *med = &exp->exp_mdt_data;
1407 struct mdt_file_data *mfd;
1409 spin_lock(&med->med_open_lock);
1410 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1411 seq_printf(seq, DFID"\n",
1412 PFID(mdt_object_fid(mfd->mfd_object)));
1414 spin_unlock(&med->med_open_lock);
1420 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1422 struct nid_stat *stats = seq->private;
1424 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
1425 lprocfs_mdt_print_open_files, seq);
1428 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1430 struct seq_file *seq;
1433 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1437 seq = file->private_data;
1438 seq->private = pde_data(inode);
1443 void mdt_counter_incr(struct ptlrpc_request *req, int opcode, long amount)
1445 struct obd_export *exp = req->rq_export;
1447 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1448 lprocfs_counter_add(exp->exp_obd->obd_md_stats,
1449 opcode + LPROC_MD_LAST_OPC, amount);
1450 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1451 lprocfs_counter_add(exp->exp_nid_stats->nid_stats, opcode,
1453 if (exp->exp_obd && obd2obt(exp->exp_obd)->obt_jobstats.ojs_hash &&
1454 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1455 lprocfs_job_stats_log(exp->exp_obd,
1456 lustre_msg_get_jobid(req->rq_reqmsg),
1460 static const char * const mdt_stats[] = {
1461 [LPROC_MDT_OPEN] = "open",
1462 [LPROC_MDT_CLOSE] = "close",
1463 [LPROC_MDT_MKNOD] = "mknod",
1464 [LPROC_MDT_LINK] = "link",
1465 [LPROC_MDT_UNLINK] = "unlink",
1466 [LPROC_MDT_MKDIR] = "mkdir",
1467 [LPROC_MDT_RMDIR] = "rmdir",
1468 [LPROC_MDT_RENAME] = "rename",
1469 [LPROC_MDT_GETATTR] = "getattr",
1470 [LPROC_MDT_SETATTR] = "setattr",
1471 [LPROC_MDT_GETXATTR] = "getxattr",
1472 [LPROC_MDT_SETXATTR] = "setxattr",
1473 [LPROC_MDT_STATFS] = "statfs",
1474 [LPROC_MDT_SYNC] = "sync",
1475 [LPROC_MDT_RENAME_SAMEDIR] = "samedir_rename",
1476 [LPROC_MDT_RENAME_PAR_FILE] = "parallel_rename_file",
1477 [LPROC_MDT_RENAME_PAR_DIR] = "parallel_rename_dir",
1478 [LPROC_MDT_RENAME_CROSSDIR] = "crossdir_rename",
1479 [LPROC_MDT_IO_READ_BYTES] = "read_bytes",
1480 [LPROC_MDT_IO_WRITE_BYTES] = "write_bytes",
1481 [LPROC_MDT_IO_READ] = "read",
1482 [LPROC_MDT_IO_WRITE] = "write",
1483 [LPROC_MDT_IO_PUNCH] = "punch",
1484 [LPROC_MDT_MIGRATE] = "migrate",
1485 [LPROC_MDT_FALLOCATE] = "fallocate",
1488 void mdt_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset,
1489 enum lprocfs_counter_config cntr_umask)
1491 int array_size = ARRAY_SIZE(mdt_stats);
1492 int oidx; /* obd_md_stats index */
1493 int midx; /* mdt_stats index */
1495 LASSERT(stats && stats->ls_num >= offset + array_size);
1497 for (midx = 0; midx < array_size; midx++) {
1498 oidx = midx + offset;
1499 if (midx == LPROC_MDT_IO_READ_BYTES ||
1500 midx == LPROC_MDT_IO_WRITE_BYTES)
1501 lprocfs_counter_init(stats, oidx,
1502 LPROCFS_TYPE_BYTES_FULL_HISTOGRAM &
1506 lprocfs_counter_init(stats, oidx,
1507 LPROCFS_TYPE_LATENCY &
1513 int mdt_tunables_init(struct mdt_device *mdt, const char *name)
1515 struct obd_device *obd = mdt2obd_dev(mdt);
1519 LASSERT(name != NULL);
1521 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdt);
1522 obd->obd_vars = lprocfs_mdt_obd_vars;
1523 rc = lprocfs_obd_setup(obd, true);
1525 CERROR("%s: cannot create proc entries: rc = %d\n",
1526 mdt_obd_name(mdt), rc);
1529 ldebugfs_add_vars(obd->obd_debugfs_entry, ldebugfs_mdt_obd_vars, obd);
1531 rc = tgt_tunables_init(&mdt->mdt_lut);
1533 CERROR("%s: failed to init target tunables: rc = %d\n",
1534 mdt_obd_name(mdt), rc);
1538 rc = hsm_cdt_tunables_init(mdt);
1540 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1541 mdt_obd_name(mdt), rc);
1545 obd->obd_debugfs_gss_dir = debugfs_create_dir("gss",
1546 obd->obd_debugfs_entry);
1547 if (obd->obd_debugfs_gss_dir)
1548 ldebugfs_add_vars(obd->obd_debugfs_gss_dir,
1549 ldebugfs_mdt_gss_vars, obd);
1551 obd->obd_proc_exports_entry = proc_mkdir("exports",
1552 obd->obd_proc_entry);
1553 if (obd->obd_proc_exports_entry)
1554 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1555 obd, &mdt_nid_stats_clear_fops);
1557 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1561 /* add additional MDT md_stats after the default ones */
1562 mdt_stats_counter_init(obd->obd_md_stats, LPROC_MD_LAST_OPC,
1563 LPROCFS_CNTR_HISTOGRAM);
1564 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1565 mdt_stats_counter_init);
1567 rc = lproc_mdt_attach_rename_seqstat(mdt);
1569 CERROR("%s: MDT can not create rename stats rc = %d\n",
1570 mdt_obd_name(mdt), rc);
1575 void mdt_tunables_fini(struct mdt_device *mdt)
1577 struct obd_device *obd = mdt2obd_dev(mdt);
1579 if (obd->obd_proc_exports_entry != NULL) {
1580 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1581 obd->obd_proc_exports_entry = NULL;
1584 lprocfs_free_per_client_stats(obd);
1585 /* hsm_cdt_tunables is disabled earlier than this to avoid
1586 * coordinator restart.
1588 hsm_cdt_tunables_fini(mdt);
1589 tgt_tunables_fini(&mdt->mdt_lut);
1590 lprocfs_obd_cleanup(obd);
1591 lprocfs_free_md_stats(obd);
1592 lprocfs_free_obd_stats(obd);
1593 lprocfs_job_stats_fini(obd);