1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
5 * Use is subject to license terms.
7 * Copyright (c) 2011, 2017, Intel Corporation.
11 * This file is part of Lustre, http://www.lustre.org/
13 * Author: Lai Siyao <lsy@clusterfs.com>
14 * Author: Fan Yong <fanyong@clusterfs.com>
17 #define DEBUG_SUBSYSTEM S_MDS
19 #include <linux/version.h>
20 #include <asm/statfs.h>
22 #include <linux/module.h>
23 #include <uapi/linux/lnet/nidstr.h>
24 /* LUSTRE_VERSION_CODE */
25 #include <uapi/linux/lustre/lustre_ver.h>
27 * struct OBD_{ALLOC,FREE}*()
30 #include <obd_support.h>
31 /* struct obd_export */
32 #include <lustre_export.h>
33 /* struct obd_device */
35 #include <obd_cksum.h>
36 #include <obd_class.h>
37 #include <lustre_mds.h>
38 #include <lprocfs_status.h>
39 #include "mdt_internal.h"
40 #include <obd_cksum.h>
41 #include <libcfs/libcfs_caps.h>
44 * The rename stats output would be YAML formats, like
46 * - snapshot_time: 1234567890.123456789
47 * - start_time: 1234567880.987654321
48 * - elapsed_time: 9.135802468
50 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
51 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
52 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
54 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
55 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
56 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
58 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
59 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
60 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
63 static void display_rename_stats(struct seq_file *seq, char *name,
64 struct obd_histogram *rs_hist)
66 unsigned long tot, t, cum = 0;
69 tot = lprocfs_oh_sum(rs_hist);
71 seq_printf(seq, "- %s:\n", name);
73 for (i = 0; i < OBD_HIST_MAX; i++) {
74 t = rs_hist->oh_buckets[i];
80 seq_printf(seq, "%6s%d%s", " ", 1 << i, "bytes:");
82 seq_printf(seq, "%6s%d%s", " ", 1 << (i - 10), "KB:");
84 seq_printf(seq, "%6s%d%s", " ", 1 << (i - 20), "MB:");
86 seq_printf(seq, " { sample: %3lu, pct: %3u, cum_pct: %3u }\n",
87 t, pct(t, tot), pct(cum, tot));
94 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
96 struct mdt_device *mdt = seq->private;
97 struct rename_stats *rename_stats = &mdt->mdt_rename_stats;
99 /* this sampling races with updates */
100 seq_puts(seq, "rename_stats:\n");
101 lprocfs_stats_header(seq, ktime_get_real(), rename_stats->rs_init, 15,
104 display_rename_stats(seq, "same_dir",
105 &rename_stats->rs_hist[RENAME_SAMEDIR_SIZE]);
106 display_rename_stats(seq, "crossdir_src",
107 &rename_stats->rs_hist[RENAME_CROSSDIR_SRC_SIZE]);
108 display_rename_stats(seq, "crossdir_tgt",
109 &rename_stats->rs_hist[RENAME_CROSSDIR_TGT_SIZE]);
115 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
116 size_t len, loff_t *off)
118 struct seq_file *seq = file->private_data;
119 struct mdt_device *mdt = seq->private;
122 for (i = 0; i < RENAME_LAST; i++)
123 lprocfs_oh_clear(&mdt->mdt_rename_stats.rs_hist[i]);
124 mdt->mdt_rename_stats.rs_init = ktime_get_real();
128 LPROC_SEQ_FOPS(mdt_rename_stats);
130 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
134 for (i = 0; i < RENAME_LAST; i++)
135 spin_lock_init(&mdt->mdt_rename_stats.rs_hist[i].oh_lock);
136 mdt->mdt_rename_stats.rs_init = ktime_get_real();
138 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
139 &mdt_rename_stats_fops, mdt);
142 void mdt_rename_counter_tally(struct mdt_thread_info *info,
143 struct mdt_device *mdt,
144 struct ptlrpc_request *req,
145 struct mdt_object *src, struct mdt_object *tgt,
146 enum mdt_stat_idx msi, s64 ktime_delta)
148 struct md_attr *ma = &info->mti_attr;
149 struct rename_stats *rstats = &mdt->mdt_rename_stats;
152 mdt_counter_incr(req, LPROC_MDT_RENAME, ktime_delta);
154 ma->ma_need = MA_INODE;
156 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
158 CERROR("%s: "DFID" attr_get, rc = %d\n",
159 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
163 if (msi) /* parallel rename type */
164 mdt_counter_incr(req, msi, ktime_delta);
167 mdt_counter_incr(req, LPROC_MDT_RENAME_SAMEDIR, ktime_delta);
168 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_SAMEDIR_SIZE],
169 (unsigned int)ma->ma_attr.la_size);
173 mdt_counter_incr(req, LPROC_MDT_RENAME_CROSSDIR, ktime_delta);
174 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_SRC_SIZE],
175 (unsigned int)ma->ma_attr.la_size);
177 ma->ma_need = MA_INODE;
179 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
181 CERROR("%s: "DFID" attr_get, rc = %d\n",
182 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
186 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_TGT_SIZE],
187 (unsigned int)ma->ma_attr.la_size);
190 static ssize_t identity_expire_show(struct kobject *kobj,
191 struct attribute *attr, char *buf)
193 struct obd_device *obd = container_of(kobj, struct obd_device,
195 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
197 return scnprintf(buf, PAGE_SIZE, "%lld\n",
198 mdt->mdt_identity_cache->uc_entry_expire);
201 static ssize_t entry_expire_store(struct upcall_cache *cache,
202 const char *buffer, size_t count)
207 rc = kstrtoll(buffer, 10, &val);
214 cache->uc_entry_expire = val;
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);
227 return entry_expire_store(mdt->mdt_identity_cache, buffer, count);
229 LUSTRE_RW_ATTR(identity_expire);
231 static ssize_t identity_acquire_expire_show(struct kobject *kobj,
232 struct attribute *attr, char *buf)
234 struct obd_device *obd = container_of(kobj, struct obd_device,
236 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
238 return scnprintf(buf, PAGE_SIZE, "%lld\n",
239 mdt->mdt_identity_cache->uc_acquire_expire);
242 static ssize_t acquire_expire_store(struct upcall_cache *cache,
243 const char *buffer, size_t count)
248 rc = kstrtoll(buffer, 0, &val);
252 if (val < 0 || val > INT_MAX)
255 cache->uc_acquire_expire = val;
260 static ssize_t identity_acquire_expire_store(struct kobject *kobj,
261 struct attribute *attr,
262 const char *buffer, size_t count)
264 struct obd_device *obd = container_of(kobj, struct obd_device,
266 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
268 return acquire_expire_store(mdt->mdt_identity_cache, buffer, count);
270 LUSTRE_RW_ATTR(identity_acquire_expire);
272 static ssize_t identity_upcall_show(struct kobject *kobj,
273 struct attribute *attr, char *buf)
275 struct obd_device *obd = container_of(kobj, struct obd_device,
277 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
278 struct upcall_cache *hash = mdt->mdt_identity_cache;
281 down_read(&hash->uc_upcall_rwsem);
282 rc = scnprintf(buf, PAGE_SIZE, "%s\n", hash->uc_upcall);
283 up_read(&hash->uc_upcall_rwsem);
287 static ssize_t identity_upcall_store(struct kobject *kobj,
288 struct attribute *attr,
289 const char *buffer, size_t count)
291 struct obd_device *obd = container_of(kobj, struct obd_device,
293 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
294 struct upcall_cache *hash = mdt->mdt_identity_cache;
297 rc = upcall_cache_set_upcall(hash, buffer, count, false);
299 CERROR("%s: incorrect identity upcall %.*s. Valid values for mdt.%s.identity_upcall are NONE, or an executable pathname: rc = %d\n",
300 mdt_obd_name(mdt), (int)count, buffer,
301 mdt_obd_name(mdt), rc);
305 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
306 CWARN("%s: write to upcall name %s\n",
307 mdt_obd_name(mdt), hash->uc_upcall);
309 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
310 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
311 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
313 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
317 LUSTRE_RW_ATTR(identity_upcall);
319 static ssize_t flush_store(struct upcall_cache *cache,
320 const char *buffer, size_t count)
325 rc = kstrtoint(buffer, 0, &uid);
329 mdt_flush_identity(cache, uid);
333 static ssize_t identity_flush_store(struct kobject *kobj,
334 struct attribute *attr,
335 const char *buffer, size_t count)
337 struct obd_device *obd = container_of(kobj, struct obd_device,
339 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
341 return flush_store(mdt->mdt_identity_cache, buffer, count);
343 LUSTRE_WO_ATTR(identity_flush);
346 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
347 size_t count, void *data)
349 struct seq_file *m = file->private_data;
350 struct obd_device *obd = m->private;
351 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
352 struct identity_downcall_data *param;
353 int size = sizeof(*param), rc, checked = 0;
357 CERROR("%s: invalid data count = %lu, size = %d\n",
358 mdt_obd_name(mdt), (unsigned long) count, size);
362 OBD_ALLOC(param, size);
366 if (copy_from_user(param, buffer, size)) {
367 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
368 GOTO(out, rc = -EFAULT);
373 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
374 CERROR("%s: MDS identity downcall bad params\n",
376 GOTO(out, rc = -EINVAL);
379 if (param->idd_nperms > N_PERMS_MAX) {
380 CERROR("%s: perm count %d more than maximum %d\n",
381 mdt_obd_name(mdt), param->idd_nperms,
383 GOTO(out, rc = -EINVAL);
386 if (param->idd_ngroups > NGROUPS_MAX) {
387 CERROR("%s: group count %d more than maximum %d\n",
388 mdt_obd_name(mdt), param->idd_ngroups,
390 GOTO(out, rc = -EINVAL);
393 if (param->idd_ngroups) {
394 rc = param->idd_ngroups; /* save idd_ngroups */
395 OBD_FREE(param, size);
396 size = offsetof(struct identity_downcall_data,
402 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
403 param->idd_uid, param);
406 OBD_FREE(param, size);
408 return rc ? rc : count;
410 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info);
412 static ssize_t identity_int_expire_show(struct kobject *kobj,
413 struct attribute *attr, char *buf)
415 struct obd_device *obd = container_of(kobj, struct obd_device,
417 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
419 return scnprintf(buf, PAGE_SIZE, "%lld\n",
420 mdt->mdt_identity_cache_int->uc_entry_expire);
423 static ssize_t identity_int_expire_store(struct kobject *kobj,
424 struct attribute *attr,
425 const char *buffer, size_t count)
427 struct obd_device *obd = container_of(kobj, struct obd_device,
429 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
431 return entry_expire_store(mdt->mdt_identity_cache_int, buffer, count);
433 LUSTRE_RW_ATTR(identity_int_expire);
435 static ssize_t identity_int_acquire_expire_show(struct kobject *kobj,
436 struct attribute *attr,
439 struct obd_device *obd = container_of(kobj, struct obd_device,
441 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
443 return scnprintf(buf, PAGE_SIZE, "%lld\n",
444 mdt->mdt_identity_cache_int->uc_acquire_expire);
447 static ssize_t identity_int_acquire_expire_store(struct kobject *kobj,
448 struct attribute *attr,
452 struct obd_device *obd = container_of(kobj, struct obd_device,
454 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
456 return acquire_expire_store(mdt->mdt_identity_cache_int, buffer, count);
458 LUSTRE_RW_ATTR(identity_int_acquire_expire);
460 static ssize_t identity_int_flush_store(struct kobject *kobj,
461 struct attribute *attr,
462 const char *buffer, size_t count)
464 struct obd_device *obd = container_of(kobj, struct obd_device,
466 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
468 return flush_store(mdt->mdt_identity_cache_int, buffer, count);
470 LUSTRE_WO_ATTR(identity_int_flush);
472 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
474 struct obd_device *obd = m->private;
475 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
477 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
479 LPROC_SEQ_FOPS_RO(mdt_site_stats);
481 #define BUFLEN LNET_NIDSTR_SIZE
484 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
485 size_t count, loff_t *off)
487 struct seq_file *m = file->private_data;
488 struct obd_device *obd = m->private;
489 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
494 OBD_ALLOC(kbuf, BUFLEN);
499 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
500 * bytes into kbuf, to ensure that the string is NUL-terminated.
501 * LNET_NIDSTR_SIZE includes space for a trailing NUL already.
503 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
504 GOTO(out, rc = -EFAULT);
505 tmpbuf = skip_spaces(kbuf);
506 tmpbuf = strsep(&tmpbuf, " \t\n\f\v\r");
508 if (strncmp(tmpbuf, "nid:", 4) != 0) {
509 count = lprocfs_evict_client_seq_write(file, buf, count, off);
513 if (mdt->mdt_evict_tgt_nids) {
514 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
515 sizeof(KEY_EVICT_BY_NID),
517 strlen(tmpbuf + 4) + 1,
520 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
524 /* See the comments in function lprocfs_wr_evict_client()
525 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
526 class_incref(obd, __func__, current);
527 obd_export_evict_by_nid(obd, tmpbuf + 4);
528 class_decref(obd, __func__, current);
532 OBD_FREE(kbuf, BUFLEN);
533 return rc < 0 ? rc : count;
538 static ssize_t commit_on_sharing_show(struct kobject *kobj,
539 struct attribute *attr, char *buf)
541 struct obd_device *obd = container_of(kobj, struct obd_device,
543 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
545 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt_cos_is_enabled(mdt));
548 static ssize_t commit_on_sharing_store(struct kobject *kobj,
549 struct attribute *attr,
550 const char *buffer, size_t count)
552 struct obd_device *obd = container_of(kobj, struct obd_device,
554 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
558 rc = kstrtobool(buffer, &val);
562 mdt_enable_cos(mdt, val);
565 LUSTRE_RW_ATTR(commit_on_sharing);
567 static ssize_t local_recovery_show(struct kobject *kobj,
568 struct attribute *attr, char *buf)
570 struct obd_device *obd = container_of(kobj, struct obd_device,
573 return scnprintf(buf, PAGE_SIZE, "%u\n",
574 obd2obt(obd)->obt_lut->lut_local_recovery);
577 static ssize_t local_recovery_store(struct kobject *kobj,
578 struct attribute *attr,
579 const char *buffer, size_t count)
581 struct obd_device *obd = container_of(kobj, struct obd_device,
586 rc = kstrtobool(buffer, &val);
590 obd2obt(obd)->obt_lut->lut_local_recovery = !!val;
593 LUSTRE_RW_ATTR(local_recovery);
595 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
597 struct obd_device *obd = m->private;
598 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
599 struct root_squash_info *squash = &mdt->mdt_squash;
601 seq_printf(m, "%u:%u\n", squash->rsi_uid,
607 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
608 size_t count, loff_t *off)
610 struct seq_file *m = file->private_data;
611 struct obd_device *obd = m->private;
612 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
613 struct root_squash_info *squash = &mdt->mdt_squash;
615 return lprocfs_wr_root_squash(buffer, count, squash,
618 LPROC_SEQ_FOPS(mdt_root_squash);
620 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
622 struct obd_device *obd = m->private;
623 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
624 struct root_squash_info *squash = &mdt->mdt_squash;
627 spin_lock(&squash->rsi_lock);
628 if (!list_empty(&squash->rsi_nosquash_nids)) {
629 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
630 &squash->rsi_nosquash_nids);
634 seq_puts(m, "NONE\n");
635 spin_unlock(&squash->rsi_lock);
641 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
642 size_t count, loff_t *off)
644 struct seq_file *m = file->private_data;
645 struct obd_device *obd = m->private;
646 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
647 struct root_squash_info *squash = &mdt->mdt_squash;
649 return lprocfs_wr_nosquash_nids(buffer, count, squash,
652 LPROC_SEQ_FOPS(mdt_nosquash_nids);
654 static ssize_t enable_cap_mask_show(struct kobject *kobj,
655 struct attribute *attr, char *buf)
657 struct obd_device *obd = container_of(kobj, struct obd_device,
659 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
660 u64 mask = libcfs_cap2num(mdt->mdt_enable_cap_mask);
662 return cfs_mask2str(buf, PAGE_SIZE, mask, libcfs_cap2str, ',');
665 static ssize_t enable_cap_mask_store(struct kobject *kobj,
666 struct attribute *attr,
667 const char *buffer, size_t count)
669 struct obd_device *obd = container_of(kobj, struct obd_device,
671 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
672 static kernel_cap_t allowed_cap = CAP_EMPTY_SET;
673 unsigned long long val;
676 rc = kstrtoull(buffer, 0, &val);
678 u64 cap = libcfs_cap2num(mdt->mdt_enable_cap_mask);
680 /* the "allmask" is filtered by allowed_mask below */
681 rc = cfs_str2mask(buffer, libcfs_cap2str, &cap, 0, ~0ULL, 0);
687 /* All of the capabilities that we currently allow/check */
688 if (unlikely(cap_isclear(allowed_cap))) {
689 allowed_cap = CAP_FS_SET;
690 cap_raise(allowed_cap, CAP_SYS_RESOURCE);
693 mdt->mdt_enable_cap_mask = cap_intersect(libcfs_num2cap(val),
698 LUSTRE_RW_ATTR(enable_cap_mask);
700 static ssize_t enable_remote_dir_gid_show(struct kobject *kobj,
701 struct attribute *attr, char *buf)
703 struct obd_device *obd = container_of(kobj, struct obd_device,
705 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
707 return scnprintf(buf, PAGE_SIZE, "%d\n",
708 (int)mdt->mdt_enable_remote_dir_gid);
711 static ssize_t enable_remote_dir_gid_store(struct kobject *kobj,
712 struct attribute *attr,
713 const char *buffer, size_t count)
715 struct obd_device *obd = container_of(kobj, struct obd_device,
717 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
721 rc = kstrtoint(buffer, 0, &val);
725 mdt->mdt_enable_remote_dir_gid = val;
728 LUSTRE_RW_ATTR(enable_remote_dir_gid);
730 static ssize_t enable_chprojid_gid_show(struct kobject *kobj,
731 struct attribute *attr, char *buf)
733 struct obd_device *obd = container_of(kobj, struct obd_device,
735 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
737 return scnprintf(buf, PAGE_SIZE, "%d\n",
738 (int)mdt->mdt_enable_chprojid_gid);
741 static ssize_t enable_chprojid_gid_store(struct kobject *kobj,
742 struct attribute *attr,
743 const char *buffer, size_t count)
745 struct obd_device *obd = container_of(kobj, struct obd_device,
747 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
751 rc = kstrtoint(buffer, 0, &val);
755 mdt->mdt_enable_chprojid_gid = val;
758 LUSTRE_RW_ATTR(enable_chprojid_gid);
760 #define MDT_BOOL_RW_ATTR(name) \
761 static ssize_t name##_show(struct kobject *kobj, struct attribute *attr,\
764 struct obd_device *obd = container_of(kobj, struct obd_device, \
766 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); \
767 if (IS_ERR_OR_NULL(mdt)) \
769 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_##name); \
771 static ssize_t name##_store(struct kobject *kobj, struct attribute *attr,\
772 const char *buffer, size_t count) \
774 struct obd_device *obd = container_of(kobj, struct obd_device, \
776 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev); \
779 if (IS_ERR_OR_NULL(mdt)) \
781 rc = kstrtobool(buffer, &val); \
784 mdt->mdt_##name = val; \
789 MDT_BOOL_RW_ATTR(readonly);
790 MDT_BOOL_RW_ATTR(evict_tgt_nids);
791 MDT_BOOL_RW_ATTR(dom_read_open);
792 MDT_BOOL_RW_ATTR(enable_remote_dir);
793 MDT_BOOL_RW_ATTR(enable_remote_rename);
794 MDT_BOOL_RW_ATTR(enable_parallel_rename_dir);
795 MDT_BOOL_RW_ATTR(enable_parallel_rename_file);
796 MDT_BOOL_RW_ATTR(enable_parallel_rename_crossdir);
797 MDT_BOOL_RW_ATTR(enable_striped_dir);
798 MDT_BOOL_RW_ATTR(enable_dir_migration);
799 MDT_BOOL_RW_ATTR(enable_dir_restripe);
800 MDT_BOOL_RW_ATTR(enable_dir_auto_split);
801 MDT_BOOL_RW_ATTR(dir_restripe_nsonly);
802 MDT_BOOL_RW_ATTR(migrate_hsm_allowed);
803 MDT_BOOL_RW_ATTR(enable_strict_som);
804 MDT_BOOL_RW_ATTR(enable_dmv_implicit_inherit);
805 MDT_BOOL_RW_ATTR(enable_dmv_xattr);
806 MDT_BOOL_RW_ATTR(enable_rename_trylock);
809 * enable_resource_id_check_show() - Show if resource ID checking is enabled
812 * @kobj: kobject for the MDT device
813 * @attr: attribute for the MDT device
814 * @buf: buffer to write the value to
816 * When enabled, MDT inodes UID/GID are checked against
817 * the nodemap mapping rules.
821 * * %negative on failure
823 static ssize_t enable_resource_id_check_show(struct kobject *kobj,
824 struct attribute *attr, char *buf)
826 struct obd_device *obd =
827 container_of(kobj, struct obd_device, obd_kset.kobj);
828 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
830 return scnprintf(buf, PAGE_SIZE, "%u\n",
831 mdt->mdt_lut.lut_enable_resource_id_check);
835 * enable_resource_id_check_store() - Enable or disable resource ID checking
838 * @kobj: kobject for the MDT device
839 * @attr: attribute for the MDT device
840 * @buffer: buffer containing the value to set
841 * @count: length of the buffer
843 * This is used to interface to userspace administrative tools to enable
844 * or disable resource ID checking on the MDT.
848 * * %negative on failure
850 static ssize_t enable_resource_id_check_store(struct kobject *kobj,
851 struct attribute *attr,
852 const char *buffer, size_t count)
854 struct obd_device *obd =
855 container_of(kobj, struct obd_device, obd_kset.kobj);
856 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
860 rc = kstrtobool(buffer, &val);
864 mdt->mdt_lut.lut_enable_resource_id_check = val;
868 LUSTRE_RW_ATTR(enable_resource_id_check);
870 static ssize_t enable_pin_gid_show(struct kobject *kobj,
871 struct attribute *attr, char *buf)
873 struct obd_device *obd = container_of(kobj, struct obd_device,
875 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
877 if (mdt->mdt_enable_pin_gid == ~0U)
878 return scnprintf(buf, PAGE_SIZE, "-1\n");
879 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_pin_gid);
882 static ssize_t enable_pin_gid_store(struct kobject *kobj,
883 struct attribute *attr,
884 const char *buffer, size_t count)
886 struct obd_device *obd = container_of(kobj, struct obd_device,
888 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
892 rc = kstrtoint(buffer, 0, &val);
896 mdt->mdt_enable_pin_gid = val;
899 LUSTRE_RW_ATTR(enable_pin_gid);
902 * Show if the MDT is in no create mode.
904 * This means MDT has been adminstratively disabled to prevent it
905 * from creating any new directories on the MDT, though existing files
906 * and directories can still be read, written, and unlinked.
908 * \retval number of bytes written
910 static ssize_t no_create_show(struct kobject *kobj, struct attribute *attr,
913 struct obd_device *obd = container_of(kobj, struct obd_device,
915 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
917 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_lut.lut_no_create);
921 * Set MDT to no create mode.
923 * This is used to interface to userspace administrative tools to
924 * disable new directory creation on the MDT.
926 * \param[in] count \a buffer length
928 * \retval \a count on success
929 * \retval negative number on error
931 static ssize_t no_create_store(struct kobject *kobj, struct attribute *attr,
932 const char *buffer, size_t count)
934 struct obd_device *obd = container_of(kobj, struct obd_device,
936 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
940 rc = kstrtobool(buffer, &val);
944 mdt->mdt_lut.lut_no_create = val;
948 LUSTRE_RW_ATTR(no_create);
951 * Show MDT async commit count.
954 * @data unused for single entry
956 * Return: 0 on success
957 * negative value on error
959 static ssize_t async_commit_count_show(struct kobject *kobj,
960 struct attribute *attr, char *buf)
962 struct obd_device *obd = container_of(kobj, struct obd_device,
964 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
966 return scnprintf(buf, PAGE_SIZE, "%d\n",
967 atomic_read(&mdt->mdt_async_commit_count));
970 static ssize_t async_commit_count_store(struct kobject *kobj,
971 struct attribute *attr,
972 const char *buffer, size_t count)
974 struct obd_device *obd = container_of(kobj, struct obd_device,
976 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
980 rc = kstrtoint(buffer, 10, &val);
984 atomic_set(&mdt->mdt_async_commit_count, val);
988 LUSTRE_RW_ATTR(async_commit_count);
991 * Show MDT sync count.
993 * \param[in] m seq_file handle
994 * \param[in] data unused for single entry
996 * \retval 0 on success
997 * \retval negative value on error
999 static ssize_t sync_count_show(struct kobject *kobj, struct attribute *attr,
1002 struct obd_device *obd = container_of(kobj, struct obd_device,
1004 struct lu_target *tgt = obd2obt(obd)->obt_lut;
1006 return scnprintf(buf, PAGE_SIZE, "%d\n",
1007 atomic_read(&tgt->lut_sync_count));
1010 static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
1011 const char *buffer, size_t count)
1013 struct obd_device *obd = container_of(kobj, struct obd_device,
1015 struct lu_target *tgt = obd2obt(obd)->obt_lut;
1019 rc = kstrtoint(buffer, 0, &val);
1023 atomic_set(&tgt->lut_sync_count, val);
1027 LUSTRE_RW_ATTR(sync_count);
1029 static const char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
1030 [NO_DOM_LOCK_ON_OPEN] = "never",
1031 [TRYLOCK_DOM_ON_OPEN] = "trylock",
1032 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
1035 /* This must be longer than the longest string above */
1036 #define DOM_LOCK_MODES_MAXLEN 16
1039 * Show MDT policy for data prefetch on open for DoM files..
1041 * \param[in] m seq_file handle
1042 * \param[in] data unused
1044 * \retval 0 on success
1045 * \retval negative value on error
1047 static ssize_t dom_lock_show(struct kobject *kobj, struct attribute *attr,
1050 struct obd_device *obd = container_of(kobj, struct obd_device,
1052 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1054 return scnprintf(buf, PAGE_SIZE, "%s\n",
1055 dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
1059 * Change MDT policy for data prefetch on open for DoM files.
1061 * This variable defines how DOM lock is taken at open enqueue.
1062 * There are three possible modes:
1063 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
1064 * IO lock with own enqueue.
1065 * 2) trylock - DoM lock will be taken only if non-blocked.
1066 * 3) always - DoM lock will be taken always even if it is blocking lock.
1068 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
1069 * is paired with LAYOUT lock when possible.
1071 * \param[in] file proc file
1072 * \param[in] buffer string which represents policy
1073 * \param[in] count \a buffer length
1074 * \param[in] off unused for single entry
1076 * \retval \a count on success
1077 * \retval negative number on error
1079 static ssize_t dom_lock_store(struct kobject *kobj, struct attribute *attr,
1080 const char *buffer, size_t count)
1082 struct obd_device *obd = container_of(kobj, struct obd_device,
1084 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1088 if (count == 0 || count >= DOM_LOCK_MODES_MAXLEN)
1091 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
1092 /* buffer might have '\n' but using strlen() avoids it */
1093 if (strncmp(buffer, dom_open_lock_modes[i],
1094 strlen(dom_open_lock_modes[i])) == 0) {
1100 /* Legacy numeric codes */
1102 rc = kstrtoint(buffer, 0, &val);
1107 if (val == ALWAYS_DOM_LOCK_ON_OPEN)
1108 val = TRYLOCK_DOM_ON_OPEN;
1110 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
1113 mdt->mdt_opts.mo_dom_lock = val;
1116 LUSTRE_RW_ATTR(dom_lock);
1118 static ssize_t dir_split_count_show(struct kobject *kobj,
1119 struct attribute *attr,
1122 struct obd_device *obd = container_of(kobj, struct obd_device,
1124 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1126 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1127 mdt->mdt_restriper.mdr_dir_split_count);
1130 static ssize_t dir_split_count_store(struct kobject *kobj,
1131 struct attribute *attr,
1132 const char *buffer, size_t count)
1134 struct obd_device *obd = container_of(kobj, struct obd_device,
1136 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1140 rc = sysfs_memparse(buffer, count, &val, "B");
1147 mdt->mdt_restriper.mdr_dir_split_count = val;
1151 LUSTRE_RW_ATTR(dir_split_count);
1153 static ssize_t dir_split_delta_show(struct kobject *kobj,
1154 struct attribute *attr,
1157 struct obd_device *obd = container_of(kobj, struct obd_device,
1159 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1161 return scnprintf(buf, PAGE_SIZE, "%u\n",
1162 mdt->mdt_restriper.mdr_dir_split_delta);
1165 static ssize_t dir_split_delta_store(struct kobject *kobj,
1166 struct attribute *attr,
1167 const char *buffer, size_t count)
1169 struct obd_device *obd = container_of(kobj, struct obd_device,
1171 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1175 rc = kstrtouint(buffer, 0, &val);
1179 mdt->mdt_restriper.mdr_dir_split_delta = val;
1183 LUSTRE_RW_ATTR(dir_split_delta);
1185 static ssize_t enable_remote_subdir_mount_show(struct kobject *kobj,
1186 struct attribute *attr,
1189 return scnprintf(buf, PAGE_SIZE, "%u\n", 1);
1192 static ssize_t enable_remote_subdir_mount_store(struct kobject *kobj,
1193 struct attribute *attr,
1197 LCONSOLE_WARN("enable_remote_subdir_mount is deprecated, it's always enabled.\n");
1200 LUSTRE_RW_ATTR(enable_remote_subdir_mount);
1203 * Show if the OFD enforces T10PI checksum.
1205 * \param[in] m seq_file handle
1206 * \param[in] data unused for single entry
1208 * \retval 0 on success
1209 * \retval negative value on error
1211 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
1212 struct attribute *attr,
1215 struct obd_device *obd = container_of(kobj, struct obd_device,
1217 struct lu_target *lut = obd2obt(obd)->obt_lut;
1219 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
1223 * Force specific T10PI checksum modes to be enabled
1225 * If T10PI *is* supported in hardware, allow only the supported T10PI type
1226 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
1227 * parameter forces all T10PI types to be enabled (even if slower) for
1230 * The final determination of which algorithm to be used depends whether
1231 * the client supports T10PI or not, and is handled at client connect time.
1233 * \param[in] file proc file
1234 * \param[in] buffer string which represents mode
1235 * 1: set T10PI checksums enforced
1236 * 0: unset T10PI checksums enforced
1237 * \param[in] count \a buffer length
1238 * \param[in] off unused for single entry
1240 * \retval \a count on success
1241 * \retval negative number on error
1243 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
1244 struct attribute *attr,
1245 const char *buffer, size_t count)
1247 struct obd_device *obd = container_of(kobj, struct obd_device,
1249 struct lu_target *lut = obd2obt(obd)->obt_lut;
1253 rc = kstrtobool(buffer, &enforce);
1257 spin_lock(&lut->lut_flags_lock);
1258 lut->lut_cksum_t10pi_enforce = enforce;
1259 spin_unlock(&lut->lut_flags_lock);
1262 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
1265 * Show MDT Maximum modify RPCs in flight.
1267 * @m seq_file handle
1268 * @data unused for single entry
1270 * Return: value on success or negative number on error
1272 static ssize_t max_mod_rpcs_in_flight_show(struct kobject *kobj,
1273 struct attribute *attr, char *buf)
1275 struct obd_device *obd = container_of(kobj, struct obd_device,
1277 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1279 return scnprintf(buf, PAGE_SIZE, "%u\n",
1280 mdt->mdt_max_mod_rpcs_in_flight);
1283 static ssize_t max_mod_rpcs_in_flight_store(struct kobject *kobj,
1284 struct attribute *attr,
1285 const char *buffer, size_t count)
1287 struct obd_device *obd = container_of(kobj, struct obd_device,
1289 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1293 rc = kstrtouint(buffer, 0, &val);
1297 if (val < 1 || val > OBD_MAX_RIF_MAX)
1300 if (mdt_max_mod_rpcs_changed(mdt)) {
1301 CWARN("%s: deprecated 'max_mod_rpcs_in_flight' module parameter has also been modified\n",
1303 max_mod_rpcs_per_client = val;
1305 mdt->mdt_max_mod_rpcs_in_flight = val;
1309 LUSTRE_RW_ATTR(max_mod_rpcs_in_flight);
1312 * mdt_checksum_type(server) proc handling
1314 static int mdt_checksum_type_seq_show(struct seq_file *m, void *data)
1316 struct obd_device *obd = m->private;
1317 struct lu_target *lut;
1318 enum cksum_types pref;
1324 lut = obd2obt(obd)->obt_lut;
1325 /* select fastest checksum type on the server */
1326 pref = obd_cksum_type_select(obd->obd_name,
1327 lut->lut_cksum_types_supported,
1328 lut->lut_dt_conf.ddp_t10_cksum_type);
1330 for (i = 0; cksum_name[i] != NULL; i++) {
1331 if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
1335 seq_printf(m, "[%s] ", cksum_name[i]);
1337 seq_printf(m, "%s ", cksum_name[i]);
1344 static ssize_t job_xattr_show(struct kobject *kobj, struct attribute *attr,
1347 struct obd_device *obd = container_of(kobj, struct obd_device,
1349 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1351 if (mdt->mdt_job_xattr[0] == '\0')
1352 return scnprintf(buf, PAGE_SIZE, "NONE\n");
1354 return scnprintf(buf, PAGE_SIZE, "%s\n", mdt->mdt_job_xattr);
1358 * Read in a name for the jobid xattr and validate it.
1359 * The only valid names are "trusted.job" or "user.*" where the name portion
1360 * is <= 7 bytes in the user namespace. Only alphanumeric characters are
1361 * allowed, aside from the namespace separator '.'.
1363 * "none" is a valid value to turn this feature off.
1365 * @return -EINVAL if the name is invalid, else count
1367 static ssize_t job_xattr_store(struct kobject *kobj, struct attribute *attr,
1368 const char *buffer, size_t count)
1370 struct obd_device *obd = container_of(kobj, struct obd_device,
1372 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1373 char name[XATTR_JOB_MAX_LEN] = { 0 };
1377 /* writing "none" turns this off by leaving the name empty */
1378 if (!strncmp(buffer, "none", 4) ||
1379 !strncmp(buffer, "NONE", 4)) {
1380 memset(mdt->mdt_job_xattr, 0, sizeof(mdt->mdt_job_xattr));
1384 /* account for stripping \n before rejecting name for being too long */
1385 if (count > XATTR_JOB_MAX_LEN - 1 &&
1386 buffer[XATTR_JOB_MAX_LEN - 1] != '\n')
1389 strncpy(name, buffer, XATTR_JOB_MAX_LEN - 1);
1391 /* reject if not in namespace.name format */
1392 p = strchr(name, '.');
1397 for (; *p != '\0'; p++) {
1399 * if there are any non-alphanumeric characters, the name is
1400 * invalid unless it's a newline, in which case overwrite it
1401 * with '\0' and that's the end of the name.
1410 /* trusted.job is only valid name in trusted namespace */
1411 if (!strncmp(name, "trusted.job", 12)) {
1412 strncpy(mdt->mdt_job_xattr, name, XATTR_JOB_MAX_LEN);
1416 /* only other valid namespace is user */
1417 if (strncmp(name, XATTR_USER_PREFIX, sizeof(XATTR_USER_PREFIX) - 1))
1420 /* ensure that a name was specified */
1421 if (name[sizeof(XATTR_USER_PREFIX) - 1] == '\0')
1424 strncpy(mdt->mdt_job_xattr, name, XATTR_JOB_MAX_LEN);
1429 LPROC_SEQ_FOPS_RO(mdt_checksum_type);
1431 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1432 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1433 LPROC_SEQ_FOPS_RW_TYPE(mdt, checksum_dump);
1434 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1435 /* belongs to export directory */
1436 LDEBUGFS_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1438 LUSTRE_RW_ATTR(job_cleanup_interval);
1439 LUSTRE_RW_ATTR(job_xattr);
1440 LUSTRE_RW_ATTR(hsm_control);
1442 LUSTRE_RW_ATTR(recovery_time_hard);
1443 LUSTRE_RW_ATTR(recovery_time_soft);
1444 LUSTRE_RW_ATTR(ir_factor);
1446 LUSTRE_RO_ATTR(tot_dirty);
1447 LUSTRE_RO_ATTR(tot_granted);
1448 LUSTRE_RO_ATTR(tot_pending);
1449 LUSTRE_RW_ATTR(grant_compat_disable);
1450 LUSTRE_RO_ATTR(instance);
1452 LUSTRE_RO_ATTR(num_exports);
1453 LUSTRE_RW_ATTR(grant_check_threshold);
1454 LUSTRE_RO_ATTR(eviction_count);
1456 /* per-device at parameters */
1457 LUSTRE_OBD_UINT_PARAM_ATTR(at_min);
1458 LUSTRE_OBD_UINT_PARAM_ATTR(at_max);
1459 LUSTRE_OBD_UINT_PARAM_ATTR(at_history);
1460 LUSTRE_OBD_UINT_PARAM_ATTR(at_unhealthy_factor);
1462 static struct attribute *mdt_attrs[] = {
1463 &lustre_attr_at_min.attr,
1464 &lustre_attr_at_max.attr,
1465 &lustre_attr_at_history.attr,
1466 &lustre_attr_at_unhealthy_factor.attr,
1467 &lustre_attr_tot_dirty.attr,
1468 &lustre_attr_tot_granted.attr,
1469 &lustre_attr_tot_pending.attr,
1470 &lustre_attr_grant_compat_disable.attr,
1471 &lustre_attr_instance.attr,
1472 &lustre_attr_recovery_time_hard.attr,
1473 &lustre_attr_recovery_time_soft.attr,
1474 &lustre_attr_ir_factor.attr,
1475 &lustre_attr_num_exports.attr,
1476 &lustre_attr_grant_check_threshold.attr,
1477 &lustre_attr_eviction_count.attr,
1478 &lustre_attr_identity_expire.attr,
1479 &lustre_attr_identity_acquire_expire.attr,
1480 &lustre_attr_identity_upcall.attr,
1481 &lustre_attr_identity_flush.attr,
1482 &lustre_attr_identity_int_expire.attr,
1483 &lustre_attr_identity_int_acquire_expire.attr,
1484 &lustre_attr_identity_int_flush.attr,
1485 &lustre_attr_evict_tgt_nids.attr,
1486 &lustre_attr_enable_cap_mask.attr,
1487 &lustre_attr_enable_chprojid_gid.attr,
1488 &lustre_attr_enable_pin_gid.attr,
1489 &lustre_attr_enable_dir_migration.attr,
1490 &lustre_attr_enable_dir_restripe.attr,
1491 &lustre_attr_enable_dir_auto_split.attr,
1492 &lustre_attr_enable_dmv_implicit_inherit.attr,
1493 &lustre_attr_enable_dmv_xattr.attr,
1494 &lustre_attr_enable_parallel_rename_dir.attr,
1495 &lustre_attr_enable_parallel_rename_file.attr,
1496 &lustre_attr_enable_parallel_rename_crossdir.attr,
1497 &lustre_attr_enable_remote_dir.attr,
1498 &lustre_attr_enable_remote_dir_gid.attr,
1499 &lustre_attr_enable_remote_rename.attr,
1500 &lustre_attr_enable_remote_subdir_mount.attr,
1501 &lustre_attr_enable_rename_trylock.attr,
1502 &lustre_attr_enable_resource_id_check.attr,
1503 &lustre_attr_enable_strict_som.attr,
1504 &lustre_attr_enable_striped_dir.attr,
1505 &lustre_attr_commit_on_sharing.attr,
1506 &lustre_attr_local_recovery.attr,
1507 &lustre_attr_no_create.attr,
1508 &lustre_attr_async_commit_count.attr,
1509 &lustre_attr_sync_count.attr,
1510 &lustre_attr_dom_lock.attr,
1511 &lustre_attr_dom_read_open.attr,
1512 &lustre_attr_migrate_hsm_allowed.attr,
1513 &lustre_attr_hsm_control.attr,
1514 &lustre_attr_job_cleanup_interval.attr,
1515 &lustre_attr_job_xattr.attr,
1516 &lustre_attr_readonly.attr,
1517 &lustre_attr_dir_split_count.attr,
1518 &lustre_attr_dir_split_delta.attr,
1519 &lustre_attr_dir_restripe_nsonly.attr,
1520 &lustre_attr_checksum_t10pi_enforce.attr,
1521 &lustre_attr_max_mod_rpcs_in_flight.attr,
1525 KOBJ_ATTRIBUTE_GROUPS(mdt); /* creates mdt_groups from mdt_attrs */
1527 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1528 { .name = "recovery_status",
1529 .fops = &mdt_recovery_status_fops },
1530 { .name = "identity_info",
1531 .fops = &mdt_identity_info_fops },
1532 { .name = "site_stats",
1533 .fops = &mdt_site_stats_fops },
1534 { .name = "evict_client",
1535 .fops = &mdt_mds_evict_client_fops },
1536 { .name = "checksum_dump",
1537 .fops = &mdt_checksum_dump_fops },
1538 { .name = "hash_stats",
1539 .fops = &mdt_hash_fops },
1540 { .name = "root_squash",
1541 .fops = &mdt_root_squash_fops },
1542 { .name = "nosquash_nids",
1543 .fops = &mdt_nosquash_nids_fops },
1544 { .name = "checksum_type",
1545 .fops = &mdt_checksum_type_fops },
1549 LDEBUGFS_SEQ_FOPS_RO_TYPE(mdt, recovery_stale_clients);
1551 static struct ldebugfs_vars ldebugfs_mdt_obd_vars[] = {
1552 { .name = "recovery_stale_clients",
1553 .fops = &mdt_recovery_stale_clients_fops },
1557 LDEBUGFS_SEQ_FOPS_RO_TYPE(mdt, srpc_serverctx);
1559 static struct ldebugfs_vars ldebugfs_mdt_gss_vars[] = {
1560 { .name = "srpc_serverctx",
1561 .fops = &mdt_srpc_serverctx_fops },
1566 ldebugfs_mdt_print_open_files(struct obd_export *exp, void *v)
1568 struct seq_file *seq = v;
1570 if (exp->exp_lock_hash != NULL) {
1571 struct mdt_export_data *med = &exp->exp_mdt_data;
1572 struct mdt_file_data *mfd;
1574 spin_lock(&med->med_open_lock);
1575 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1576 seq_printf(seq, DFID"\n",
1577 PFID(mdt_object_fid(mfd->mfd_object)));
1579 spin_unlock(&med->med_open_lock);
1585 static int ldebugfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1587 struct nid_stat *stats = seq->private;
1589 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
1590 ldebugfs_mdt_print_open_files, seq);
1593 int ldebugfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1595 struct seq_file *seq;
1598 rc = single_open(file, &ldebugfs_mdt_open_files_seq_show, NULL);
1602 seq = file->private_data;
1603 seq->private = inode->i_private;
1608 void mdt_counter_incr(struct ptlrpc_request *req, int opcode, long amount)
1610 struct obd_export *exp = req->rq_export;
1612 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1613 lprocfs_counter_add(exp->exp_obd->obd_md_stats,
1614 opcode + LPROC_MD_LAST_OPC, amount);
1615 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1616 lprocfs_counter_add(exp->exp_nid_stats->nid_stats, opcode,
1618 if (exp->exp_obd && obd2obt(exp->exp_obd)->obt_jobstats.ojs_cntr_num &&
1619 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1620 lprocfs_job_stats_log(exp->exp_obd,
1621 lustre_msg_get_jobid(req->rq_reqmsg),
1625 static const char * const mdt_stats[] = {
1626 [LPROC_MDT_OPEN] = "open",
1627 [LPROC_MDT_CLOSE] = "close",
1628 [LPROC_MDT_MKNOD] = "mknod",
1629 [LPROC_MDT_LINK] = "link",
1630 [LPROC_MDT_UNLINK] = "unlink",
1631 [LPROC_MDT_MKDIR] = "mkdir",
1632 [LPROC_MDT_RMDIR] = "rmdir",
1633 [LPROC_MDT_RENAME] = "rename",
1634 [LPROC_MDT_GETATTR] = "getattr",
1635 [LPROC_MDT_SETATTR] = "setattr",
1636 [LPROC_MDT_GETXATTR] = "getxattr",
1637 [LPROC_MDT_SETXATTR] = "setxattr",
1638 [LPROC_MDT_STATFS] = "statfs",
1639 [LPROC_MDT_SYNC] = "sync",
1640 [LPROC_MDT_RENAME_SAMEDIR] = "samedir_rename",
1641 [LPROC_MDT_RENAME_PAR_FILE] = "parallel_rename_file",
1642 [LPROC_MDT_RENAME_PAR_DIR] = "parallel_rename_dir",
1643 [LPROC_MDT_RENAME_CROSSDIR] = "crossdir_rename",
1644 [LPROC_MDT_RENAME_TRYLOCK] = "rename_trylocks",
1645 [LPROC_MDT_IO_READ_BYTES] = "read_bytes",
1646 [LPROC_MDT_IO_WRITE_BYTES] = "write_bytes",
1647 [LPROC_MDT_IO_READ] = "read",
1648 [LPROC_MDT_IO_WRITE] = "write",
1649 [LPROC_MDT_IO_PUNCH] = "punch",
1650 [LPROC_MDT_MIGRATE] = "migrate",
1651 [LPROC_MDT_FALLOCATE] = "fallocate",
1654 void mdt_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset,
1655 enum lprocfs_counter_config cntr_umask)
1657 int array_size = ARRAY_SIZE(mdt_stats);
1658 int oidx; /* obd_md_stats index */
1659 int midx; /* mdt_stats index */
1661 LASSERT(stats && stats->ls_num >= offset + array_size);
1663 for (midx = 0; midx < array_size; midx++) {
1664 oidx = midx + offset;
1665 if (midx == LPROC_MDT_IO_READ_BYTES ||
1666 midx == LPROC_MDT_IO_WRITE_BYTES)
1667 lprocfs_counter_init(stats, oidx,
1668 LPROCFS_TYPE_BYTES_FULL_HISTOGRAM &
1672 lprocfs_counter_init(stats, oidx,
1673 LPROCFS_TYPE_LATENCY &
1679 int mdt_tunables_init(struct mdt_device *mdt, const char *name)
1681 struct obd_device *obd = mdt2obd_dev(mdt);
1685 LASSERT(name != NULL);
1687 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdt);
1688 obd->obd_vars = lprocfs_mdt_obd_vars;
1689 rc = lprocfs_obd_setup(obd, true);
1691 CERROR("%s: cannot create proc entries: rc = %d\n",
1692 mdt_obd_name(mdt), rc);
1695 ldebugfs_add_vars(obd->obd_debugfs_entry, ldebugfs_mdt_obd_vars, obd);
1697 rc = tgt_tunables_init(&mdt->mdt_lut);
1699 CERROR("%s: failed to init target tunables: rc = %d\n",
1700 mdt_obd_name(mdt), rc);
1704 rc = hsm_cdt_tunables_init(mdt);
1706 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1707 mdt_obd_name(mdt), rc);
1711 obd->obd_debugfs_gss_dir = debugfs_create_dir("gss",
1712 obd->obd_debugfs_entry);
1713 if (IS_ERR(obd->obd_debugfs_gss_dir))
1714 obd->obd_debugfs_gss_dir = NULL;
1716 ldebugfs_add_vars(obd->obd_debugfs_gss_dir,
1717 ldebugfs_mdt_gss_vars, obd);
1719 obd->obd_debugfs_exports = debugfs_create_dir("exports",
1720 obd->obd_debugfs_entry);
1721 if (IS_ERR(obd->obd_debugfs_exports))
1722 obd->obd_debugfs_exports = NULL;
1724 debugfs_create_file("clear", 0644, obd->obd_debugfs_exports,
1725 obd, &mdt_nid_stats_clear_fops);
1727 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1731 /* add additional MDT md_stats after the default ones */
1732 mdt_stats_counter_init(obd->obd_md_stats, LPROC_MD_LAST_OPC,
1733 LPROCFS_CNTR_HISTOGRAM);
1734 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1735 mdt_stats_counter_init);
1737 rc = lproc_mdt_attach_rename_seqstat(mdt);
1739 CERROR("%s: MDT can not create rename stats rc = %d\n",
1740 mdt_obd_name(mdt), rc);
1745 void mdt_tunables_fini(struct mdt_device *mdt)
1747 struct obd_device *obd = mdt2obd_dev(mdt);
1749 lprocfs_free_per_client_stats(obd);
1750 /* hsm_cdt_tunables is disabled earlier than this to avoid
1751 * coordinator restart.
1753 hsm_cdt_tunables_fini(mdt);
1754 tgt_tunables_fini(&mdt->mdt_lut);
1755 lprocfs_obd_cleanup(obd);
1756 lprocfs_free_md_stats(obd);
1757 ldebugfs_free_obd_stats(obd);
1758 lprocfs_job_stats_fini(obd);