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-\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);
182 mdt_counter_incr(req, LPROC_MDT_RENAME_SAMEDIR, ktime_delta);
183 if (msi) /* parallel rename type */
184 mdt_counter_incr(req, msi, ktime_delta);
185 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_SAMEDIR_SIZE],
186 (unsigned int)ma->ma_attr.la_size);
190 mdt_counter_incr(req, LPROC_MDT_RENAME_CROSSDIR, ktime_delta);
191 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_SRC_SIZE],
192 (unsigned int)ma->ma_attr.la_size);
194 ma->ma_need = MA_INODE;
196 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
198 CERROR("%s: "DFID" attr_get, rc = %d\n",
199 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
203 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_TGT_SIZE],
204 (unsigned int)ma->ma_attr.la_size);
207 static ssize_t identity_expire_show(struct kobject *kobj,
208 struct attribute *attr, char *buf)
210 struct obd_device *obd = container_of(kobj, struct obd_device,
212 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
214 return scnprintf(buf, PAGE_SIZE, "%lld\n",
215 mdt->mdt_identity_cache->uc_entry_expire);
218 static ssize_t identity_expire_store(struct kobject *kobj,
219 struct attribute *attr,
220 const char *buffer, size_t count)
222 struct obd_device *obd = container_of(kobj, struct obd_device,
224 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
228 rc = kstrtoll(buffer, 10, &val);
235 mdt->mdt_identity_cache->uc_entry_expire = val;
239 LUSTRE_RW_ATTR(identity_expire);
241 static ssize_t identity_acquire_expire_show(struct kobject *kobj,
242 struct attribute *attr, char *buf)
244 struct obd_device *obd = container_of(kobj, struct obd_device,
246 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
248 return scnprintf(buf, PAGE_SIZE, "%lld\n",
249 mdt->mdt_identity_cache->uc_acquire_expire);
252 static ssize_t identity_acquire_expire_store(struct kobject *kobj,
253 struct attribute *attr,
254 const char *buffer, size_t count)
256 struct obd_device *obd = container_of(kobj, struct obd_device,
258 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
262 rc = kstrtoll(buffer, 0, &val);
266 if (val < 0 || val > INT_MAX)
269 mdt->mdt_identity_cache->uc_acquire_expire = val;
273 LUSTRE_RW_ATTR(identity_acquire_expire);
275 static ssize_t identity_upcall_show(struct kobject *kobj,
276 struct attribute *attr, char *buf)
278 struct obd_device *obd = container_of(kobj, struct obd_device,
280 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
281 struct upcall_cache *hash = mdt->mdt_identity_cache;
284 down_read(&hash->uc_upcall_rwsem);
285 rc = scnprintf(buf, PAGE_SIZE, "%s\n", hash->uc_upcall);
286 up_read(&hash->uc_upcall_rwsem);
290 static ssize_t identity_upcall_store(struct kobject *kobj,
291 struct attribute *attr,
292 const char *buffer, size_t count)
294 struct obd_device *obd = container_of(kobj, struct obd_device,
296 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
297 struct upcall_cache *hash = mdt->mdt_identity_cache;
299 if (count >= UC_CACHE_UPCALL_MAXPATH) {
300 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
304 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
305 down_write(&hash->uc_upcall_rwsem);
306 sscanf(buffer, "%s", hash->uc_upcall);
307 up_write(&hash->uc_upcall_rwsem);
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_opts.mo_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 evict_tgt_nids_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",
484 mdt->mdt_opts.mo_evict_tgt_nids);
487 static ssize_t evict_tgt_nids_store(struct kobject *kobj,
488 struct attribute *attr, const char *buffer,
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->mdt_opts.mo_evict_tgt_nids = val;
504 LUSTRE_RW_ATTR(evict_tgt_nids);
506 static ssize_t commit_on_sharing_show(struct kobject *kobj,
507 struct attribute *attr, char *buf)
509 struct obd_device *obd = container_of(kobj, struct obd_device,
511 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
513 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt_cos_is_enabled(mdt));
516 static ssize_t commit_on_sharing_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,
522 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
526 rc = kstrtobool(buffer, &val);
530 mdt_enable_cos(mdt, val);
533 LUSTRE_RW_ATTR(commit_on_sharing);
535 static ssize_t local_recovery_show(struct kobject *kobj,
536 struct attribute *attr, char *buf)
538 struct obd_device *obd = container_of(kobj, struct obd_device,
541 return scnprintf(buf, PAGE_SIZE, "%u\n",
542 obd2obt(obd)->obt_lut->lut_local_recovery);
545 static ssize_t local_recovery_store(struct kobject *kobj,
546 struct attribute *attr,
547 const char *buffer, size_t count)
549 struct obd_device *obd = container_of(kobj, struct obd_device,
554 rc = kstrtobool(buffer, &val);
558 obd2obt(obd)->obt_lut->lut_local_recovery = !!val;
561 LUSTRE_RW_ATTR(local_recovery);
563 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
565 struct obd_device *obd = m->private;
566 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
567 struct root_squash_info *squash = &mdt->mdt_squash;
569 seq_printf(m, "%u:%u\n", squash->rsi_uid,
575 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
576 size_t count, loff_t *off)
578 struct seq_file *m = file->private_data;
579 struct obd_device *obd = m->private;
580 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
581 struct root_squash_info *squash = &mdt->mdt_squash;
583 return lprocfs_wr_root_squash(buffer, count, squash,
586 LPROC_SEQ_FOPS(mdt_root_squash);
588 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
590 struct obd_device *obd = m->private;
591 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
592 struct root_squash_info *squash = &mdt->mdt_squash;
595 spin_lock(&squash->rsi_lock);
596 if (!list_empty(&squash->rsi_nosquash_nids)) {
597 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
598 &squash->rsi_nosquash_nids);
602 seq_puts(m, "NONE\n");
603 spin_unlock(&squash->rsi_lock);
609 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
610 size_t count, loff_t *off)
612 struct seq_file *m = file->private_data;
613 struct obd_device *obd = m->private;
614 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
615 struct root_squash_info *squash = &mdt->mdt_squash;
617 return lprocfs_wr_nosquash_nids(buffer, count, squash,
620 LPROC_SEQ_FOPS(mdt_nosquash_nids);
622 static ssize_t enable_remote_dir_show(struct kobject *kobj,
623 struct attribute *attr, char *buf)
625 struct obd_device *obd = container_of(kobj, struct obd_device,
627 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
629 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_remote_dir);
632 static ssize_t enable_remote_dir_store(struct kobject *kobj,
633 struct attribute *attr,
634 const char *buffer, size_t count)
636 struct obd_device *obd = container_of(kobj, struct obd_device,
638 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
642 rc = kstrtobool(buffer, &val);
646 mdt->mdt_enable_remote_dir = val;
649 LUSTRE_RW_ATTR(enable_remote_dir);
651 static ssize_t enable_remote_dir_gid_show(struct kobject *kobj,
652 struct attribute *attr, char *buf)
654 struct obd_device *obd = container_of(kobj, struct obd_device,
656 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
658 return scnprintf(buf, PAGE_SIZE, "%d\n",
659 (int)mdt->mdt_enable_remote_dir_gid);
662 static ssize_t enable_remote_dir_gid_store(struct kobject *kobj,
663 struct attribute *attr,
664 const char *buffer, size_t count)
666 struct obd_device *obd = container_of(kobj, struct obd_device,
668 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
672 rc = kstrtoint(buffer, 0, &val);
676 mdt->mdt_enable_remote_dir_gid = val;
679 LUSTRE_RW_ATTR(enable_remote_dir_gid);
681 static ssize_t enable_chprojid_gid_show(struct kobject *kobj,
682 struct attribute *attr, char *buf)
684 struct obd_device *obd = container_of(kobj, struct obd_device,
686 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
688 return scnprintf(buf, PAGE_SIZE, "%d\n",
689 (int)mdt->mdt_enable_chprojid_gid);
692 static ssize_t enable_chprojid_gid_store(struct kobject *kobj,
693 struct attribute *attr,
694 const char *buffer, size_t count)
696 struct obd_device *obd = container_of(kobj, struct obd_device,
698 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
702 rc = kstrtoint(buffer, 0, &val);
706 mdt->mdt_enable_chprojid_gid = val;
709 LUSTRE_RW_ATTR(enable_chprojid_gid);
711 static ssize_t enable_parallel_rename_dir_show(struct kobject *kobj,
712 struct attribute *attr,
715 struct obd_device *obd = container_of(kobj, struct obd_device,
717 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
719 return scnprintf(buf, PAGE_SIZE, "%u\n",
720 mdt->mdt_enable_parallel_rename_dir);
723 static ssize_t enable_parallel_rename_dir_store(struct kobject *kobj,
724 struct attribute *attr,
728 struct obd_device *obd = container_of(kobj, struct obd_device,
730 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
734 rc = kstrtobool(buffer, &val);
738 mdt->mdt_enable_parallel_rename_dir = val;
742 LUSTRE_RW_ATTR(enable_parallel_rename_dir);
744 static ssize_t enable_parallel_rename_file_show(struct kobject *kobj,
745 struct attribute *attr,
748 struct obd_device *obd = container_of(kobj, struct obd_device,
750 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
752 return scnprintf(buf, PAGE_SIZE, "%u\n",
753 mdt->mdt_enable_parallel_rename_file);
756 static ssize_t enable_parallel_rename_file_store(struct kobject *kobj,
757 struct attribute *attr,
761 struct obd_device *obd = container_of(kobj, struct obd_device,
763 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
767 rc = kstrtobool(buffer, &val);
771 mdt->mdt_enable_parallel_rename_file = val;
775 LUSTRE_RW_ATTR(enable_parallel_rename_file);
777 static ssize_t enable_striped_dir_show(struct kobject *kobj,
778 struct attribute *attr, char *buf)
780 struct obd_device *obd = container_of(kobj, struct obd_device,
782 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
784 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_striped_dir);
787 static ssize_t enable_striped_dir_store(struct kobject *kobj,
788 struct attribute *attr,
789 const char *buffer, size_t count)
791 struct obd_device *obd = container_of(kobj, struct obd_device,
793 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
797 rc = kstrtobool(buffer, &val);
801 mdt->mdt_enable_striped_dir = val;
804 LUSTRE_RW_ATTR(enable_striped_dir);
806 static ssize_t enable_dir_migration_show(struct kobject *kobj,
807 struct attribute *attr, char *buf)
809 struct obd_device *obd = container_of(kobj, struct obd_device,
811 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
813 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_dir_migration);
816 static ssize_t enable_dir_migration_store(struct kobject *kobj,
817 struct attribute *attr,
818 const char *buffer, size_t count)
820 struct obd_device *obd = container_of(kobj, struct obd_device,
822 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
826 rc = kstrtobool(buffer, &val);
830 mdt->mdt_enable_dir_migration = val;
833 LUSTRE_RW_ATTR(enable_dir_migration);
835 static ssize_t enable_dir_restripe_show(struct kobject *kobj,
836 struct attribute *attr, char *buf)
838 struct obd_device *obd = container_of(kobj, struct obd_device,
840 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
842 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_dir_restripe);
845 static ssize_t enable_dir_restripe_store(struct kobject *kobj,
846 struct attribute *attr,
847 const char *buffer, size_t count)
849 struct obd_device *obd = container_of(kobj, struct obd_device,
851 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
855 rc = kstrtobool(buffer, &val);
859 mdt->mdt_enable_dir_restripe = val;
862 LUSTRE_RW_ATTR(enable_dir_restripe);
864 static ssize_t enable_dir_auto_split_show(struct kobject *kobj,
865 struct attribute *attr, char *buf)
867 struct obd_device *obd = container_of(kobj, struct obd_device,
869 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
871 return scnprintf(buf, PAGE_SIZE, "%u\n",
872 mdt->mdt_enable_dir_auto_split);
875 static ssize_t enable_dir_auto_split_store(struct kobject *kobj,
876 struct attribute *attr,
877 const char *buffer, size_t count)
879 struct obd_device *obd = container_of(kobj, struct obd_device,
881 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
885 rc = kstrtobool(buffer, &val);
889 mdt->mdt_enable_dir_auto_split = val;
892 LUSTRE_RW_ATTR(enable_dir_auto_split);
895 * Show MDT async commit count.
898 * @data unused for single entry
900 * Return: 0 on success
901 * negative value on error
903 static ssize_t async_commit_count_show(struct kobject *kobj,
904 struct attribute *attr, char *buf)
906 struct obd_device *obd = container_of(kobj, struct obd_device,
908 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
910 return scnprintf(buf, PAGE_SIZE, "%d\n",
911 atomic_read(&mdt->mdt_async_commit_count));
914 static ssize_t async_commit_count_store(struct kobject *kobj,
915 struct attribute *attr,
916 const char *buffer, size_t count)
918 struct obd_device *obd = container_of(kobj, struct obd_device,
920 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
924 rc = kstrtoint(buffer, 10, &val);
928 atomic_set(&mdt->mdt_async_commit_count, val);
932 LUSTRE_RW_ATTR(async_commit_count);
935 * Show MDT sync count.
937 * \param[in] m seq_file handle
938 * \param[in] data unused for single entry
940 * \retval 0 on success
941 * \retval negative value on error
943 static ssize_t sync_count_show(struct kobject *kobj, struct attribute *attr,
946 struct obd_device *obd = container_of(kobj, struct obd_device,
948 struct lu_target *tgt = obd2obt(obd)->obt_lut;
950 return scnprintf(buf, PAGE_SIZE, "%d\n",
951 atomic_read(&tgt->lut_sync_count));
954 static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
955 const char *buffer, size_t count)
957 struct obd_device *obd = container_of(kobj, struct obd_device,
959 struct lu_target *tgt = obd2obt(obd)->obt_lut;
963 rc = kstrtoint(buffer, 0, &val);
967 atomic_set(&tgt->lut_sync_count, val);
971 LUSTRE_RW_ATTR(sync_count);
973 static const char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
974 [NO_DOM_LOCK_ON_OPEN] = "never",
975 [TRYLOCK_DOM_ON_OPEN] = "trylock",
976 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
979 /* This must be longer than the longest string above */
980 #define DOM_LOCK_MODES_MAXLEN 16
983 * Show MDT policy for data prefetch on open for DoM files..
985 * \param[in] m seq_file handle
986 * \param[in] data unused
988 * \retval 0 on success
989 * \retval negative value on error
991 static ssize_t dom_lock_show(struct kobject *kobj, struct attribute *attr,
994 struct obd_device *obd = container_of(kobj, struct obd_device,
996 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
998 return scnprintf(buf, PAGE_SIZE, "%s\n",
999 dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
1003 * Change MDT policy for data prefetch on open for DoM files.
1005 * This variable defines how DOM lock is taken at open enqueue.
1006 * There are three possible modes:
1007 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
1008 * IO lock with own enqueue.
1009 * 2) trylock - DoM lock will be taken only if non-blocked.
1010 * 3) always - DoM lock will be taken always even if it is blocking lock.
1012 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
1013 * is paired with LAYOUT lock when possible.
1015 * \param[in] file proc file
1016 * \param[in] buffer string which represents policy
1017 * \param[in] count \a buffer length
1018 * \param[in] off unused for single entry
1020 * \retval \a count on success
1021 * \retval negative number on error
1023 static ssize_t dom_lock_store(struct kobject *kobj, struct attribute *attr,
1024 const char *buffer, size_t count)
1026 struct obd_device *obd = container_of(kobj, struct obd_device,
1028 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1032 if (count == 0 || count >= DOM_LOCK_MODES_MAXLEN)
1035 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
1036 /* buffer might have '\n' but using strlen() avoids it */
1037 if (strncmp(buffer, dom_open_lock_modes[i],
1038 strlen(dom_open_lock_modes[i])) == 0) {
1044 /* Legacy numeric codes */
1046 rc = kstrtoint(buffer, 0, &val);
1051 if (val == ALWAYS_DOM_LOCK_ON_OPEN)
1052 val = TRYLOCK_DOM_ON_OPEN;
1054 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
1057 mdt->mdt_opts.mo_dom_lock = val;
1060 LUSTRE_RW_ATTR(dom_lock);
1063 * Show MDT policy for data prefetch on open for DoM files..
1065 * \param[in] m seq_file handle
1066 * \param[in] data unused
1068 * \retval 0 on success
1069 * \retval negative value on error
1071 static ssize_t dom_read_open_show(struct kobject *kobj,
1072 struct attribute *attr, char *buf)
1074 struct obd_device *obd = container_of(kobj, struct obd_device,
1076 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1078 return scnprintf(buf, PAGE_SIZE, "%u\n",
1079 !!mdt->mdt_opts.mo_dom_read_open);
1083 * Modify MDT policy for data prefetch on open for DoM files.
1085 * If enabled then Data-on-MDT file data may be read during open and
1086 * returned back in reply. It works only with mo_dom_lock enabled.
1088 * \param[in] file proc file
1089 * \param[in] buffer string which represents policy
1090 * \param[in] count \a buffer length
1091 * \param[in] off unused for single entry
1093 * \retval \a count on success
1094 * \retval negative number on error
1096 static ssize_t dom_read_open_store(struct kobject *kobj,
1097 struct attribute *attr, const char *buffer,
1100 struct obd_device *obd = container_of(kobj, struct obd_device,
1102 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1106 rc = kstrtobool(buffer, &val);
1110 mdt->mdt_opts.mo_dom_read_open = !!val;
1113 LUSTRE_RW_ATTR(dom_read_open);
1116 * Show policy for using strict SOM information for real size (stat size).
1118 * \param[in] m seq_file handle
1119 * \param[in] data unused
1121 * \retval 0 on success
1122 * \retval negative value on error
1124 static ssize_t enable_strict_som_show(struct kobject *kobj,
1125 struct attribute *attr, char *buf)
1127 struct obd_device *obd = container_of(kobj, struct obd_device,
1129 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1131 return scnprintf(buf, PAGE_SIZE, "%u\n",
1132 !!mdt->mdt_opts.mo_enable_strict_som);
1136 * Modify policy for using strict SOM information for real size (stat size).
1138 * If disabled, SOM is never used for stat.
1140 * \param[in] file proc file
1141 * \param[in] buffer string which represents policy
1142 * \param[in] count \a buffer length
1143 * \param[in] off unused for single entry
1145 * \retval \a count on success
1146 * \retval negative number on error
1148 static ssize_t enable_strict_som_store(struct kobject *kobj,
1149 struct attribute *attr,
1150 const char *buffer, size_t count)
1152 struct obd_device *obd = container_of(kobj, struct obd_device,
1154 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1158 rc = kstrtobool(buffer, &val);
1162 mdt->mdt_opts.mo_enable_strict_som = !!val;
1165 LUSTRE_RW_ATTR(enable_strict_som);
1167 static ssize_t migrate_hsm_allowed_show(struct kobject *kobj,
1168 struct attribute *attr, char *buf)
1170 struct obd_device *obd = container_of(kobj, struct obd_device,
1172 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1174 return scnprintf(buf, PAGE_SIZE, "%u\n",
1175 mdt->mdt_opts.mo_migrate_hsm_allowed);
1178 static ssize_t migrate_hsm_allowed_store(struct kobject *kobj,
1179 struct attribute *attr,
1180 const char *buffer, size_t count)
1182 struct obd_device *obd = container_of(kobj, struct obd_device,
1184 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1188 rc = kstrtobool(buffer, &val);
1192 mdt->mdt_opts.mo_migrate_hsm_allowed = val;
1195 LUSTRE_RW_ATTR(migrate_hsm_allowed);
1197 static ssize_t readonly_show(struct kobject *kobj, struct attribute *attr,
1200 struct obd_device *obd = container_of(kobj, struct obd_device,
1202 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1204 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_readonly);
1207 static ssize_t readonly_store(struct kobject *kobj, struct attribute *attr,
1208 const char *buffer, size_t count)
1210 struct obd_device *obd = container_of(kobj, struct obd_device,
1212 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1216 rc = kstrtobool(buffer, &val);
1220 mdt->mdt_readonly = val;
1223 LUSTRE_RW_ATTR(readonly);
1225 static ssize_t enable_remote_rename_show(struct kobject *kobj,
1226 struct attribute *attr,
1229 struct obd_device *obd = container_of(kobj, struct obd_device,
1231 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1233 return scnprintf(buf, PAGE_SIZE, "%u\n",
1234 mdt->mdt_enable_remote_rename);
1237 static ssize_t enable_remote_rename_store(struct kobject *kobj,
1238 struct attribute *attr,
1239 const char *buffer, size_t count)
1241 struct obd_device *obd = container_of(kobj, struct obd_device,
1243 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1247 rc = kstrtobool(buffer, &val);
1251 mdt->mdt_enable_remote_rename = val;
1254 LUSTRE_RW_ATTR(enable_remote_rename);
1256 static ssize_t dir_split_count_show(struct kobject *kobj,
1257 struct attribute *attr,
1260 struct obd_device *obd = container_of(kobj, struct obd_device,
1262 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1264 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1265 mdt->mdt_restriper.mdr_dir_split_count);
1268 static ssize_t dir_split_count_store(struct kobject *kobj,
1269 struct attribute *attr,
1270 const char *buffer, size_t count)
1272 struct obd_device *obd = container_of(kobj, struct obd_device,
1274 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1278 rc = sysfs_memparse(buffer, count, &val, "B");
1285 mdt->mdt_restriper.mdr_dir_split_count = val;
1289 LUSTRE_RW_ATTR(dir_split_count);
1291 static ssize_t dir_split_delta_show(struct kobject *kobj,
1292 struct attribute *attr,
1295 struct obd_device *obd = container_of(kobj, struct obd_device,
1297 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1299 return scnprintf(buf, PAGE_SIZE, "%u\n",
1300 mdt->mdt_restriper.mdr_dir_split_delta);
1303 static ssize_t dir_split_delta_store(struct kobject *kobj,
1304 struct attribute *attr,
1305 const char *buffer, size_t count)
1307 struct obd_device *obd = container_of(kobj, struct obd_device,
1309 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1313 rc = kstrtouint(buffer, 0, &val);
1317 mdt->mdt_restriper.mdr_dir_split_delta = val;
1321 LUSTRE_RW_ATTR(dir_split_delta);
1323 static ssize_t dir_restripe_nsonly_show(struct kobject *kobj,
1324 struct attribute *attr, char *buf)
1326 struct obd_device *obd = container_of(kobj, struct obd_device,
1328 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1330 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_dir_restripe_nsonly);
1333 static ssize_t dir_restripe_nsonly_store(struct kobject *kobj,
1334 struct attribute *attr,
1335 const char *buffer, size_t count)
1337 struct obd_device *obd = container_of(kobj, struct obd_device,
1339 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1343 rc = kstrtobool(buffer, &val);
1347 mdt->mdt_dir_restripe_nsonly = val;
1350 LUSTRE_RW_ATTR(dir_restripe_nsonly);
1352 static ssize_t enable_remote_subdir_mount_show(struct kobject *kobj,
1353 struct attribute *attr,
1356 struct obd_device *obd = container_of(kobj, struct obd_device,
1358 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1360 return scnprintf(buf, PAGE_SIZE, "%u\n",
1361 mdt->mdt_enable_remote_subdir_mount);
1364 static ssize_t enable_remote_subdir_mount_store(struct kobject *kobj,
1365 struct attribute *attr,
1369 struct obd_device *obd = container_of(kobj, struct obd_device,
1371 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1375 rc = kstrtobool(buffer, &val);
1379 mdt->mdt_enable_remote_subdir_mount = val;
1382 LUSTRE_RW_ATTR(enable_remote_subdir_mount);
1385 * Show if the OFD enforces T10PI checksum.
1387 * \param[in] m seq_file handle
1388 * \param[in] data unused for single entry
1390 * \retval 0 on success
1391 * \retval negative value on error
1393 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
1394 struct attribute *attr,
1397 struct obd_device *obd = container_of(kobj, struct obd_device,
1399 struct lu_target *lut = obd2obt(obd)->obt_lut;
1401 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
1405 * Force specific T10PI checksum modes to be enabled
1407 * If T10PI *is* supported in hardware, allow only the supported T10PI type
1408 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
1409 * parameter forces all T10PI types to be enabled (even if slower) for
1412 * The final determination of which algorithm to be used depends whether
1413 * the client supports T10PI or not, and is handled at client connect time.
1415 * \param[in] file proc file
1416 * \param[in] buffer string which represents mode
1417 * 1: set T10PI checksums enforced
1418 * 0: unset T10PI checksums enforced
1419 * \param[in] count \a buffer length
1420 * \param[in] off unused for single entry
1422 * \retval \a count on success
1423 * \retval negative number on error
1425 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
1426 struct attribute *attr,
1427 const char *buffer, size_t count)
1429 struct obd_device *obd = container_of(kobj, struct obd_device,
1431 struct lu_target *lut = obd2obt(obd)->obt_lut;
1435 rc = kstrtobool(buffer, &enforce);
1439 spin_lock(&lut->lut_flags_lock);
1440 lut->lut_cksum_t10pi_enforce = enforce;
1441 spin_unlock(&lut->lut_flags_lock);
1444 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
1447 * mdt_checksum_type(server) proc handling
1451 static int mdt_checksum_type_seq_show(struct seq_file *m, void *data)
1453 struct obd_device *obd = m->private;
1454 struct lu_target *lut;
1455 enum cksum_types pref;
1461 lut = obd2obt(obd)->obt_lut;
1462 /* select fastest checksum type on the server */
1463 pref = obd_cksum_type_select(obd->obd_name,
1464 lut->lut_cksum_types_supported, 0);
1466 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
1467 if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
1471 seq_printf(m, "[%s] ", cksum_name[i]);
1473 seq_printf(m, "%s ", cksum_name[i]);
1480 LPROC_SEQ_FOPS_RO(mdt_checksum_type);
1482 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1483 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1484 LPROC_SEQ_FOPS_RW_TYPE(mdt, checksum_dump);
1485 LUSTRE_RW_ATTR(job_cleanup_interval);
1486 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1487 LUSTRE_RW_ATTR(hsm_control);
1489 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1490 LUSTRE_RW_ATTR(recovery_time_hard);
1491 LUSTRE_RW_ATTR(recovery_time_soft);
1492 LUSTRE_RW_ATTR(ir_factor);
1494 LUSTRE_RO_ATTR(tot_dirty);
1495 LUSTRE_RO_ATTR(tot_granted);
1496 LUSTRE_RO_ATTR(tot_pending);
1497 LUSTRE_RW_ATTR(grant_compat_disable);
1498 LUSTRE_RO_ATTR(instance);
1500 LUSTRE_RO_ATTR(num_exports);
1501 LUSTRE_RW_ATTR(grant_check_threshold);
1503 static struct attribute *mdt_attrs[] = {
1504 &lustre_attr_tot_dirty.attr,
1505 &lustre_attr_tot_granted.attr,
1506 &lustre_attr_tot_pending.attr,
1507 &lustre_attr_grant_compat_disable.attr,
1508 &lustre_attr_instance.attr,
1509 &lustre_attr_recovery_time_hard.attr,
1510 &lustre_attr_recovery_time_soft.attr,
1511 &lustre_attr_ir_factor.attr,
1512 &lustre_attr_num_exports.attr,
1513 &lustre_attr_grant_check_threshold.attr,
1514 &lustre_attr_identity_expire.attr,
1515 &lustre_attr_identity_acquire_expire.attr,
1516 &lustre_attr_identity_upcall.attr,
1517 &lustre_attr_identity_flush.attr,
1518 &lustre_attr_evict_tgt_nids.attr,
1519 &lustre_attr_enable_chprojid_gid.attr,
1520 &lustre_attr_enable_dir_migration.attr,
1521 &lustre_attr_enable_dir_restripe.attr,
1522 &lustre_attr_enable_dir_auto_split.attr,
1523 &lustre_attr_enable_parallel_rename_dir.attr,
1524 &lustre_attr_enable_parallel_rename_file.attr,
1525 &lustre_attr_enable_remote_dir.attr,
1526 &lustre_attr_enable_remote_dir_gid.attr,
1527 &lustre_attr_enable_remote_rename.attr,
1528 &lustre_attr_enable_striped_dir.attr,
1529 &lustre_attr_commit_on_sharing.attr,
1530 &lustre_attr_local_recovery.attr,
1531 &lustre_attr_async_commit_count.attr,
1532 &lustre_attr_sync_count.attr,
1533 &lustre_attr_dom_lock.attr,
1534 &lustre_attr_dom_read_open.attr,
1535 &lustre_attr_enable_strict_som.attr,
1536 &lustre_attr_migrate_hsm_allowed.attr,
1537 &lustre_attr_hsm_control.attr,
1538 &lustre_attr_job_cleanup_interval.attr,
1539 &lustre_attr_readonly.attr,
1540 &lustre_attr_dir_split_count.attr,
1541 &lustre_attr_dir_split_delta.attr,
1542 &lustre_attr_dir_restripe_nsonly.attr,
1543 &lustre_attr_checksum_t10pi_enforce.attr,
1544 &lustre_attr_enable_remote_subdir_mount.attr,
1548 KOBJ_ATTRIBUTE_GROUPS(mdt); /* creates mdt_groups from mdt_attrs */
1550 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1551 { .name = "recovery_status",
1552 .fops = &mdt_recovery_status_fops },
1553 { .name = "identity_info",
1554 .fops = &mdt_identity_info_fops },
1555 { .name = "site_stats",
1556 .fops = &mdt_site_stats_fops },
1557 { .name = "evict_client",
1558 .fops = &mdt_mds_evict_client_fops },
1559 { .name = "checksum_dump",
1560 .fops = &mdt_checksum_dump_fops },
1561 { .name = "hash_stats",
1562 .fops = &mdt_hash_fops },
1563 { .name = "root_squash",
1564 .fops = &mdt_root_squash_fops },
1565 { .name = "nosquash_nids",
1566 .fops = &mdt_nosquash_nids_fops },
1567 { .name = "checksum_type",
1568 .fops = &mdt_checksum_type_fops },
1573 lprocfs_mdt_print_open_files(struct obd_export *exp, void *v)
1575 struct seq_file *seq = v;
1577 if (exp->exp_lock_hash != NULL) {
1578 struct mdt_export_data *med = &exp->exp_mdt_data;
1579 struct mdt_file_data *mfd;
1581 spin_lock(&med->med_open_lock);
1582 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1583 seq_printf(seq, DFID"\n",
1584 PFID(mdt_object_fid(mfd->mfd_object)));
1586 spin_unlock(&med->med_open_lock);
1592 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1594 struct nid_stat *stats = seq->private;
1596 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
1597 lprocfs_mdt_print_open_files, seq);
1600 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1602 struct seq_file *seq;
1605 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1609 seq = file->private_data;
1610 seq->private = pde_data(inode);
1615 void mdt_counter_incr(struct ptlrpc_request *req, int opcode, long amount)
1617 struct obd_export *exp = req->rq_export;
1619 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1620 lprocfs_counter_add(exp->exp_obd->obd_md_stats,
1621 opcode + LPROC_MD_LAST_OPC, amount);
1622 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1623 lprocfs_counter_add(exp->exp_nid_stats->nid_stats, opcode,
1625 if (exp->exp_obd && obd2obt(exp->exp_obd)->obt_jobstats.ojs_hash &&
1626 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1627 lprocfs_job_stats_log(exp->exp_obd,
1628 lustre_msg_get_jobid(req->rq_reqmsg),
1632 static const char * const mdt_stats[] = {
1633 [LPROC_MDT_OPEN] = "open",
1634 [LPROC_MDT_CLOSE] = "close",
1635 [LPROC_MDT_MKNOD] = "mknod",
1636 [LPROC_MDT_LINK] = "link",
1637 [LPROC_MDT_UNLINK] = "unlink",
1638 [LPROC_MDT_MKDIR] = "mkdir",
1639 [LPROC_MDT_RMDIR] = "rmdir",
1640 [LPROC_MDT_RENAME] = "rename",
1641 [LPROC_MDT_GETATTR] = "getattr",
1642 [LPROC_MDT_SETATTR] = "setattr",
1643 [LPROC_MDT_GETXATTR] = "getxattr",
1644 [LPROC_MDT_SETXATTR] = "setxattr",
1645 [LPROC_MDT_STATFS] = "statfs",
1646 [LPROC_MDT_SYNC] = "sync",
1647 [LPROC_MDT_RENAME_SAMEDIR] = "samedir_rename",
1648 [LPROC_MDT_RENAME_PAR_FILE] = "parallel_rename_file",
1649 [LPROC_MDT_RENAME_PAR_DIR] = "parallel_rename_dir",
1650 [LPROC_MDT_RENAME_CROSSDIR] = "crossdir_rename",
1651 [LPROC_MDT_IO_READ_BYTES] = "read_bytes",
1652 [LPROC_MDT_IO_WRITE_BYTES] = "write_bytes",
1653 [LPROC_MDT_IO_READ] = "read",
1654 [LPROC_MDT_IO_WRITE] = "write",
1655 [LPROC_MDT_IO_PUNCH] = "punch",
1656 [LPROC_MDT_MIGRATE] = "migrate",
1657 [LPROC_MDT_FALLOCATE] = "fallocate",
1660 void mdt_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset,
1661 enum lprocfs_counter_config cntr_umask)
1663 int array_size = ARRAY_SIZE(mdt_stats);
1664 int oidx; /* obd_md_stats index */
1665 int midx; /* mdt_stats index */
1667 LASSERT(stats && stats->ls_num >= offset + array_size);
1669 for (midx = 0; midx < array_size; midx++) {
1670 oidx = midx + offset;
1671 if (midx == LPROC_MDT_IO_READ_BYTES ||
1672 midx == LPROC_MDT_IO_WRITE_BYTES)
1673 lprocfs_counter_init(stats, oidx,
1674 LPROCFS_TYPE_BYTES_FULL_HISTOGRAM &
1678 lprocfs_counter_init(stats, oidx,
1679 LPROCFS_TYPE_LATENCY &
1685 int mdt_tunables_init(struct mdt_device *mdt, const char *name)
1687 struct obd_device *obd = mdt2obd_dev(mdt);
1691 LASSERT(name != NULL);
1693 obd->obd_ktype.default_groups = KOBJ_ATTR_GROUPS(mdt);
1694 obd->obd_vars = lprocfs_mdt_obd_vars;
1695 rc = lprocfs_obd_setup(obd, true);
1697 CERROR("%s: cannot create proc entries: rc = %d\n",
1698 mdt_obd_name(mdt), rc);
1702 rc = tgt_tunables_init(&mdt->mdt_lut);
1704 CERROR("%s: failed to init target tunables: rc = %d\n",
1705 mdt_obd_name(mdt), rc);
1709 rc = hsm_cdt_tunables_init(mdt);
1711 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1712 mdt_obd_name(mdt), rc);
1716 obd->obd_proc_exports_entry = proc_mkdir("exports",
1717 obd->obd_proc_entry);
1718 if (obd->obd_proc_exports_entry)
1719 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1720 obd, &mdt_nid_stats_clear_fops);
1722 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1726 /* add additional MDT md_stats after the default ones */
1727 mdt_stats_counter_init(obd->obd_md_stats, LPROC_MD_LAST_OPC,
1728 LPROCFS_CNTR_HISTOGRAM);
1729 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1730 mdt_stats_counter_init);
1732 rc = lproc_mdt_attach_rename_seqstat(mdt);
1734 CERROR("%s: MDT can not create rename stats rc = %d\n",
1735 mdt_obd_name(mdt), rc);
1740 void mdt_tunables_fini(struct mdt_device *mdt)
1742 struct obd_device *obd = mdt2obd_dev(mdt);
1744 if (obd->obd_proc_exports_entry != NULL) {
1745 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1746 obd->obd_proc_exports_entry = NULL;
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 lprocfs_free_obd_stats(obd);
1758 lprocfs_job_stats_fini(obd);