Whamcloud - gitweb
LU-5275 lprocfs: sync names to upstream kernel lustre client
[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, 2014, 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 CONFIG_PROC_FS
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         struct list_head         list;
53         struct mgs_direntry     *dirent, *n;
54         struct lu_env            env;
55         int rc, len;
56
57         ENTRY;
58
59         LASSERT(obd != NULL);
60         LASSERT(obd->obd_lu_dev != NULL);
61         mgs = lu2mgs_dev(obd->obd_lu_dev);
62
63         rc = lu_env_init(&env, LCT_MG_THREAD);
64         if (rc)
65                 RETURN(rc);
66
67         rc = class_dentry_readdir(&env, mgs, &list);
68         if (rc)
69                 GOTO(out, rc);
70
71         list_for_each_entry_safe(dirent, n, &list, mde_list) {
72                 list_del_init(&dirent->mde_list);
73                 len = strlen(dirent->mde_name);
74                 if (len > 7 &&
75                     strncmp(dirent->mde_name + len - 7, "-client", len) == 0)
76                         seq_printf(seq, "%.*s\n", len - 7, dirent->mde_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 = lu2mgs_dev(obd->obd_lu_dev);
121         struct lu_target        *tgt = &mgs->mgs_lut;
122
123         read_lock(&tgt->lut_sptlrpc_lock);
124         seq_show_srpc_rules(seq, MGSSELF_NAME, &tgt->lut_sptlrpc_rset);
125         read_unlock(&tgt->lut_sptlrpc_lock);
126
127         return 0;
128 }
129 LPROC_SEQ_FOPS_RO(mgsself_srpc);
130
131 static int mgs_live_seq_show(struct seq_file *seq, void *v)
132 {
133         struct fs_db             *fsdb = seq->private;
134         struct mgs_tgt_srpc_conf *srpc_tgt;
135         int i;
136
137         mutex_lock(&fsdb->fsdb_mutex);
138
139         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
140         seq_printf(seq, "flags: %#lx     gen: %d\n",
141                    fsdb->fsdb_flags, fsdb->fsdb_gen);
142         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
143                 if (test_bit(i, fsdb->fsdb_mdt_index_map))
144                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
145         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
146                 if (test_bit(i, fsdb->fsdb_ost_index_map))
147                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
148
149         seq_printf(seq, "\nSecure RPC Config Rules:\n");
150 #if 0
151         seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
152                    PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
153 #endif
154         for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
155              srpc_tgt = srpc_tgt->mtsc_next) {
156                 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
157                                     &srpc_tgt->mtsc_rset);
158         }
159         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
160
161         lprocfs_rd_ir_state(seq, fsdb);
162
163         mutex_unlock(&fsdb->fsdb_mutex);
164         return 0;
165 }
166
167 static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
168                                   size_t len, loff_t *off)
169 {
170         struct seq_file *seq  = file->private_data;
171         struct fs_db    *fsdb = seq->private;
172         ssize_t rc;
173
174         rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
175         if (rc >= 0)
176                 rc = len;
177         return rc;
178 }
179 LPROC_SEQ_FOPS(mgs_live);
180
181 int lproc_mgs_add_live(struct mgs_device *mgs, struct fs_db *fsdb)
182 {
183         int rc;
184
185         if (!mgs->mgs_proc_live)
186                 return 0;
187         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0644,
188                                 &mgs_live_fops, fsdb);
189
190         return 0;
191 }
192
193 int lproc_mgs_del_live(struct mgs_device *mgs, struct fs_db *fsdb)
194 {
195         if (!mgs->mgs_proc_live)
196                 return 0;
197
198         /* didn't create the proc file for MGSSELF_NAME */
199         if (!test_bit(FSDB_MGS_SELF, &fsdb->fsdb_flags))
200                 lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
201         return 0;
202 }
203
204 LPROC_SEQ_FOPS_RO_TYPE(mgs, uuid);
205 LPROC_SEQ_FOPS_RO_TYPE(mgs, num_exports);
206 LPROC_SEQ_FOPS_RO_TYPE(mgs, hash);
207 LPROC_SEQ_FOPS_WO_TYPE(mgs, evict_client);
208 LPROC_SEQ_FOPS_RW_TYPE(mgs, ir_timeout);
209
210 static struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
211         { .name =       "uuid",
212           .fops =       &mgs_uuid_fops          },
213         { .name =       "num_exports",
214           .fops =       &mgs_num_exports_fops   },
215         { .name =       "hash_stats",
216           .fops =       &mgs_hash_fops          },
217         { .name =       "evict_client",
218           .fops =       &mgs_evict_client_fops  },
219         { .name =       "ir_timeout",
220           .fops =       &mgs_ir_timeout_fops    },
221         { NULL }
222 };
223
224 int lproc_mgs_setup(struct mgs_device *mgs, const char *osd_name)
225 {
226         struct obd_device *obd = mgs->mgs_obd;
227         struct obd_device *osd_obd = mgs->mgs_bottom->dd_lu_dev.ld_obd;
228         int                osd_len = strlen(osd_name) - strlen("-osd");
229         int                rc;
230
231         obd->obd_vars = lprocfs_mgs_obd_vars;
232         rc = lprocfs_obd_setup(obd);
233         if (rc != 0)
234                 GOTO(out, rc);
235
236         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
237                                     &mgs_fs_fops, obd);
238         if (rc != 0)
239                 GOTO(out, rc);
240
241         rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0400,
242                                     &mgsself_srpc_fops, obd);
243         if (rc != 0)
244                 GOTO(out, rc);
245
246         mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
247                                               NULL, NULL);
248         if (IS_ERR(mgs->mgs_proc_live)) {
249                 rc = PTR_ERR(mgs->mgs_proc_live);
250                 mgs->mgs_proc_live = NULL;
251                 GOTO(out, rc);
252         }
253
254         obd->obd_proc_exports_entry = lprocfs_register("exports",
255                                                        obd->obd_proc_entry,
256                                                        NULL, NULL);
257         if (IS_ERR(obd->obd_proc_exports_entry)) {
258                 rc = PTR_ERR(obd->obd_proc_exports_entry);
259                 obd->obd_proc_exports_entry = NULL;
260                 GOTO(out, rc);
261         }
262
263         mgs->mgs_proc_osd = lprocfs_add_symlink("osd",
264                                                 obd->obd_proc_entry,
265                                                 "../../%s/%.*s",
266                                                 osd_obd->obd_type->typ_name,
267                                                 osd_len, /* Strip "-osd". */
268                                                 osd_name);
269         if (mgs->mgs_proc_osd == NULL)
270                 GOTO(out, rc = -ENOMEM);
271
272         mgs->mgs_proc_mntdev = lprocfs_add_symlink("mntdev",
273                                                    obd->obd_proc_entry,
274                                                    "osd/mntdev");
275         if (mgs->mgs_proc_mntdev == NULL)
276                 GOTO(out, rc = -ENOMEM);
277
278         mgs->mgs_proc_fstype = lprocfs_add_symlink("fstype",
279                                                    obd->obd_proc_entry,
280                                                    "osd/fstype");
281         if (mgs->mgs_proc_fstype == NULL)
282                 GOTO(out, rc = -ENOMEM);
283
284 out:
285         if (rc != 0)
286                 lproc_mgs_cleanup(mgs);
287
288         return rc;
289 }
290
291 void lproc_mgs_cleanup(struct mgs_device *mgs)
292 {
293         struct obd_device *obd = mgs->mgs_obd;
294
295         if (obd == NULL)
296                 return;
297
298         if (mgs->mgs_proc_osd != NULL)
299                 lprocfs_remove(&mgs->mgs_proc_osd);
300
301         if (mgs->mgs_proc_fstype != NULL)
302                 lprocfs_remove(&mgs->mgs_proc_fstype);
303
304         if (mgs->mgs_proc_mntdev != NULL)
305                 lprocfs_remove(&mgs->mgs_proc_mntdev);
306
307         if (mgs->mgs_proc_live != NULL) {
308                 /* Should be no live entries */
309                 lprocfs_remove(&mgs->mgs_proc_live);
310                 mgs->mgs_proc_live = NULL;
311         }
312
313         lprocfs_free_per_client_stats(obd);
314         lprocfs_obd_cleanup(obd);
315         lprocfs_free_obd_stats(obd);
316         lprocfs_free_md_stats(obd);
317 }
318
319 void mgs_counter_incr(struct obd_export *exp, int opcode)
320 {
321         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
322         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
323                 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
324 }
325
326 void mgs_stats_counter_init(struct lprocfs_stats *stats)
327 {
328         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
329         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
330                              "reqs");
331         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
332                              "reqs");
333         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
334         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
335 }
336 #endif