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, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/mdt/mdt_lproc.c
34 * Author: Lai Siyao <lsy@clusterfs.com>
35 * Author: Fan Yong <fanyong@clusterfs.com>
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <linux/version.h>
41 #include <asm/statfs.h>
43 #include <linux/module.h>
44 #include <lnet/nidstr.h>
45 /* LUSTRE_VERSION_CODE */
46 #include <lustre_ver.h>
48 * struct OBD_{ALLOC,FREE}*()
51 #include <obd_support.h>
52 /* struct obd_export */
53 #include <lustre_export.h>
54 /* struct obd_device */
56 #include <obd_class.h>
57 #include <lustre_mds.h>
58 #include <lprocfs_status.h>
59 #include "mdt_internal.h"
62 * The rename stats output would be YAML formats, like
64 * - snapshot_time: 1234567890.123456
66 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
67 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
68 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
70 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
71 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
72 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
74 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
75 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
76 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
79 #define pct(a, b) (b ? a * 100 / b : 0)
81 static void display_rename_stats(struct seq_file *seq, char *name,
82 struct obd_histogram *hist)
84 unsigned long tot, t, cum = 0;
87 tot = lprocfs_oh_sum(hist);
89 seq_printf(seq, "- %-15s\n", name);
90 /* dir size start from 4K, start i from 10(2^10) here */
91 for (i = 0; i < OBD_HIST_MAX; i++) {
92 t = 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: %3lu, cum_pct: %3lu }\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 struct timespec64 now;
117 /* this sampling races with updates */
118 ktime_get_real_ts64(&now);
119 seq_printf(seq, "rename_stats:\n");
120 seq_printf(seq, "- %-15s %llu.%9lu\n", "snapshot_time:",
121 (s64)now.tv_sec, now.tv_nsec);
123 display_rename_stats(seq, "same_dir",
124 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
125 display_rename_stats(seq, "crossdir_src",
126 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
127 display_rename_stats(seq, "crossdir_tgt",
128 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
133 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
135 struct mdt_device *mdt = seq->private;
137 rename_stats_show(seq, &mdt->mdt_rename_stats);
143 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
144 size_t len, loff_t *off)
146 struct seq_file *seq = file->private_data;
147 struct mdt_device *mdt = seq->private;
150 for (i = 0; i < RENAME_LAST; i++)
151 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
155 LPROC_SEQ_FOPS(mdt_rename_stats);
157 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
161 for (i = 0; i < RENAME_LAST; i++)
162 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
164 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
165 &mdt_rename_stats_fops, mdt);
168 void mdt_rename_counter_tally(struct mdt_thread_info *info,
169 struct mdt_device *mdt,
170 struct ptlrpc_request *req,
171 struct mdt_object *src,
172 struct mdt_object *tgt)
174 struct md_attr *ma = &info->mti_attr;
175 struct rename_stats *rstats = &mdt->mdt_rename_stats;
178 ma->ma_need = MA_INODE;
180 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
182 CERROR("%s: "DFID" attr_get, rc = %d\n",
183 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
188 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
189 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
190 (unsigned int)ma->ma_attr.la_size);
194 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
195 lprocfs_oh_tally_log2(&rstats->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->hist[RENAME_CROSSDIR_TGT_SIZE],
208 (unsigned int)ma->ma_attr.la_size);
211 static int mdt_identity_expire_seq_show(struct seq_file *m, void *data)
213 struct obd_device *obd = m->private;
214 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
216 seq_printf(m, "%u\n", mdt->mdt_identity_cache->uc_entry_expire);
221 mdt_identity_expire_seq_write(struct file *file, const char __user *buffer,
222 size_t count, loff_t *off)
224 struct seq_file *m = file->private_data;
225 struct obd_device *obd = m->private;
226 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
230 rc = lprocfs_str_to_s64(buffer, count, &val);
233 if (val < 0 || val > INT_MAX)
236 mdt->mdt_identity_cache->uc_entry_expire = val;
240 LPROC_SEQ_FOPS(mdt_identity_expire);
242 static int mdt_identity_acquire_expire_seq_show(struct seq_file *m, void *data)
244 struct obd_device *obd = m->private;
245 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
247 seq_printf(m, "%u\n", mdt->mdt_identity_cache->uc_acquire_expire);
252 mdt_identity_acquire_expire_seq_write(struct file *file,
253 const char __user *buffer,
254 size_t count, loff_t *off)
256 struct seq_file *m = file->private_data;
257 struct obd_device *obd = m->private;
258 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
262 rc = lprocfs_str_to_s64(buffer, count, &val);
265 if (val < 0 || val > INT_MAX)
268 mdt->mdt_identity_cache->uc_acquire_expire = val;
272 LPROC_SEQ_FOPS(mdt_identity_acquire_expire);
274 static int mdt_identity_upcall_seq_show(struct seq_file *m, void *data)
276 struct obd_device *obd = m->private;
277 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
278 struct upcall_cache *hash = mdt->mdt_identity_cache;
280 down_read(&hash->uc_upcall_rwsem);
281 seq_printf(m, "%s\n", hash->uc_upcall);
282 up_read(&hash->uc_upcall_rwsem);
287 mdt_identity_upcall_seq_write(struct file *file, const char __user *buffer,
288 size_t count, loff_t *off)
290 struct seq_file *m = file->private_data;
291 struct obd_device *obd = m->private;
292 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
293 struct upcall_cache *hash = mdt->mdt_identity_cache;
297 if (count >= UC_CACHE_UPCALL_MAXPATH) {
298 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
301 OBD_ALLOC(kernbuf, count + 1);
303 GOTO(failed, rc = -ENOMEM);
304 if (copy_from_user(kernbuf, buffer, count))
305 GOTO(failed, rc = -EFAULT);
307 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
308 down_write(&hash->uc_upcall_rwsem);
309 sscanf(kernbuf, "%s", hash->uc_upcall);
310 up_write(&hash->uc_upcall_rwsem);
312 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
313 CWARN("%s: write to upcall name %s\n",
314 mdt_obd_name(mdt), hash->uc_upcall);
316 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
317 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
318 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
320 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
322 OBD_FREE(kernbuf, count + 1);
327 OBD_FREE(kernbuf, count + 1);
330 LPROC_SEQ_FOPS(mdt_identity_upcall);
333 lprocfs_identity_flush_seq_write(struct file *file, const char __user *buffer,
334 size_t count, void *data)
336 struct seq_file *m = file->private_data;
337 struct obd_device *obd = m->private;
338 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
342 rc = lprocfs_str_to_s64(buffer, count, &uid);
345 if (uid < INT_MIN || uid > INT_MAX)
348 mdt_flush_identity(mdt->mdt_identity_cache, uid);
351 LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_flush);
354 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
355 size_t count, void *data)
357 struct seq_file *m = file->private_data;
358 struct obd_device *obd = m->private;
359 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
360 struct identity_downcall_data *param;
361 int size = sizeof(*param), rc, checked = 0;
365 CERROR("%s: invalid data count = %lu, size = %d\n",
366 mdt_obd_name(mdt), (unsigned long) count, size);
370 OBD_ALLOC(param, size);
374 if (copy_from_user(param, buffer, size)) {
375 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
376 GOTO(out, rc = -EFAULT);
381 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
382 CERROR("%s: MDS identity downcall bad params\n",
384 GOTO(out, rc = -EINVAL);
387 if (param->idd_nperms > N_PERMS_MAX) {
388 CERROR("%s: perm count %d more than maximum %d\n",
389 mdt_obd_name(mdt), param->idd_nperms,
391 GOTO(out, rc = -EINVAL);
394 if (param->idd_ngroups > NGROUPS_MAX) {
395 CERROR("%s: group count %d more than maximum %d\n",
396 mdt_obd_name(mdt), param->idd_ngroups,
398 GOTO(out, rc = -EINVAL);
401 if (param->idd_ngroups) {
402 rc = param->idd_ngroups; /* save idd_ngroups */
403 OBD_FREE(param, size);
404 size = offsetof(struct identity_downcall_data,
410 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
411 param->idd_uid, param);
415 OBD_FREE(param, size);
417 return rc ? rc : count;
419 LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_info);
421 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
423 struct obd_device *obd = m->private;
424 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
426 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
428 LPROC_SEQ_FOPS_RO(mdt_site_stats);
430 #define BUFLEN (UUID_MAX + 4)
433 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
434 size_t count, loff_t *off)
436 struct seq_file *m = file->private_data;
437 struct obd_device *obd = m->private;
438 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
443 OBD_ALLOC(kbuf, BUFLEN);
448 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
449 * bytes into kbuf, to ensure that the string is NUL-terminated.
450 * UUID_MAX should include a trailing NUL already.
452 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
453 GOTO(out, rc = -EFAULT);
454 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
456 if (strncmp(tmpbuf, "nid:", 4) != 0) {
457 count = lprocfs_evict_client_seq_write(file, buf, count, off);
461 if (mdt->mdt_opts.mo_evict_tgt_nids) {
462 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
463 sizeof(KEY_EVICT_BY_NID),
465 strlen(tmpbuf + 4) + 1,
468 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
472 /* See the comments in function lprocfs_wr_evict_client()
473 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
474 class_incref(obd, __func__, current);
475 obd_export_evict_by_nid(obd, tmpbuf + 4);
476 class_decref(obd, __func__, current);
480 OBD_FREE(kbuf, BUFLEN);
481 return rc < 0 ? rc : count;
486 static int mdt_evict_tgt_nids_seq_show(struct seq_file *m, void *data)
488 struct obd_device *obd = m->private;
489 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
491 seq_printf(m, "%u\n", mdt->mdt_opts.mo_evict_tgt_nids);
496 mdt_evict_tgt_nids_seq_write(struct file *file, const char __user *buffer,
497 size_t count, loff_t *off)
499 struct seq_file *m = file->private_data;
500 struct obd_device *obd = m->private;
501 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
505 rc = lprocfs_str_to_s64(buffer, count, &val);
508 mdt->mdt_opts.mo_evict_tgt_nids = !!val;
511 LPROC_SEQ_FOPS(mdt_evict_tgt_nids);
513 static int mdt_cos_seq_show(struct seq_file *m, void *data)
515 struct obd_device *obd = m->private;
516 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
518 seq_printf(m, "%u\n", mdt_cos_is_enabled(mdt));
523 mdt_cos_seq_write(struct file *file, const char __user *buffer,
524 size_t count, loff_t *off)
526 struct seq_file *m = file->private_data;
527 struct obd_device *obd = m->private;
528 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
532 rc = lprocfs_str_to_s64(buffer, count, &val);
535 if (val < INT_MIN || val > INT_MAX)
538 mdt_enable_cos(mdt, val);
541 LPROC_SEQ_FOPS(mdt_cos);
543 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
545 struct obd_device *obd = m->private;
546 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
547 struct root_squash_info *squash = &mdt->mdt_squash;
549 seq_printf(m, "%u:%u\n", squash->rsi_uid,
555 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
556 size_t count, loff_t *off)
558 struct seq_file *m = file->private_data;
559 struct obd_device *obd = m->private;
560 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
561 struct root_squash_info *squash = &mdt->mdt_squash;
563 return lprocfs_wr_root_squash(buffer, count, squash,
566 LPROC_SEQ_FOPS(mdt_root_squash);
568 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
570 struct obd_device *obd = m->private;
571 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
572 struct root_squash_info *squash = &mdt->mdt_squash;
575 down_read(&squash->rsi_sem);
576 if (!list_empty(&squash->rsi_nosquash_nids)) {
577 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
578 &squash->rsi_nosquash_nids);
582 seq_puts(m, "NONE\n");
583 up_read(&squash->rsi_sem);
589 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
590 size_t count, loff_t *off)
592 struct seq_file *m = file->private_data;
593 struct obd_device *obd = m->private;
594 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
595 struct root_squash_info *squash = &mdt->mdt_squash;
597 return lprocfs_wr_nosquash_nids(buffer, count, squash,
600 LPROC_SEQ_FOPS(mdt_nosquash_nids);
602 static int mdt_enable_remote_dir_seq_show(struct seq_file *m, void *data)
604 struct obd_device *obd = m->private;
605 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
607 seq_printf(m, "%u\n", mdt->mdt_enable_remote_dir);
612 mdt_enable_remote_dir_seq_write(struct file *file, const char __user *buffer,
613 size_t count, loff_t *off)
615 struct seq_file *m = file->private_data;
616 struct obd_device *obd = m->private;
617 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
621 rc = lprocfs_str_to_s64(buffer, count, &val);
625 if (val > 1 || val < 0)
628 mdt->mdt_enable_remote_dir = val;
631 LPROC_SEQ_FOPS(mdt_enable_remote_dir);
633 static int mdt_enable_remote_dir_gid_seq_show(struct seq_file *m, void *data)
635 struct obd_device *obd = m->private;
636 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
638 seq_printf(m, "%d\n",
639 (int)mdt->mdt_enable_remote_dir_gid);
644 mdt_enable_remote_dir_gid_seq_write(struct file *file,
645 const char __user *buffer,
646 size_t count, loff_t *off)
648 struct seq_file *m = file->private_data;
649 struct obd_device *obd = m->private;
650 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
654 rc = lprocfs_str_to_s64(buffer, count, &val);
658 mdt->mdt_enable_remote_dir_gid = val;
661 LPROC_SEQ_FOPS(mdt_enable_remote_dir_gid);
664 * Show MDT policy for handling dirty metadata under a lock being cancelled.
666 * \param[in] m seq_file handle
667 * \param[in] data unused for single entry
669 * \retval 0 on success
670 * \retval negative value on error
672 static int mdt_slc_seq_show(struct seq_file *m, void *data)
674 struct obd_device *obd = m->private;
675 struct lu_target *tgt = obd->u.obt.obt_lut;
676 char *slc_states[] = {"never", "blocking", "always" };
678 seq_printf(m, "%s\n", slc_states[tgt->lut_sync_lock_cancel]);
681 LPROC_SEQ_FOPS_RO(mdt_slc);
684 * Show MDT async commit count.
686 * \param[in] m seq_file handle
687 * \param[in] data unused for single entry
689 * \retval 0 on success
690 * \retval negative value on error
692 static int mdt_async_commit_count_seq_show(struct seq_file *m, void *data)
694 struct obd_device *obd = m->private;
695 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
697 seq_printf(m, "%d\n", atomic_read(&mdt->mdt_async_commit_count));
702 mdt_async_commit_count_seq_write(struct file *file, const char __user *buffer,
703 size_t count, loff_t *off)
705 struct seq_file *m = file->private_data;
706 struct obd_device *obd = m->private;
707 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
711 rc = lprocfs_str_to_s64(buffer, count, &val);
715 if (val < INT_MIN || val > INT_MAX)
718 atomic_set(&mdt->mdt_async_commit_count, val);
722 LPROC_SEQ_FOPS(mdt_async_commit_count);
725 * Show MDT sync count.
727 * \param[in] m seq_file handle
728 * \param[in] data unused for single entry
730 * \retval 0 on success
731 * \retval negative value on error
733 static int mdt_sync_count_seq_show(struct seq_file *m, void *data)
735 struct obd_device *obd = m->private;
736 struct lu_target *tgt = obd->u.obt.obt_lut;
738 seq_printf(m, "%d\n", atomic_read(&tgt->lut_sync_count));
743 mdt_sync_count_seq_write(struct file *file, const char __user *buffer,
744 size_t count, loff_t *off)
746 struct seq_file *m = file->private_data;
747 struct obd_device *obd = m->private;
748 struct lu_target *tgt = obd->u.obt.obt_lut;
752 rc = lprocfs_str_to_s64(buffer, count, &val);
756 if (val < INT_MIN || val > INT_MAX)
759 atomic_set(&tgt->lut_sync_count, val);
763 LPROC_SEQ_FOPS(mdt_sync_count);
765 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
766 LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports);
767 LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance);
768 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
769 LPROC_SEQ_FOPS_WO_TYPE(mdt, mds_evict_client);
770 LPROC_SEQ_FOPS_RW_TYPE(mdt, job_interval);
771 LPROC_SEQ_FOPS_RW_TYPE(mdt, ir_factor);
772 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
773 LPROC_SEQ_FOPS(mdt_hsm_cdt_control);
775 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_hard);
776 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_soft);
778 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
779 { .name = "recovery_status",
780 .fops = &mdt_recovery_status_fops },
781 { .name = "num_exports",
782 .fops = &mdt_num_exports_fops },
783 { .name = "identity_expire",
784 .fops = &mdt_identity_expire_fops },
785 { .name = "identity_acquire_expire",
786 .fops = &mdt_identity_acquire_expire_fops },
787 { .name = "identity_upcall",
788 .fops = &mdt_identity_upcall_fops },
789 { .name = "identity_flush",
790 .fops = &mdt_identity_flush_fops },
791 { .name = "identity_info",
792 .fops = &mdt_identity_info_fops },
793 { .name = "site_stats",
794 .fops = &mdt_site_stats_fops },
795 { .name = "evict_client",
796 .fops = &mdt_mds_evict_client_fops },
797 { .name = "evict_tgt_nids",
798 .fops = &mdt_evict_tgt_nids_fops },
799 { .name = "hash_stats",
800 .fops = &mdt_hash_fops },
801 { .name = "commit_on_sharing",
802 .fops = &mdt_cos_fops },
803 { .name = "root_squash",
804 .fops = &mdt_root_squash_fops },
805 { .name = "nosquash_nids",
806 .fops = &mdt_nosquash_nids_fops },
807 { .name = "instance",
808 .fops = &mdt_target_instance_fops },
809 { .name = "ir_factor",
810 .fops = &mdt_ir_factor_fops },
811 { .name = "job_cleanup_interval",
812 .fops = &mdt_job_interval_fops },
813 { .name = "enable_remote_dir",
814 .fops = &mdt_enable_remote_dir_fops },
815 { .name = "enable_remote_dir_gid",
816 .fops = &mdt_enable_remote_dir_gid_fops },
817 { .name = "hsm_control",
818 .fops = &mdt_hsm_cdt_control_fops },
819 { .name = "recovery_time_hard",
820 .fops = &mdt_recovery_time_hard_fops },
821 { .name = "recovery_time_soft",
822 .fops = &mdt_recovery_time_soft_fops },
823 { .name = "sync_lock_cancel",
824 .fops = &mdt_slc_fops },
825 { .name = "async_commit_count",
826 .fops = &mdt_async_commit_count_fops },
827 { .name = "sync_count",
828 .fops = &mdt_sync_count_fops },
833 lprocfs_mdt_print_open_files(struct cfs_hash *hs, struct cfs_hash_bd *bd,
834 struct hlist_node *hnode, void *v)
836 struct obd_export *exp = cfs_hash_object(hs, hnode);
837 struct seq_file *seq = v;
839 if (exp->exp_lock_hash != NULL) {
840 struct mdt_export_data *med = &exp->exp_mdt_data;
841 struct mdt_file_data *mfd;
843 spin_lock(&med->med_open_lock);
844 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
845 seq_printf(seq, DFID"\n",
846 PFID(mdt_object_fid(mfd->mfd_object)));
848 spin_unlock(&med->med_open_lock);
854 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
856 struct nid_stat *stats = seq->private;
857 struct obd_device *obd = stats->nid_obd;
859 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
860 lprocfs_mdt_print_open_files, seq);
865 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
867 struct seq_file *seq;
870 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
874 seq = file->private_data;
875 seq->private = PDE_DATA(inode);
880 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
882 struct obd_export *exp = req->rq_export;
884 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
885 lprocfs_counter_incr(exp->exp_obd->obd_md_stats, opcode);
886 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
887 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
888 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
889 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
890 lprocfs_job_stats_log(exp->exp_obd,
891 lustre_msg_get_jobid(req->rq_reqmsg),
895 void mdt_stats_counter_init(struct lprocfs_stats *stats)
897 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
898 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
899 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
900 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
901 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
902 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
903 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
904 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
905 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
906 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
907 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
908 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
909 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
910 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
911 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
912 "samedir_rename", "reqs");
913 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
914 "crossdir_rename", "reqs");
917 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
919 struct obd_device *obd = mdt2obd_dev(mdt);
923 LASSERT(name != NULL);
925 obd->obd_vars = lprocfs_mdt_obd_vars;
926 rc = lprocfs_obd_setup(obd, true);
928 CERROR("%s: cannot create proc entries: rc = %d\n",
929 mdt_obd_name(mdt), rc);
933 rc = hsm_cdt_procfs_init(mdt);
935 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
936 mdt_obd_name(mdt), rc);
940 obd->obd_proc_exports_entry = proc_mkdir("exports",
941 obd->obd_proc_entry);
942 if (obd->obd_proc_exports_entry)
943 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
944 obd, &mdt_nid_stats_clear_fops);
945 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
948 mdt_stats_counter_init(obd->obd_md_stats);
950 rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
951 mdt_stats_counter_init);
953 rc = lproc_mdt_attach_rename_seqstat(mdt);
955 CERROR("%s: MDT can not create rename stats rc = %d\n",
956 mdt_obd_name(mdt), rc);
961 void mdt_procfs_fini(struct mdt_device *mdt)
963 struct obd_device *obd = mdt2obd_dev(mdt);
965 if (obd->obd_proc_exports_entry != NULL) {
966 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
967 obd->obd_proc_exports_entry = NULL;
970 lprocfs_free_per_client_stats(obd);
971 hsm_cdt_procfs_fini(mdt);
972 lprocfs_obd_cleanup(obd);
973 lprocfs_free_md_stats(obd);
974 lprocfs_free_obd_stats(obd);
975 lprocfs_job_stats_fini(obd);