Whamcloud - gitweb
2add9953b616241bb4146d9dbfaae913f8aee6ac
[fs/lustre-release.git] / lustre / ptlrpc / sec_lproc.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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lustre/ptlrpc/sec_lproc.c
35  *
36  * Author: Eric Mei <ericm@clusterfs.com>
37  */
38
39 #define DEBUG_SUBSYSTEM S_SEC
40
41 #include <libcfs/libcfs.h>
42 #ifndef __KERNEL__
43 #include <liblustre.h>
44 #include <libcfs/list.h>
45 #else
46 #include <linux/crypto.h>
47 #endif
48
49 #include <obd.h>
50 #include <obd_class.h>
51 #include <obd_support.h>
52 #include <lustre_net.h>
53 #include <lustre_import.h>
54 #include <lustre_dlm.h>
55 #include <lustre_sec.h>
56
57 #include "ptlrpc_internal.h"
58
59 #ifdef __KERNEL__
60
61 struct proc_dir_entry *sptlrpc_proc_root = NULL;
62 EXPORT_SYMBOL(sptlrpc_proc_root);
63
64 char *sec_flags2str(unsigned long flags, char *buf, int bufsize)
65 {
66         buf[0] = '\0';
67
68         if (flags & PTLRPC_SEC_FL_REVERSE)
69                 strncat(buf, "reverse,", bufsize);
70         if (flags & PTLRPC_SEC_FL_ROOTONLY)
71                 strncat(buf, "rootonly,", bufsize);
72         if (flags & PTLRPC_SEC_FL_UDESC)
73                 strncat(buf, "udesc,", bufsize);
74         if (flags & PTLRPC_SEC_FL_BULK)
75                 strncat(buf, "bulk,", bufsize);
76         if (buf[0] == '\0')
77                 strncat(buf, "-,", bufsize);
78
79         buf[strlen(buf) - 1] = '\0';
80         return buf;
81 }
82
83 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
84 {
85         struct obd_device *dev = seq->private;
86         struct client_obd *cli = &dev->u.cli;
87         struct ptlrpc_sec *sec = NULL;
88         char               str[32];
89
90         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
91                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
92                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
93
94         if (cli->cl_import)
95                 sec = sptlrpc_import_sec_ref(cli->cl_import);
96         if (sec == NULL)
97                 goto out;
98
99         sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str));
100
101         seq_printf(seq, "rpc flavor:    %s\n",
102                    sptlrpc_flavor2name_base(sec->ps_flvr.sf_rpc));
103         seq_printf(seq, "bulk flavor:   %s\n",
104                    sptlrpc_flavor2name_bulk(&sec->ps_flvr, str, sizeof(str)));
105         seq_printf(seq, "flags:         %s\n",
106                    sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str)));
107         seq_printf(seq, "id:            %d\n", sec->ps_id);
108         seq_printf(seq, "refcount:      %d\n",
109                    cfs_atomic_read(&sec->ps_refcount));
110         seq_printf(seq, "nctx:          %d\n", cfs_atomic_read(&sec->ps_nctx));
111         seq_printf(seq, "gc internal    %ld\n", sec->ps_gc_interval);
112         seq_printf(seq, "gc next        %ld\n",
113                    sec->ps_gc_interval ?
114                    sec->ps_gc_next - cfs_time_current_sec() : 0);
115
116         sptlrpc_sec_put(sec);
117 out:
118         return 0;
119 }
120 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
121
122 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
123 {
124         struct obd_device *dev = seq->private;
125         struct client_obd *cli = &dev->u.cli;
126         struct ptlrpc_sec *sec = NULL;
127
128         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
129                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
130                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
131
132         if (cli->cl_import)
133                 sec = sptlrpc_import_sec_ref(cli->cl_import);
134         if (sec == NULL)
135                 goto out;
136
137         if (sec->ps_policy->sp_cops->display)
138                 sec->ps_policy->sp_cops->display(sec, seq);
139
140         sptlrpc_sec_put(sec);
141 out:
142         return 0;
143 }
144 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
145
146 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
147 {
148         int     rc;
149
150         if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
151             strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
152             strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
153                 CERROR("can't register lproc for obd type %s\n",
154                        dev->obd_type->typ_name);
155                 return -EINVAL;
156         }
157
158         rc = lprocfs_obd_seq_create(dev, "srpc_info", 0444,
159                                     &sptlrpc_info_lprocfs_fops, dev);
160         if (rc) {
161                 CERROR("create proc entry srpc_info for %s: %d\n",
162                        dev->obd_name, rc);
163                 return rc;
164         }
165
166         rc = lprocfs_obd_seq_create(dev, "srpc_contexts", 0444,
167                                     &sptlrpc_ctxs_lprocfs_fops, dev);
168         if (rc) {
169                 CERROR("create proc entry srpc_contexts for %s: %d\n",
170                        dev->obd_name, rc);
171                 return rc;
172         }
173
174         return 0;
175 }
176 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
177
178 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
179         { "encrypt_page_pools", sptlrpc_proc_read_enc_pool, NULL, NULL },
180         { NULL }
181 };
182
183 int sptlrpc_lproc_init(void)
184 {
185         int     rc;
186
187         LASSERT(sptlrpc_proc_root == NULL);
188
189         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
190                                              sptlrpc_lprocfs_vars, NULL);
191         if (IS_ERR(sptlrpc_proc_root)) {
192                 rc = PTR_ERR(sptlrpc_proc_root);
193                 sptlrpc_proc_root = NULL;
194                 return rc;
195         }
196         return 0;
197 }
198
199 void sptlrpc_lproc_fini(void)
200 {
201         if (sptlrpc_proc_root) {
202                 lprocfs_remove(&sptlrpc_proc_root);
203                 sptlrpc_proc_root = NULL;
204         }
205 }
206
207 #else /* !__KERNEL__ */
208
209 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
210 {
211         return 0;
212 }
213
214 int sptlrpc_lproc_init(void)
215 {
216         return 0;
217 }
218
219 void sptlrpc_lproc_fini(void)
220 {
221 }
222
223 #endif