Whamcloud - gitweb
LU-2484 mgs: remove unused md_stats
[fs/lustre-release.git] / lustre / mgs / lproc_mgs.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
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 mgs_fs_seq_show(struct seq_file *seq, void *v)
49 {
50         struct obd_device *obd = seq->private;
51         struct mgs_device *mgs;
52         cfs_list_t list;
53         struct mgs_direntry *dirent, *n;
54         struct lu_env env;
55         int rc, len;
56         ENTRY;
57
58         LASSERT(obd != NULL);
59         LASSERT(obd->obd_lu_dev != NULL);
60         mgs = lu2mgs_dev(obd->obd_lu_dev);
61
62         rc = lu_env_init(&env, LCT_MG_THREAD);
63         if (rc)
64                 RETURN(rc);
65
66         rc = class_dentry_readdir(&env, mgs, &list);
67         if (rc) {
68                 CERROR("Can't read config dir\n");
69                 GOTO(out, rc);
70         }
71         cfs_list_for_each_entry_safe(dirent, n, &list, list) {
72                 cfs_list_del(&dirent->list);
73                 len = strlen(dirent->name);
74                 if (len > 7 &&
75                     strncmp(dirent->name + len - 7, "-client", len) == 0)
76                         seq_printf(seq, "%.*s\n", len - 7, dirent->name);
77                 mgs_direntry_free(dirent);
78         }
79
80 out:
81         lu_env_fini(&env);
82         RETURN(0);
83 }
84
85 LPROC_SEQ_FOPS_RO(mgs_fs);
86
87 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
88                                 struct sptlrpc_rule_set *rset)
89 {
90         struct sptlrpc_rule    *r;
91         char                    dirbuf[10];
92         char                    flvrbuf[40];
93         char                   *net;
94         int                     i;
95
96         for (i = 0; i < rset->srs_nrule; i++) {
97                 r = &rset->srs_rules[i];
98
99                 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
100                         net = "default";
101                 else
102                         net = libcfs_net2str(r->sr_netid);
103
104                 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
105                         dirbuf[0] = '\0';
106                 else
107                         snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
108                                  sptlrpc_part2name(r->sr_from),
109                                  sptlrpc_part2name(r->sr_to));
110
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);
114         }
115 }
116
117 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
118 {
119         struct obd_device *obd = seq->private;
120         struct mgs_device *mgs;
121         struct fs_db      *fsdb;
122         struct lu_env      env;
123         int                rc;
124
125         LASSERT(obd != NULL);
126         LASSERT(obd->obd_lu_dev != NULL);
127         mgs = lu2mgs_dev(obd->obd_lu_dev);
128
129         rc = lu_env_init(&env, LCT_MG_THREAD);
130         if (rc)
131                 return rc;
132
133         rc = mgs_find_or_make_fsdb(&env, mgs, MGSSELF_NAME, &fsdb);
134         if (rc)
135                 goto out;
136
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);
140
141 out:
142         lu_env_fini(&env);
143         return 0;
144 }
145
146 LPROC_SEQ_FOPS_RO(mgsself_srpc);
147
148 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
149 {
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_len = strlen(osd_name) - strlen("-osd");
153         int                rc;
154         struct lprocfs_static_vars lvars;
155
156         lprocfs_mgs_init_vars(&lvars);
157         rc = lprocfs_obd_setup(obd, lvars.obd_vars);
158         if (rc != 0)
159                 GOTO(out, rc);
160
161         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
162                                     &mgs_fs_fops, obd);
163         if (rc != 0)
164                 GOTO(out, rc);
165
166         rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0400,
167                                     &mgsself_srpc_fops, obd);
168         if (rc != 0)
169                 GOTO(out, rc);
170
171         mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
172                                               NULL, NULL);
173         if (IS_ERR(mgs->mgs_proc_live)) {
174                 rc = PTR_ERR(mgs->mgs_proc_live);
175                 mgs->mgs_proc_live = NULL;
176                 GOTO(out, rc);
177         }
178
179         obd->obd_proc_exports_entry = lprocfs_register("exports",
180                                                        obd->obd_proc_entry,
181                                                        NULL, NULL);
182         if (IS_ERR(obd->obd_proc_exports_entry)) {
183                 rc = PTR_ERR(obd->obd_proc_exports_entry);
184                 obd->obd_proc_exports_entry = NULL;
185                 GOTO(out, rc);
186         }
187
188         mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
189                                                 obd->obd_proc_entry,
190                                                 "../../%s/%.*s",
191                                                 osd_obd->obd_type->typ_name,
192                                                 osd_len, /* Strip "-osd". */
193                                                 osd_name);
194         if (mgs->mgs_proc_osd == NULL)
195                 GOTO(out, rc = -ENOMEM);
196
197         mgs->mgs_proc_mntdev = lprocfs_add_symlink("mntdev",
198                                                    obd->obd_proc_entry,
199                                                    "osd/mntdev");
200         if (mgs->mgs_proc_mntdev == NULL)
201                 GOTO(out, rc = -ENOMEM);
202
203         mgs->mgs_proc_fstype = lprocfs_add_symlink("fstype",
204                                                    obd->obd_proc_entry,
205                                                    "osd/fstype");
206         if (mgs->mgs_proc_fstype == NULL)
207                 GOTO(out, rc = -ENOMEM);
208
209 out:
210         if (rc != 0)
211                 lproc_mgs_cleanup(mgs);
212
213         return rc;
214 }
215
216 void lproc_mgs_cleanup(struct mgs_device *mgs)
217 {
218         struct obd_device *obd = mgs->mgs_obd;
219
220         if (obd == NULL)
221                 return;
222
223         if (mgs->mgs_proc_osd != NULL)
224                 lprocfs_remove(&mgs->mgs_proc_osd);
225
226         if (mgs->mgs_proc_fstype != NULL)
227                 lprocfs_remove(&mgs->mgs_proc_fstype);
228
229         if (mgs->mgs_proc_mntdev != NULL)
230                 lprocfs_remove(&mgs->mgs_proc_mntdev);
231
232         if (mgs->mgs_proc_live != NULL) {
233                 /* Should be no live entries */
234                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
235                 lprocfs_remove(&mgs->mgs_proc_live);
236                 mgs->mgs_proc_live = NULL;
237         }
238
239         lprocfs_free_per_client_stats(obd);
240         lprocfs_obd_cleanup(obd);
241         lprocfs_free_obd_stats(obd);
242         lprocfs_free_md_stats(obd);
243 }
244
245 static int mgs_live_seq_show(struct seq_file *seq, void *v)
246 {
247         struct fs_db             *fsdb = seq->private;
248         struct mgs_tgt_srpc_conf *srpc_tgt;
249         int i;
250
251         mutex_lock(&fsdb->fsdb_mutex);
252
253         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
254         seq_printf(seq, "flags: %#lx     gen: %d\n",
255                    fsdb->fsdb_flags, fsdb->fsdb_gen);
256         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
257                 if (test_bit(i, fsdb->fsdb_mdt_index_map))
258                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
259         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
260                 if (test_bit(i, fsdb->fsdb_ost_index_map))
261                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
262
263         seq_printf(seq, "\nSecure RPC Config Rules:\n");
264 #if 0
265         seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
266                    PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
267 #endif
268         for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
269              srpc_tgt = srpc_tgt->mtsc_next) {
270                 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
271                                     &srpc_tgt->mtsc_rset);
272         }
273         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
274
275         lprocfs_rd_ir_state(seq, fsdb);
276
277         mutex_unlock(&fsdb->fsdb_mutex);
278         return 0;
279 }
280
281 static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
282                                   size_t len, loff_t *off)
283 {
284         struct seq_file *seq  = file->private_data;
285         struct fs_db    *fsdb = seq->private;
286         ssize_t rc;
287
288         rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
289         if (rc >= 0)
290                 rc = len;
291         return rc;
292 }
293 LPROC_SEQ_FOPS(mgs_live);
294
295 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
296 {
297         int rc;
298
299         if (!mgs->mgs_proc_live)
300                 return 0;
301         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644,
302                                 &mgs_live_fops, fsdb);
303
304         return 0;
305 }
306
307 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
308 {
309         if (!mgs->mgs_proc_live)
310                 return 0;
311
312         /* didn't create the proc file for MGSSELF_NAME */
313         if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
314                 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
315         return 0;
316 }
317
318 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
319         { "uuid",            lprocfs_rd_uuid,        0, 0 },
320         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
321         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
322         { "evict_client",    0, lprocfs_wr_evict_client, 0 },
323         { "ir_timeout",      lprocfs_rd_ir_timeout, lprocfs_wr_ir_timeout, 0 },
324         { 0 }
325 };
326
327 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
328         { 0 }
329 };
330
331 void mgs_counter_incr(struct obd_export *exp, int opcode)
332 {
333         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
334         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
335                 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
336 }
337
338 void mgs_stats_counter_init(struct lprocfs_stats *stats)
339 {
340         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
341         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
342                              "reqs");
343         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
344                              "reqs");
345         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
346         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
347 }
348
349 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
350 {
351     lvars->module_vars  = lprocfs_mgs_module_vars;
352     lvars->obd_vars     = lprocfs_mgs_obd_vars;
353 }
354 #endif