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);
712 * Show MDT async commit count.
714 * \param[in] m seq_file handle
715 * \param[in] data unused for single entry
717 * \retval 0 on success
718 * \retval negative value on error
720 static int mdt_async_commit_count_seq_show(struct seq_file *m, void *data)
722 struct obd_device *obd = m->private;
723 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
725 seq_printf(m, "%d\n", atomic_read(&mdt->mdt_async_commit_count));
730 mdt_async_commit_count_seq_write(struct file *file, const char __user *buffer,
731 size_t count, loff_t *off)
733 struct seq_file *m = file->private_data;
734 struct obd_device *obd = m->private;
735 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
739 rc = kstrtoint_from_user(buffer, count, 0, &val);
743 atomic_set(&mdt->mdt_async_commit_count, val);
747 LPROC_SEQ_FOPS(mdt_async_commit_count);
750 * Show MDT sync count.
752 * \param[in] m seq_file handle
753 * \param[in] data unused for single entry
755 * \retval 0 on success
756 * \retval negative value on error
758 static int mdt_sync_count_seq_show(struct seq_file *m, void *data)
760 struct obd_device *obd = m->private;
761 struct lu_target *tgt = obd->u.obt.obt_lut;
763 seq_printf(m, "%d\n", atomic_read(&tgt->lut_sync_count));
768 mdt_sync_count_seq_write(struct file *file, const char __user *buffer,
769 size_t count, loff_t *off)
771 struct seq_file *m = file->private_data;
772 struct obd_device *obd = m->private;
773 struct lu_target *tgt = obd->u.obt.obt_lut;
777 rc = kstrtoint_from_user(buffer, count, 0, &val);
781 atomic_set(&tgt->lut_sync_count, val);
785 LPROC_SEQ_FOPS(mdt_sync_count);
787 static char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
788 [NO_DOM_LOCK_ON_OPEN] = "never",
789 [TRYLOCK_DOM_ON_OPEN] = "trylock",
790 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
793 /* This must be longer than the longest string above */
794 #define DOM_LOCK_MODES_MAXLEN 16
797 * Show MDT policy for data prefetch on open for DoM files..
799 * \param[in] m seq_file handle
800 * \param[in] data unused
802 * \retval 0 on success
803 * \retval negative value on error
805 static int mdt_dom_lock_seq_show(struct seq_file *m, void *data)
807 struct obd_device *obd = m->private;
808 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
810 seq_printf(m, "%s\n", dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
815 * Change MDT policy for data prefetch on open for DoM files.
817 * This variable defines how DOM lock is taken at open enqueue.
818 * There are three possible modes:
819 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
820 * IO lock with own enqueue.
821 * 2) trylock - DoM lock will be taken only if non-blocked.
822 * 3) always - DoM lock will be taken always even if it is blocking lock.
824 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
825 * is paired with LAYOUT lock when possible.
827 * \param[in] file proc file
828 * \param[in] buffer string which represents policy
829 * \param[in] count \a buffer length
830 * \param[in] off unused for single entry
832 * \retval \a count on success
833 * \retval negative number on error
836 mdt_dom_lock_seq_write(struct file *file, const char __user *buffer,
837 size_t count, loff_t *off)
839 struct seq_file *m = file->private_data;
840 struct obd_device *obd = m->private;
841 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
842 char kernbuf[DOM_LOCK_MODES_MAXLEN];
846 if (count == 0 || count >= sizeof(kernbuf))
849 if (copy_from_user(kernbuf, buffer, count))
853 if (kernbuf[count - 1] == '\n')
854 kernbuf[count - 1] = 0;
856 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
857 if (strcmp(kernbuf, dom_open_lock_modes[i]) == 0) {
863 /* Legacy numeric codes */
865 rc = kstrtoint_from_user(buffer, count, 0, &val);
870 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
873 mdt->mdt_opts.mo_dom_lock = val;
876 LPROC_SEQ_FOPS(mdt_dom_lock);
879 * Show MDT policy for data prefetch on open for DoM files..
881 * \param[in] m seq_file handle
882 * \param[in] data unused
884 * \retval 0 on success
885 * \retval negative value on error
887 static int mdt_dom_read_open_seq_show(struct seq_file *m, void *data)
889 struct obd_device *obd = m->private;
890 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
892 seq_printf(m, "%u\n", !!mdt->mdt_opts.mo_dom_read_open);
897 * Modify MDT policy for data prefetch on open for DoM files.
899 * If enabled then Data-on-MDT file data may be read during open and
900 * returned back in reply. It works only with mo_dom_lock enabled.
902 * \param[in] file proc file
903 * \param[in] buffer string which represents policy
904 * \param[in] count \a buffer length
905 * \param[in] off unused for single entry
907 * \retval \a count on success
908 * \retval negative number on error
911 mdt_dom_read_open_seq_write(struct file *file, const char __user *buffer,
912 size_t count, loff_t *off)
914 struct seq_file *m = file->private_data;
915 struct obd_device *obd = m->private;
916 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
920 rc = kstrtobool_from_user(buffer, count, &val);
924 mdt->mdt_opts.mo_dom_read_open = !!val;
927 LPROC_SEQ_FOPS(mdt_dom_read_open);
929 static int mdt_migrate_hsm_allowed_seq_show(struct seq_file *m, void *data)
931 struct obd_device *obd = m->private;
932 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
934 seq_printf(m, "%u\n", (mdt->mdt_opts.mo_migrate_hsm_allowed != 0));
939 mdt_migrate_hsm_allowed_seq_write(struct file *file, const char __user *buffer,
940 size_t count, loff_t *off)
942 struct seq_file *m = file->private_data;
943 struct obd_device *obd = m->private;
944 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
948 rc = kstrtobool_from_user(buffer, count, &val);
952 mdt->mdt_opts.mo_migrate_hsm_allowed = val;
955 LPROC_SEQ_FOPS(mdt_migrate_hsm_allowed);
957 static int mdt_readonly_seq_show(struct seq_file *m, void *data)
959 struct obd_device *obd = m->private;
960 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
962 seq_printf(m, "%u\n", mdt->mdt_readonly);
967 mdt_readonly_seq_write(struct file *file, const char __user *buffer,
968 size_t count, loff_t *off)
970 struct seq_file *m = file->private_data;
971 struct obd_device *obd = m->private;
972 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
976 rc = kstrtobool_from_user(buffer, count, &val);
980 mdt->mdt_readonly = val;
983 LPROC_SEQ_FOPS(mdt_readonly);
985 static int mdt_enable_remote_rename_seq_show(struct seq_file *m, void *data)
987 struct obd_device *obd = m->private;
988 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
990 seq_printf(m, "%u\n", mdt->mdt_enable_remote_rename);
995 mdt_enable_remote_rename_seq_write(struct file *file, const char __user *buffer,
996 size_t count, loff_t *off)
998 struct seq_file *m = file->private_data;
999 struct obd_device *obd = m->private;
1000 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1004 rc = kstrtobool_from_user(buffer, count, &val);
1008 mdt->mdt_enable_remote_rename = val;
1011 LPROC_SEQ_FOPS(mdt_enable_remote_rename);
1013 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1014 LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports);
1015 LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance);
1016 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1017 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1018 LPROC_SEQ_FOPS_RW_TYPE(mdt, job_interval);
1019 LPROC_SEQ_FOPS_RW_TYPE(mdt, ir_factor);
1020 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1021 LPROC_SEQ_FOPS(mdt_hsm_cdt_control);
1023 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_hard);
1024 LPROC_SEQ_FOPS_RW_TYPE(mdt, recovery_time_soft);
1026 LPROC_SEQ_FOPS_RO(tgt_tot_dirty);
1027 LPROC_SEQ_FOPS_RO(tgt_tot_granted);
1028 LPROC_SEQ_FOPS_RO(tgt_tot_pending);
1029 LPROC_SEQ_FOPS(tgt_grant_compat_disable);
1031 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1032 { .name = "tot_dirty",
1033 .fops = &tgt_tot_dirty_fops },
1034 { .name = "tot_pending",
1035 .fops = &tgt_tot_pending_fops },
1036 { .name = "tot_granted",
1037 .fops = &tgt_tot_granted_fops },
1038 { .name = "grant_compat_disable",
1039 .fops = &tgt_grant_compat_disable_fops },
1040 { .name = "recovery_status",
1041 .fops = &mdt_recovery_status_fops },
1042 { .name = "num_exports",
1043 .fops = &mdt_num_exports_fops },
1044 { .name = "identity_expire",
1045 .fops = &mdt_identity_expire_fops },
1046 { .name = "identity_acquire_expire",
1047 .fops = &mdt_identity_acquire_expire_fops },
1048 { .name = "identity_upcall",
1049 .fops = &mdt_identity_upcall_fops },
1050 { .name = "identity_flush",
1051 .fops = &mdt_identity_flush_fops },
1052 { .name = "identity_info",
1053 .fops = &mdt_identity_info_fops },
1054 { .name = "site_stats",
1055 .fops = &mdt_site_stats_fops },
1056 { .name = "evict_client",
1057 .fops = &mdt_mds_evict_client_fops },
1058 { .name = "evict_tgt_nids",
1059 .fops = &mdt_evict_tgt_nids_fops },
1060 { .name = "hash_stats",
1061 .fops = &mdt_hash_fops },
1062 { .name = "commit_on_sharing",
1063 .fops = &mdt_cos_fops },
1064 { .name = "root_squash",
1065 .fops = &mdt_root_squash_fops },
1066 { .name = "nosquash_nids",
1067 .fops = &mdt_nosquash_nids_fops },
1068 { .name = "instance",
1069 .fops = &mdt_target_instance_fops },
1070 { .name = "ir_factor",
1071 .fops = &mdt_ir_factor_fops },
1072 { .name = "job_cleanup_interval",
1073 .fops = &mdt_job_interval_fops },
1074 { .name = "enable_remote_dir",
1075 .fops = &mdt_enable_remote_dir_fops },
1076 { .name = "enable_remote_dir_gid",
1077 .fops = &mdt_enable_remote_dir_gid_fops },
1078 { .name = "enable_striped_dir",
1079 .fops = &mdt_enable_striped_dir_fops },
1080 { .name = "enable_dir_migration",
1081 .fops = &mdt_enable_dir_migration_fops },
1082 { .name = "enable_remote_rename",
1083 .fops = &mdt_enable_remote_rename_fops },
1084 { .name = "hsm_control",
1085 .fops = &mdt_hsm_cdt_control_fops },
1086 { .name = "recovery_time_hard",
1087 .fops = &mdt_recovery_time_hard_fops },
1088 { .name = "recovery_time_soft",
1089 .fops = &mdt_recovery_time_soft_fops },
1090 { .name = "async_commit_count",
1091 .fops = &mdt_async_commit_count_fops },
1092 { .name = "sync_count",
1093 .fops = &mdt_sync_count_fops },
1094 { .name = "dom_lock",
1095 .fops = &mdt_dom_lock_fops },
1096 { .name = "dom_read_open",
1097 .fops = &mdt_dom_read_open_fops },
1098 { .name = "migrate_hsm_allowed",
1099 .fops = &mdt_migrate_hsm_allowed_fops },
1100 { .name = "readonly",
1101 .fops = &mdt_readonly_fops },
1106 lprocfs_mdt_print_open_files(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1107 struct hlist_node *hnode, void *v)
1109 struct obd_export *exp = cfs_hash_object(hs, hnode);
1110 struct seq_file *seq = v;
1112 if (exp->exp_lock_hash != NULL) {
1113 struct mdt_export_data *med = &exp->exp_mdt_data;
1114 struct mdt_file_data *mfd;
1116 spin_lock(&med->med_open_lock);
1117 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1118 seq_printf(seq, DFID"\n",
1119 PFID(mdt_object_fid(mfd->mfd_object)));
1121 spin_unlock(&med->med_open_lock);
1127 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1129 struct nid_stat *stats = seq->private;
1130 struct obd_device *obd = stats->nid_obd;
1132 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
1133 lprocfs_mdt_print_open_files, seq);
1138 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1140 struct seq_file *seq;
1143 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1147 seq = file->private_data;
1148 seq->private = PDE_DATA(inode);
1153 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1155 struct obd_export *exp = req->rq_export;
1157 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1158 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1159 opcode + LPROC_MD_LAST_OPC);
1160 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1161 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1162 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1163 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1164 lprocfs_job_stats_log(exp->exp_obd,
1165 lustre_msg_get_jobid(req->rq_reqmsg),
1169 static const char * const mdt_stats[] = {
1170 [LPROC_MDT_OPEN] = "open",
1171 [LPROC_MDT_CLOSE] = "close",
1172 [LPROC_MDT_MKNOD] = "mknod",
1173 [LPROC_MDT_LINK] = "link",
1174 [LPROC_MDT_UNLINK] = "unlink",
1175 [LPROC_MDT_MKDIR] = "mkdir",
1176 [LPROC_MDT_RMDIR] = "rmdir",
1177 [LPROC_MDT_RENAME] = "rename",
1178 [LPROC_MDT_GETATTR] = "getattr",
1179 [LPROC_MDT_SETATTR] = "setattr",
1180 [LPROC_MDT_GETXATTR] = "getxattr",
1181 [LPROC_MDT_SETXATTR] = "setxattr",
1182 [LPROC_MDT_STATFS] = "statfs",
1183 [LPROC_MDT_SYNC] = "sync",
1184 [LPROC_MDT_SAMEDIR_RENAME] = "samedir_rename",
1185 [LPROC_MDT_CROSSDIR_RENAME] = "crossdir_rename",
1186 [LPROC_MDT_IO_READ] = "read_bytes",
1187 [LPROC_MDT_IO_WRITE] = "write_bytes",
1188 [LPROC_MDT_IO_PUNCH] = "punch",
1191 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1195 LASSERT(stats && stats->ls_num >= ARRAY_SIZE(mdt_stats));
1197 for (idx = 0; idx < ARRAY_SIZE(mdt_stats); idx++) {
1200 if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
1201 flags = LPROCFS_CNTR_AVGMINMAX;
1203 lprocfs_counter_init(stats, idx, flags, mdt_stats[idx], "reqs");
1207 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
1209 struct obd_device *obd = mdt2obd_dev(mdt);
1214 LASSERT(name != NULL);
1216 obd->obd_vars = lprocfs_mdt_obd_vars;
1217 rc = lprocfs_obd_setup(obd, true);
1219 CERROR("%s: cannot create proc entries: rc = %d\n",
1220 mdt_obd_name(mdt), rc);
1224 rc = tgt_tunables_init(&mdt->mdt_lut);
1226 CERROR("%s: failed to init target tunables: rc = %d\n",
1227 mdt_obd_name(mdt), rc);
1231 rc = hsm_cdt_procfs_init(mdt);
1233 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1234 mdt_obd_name(mdt), rc);
1238 obd->obd_proc_exports_entry = proc_mkdir("exports",
1239 obd->obd_proc_entry);
1240 if (obd->obd_proc_exports_entry)
1241 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1242 obd, &mdt_nid_stats_clear_fops);
1244 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1248 /* add additional MDT md_stats after the default ones */
1249 for (i = 0; i < ARRAY_SIZE(mdt_stats); i++) {
1250 int idx = i + LPROC_MD_LAST_OPC;
1253 if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
1254 flags = LPROCFS_CNTR_AVGMINMAX;
1256 lprocfs_counter_init(obd->obd_md_stats, idx, flags,
1257 mdt_stats[i], "reqs");
1260 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1261 mdt_stats_counter_init);
1263 rc = lproc_mdt_attach_rename_seqstat(mdt);
1265 CERROR("%s: MDT can not create rename stats rc = %d\n",
1266 mdt_obd_name(mdt), rc);
1271 void mdt_procfs_fini(struct mdt_device *mdt)
1273 struct obd_device *obd = mdt2obd_dev(mdt);
1275 if (obd->obd_proc_exports_entry != NULL) {
1276 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1277 obd->obd_proc_exports_entry = NULL;
1280 lprocfs_free_per_client_stats(obd);
1281 hsm_cdt_procfs_fini(mdt);
1282 tgt_tunables_fini(&mdt->mdt_lut);
1283 lprocfs_obd_cleanup(obd);
1284 lprocfs_free_md_stats(obd);
1285 lprocfs_free_obd_stats(obd);
1286 lprocfs_job_stats_fini(obd);