Whamcloud - gitweb
fix typo in procfs cleanup.
[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  *  Copyright (C) 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of the Lustre file system, http://www.lustre.org
7  *   Lustre is a trademark of Cluster File Systems, Inc.
8  *
9  *   You may have signed or agreed to another license before downloading
10  *   this software.  If so, you are bound by the terms and conditions
11  *   of that agreement, and the following does not apply to you.  See the
12  *   LICENSE file included with this distribution for more information.
13  *
14  *   If you did not agree to a different license, then this copy of Lustre
15  *   is open source software; you can redistribute it and/or modify it
16  *   under the terms of version 2 of the GNU General Public License as
17  *   published by the Free Software Foundation.
18  *
19  *   In either case, Lustre is distributed in the hope that it will be
20  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *   license text for more details.
23  *
24  */
25 #define DEBUG_SUBSYSTEM S_CLASS
26
27 #include <linux/version.h>
28 #include <asm/statfs.h>
29 #include <obd.h>
30 #include <obd_class.h>
31 #include <lprocfs_status.h>
32 #include <lustre_param.h>
33 #include "mgs_internal.h"
34
35 #ifdef LPROCFS
36
37 static int lprocfs_mgs_rd_mntdev(char *page, char **start, off_t off, int count,
38                                  int *eof, void *data)
39 {
40         struct obd_device* obd = (struct obd_device *)data;
41
42         LASSERT(obd != NULL);
43         LASSERT(obd->u.mgs.mgs_vfsmnt->mnt_devname);
44         *eof = 1;
45
46         return snprintf(page, count, "%s\n",obd->u.mgs.mgs_vfsmnt->mnt_devname);
47 }
48
49 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
50 {
51         struct obd_device *obd = seq->private;
52         struct mgs_obd *mgs = &obd->u.mgs;
53         struct list_head dentry_list;
54         struct l_linux_dirent *dirent, *n;
55         int rc, len;
56         ENTRY;
57
58         LASSERT(obd != NULL);
59         rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
60                                   mgs->mgs_vfsmnt, &dentry_list);
61         if (rc) {
62                 CERROR("Can't read config dir\n");
63                 RETURN(rc);
64         }
65         list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
66                 list_del(&dirent->lld_list);
67                 len = strlen(dirent->lld_name);
68                 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
69                                           len) == 0)) {
70                         seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
71                 }
72                 OBD_FREE(dirent, sizeof(*dirent));
73         }
74
75         RETURN(0);
76 }
77
78 LPROC_SEQ_FOPS_RO(mgs_fs);
79
80 int lproc_mgs_setup(struct obd_device *obd)
81 {
82         struct mgs_obd *mgs = &obd->u.mgs;
83         int rc;
84
85         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
86                                     &mgs_fs_fops, obd);
87         mgs->mgs_proc_live = proc_mkdir("live", obd->obd_proc_entry);
88         obd->obd_proc_exports = proc_mkdir("exports", obd->obd_proc_entry);
89
90         return rc;
91 }
92
93 int lproc_mgs_cleanup(struct obd_device *obd)
94 {
95         struct mgs_obd *mgs;
96
97         if (!obd)
98                 RETURN(-EINVAL);
99
100         mgs = &obd->u.mgs;
101         if (mgs->mgs_proc_live) {
102                 /* Should be no live entries */
103                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
104                 lprocfs_remove(&mgs->mgs_proc_live);
105                 mgs->mgs_proc_live = NULL;
106         }
107         lprocfs_free_obd_stats(obd);
108
109         return lprocfs_obd_cleanup(obd);
110 }
111
112 static void seq_show_srpc_rule(struct seq_file *seq, const char *tgtname,
113                                struct sptlrpc_rule_set *rset)
114 {
115         struct sptlrpc_rule    *r;
116         char                    dirbuf[10];
117         char                    flvrbuf[40];
118         char                   *net;
119         int                     i;
120
121         for (i = 0; i < rset->srs_nrule; i++) {
122                 r = &rset->srs_rules[i];
123
124                 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
125                         net = "default";
126                 else
127                         net = libcfs_net2str(r->sr_netid);
128
129                 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
130                         dirbuf[0] = '\0';
131                 else
132                         snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
133                                  sptlrpc_part2name(r->sr_from),
134                                  sptlrpc_part2name(r->sr_to));
135
136                 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
137                 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
138                            net, dirbuf, flvrbuf);
139         }
140 }
141
142 static int mgs_live_seq_show(struct seq_file *seq, void *v) 
143 {
144         struct fs_db             *fsdb = seq->private;
145         struct mgs_tgt_srpc_conf *srpc_tgt;
146         int i;
147         
148         down(&fsdb->fsdb_sem);
149
150         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
151         seq_printf(seq, "flags: %#x     gen: %d\n", 
152                    fsdb->fsdb_flags, fsdb->fsdb_gen);
153         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
154                  if (test_bit(i, fsdb->fsdb_mdt_index_map)) 
155                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
156         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
157                  if (test_bit(i, fsdb->fsdb_ost_index_map)) 
158                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
159
160         seq_printf(seq, "\nSecure RPC Config Rules:\n");
161 #if 0
162         seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
163                    PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
164 #endif
165         for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
166              srpc_tgt = srpc_tgt->mtsc_next) {
167                 seq_show_srpc_rule(seq, srpc_tgt->mtsc_tgt,
168                                    &srpc_tgt->mtsc_rset);
169         }
170         seq_show_srpc_rule(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
171
172         up(&fsdb->fsdb_sem);
173         return 0;
174 }
175
176 LPROC_SEQ_FOPS_RO(mgs_live);
177
178 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
179 {
180         struct mgs_obd *mgs = &obd->u.mgs;
181         int rc;
182
183         if (!mgs->mgs_proc_live) 
184                 return 0;
185         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444, 
186                                 &mgs_live_fops, fsdb);
187
188         return 0;
189 }
190
191 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
192 {
193         struct mgs_obd *mgs = &obd->u.mgs;
194
195         if (!mgs->mgs_proc_live) 
196                 return 0;
197         remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
198         return 0;
199 }
200
201 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
202         { "uuid",            lprocfs_rd_uuid,        0, 0 },
203         { "fstype",          lprocfs_rd_fstype,      0, 0 },
204         { "mntdev",          lprocfs_mgs_rd_mntdev,  0, 0 },
205         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
206         { "evict_client",    0, lprocfs_wr_evict_client, 0 },
207         { 0 }
208 };
209
210 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
211         { 0 }
212 };
213
214 void mgs_counter_incr(struct obd_export *exp, int opcode)
215 {
216         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
217         lprocfs_counter_incr(exp->exp_ops_stats, opcode);
218 }
219
220 void mgs_stats_counter_init(struct lprocfs_stats *stats)
221 {
222         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
223         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
224                              "reqs");
225         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
226                              "reqs");
227         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
228         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
229 }
230
231 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
232 {
233     lvars->module_vars  = lprocfs_mgs_module_vars;
234     lvars->obd_vars     = lprocfs_mgs_obd_vars;
235 }
236 #endif