Whamcloud - gitweb
LU-812 compat: clean up mutex lock to use kernel mutex primitive
[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 (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2011, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  */
38 #define DEBUG_SUBSYSTEM S_CLASS
39
40 #include <linux/version.h>
41 #include <asm/statfs.h>
42 #include <obd.h>
43 #include <obd_class.h>
44 #include <lprocfs_status.h>
45 #include <lustre_param.h>
46 #include "mgs_internal.h"
47
48 #ifdef LPROCFS
49
50 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
51                                  int *eof, void *data)
52 {
53         struct obd_device* obd = (struct obd_device *)data;
54
55         LASSERT(obd != NULL);
56         LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
57         *eof = 1;
58
59         return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
60 }
61
62 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
63 {
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;
68         int rc, len;
69         ENTRY;
70
71         LASSERT(obd != NULL);
72         rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
73                                   mgs->mgs_vfsmnt, &dentry_list);
74         if (rc) {
75                 CERROR("Can't read config dir\n");
76                 RETURN(rc);
77         }
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",
82                                           len) == 0)) {
83                         seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
84                 }
85                 OBD_FREE(dirent, sizeof(*dirent));
86         }
87
88         RETURN(0);
89 }
90
91 LPROC_SEQ_FOPS_RO(mgs_fs);
92
93 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
94                                 struct sptlrpc_rule_set *rset)
95 {
96         struct sptlrpc_rule    *r;
97         char                    dirbuf[10];
98         char                    flvrbuf[40];
99         char                   *net;
100         int                     i;
101
102         for (i = 0; i < rset->srs_nrule; i++) {
103                 r = &rset->srs_rules[i];
104
105                 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
106                         net = "default";
107                 else
108                         net = libcfs_net2str(r->sr_netid);
109
110                 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
111                         dirbuf[0] = '\0';
112                 else
113                         snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
114                                  sptlrpc_part2name(r->sr_from),
115                                  sptlrpc_part2name(r->sr_to));
116
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);
120         }
121 }
122
123 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
124 {
125         struct obd_device *obd = seq->private;
126         struct fs_db      *fsdb;
127         int                rc;
128
129         rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
130         if (rc)
131                 return rc;
132
133         cfs_mutex_lock(&fsdb->fsdb_mutex);
134         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
135         cfs_mutex_unlock(&fsdb->fsdb_mutex);
136         return 0;
137 }
138
139 LPROC_SEQ_FOPS_RO(mgsself_srpc);
140
141 int lproc_mgs_setup(struct obd_device *obd)
142 {
143         struct mgs_obd *mgs = &obd->u.mgs;
144         int rc;
145
146         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
147                                     &mgs_fs_fops, obd);
148         rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
149                                     &mgsself_srpc_fops, obd);
150
151         mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
152                                               NULL, NULL);
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;
157         }
158
159         obd->obd_proc_exports_entry = lprocfs_register("exports",
160                                                        obd->obd_proc_entry,
161                                                        NULL, NULL);
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;
166         }
167
168         return rc;
169 }
170
171 int lproc_mgs_cleanup(struct obd_device *obd)
172 {
173         struct mgs_obd *mgs;
174
175         if (!obd)
176                 return -EINVAL;
177
178         mgs = &obd->u.mgs;
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;
184         }
185         lprocfs_free_per_client_stats(obd);
186         lprocfs_free_obd_stats(obd);
187         lprocfs_free_md_stats(obd);
188
189         return lprocfs_obd_cleanup(obd);
190 }
191
192 static int mgs_live_seq_show(struct seq_file *seq, void *v)
193 {
194         struct fs_db             *fsdb = seq->private;
195         struct mgs_tgt_srpc_conf *srpc_tgt;
196         int i;
197
198         cfs_mutex_lock(&fsdb->fsdb_mutex);
199
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);
209
210         seq_printf(seq, "\nSecure RPC Config Rules:\n");
211 #if 0
212         seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
213                    PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
214 #endif
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);
219         }
220         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
221
222         lprocfs_rd_ir_state(seq, fsdb);
223
224         cfs_mutex_unlock(&fsdb->fsdb_mutex);
225         return 0;
226 }
227
228 static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
229                                   size_t len, loff_t *off)
230 {
231         struct seq_file *seq  = file->private_data;
232         struct fs_db    *fsdb = seq->private;
233         ssize_t rc;
234
235         rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
236         if (rc >= 0)
237                 rc = len;
238         return rc;
239 }
240 LPROC_SEQ_FOPS(mgs_live);
241
242 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
243 {
244         struct mgs_obd *mgs = &obd->u.mgs;
245         int rc;
246
247         if (!mgs->mgs_proc_live)
248                 return 0;
249         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
250                                 &mgs_live_fops, fsdb);
251
252         return 0;
253 }
254
255 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
256 {
257         struct mgs_obd *mgs = &obd->u.mgs;
258
259         if (!mgs->mgs_proc_live)
260                 return 0;
261
262         lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
263         return 0;
264 }
265
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 },
274         { 0 }
275 };
276
277 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
278         { 0 }
279 };
280
281 void mgs_counter_incr(struct obd_export *exp, int opcode)
282 {
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);
286 }
287
288 void mgs_stats_counter_init(struct lprocfs_stats *stats)
289 {
290         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
291         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
292                              "reqs");
293         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
294                              "reqs");
295         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
296         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
297 }
298
299 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
300 {
301     lvars->module_vars  = lprocfs_mgs_module_vars;
302     lvars->obd_vars     = lprocfs_mgs_obd_vars;
303 }
304 #endif