1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002 Cluster File Systems, Inc.
6 * This file is part of the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
25 #define DEBUG_SUBSYSTEM S_CLASS
27 #include <linux/version.h>
28 #include <asm/statfs.h>
30 #include <obd_class.h>
31 #include <lprocfs_status.h>
32 #include <lustre_param.h>
33 #include "mgs_internal.h"
37 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
40 struct obd_device* obd = (struct obd_device *)data;
43 LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
46 return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
49 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
51 struct obd_device *obd = seq->private;
52 struct mgs_obd *mgs = &obd->u.mgs;
53 struct list_head dentry_list;
54 struct l_linux_dirent *dirent, *n;
59 rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
60 mgs->mgs_vfsmnt, &dentry_list);
62 CERROR("Can't read config dir\n");
65 list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
66 list_del(&dirent->lld_list);
67 len = strlen(dirent->lld_name);
68 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
70 seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
72 OBD_FREE(dirent, sizeof(*dirent));
78 LPROC_SEQ_FOPS_RO(mgs_fs);
80 int lproc_mgs_setup(struct obd_device *obd)
82 struct mgs_obd *mgs = &obd->u.mgs;
85 rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
88 mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
90 if (IS_ERR(mgs->mgs_proc_live)) {
91 rc = PTR_ERR(mgs->mgs_proc_live);
92 CERROR("error %d setting up lprocfs for %s\n", rc, "live");
93 mgs->mgs_proc_live = NULL;
96 obd->obd_proc_exports_entry = lprocfs_register("exports",
99 if (IS_ERR(obd->obd_proc_exports_entry)) {
100 rc = PTR_ERR(obd->obd_proc_exports_entry);
101 CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
102 obd->obd_proc_exports_entry = NULL;
108 int lproc_mgs_cleanup(struct obd_device *obd)
116 if (mgs->mgs_proc_live) {
117 /* Should be no live entries */
118 LASSERT(mgs->mgs_proc_live->subdir == NULL);
119 lprocfs_remove(&mgs->mgs_proc_live);
120 mgs->mgs_proc_live = NULL;
122 lprocfs_free_obd_stats(obd);
124 return lprocfs_obd_cleanup(obd);
127 static void seq_show_srpc_rule(struct seq_file *seq, const char *tgtname,
128 struct sptlrpc_rule_set *rset)
130 struct sptlrpc_rule *r;
136 for (i = 0; i < rset->srs_nrule; i++) {
137 r = &rset->srs_rules[i];
139 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
142 net = libcfs_net2str(r->sr_netid);
144 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
147 snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
148 sptlrpc_part2name(r->sr_from),
149 sptlrpc_part2name(r->sr_to));
151 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
152 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
153 net, dirbuf, flvrbuf);
157 static int mgs_live_seq_show(struct seq_file *seq, void *v)
159 struct fs_db *fsdb = seq->private;
160 struct mgs_tgt_srpc_conf *srpc_tgt;
163 down(&fsdb->fsdb_sem);
165 seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
166 seq_printf(seq, "flags: %#x gen: %d\n",
167 fsdb->fsdb_flags, fsdb->fsdb_gen);
168 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
169 if (test_bit(i, fsdb->fsdb_mdt_index_map))
170 seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
171 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
172 if (test_bit(i, fsdb->fsdb_ost_index_map))
173 seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
175 seq_printf(seq, "\nSecure RPC Config Rules:\n");
177 seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
178 PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
180 for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
181 srpc_tgt = srpc_tgt->mtsc_next) {
182 seq_show_srpc_rule(seq, srpc_tgt->mtsc_tgt,
183 &srpc_tgt->mtsc_rset);
185 seq_show_srpc_rule(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
191 LPROC_SEQ_FOPS_RO(mgs_live);
193 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
195 struct mgs_obd *mgs = &obd->u.mgs;
198 if (!mgs->mgs_proc_live)
200 rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
201 &mgs_live_fops, fsdb);
206 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
208 struct mgs_obd *mgs = &obd->u.mgs;
210 if (!mgs->mgs_proc_live)
213 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
217 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
218 { "uuid", lprocfs_rd_uuid, 0, 0 },
219 { "fstype", lprocfs_rd_fstype, 0, 0 },
220 { "mntdev", lprocfs_mgs_rd_mntdev, 0, 0 },
221 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
222 { "evict_client", 0, lprocfs_wr_evict_client, 0 },
226 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
230 void mgs_counter_incr(struct obd_export *exp, int opcode)
232 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
233 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
234 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
237 void mgs_stats_counter_init(struct lprocfs_stats *stats)
239 lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
240 lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
242 lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
244 lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
245 lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
248 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
250 lvars->module_vars = lprocfs_mgs_module_vars;
251 lvars->obd_vars = lprocfs_mgs_obd_vars;