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 void rename_stats_show(struct seq_file *seq,
113 struct rename_stats *rename_stats)
115 /* this sampling races with updates */
116 seq_puts(seq, "rename_stats:\n- ");
117 lprocfs_stats_header(seq, ktime_get(), rename_stats->rs_init, 15, ":",
120 display_rename_stats(seq, "same_dir",
121 &rename_stats->rs_hist[RENAME_SAMEDIR_SIZE]);
122 display_rename_stats(seq, "crossdir_src",
123 &rename_stats->rs_hist[RENAME_CROSSDIR_SRC_SIZE]);
124 display_rename_stats(seq, "crossdir_tgt",
125 &rename_stats->rs_hist[RENAME_CROSSDIR_TGT_SIZE]);
128 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
130 struct mdt_device *mdt = seq->private;
132 rename_stats_show(seq, &mdt->mdt_rename_stats);
138 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
139 size_t len, loff_t *off)
141 struct seq_file *seq = file->private_data;
142 struct mdt_device *mdt = seq->private;
145 for (i = 0; i < RENAME_LAST; i++)
146 lprocfs_oh_clear(&mdt->mdt_rename_stats.rs_hist[i]);
147 mdt->mdt_rename_stats.rs_init = ktime_get();
151 LPROC_SEQ_FOPS(mdt_rename_stats);
153 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
157 for (i = 0; i < RENAME_LAST; i++)
158 spin_lock_init(&mdt->mdt_rename_stats.rs_hist[i].oh_lock);
160 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
161 &mdt_rename_stats_fops, mdt);
164 void mdt_rename_counter_tally(struct mdt_thread_info *info,
165 struct mdt_device *mdt,
166 struct ptlrpc_request *req,
167 struct mdt_object *src, struct mdt_object *tgt,
168 enum mdt_stat_idx msi, s64 ktime_delta)
170 struct md_attr *ma = &info->mti_attr;
171 struct rename_stats *rstats = &mdt->mdt_rename_stats;
174 mdt_counter_incr(req, LPROC_MDT_RENAME, ktime_delta);
176 ma->ma_need = MA_INODE;
178 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
180 CERROR("%s: "DFID" attr_get, rc = %d\n",
181 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
186 mdt_counter_incr(req, LPROC_MDT_RENAME_SAMEDIR, ktime_delta);
187 if (msi) /* parallel rename type */
188 mdt_counter_incr(req, msi, ktime_delta);
189 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_SAMEDIR_SIZE],
190 (unsigned int)ma->ma_attr.la_size);
194 mdt_counter_incr(req, LPROC_MDT_RENAME_CROSSDIR, ktime_delta);
195 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_SRC_SIZE],
196 (unsigned int)ma->ma_attr.la_size);
198 ma->ma_need = MA_INODE;
200 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
202 CERROR("%s: "DFID" attr_get, rc = %d\n",
203 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
207 lprocfs_oh_tally_log2(&rstats->rs_hist[RENAME_CROSSDIR_TGT_SIZE],
208 (unsigned int)ma->ma_attr.la_size);
211 static ssize_t identity_expire_show(struct kobject *kobj,
212 struct attribute *attr, char *buf)
214 struct obd_device *obd = container_of(kobj, struct obd_device,
216 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
218 return scnprintf(buf, PAGE_SIZE, "%lld\n",
219 mdt->mdt_identity_cache->uc_entry_expire);
222 static ssize_t identity_expire_store(struct kobject *kobj,
223 struct attribute *attr,
224 const char *buffer, size_t count)
226 struct obd_device *obd = container_of(kobj, struct obd_device,
228 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
232 rc = kstrtoll(buffer, 10, &val);
239 mdt->mdt_identity_cache->uc_entry_expire = val;
243 LUSTRE_RW_ATTR(identity_expire);
245 static ssize_t identity_acquire_expire_show(struct kobject *kobj,
246 struct attribute *attr, char *buf)
248 struct obd_device *obd = container_of(kobj, struct obd_device,
250 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
252 return scnprintf(buf, PAGE_SIZE, "%lld\n",
253 mdt->mdt_identity_cache->uc_acquire_expire);
256 static ssize_t identity_acquire_expire_store(struct kobject *kobj,
257 struct attribute *attr,
258 const char *buffer, size_t count)
260 struct obd_device *obd = container_of(kobj, struct obd_device,
262 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
266 rc = kstrtoll(buffer, 0, &val);
270 if (val < 0 || val > INT_MAX)
273 mdt->mdt_identity_cache->uc_acquire_expire = val;
277 LUSTRE_RW_ATTR(identity_acquire_expire);
279 static ssize_t identity_upcall_show(struct kobject *kobj,
280 struct attribute *attr, char *buf)
282 struct obd_device *obd = container_of(kobj, struct obd_device,
284 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
285 struct upcall_cache *hash = mdt->mdt_identity_cache;
288 down_read(&hash->uc_upcall_rwsem);
289 rc = scnprintf(buf, PAGE_SIZE, "%s\n", hash->uc_upcall);
290 up_read(&hash->uc_upcall_rwsem);
294 static ssize_t identity_upcall_store(struct kobject *kobj,
295 struct attribute *attr,
296 const char *buffer, size_t count)
298 struct obd_device *obd = container_of(kobj, struct obd_device,
300 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
301 struct upcall_cache *hash = mdt->mdt_identity_cache;
303 if (count >= UC_CACHE_UPCALL_MAXPATH) {
304 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
308 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
309 down_write(&hash->uc_upcall_rwsem);
310 sscanf(buffer, "%s", hash->uc_upcall);
311 up_write(&hash->uc_upcall_rwsem);
313 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
314 CWARN("%s: write to upcall name %s\n",
315 mdt_obd_name(mdt), hash->uc_upcall);
317 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
318 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
319 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
321 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
325 LUSTRE_RW_ATTR(identity_upcall);
327 static ssize_t identity_flush_store(struct kobject *kobj,
328 struct attribute *attr,
329 const char *buffer, size_t count)
331 struct obd_device *obd = container_of(kobj, struct obd_device,
333 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
337 rc = kstrtoint(buffer, 0, &uid);
341 mdt_flush_identity(mdt->mdt_identity_cache, uid);
344 LUSTRE_WO_ATTR(identity_flush);
347 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
348 size_t count, void *data)
350 struct seq_file *m = file->private_data;
351 struct obd_device *obd = m->private;
352 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
353 struct identity_downcall_data *param;
354 int size = sizeof(*param), rc, checked = 0;
358 CERROR("%s: invalid data count = %lu, size = %d\n",
359 mdt_obd_name(mdt), (unsigned long) count, size);
363 OBD_ALLOC(param, size);
367 if (copy_from_user(param, buffer, size)) {
368 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
369 GOTO(out, rc = -EFAULT);
374 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
375 CERROR("%s: MDS identity downcall bad params\n",
377 GOTO(out, rc = -EINVAL);
380 if (param->idd_nperms > N_PERMS_MAX) {
381 CERROR("%s: perm count %d more than maximum %d\n",
382 mdt_obd_name(mdt), param->idd_nperms,
384 GOTO(out, rc = -EINVAL);
387 if (param->idd_ngroups > NGROUPS_MAX) {
388 CERROR("%s: group count %d more than maximum %d\n",
389 mdt_obd_name(mdt), param->idd_ngroups,
391 GOTO(out, rc = -EINVAL);
394 if (param->idd_ngroups) {
395 rc = param->idd_ngroups; /* save idd_ngroups */
396 OBD_FREE(param, size);
397 size = offsetof(struct identity_downcall_data,
403 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
404 param->idd_uid, param);
408 OBD_FREE(param, size);
410 return rc ? rc : count;
412 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info);
414 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
416 struct obd_device *obd = m->private;
417 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
419 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
421 LPROC_SEQ_FOPS_RO(mdt_site_stats);
423 #define BUFLEN (UUID_MAX + 4)
426 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
427 size_t count, loff_t *off)
429 struct seq_file *m = file->private_data;
430 struct obd_device *obd = m->private;
431 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
436 OBD_ALLOC(kbuf, BUFLEN);
441 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
442 * bytes into kbuf, to ensure that the string is NUL-terminated.
443 * UUID_MAX should include a trailing NUL already.
445 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
446 GOTO(out, rc = -EFAULT);
447 tmpbuf = skip_spaces(kbuf);
448 tmpbuf = strsep(&tmpbuf, " \t\n\f\v\r");
450 if (strncmp(tmpbuf, "nid:", 4) != 0) {
451 count = lprocfs_evict_client_seq_write(file, buf, count, off);
455 if (mdt->mdt_opts.mo_evict_tgt_nids) {
456 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
457 sizeof(KEY_EVICT_BY_NID),
459 strlen(tmpbuf + 4) + 1,
462 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
466 /* See the comments in function lprocfs_wr_evict_client()
467 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
468 class_incref(obd, __func__, current);
469 obd_export_evict_by_nid(obd, tmpbuf + 4);
470 class_decref(obd, __func__, current);
474 OBD_FREE(kbuf, BUFLEN);
475 return rc < 0 ? rc : count;
480 static ssize_t evict_tgt_nids_show(struct kobject *kobj,
481 struct attribute *attr, char *buf)
483 struct obd_device *obd = container_of(kobj, struct obd_device,
485 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
487 return scnprintf(buf, PAGE_SIZE, "%u\n",
488 mdt->mdt_opts.mo_evict_tgt_nids);
491 static ssize_t evict_tgt_nids_store(struct kobject *kobj,
492 struct attribute *attr, const char *buffer,
495 struct obd_device *obd = container_of(kobj, struct obd_device,
497 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
501 rc = kstrtobool(buffer, &val);
505 mdt->mdt_opts.mo_evict_tgt_nids = val;
508 LUSTRE_RW_ATTR(evict_tgt_nids);
510 static ssize_t commit_on_sharing_show(struct kobject *kobj,
511 struct attribute *attr, char *buf)
513 struct obd_device *obd = container_of(kobj, struct obd_device,
515 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
517 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt_cos_is_enabled(mdt));
520 static ssize_t commit_on_sharing_store(struct kobject *kobj,
521 struct attribute *attr,
522 const char *buffer, size_t count)
524 struct obd_device *obd = container_of(kobj, struct obd_device,
526 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
530 rc = kstrtobool(buffer, &val);
534 mdt_enable_cos(mdt, val);
537 LUSTRE_RW_ATTR(commit_on_sharing);
539 static ssize_t local_recovery_show(struct kobject *kobj,
540 struct attribute *attr, char *buf)
542 struct obd_device *obd = container_of(kobj, struct obd_device,
545 return scnprintf(buf, PAGE_SIZE, "%u\n",
546 obd->u.obt.obt_lut->lut_local_recovery);
549 static ssize_t local_recovery_store(struct kobject *kobj,
550 struct attribute *attr,
551 const char *buffer, size_t count)
553 struct obd_device *obd = container_of(kobj, struct obd_device,
558 rc = kstrtobool(buffer, &val);
562 obd->u.obt.obt_lut->lut_local_recovery = !!val;
565 LUSTRE_RW_ATTR(local_recovery);
567 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
569 struct obd_device *obd = m->private;
570 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
571 struct root_squash_info *squash = &mdt->mdt_squash;
573 seq_printf(m, "%u:%u\n", squash->rsi_uid,
579 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
580 size_t count, loff_t *off)
582 struct seq_file *m = file->private_data;
583 struct obd_device *obd = m->private;
584 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
585 struct root_squash_info *squash = &mdt->mdt_squash;
587 return lprocfs_wr_root_squash(buffer, count, squash,
590 LPROC_SEQ_FOPS(mdt_root_squash);
592 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
594 struct obd_device *obd = m->private;
595 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
596 struct root_squash_info *squash = &mdt->mdt_squash;
599 spin_lock(&squash->rsi_lock);
600 if (!list_empty(&squash->rsi_nosquash_nids)) {
601 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
602 &squash->rsi_nosquash_nids);
606 seq_puts(m, "NONE\n");
607 spin_unlock(&squash->rsi_lock);
613 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
614 size_t count, loff_t *off)
616 struct seq_file *m = file->private_data;
617 struct obd_device *obd = m->private;
618 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
619 struct root_squash_info *squash = &mdt->mdt_squash;
621 return lprocfs_wr_nosquash_nids(buffer, count, squash,
624 LPROC_SEQ_FOPS(mdt_nosquash_nids);
626 static ssize_t enable_remote_dir_show(struct kobject *kobj,
627 struct attribute *attr, char *buf)
629 struct obd_device *obd = container_of(kobj, struct obd_device,
631 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
633 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_remote_dir);
636 static ssize_t enable_remote_dir_store(struct kobject *kobj,
637 struct attribute *attr,
638 const char *buffer, size_t count)
640 struct obd_device *obd = container_of(kobj, struct obd_device,
642 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
646 rc = kstrtobool(buffer, &val);
650 mdt->mdt_enable_remote_dir = val;
653 LUSTRE_RW_ATTR(enable_remote_dir);
655 static ssize_t enable_remote_dir_gid_show(struct kobject *kobj,
656 struct attribute *attr, char *buf)
658 struct obd_device *obd = container_of(kobj, struct obd_device,
660 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
662 return scnprintf(buf, PAGE_SIZE, "%d\n",
663 (int)mdt->mdt_enable_remote_dir_gid);
666 static ssize_t enable_remote_dir_gid_store(struct kobject *kobj,
667 struct attribute *attr,
668 const char *buffer, size_t count)
670 struct obd_device *obd = container_of(kobj, struct obd_device,
672 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
676 rc = kstrtoint(buffer, 0, &val);
680 mdt->mdt_enable_remote_dir_gid = val;
683 LUSTRE_RW_ATTR(enable_remote_dir_gid);
685 static ssize_t enable_chprojid_gid_show(struct kobject *kobj,
686 struct attribute *attr, char *buf)
688 struct obd_device *obd = container_of(kobj, struct obd_device,
690 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
692 return scnprintf(buf, PAGE_SIZE, "%d\n",
693 (int)mdt->mdt_enable_chprojid_gid);
696 static ssize_t enable_chprojid_gid_store(struct kobject *kobj,
697 struct attribute *attr,
698 const char *buffer, size_t count)
700 struct obd_device *obd = container_of(kobj, struct obd_device,
702 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
706 rc = kstrtoint(buffer, 0, &val);
710 mdt->mdt_enable_chprojid_gid = val;
713 LUSTRE_RW_ATTR(enable_chprojid_gid);
715 static ssize_t enable_parallel_rename_dir_show(struct kobject *kobj,
716 struct attribute *attr,
719 struct obd_device *obd = container_of(kobj, struct obd_device,
721 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
723 return scnprintf(buf, PAGE_SIZE, "%u\n",
724 mdt->mdt_enable_parallel_rename_dir);
727 static ssize_t enable_parallel_rename_dir_store(struct kobject *kobj,
728 struct attribute *attr,
732 struct obd_device *obd = container_of(kobj, struct obd_device,
734 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
738 rc = kstrtobool(buffer, &val);
742 mdt->mdt_enable_parallel_rename_dir = val;
746 LUSTRE_RW_ATTR(enable_parallel_rename_dir);
748 static ssize_t enable_parallel_rename_file_show(struct kobject *kobj,
749 struct attribute *attr,
752 struct obd_device *obd = container_of(kobj, struct obd_device,
754 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
756 return scnprintf(buf, PAGE_SIZE, "%u\n",
757 mdt->mdt_enable_parallel_rename_file);
760 static ssize_t enable_parallel_rename_file_store(struct kobject *kobj,
761 struct attribute *attr,
765 struct obd_device *obd = container_of(kobj, struct obd_device,
767 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
771 rc = kstrtobool(buffer, &val);
775 mdt->mdt_enable_parallel_rename_file = val;
779 LUSTRE_RW_ATTR(enable_parallel_rename_file);
781 static ssize_t enable_striped_dir_show(struct kobject *kobj,
782 struct attribute *attr, char *buf)
784 struct obd_device *obd = container_of(kobj, struct obd_device,
786 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
788 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_striped_dir);
791 static ssize_t enable_striped_dir_store(struct kobject *kobj,
792 struct attribute *attr,
793 const char *buffer, size_t count)
795 struct obd_device *obd = container_of(kobj, struct obd_device,
797 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
801 rc = kstrtobool(buffer, &val);
805 mdt->mdt_enable_striped_dir = val;
808 LUSTRE_RW_ATTR(enable_striped_dir);
810 static ssize_t enable_dir_migration_show(struct kobject *kobj,
811 struct attribute *attr, char *buf)
813 struct obd_device *obd = container_of(kobj, struct obd_device,
815 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
817 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_dir_migration);
820 static ssize_t enable_dir_migration_store(struct kobject *kobj,
821 struct attribute *attr,
822 const char *buffer, size_t count)
824 struct obd_device *obd = container_of(kobj, struct obd_device,
826 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
830 rc = kstrtobool(buffer, &val);
834 mdt->mdt_enable_dir_migration = val;
837 LUSTRE_RW_ATTR(enable_dir_migration);
839 static ssize_t enable_dir_restripe_show(struct kobject *kobj,
840 struct attribute *attr, char *buf)
842 struct obd_device *obd = container_of(kobj, struct obd_device,
844 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
846 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_dir_restripe);
849 static ssize_t enable_dir_restripe_store(struct kobject *kobj,
850 struct attribute *attr,
851 const char *buffer, size_t count)
853 struct obd_device *obd = container_of(kobj, struct obd_device,
855 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
859 rc = kstrtobool(buffer, &val);
863 mdt->mdt_enable_dir_restripe = val;
866 LUSTRE_RW_ATTR(enable_dir_restripe);
868 static ssize_t enable_dir_auto_split_show(struct kobject *kobj,
869 struct attribute *attr, char *buf)
871 struct obd_device *obd = container_of(kobj, struct obd_device,
873 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
875 return scnprintf(buf, PAGE_SIZE, "%u\n",
876 mdt->mdt_enable_dir_auto_split);
879 static ssize_t enable_dir_auto_split_store(struct kobject *kobj,
880 struct attribute *attr,
881 const char *buffer, size_t count)
883 struct obd_device *obd = container_of(kobj, struct obd_device,
885 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
889 rc = kstrtobool(buffer, &val);
893 mdt->mdt_enable_dir_auto_split = val;
896 LUSTRE_RW_ATTR(enable_dir_auto_split);
899 * Show MDT async commit count.
902 * @data unused for single entry
904 * Return: 0 on success
905 * negative value on error
907 static ssize_t async_commit_count_show(struct kobject *kobj,
908 struct attribute *attr, char *buf)
910 struct obd_device *obd = container_of(kobj, struct obd_device,
912 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
914 return scnprintf(buf, PAGE_SIZE, "%d\n",
915 atomic_read(&mdt->mdt_async_commit_count));
918 static ssize_t async_commit_count_store(struct kobject *kobj,
919 struct attribute *attr,
920 const char *buffer, size_t count)
922 struct obd_device *obd = container_of(kobj, struct obd_device,
924 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
928 rc = kstrtoint(buffer, 10, &val);
932 atomic_set(&mdt->mdt_async_commit_count, val);
936 LUSTRE_RW_ATTR(async_commit_count);
939 * Show MDT sync count.
941 * \param[in] m seq_file handle
942 * \param[in] data unused for single entry
944 * \retval 0 on success
945 * \retval negative value on error
947 static ssize_t sync_count_show(struct kobject *kobj, struct attribute *attr,
950 struct obd_device *obd = container_of(kobj, struct obd_device,
952 struct lu_target *tgt = obd->u.obt.obt_lut;
954 return scnprintf(buf, PAGE_SIZE, "%d\n",
955 atomic_read(&tgt->lut_sync_count));
958 static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
959 const char *buffer, size_t count)
961 struct obd_device *obd = container_of(kobj, struct obd_device,
963 struct lu_target *tgt = obd->u.obt.obt_lut;
967 rc = kstrtoint(buffer, 0, &val);
971 atomic_set(&tgt->lut_sync_count, val);
975 LUSTRE_RW_ATTR(sync_count);
977 static const char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
978 [NO_DOM_LOCK_ON_OPEN] = "never",
979 [TRYLOCK_DOM_ON_OPEN] = "trylock",
980 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
983 /* This must be longer than the longest string above */
984 #define DOM_LOCK_MODES_MAXLEN 16
987 * Show MDT policy for data prefetch on open for DoM files..
989 * \param[in] m seq_file handle
990 * \param[in] data unused
992 * \retval 0 on success
993 * \retval negative value on error
995 static ssize_t dom_lock_show(struct kobject *kobj, struct attribute *attr,
998 struct obd_device *obd = container_of(kobj, struct obd_device,
1000 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1002 return scnprintf(buf, PAGE_SIZE, "%s\n",
1003 dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
1007 * Change MDT policy for data prefetch on open for DoM files.
1009 * This variable defines how DOM lock is taken at open enqueue.
1010 * There are three possible modes:
1011 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
1012 * IO lock with own enqueue.
1013 * 2) trylock - DoM lock will be taken only if non-blocked.
1014 * 3) always - DoM lock will be taken always even if it is blocking lock.
1016 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
1017 * is paired with LAYOUT lock when possible.
1019 * \param[in] file proc file
1020 * \param[in] buffer string which represents policy
1021 * \param[in] count \a buffer length
1022 * \param[in] off unused for single entry
1024 * \retval \a count on success
1025 * \retval negative number on error
1027 static ssize_t dom_lock_store(struct kobject *kobj, struct attribute *attr,
1028 const char *buffer, size_t count)
1030 struct obd_device *obd = container_of(kobj, struct obd_device,
1032 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1036 if (count == 0 || count >= DOM_LOCK_MODES_MAXLEN)
1039 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
1040 /* buffer might have '\n' but using strlen() avoids it */
1041 if (strncmp(buffer, dom_open_lock_modes[i],
1042 strlen(dom_open_lock_modes[i])) == 0) {
1048 /* Legacy numeric codes */
1050 rc = kstrtoint(buffer, 0, &val);
1055 if (val == ALWAYS_DOM_LOCK_ON_OPEN)
1056 val = TRYLOCK_DOM_ON_OPEN;
1058 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
1061 mdt->mdt_opts.mo_dom_lock = val;
1064 LUSTRE_RW_ATTR(dom_lock);
1067 * Show MDT policy for data prefetch on open for DoM files..
1069 * \param[in] m seq_file handle
1070 * \param[in] data unused
1072 * \retval 0 on success
1073 * \retval negative value on error
1075 static ssize_t dom_read_open_show(struct kobject *kobj,
1076 struct attribute *attr, char *buf)
1078 struct obd_device *obd = container_of(kobj, struct obd_device,
1080 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1082 return scnprintf(buf, PAGE_SIZE, "%u\n",
1083 !!mdt->mdt_opts.mo_dom_read_open);
1087 * Modify MDT policy for data prefetch on open for DoM files.
1089 * If enabled then Data-on-MDT file data may be read during open and
1090 * returned back in reply. It works only with mo_dom_lock enabled.
1092 * \param[in] file proc file
1093 * \param[in] buffer string which represents policy
1094 * \param[in] count \a buffer length
1095 * \param[in] off unused for single entry
1097 * \retval \a count on success
1098 * \retval negative number on error
1100 static ssize_t dom_read_open_store(struct kobject *kobj,
1101 struct attribute *attr, const char *buffer,
1104 struct obd_device *obd = container_of(kobj, struct obd_device,
1106 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1110 rc = kstrtobool(buffer, &val);
1114 mdt->mdt_opts.mo_dom_read_open = !!val;
1117 LUSTRE_RW_ATTR(dom_read_open);
1120 * Show policy for using strict SOM information for real size (stat size).
1122 * \param[in] m seq_file handle
1123 * \param[in] data unused
1125 * \retval 0 on success
1126 * \retval negative value on error
1128 static ssize_t enable_strict_som_show(struct kobject *kobj,
1129 struct attribute *attr, char *buf)
1131 struct obd_device *obd = container_of(kobj, struct obd_device,
1133 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1135 return scnprintf(buf, PAGE_SIZE, "%u\n",
1136 !!mdt->mdt_opts.mo_enable_strict_som);
1140 * Modify policy for using strict SOM information for real size (stat size).
1142 * If disabled, SOM is never used for stat.
1144 * \param[in] file proc file
1145 * \param[in] buffer string which represents policy
1146 * \param[in] count \a buffer length
1147 * \param[in] off unused for single entry
1149 * \retval \a count on success
1150 * \retval negative number on error
1152 static ssize_t enable_strict_som_store(struct kobject *kobj,
1153 struct attribute *attr,
1154 const char *buffer, size_t count)
1156 struct obd_device *obd = container_of(kobj, struct obd_device,
1158 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1162 rc = kstrtobool(buffer, &val);
1166 mdt->mdt_opts.mo_enable_strict_som = !!val;
1169 LUSTRE_RW_ATTR(enable_strict_som);
1171 static ssize_t migrate_hsm_allowed_show(struct kobject *kobj,
1172 struct attribute *attr, char *buf)
1174 struct obd_device *obd = container_of(kobj, struct obd_device,
1176 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1178 return scnprintf(buf, PAGE_SIZE, "%u\n",
1179 mdt->mdt_opts.mo_migrate_hsm_allowed);
1182 static ssize_t migrate_hsm_allowed_store(struct kobject *kobj,
1183 struct attribute *attr,
1184 const char *buffer, size_t count)
1186 struct obd_device *obd = container_of(kobj, struct obd_device,
1188 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1192 rc = kstrtobool(buffer, &val);
1196 mdt->mdt_opts.mo_migrate_hsm_allowed = val;
1199 LUSTRE_RW_ATTR(migrate_hsm_allowed);
1201 static ssize_t readonly_show(struct kobject *kobj, struct attribute *attr,
1204 struct obd_device *obd = container_of(kobj, struct obd_device,
1206 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1208 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_readonly);
1211 static ssize_t readonly_store(struct kobject *kobj, struct attribute *attr,
1212 const char *buffer, size_t count)
1214 struct obd_device *obd = container_of(kobj, struct obd_device,
1216 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1220 rc = kstrtobool(buffer, &val);
1224 mdt->mdt_readonly = val;
1227 LUSTRE_RW_ATTR(readonly);
1229 static ssize_t enable_remote_rename_show(struct kobject *kobj,
1230 struct attribute *attr,
1233 struct obd_device *obd = container_of(kobj, struct obd_device,
1235 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1237 return scnprintf(buf, PAGE_SIZE, "%u\n",
1238 mdt->mdt_enable_remote_rename);
1241 static ssize_t enable_remote_rename_store(struct kobject *kobj,
1242 struct attribute *attr,
1243 const char *buffer, size_t count)
1245 struct obd_device *obd = container_of(kobj, struct obd_device,
1247 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1251 rc = kstrtobool(buffer, &val);
1255 mdt->mdt_enable_remote_rename = val;
1258 LUSTRE_RW_ATTR(enable_remote_rename);
1260 static ssize_t dir_split_count_show(struct kobject *kobj,
1261 struct attribute *attr,
1264 struct obd_device *obd = container_of(kobj, struct obd_device,
1266 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1268 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1269 mdt->mdt_restriper.mdr_dir_split_count);
1272 static ssize_t dir_split_count_store(struct kobject *kobj,
1273 struct attribute *attr,
1274 const char *buffer, size_t count)
1276 struct obd_device *obd = container_of(kobj, struct obd_device,
1278 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1282 rc = sysfs_memparse(buffer, count, &val, "B");
1289 mdt->mdt_restriper.mdr_dir_split_count = val;
1293 LUSTRE_RW_ATTR(dir_split_count);
1295 static ssize_t dir_split_delta_show(struct kobject *kobj,
1296 struct attribute *attr,
1299 struct obd_device *obd = container_of(kobj, struct obd_device,
1301 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1303 return scnprintf(buf, PAGE_SIZE, "%u\n",
1304 mdt->mdt_restriper.mdr_dir_split_delta);
1307 static ssize_t dir_split_delta_store(struct kobject *kobj,
1308 struct attribute *attr,
1309 const char *buffer, size_t count)
1311 struct obd_device *obd = container_of(kobj, struct obd_device,
1313 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1317 rc = kstrtouint(buffer, 0, &val);
1321 mdt->mdt_restriper.mdr_dir_split_delta = val;
1325 LUSTRE_RW_ATTR(dir_split_delta);
1327 static ssize_t dir_restripe_nsonly_show(struct kobject *kobj,
1328 struct attribute *attr, char *buf)
1330 struct obd_device *obd = container_of(kobj, struct obd_device,
1332 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1334 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_dir_restripe_nsonly);
1337 static ssize_t dir_restripe_nsonly_store(struct kobject *kobj,
1338 struct attribute *attr,
1339 const char *buffer, size_t count)
1341 struct obd_device *obd = container_of(kobj, struct obd_device,
1343 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1347 rc = kstrtobool(buffer, &val);
1351 mdt->mdt_dir_restripe_nsonly = val;
1354 LUSTRE_RW_ATTR(dir_restripe_nsonly);
1356 static ssize_t enable_remote_subdir_mount_show(struct kobject *kobj,
1357 struct attribute *attr,
1360 struct obd_device *obd = container_of(kobj, struct obd_device,
1362 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1364 return scnprintf(buf, PAGE_SIZE, "%u\n",
1365 mdt->mdt_enable_remote_subdir_mount);
1368 static ssize_t enable_remote_subdir_mount_store(struct kobject *kobj,
1369 struct attribute *attr,
1373 struct obd_device *obd = container_of(kobj, struct obd_device,
1375 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1379 rc = kstrtobool(buffer, &val);
1383 mdt->mdt_enable_remote_subdir_mount = val;
1386 LUSTRE_RW_ATTR(enable_remote_subdir_mount);
1389 * Show if the OFD enforces T10PI checksum.
1391 * \param[in] m seq_file handle
1392 * \param[in] data unused for single entry
1394 * \retval 0 on success
1395 * \retval negative value on error
1397 static ssize_t checksum_t10pi_enforce_show(struct kobject *kobj,
1398 struct attribute *attr,
1401 struct obd_device *obd = container_of(kobj, struct obd_device,
1403 struct lu_target *lut = obd->u.obt.obt_lut;
1405 return scnprintf(buf, PAGE_SIZE, "%u\n", lut->lut_cksum_t10pi_enforce);
1409 * Force specific T10PI checksum modes to be enabled
1411 * If T10PI *is* supported in hardware, allow only the supported T10PI type
1412 * to be used. If T10PI is *not* supported by the OSD, setting the enforce
1413 * parameter forces all T10PI types to be enabled (even if slower) for
1416 * The final determination of which algorithm to be used depends whether
1417 * the client supports T10PI or not, and is handled at client connect time.
1419 * \param[in] file proc file
1420 * \param[in] buffer string which represents mode
1421 * 1: set T10PI checksums enforced
1422 * 0: unset T10PI checksums enforced
1423 * \param[in] count \a buffer length
1424 * \param[in] off unused for single entry
1426 * \retval \a count on success
1427 * \retval negative number on error
1429 static ssize_t checksum_t10pi_enforce_store(struct kobject *kobj,
1430 struct attribute *attr,
1431 const char *buffer, size_t count)
1433 struct obd_device *obd = container_of(kobj, struct obd_device,
1435 struct lu_target *lut = obd->u.obt.obt_lut;
1439 rc = kstrtobool(buffer, &enforce);
1443 spin_lock(&lut->lut_flags_lock);
1444 lut->lut_cksum_t10pi_enforce = enforce;
1445 spin_unlock(&lut->lut_flags_lock);
1448 LUSTRE_RW_ATTR(checksum_t10pi_enforce);
1451 * mdt_checksum_type(server) proc handling
1455 static int mdt_checksum_type_seq_show(struct seq_file *m, void *data)
1457 struct obd_device *obd = m->private;
1458 struct lu_target *lut;
1459 enum cksum_types pref;
1465 lut = obd->u.obt.obt_lut;
1467 /* select fastest checksum type on the server */
1468 pref = obd_cksum_type_select(obd->obd_name,
1469 lut->lut_cksum_types_supported, 0);
1471 for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
1472 if ((BIT(i) & lut->lut_cksum_types_supported) == 0)
1476 seq_printf(m, "[%s] ", cksum_name[i]);
1478 seq_printf(m, "%s ", cksum_name[i]);
1485 LPROC_SEQ_FOPS_RO(mdt_checksum_type);
1487 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1488 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1489 LPROC_SEQ_FOPS_RW_TYPE(mdt, checksum_dump);
1490 LUSTRE_RW_ATTR(job_cleanup_interval);
1491 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1492 LUSTRE_RW_ATTR(hsm_control);
1494 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1495 LUSTRE_RW_ATTR(recovery_time_hard);
1496 LUSTRE_RW_ATTR(recovery_time_soft);
1497 LUSTRE_RW_ATTR(ir_factor);
1499 LUSTRE_RO_ATTR(tot_dirty);
1500 LUSTRE_RO_ATTR(tot_granted);
1501 LUSTRE_RO_ATTR(tot_pending);
1502 LUSTRE_RW_ATTR(grant_compat_disable);
1503 LUSTRE_RO_ATTR(instance);
1505 LUSTRE_RO_ATTR(num_exports);
1506 LUSTRE_RW_ATTR(grant_check_threshold);
1508 static struct attribute *mdt_attrs[] = {
1509 &lustre_attr_tot_dirty.attr,
1510 &lustre_attr_tot_granted.attr,
1511 &lustre_attr_tot_pending.attr,
1512 &lustre_attr_grant_compat_disable.attr,
1513 &lustre_attr_instance.attr,
1514 &lustre_attr_recovery_time_hard.attr,
1515 &lustre_attr_recovery_time_soft.attr,
1516 &lustre_attr_ir_factor.attr,
1517 &lustre_attr_num_exports.attr,
1518 &lustre_attr_grant_check_threshold.attr,
1519 &lustre_attr_identity_expire.attr,
1520 &lustre_attr_identity_acquire_expire.attr,
1521 &lustre_attr_identity_upcall.attr,
1522 &lustre_attr_identity_flush.attr,
1523 &lustre_attr_evict_tgt_nids.attr,
1524 &lustre_attr_enable_chprojid_gid.attr,
1525 &lustre_attr_enable_dir_migration.attr,
1526 &lustre_attr_enable_dir_restripe.attr,
1527 &lustre_attr_enable_dir_auto_split.attr,
1528 &lustre_attr_enable_parallel_rename_dir.attr,
1529 &lustre_attr_enable_parallel_rename_file.attr,
1530 &lustre_attr_enable_remote_dir.attr,
1531 &lustre_attr_enable_remote_dir_gid.attr,
1532 &lustre_attr_enable_remote_rename.attr,
1533 &lustre_attr_enable_striped_dir.attr,
1534 &lustre_attr_commit_on_sharing.attr,
1535 &lustre_attr_local_recovery.attr,
1536 &lustre_attr_async_commit_count.attr,
1537 &lustre_attr_sync_count.attr,
1538 &lustre_attr_dom_lock.attr,
1539 &lustre_attr_dom_read_open.attr,
1540 &lustre_attr_enable_strict_som.attr,
1541 &lustre_attr_migrate_hsm_allowed.attr,
1542 &lustre_attr_hsm_control.attr,
1543 &lustre_attr_job_cleanup_interval.attr,
1544 &lustre_attr_readonly.attr,
1545 &lustre_attr_dir_split_count.attr,
1546 &lustre_attr_dir_split_delta.attr,
1547 &lustre_attr_dir_restripe_nsonly.attr,
1548 &lustre_attr_checksum_t10pi_enforce.attr,
1549 &lustre_attr_enable_remote_subdir_mount.attr,
1553 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1554 { .name = "recovery_status",
1555 .fops = &mdt_recovery_status_fops },
1556 { .name = "identity_info",
1557 .fops = &mdt_identity_info_fops },
1558 { .name = "site_stats",
1559 .fops = &mdt_site_stats_fops },
1560 { .name = "evict_client",
1561 .fops = &mdt_mds_evict_client_fops },
1562 { .name = "checksum_dump",
1563 .fops = &mdt_checksum_dump_fops },
1564 { .name = "hash_stats",
1565 .fops = &mdt_hash_fops },
1566 { .name = "root_squash",
1567 .fops = &mdt_root_squash_fops },
1568 { .name = "nosquash_nids",
1569 .fops = &mdt_nosquash_nids_fops },
1570 { .name = "checksum_type",
1571 .fops = &mdt_checksum_type_fops },
1576 lprocfs_mdt_print_open_files(struct obd_export *exp, void *v)
1578 struct seq_file *seq = v;
1580 if (exp->exp_lock_hash != NULL) {
1581 struct mdt_export_data *med = &exp->exp_mdt_data;
1582 struct mdt_file_data *mfd;
1584 spin_lock(&med->med_open_lock);
1585 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1586 seq_printf(seq, DFID"\n",
1587 PFID(mdt_object_fid(mfd->mfd_object)));
1589 spin_unlock(&med->med_open_lock);
1595 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1597 struct nid_stat *stats = seq->private;
1599 return obd_nid_export_for_each(stats->nid_obd, &stats->nid,
1600 lprocfs_mdt_print_open_files, seq);
1603 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1605 struct seq_file *seq;
1608 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1612 seq = file->private_data;
1613 seq->private = PDE_DATA(inode);
1618 void mdt_counter_incr(struct ptlrpc_request *req, int opcode, long amount)
1620 struct obd_export *exp = req->rq_export;
1622 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1623 lprocfs_counter_add(exp->exp_obd->obd_md_stats,
1624 opcode + LPROC_MD_LAST_OPC, amount);
1625 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1626 lprocfs_counter_add(exp->exp_nid_stats->nid_stats, opcode,
1628 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1629 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1630 lprocfs_job_stats_log(exp->exp_obd,
1631 lustre_msg_get_jobid(req->rq_reqmsg),
1635 static const char * const mdt_stats[] = {
1636 [LPROC_MDT_OPEN] = "open",
1637 [LPROC_MDT_CLOSE] = "close",
1638 [LPROC_MDT_MKNOD] = "mknod",
1639 [LPROC_MDT_LINK] = "link",
1640 [LPROC_MDT_UNLINK] = "unlink",
1641 [LPROC_MDT_MKDIR] = "mkdir",
1642 [LPROC_MDT_RMDIR] = "rmdir",
1643 [LPROC_MDT_RENAME] = "rename",
1644 [LPROC_MDT_GETATTR] = "getattr",
1645 [LPROC_MDT_SETATTR] = "setattr",
1646 [LPROC_MDT_GETXATTR] = "getxattr",
1647 [LPROC_MDT_SETXATTR] = "setxattr",
1648 [LPROC_MDT_STATFS] = "statfs",
1649 [LPROC_MDT_SYNC] = "sync",
1650 [LPROC_MDT_RENAME_SAMEDIR] = "samedir_rename",
1651 [LPROC_MDT_RENAME_PAR_FILE] = "parallel_rename_file",
1652 [LPROC_MDT_RENAME_PAR_DIR] = "parallel_rename_dir",
1653 [LPROC_MDT_RENAME_CROSSDIR] = "crossdir_rename",
1654 [LPROC_MDT_IO_READ_BYTES] = "read_bytes",
1655 [LPROC_MDT_IO_WRITE_BYTES] = "write_bytes",
1656 [LPROC_MDT_IO_READ] = "read",
1657 [LPROC_MDT_IO_WRITE] = "write",
1658 [LPROC_MDT_IO_PUNCH] = "punch",
1659 [LPROC_MDT_MIGRATE] = "migrate",
1660 [LPROC_MDT_FALLOCATE] = "fallocate",
1663 void mdt_stats_counter_init(struct lprocfs_stats *stats, unsigned int offset)
1665 int array_size = ARRAY_SIZE(mdt_stats);
1666 int oidx; /* obd_md_stats index */
1667 int midx; /* mdt_stats index */
1669 LASSERT(stats && stats->ls_num >= offset + array_size);
1671 for (midx = 0; midx < array_size; midx++) {
1672 oidx = midx + offset;
1673 if (midx == LPROC_MDT_IO_READ_BYTES ||
1674 midx == LPROC_MDT_IO_WRITE_BYTES)
1675 lprocfs_counter_init(stats, oidx,
1676 LPROCFS_TYPE_BYTES_FULL,
1679 lprocfs_counter_init(stats, oidx, LPROCFS_TYPE_LATENCY,
1684 int mdt_tunables_init(struct mdt_device *mdt, const char *name)
1686 struct obd_device *obd = mdt2obd_dev(mdt);
1690 LASSERT(name != NULL);
1692 obd->obd_ktype.default_attrs = mdt_attrs;
1693 obd->obd_vars = lprocfs_mdt_obd_vars;
1694 rc = lprocfs_obd_setup(obd, true);
1696 CERROR("%s: cannot create proc entries: rc = %d\n",
1697 mdt_obd_name(mdt), rc);
1701 rc = tgt_tunables_init(&mdt->mdt_lut);
1703 CERROR("%s: failed to init target tunables: rc = %d\n",
1704 mdt_obd_name(mdt), rc);
1708 rc = hsm_cdt_tunables_init(mdt);
1710 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1711 mdt_obd_name(mdt), rc);
1715 obd->obd_proc_exports_entry = proc_mkdir("exports",
1716 obd->obd_proc_entry);
1717 if (obd->obd_proc_exports_entry)
1718 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1719 obd, &mdt_nid_stats_clear_fops);
1721 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1725 /* add additional MDT md_stats after the default ones */
1726 mdt_stats_counter_init(obd->obd_md_stats, LPROC_MD_LAST_OPC);
1727 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1728 mdt_stats_counter_init);
1730 rc = lproc_mdt_attach_rename_seqstat(mdt);
1732 CERROR("%s: MDT can not create rename stats rc = %d\n",
1733 mdt_obd_name(mdt), rc);
1738 void mdt_tunables_fini(struct mdt_device *mdt)
1740 struct obd_device *obd = mdt2obd_dev(mdt);
1742 if (obd->obd_proc_exports_entry != NULL) {
1743 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1744 obd->obd_proc_exports_entry = NULL;
1747 lprocfs_free_per_client_stats(obd);
1748 /* hsm_cdt_tunables is disabled earlier than this to avoid
1749 * coordinator restart.
1751 hsm_cdt_tunables_fini(mdt);
1752 tgt_tunables_fini(&mdt->mdt_lut);
1753 lprocfs_obd_cleanup(obd);
1754 lprocfs_free_md_stats(obd);
1755 lprocfs_free_obd_stats(obd);
1756 lprocfs_job_stats_fini(obd);