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, 2014, 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>
48 #include <lnet/nidstr.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"
66 * The rename stats output would be YAML formats, like
68 * - snapshot_time: 1234567890.123456
70 * 4kB: { samples: 1230, pct: 33, cum_pct: 45 }
71 * 8kB: { samples: 1242, pct: 33, cum_pct: 78 }
72 * 16kB: { samples: 132, 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 }
78 * 4kB: { samples: 123, pct: 33, cum_pct: 45 }
79 * 8kB: { samples: 124, pct: 33, cum_pct: 78 }
80 * 16kB: { samples: 12, pct: 3, cum_pct: 81 }
83 #define pct(a, b) (b ? a * 100 / b : 0)
85 static void display_rename_stats(struct seq_file *seq, char *name,
86 struct obd_histogram *hist)
88 unsigned long tot, t, cum = 0;
91 tot = lprocfs_oh_sum(hist);
93 seq_printf(seq, "- %-15s\n", name);
94 /* dir size start from 4K, start i from 10(2^10) here */
95 for (i = 0; i < OBD_HIST_MAX; i++) {
96 t = hist->oh_buckets[i];
102 seq_printf(seq, "%6s%d%s", " ", 1<< i, "bytes:");
104 seq_printf(seq, "%6s%d%s", " ", 1<<(i-10), "KB:");
106 seq_printf(seq, "%6s%d%s", " ", 1<<(i-20), "MB:");
108 seq_printf(seq, " { sample: %3lu, pct: %3lu, cum_pct: %3lu }\n",
109 t, pct(t, tot), pct(cum, tot));
116 static void rename_stats_show(struct seq_file *seq,
117 struct rename_stats *rename_stats)
121 /* this sampling races with updates */
122 do_gettimeofday(&now);
123 seq_printf(seq, "rename_stats:\n");
124 seq_printf(seq, "- %-15s %lu.%lu\n", "snapshot_time:",
125 now.tv_sec, now.tv_usec);
127 display_rename_stats(seq, "same_dir",
128 &rename_stats->hist[RENAME_SAMEDIR_SIZE]);
129 display_rename_stats(seq, "crossdir_src",
130 &rename_stats->hist[RENAME_CROSSDIR_SRC_SIZE]);
131 display_rename_stats(seq, "crossdir_tgt",
132 &rename_stats->hist[RENAME_CROSSDIR_TGT_SIZE]);
137 static int mdt_rename_stats_seq_show(struct seq_file *seq, void *v)
139 struct mdt_device *mdt = seq->private;
141 rename_stats_show(seq, &mdt->mdt_rename_stats);
147 mdt_rename_stats_seq_write(struct file *file, const char __user *buf,
148 size_t len, loff_t *off)
150 struct seq_file *seq = file->private_data;
151 struct mdt_device *mdt = seq->private;
154 for (i = 0; i < RENAME_LAST; i++)
155 lprocfs_oh_clear(&mdt->mdt_rename_stats.hist[i]);
159 LPROC_SEQ_FOPS(mdt_rename_stats);
161 static int lproc_mdt_attach_rename_seqstat(struct mdt_device *mdt)
165 for (i = 0; i < RENAME_LAST; i++)
166 spin_lock_init(&mdt->mdt_rename_stats.hist[i].oh_lock);
168 return lprocfs_obd_seq_create(mdt2obd_dev(mdt), "rename_stats", 0644,
169 &mdt_rename_stats_fops, mdt);
172 void mdt_rename_counter_tally(struct mdt_thread_info *info,
173 struct mdt_device *mdt,
174 struct ptlrpc_request *req,
175 struct mdt_object *src,
176 struct mdt_object *tgt)
178 struct md_attr *ma = &info->mti_attr;
179 struct rename_stats *rstats = &mdt->mdt_rename_stats;
182 ma->ma_need = MA_INODE;
184 rc = mo_attr_get(info->mti_env, mdt_object_child(src), ma);
186 CERROR("%s: "DFID" attr_get, rc = %d\n",
187 mdt_obd_name(mdt), PFID(mdt_object_fid(src)), rc);
192 mdt_counter_incr(req, LPROC_MDT_SAMEDIR_RENAME);
193 lprocfs_oh_tally_log2(&rstats->hist[RENAME_SAMEDIR_SIZE],
194 (unsigned int)ma->ma_attr.la_size);
198 mdt_counter_incr(req, LPROC_MDT_CROSSDIR_RENAME);
199 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_SRC_SIZE],
200 (unsigned int)ma->ma_attr.la_size);
202 ma->ma_need = MA_INODE;
204 rc = mo_attr_get(info->mti_env, mdt_object_child(tgt), ma);
206 CERROR("%s: "DFID" attr_get, rc = %d\n",
207 mdt_obd_name(mdt), PFID(mdt_object_fid(tgt)), rc);
211 lprocfs_oh_tally_log2(&rstats->hist[RENAME_CROSSDIR_TGT_SIZE],
212 (unsigned int)ma->ma_attr.la_size);
215 static int mdt_identity_expire_seq_show(struct seq_file *m, void *data)
217 struct obd_device *obd = m->private;
218 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
220 return seq_printf(m, "%u\n", mdt->mdt_identity_cache->uc_entry_expire);
224 mdt_identity_expire_seq_write(struct file *file, const char __user *buffer,
225 size_t count, loff_t *off)
227 struct seq_file *m = file->private_data;
228 struct obd_device *obd = m->private;
229 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
232 rc = lprocfs_write_helper(buffer, count, &val);
236 mdt->mdt_identity_cache->uc_entry_expire = val;
239 LPROC_SEQ_FOPS(mdt_identity_expire);
241 static int mdt_identity_acquire_expire_seq_show(struct seq_file *m, void *data)
243 struct obd_device *obd = m->private;
244 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
246 return seq_printf(m, "%u\n", mdt->mdt_identity_cache->uc_acquire_expire);
250 mdt_identity_acquire_expire_seq_write(struct file *file,
251 const char __user *buffer,
252 size_t count, loff_t *off)
254 struct seq_file *m = file->private_data;
255 struct obd_device *obd = m->private;
256 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
259 rc = lprocfs_write_helper(buffer, count, &val);
263 mdt->mdt_identity_cache->uc_acquire_expire = val;
266 LPROC_SEQ_FOPS(mdt_identity_acquire_expire);
268 static int mdt_identity_upcall_seq_show(struct seq_file *m, void *data)
270 struct obd_device *obd = m->private;
271 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
272 struct upcall_cache *hash = mdt->mdt_identity_cache;
274 read_lock(&hash->uc_upcall_rwlock);
275 seq_printf(m, "%s\n", hash->uc_upcall);
276 read_unlock(&hash->uc_upcall_rwlock);
281 mdt_identity_upcall_seq_write(struct file *file, const char __user *buffer,
282 size_t count, loff_t *off)
284 struct seq_file *m = file->private_data;
285 struct obd_device *obd = m->private;
286 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
287 struct upcall_cache *hash = mdt->mdt_identity_cache;
291 if (count >= UC_CACHE_UPCALL_MAXPATH) {
292 CERROR("%s: identity upcall too long\n", mdt_obd_name(mdt));
295 OBD_ALLOC(kernbuf, count + 1);
297 GOTO(failed, rc = -ENOMEM);
298 if (copy_from_user(kernbuf, buffer, count))
299 GOTO(failed, rc = -EFAULT);
301 /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
302 write_lock(&hash->uc_upcall_rwlock);
303 sscanf(kernbuf, "%s", hash->uc_upcall);
304 write_unlock(&hash->uc_upcall_rwlock);
306 if (strcmp(hash->uc_name, mdt_obd_name(mdt)) != 0)
307 CWARN("%s: write to upcall name %s\n",
308 mdt_obd_name(mdt), hash->uc_upcall);
310 if (strcmp(hash->uc_upcall, "NONE") == 0 && mdt->mdt_opts.mo_acl)
311 CWARN("%s: disable \"identity_upcall\" with ACL enabled maybe "
312 "cause unexpected \"EACCESS\"\n", mdt_obd_name(mdt));
314 CDEBUG(D_CONFIG, "%s: identity upcall set to %s\n", mdt_obd_name(mdt),
316 OBD_FREE(kernbuf, count + 1);
321 OBD_FREE(kernbuf, count + 1);
324 LPROC_SEQ_FOPS(mdt_identity_upcall);
327 lprocfs_identity_flush_seq_write(struct file *file, const char __user *buffer,
328 size_t count, void *data)
330 struct seq_file *m = file->private_data;
331 struct obd_device *obd = m->private;
332 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
335 rc = lprocfs_write_helper(buffer, count, &uid);
339 mdt_flush_identity(mdt->mdt_identity_cache, uid);
342 LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_flush);
345 lprocfs_identity_info_seq_write(struct file *file, const char __user *buffer,
346 size_t count, void *data)
348 struct seq_file *m = file->private_data;
349 struct obd_device *obd = m->private;
350 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
351 struct identity_downcall_data *param;
352 int size = sizeof(*param), rc, checked = 0;
356 CERROR("%s: invalid data count = %lu, size = %d\n",
357 mdt_obd_name(mdt), (unsigned long) count, size);
361 OBD_ALLOC(param, size);
365 if (copy_from_user(param, buffer, size)) {
366 CERROR("%s: bad identity data\n", mdt_obd_name(mdt));
367 GOTO(out, rc = -EFAULT);
372 if (param->idd_magic != IDENTITY_DOWNCALL_MAGIC) {
373 CERROR("%s: MDS identity downcall bad params\n",
375 GOTO(out, rc = -EINVAL);
378 if (param->idd_nperms > N_PERMS_MAX) {
379 CERROR("%s: perm count %d more than maximum %d\n",
380 mdt_obd_name(mdt), param->idd_nperms,
382 GOTO(out, rc = -EINVAL);
385 if (param->idd_ngroups > NGROUPS_MAX) {
386 CERROR("%s: group count %d more than maximum %d\n",
387 mdt_obd_name(mdt), param->idd_ngroups,
389 GOTO(out, rc = -EINVAL);
392 if (param->idd_ngroups) {
393 rc = param->idd_ngroups; /* save idd_ngroups */
394 OBD_FREE(param, size);
395 size = offsetof(struct identity_downcall_data,
401 rc = upcall_cache_downcall(mdt->mdt_identity_cache, param->idd_err,
402 param->idd_uid, param);
406 OBD_FREE(param, size);
408 return rc ? rc : count;
410 LPROC_SEQ_FOPS_WO_TYPE(mdt, identity_info);
412 static int mdt_site_stats_seq_show(struct seq_file *m, void *data)
414 struct obd_device *obd = m->private;
415 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
417 return lu_site_stats_seq_print(mdt_lu_site(mdt), m);
419 LPROC_SEQ_FOPS_RO(mdt_site_stats);
421 #define BUFLEN (UUID_MAX + 4)
424 lprocfs_mds_evict_client_seq_write(struct file *file,
425 const char __user *buffer,
426 size_t count, loff_t *off)
431 OBD_ALLOC(kbuf, BUFLEN);
436 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
437 * bytes into kbuf, to ensure that the string is NUL-terminated.
438 * UUID_MAX should include a trailing NUL already.
440 if (copy_from_user(kbuf, buffer,
441 min_t(unsigned long, BUFLEN - 1, count))) {
445 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
447 if (strncmp(tmpbuf, "nid:", 4) != 0) {
448 count = lprocfs_evict_client_seq_write(file, buffer, count,
453 CERROR("NOT implement evict client by nid %s\n", tmpbuf);
456 OBD_FREE(kbuf, BUFLEN);
462 static int mdt_sec_level_seq_show(struct seq_file *m, void *data)
464 struct obd_device *obd = m->private;
465 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
467 return seq_printf(m, "%d\n", mdt->mdt_lut.lut_sec_level);
471 mdt_sec_level_seq_write(struct file *file, const char __user *buffer,
472 size_t count, loff_t *off)
474 struct seq_file *m = file->private_data;
475 struct obd_device *obd = m->private;
476 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
479 rc = lprocfs_write_helper(buffer, count, &val);
483 if (val > LUSTRE_SEC_ALL || val < LUSTRE_SEC_NONE)
486 if (val == LUSTRE_SEC_SPECIFY) {
487 CWARN("security level %d will be supported in future.\n",
492 mdt->mdt_lut.lut_sec_level = val;
495 LPROC_SEQ_FOPS(mdt_sec_level);
497 static int mdt_cos_seq_show(struct seq_file *m, void *data)
499 struct obd_device *obd = m->private;
500 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
502 return seq_printf(m, "%u\n", mdt_cos_is_enabled(mdt));
506 mdt_cos_seq_write(struct file *file, const char __user *buffer,
507 size_t count, loff_t *off)
509 struct seq_file *m = file->private_data;
510 struct obd_device *obd = m->private;
511 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
514 rc = lprocfs_write_helper(buffer, count, &val);
517 mdt_enable_cos(mdt, val);
520 LPROC_SEQ_FOPS(mdt_cos);
522 static int mdt_root_squash_seq_show(struct seq_file *m, void *data)
524 struct obd_device *obd = m->private;
525 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
526 struct root_squash_info *squash = &mdt->mdt_squash;
528 return seq_printf(m, "%u:%u\n", squash->rsi_uid,
533 mdt_root_squash_seq_write(struct file *file, const char __user *buffer,
534 size_t count, loff_t *off)
536 struct seq_file *m = file->private_data;
537 struct obd_device *obd = m->private;
538 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
539 struct root_squash_info *squash = &mdt->mdt_squash;
541 return lprocfs_wr_root_squash(buffer, count, squash,
544 LPROC_SEQ_FOPS(mdt_root_squash);
546 static int mdt_nosquash_nids_seq_show(struct seq_file *m, void *data)
548 struct obd_device *obd = m->private;
549 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
550 struct root_squash_info *squash = &mdt->mdt_squash;
553 down_read(&squash->rsi_sem);
554 if (!list_empty(&squash->rsi_nosquash_nids)) {
555 len = cfs_print_nidlist(m->buf + m->count, m->size - m->count,
556 &squash->rsi_nosquash_nids);
558 rc = seq_printf(m, "\n");
560 rc = seq_printf(m, "NONE\n");
561 up_read(&squash->rsi_sem);
567 mdt_nosquash_nids_seq_write(struct file *file, const char __user *buffer,
568 size_t count, loff_t *off)
570 struct seq_file *m = file->private_data;
571 struct obd_device *obd = m->private;
572 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
573 struct root_squash_info *squash = &mdt->mdt_squash;
575 return lprocfs_wr_nosquash_nids(buffer, count, squash,
578 LPROC_SEQ_FOPS(mdt_nosquash_nids);
580 static int mdt_enable_remote_dir_seq_show(struct seq_file *m, void *data)
582 struct obd_device *obd = m->private;
583 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
585 return seq_printf(m, "%u\n", mdt->mdt_enable_remote_dir);
589 mdt_enable_remote_dir_seq_write(struct file *file, const char __user *buffer,
590 size_t count, loff_t *off)
592 struct seq_file *m = file->private_data;
593 struct obd_device *obd = m->private;
594 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
598 rc = lprocfs_write_helper(buffer, count, &val);
605 mdt->mdt_enable_remote_dir = val;
608 LPROC_SEQ_FOPS(mdt_enable_remote_dir);
610 static int mdt_enable_remote_dir_gid_seq_show(struct seq_file *m, void *data)
612 struct obd_device *obd = m->private;
613 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
615 return seq_printf(m, "%d\n",
616 (int)mdt->mdt_enable_remote_dir_gid);
620 mdt_enable_remote_dir_gid_seq_write(struct file *file,
621 const char __user *buffer,
622 size_t count, loff_t *off)
624 struct seq_file *m = file->private_data;
625 struct obd_device *obd = m->private;
626 struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
630 rc = lprocfs_write_helper(buffer, count, &val);
634 mdt->mdt_enable_remote_dir_gid = val;
637 LPROC_SEQ_FOPS(mdt_enable_remote_dir_gid);
639 LPROC_SEQ_FOPS_RO_TYPE(mdt, uuid);
640 LPROC_SEQ_FOPS_RO_TYPE(mdt, recovery_status);
641 LPROC_SEQ_FOPS_RO_TYPE(mdt, num_exports);
642 LPROC_SEQ_FOPS_RO_TYPE(mdt, target_instance);
643 LPROC_SEQ_FOPS_RO_TYPE(mdt, hash);
644 LPROC_SEQ_FOPS_WO_TYPE(mdt, mds_evict_client);
645 LPROC_SEQ_FOPS_RW_TYPE(mdt, job_interval);
646 LPROC_SEQ_FOPS_RW_TYPE(mdt, ir_factor);
647 LPROC_SEQ_FOPS_RW_TYPE(mdt, nid_stats_clear);
648 LPROC_SEQ_FOPS(mdt_hsm_cdt_control);
650 static struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
652 .fops = &mdt_uuid_fops },
653 { .name = "recovery_status",
654 .fops = &mdt_recovery_status_fops },
655 { .name = "num_exports",
656 .fops = &mdt_num_exports_fops },
657 { .name = "identity_expire",
658 .fops = &mdt_identity_expire_fops },
659 { .name = "identity_acquire_expire",
660 .fops = &mdt_identity_acquire_expire_fops },
661 { .name = "identity_upcall",
662 .fops = &mdt_identity_upcall_fops },
663 { .name = "identity_flush",
664 .fops = &mdt_identity_flush_fops },
665 { .name = "identity_info",
666 .fops = &mdt_identity_info_fops },
667 { .name = "site_stats",
668 .fops = &mdt_site_stats_fops },
669 { .name = "evict_client",
670 .fops = &mdt_mds_evict_client_fops },
671 { .name = "hash_stats",
672 .fops = &mdt_hash_fops },
673 { .name = "sec_level",
674 .fops = &mdt_sec_level_fops },
675 { .name = "commit_on_sharing",
676 .fops = &mdt_cos_fops },
677 { .name = "root_squash",
678 .fops = &mdt_root_squash_fops },
679 { .name = "nosquash_nids",
680 .fops = &mdt_nosquash_nids_fops },
681 { .name = "instance",
682 .fops = &mdt_target_instance_fops },
683 { .name = "ir_factor",
684 .fops = &mdt_ir_factor_fops },
685 { .name = "job_cleanup_interval",
686 .fops = &mdt_job_interval_fops },
687 { .name = "enable_remote_dir",
688 .fops = &mdt_enable_remote_dir_fops },
689 { .name = "enable_remote_dir_gid",
690 .fops = &mdt_enable_remote_dir_gid_fops },
691 { .name = "hsm_control",
692 .fops = &mdt_hsm_cdt_control_fops },
696 static int lprocfs_mdt_print_open_files(cfs_hash_t *hs, cfs_hash_bd_t *bd,
697 struct hlist_node *hnode, void *v)
699 struct obd_export *exp = cfs_hash_object(hs, hnode);
700 struct seq_file *seq = v;
702 if (exp->exp_lock_hash != NULL) {
703 struct mdt_export_data *med = &exp->exp_mdt_data;
704 struct mdt_file_data *mfd;
706 spin_lock(&med->med_open_lock);
707 list_for_each_entry(mfd, &med->med_open_head, mfd_list) {
708 seq_printf(seq, DFID"\n",
709 PFID(mdt_object_fid(mfd->mfd_object)));
711 spin_unlock(&med->med_open_lock);
717 static int lprocfs_mdt_open_files_seq_show(struct seq_file *seq, void *v)
719 struct nid_stat *stats = seq->private;
720 struct obd_device *obd = stats->nid_obd;
722 cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
723 lprocfs_mdt_print_open_files, seq);
728 int lprocfs_mdt_open_files_seq_open(struct inode *inode, struct file *file)
730 struct seq_file *seq;
733 rc = single_open(file, &lprocfs_mdt_open_files_seq_show, NULL);
737 seq = file->private_data;
738 seq->private = PDE_DATA(inode);
743 void mdt_counter_incr(struct ptlrpc_request *req, int opcode)
745 struct obd_export *exp = req->rq_export;
747 if (exp->exp_obd && exp->exp_obd->obd_md_stats)
748 lprocfs_counter_incr(exp->exp_obd->obd_md_stats, opcode);
749 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
750 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
751 if (exp->exp_obd && exp->exp_obd->u.obt.obt_jobstats.ojs_hash &&
752 (exp_connect_flags(exp) & OBD_CONNECT_JOBSTATS))
753 lprocfs_job_stats_log(exp->exp_obd,
754 lustre_msg_get_jobid(req->rq_reqmsg),
758 void mdt_stats_counter_init(struct lprocfs_stats *stats)
760 lprocfs_counter_init(stats, LPROC_MDT_OPEN, 0, "open", "reqs");
761 lprocfs_counter_init(stats, LPROC_MDT_CLOSE, 0, "close", "reqs");
762 lprocfs_counter_init(stats, LPROC_MDT_MKNOD, 0, "mknod", "reqs");
763 lprocfs_counter_init(stats, LPROC_MDT_LINK, 0, "link", "reqs");
764 lprocfs_counter_init(stats, LPROC_MDT_UNLINK, 0, "unlink", "reqs");
765 lprocfs_counter_init(stats, LPROC_MDT_MKDIR, 0, "mkdir", "reqs");
766 lprocfs_counter_init(stats, LPROC_MDT_RMDIR, 0, "rmdir", "reqs");
767 lprocfs_counter_init(stats, LPROC_MDT_RENAME, 0, "rename", "reqs");
768 lprocfs_counter_init(stats, LPROC_MDT_GETATTR, 0, "getattr", "reqs");
769 lprocfs_counter_init(stats, LPROC_MDT_SETATTR, 0, "setattr", "reqs");
770 lprocfs_counter_init(stats, LPROC_MDT_GETXATTR, 0, "getxattr", "reqs");
771 lprocfs_counter_init(stats, LPROC_MDT_SETXATTR, 0, "setxattr", "reqs");
772 lprocfs_counter_init(stats, LPROC_MDT_STATFS, 0, "statfs", "reqs");
773 lprocfs_counter_init(stats, LPROC_MDT_SYNC, 0, "sync", "reqs");
774 lprocfs_counter_init(stats, LPROC_MDT_SAMEDIR_RENAME, 0,
775 "samedir_rename", "reqs");
776 lprocfs_counter_init(stats, LPROC_MDT_CROSSDIR_RENAME, 0,
777 "crossdir_rename", "reqs");
780 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
782 struct obd_device *obd = mdt2obd_dev(mdt);
786 LASSERT(name != NULL);
788 obd->obd_vars = lprocfs_mdt_obd_vars;
789 rc = lprocfs_obd_setup(obd);
791 CERROR("%s: cannot create proc entries: rc = %d\n",
792 mdt_obd_name(mdt), rc);
796 rc = hsm_cdt_procfs_init(mdt);
798 CERROR("%s: cannot create hsm proc entries: rc = %d\n",
799 mdt_obd_name(mdt), rc);
803 obd->obd_proc_exports_entry = proc_mkdir("exports",
804 obd->obd_proc_entry);
805 if (obd->obd_proc_exports_entry)
806 lprocfs_add_simple(obd->obd_proc_exports_entry, "clear",
807 obd, &mdt_nid_stats_clear_fops);
808 rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_LAST);
811 mdt_stats_counter_init(obd->obd_md_stats);
813 rc = lprocfs_job_stats_init(obd, LPROC_MDT_LAST,
814 mdt_stats_counter_init);
816 rc = lproc_mdt_attach_rename_seqstat(mdt);
818 CERROR("%s: MDT can not create rename stats rc = %d\n",
819 mdt_obd_name(mdt), rc);
824 void mdt_procfs_fini(struct mdt_device *mdt)
826 struct obd_device *obd = mdt2obd_dev(mdt);
828 if (obd->obd_proc_exports_entry != NULL) {
829 lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
830 obd->obd_proc_exports_entry = NULL;
833 lprocfs_free_per_client_stats(obd);
834 hsm_cdt_procfs_fini(mdt);
835 lprocfs_obd_cleanup(obd);
836 lprocfs_free_md_stats(obd);
837 lprocfs_free_obd_stats(obd);
838 lprocfs_job_stats_fini(obd);