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.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2013, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mdt/mdt_lproc.c
38 * Author: Lai Siyao <lsy@clusterfs.com>
39 * Author: Fan Yong <fanyong@clusterfs.com>
42 #define DEBUG_SUBSYSTEM S_MDS
44 #include <linux/version.h>
45 #include <asm/statfs.h>
47 #include <linux/module.h>
49 /* LUSTRE_VERSION_CODE */
50 #include <lustre_ver.h>
52 * struct OBD_{ALLOC,FREE}*()
55 #include <obd_support.h>
56 /* struct obd_export */
57 #include <lustre_export.h>
58 /* struct obd_device */
60 #include <obd_class.h>
61 #include <lustre_mds.h>
62 #include <lprocfs_status.h>
63 #include "mdt_internal.h"
64 #include <lnet/lib-lnet.h>
67 * The rename stats output would be YAML formats, like
69 * - snapshot_time: 1234567890.123456
71 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
72 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
73 * 16kB: { samples: 132, pct: 3, cum_pct: 81 }
75 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
76 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
77 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
79 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
80 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
81 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
84 #define pct(a, b) (b ? a * 100 / b : 0)
86 static void display_rename_stats(struct seq_file *seq, char *name,
87 struct obd_histogram *hist)
89 unsigned long tot, t, cum = 0;
92 tot = lprocfs_oh_sum(hist);
94 seq_printf(seq, "- %-15s\n", name);
95 /* dir size start from 4K, start i from 10(2^10) here */
96 for (i = 0; i < OBD_HIST_MAX; i++) {
97 t = hist->oh_buckets[i];
103 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
105 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
107 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
109 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
110 t, pct(t, tot), pct(cum, tot));
117 static void rename_stats_show(struct seq_file *seq,
118 struct rename_stats *rename_stats)
122 /* this sampling races with updates */
123 do_gettimeofday(&now);
124 seq_printf(seq, "rename_stats:\n");
125 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
126 now.tv_sec, now.tv_usec);
128 display_rename_stats(seq, "same_dir",
129 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
130 display_rename_stats(seq, "crossdir_src",
131 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
132 display_rename_stats(seq, "crossdir_tgt",
133 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
138 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
140 struct mdt_device *mdt = seq->private;
142 rename_stats_show(seq, &mdt->mdt_rename_stats);
148 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
149 size_t len, loff_t *off)
151 struct seq_file *seq = file->private_data;
152 struct mdt_device *mdt = seq->private;
155 for (i = 0; i < RENAME_LAST; i++)
156 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
160 LPROC_SEQ_FOPS(mdt_rename_stats);
162 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
166 for (i = 0; i < RENAME_LAST; i++)
167 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
169 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
170 &mdt_rename_stats_fops, mdt);
173 void mdt_rename_counter_tally(struct mdt_thread_info *info,
174 struct mdt_device *mdt,
175 struct ptlrpc_request *req,
176 struct mdt_object *src,
177 struct mdt_object *tgt)
179 struct md_attr *ma = &info->mti_attr;
180 struct rename_stats *rstats = &mdt->mdt_rename_stats;
183 ma->ma_need = MA_INODE;
185 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
187 CERROR("%s: "DFID" attr_get, rc = %d\n",
188 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
193 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
194 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
195 (unsigned int)ma->ma_attr.la_size);
199 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
200 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
201 (unsigned int)ma->ma_attr.la_size);
203 ma->ma_need = MA_INODE;
205 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
207 CERROR("%s: "DFID" attr_get, rc = %d\n",
208 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
212 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
213 (unsigned int)ma->ma_attr.la_size);
216 static int mdt_identity_expire_seq_show(struct seq_file *m, void *data)
218 struct obd_device *obd = m->private;
219 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
221 return seq_printf(m, "%u\n", mdt->mdt_identity_cache->uc_entry_expire);
225 mdt_identity_expire_seq_write(struct file *file, const char __user *buffer,
226 size_t count, loff_t *off)
228 struct seq_file *m = file->private_data;
229 struct obd_device *obd = m->private;
230 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
233 rc = lprocfs_write_helper(buffer, count, &val);
237 mdt->mdt_identity_cache->uc_entry_expire = val;
240 LPROC_SEQ_FOPS(mdt_identity_expire);
242 static int mdt_identity_acquire_expire_seq_show(struct seq_file *m, void *data)
244 struct obd_device *obd = m->private;
245 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
247 return seq_printf(m, "%u\n", mdt->mdt_identity_cache->uc_acquire_expire);
251 mdt_identity_acquire_expire_seq_write(struct file *file,
252 const char __user *buffer,
253 size_t count, loff_t *off)
255 struct seq_file *m = file->private_data;
256 struct obd_device *obd = m->private;
257 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
260 rc = lprocfs_write_helper(buffer, count, &val);
264 mdt->mdt_identity_cache->uc_acquire_expire = val;
267 LPROC_SEQ_FOPS(mdt_identity_acquire_expire);
269 static int mdt_identity_upcall_seq_show(struct seq_file *m, void *data)
271 struct obd_device *obd = m->private;
272 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
273 struct upcall_cache *hash = mdt->mdt_identity_cache;
275 read_lock(&hash->uc_upcall_rwlock);
276 seq_printf(m, "%s\n", hash->uc_upcall);
277 read_unlock(&hash->uc_upcall_rwlock);
282 mdt_identity_upcall_seq_write(struct file *file, const char __user *buffer,
283 size_t count, loff_t *off)
285 struct seq_file *m = file->private_data;
286 struct obd_device *obd = m->private;
287 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
288 struct upcall_cache *hash = mdt->mdt_identity_cache;
292 if (count >= UC_CACHE_UPCALL_MAXPATH) {
293 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
296 OBD_ALLOC(kernbuf, count + 1);
298 GOTO(failed, rc = -ENOMEM);
299 if (copy_from_user(kernbuf, buffer, count))
300 GOTO(failed, rc = -EFAULT);
302 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
303 write_lock(&hash->uc_upcall_rwlock);
304 sscanf(kernbuf, "%s", hash->uc_upcall);
305 write_unlock(&hash->uc_upcall_rwlock);
307 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
308 CWARN("%s: write to upcall name %s\n",
309 mdt_obd_name(mdt), hash->uc_upcall);
311 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
312 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
313 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
315 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
317 OBD_FREE(kernbuf, count + 1);
322 OBD_FREE(kernbuf, count + 1);
325 LPROC_SEQ_FOPS(mdt_identity_upcall);
328 lprocfs_identity_flush_seq_write(struct file *file, const char __user *buffer,
329 size_t count, void *data)
331 struct seq_file *m = file->private_data;
332 struct obd_device *obd = m->private;
333 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
336 rc = lprocfs_write_helper(buffer, count, &uid);
340 mdt_flush_identity(mdt->mdt_identity_cache, uid);
343 LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_flush);
346 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
347 size_t count, void *data)
349 struct seq_file *m = file->private_data;
350 struct obd_device *obd = m->private;
351 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
352 struct identity_downcall_data *param;
353 int size = sizeof(*param), rc, checked = 0;
357 CERROR("%s: invalid data count = %lu, size = %d\n",
358 mdt_obd_name(mdt), (unsigned long) count, size);
362 OBD_ALLOC(param, size);
366 if (copy_from_user(param, buffer, size)) {
367 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
368 GOTO(out, rc = -EFAULT);
373 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
374 CERROR("%s: MDS identity downcall bad params\n",
376 GOTO(out, rc = -EINVAL);
379 if (param->idd_nperms > N_PERMS_MAX) {
380 CERROR("%s: perm count %d more than maximum %d\n",
381 mdt_obd_name(mdt), param->idd_nperms,
383 GOTO(out, rc = -EINVAL);
386 if (param->idd_ngroups > NGROUPS_MAX) {
387 CERROR("%s: group count %d more than maximum %d\n",
388 mdt_obd_name(mdt), param->idd_ngroups,
390 GOTO(out, rc = -EINVAL);
393 if (param->idd_ngroups) {
394 rc = param->idd_ngroups; /* save idd_ngroups */
395 OBD_FREE(param, size);
396 size = offsetof(struct identity_downcall_data,
402 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
403 param->idd_uid, param);
407 OBD_FREE(param, size);
409 return rc ? rc : count;
411 LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_info);
414 static int mdt_capa_seq_show(struct seq_file *m, void *data)
416 struct obd_device *obd = m->private;
417 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
419 return seq_printf(m, "capability on: %s %s\n",
420 mdt->mdt_lut.lut_oss_capa ? "oss" : "",
421 mdt->mdt_lut.lut_mds_capa ? "mds" : "");
425 mdt_capa_seq_write(struct file *file, const char __user *buffer,
426 size_t count, loff_t *off)
428 struct seq_file *m = file->private_data;
429 struct obd_device *obd = m->private;
430 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
433 rc = lprocfs_write_helper(buffer, count, &val);
437 if (val < 0 || val > 3) {
438 CERROR("invalid capability mode, only 0/2/3 is accepted.\n"
439 " 0: disable fid capability\n"
440 " 2: enable MDS fid capability\n"
441 " 3: enable both MDS and OSS fid capability\n");
445 /* OSS fid capability needs enable both MDS and OSS fid capability on
448 CERROR("can't enable OSS fid capability only, you should use "
449 "'3' to enable both MDS and OSS fid capability.\n");
453 spin_lock(&mdt->mdt_lut.lut_flags_lock);
454 mdt->mdt_lut.lut_oss_capa = !!(val & 0x1);
455 mdt->mdt_lut.lut_mds_capa = !!(val & 0x2);
456 spin_unlock(&mdt->mdt_lut.lut_flags_lock);
457 mdt->mdt_capa_conf = 1;
458 LCONSOLE_INFO("MDS %s %s MDS fid capability.\n",
460 mdt->mdt_lut.lut_mds_capa ? "enabled" : "disabled");
461 LCONSOLE_INFO("MDS %s %s OSS fid capability.\n",
463 mdt->mdt_lut.lut_oss_capa ? "enabled" : "disabled");
466 LPROC_SEQ_FOPS(mdt_capa);
468 static int mdt_capa_count_seq_show(struct seq_file *m, void *data)
470 return seq_printf(m, "%d %d\n", capa_count[CAPA_SITE_CLIENT],
471 capa_count[CAPA_SITE_SERVER]);
473 LPROC_SEQ_FOPS_RO(mdt_capa_count);
475 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
477 struct obd_device *obd = m->private;
478 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
480 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
482 LPROC_SEQ_FOPS_RO(mdt_site_stats);
484 static int mdt_capa_timeout_seq_show(struct seq_file *m, void *data)
486 struct obd_device *obd = m->private;
487 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
489 return seq_printf(m, "%lu\n", mdt->mdt_capa_timeout);
493 mdt_capa_timeout_seq_write(struct file *file, const char __user *buffer,
494 size_t count, loff_t *off)
496 struct seq_file *m = file->private_data;
497 struct obd_device *obd = m->private;
498 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
501 rc = lprocfs_write_helper(buffer, count, &val);
505 mdt->mdt_capa_timeout = (unsigned long)val;
506 mdt->mdt_capa_conf = 1;
509 LPROC_SEQ_FOPS(mdt_capa_timeout);
511 static int mdt_ck_timeout_seq_show(struct seq_file *m, void *data)
513 struct obd_device *obd = m->private;
514 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
516 return seq_printf(m, "%lu\n", mdt->mdt_ck_timeout);
520 mdt_ck_timeout_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);
528 rc = lprocfs_write_helper(buffer, count, &val);
532 mdt->mdt_ck_timeout = (unsigned long)val;
533 mdt->mdt_capa_conf = 1;
536 LPROC_SEQ_FOPS(mdt_ck_timeout);
538 #define BUFLEN (UUID_MAX + 4)
541 lprocfs_mds_evict_client_seq_write(struct file *file,
542 const char __user *buffer,
543 size_t count, loff_t *off)
548 OBD_ALLOC(kbuf, BUFLEN);
553 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
554 * bytes into kbuf, to ensure that the string is NUL-terminated.
555 * UUID_MAX should include a trailing NUL already.
557 if (copy_from_user(kbuf, buffer,
558 min_t(unsigned long, BUFLEN - 1, count))) {
562 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
564 if (strncmp(tmpbuf, "nid:", 4) != 0) {
565 count = lprocfs_evict_client_seq_write(file, buffer, count,
570 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
573 OBD_FREE(kbuf, BUFLEN);
579 static int mdt_sec_level_seq_show(struct seq_file *m, void *data)
581 struct obd_device *obd = m->private;
582 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
584 return seq_printf(m, "%d\n", mdt->mdt_lut.lut_sec_level);
588 mdt_sec_level_seq_write(struct file *file, const char __user *buffer,
589 size_t count, loff_t *off)
591 struct seq_file *m = file->private_data;
592 struct obd_device *obd = m->private;
593 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
596 rc = lprocfs_write_helper(buffer, count, &val);
600 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
603 if (val == LUSTRE_SEC_SPECIFY) {
604 CWARN("security level %d will be supported in future.\n",
609 mdt->mdt_lut.lut_sec_level = val;
612 LPROC_SEQ_FOPS(mdt_sec_level);
614 static int mdt_cos_seq_show(struct seq_file *m, void *data)
616 struct obd_device *obd = m->private;
617 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
619 return seq_printf(m, "%u\n", mdt_cos_is_enabled(mdt));
623 mdt_cos_seq_write(struct file *file, const char __user *buffer,
624 size_t count, loff_t *off)
626 struct seq_file *m = file->private_data;
627 struct obd_device *obd = m->private;
628 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
631 rc = lprocfs_write_helper(buffer, count, &val);
634 mdt_enable_cos(mdt, val);
637 LPROC_SEQ_FOPS(mdt_cos);
639 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
641 struct obd_device *obd = m->private;
642 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
643 struct root_squash_info *squash = &mdt->mdt_squash;
645 return seq_printf(m, "%u:%u\n", squash->rsi_uid,
650 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
651 size_t count, loff_t *off)
653 struct seq_file *m = file->private_data;
654 struct obd_device *obd = m->private;
655 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
656 struct root_squash_info *squash = &mdt->mdt_squash;
658 return lprocfs_wr_root_squash(buffer, count, squash,
661 LPROC_SEQ_FOPS(mdt_root_squash);
663 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
665 struct obd_device *obd = m->private;
666 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
667 struct root_squash_info *squash = &mdt->mdt_squash;
670 down_read(&squash->rsi_sem);
671 if (!list_empty(&squash->rsi_nosquash_nids)) {
672 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
673 &squash->rsi_nosquash_nids);
675 rc = seq_printf(m, "\n");
677 rc = seq_printf(m, "NONE\n");
678 up_read(&squash->rsi_sem);
684 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
685 size_t count, loff_t *off)
687 struct seq_file *m = file->private_data;
688 struct obd_device *obd = m->private;
689 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
690 struct root_squash_info *squash = &mdt->mdt_squash;
692 return lprocfs_wr_nosquash_nids(buffer, count, squash,
695 LPROC_SEQ_FOPS(mdt_nosquash_nids);
697 static int mdt_som_seq_show(struct seq_file *m, void *data)
699 struct obd_device *obd = m->private;
700 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
702 return seq_printf(m, "%sabled\n",
703 mdt->mdt_som_conf ? "en" : "dis");
707 mdt_som_seq_write(struct file *file, const char __user *buffer,
708 size_t count, loff_t *off)
710 struct seq_file *m = file->private_data;
711 struct obd_device *obd = m->private;
712 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
713 struct obd_export *exp;
715 unsigned long val = 0;
717 if (count > (sizeof(kernbuf) - 1))
720 if (copy_from_user(kernbuf, buffer, count))
723 kernbuf[count] = '\0';
725 if (!strcmp(kernbuf, "enabled"))
727 else if (strcmp(kernbuf, "disabled"))
730 if (mdt->mdt_som_conf == val)
733 if (!obd->obd_process_conf) {
734 CERROR("Temporary SOM change is not supported, use lctl "
735 "conf_param for permanent setting\n");
739 /* 1 stands for self export. */
740 cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
741 if (exp == obd->obd_self_export)
743 if (exp_connect_flags(exp) & OBD_CONNECT_MDS_MDS)
745 /* Some clients are already connected, skip the change */
746 LCONSOLE_INFO("%s is already connected, SOM will be %s on "
747 "the next mount\n", exp->exp_client_uuid.uuid,
748 val ? "enabled" : "disabled");
752 mdt->mdt_som_conf = val;
753 LCONSOLE_INFO("Enabling SOM\n");
757 LPROC_SEQ_FOPS(mdt_som);
759 static int mdt_enable_remote_dir_seq_show(struct seq_file *m, void *data)
761 struct obd_device *obd = m->private;
762 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
764 return seq_printf(m, "%u\n", mdt->mdt_enable_remote_dir);
768 mdt_enable_remote_dir_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 mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
777 rc = lprocfs_write_helper(buffer, count, &val);
784 mdt->mdt_enable_remote_dir = val;
787 LPROC_SEQ_FOPS(mdt_enable_remote_dir);
789 static int mdt_enable_remote_dir_gid_seq_show(struct seq_file *m, void *data)
791 struct obd_device *obd = m->private;
792 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
794 return seq_printf(m, "%d\n",
795 (int)mdt->mdt_enable_remote_dir_gid);
799 mdt_enable_remote_dir_gid_seq_write(struct file *file,
800 const char __user *buffer,
801 size_t count, loff_t *off)
803 struct seq_file *m = file->private_data;
804 struct obd_device *obd = m->private;
805 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
809 rc = lprocfs_write_helper(buffer, count, &val);
813 mdt->mdt_enable_remote_dir_gid = val;
816 LPROC_SEQ_FOPS(mdt_enable_remote_dir_gid);
818 LPROC_SEQ_FOPS_RO_TYPE(mdt, uuid);
819 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
820 LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports);
821 LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance);
822 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
823 LPROC_SEQ_FOPS_WO_TYPE(mdt, mds_evict_client);
824 LPROC_SEQ_FOPS_RW_TYPE(mdt, job_interval);
825 LPROC_SEQ_FOPS_RW_TYPE(mdt, ir_factor);
826 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
827 LPROC_SEQ_FOPS(mdt_hsm_cdt_control);
829 static struct lprocfs_seq_vars lprocfs_mdt_obd_vars[] = {
831 .fops = &mdt_uuid_fops },
832 { .name = "recovery_status",
833 .fops = &mdt_recovery_status_fops },
834 { .name = "num_exports",
835 .fops = &mdt_num_exports_fops },
836 { .name = "identity_expire",
837 .fops = &mdt_identity_expire_fops },
838 { .name = "identity_acquire_expire",
839 .fops = &mdt_identity_acquire_expire_fops },
840 { .name = "identity_upcall",
841 .fops = &mdt_identity_upcall_fops },
842 { .name = "identity_flush",
843 .fops = &mdt_identity_flush_fops },
844 { .name = "identity_info",
845 .fops = &mdt_identity_info_fops },
847 .fops = &mdt_capa_fops },
848 { .name = "capa_timeout",
849 .fops = &mdt_capa_timeout_fops },
850 { .name = "capa_key_timeout",
851 .fops = &mdt_ck_timeout_fops },
852 { .name = "capa_count",
853 .fops = &mdt_capa_count_fops },
854 { .name = "site_stats",
855 .fops = &mdt_site_stats_fops },
856 { .name = "evict_client",
857 .fops = &mdt_mds_evict_client_fops },
858 { .name = "hash_stats",
859 .fops = &mdt_hash_fops },
860 { .name = "sec_level",
861 .fops = &mdt_sec_level_fops },
862 { .name = "commit_on_sharing",
863 .fops = &mdt_cos_fops },
864 { .name = "root_squash",
865 .fops = &mdt_root_squash_fops },
866 { .name = "nosquash_nids",
867 .fops = &mdt_nosquash_nids_fops },
869 .fops = &mdt_som_fops },
870 { .name = "instance",
871 .fops = &mdt_target_instance_fops },
872 { .name = "ir_factor",
873 .fops = &mdt_ir_factor_fops },
874 { .name = "job_cleanup_interval",
875 .fops = &mdt_job_interval_fops },
876 { .name = "enable_remote_dir",
877 .fops = &mdt_enable_remote_dir_fops },
878 { .name = "enable_remote_dir_gid",
879 .fops = &mdt_enable_remote_dir_gid_fops },
880 { .name = "hsm_control",
881 .fops = &mdt_hsm_cdt_control_fops },
885 int lprocfs_mdt_print_open_files(cfs_hash_t *hs, cfs_hash_bd_t *bd,
886 cfs_hlist_node_t *hnode, void *v)
888 struct obd_export *exp = cfs_hash_object(hs, hnode);
889 struct seq_file *seq = v;
891 if (exp->exp_lock_hash != NULL) {
892 struct mdt_export_data *med = &exp->exp_mdt_data;
893 struct mdt_file_data *mfd;
895 spin_lock(&med->med_open_lock);
896 cfs_list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
897 seq_printf(seq, DFID"\n",
898 PFID(mdt_object_fid(mfd->mfd_object)));
900 spin_unlock(&med->med_open_lock);
906 int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
908 struct nid_stat *stats = seq->private;
909 struct obd_device *obd = stats->nid_obd;
911 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
912 lprocfs_mdt_print_open_files, seq);
917 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
919 struct seq_file *seq;
922 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
926 seq = file->private_data;
927 seq->private = PDE_DATA(inode);
932 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
934 struct obd_export *exp = req->rq_export;
936 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
937 lprocfs_counter_incr(exp->exp_obd->obd_md_stats, opcode);
938 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
939 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
940 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
941 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
942 lprocfs_job_stats_log(exp->exp_obd,
943 lustre_msg_get_jobid(req->rq_reqmsg),
947 void mdt_stats_counter_init(struct lprocfs_stats *stats)
949 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
950 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
951 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
952 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
953 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
954 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
955 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
956 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
957 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
958 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
959 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
960 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
961 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
962 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
963 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
964 "samedir_rename", "reqs");
965 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
966 "crossdir_rename", "reqs");
969 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
971 struct obd_device *obd = mdt2obd_dev(mdt);
975 LASSERT(name != NULL);
977 obd->obd_vars = lprocfs_mdt_obd_vars;
978 rc = lprocfs_seq_obd_setup(obd);
980 CERROR("%s: cannot create proc entries: rc = %d\n",
981 mdt_obd_name(mdt), rc);
985 rc = hsm_cdt_procfs_init(mdt);
987 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
988 mdt_obd_name(mdt), rc);
992 obd->obd_proc_exports_entry = proc_mkdir("exports",
993 obd->obd_proc_entry);
994 if (obd->obd_proc_exports_entry)
995 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
996 #ifndef HAVE_ONLY_PROCFS_SEQ
999 obd, &mdt_nid_stats_clear_fops);
1000 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
1003 mdt_stats_counter_init(obd->obd_md_stats);
1005 rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
1006 mdt_stats_counter_init);
1008 rc = lproc_mdt_attach_rename_seqstat(mdt);
1010 CERROR("%s: MDT can not create rename stats rc = %d\n",
1011 mdt_obd_name(mdt), rc);
1016 void mdt_procfs_fini(struct mdt_device *mdt)
1018 struct obd_device *obd = mdt2obd_dev(mdt);
1020 if (obd->obd_proc_exports_entry != NULL) {
1021 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
1022 obd->obd_proc_exports_entry = NULL;
1025 lprocfs_free_per_client_stats(obd);
1026 hsm_cdt_procfs_fini(mdt);
1027 lprocfs_obd_cleanup(obd);
1028 lprocfs_free_md_stats(obd);
1029 lprocfs_free_obd_stats(obd);
1030 lprocfs_job_stats_fini(obd);