Whamcloud - gitweb
Mass conversion of all copyright messages to Oracle.
[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 (c) 2007, 2010, Oracle and/or its affiliates. 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 char *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         return buf;
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               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, str, sizeof(str));
105
106         seq_printf(seq, "rpc flavor:    %s\n",
107                    sptlrpc_flavor2name_base(sec->ps_flvr.sf_rpc));
108         seq_printf(seq, "bulk flavor:   %s\n",
109                    sptlrpc_flavor2name_bulk(&sec->ps_flvr, str, sizeof(str)));
110         seq_printf(seq, "flags:         %s\n",
111                    sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str)));
112         seq_printf(seq, "id:            %d\n", sec->ps_id);
113         seq_printf(seq, "refcount:      %d\n",
114                    cfs_atomic_read(&sec->ps_refcount));
115         seq_printf(seq, "nctx:          %d\n", cfs_atomic_read(&sec->ps_nctx));
116         seq_printf(seq, "gc internal    %ld\n", sec->ps_gc_interval);
117         seq_printf(seq, "gc next        %ld\n",
118                    sec->ps_gc_interval ?
119                    sec->ps_gc_next - cfs_time_current_sec() : 0);
120
121         sptlrpc_sec_put(sec);
122 out:
123         return 0;
124 }
125 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
126
127 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
128 {
129         struct obd_device *dev = seq->private;
130         struct client_obd *cli = &dev->u.cli;
131         struct ptlrpc_sec *sec = NULL;
132
133         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
134                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
135                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
136
137         if (cli->cl_import)
138                 sec = sptlrpc_import_sec_ref(cli->cl_import);
139         if (sec == NULL)
140                 goto out;
141
142         if (sec->ps_policy->sp_cops->display)
143                 sec->ps_policy->sp_cops->display(sec, seq);
144
145         sptlrpc_sec_put(sec);
146 out:
147         return 0;
148 }
149 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
150
151 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
152 {
153         int     rc;
154
155         if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
156             strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
157             strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
158                 CERROR("can't register lproc for obd type %s\n",
159                        dev->obd_type->typ_name);
160                 return -EINVAL;
161         }
162
163         rc = lprocfs_obd_seq_create(dev, "srpc_info", 0444,
164                                     &sptlrpc_info_lprocfs_fops, dev);
165         if (rc) {
166                 CERROR("create proc entry srpc_info for %s: %d\n",
167                        dev->obd_name, rc);
168                 return rc;
169         }
170
171         rc = lprocfs_obd_seq_create(dev, "srpc_contexts", 0444,
172                                     &sptlrpc_ctxs_lprocfs_fops, dev);
173         if (rc) {
174                 CERROR("create proc entry srpc_contexts for %s: %d\n",
175                        dev->obd_name, rc);
176                 return rc;
177         }
178
179         return 0;
180 }
181 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
182
183 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
184         { "encrypt_page_pools", sptlrpc_proc_read_enc_pool, NULL, NULL },
185         { NULL }
186 };
187
188 int sptlrpc_lproc_init(void)
189 {
190         int     rc;
191
192         LASSERT(sptlrpc_proc_root == NULL);
193
194         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
195                                              sptlrpc_lprocfs_vars, NULL);
196         if (IS_ERR(sptlrpc_proc_root)) {
197                 rc = PTR_ERR(sptlrpc_proc_root);
198                 sptlrpc_proc_root = NULL;
199                 return rc;
200         }
201         return 0;
202 }
203
204 void sptlrpc_lproc_fini(void)
205 {
206         if (sptlrpc_proc_root) {
207                 lprocfs_remove(&sptlrpc_proc_root);
208                 sptlrpc_proc_root = NULL;
209         }
210 }
211
212 #else /* !__KERNEL__ */
213
214 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
215 {
216         return 0;
217 }
218
219 int sptlrpc_lproc_init(void)
220 {
221         return 0;
222 }
223
224 void sptlrpc_lproc_fini(void)
225 {
226 }
227
228 #endif