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 ssize_t identity_expire_show(struct kobject *kobj,
208 struct attribute *attr, char *buf)
210 struct obd_device *obd = container_of(kobj, struct obd_device,
212 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
214 return scnprintf(buf, PAGE_SIZE, "%lld\n",
215 mdt->mdt_identity_cache->uc_entry_expire);
218 static ssize_t identity_expire_store(struct kobject *kobj,
219 struct attribute *attr,
220 const char *buffer, size_t count)
222 struct obd_device *obd = container_of(kobj, struct obd_device,
224 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
228 rc = kstrtoll(buffer, 10, &val);
235 mdt->mdt_identity_cache->uc_entry_expire = val;
239 LUSTRE_RW_ATTR(identity_expire);
241 static ssize_t identity_acquire_expire_show(struct kobject *kobj,
242 struct attribute *attr, char *buf)
244 struct obd_device *obd = container_of(kobj, struct obd_device,
246 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
248 return scnprintf(buf, PAGE_SIZE, "%lld\n",
249 mdt->mdt_identity_cache->uc_acquire_expire);
252 static ssize_t identity_acquire_expire_store(struct kobject *kobj,
253 struct attribute *attr,
254 const char *buffer, size_t count)
256 struct obd_device *obd = container_of(kobj, struct obd_device,
258 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
262 rc = kstrtoll(buffer, 0, &val);
266 if (val < 0 || val > INT_MAX)
269 mdt->mdt_identity_cache->uc_acquire_expire = val;
273 LUSTRE_RW_ATTR(identity_acquire_expire);
275 static ssize_t identity_upcall_show(struct kobject *kobj,
276 struct attribute *attr, char *buf)
278 struct obd_device *obd = container_of(kobj, struct obd_device,
280 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
281 struct upcall_cache *hash = mdt->mdt_identity_cache;
284 down_read(&hash->uc_upcall_rwsem);
285 rc = scnprintf(buf, PAGE_SIZE, "%s\n", hash->uc_upcall);
286 up_read(&hash->uc_upcall_rwsem);
290 static ssize_t identity_upcall_store(struct kobject *kobj,
291 struct attribute *attr,
292 const char *buffer, size_t count)
294 struct obd_device *obd = container_of(kobj, struct obd_device,
296 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
297 struct upcall_cache *hash = mdt->mdt_identity_cache;
299 if (count >= UC_CACHE_UPCALL_MAXPATH) {
300 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
304 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
305 down_write(&hash->uc_upcall_rwsem);
306 sscanf(buffer, "%s", hash->uc_upcall);
307 up_write(&hash->uc_upcall_rwsem);
309 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
310 CWARN("%s: write to upcall name %s\n",
311 mdt_obd_name(mdt), hash->uc_upcall);
313 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
314 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
315 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
317 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
321 LUSTRE_RW_ATTR(identity_upcall);
323 static ssize_t identity_flush_store(struct kobject *kobj,
324 struct attribute *attr,
325 const char *buffer, size_t count)
327 struct obd_device *obd = container_of(kobj, struct obd_device,
329 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
333 rc = kstrtoint(buffer, 0, &uid);
337 mdt_flush_identity(mdt->mdt_identity_cache, uid);
340 LUSTRE_WO_ATTR(identity_flush);
343 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
344 size_t count, void *data)
346 struct seq_file *m = file->private_data;
347 struct obd_device *obd = m->private;
348 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
349 struct identity_downcall_data *param;
350 int size = sizeof(*param), rc, checked = 0;
354 CERROR("%s: invalid data count = %lu, size = %d\n",
355 mdt_obd_name(mdt), (unsigned long) count, size);
359 OBD_ALLOC(param, size);
363 if (copy_from_user(param, buffer, size)) {
364 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
365 GOTO(out, rc = -EFAULT);
370 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
371 CERROR("%s: MDS identity downcall bad params\n",
373 GOTO(out, rc = -EINVAL);
376 if (param->idd_nperms > N_PERMS_MAX) {
377 CERROR("%s: perm count %d more than maximum %d\n",
378 mdt_obd_name(mdt), param->idd_nperms,
380 GOTO(out, rc = -EINVAL);
383 if (param->idd_ngroups > NGROUPS_MAX) {
384 CERROR("%s: group count %d more than maximum %d\n",
385 mdt_obd_name(mdt), param->idd_ngroups,
387 GOTO(out, rc = -EINVAL);
390 if (param->idd_ngroups) {
391 rc = param->idd_ngroups; /* save idd_ngroups */
392 OBD_FREE(param, size);
393 size = offsetof(struct identity_downcall_data,
399 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
400 param->idd_uid, param);
404 OBD_FREE(param, size);
406 return rc ? rc : count;
408 LPROC_SEQ_FOPS_WR_ONLY(mdt, identity_info);
410 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
412 struct obd_device *obd = m->private;
413 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
415 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
417 LPROC_SEQ_FOPS_RO(mdt_site_stats);
419 #define BUFLEN (UUID_MAX + 4)
422 lprocfs_mds_evict_client_seq_write(struct file *file, const char __user *buf,
423 size_t count, loff_t *off)
425 struct seq_file *m = file->private_data;
426 struct obd_device *obd = m->private;
427 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
432 OBD_ALLOC(kbuf, BUFLEN);
437 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
438 * bytes into kbuf, to ensure that the string is NUL-terminated.
439 * UUID_MAX should include a trailing NUL already.
441 if (copy_from_user(kbuf, buf, min_t(unsigned long, BUFLEN - 1, count)))
442 GOTO(out, rc = -EFAULT);
443 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
445 if (strncmp(tmpbuf, "nid:", 4) != 0) {
446 count = lprocfs_evict_client_seq_write(file, buf, count, off);
450 if (mdt->mdt_opts.mo_evict_tgt_nids) {
451 rc = obd_set_info_async(NULL, mdt->mdt_child_exp,
452 sizeof(KEY_EVICT_BY_NID),
454 strlen(tmpbuf + 4) + 1,
457 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
461 /* See the comments in function lprocfs_wr_evict_client()
462 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
463 class_incref(obd, __func__, current);
464 obd_export_evict_by_nid(obd, tmpbuf + 4);
465 class_decref(obd, __func__, current);
469 OBD_FREE(kbuf, BUFLEN);
470 return rc < 0 ? rc : count;
475 static ssize_t evict_tgt_nids_show(struct kobject *kobj,
476 struct attribute *attr, char *buf)
478 struct obd_device *obd = container_of(kobj, struct obd_device,
480 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
482 return scnprintf(buf, PAGE_SIZE, "%u\n",
483 mdt->mdt_opts.mo_evict_tgt_nids);
486 static ssize_t evict_tgt_nids_store(struct kobject *kobj,
487 struct attribute *attr, const char *buffer,
490 struct obd_device *obd = container_of(kobj, struct obd_device,
492 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
496 rc = kstrtobool(buffer, &val);
500 mdt->mdt_opts.mo_evict_tgt_nids = val;
503 LUSTRE_RW_ATTR(evict_tgt_nids);
505 static ssize_t commit_on_sharing_show(struct kobject *kobj,
506 struct attribute *attr, char *buf)
508 struct obd_device *obd = container_of(kobj, struct obd_device,
510 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
512 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt_cos_is_enabled(mdt));
515 static ssize_t commit_on_sharing_store(struct kobject *kobj,
516 struct attribute *attr,
517 const char *buffer, size_t count)
519 struct obd_device *obd = container_of(kobj, struct obd_device,
521 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
525 rc = kstrtobool(buffer, &val);
529 mdt_enable_cos(mdt, val);
532 LUSTRE_RW_ATTR(commit_on_sharing);
534 static ssize_t local_recovery_show(struct kobject *kobj,
535 struct attribute *attr, char *buf)
537 struct obd_device *obd = container_of(kobj, struct obd_device,
540 return scnprintf(buf, PAGE_SIZE, "%u\n",
541 obd->u.obt.obt_lut->lut_local_recovery);
544 static ssize_t local_recovery_store(struct kobject *kobj,
545 struct attribute *attr,
546 const char *buffer, size_t count)
548 struct obd_device *obd = container_of(kobj, struct obd_device,
553 rc = kstrtobool(buffer, &val);
557 obd->u.obt.obt_lut->lut_local_recovery = !!val;
560 LUSTRE_RW_ATTR(local_recovery);
562 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
564 struct obd_device *obd = m->private;
565 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
566 struct root_squash_info *squash = &mdt->mdt_squash;
568 seq_printf(m, "%u:%u\n", squash->rsi_uid,
574 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
575 size_t count, loff_t *off)
577 struct seq_file *m = file->private_data;
578 struct obd_device *obd = m->private;
579 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
580 struct root_squash_info *squash = &mdt->mdt_squash;
582 return lprocfs_wr_root_squash(buffer, count, squash,
585 LPROC_SEQ_FOPS(mdt_root_squash);
587 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
589 struct obd_device *obd = m->private;
590 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
591 struct root_squash_info *squash = &mdt->mdt_squash;
594 spin_lock(&squash->rsi_lock);
595 if (!list_empty(&squash->rsi_nosquash_nids)) {
596 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
597 &squash->rsi_nosquash_nids);
601 seq_puts(m, "NONE\n");
602 spin_unlock(&squash->rsi_lock);
608 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
609 size_t count, loff_t *off)
611 struct seq_file *m = file->private_data;
612 struct obd_device *obd = m->private;
613 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
614 struct root_squash_info *squash = &mdt->mdt_squash;
616 return lprocfs_wr_nosquash_nids(buffer, count, squash,
619 LPROC_SEQ_FOPS(mdt_nosquash_nids);
621 static ssize_t enable_remote_dir_show(struct kobject *kobj,
622 struct attribute *attr, char *buf)
624 struct obd_device *obd = container_of(kobj, struct obd_device,
626 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
628 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_remote_dir);
631 static ssize_t enable_remote_dir_store(struct kobject *kobj,
632 struct attribute *attr,
633 const char *buffer, size_t count)
635 struct obd_device *obd = container_of(kobj, struct obd_device,
637 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
641 rc = kstrtobool(buffer, &val);
645 mdt->mdt_enable_remote_dir = val;
648 LUSTRE_RW_ATTR(enable_remote_dir);
650 static ssize_t enable_remote_dir_gid_show(struct kobject *kobj,
651 struct attribute *attr, char *buf)
653 struct obd_device *obd = container_of(kobj, struct obd_device,
655 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
657 return scnprintf(buf, PAGE_SIZE, "%d\n",
658 (int)mdt->mdt_enable_remote_dir_gid);
661 static ssize_t enable_remote_dir_gid_store(struct kobject *kobj,
662 struct attribute *attr,
663 const char *buffer, size_t count)
665 struct obd_device *obd = container_of(kobj, struct obd_device,
667 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
671 rc = kstrtoint(buffer, 0, &val);
675 mdt->mdt_enable_remote_dir_gid = val;
678 LUSTRE_RW_ATTR(enable_remote_dir_gid);
680 static ssize_t enable_chprojid_gid_show(struct kobject *kobj,
681 struct attribute *attr, char *buf)
683 struct obd_device *obd = container_of(kobj, struct obd_device,
685 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
687 return scnprintf(buf, PAGE_SIZE, "%d\n",
688 (int)mdt->mdt_enable_chprojid_gid);
691 static ssize_t enable_chprojid_gid_store(struct kobject *kobj,
692 struct attribute *attr,
693 const char *buffer, size_t count)
695 struct obd_device *obd = container_of(kobj, struct obd_device,
697 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
701 rc = kstrtoint(buffer, 0, &val);
705 mdt->mdt_enable_chprojid_gid = val;
708 LUSTRE_RW_ATTR(enable_chprojid_gid);
710 static ssize_t enable_striped_dir_show(struct kobject *kobj,
711 struct attribute *attr, char *buf)
713 struct obd_device *obd = container_of(kobj, struct obd_device,
715 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
717 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_striped_dir);
720 static ssize_t enable_striped_dir_store(struct kobject *kobj,
721 struct attribute *attr,
722 const char *buffer, size_t count)
724 struct obd_device *obd = container_of(kobj, struct obd_device,
726 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
730 rc = kstrtobool(buffer, &val);
734 mdt->mdt_enable_striped_dir = val;
737 LUSTRE_RW_ATTR(enable_striped_dir);
739 static ssize_t enable_dir_migration_show(struct kobject *kobj,
740 struct attribute *attr, char *buf)
742 struct obd_device *obd = container_of(kobj, struct obd_device,
744 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
746 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_enable_dir_migration);
749 static ssize_t enable_dir_migration_store(struct kobject *kobj,
750 struct attribute *attr,
751 const char *buffer, size_t count)
753 struct obd_device *obd = container_of(kobj, struct obd_device,
755 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
759 rc = kstrtobool(buffer, &val);
763 mdt->mdt_enable_dir_migration = val;
766 LUSTRE_RW_ATTR(enable_dir_migration);
769 * Show MDT async commit count.
772 * @data unused for single entry
774 * Return: 0 on success
775 * negative value on error
777 static ssize_t async_commit_count_show(struct kobject *kobj,
778 struct attribute *attr, char *buf)
780 struct obd_device *obd = container_of(kobj, struct obd_device,
782 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
784 return scnprintf(buf, PAGE_SIZE, "%d\n",
785 atomic_read(&mdt->mdt_async_commit_count));
788 static ssize_t async_commit_count_store(struct kobject *kobj,
789 struct attribute *attr,
790 const char *buffer, size_t count)
792 struct obd_device *obd = container_of(kobj, struct obd_device,
794 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
798 rc = kstrtoint(buffer, 10, &val);
802 atomic_set(&mdt->mdt_async_commit_count, val);
806 LUSTRE_RW_ATTR(async_commit_count);
809 * Show MDT sync count.
811 * \param[in] m seq_file handle
812 * \param[in] data unused for single entry
814 * \retval 0 on success
815 * \retval negative value on error
817 static ssize_t sync_count_show(struct kobject *kobj, struct attribute *attr,
820 struct obd_device *obd = container_of(kobj, struct obd_device,
822 struct lu_target *tgt = obd->u.obt.obt_lut;
824 return scnprintf(buf, PAGE_SIZE, "%d\n",
825 atomic_read(&tgt->lut_sync_count));
828 static ssize_t sync_count_store(struct kobject *kobj, struct attribute *attr,
829 const char *buffer, size_t count)
831 struct obd_device *obd = container_of(kobj, struct obd_device,
833 struct lu_target *tgt = obd->u.obt.obt_lut;
837 rc = kstrtoint(buffer, 0, &val);
841 atomic_set(&tgt->lut_sync_count, val);
845 LUSTRE_RW_ATTR(sync_count);
847 static char *dom_open_lock_modes[NUM_DOM_LOCK_ON_OPEN_MODES] = {
848 [NO_DOM_LOCK_ON_OPEN] = "never",
849 [TRYLOCK_DOM_ON_OPEN] = "trylock",
850 [ALWAYS_DOM_LOCK_ON_OPEN] = "always",
853 /* This must be longer than the longest string above */
854 #define DOM_LOCK_MODES_MAXLEN 16
857 * Show MDT policy for data prefetch on open for DoM files..
859 * \param[in] m seq_file handle
860 * \param[in] data unused
862 * \retval 0 on success
863 * \retval negative value on error
865 static ssize_t dom_lock_show(struct kobject *kobj, struct attribute *attr,
868 struct obd_device *obd = container_of(kobj, struct obd_device,
870 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
872 return scnprintf(buf, PAGE_SIZE, "%s\n",
873 dom_open_lock_modes[mdt->mdt_opts.mo_dom_lock]);
877 * Change MDT policy for data prefetch on open for DoM files.
879 * This variable defines how DOM lock is taken at open enqueue.
880 * There are three possible modes:
881 * 1) never - never take DoM lock on open. DoM lock will be taken as separate
882 * IO lock with own enqueue.
883 * 2) trylock - DoM lock will be taken only if non-blocked.
884 * 3) always - DoM lock will be taken always even if it is blocking lock.
886 * If dom_read_open is enabled too then DoM lock is taken in PR mode and
887 * is paired with LAYOUT lock when possible.
889 * \param[in] file proc file
890 * \param[in] buffer string which represents policy
891 * \param[in] count \a buffer length
892 * \param[in] off unused for single entry
894 * \retval \a count on success
895 * \retval negative number on error
897 static ssize_t dom_lock_store(struct kobject *kobj, struct attribute *attr,
898 const char *buffer, size_t count)
900 struct obd_device *obd = container_of(kobj, struct obd_device,
902 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
906 if (count == 0 || count >= DOM_LOCK_MODES_MAXLEN)
909 for (i = 0 ; i < NUM_DOM_LOCK_ON_OPEN_MODES; i++) {
910 /* buffer might have '\n' but using strlen() avoids it */
911 if (strncmp(buffer, dom_open_lock_modes[i],
912 strlen(dom_open_lock_modes[i])) == 0) {
918 /* Legacy numeric codes */
920 rc = kstrtoint(buffer, 0, &val);
925 if (val < 0 || val >= NUM_DOM_LOCK_ON_OPEN_MODES)
928 mdt->mdt_opts.mo_dom_lock = val;
931 LUSTRE_RW_ATTR(dom_lock);
934 * Show MDT policy for data prefetch on open for DoM files..
936 * \param[in] m seq_file handle
937 * \param[in] data unused
939 * \retval 0 on success
940 * \retval negative value on error
942 static ssize_t dom_read_open_show(struct kobject *kobj,
943 struct attribute *attr, char *buf)
945 struct obd_device *obd = container_of(kobj, struct obd_device,
947 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
949 return scnprintf(buf, PAGE_SIZE, "%u\n",
950 !!mdt->mdt_opts.mo_dom_read_open);
954 * Modify MDT policy for data prefetch on open for DoM files.
956 * If enabled then Data-on-MDT file data may be read during open and
957 * returned back in reply. It works only with mo_dom_lock enabled.
959 * \param[in] file proc file
960 * \param[in] buffer string which represents policy
961 * \param[in] count \a buffer length
962 * \param[in] off unused for single entry
964 * \retval \a count on success
965 * \retval negative number on error
967 static ssize_t dom_read_open_store(struct kobject *kobj,
968 struct attribute *attr, const char *buffer,
971 struct obd_device *obd = container_of(kobj, struct obd_device,
973 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
977 rc = kstrtobool(buffer, &val);
981 mdt->mdt_opts.mo_dom_read_open = !!val;
984 LUSTRE_RW_ATTR(dom_read_open);
986 static ssize_t migrate_hsm_allowed_show(struct kobject *kobj,
987 struct attribute *attr, char *buf)
989 struct obd_device *obd = container_of(kobj, struct obd_device,
991 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
993 return scnprintf(buf, PAGE_SIZE, "%u\n",
994 mdt->mdt_opts.mo_migrate_hsm_allowed);
997 static ssize_t migrate_hsm_allowed_store(struct kobject *kobj,
998 struct attribute *attr,
999 const char *buffer, size_t count)
1001 struct obd_device *obd = container_of(kobj, struct obd_device,
1003 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1007 rc = kstrtobool(buffer, &val);
1011 mdt->mdt_opts.mo_migrate_hsm_allowed = val;
1014 LUSTRE_RW_ATTR(migrate_hsm_allowed);
1016 static ssize_t readonly_show(struct kobject *kobj, struct attribute *attr,
1019 struct obd_device *obd = container_of(kobj, struct obd_device,
1021 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1023 return scnprintf(buf, PAGE_SIZE, "%u\n", mdt->mdt_readonly);
1026 static ssize_t readonly_store(struct kobject *kobj, struct attribute *attr,
1027 const char *buffer, size_t count)
1029 struct obd_device *obd = container_of(kobj, struct obd_device,
1031 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1035 rc = kstrtobool(buffer, &val);
1039 mdt->mdt_readonly = val;
1042 LUSTRE_RW_ATTR(readonly);
1044 static ssize_t enable_remote_rename_show(struct kobject *kobj,
1045 struct attribute *attr,
1048 struct obd_device *obd = container_of(kobj, struct obd_device,
1050 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1052 return scnprintf(buf, PAGE_SIZE, "%u\n",
1053 mdt->mdt_enable_remote_rename);
1056 static ssize_t enable_remote_rename_store(struct kobject *kobj,
1057 struct attribute *attr,
1058 const char *buffer, size_t count)
1060 struct obd_device *obd = container_of(kobj, struct obd_device,
1062 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
1066 rc = kstrtobool(buffer, &val);
1070 mdt->mdt_enable_remote_rename = val;
1073 LUSTRE_RW_ATTR(enable_remote_rename);
1075 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
1076 LPROC_SEQ_FOPS_WR_ONLY(mdt, mds_evict_client);
1077 LUSTRE_RW_ATTR(job_cleanup_interval);
1078 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
1079 LUSTRE_RW_ATTR(hsm_control);
1081 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
1082 LUSTRE_RW_ATTR(recovery_time_hard);
1083 LUSTRE_RW_ATTR(recovery_time_soft);
1084 LUSTRE_RW_ATTR(ir_factor);
1086 LUSTRE_RO_ATTR(tot_dirty);
1087 LUSTRE_RO_ATTR(tot_granted);
1088 LUSTRE_RO_ATTR(tot_pending);
1089 LUSTRE_RW_ATTR(grant_compat_disable);
1090 LUSTRE_RO_ATTR(instance);
1092 LUSTRE_RO_ATTR(num_exports);
1094 static struct attribute *mdt_attrs[] = {
1095 &lustre_attr_tot_dirty.attr,
1096 &lustre_attr_tot_granted.attr,
1097 &lustre_attr_tot_pending.attr,
1098 &lustre_attr_grant_compat_disable.attr,
1099 &lustre_attr_instance.attr,
1100 &lustre_attr_recovery_time_hard.attr,
1101 &lustre_attr_recovery_time_soft.attr,
1102 &lustre_attr_ir_factor.attr,
1103 &lustre_attr_num_exports.attr,
1104 &lustre_attr_identity_expire.attr,
1105 &lustre_attr_identity_acquire_expire.attr,
1106 &lustre_attr_identity_upcall.attr,
1107 &lustre_attr_identity_flush.attr,
1108 &lustre_attr_evict_tgt_nids.attr,
1109 &lustre_attr_enable_remote_dir.attr,
1110 &lustre_attr_enable_remote_dir_gid.attr,
1111 &lustre_attr_enable_chprojid_gid.attr,
1112 &lustre_attr_enable_striped_dir.attr,
1113 &lustre_attr_enable_dir_migration.attr,
1114 &lustre_attr_enable_remote_rename.attr,
1115 &lustre_attr_commit_on_sharing.attr,
1116 &lustre_attr_local_recovery.attr,
1117 &lustre_attr_async_commit_count.attr,
1118 &lustre_attr_sync_count.attr,
1119 &lustre_attr_dom_lock.attr,
1120 &lustre_attr_dom_read_open.attr,
1121 &lustre_attr_migrate_hsm_allowed.attr,
1122 &lustre_attr_hsm_control.attr,
1123 &lustre_attr_job_cleanup_interval.attr,
1124 &lustre_attr_readonly.attr,
1128 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
1129 { .name = "recovery_status",
1130 .fops = &mdt_recovery_status_fops },
1131 { .name = "identity_info",
1132 .fops = &mdt_identity_info_fops },
1133 { .name = "site_stats",
1134 .fops = &mdt_site_stats_fops },
1135 { .name = "evict_client",
1136 .fops = &mdt_mds_evict_client_fops },
1137 { .name = "hash_stats",
1138 .fops = &mdt_hash_fops },
1139 { .name = "root_squash",
1140 .fops = &mdt_root_squash_fops },
1141 { .name = "nosquash_nids",
1142 .fops = &mdt_nosquash_nids_fops },
1147 lprocfs_mdt_print_open_files(struct cfs_hash *hs, struct cfs_hash_bd *bd,
1148 struct hlist_node *hnode, void *v)
1150 struct obd_export *exp = cfs_hash_object(hs, hnode);
1151 struct seq_file *seq = v;
1153 if (exp->exp_lock_hash != NULL) {
1154 struct mdt_export_data *med = &exp->exp_mdt_data;
1155 struct mdt_file_data *mfd;
1157 spin_lock(&med->med_open_lock);
1158 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
1159 seq_printf(seq, DFID"\n",
1160 PFID(mdt_object_fid(mfd->mfd_object)));
1162 spin_unlock(&med->med_open_lock);
1168 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
1170 struct nid_stat *stats = seq->private;
1171 struct obd_device *obd = stats->nid_obd;
1173 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
1174 lprocfs_mdt_print_open_files, seq);
1179 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
1181 struct seq_file *seq;
1184 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
1188 seq = file->private_data;
1189 seq->private = PDE_DATA(inode);
1194 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
1196 struct obd_export *exp = req->rq_export;
1198 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
1199 lprocfs_counter_incr(exp->exp_obd->obd_md_stats,
1200 opcode + LPROC_MD_LAST_OPC);
1201 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
1202 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
1203 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
1204 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
1205 lprocfs_job_stats_log(exp->exp_obd,
1206 lustre_msg_get_jobid(req->rq_reqmsg),
1210 static const char * const mdt_stats[] = {
1211 [LPROC_MDT_OPEN] = "open",
1212 [LPROC_MDT_CLOSE] = "close",
1213 [LPROC_MDT_MKNOD] = "mknod",
1214 [LPROC_MDT_LINK] = "link",
1215 [LPROC_MDT_UNLINK] = "unlink",
1216 [LPROC_MDT_MKDIR] = "mkdir",
1217 [LPROC_MDT_RMDIR] = "rmdir",
1218 [LPROC_MDT_RENAME] = "rename",
1219 [LPROC_MDT_GETATTR] = "getattr",
1220 [LPROC_MDT_SETATTR] = "setattr",
1221 [LPROC_MDT_GETXATTR] = "getxattr",
1222 [LPROC_MDT_SETXATTR] = "setxattr",
1223 [LPROC_MDT_STATFS] = "statfs",
1224 [LPROC_MDT_SYNC] = "sync",
1225 [LPROC_MDT_SAMEDIR_RENAME] = "samedir_rename",
1226 [LPROC_MDT_CROSSDIR_RENAME] = "crossdir_rename",
1227 [LPROC_MDT_IO_READ] = "read_bytes",
1228 [LPROC_MDT_IO_WRITE] = "write_bytes",
1229 [LPROC_MDT_IO_PUNCH] = "punch",
1230 [LPROC_MDT_MIGRATE] = "migrate",
1233 void mdt_stats_counter_init(struct lprocfs_stats *stats)
1237 LASSERT(stats && stats->ls_num >= ARRAY_SIZE(mdt_stats));
1239 for (idx = 0; idx < ARRAY_SIZE(mdt_stats); idx++) {
1242 if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
1243 flags = LPROCFS_CNTR_AVGMINMAX;
1245 lprocfs_counter_init(stats, idx, flags, mdt_stats[idx], "reqs");
1249 int mdt_tunables_init(struct mdt_device *mdt, const char *name)
1251 struct obd_device *obd = mdt2obd_dev(mdt);
1256 LASSERT(name != NULL);
1258 obd->obd_ktype.default_attrs = mdt_attrs;
1259 obd->obd_vars = lprocfs_mdt_obd_vars;
1260 rc = lprocfs_obd_setup(obd, true);
1262 CERROR("%s: cannot create proc entries: rc = %d\n",
1263 mdt_obd_name(mdt), rc);
1267 rc = tgt_tunables_init(&mdt->mdt_lut);
1269 CERROR("%s: failed to init target tunables: rc = %d\n",
1270 mdt_obd_name(mdt), rc);
1274 rc = hsm_cdt_tunables_init(mdt);
1276 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
1277 mdt_obd_name(mdt), rc);
1281 obd->obd_proc_exports_entry = proc_mkdir("exports",
1282 obd->obd_proc_entry);
1283 if (obd->obd_proc_exports_entry)
1284 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
1285 obd, &mdt_nid_stats_clear_fops);
1287 rc = lprocfs_alloc_md_stats(obd, ARRAY_SIZE(mdt_stats));
1291 /* add additional MDT md_stats after the default ones */
1292 for (i = 0; i < ARRAY_SIZE(mdt_stats); i++) {
1293 int idx = i + LPROC_MD_LAST_OPC;
1296 if (idx == LPROC_MDT_IO_WRITE || idx == LPROC_MDT_IO_READ)
1297 flags = LPROCFS_CNTR_AVGMINMAX;
1299 lprocfs_counter_init(obd->obd_md_stats, idx, flags,
1300 mdt_stats[i], "reqs");
1303 rc = lprocfs_job_stats_init(obd, ARRAY_SIZE(mdt_stats),
1304 mdt_stats_counter_init);
1306 rc = lproc_mdt_attach_rename_seqstat(mdt);
1308 CERROR("%s: MDT can not create rename stats rc = %d\n",
1309 mdt_obd_name(mdt), rc);
1314 void mdt_tunables_fini(struct mdt_device *mdt)
1316 struct obd_device *obd = mdt2obd_dev(mdt);
1318 if (obd->obd_proc_exports_entry != NULL) {
1319 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1320 obd->obd_proc_exports_entry = NULL;
1323 lprocfs_free_per_client_stats(obd);
1324 /* hsm_cdt_tunables is disabled earlier than this to avoid
1325 * coordinator restart.
1327 hsm_cdt_tunables_fini(mdt);
1328 tgt_tunables_fini(&mdt->mdt_lut);
1329 lprocfs_obd_cleanup(obd);
1330 lprocfs_free_md_stats(obd);
1331 lprocfs_free_obd_stats(obd);
1332 lprocfs_job_stats_fini(obd);