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