Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / ptlrpc / sec_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ptlrpc/sec_lproc.c
37  *
38  * Author: Eric Mei <ericm@clusterfs.com>
39  */
40
41 #ifndef EXPORT_SYMTAB
42 #define EXPORT_SYMTAB
43 #endif
44 #define DEBUG_SUBSYSTEM S_SEC
45
46 #include <libcfs/libcfs.h>
47 #ifndef __KERNEL__
48 #include <liblustre.h>
49 #include <libcfs/list.h>
50 #else
51 #include <linux/crypto.h>
52 #endif
53
54 #include <obd.h>
55 #include <obd_class.h>
56 #include <obd_support.h>
57 #include <lustre_net.h>
58 #include <lustre_import.h>
59 #include <lustre_dlm.h>
60 #include <lustre_sec.h>
61
62 #include "ptlrpc_internal.h"
63
64 #ifdef __KERNEL__
65
66 struct proc_dir_entry *sptlrpc_proc_root = NULL;
67 EXPORT_SYMBOL(sptlrpc_proc_root);
68
69 void sec_flags2str(unsigned long flags, char *buf, int bufsize)
70 {
71         buf[0] = '\0';
72
73         if (flags & PTLRPC_SEC_FL_REVERSE)
74                 strncat(buf, "reverse,", bufsize);
75         if (flags & PTLRPC_SEC_FL_ROOTONLY)
76                 strncat(buf, "rootonly,", bufsize);
77         if (flags & PTLRPC_SEC_FL_UDESC)
78                 strncat(buf, "udesc,", bufsize);
79         if (flags & PTLRPC_SEC_FL_BULK)
80                 strncat(buf, "bulk,", bufsize);
81         if (buf[0] == '\0')
82                 strncat(buf, "-,", bufsize);
83
84         buf[strlen(buf) - 1] = '\0';
85
86 }
87
88 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
89 {
90         struct obd_device *dev = seq->private;
91         struct client_obd *cli = &dev->u.cli;
92         struct ptlrpc_sec *sec = NULL;
93         char               flags_str[32];
94
95         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
96                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
97                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
98
99         if (cli->cl_import)
100                 sec = sptlrpc_import_sec_ref(cli->cl_import);
101         if (sec == NULL)
102                 goto out;
103
104         sec_flags2str(sec->ps_flvr.sf_flags, flags_str, sizeof(flags_str));
105
106         seq_printf(seq, "rpc flavor:    %s\n",
107                    sptlrpc_rpcflavor2name(sec->ps_flvr.sf_rpc));
108         seq_printf(seq, "bulk flavor:   %s/%s\n",
109                    sptlrpc_get_hash_name(sec->ps_flvr.sf_bulk_hash),
110                    sptlrpc_get_ciph_name(sec->ps_flvr.sf_bulk_ciph));
111         seq_printf(seq, "flags:         %s\n", flags_str);
112         seq_printf(seq, "id:            %d\n", sec->ps_id);
113         seq_printf(seq, "refcount:      %d\n", atomic_read(&sec->ps_refcount));
114         seq_printf(seq, "nctx:          %d\n", atomic_read(&sec->ps_nctx));
115         seq_printf(seq, "gc internal    %ld\n", sec->ps_gc_interval);
116         seq_printf(seq, "gc next        %ld\n",
117                    sec->ps_gc_interval ?
118                    sec->ps_gc_next - cfs_time_current_sec() : 0);
119
120         sptlrpc_sec_put(sec);
121 out:
122         return 0;
123 }
124 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
125
126 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
127 {
128         struct obd_device *dev = seq->private;
129         struct client_obd *cli = &dev->u.cli;
130         struct ptlrpc_sec *sec = NULL;
131
132         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
133                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
134                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
135
136         if (cli->cl_import)
137                 sec = sptlrpc_import_sec_ref(cli->cl_import);
138         if (sec == NULL)
139                 goto out;
140
141         if (sec->ps_policy->sp_cops->display)
142                 sec->ps_policy->sp_cops->display(sec, seq);
143
144         sptlrpc_sec_put(sec);
145 out:
146         return 0;
147 }
148 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
149
150 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
151 {
152         int     rc;
153
154         if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
155             strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
156             strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
157                 CERROR("can't register lproc for obd type %s\n",
158                        dev->obd_type->typ_name);
159                 return -EINVAL;
160         }
161
162         rc = lprocfs_obd_seq_create(dev, "srpc.info", 0444,
163                                     &sptlrpc_info_lprocfs_fops, dev);
164         if (rc) {
165                 CERROR("create proc entry srpc.info for %s: %d\n",
166                        dev->obd_name, rc);
167                 return rc;
168         }
169
170         rc = lprocfs_obd_seq_create(dev, "srpc.contexts", 0444,
171                                     &sptlrpc_ctxs_lprocfs_fops, dev);
172         if (rc) {
173                 CERROR("create proc entry srpc.contexts for %s: %d\n",
174                        dev->obd_name, rc);
175                 return rc;
176         }
177
178         return 0;
179 }
180 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
181
182 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
183         { "encrypt_page_pools", sptlrpc_proc_read_enc_pool, NULL, NULL },
184         { NULL }
185 };
186
187 int sptlrpc_lproc_init(void)
188 {
189         int     rc;
190
191         LASSERT(sptlrpc_proc_root == NULL);
192
193         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
194                                              sptlrpc_lprocfs_vars, NULL);
195         if (IS_ERR(sptlrpc_proc_root)) {
196                 rc = PTR_ERR(sptlrpc_proc_root);
197                 sptlrpc_proc_root = NULL;
198                 return rc;
199         }
200         return 0;
201 }
202
203 void sptlrpc_lproc_fini(void)
204 {
205         if (sptlrpc_proc_root) {
206                 lprocfs_remove(&sptlrpc_proc_root);
207                 sptlrpc_proc_root = NULL;
208         }
209 }
210
211 #else /* !__KERNEL__ */
212
213 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
214 {
215         return 0;
216 }
217
218 int sptlrpc_lproc_init(void)
219 {
220         return 0;
221 }
222
223 void sptlrpc_lproc_fini(void)
224 {
225 }
226
227 #endif