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/
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 <uapi/linux/lnet/nidstr.h>
45 /* LUSTRE_VERSION_CODE */
46 #include <uapi/linux/lustre/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 static void display_rename_stats(struct seq_file *seq, char *name,
80 struct obd_histogram *hist)
82 unsigned long tot, t, cum = 0;
85 tot = lprocfs_oh_sum(hist);
87 seq_printf(seq, "- %-15s\n", name);
88 /* dir size start from 4K, start i from 10(2^10) here */
89 for (i = 0; i < OBD_HIST_MAX; i++) {
90 t = hist->oh_buckets[i];
96 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
98 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
100 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
102 seq_printf(seq, " { sample: %3lu, pct: %3u, cum_pct: %3u }\n",
103 t, pct(t, tot), pct(cum, tot));
110 static void rename_stats_show(struct seq_file *seq,
111 struct rename_stats *rename_stats)
113 struct timespec64 now;
115 /* this sampling races with updates */
116 ktime_get_real_ts64(&now);
117 seq_printf(seq, "rename_stats:\n");
118 seq_printf(seq, "- %-15s %llu.%9lu\n", "snapshot_time:",
119 (s64)now.tv_sec, now.tv_nsec);
121 display_rename_stats(seq, "same_dir",
122 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
123 display_rename_stats(seq, "crossdir_src",
124 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
125 display_rename_stats(seq, "crossdir_tgt",
126 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
129 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
131 struct mdt_device *mdt = seq->private;
133 rename_stats_show(seq, &mdt->mdt_rename_stats);
139 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
140 size_t len, loff_t *off)
142 struct seq_file *seq = file->private_data;
143 struct mdt_device *mdt = seq->private;
146 for (i = 0; i < RENAME_LAST; i++)
147 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
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.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,
168 struct mdt_object *tgt)
170 struct md_attr *ma = &info->mti_attr;
171 struct rename_stats *rstats = &mdt->mdt_rename_stats;
174 ma->ma_need = MA_INODE;
176 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
178 CERROR("%s: "DFID" attr_get, rc = %d\n",
179 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
184 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
185 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
186 (unsigned int)ma->ma_attr.la_size);
190 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
191 lprocfs_oh_tally_log2(&rstats->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->hist[RENAME_CROSSDIR_TGT_SIZE],
204 (unsigned int)ma->ma_attr.la_size);
207 static int mdt_identity_expire_seq_show(struct seq_file *m, void *data)
209 struct obd_device *obd = m->private;
210 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
212 seq_printf(m, "%lld\n", mdt->mdt_identity_cache->uc_entry_expire);
217 mdt_identity_expire_seq_write(struct file *file, const char __user *buffer,
218 size_t count, loff_t *off)
220 struct seq_file *m = file->private_data;
221 struct obd_device *obd = m->private;
222 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
226 rc = kstrtoll_from_user(buffer, count, 0, &val);
233 mdt->mdt_identity_cache->uc_entry_expire = val;
237 LPROC_SEQ_FOPS(mdt_identity_expire);
239 static int mdt_identity_acquire_expire_seq_show(struct seq_file *m, void *data)
241 struct obd_device *obd = m->private;
242 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
244 seq_printf(m, "%lld\n", mdt->mdt_identity_cache->uc_acquire_expire);
249 mdt_identity_acquire_expire_seq_write(struct file *file,
250 const char __user *buffer,
251 size_t count, loff_t *off)
253 struct seq_file *m = file->private_data;
254 struct obd_device *obd = m->private;
255 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
259 rc = kstrtoll_from_user(buffer, count, 0, &val);
263 if (val < 0 || val > INT_MAX)
266 mdt->mdt_identity_cache->uc_acquire_expire = val;
270 LPROC_SEQ_FOPS(mdt_identity_acquire_expire);
272 static int mdt_identity_upcall_seq_show(struct seq_file *m, void *data)
274 struct obd_device *obd = m->private;
275 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
276 struct upcall_cache *hash = mdt->mdt_identity_cache;
278 down_read(&hash->uc_upcall_rwsem);
279 seq_printf(m, "%s\n", hash->uc_upcall);
280 up_read(&hash->uc_upcall_rwsem);
285 mdt_identity_upcall_seq_write(struct file *file, const char __user *buffer,
286 size_t count, loff_t *off)
288 struct seq_file *m = file->private_data;
289 struct obd_device *obd = m->private;
290 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
291 struct upcall_cache *hash = mdt->mdt_identity_cache;
295 if (count >= UC_CACHE_UPCALL_MAXPATH) {
296 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
299 OBD_ALLOC(kernbuf, count + 1);
301 GOTO(failed, rc = -ENOMEM);
302 if (copy_from_user(kernbuf, buffer, count))
303 GOTO(failed, rc = -EFAULT);
305 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
306 down_write(&hash->uc_upcall_rwsem);
307 sscanf(kernbuf, "%s", hash->uc_upcall);
308 up_write(&hash->uc_upcall_rwsem);
310 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
311 CWARN("%s: write to upcall name %s\n",
312 mdt_obd_name(mdt), hash->uc_upcall);
314 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
315 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
316 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
318 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
320 OBD_FREE(kernbuf, count + 1);
325 OBD_FREE(kernbuf, count + 1);
328 LPROC_SEQ_FOPS(mdt_identity_upcall);
331 lprocfs_identity_flush_seq_write(struct file *file, const char __user *buffer,
332 size_t count, void *data)
334 struct seq_file *m = file->private_data;
335 struct obd_device *obd = m->private;
336 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
340 rc = kstrtoint_from_user(buffer, count, 0, &uid);
344 mdt_flush_identity(mdt->mdt_identity_cache, uid);
347 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_flush);
350 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
351 size_t count, void *data)
353 struct seq_file *m = file->private_data;
354 struct obd_device *obd = m->private;
355 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
356 struct identity_downcall_data *param;
357 int size = sizeof(*param), rc, checked = 0;
361 CERROR("%s: invalid data count = %lu, size = %d\n",
362 mdt_obd_name(mdt), (unsigned long) count, size);
366 OBD_ALLOC(param, size);
370 if (copy_from_user(param, buffer, size)) {
371 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
372 GOTO(out, rc = -EFAULT);
377 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
378 CERROR("%s: MDS identity downcall bad params\n",
380 GOTO(out, rc = -EINVAL);
383 if (param->idd_nperms > N_PERMS_MAX) {
384 CERROR("%s: perm count %d more than maximum %d\n",
385 mdt_obd_name(mdt), param->idd_nperms,
387 GOTO(out, rc = -EINVAL);
390 if (param->idd_ngroups > NGROUPS_MAX) {
391 CERROR("%s: group count %d more than maximum %d\n",
392 mdt_obd_name(mdt), param->idd_ngroups,
394 GOTO(out, rc = -EINVAL);
397 if (param->idd_ngroups) {
398 rc = param->idd_ngroups; /* save idd_ngroups */
399 OBD_FREE(param, size);
400 size = offsetof(struct identity_downcall_data,
406 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
407 param->idd_uid, param);
411 OBD_FREE(param, size);
413 return rc ? rc : count;
415 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info);
417 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
419 struct obd_device *obd = m->private;
420 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
422 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
424 LPROC_SEQ_FOPS_RO(mdt_site_stats);
426 #define BUFLEN (UUID_MAX + 4)
429 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
430 size_t count, loff_t *off)
432 struct seq_file *m = file->private_data;
433 struct obd_device *obd = m->private;
434 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
439 OBD_ALLOC(kbuf, BUFLEN);
444 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
445 * bytes into kbuf, to ensure that the string is NUL-terminated.
446 * UUID_MAX should include a trailing NUL already.
448 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
449 GOTO(out, rc = -EFAULT);
450 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
452 if (strncmp(tmpbuf, "nid:", 4) != 0) {
453 count = lprocfs_evict_client_seq_write(file, buf, count, off);
457 if (mdt->mdt_opts.mo_evict_tgt_nids) {
458 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
459 sizeof(KEY_EVICT_BY_NID),
461 strlen(tmpbuf + 4) + 1,
464 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
468 /* See the comments in function lprocfs_wr_evict_client()
469 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
470 class_incref(obd, __func__, current);
471 obd_export_evict_by_nid(obd, tmpbuf + 4);
472 class_decref(obd, __func__, current);
476 OBD_FREE(kbuf, BUFLEN);
477 return rc < 0 ? rc : count;
482 static int mdt_evict_tgt_nids_seq_show(struct seq_file *m, void *data)
484 struct obd_device *obd = m->private;
485 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
487 seq_printf(m, "%u\n", mdt->mdt_opts.mo_evict_tgt_nids);
492 mdt_evict_tgt_nids_seq_write(struct file *file, const char __user *buffer,
493 size_t count, loff_t *off)
495 struct seq_file *m = file->private_data;
496 struct obd_device *obd = m->private;
497 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
501 rc = kstrtobool_from_user(buffer, count, &val);
505 mdt->mdt_opts.mo_evict_tgt_nids = val;
508 LPROC_SEQ_FOPS(mdt_evict_tgt_nids);
510 static int mdt_cos_seq_show(struct seq_file *m, void *data)
512 struct obd_device *obd = m->private;
513 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
515 seq_printf(m, "%u\n", mdt_cos_is_enabled(mdt));
520 mdt_cos_seq_write(struct file *file, const char __user *buffer,
521 size_t count, loff_t *off)
523 struct seq_file *m = file->private_data;
524 struct obd_device *obd = m->private;
525 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
529 rc = kstrtobool_from_user(buffer, count, &val);
533 mdt_enable_cos(mdt, val);
536 LPROC_SEQ_FOPS(mdt_cos);
538 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
540 struct obd_device *obd = m->private;
541 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
542 struct root_squash_info *squash = &mdt->mdt_squash;
544 seq_printf(m, "%u:%u\n", squash->rsi_uid,
550 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
551 size_t count, loff_t *off)
553 struct seq_file *m = file->private_data;
554 struct obd_device *obd = m->private;
555 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
556 struct root_squash_info *squash = &mdt->mdt_squash;
558 return lprocfs_wr_root_squash(buffer, count, squash,
561 LPROC_SEQ_FOPS(mdt_root_squash);
563 static int mdt_nosquash_nids_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;
570 down_read(&squash->rsi_sem);
571 if (!list_empty(&squash->rsi_nosquash_nids)) {
572 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
573 &squash->rsi_nosquash_nids);
577 seq_puts(m, "NONE\n");
578 up_read(&squash->rsi_sem);
584 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
585 size_t count, loff_t *off)
587 struct seq_file *m = file->private_data;
588 struct obd_device *obd = m->private;
589 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
590 struct root_squash_info *squash = &mdt->mdt_squash;
592 return lprocfs_wr_nosquash_nids(buffer, count, squash,
595 LPROC_SEQ_FOPS(mdt_nosquash_nids);
597 static int mdt_enable_remote_dir_seq_show(struct seq_file *m, void *data)
599 struct obd_device *obd = m->private;
600 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
602 seq_printf(m, "%u\n", mdt->mdt_enable_remote_dir);
607 mdt_enable_remote_dir_seq_write(struct file *file, const char __user *buffer,
608 size_t count, loff_t *off)
610 struct seq_file *m = file->private_data;
611 struct obd_device *obd = m->private;
612 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
616 rc = kstrtobool_from_user(buffer, count, &val);
620 mdt->mdt_enable_remote_dir = val;
623 LPROC_SEQ_FOPS(mdt_enable_remote_dir);
625 static int mdt_enable_remote_dir_gid_seq_show(struct seq_file *m, void *data)
627 struct obd_device *obd = m->private;
628 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
630 seq_printf(m, "%d\n",
631 (int)mdt->mdt_enable_remote_dir_gid);
636 mdt_enable_remote_dir_gid_seq_write(struct file *file,
637 const char __user *buffer,
638 size_t count, loff_t *off)
640 struct seq_file *m = file->private_data;
641 struct obd_device *obd = m->private;
642 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
646 rc = kstrtoint_from_user(buffer, count, 0, &val);
650 mdt->mdt_enable_remote_dir_gid = val;
653 LPROC_SEQ_FOPS(mdt_enable_remote_dir_gid);
655 static int mdt_enable_striped_dir_seq_show(struct seq_file *m, void *data)
657 struct obd_device *obd = m->private;
658 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
660 seq_printf(m, "%u\n", mdt->mdt_enable_striped_dir);
665 mdt_enable_striped_dir_seq_write(struct file *file, const char __user *buffer,
666 size_t count, loff_t *off)
668 struct seq_file *m = file->private_data;
669 struct obd_device *obd = m->private;
670 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
674 rc = kstrtobool_from_user(buffer, count, &val);
678 mdt->mdt_enable_striped_dir = val;
681 LPROC_SEQ_FOPS(mdt_enable_striped_dir);
683 static int mdt_enable_dir_migration_seq_show(struct seq_file *m, void *data)
685 struct obd_device *obd = m->private;
686 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
688 seq_printf(m, "%u\n", mdt->mdt_enable_dir_migration);
693 mdt_enable_dir_migration_seq_write(struct file *file, const char __user *buffer,
694 size_t count, loff_t *off)
696 struct seq_file *m = file->private_data;
697 struct obd_device *obd = m->private;
698 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
702 rc = kstrtobool_from_user(buffer, count, &val);
706 mdt->mdt_enable_dir_migration = val;
709 LPROC_SEQ_FOPS(mdt_enable_dir_migration);
713 * Show MDT policy for handling dirty metadata under a lock being cancelled.
715 * \param[in] m seq_file handle
716 * \param[in] data unused for single entry
718 * \retval 0 on success
719 * \retval negative value on error
721 static int mdt_slc_seq_show(struct seq_file *m, void *data)
723 struct obd_device *obd = m->private;
724 struct lu_target *tgt = obd->u.obt.obt_lut;
725 char *slc_states[] = {"never", "blocking", "always" };
727 seq_printf(m, "%s\n", slc_states[tgt->lut_sync_lock_cancel]);
730 LPROC_SEQ_FOPS_RO(mdt_slc);
733 * Show MDT async commit count.
735 * \param[in] m seq_file handle
736 * \param[in] data unused for single entry
738 * \retval 0 on success
739 * \retval negative value on error
741 static int mdt_async_commit_count_seq_show(struct seq_file *m, void *data)
743 struct obd_device *obd = m->private;
744 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
746 seq_printf(m, "%d\n", atomic_read(&mdt->mdt_async_commit_count));
751 mdt_async_commit_count_seq_write(struct file *file, const char __user *buffer,
752 size_t count, loff_t *off)
754 struct seq_file *m = file->private_data;
755 struct obd_device *obd = m->private;
756 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
760 rc = kstrtoint_from_user(buffer, count, 0, &val);
764 atomic_set(&mdt->mdt_async_commit_count, val);
768 LPROC_SEQ_FOPS(mdt_async_commit_count);
771 * Show MDT sync count.
773 * \param[in] m seq_file handle
774 * \param[in] data unused for single entry
776 * \retval 0 on success
777 * \retval negative value on error
779 static int mdt_sync_count_seq_show(struct seq_file *m, void *data)
781 struct obd_device *obd = m->private;
782 struct lu_target *tgt = obd->u.obt.obt_lut;
784 seq_printf(m, "%d\n", atomic_read(&tgt->lut_sync_count));
789 mdt_sync_count_seq_write(struct file *file, const char __user *buffer,
790 size_t count, loff_t *off)
792 struct seq_file *m = file->private_data;
793 struct obd_device *obd = m->private;
794 struct lu_target *tgt = obd->u.obt.obt_lut;
798 rc = kstrtoint_from_user(buffer, count, 0, &val);
802 atomic_set(&tgt->lut_sync_count, val);
806 LPROC_SEQ_FOPS(mdt_sync_count);
808 static char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
809 [NO_DOM_LOCK_ON_OPEN] = "never",
810 [TRYLOCK_DOM_ON_OPEN] = "trylock",
811 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
814 /* This must be longer than the longest string above */
815 #define DOM_LOCK_MODES_MAXLEN 16
818 * Show MDT policy for data prefetch on open for DoM files..
820 * \param[in] m seq_file handle
821 * \param[in] data unused
823 * \retval 0 on success
824 * \retval negative value on error
826 static int mdt_dom_lock_seq_show(struct seq_file *m, void *data)
828 struct obd_device *obd = m->private;
829 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
831 seq_printf(m, "%s\n", dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
836 * Change MDT policy for data prefetch on open for DoM files.
838 * This variable defines how DOM lock is taken at open enqueue.
839 * There are three possible modes:
840 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
841 * IO lock with own enqueue.
842 * 2) trylock - DoM lock will be taken only if non-blocked.
843 * 3) always - DoM lock will be taken always even if it is blocking lock.
845 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
846 * is paired with LAYOUT lock when possible.
848 * \param[in] file proc file
849 * \param[in] buffer string which represents policy
850 * \param[in] count \a buffer length
851 * \param[in] off unused for single entry
853 * \retval \a count on success
854 * \retval negative number on error
857 mdt_dom_lock_seq_write(struct file *file, const char __user *buffer,
858 size_t count, loff_t *off)
860 struct seq_file *m = file->private_data;
861 struct obd_device *obd = m->private;
862 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
863 char kernbuf[DOM_LOCK_MODES_MAXLEN];
867 if (count == 0 || count >= sizeof(kernbuf))
870 if (copy_from_user(kernbuf, buffer, count))
874 if (kernbuf[count - 1] == '\n')
875 kernbuf[count - 1] = 0;
877 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
878 if (strcmp(kernbuf, dom_open_lock_modes[i]) == 0) {
884 /* Legacy numeric codes */
886 rc = kstrtoint_from_user(buffer, count, 0, &val);
891 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
894 mdt->mdt_opts.mo_dom_lock = val;
897 LPROC_SEQ_FOPS(mdt_dom_lock);
900 * Show MDT policy for data prefetch on open for DoM files..
902 * \param[in] m seq_file handle
903 * \param[in] data unused
905 * \retval 0 on success
906 * \retval negative value on error
908 static int mdt_dom_read_open_seq_show(struct seq_file *m, void *data)
910 struct obd_device *obd = m->private;
911 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
913 seq_printf(m, "%u\n", !!mdt->mdt_opts.mo_dom_read_open);
918 * Modify MDT policy for data prefetch on open for DoM files.
920 * If enabled then Data-on-MDT file data may be read during open and
921 * returned back in reply. It works only with mo_dom_lock enabled.
923 * \param[in] file proc file
924 * \param[in] buffer string which represents policy
925 * \param[in] count \a buffer length
926 * \param[in] off unused for single entry
928 * \retval \a count on success
929 * \retval negative number on error
932 mdt_dom_read_open_seq_write(struct file *file, const char __user *buffer,
933 size_t count, loff_t *off)
935 struct seq_file *m = file->private_data;
936 struct obd_device *obd = m->private;
937 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
941 rc = kstrtobool_from_user(buffer, count, &val);
945 mdt->mdt_opts.mo_dom_read_open = !!val;
948 LPROC_SEQ_FOPS(mdt_dom_read_open);
950 static int mdt_migrate_hsm_allowed_seq_show(struct seq_file *m, void *data)
952 struct obd_device *obd = m->private;
953 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
955 seq_printf(m, "%u\n", (mdt->mdt_opts.mo_migrate_hsm_allowed != 0));
960 mdt_migrate_hsm_allowed_seq_write(struct file *file, const char __user *buffer,
961 size_t count, loff_t *off)
963 struct seq_file *m = file->private_data;
964 struct obd_device *obd = m->private;
965 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
969 rc = kstrtobool_from_user(buffer, count, &val);
973 mdt->mdt_opts.mo_migrate_hsm_allowed = val;
976 LPROC_SEQ_FOPS(mdt_migrate_hsm_allowed);
978 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
979 LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports);
980 LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance);
981 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
982 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
983 LPROC_SEQ_FOPS_RW_TYPE(mdt, job_interval);
984 LPROC_SEQ_FOPS_RW_TYPE(mdt, ir_factor);
985 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
986 LPROC_SEQ_FOPS(mdt_hsm_cdt_control);
988 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_hard);
989 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_soft);
991 LPROC_SEQ_FOPS_RO(tgt_tot_dirty);
992 LPROC_SEQ_FOPS_RO(tgt_tot_granted);
993 LPROC_SEQ_FOPS_RO(tgt_tot_pending);
994 LPROC_SEQ_FOPS(tgt_grant_compat_disable);
996 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
997 { .name = "tot_dirty",
998 .fops = &tgt_tot_dirty_fops },
999 { .name = "tot_pending",
1000 .fops = &tgt_tot_pending_fops },
1001 { .name = "tot_granted",
1002 .fops = &tgt_tot_granted_fops },
1003 { .name = "grant_compat_disable",
1004 .fops = &tgt_grant_compat_disable_fops },
1005 { .name = "recovery_status",
1006 .fops = &mdt_recovery_status_fops },
1007 { .name = "num_exports",
1008 .fops = &mdt_num_exports_fops },
1009 { .name = "identity_expire",
1010 .fops = &mdt_identity_expire_fops },
1011 { .name = "identity_acquire_expire",
1012 .fops = &mdt_identity_acquire_expire_fops },
1013 { .name = "identity_upcall",
1014 .fops = &mdt_identity_upcall_fops },
1015 { .name = "identity_flush",
1016 .fops = &mdt_identity_flush_fops },
1017 { .name = "identity_info",
1018 .fops = &mdt_identity_info_fops },
1019 { .name = "site_stats",
1020 .fops = &mdt_site_stats_fops },
1021 { .name = "evict_client",
1022 .fops = &mdt_mds_evict_client_fops },
1023 { .name = "evict_tgt_nids",
1024 .fops = &mdt_evict_tgt_nids_fops },
1025 { .name = "hash_stats",
1026 .fops = &mdt_hash_fops },
1027 { .name = "commit_on_sharing",
1028 .fops = &mdt_cos_fops },
1029 { .name = "root_squash",
1030 .fops = &mdt_root_squash_fops },
1031 { .name = "nosquash_nids",
1032 .fops = &mdt_nosquash_nids_fops },
1033 { .name = "instance",
1034 .fops = &mdt_target_instance_fops },
1035 { .name = "ir_factor",
1036 .fops = &mdt_ir_factor_fops },
1037 { .name = "job_cleanup_interval",
1038 .fops = &mdt_job_interval_fops },
1039 { .name = "enable_remote_dir",
1040 .fops = &mdt_enable_remote_dir_fops },
1041 { .name = "enable_remote_dir_gid",
1042 .fops = &mdt_enable_remote_dir_gid_fops },
1043 { .name = "enable_striped_dir",
1044 .fops = &mdt_enable_striped_dir_fops },
1045 { .name = "enable_dir_migration",
1046 .fops = &mdt_enable_dir_migration_fops },
1047 { .name = "hsm_control",
1048 .fops = &mdt_hsm_cdt_control_fops },
1049 { .name = "recovery_time_hard",
1050 .fops = &mdt_recovery_time_hard_fops },
1051 { .name = "recovery_time_soft",
1052 .fops = &mdt_recovery_time_soft_fops },
1053 { .name = "sync_lock_cancel",
1054 .fops = &mdt_slc_fops },
1055 { .name = "async_commit_count",
1056 .fops = &mdt_async_commit_count_fops },
1057 { .name = "sync_count",
1058 .fops = &mdt_sync_count_fops },
1059 { .name = "dom_lock",
1060 .fops = &mdt_dom_lock_fops },
1061 { .name = "dom_read_open",
1062 .fops = &mdt_dom_read_open_fops },
1063 { .name = "migrate_hsm_allowed",
1064 .fops = &mdt_migrate_hsm_allowed_fops },
1069 lprocfs_mdt_print_open_files(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1070 struct hlist_node *hnode, void *v)
1072 struct obd_export *exp = cfs_hash_object(hs, hnode);
1073 struct seq_file *seq = v;
1075 if (exp->exp_lock_hash != NULL) {
1076 struct mdt_export_data *med = &exp->exp_mdt_data;
1077 struct mdt_file_data *mfd;
1079 spin_lock(&med->med_open_lock);
1080 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1081 seq_printf(seq, DFID"\n",
1082 PFID(mdt_object_fid(mfd->mfd_object)));
1084 spin_unlock(&med->med_open_lock);
1090 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1092 struct nid_stat *stats = seq->private;
1093 struct obd_device *obd = stats->nid_obd;
1095 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
1096 lprocfs_mdt_print_open_files, seq);
1101 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1103 struct seq_file *seq;
1106 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1110 seq = file->private_data;
1111 seq->private = PDE_DATA(inode);
1116 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1118 struct obd_export *exp = req->rq_export;
1120 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1121 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1122 opcode + LPROC_MD_LAST_OPC);
1123 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1124 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1125 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1126 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1127 lprocfs_job_stats_log(exp->exp_obd,
1128 lustre_msg_get_jobid(req->rq_reqmsg),
1132 static const char * const mdt_stats[] = {
1133 [LPROC_MDT_OPEN] = "open",
1134 [LPROC_MDT_CLOSE] = "close",
1135 [LPROC_MDT_MKNOD] = "mknod",
1136 [LPROC_MDT_LINK] = "link",
1137 [LPROC_MDT_UNLINK] = "unlink",
1138 [LPROC_MDT_MKDIR] = "mkdir",
1139 [LPROC_MDT_RMDIR] = "rmdir",
1140 [LPROC_MDT_RENAME] = "rename",
1141 [LPROC_MDT_GETATTR] = "getattr",
1142 [LPROC_MDT_SETATTR] = "setattr",
1143 [LPROC_MDT_GETXATTR] = "getxattr",
1144 [LPROC_MDT_SETXATTR] = "setxattr",
1145 [LPROC_MDT_STATFS] = "statfs",
1146 [LPROC_MDT_SYNC] = "sync",
1147 [LPROC_MDT_SAMEDIR_RENAME] = "samedir_rename",
1148 [LPROC_MDT_CROSSDIR_RENAME] = "crossdir_rename",
1149 [LPROC_MDT_IO_READ] = "read_bytes",
1150 [LPROC_MDT_IO_WRITE] = "write_bytes",
1151 [LPROC_MDT_IO_PUNCH] = "punch",
1154 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1158 LASSERT(stats && stats->ls_num >= ARRAY_SIZE(mdt_stats));
1160 for (idx = 0; idx < ARRAY_SIZE(mdt_stats); idx++) {
1163 if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
1164 flags = LPROCFS_CNTR_AVGMINMAX;
1166 lprocfs_counter_init(stats, idx, flags, mdt_stats[idx], "reqs");
1170 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
1172 struct obd_device *obd = mdt2obd_dev(mdt);
1177 LASSERT(name != NULL);
1179 obd->obd_vars = lprocfs_mdt_obd_vars;
1180 rc = lprocfs_obd_setup(obd, true);
1182 CERROR("%s: cannot create proc entries: rc = %d\n",
1183 mdt_obd_name(mdt), rc);
1187 rc = hsm_cdt_procfs_init(mdt);
1189 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1190 mdt_obd_name(mdt), rc);
1194 obd->obd_proc_exports_entry = proc_mkdir("exports",
1195 obd->obd_proc_entry);
1196 if (obd->obd_proc_exports_entry)
1197 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1198 obd, &mdt_nid_stats_clear_fops);
1200 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1204 /* add additional MDT md_stats after the default ones */
1205 for (i = 0; i < ARRAY_SIZE(mdt_stats); i++) {
1206 int idx = i + LPROC_MD_LAST_OPC;
1209 if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
1210 flags = LPROCFS_CNTR_AVGMINMAX;
1212 lprocfs_counter_init(obd->obd_md_stats, idx, flags,
1213 mdt_stats[i], "reqs");
1216 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1217 mdt_stats_counter_init);
1219 rc = lproc_mdt_attach_rename_seqstat(mdt);
1221 CERROR("%s: MDT can not create rename stats rc = %d\n",
1222 mdt_obd_name(mdt), rc);
1227 void mdt_procfs_fini(struct mdt_device *mdt)
1229 struct obd_device *obd = mdt2obd_dev(mdt);
1231 if (obd->obd_proc_exports_entry != NULL) {
1232 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1233 obd->obd_proc_exports_entry = NULL;
1236 lprocfs_free_per_client_stats(obd);
1237 hsm_cdt_procfs_fini(mdt);
1238 lprocfs_obd_cleanup(obd);
1239 lprocfs_free_md_stats(obd);
1240 lprocfs_free_obd_stats(obd);
1241 lprocfs_job_stats_fini(obd);