Whamcloud - gitweb
2d93e548a4f7fd45b9bfb7f8ca6d96f762163022
[fs/lustre-release.git] / lustre / mgs / lproc_mgs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36 #define DEBUG_SUBSYSTEM S_CLASS
37
38 #include <linux/version.h>
39 #include <asm/statfs.h>
40 #include <obd.h>
41 #include <obd_class.h>
42 #include <lprocfs_status.h>
43 #include <lustre_param.h>
44 #include "mgs_internal.h"
45
46 #ifdef LPROCFS
47
48 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
49                                  int *eof, void *data)
50 {
51         struct obd_device* obd = (struct obd_device *)data;
52
53         LASSERT(obd != NULL);
54         LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
55         *eof = 1;
56
57         return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
58 }
59
60 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
61 {
62         struct obd_device *obd = seq->private;
63         struct mgs_obd *mgs = &obd->u.mgs;
64         cfs_list_t dentry_list;
65         struct l_linux_dirent *dirent, *n;
66         int rc, len;
67         ENTRY;
68
69         LASSERT(obd != NULL);
70         rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
71                                   mgs->mgs_vfsmnt, &dentry_list);
72         if (rc) {
73                 CERROR("Can't read config dir\n");
74                 RETURN(rc);
75         }
76         cfs_list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
77                 cfs_list_del(&dirent->lld_list);
78                 len = strlen(dirent->lld_name);
79                 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
80                                           len) == 0)) {
81                         seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
82                 }
83                 OBD_FREE(dirent, sizeof(*dirent));
84         }
85
86         RETURN(0);
87 }
88
89 LPROC_SEQ_FOPS_RO(mgs_fs);
90
91 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
92                                 struct sptlrpc_rule_set *rset)
93 {
94         struct sptlrpc_rule    *r;
95         char                    dirbuf[10];
96         char                    flvrbuf[40];
97         char                   *net;
98         int                     i;
99
100         for (i = 0; i < rset->srs_nrule; i++) {
101                 r = &rset->srs_rules[i];
102
103                 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
104                         net = "default";
105                 else
106                         net = libcfs_net2str(r->sr_netid);
107
108                 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
109                         dirbuf[0] = '\0';
110                 else
111                         snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
112                                  sptlrpc_part2name(r->sr_from),
113                                  sptlrpc_part2name(r->sr_to));
114
115                 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
116                 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
117                            net, dirbuf, flvrbuf);
118         }
119 }
120
121 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
122 {
123         struct obd_device *obd = seq->private;
124         struct fs_db      *fsdb;
125         int                rc;
126
127         rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
128         if (rc)
129                 return rc;
130
131         cfs_down(&fsdb->fsdb_sem);
132         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
133         cfs_up(&fsdb->fsdb_sem);
134         return 0;
135 }
136
137 LPROC_SEQ_FOPS_RO(mgsself_srpc);
138
139 int lproc_mgs_setup(struct obd_device *obd)
140 {
141         struct mgs_obd *mgs = &obd->u.mgs;
142         int rc;
143
144         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
145                                     &mgs_fs_fops, obd);
146         rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
147                                     &mgsself_srpc_fops, obd);
148
149         mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
150                                               NULL, NULL);
151         if (IS_ERR(mgs->mgs_proc_live)) {
152                 rc = PTR_ERR(mgs->mgs_proc_live);
153                 CERROR("error %d setting up lprocfs for %s\n", rc, "live");
154                 mgs->mgs_proc_live = NULL;
155         }
156
157         obd->obd_proc_exports_entry = lprocfs_register("exports",
158                                                        obd->obd_proc_entry,
159                                                        NULL, NULL);
160         if (IS_ERR(obd->obd_proc_exports_entry)) {
161                 rc = PTR_ERR(obd->obd_proc_exports_entry);
162                 CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
163                 obd->obd_proc_exports_entry = NULL;
164         }
165
166         return rc;
167 }
168
169 int lproc_mgs_cleanup(struct obd_device *obd)
170 {
171         struct mgs_obd *mgs;
172
173         if (!obd)
174                 return -EINVAL;
175
176         mgs = &obd->u.mgs;
177         if (mgs->mgs_proc_live) {
178                 /* Should be no live entries */
179                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
180                 lprocfs_remove(&mgs->mgs_proc_live);
181                 mgs->mgs_proc_live = NULL;
182         }
183         lprocfs_free_per_client_stats(obd);
184         lprocfs_free_obd_stats(obd);
185         lprocfs_free_md_stats(obd);
186
187         return lprocfs_obd_cleanup(obd);
188 }
189
190 static int mgs_live_seq_show(struct seq_file *seq, void *v)
191 {
192         struct fs_db             *fsdb = seq->private;
193         struct mgs_tgt_srpc_conf *srpc_tgt;
194         int i;
195
196         cfs_down(&fsdb->fsdb_sem);
197
198         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
199         seq_printf(seq, "flags: %#x     gen: %d\n",
200                    fsdb->fsdb_flags, fsdb->fsdb_gen);
201         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
202                  if (cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
203                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
204         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
205                  if (cfs_test_bit(i, fsdb->fsdb_ost_index_map))
206                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
207
208         seq_printf(seq, "\nSecure RPC Config Rules:\n");
209 #if 0
210         seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
211                    PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
212 #endif
213         for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
214              srpc_tgt = srpc_tgt->mtsc_next) {
215                 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
216                                     &srpc_tgt->mtsc_rset);
217         }
218         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
219
220         cfs_up(&fsdb->fsdb_sem);
221         return 0;
222 }
223
224 LPROC_SEQ_FOPS_RO(mgs_live);
225
226 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
227 {
228         struct mgs_obd *mgs = &obd->u.mgs;
229         int rc;
230
231         if (!mgs->mgs_proc_live)
232                 return 0;
233         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
234                                 &mgs_live_fops, fsdb);
235
236         return 0;
237 }
238
239 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
240 {
241         struct mgs_obd *mgs = &obd->u.mgs;
242
243         if (!mgs->mgs_proc_live)
244                 return 0;
245
246         lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
247         return 0;
248 }
249
250 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
251         { "uuid",            lprocfs_rd_uuid,        0, 0 },
252         { "fstype",          lprocfs_rd_fstype,      0, 0 },
253         { "mntdev",          lprocfs_mgs_rd_mntdev,  0, 0 },
254         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
255         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
256         { "evict_client",    0, lprocfs_wr_evict_client, 0 },
257         { 0 }
258 };
259
260 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
261         { 0 }
262 };
263
264 void mgs_counter_incr(struct obd_export *exp, int opcode)
265 {
266         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
267         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
268                 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
269 }
270
271 void mgs_stats_counter_init(struct lprocfs_stats *stats)
272 {
273         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
274         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
275                              "reqs");
276         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
277                              "reqs");
278         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
279         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
280 }
281
282 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
283 {
284     lvars->module_vars  = lprocfs_mgs_module_vars;
285     lvars->obd_vars     = lprocfs_mgs_obd_vars;
286 }
287 #endif