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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 #define DEBUG_SUBSYSTEM S_CLASS
40 #include <linux/version.h>
41 #include <asm/statfs.h>
43 #include <obd_class.h>
44 #include <lprocfs_status.h>
45 #include <lustre_param.h>
46 #include "mgs_internal.h"
50 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
53 struct obd_device* obd = (struct obd_device *)data;
56 LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
59 return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
62 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
64 struct obd_device *obd = seq->private;
65 struct mgs_obd *mgs = &obd->u.mgs;
66 cfs_list_t dentry_list;
67 struct l_linux_dirent *dirent, *n;
72 rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
73 mgs->mgs_vfsmnt, &dentry_list);
75 CERROR("Can't read config dir\n");
78 cfs_list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
79 cfs_list_del(&dirent->lld_list);
80 len = strlen(dirent->lld_name);
81 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
83 seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
85 OBD_FREE(dirent, sizeof(*dirent));
91 LPROC_SEQ_FOPS_RO(mgs_fs);
93 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
94 struct sptlrpc_rule_set *rset)
96 struct sptlrpc_rule *r;
102 for (i = 0; i < rset->srs_nrule; i++) {
103 r = &rset->srs_rules[i];
105 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
108 net = libcfs_net2str(r->sr_netid);
110 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
113 snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
114 sptlrpc_part2name(r->sr_from),
115 sptlrpc_part2name(r->sr_to));
117 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
118 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
119 net, dirbuf, flvrbuf);
123 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
125 struct obd_device *obd = seq->private;
129 rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
133 cfs_down(&fsdb->fsdb_sem);
134 seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
135 cfs_up(&fsdb->fsdb_sem);
139 LPROC_SEQ_FOPS_RO(mgsself_srpc);
141 int lproc_mgs_setup(struct obd_device *obd)
143 struct mgs_obd *mgs = &obd->u.mgs;
146 rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
148 rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
149 &mgsself_srpc_fops, obd);
151 mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
153 if (IS_ERR(mgs->mgs_proc_live)) {
154 rc = PTR_ERR(mgs->mgs_proc_live);
155 CERROR("error %d setting up lprocfs for %s\n", rc, "live");
156 mgs->mgs_proc_live = NULL;
159 obd->obd_proc_exports_entry = lprocfs_register("exports",
162 if (IS_ERR(obd->obd_proc_exports_entry)) {
163 rc = PTR_ERR(obd->obd_proc_exports_entry);
164 CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
165 obd->obd_proc_exports_entry = NULL;
171 int lproc_mgs_cleanup(struct obd_device *obd)
179 if (mgs->mgs_proc_live) {
180 /* Should be no live entries */
181 LASSERT(mgs->mgs_proc_live->subdir == NULL);
182 lprocfs_remove(&mgs->mgs_proc_live);
183 mgs->mgs_proc_live = NULL;
185 lprocfs_free_per_client_stats(obd);
186 lprocfs_free_obd_stats(obd);
187 lprocfs_free_md_stats(obd);
189 return lprocfs_obd_cleanup(obd);
192 static int mgs_live_seq_show(struct seq_file *seq, void *v)
194 struct fs_db *fsdb = seq->private;
195 struct mgs_tgt_srpc_conf *srpc_tgt;
198 cfs_down(&fsdb->fsdb_sem);
200 seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
201 seq_printf(seq, "flags: %#lx gen: %d\n",
202 fsdb->fsdb_flags, fsdb->fsdb_gen);
203 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
204 if (cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
205 seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
206 for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
207 if (cfs_test_bit(i, fsdb->fsdb_ost_index_map))
208 seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
210 seq_printf(seq, "\nSecure RPC Config Rules:\n");
212 seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
213 PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
215 for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
216 srpc_tgt = srpc_tgt->mtsc_next) {
217 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
218 &srpc_tgt->mtsc_rset);
220 seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
222 lprocfs_rd_ir_state(seq, fsdb);
224 cfs_up(&fsdb->fsdb_sem);
228 static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
229 size_t len, loff_t *off)
231 struct seq_file *seq = file->private_data;
232 struct fs_db *fsdb = seq->private;
235 rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
240 LPROC_SEQ_FOPS(mgs_live);
242 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
244 struct mgs_obd *mgs = &obd->u.mgs;
247 if (!mgs->mgs_proc_live)
249 rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
250 &mgs_live_fops, fsdb);
255 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
257 struct mgs_obd *mgs = &obd->u.mgs;
259 if (!mgs->mgs_proc_live)
262 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
266 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
267 { "uuid", lprocfs_rd_uuid, 0, 0 },
268 { "fstype", lprocfs_rd_fstype, 0, 0 },
269 { "mntdev", lprocfs_mgs_rd_mntdev, 0, 0 },
270 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
271 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
272 { "evict_client", 0, lprocfs_wr_evict_client, 0 },
273 { "ir_timeout", lprocfs_rd_ir_timeout, lprocfs_wr_ir_timeout, 0 },
277 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
281 void mgs_counter_incr(struct obd_export *exp, int opcode)
283 lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
284 if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
285 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
288 void mgs_stats_counter_init(struct lprocfs_stats *stats)
290 lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
291 lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
293 lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
295 lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
296 lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
299 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
301 lvars->module_vars = lprocfs_mgs_module_vars;
302 lvars->obd_vars = lprocfs_mgs_obd_vars;