Whamcloud - gitweb
LU-1818 quota: en/disable quota enforcement via conf_param
[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, Whamcloud, Inc.
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(mnt_get_devname(obd->u.mgs.mgs_vfsmnt));
55         *eof = 1;
56
57         return snprintf(page, count, "%s\n",
58                         mnt_get_devname(obd->u.mgs.mgs_vfsmnt));
59 }
60
61 static int mgs_fs_seq_show(struct seq_file *seq, void *v)
62 {
63         struct obd_device *obd = seq->private;
64         struct mgs_obd *mgs = &obd->u.mgs;
65         cfs_list_t dentry_list;
66         struct l_linux_dirent *dirent, *n;
67         int rc, len;
68         ENTRY;
69
70         LASSERT(obd != NULL);
71         rc = class_dentry_readdir(obd, mgs->mgs_configs_dir,
72                                   mgs->mgs_vfsmnt, &dentry_list);
73         if (rc) {
74                 CERROR("Can't read config dir\n");
75                 RETURN(rc);
76         }
77         cfs_list_for_each_entry_safe(dirent, n, &dentry_list, lld_list) {
78                 cfs_list_del(&dirent->lld_list);
79                 len = strlen(dirent->lld_name);
80                 if ((len > 7) && (strncmp(dirent->lld_name + len - 7, "-client",
81                                           len) == 0)) {
82                         seq_printf(seq, "%.*s\n", len - 7, dirent->lld_name);
83                 }
84                 OBD_FREE(dirent, sizeof(*dirent));
85         }
86
87         RETURN(0);
88 }
89
90 LPROC_SEQ_FOPS_RO(mgs_fs);
91
92 static void seq_show_srpc_rules(struct seq_file *seq, const char *tgtname,
93                                 struct sptlrpc_rule_set *rset)
94 {
95         struct sptlrpc_rule    *r;
96         char                    dirbuf[10];
97         char                    flvrbuf[40];
98         char                   *net;
99         int                     i;
100
101         for (i = 0; i < rset->srs_nrule; i++) {
102                 r = &rset->srs_rules[i];
103
104                 if (r->sr_netid == LNET_NIDNET(LNET_NID_ANY))
105                         net = "default";
106                 else
107                         net = libcfs_net2str(r->sr_netid);
108
109                 if (r->sr_from == LUSTRE_SP_ANY && r->sr_to == LUSTRE_SP_ANY)
110                         dirbuf[0] = '\0';
111                 else
112                         snprintf(dirbuf, sizeof(dirbuf), ".%s2%s",
113                                  sptlrpc_part2name(r->sr_from),
114                                  sptlrpc_part2name(r->sr_to));
115
116                 sptlrpc_flavor2name(&r->sr_flvr, flvrbuf, sizeof(flvrbuf));
117                 seq_printf(seq, "%s.srpc.flavor.%s%s=%s\n", tgtname,
118                            net, dirbuf, flvrbuf);
119         }
120 }
121
122 static int mgsself_srpc_seq_show(struct seq_file *seq, void *v)
123 {
124         struct obd_device *obd = seq->private;
125         struct fs_db      *fsdb;
126         int                rc;
127
128         rc = mgs_find_or_make_fsdb(obd, MGSSELF_NAME, &fsdb);
129         if (rc)
130                 return rc;
131
132         cfs_mutex_lock(&fsdb->fsdb_mutex);
133         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
134         cfs_mutex_unlock(&fsdb->fsdb_mutex);
135         return 0;
136 }
137
138 LPROC_SEQ_FOPS_RO(mgsself_srpc);
139
140 int lproc_mgs_setup(struct obd_device *obd)
141 {
142         struct mgs_obd *mgs = &obd->u.mgs;
143         int rc;
144
145         rc = lprocfs_obd_seq_create(obd, "filesystems", 0444,
146                                     &mgs_fs_fops, obd);
147         rc = lprocfs_obd_seq_create(obd, "srpc_rules", 0600,
148                                     &mgsself_srpc_fops, obd);
149
150         mgs->mgs_proc_live = lprocfs_register("live", obd->obd_proc_entry,
151                                               NULL, NULL);
152         if (IS_ERR(mgs->mgs_proc_live)) {
153                 rc = PTR_ERR(mgs->mgs_proc_live);
154                 CERROR("error %d setting up lprocfs for %s\n", rc, "live");
155                 mgs->mgs_proc_live = NULL;
156         }
157
158         obd->obd_proc_exports_entry = lprocfs_register("exports",
159                                                        obd->obd_proc_entry,
160                                                        NULL, NULL);
161         if (IS_ERR(obd->obd_proc_exports_entry)) {
162                 rc = PTR_ERR(obd->obd_proc_exports_entry);
163                 CERROR("error %d setting up lprocfs for %s\n", rc, "exports");
164                 obd->obd_proc_exports_entry = NULL;
165         }
166
167         return rc;
168 }
169
170 int lproc_mgs_cleanup(struct obd_device *obd)
171 {
172         struct mgs_obd *mgs;
173
174         if (!obd)
175                 return -EINVAL;
176
177         mgs = &obd->u.mgs;
178         if (mgs->mgs_proc_live) {
179                 /* Should be no live entries */
180                 LASSERT(mgs->mgs_proc_live->subdir == NULL);
181                 lprocfs_remove(&mgs->mgs_proc_live);
182                 mgs->mgs_proc_live = NULL;
183         }
184         lprocfs_free_per_client_stats(obd);
185         lprocfs_free_obd_stats(obd);
186         lprocfs_free_md_stats(obd);
187
188         return lprocfs_obd_cleanup(obd);
189 }
190
191 static int mgs_live_seq_show(struct seq_file *seq, void *v)
192 {
193         struct fs_db             *fsdb = seq->private;
194         struct mgs_tgt_srpc_conf *srpc_tgt;
195         int i;
196
197         cfs_mutex_lock(&fsdb->fsdb_mutex);
198
199         seq_printf(seq, "fsname: %s\n", fsdb->fsdb_name);
200         seq_printf(seq, "flags: %#lx     gen: %d\n",
201                    fsdb->fsdb_flags, fsdb->fsdb_gen);
202         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
203                  if (cfs_test_bit(i, fsdb->fsdb_mdt_index_map))
204                          seq_printf(seq, "%s-MDT%04x\n", fsdb->fsdb_name, i);
205         for (i = 0; i < INDEX_MAP_SIZE * 8; i++)
206                  if (cfs_test_bit(i, fsdb->fsdb_ost_index_map))
207                          seq_printf(seq, "%s-OST%04x\n", fsdb->fsdb_name, i);
208
209         seq_printf(seq, "\nSecure RPC Config Rules:\n");
210 #if 0
211         seq_printf(seq, "%s.%s=%s\n", fsdb->fsdb_name,
212                    PARAM_SRPC_UDESC, fsdb->fsdb_srpc_fl_udesc ? "yes" : "no");
213 #endif
214         for (srpc_tgt = fsdb->fsdb_srpc_tgt; srpc_tgt;
215              srpc_tgt = srpc_tgt->mtsc_next) {
216                 seq_show_srpc_rules(seq, srpc_tgt->mtsc_tgt,
217                                     &srpc_tgt->mtsc_rset);
218         }
219         seq_show_srpc_rules(seq, fsdb->fsdb_name, &fsdb->fsdb_srpc_gen);
220
221         lprocfs_rd_ir_state(seq, fsdb);
222
223         cfs_mutex_unlock(&fsdb->fsdb_mutex);
224         return 0;
225 }
226
227 static ssize_t mgs_live_seq_write(struct file *file, const char *buf,
228                                   size_t len, loff_t *off)
229 {
230         struct seq_file *seq  = file->private_data;
231         struct fs_db    *fsdb = seq->private;
232         ssize_t rc;
233
234         rc = lprocfs_wr_ir_state(file, buf, len, fsdb);
235         if (rc >= 0)
236                 rc = len;
237         return rc;
238 }
239 LPROC_SEQ_FOPS(mgs_live);
240
241 int lproc_mgs_add_live(struct obd_device *obd, struct fs_db *fsdb)
242 {
243         struct mgs_obd *mgs = &obd->u.mgs;
244         int rc;
245
246         if (!mgs->mgs_proc_live)
247                 return 0;
248         rc = lprocfs_seq_create(mgs->mgs_proc_live, fsdb->fsdb_name, 0444,
249                                 &mgs_live_fops, fsdb);
250
251         return 0;
252 }
253
254 int lproc_mgs_del_live(struct obd_device *obd, struct fs_db *fsdb)
255 {
256         struct mgs_obd *mgs = &obd->u.mgs;
257
258         if (!mgs->mgs_proc_live)
259                 return 0;
260
261         lprocfs_remove_proc_entry(fsdb->fsdb_name, mgs->mgs_proc_live);
262         return 0;
263 }
264
265 struct lprocfs_vars lprocfs_mgs_obd_vars[] = {
266         { "uuid",            lprocfs_rd_uuid,        0, 0 },
267         { "fstype",          lprocfs_rd_fstype,      0, 0 },
268         { "mntdev",          lprocfs_mgs_rd_mntdev,  0, 0 },
269         { "num_exports",     lprocfs_rd_num_exports, 0, 0 },
270         { "hash_stats",      lprocfs_obd_rd_hash,    0, 0 },
271         { "evict_client",    0, lprocfs_wr_evict_client, 0 },
272         { "ir_timeout",      lprocfs_rd_ir_timeout, lprocfs_wr_ir_timeout, 0 },
273         { 0 }
274 };
275
276 struct lprocfs_vars lprocfs_mgs_module_vars[] = {
277         { 0 }
278 };
279
280 void mgs_counter_incr(struct obd_export *exp, int opcode)
281 {
282         lprocfs_counter_incr(exp->exp_obd->obd_stats, opcode);
283         if (exp->exp_nid_stats && exp->exp_nid_stats->nid_stats != NULL)
284                 lprocfs_counter_incr(exp->exp_nid_stats->nid_stats, opcode);
285 }
286
287 void mgs_stats_counter_init(struct lprocfs_stats *stats)
288 {
289         lprocfs_counter_init(stats, LPROC_MGS_CONNECT, 0, "connect", "reqs");
290         lprocfs_counter_init(stats, LPROC_MGS_DISCONNECT, 0, "disconnect",
291                              "reqs");
292         lprocfs_counter_init(stats, LPROC_MGS_EXCEPTION, 0, "exception",
293                              "reqs");
294         lprocfs_counter_init(stats, LPROC_MGS_TARGET_REG, 0, "tgtreg", "reqs");
295         lprocfs_counter_init(stats, LPROC_MGS_TARGET_DEL, 0, "tgtdel", "reqs");
296 }
297
298 void lprocfs_mgs_init_vars(struct lprocfs_static_vars *lvars)
299 {
300     lvars->module_vars  = lprocfs_mgs_module_vars;
301     lvars->obd_vars     = lprocfs_mgs_obd_vars;
302 }
303 #endif