1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 #define DEBUG_SUBSYSTEM S_CLASS
38 #include <linux/version.h>
39 #include <asm/statfs.h>
41 #include <obd_class.h>
42 #include <lprocfs_status.h>
43 #include <lustre_param.h>
44 #include "mgs_internal.h"
48 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
51 struct obd_device* obd = (struct obd_device *)data;
54 LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
57 return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
60 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
62 struct obd_device *obd = seq->private;
63 struct mgs_obd *mgs = &obd->u.mgs;
64 struct list_head dentry_list;
65 struct l_linux_dirent *dirent, *n;
70 rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
71 mgs->mgs_vfsmnt, &dentry_list);
73 CERROR("Can't read config dir\n");
76 list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
77 list_del(&dirent->lld_list);
78 len = strlen(dirent->lld_name);
79 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
81 seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
83 OBD_FREE(dirent, sizeof(*dirent));
89 LPROC_SEQ_FOPS_RO(mgs_fs);
91 int lproc_mgs_setup(struct obd_device *obd)
93 struct mgs_obd *mgs = &obd->u.mgs;
96 rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
99 mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
101 if (IS_ERR(mgs->mgs_proc_live)) {
102 rc = PTR_ERR(mgs->mgs_proc_live);
103 CERROR("error %d setting up lprocfs for %s\n", rc, "live");
104 mgs->mgs_proc_live = NULL;
107 obd->obd_proc_exports_entry = lprocfs_register("exports",
110 if (IS_ERR(obd->obd_proc_exports_entry)) {
111 rc = PTR_ERR(obd->obd_proc_exports_entry);
112 CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
113 obd->obd_proc_exports_entry = NULL;
119 int lproc_mgs_cleanup(struct obd_device *obd)
127 if (mgs->mgs_proc_live) {
128 /* Should be no live entries */
129 LASSERT(mgs->mgs_proc_live->subdir == NULL);
130 lprocfs_remove(&mgs->mgs_proc_live);
131 mgs->mgs_proc_live = NULL;
133 lprocfs_free_obd_stats(obd);
135 return lprocfs_obd_cleanup(obd);
138 static void seq_show_srpc_rule(struct seq_file *seq, const char *tgtname,
139 struct sptlrpc_rule_set *rset)
141 struct sptlrpc_rule *r;
147 for (i = 0; i < rset->srs_nrule; i++) {
148 r = &rset->srs_rules[i];
150 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
153 net = libcfs_net2str(r->sr_netid);
155 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
158 snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
159 sptlrpc_part2name(r->sr_from),
160 sptlrpc_part2name(r->sr_to));
162 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
163 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
164 net, dirbuf, flvrbuf);
168 static int mgs_live_seq_show(struct seq_file *seq, void *v)
170 struct fs_db *fsdb = seq->private;
171 struct mgs_tgt_srpc_conf *srpc_tgt;
174 down(&fsdb->fsdb_sem);
176 seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
177 seq_printf(seq, "flags: %#x gen: %d\n",
178 fsdb->fsdb_flags, fsdb->fsdb_gen);
179 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
180 if (test_bit(i, fsdb->fsdb_mdt_index_map))
181 seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
182 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
183 if (test_bit(i, fsdb->fsdb_ost_index_map))
184 seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
186 seq_printf(seq, "\nSecure RPC Config Rules:\n");
188 seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
189 PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
191 for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
192 srpc_tgt = srpc_tgt->mtsc_next) {
193 seq_show_srpc_rule(seq, srpc_tgt->mtsc_tgt,
194 &srpc_tgt->mtsc_rset);
196 seq_show_srpc_rule(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
202 LPROC_SEQ_FOPS_RO(mgs_live);
204 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
206 struct mgs_obd *mgs = &obd->u.mgs;
209 if (!mgs->mgs_proc_live)
211 rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
212 &mgs_live_fops, fsdb);
217 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
219 struct mgs_obd *mgs = &obd->u.mgs;
221 if (!mgs->mgs_proc_live)
224 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
228 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
229 { "uuid", lprocfs_rd_uuid, 0, 0 },
230 { "fstype", lprocfs_rd_fstype, 0, 0 },
231 { "mntdev", lprocfs_mgs_rd_mntdev, 0, 0 },
232 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
233 { "evict_client", 0, lprocfs_wr_evict_client, 0 },
237 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
241 void mgs_counter_incr(struct obd_export *exp, int opcode)
243 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
244 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
245 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
248 void mgs_stats_counter_init(struct lprocfs_stats *stats)
250 lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
251 lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
253 lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
255 lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
256 lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
259 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
261 lvars->module_vars = lprocfs_mgs_module_vars;
262 lvars->obd_vars = lprocfs_mgs_obd_vars;