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, Whamcloud, Inc.
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 mgs_fs_seq_show(struct seq_file *seq, void *v)
50 struct obd_device *obd = seq->private;
51 struct mgs_device *mgs;
53 struct mgs_direntry *dirent, *n;
59 LASSERT(obd->obd_lu_dev != NULL);
60 mgs = lu2mgs_dev(obd->obd_lu_dev);
62 rc = lu_env_init(&env, LCT_MG_THREAD);
66 rc = class_dentry_readdir(&env, mgs, &list);
68 CERROR("Can't read config dir\n");
71 cfs_list_for_each_entry_safe(dirent, n, &list, list) {
72 cfs_list_del(&dirent->list);
73 len = strlen(dirent->name);
75 strncmp(dirent->name + len - 7, "-client", len) == 0)
76 seq_printf(seq, "%.*s\n", len - 7, dirent->name);
77 mgs_direntry_free(dirent);
85 LPROC_SEQ_FOPS_RO(mgs_fs);
87 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
88 struct sptlrpc_rule_set *rset)
90 struct sptlrpc_rule *r;
96 for (i = 0; i < rset->srs_nrule; i++) {
97 r = &rset->srs_rules[i];
99 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
102 net = libcfs_net2str(r->sr_netid);
104 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
107 snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
108 sptlrpc_part2name(r->sr_from),
109 sptlrpc_part2name(r->sr_to));
111 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
112 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
113 net, dirbuf, flvrbuf);
117 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
119 struct obd_device *obd = seq->private;
120 struct mgs_device *mgs;
125 LASSERT(obd != NULL);
126 LASSERT(obd->obd_lu_dev != NULL);
127 mgs = lu2mgs_dev(obd->obd_lu_dev);
129 rc = lu_env_init(&env, LCT_MG_THREAD);
133 rc = mgs_find_or_make_fsdb(&env, mgs, MGSSELF_NAME, &fsdb);
137 mutex_lock(&fsdb->fsdb_mutex);
138 seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
139 mutex_unlock(&fsdb->fsdb_mutex);
146 LPROC_SEQ_FOPS_RO(mgsself_srpc);
148 int lproc_mgs_setup(struct mgs_device *mgs, char *osd_name)
150 struct obd_device *obd = mgs->mgs_obd;
151 struct obd_device *osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
152 int osd_suffix = strlen(osd_name) - strlen("-osd");
153 char c = osd_name[osd_suffix];
156 rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
158 rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
159 &mgsself_srpc_fops, obd);
161 mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
163 if (IS_ERR(mgs->mgs_proc_live)) {
164 rc = PTR_ERR(mgs->mgs_proc_live);
165 CERROR("error %d setting up lprocfs for %s\n", rc, "live");
166 mgs->mgs_proc_live = NULL;
169 obd->obd_proc_exports_entry = lprocfs_register("exports",
172 if (IS_ERR(obd->obd_proc_exports_entry)) {
173 rc = PTR_ERR(obd->obd_proc_exports_entry);
174 CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
175 obd->obd_proc_exports_entry = NULL;
178 osd_name[osd_suffix] = '\0'; /* Remove the "-osd" suffix. */
179 mgs->mgs_proc_mntdev = lprocfs_add_symlink("mntdev",
181 "../../%s/%s/mntdev",
182 osd_obd->obd_type->typ_name,
184 osd_name[osd_suffix] = c;
185 if (mgs->mgs_proc_mntdev == NULL)
191 int lproc_mgs_cleanup(struct mgs_device *mgs)
193 struct obd_device *obd = mgs->mgs_obd;
198 if (mgs->mgs_proc_mntdev)
199 lprocfs_remove(&mgs->mgs_proc_mntdev);
200 if (mgs->mgs_proc_live) {
201 /* Should be no live entries */
202 LASSERT(mgs->mgs_proc_live->subdir == NULL);
203 lprocfs_remove(&mgs->mgs_proc_live);
204 mgs->mgs_proc_live = NULL;
206 lprocfs_free_per_client_stats(obd);
207 lprocfs_free_obd_stats(obd);
208 lprocfs_free_md_stats(obd);
210 return lprocfs_obd_cleanup(obd);
213 static int mgs_live_seq_show(struct seq_file *seq, void *v)
215 struct fs_db *fsdb = seq->private;
216 struct mgs_tgt_srpc_conf *srpc_tgt;
219 mutex_lock(&fsdb->fsdb_mutex);
221 seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
222 seq_printf(seq, "flags: %#lx gen: %d\n",
223 fsdb->fsdb_flags, fsdb->fsdb_gen);
224 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
225 if (test_bit(i, fsdb->fsdb_mdt_index_map))
226 seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
227 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
228 if (test_bit(i, fsdb->fsdb_ost_index_map))
229 seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
231 seq_printf(seq, "\nSecure RPC Config Rules:\n");
233 seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
234 PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
236 for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
237 srpc_tgt = srpc_tgt->mtsc_next) {
238 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
239 &srpc_tgt->mtsc_rset);
241 seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
243 lprocfs_rd_ir_state(seq, fsdb);
245 mutex_unlock(&fsdb->fsdb_mutex);
249 static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
250 size_t len, loff_t *off)
252 struct seq_file *seq = file->private_data;
253 struct fs_db *fsdb = seq->private;
256 rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
261 LPROC_SEQ_FOPS(mgs_live);
263 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
267 if (!mgs->mgs_proc_live)
269 rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
270 &mgs_live_fops, fsdb);
275 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
277 if (!mgs->mgs_proc_live)
280 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
284 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
285 { "uuid", lprocfs_rd_uuid, 0, 0 },
286 { "fstype", lprocfs_rd_fstype, 0, 0 },
287 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
288 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
289 { "evict_client", 0, lprocfs_wr_evict_client, 0 },
290 { "ir_timeout", lprocfs_rd_ir_timeout, lprocfs_wr_ir_timeout, 0 },
294 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
298 void mgs_counter_incr(struct obd_export *exp, int opcode)
300 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
301 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
302 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
305 void mgs_stats_counter_init(struct lprocfs_stats *stats)
307 lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
308 lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
310 lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
312 lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
313 lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
316 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
318 lvars->module_vars = lprocfs_mgs_module_vars;
319 lvars->obd_vars = lprocfs_mgs_obd_vars;