]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/staging/lustre/lustre/ptlrpc/sec_lproc.c
Merge branches 'arm/omap', 'arm/msm', 'arm/smmu', 'arm/tegra', 'x86/vt-d', 'x86/amd...
[karo-tx-linux.git] / drivers / staging / lustre / 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 "../../include/linux/libcfs/libcfs.h"
42 #include <linux/crypto.h>
43
44 #include "../include/obd.h"
45 #include "../include/obd_class.h"
46 #include "../include/obd_support.h"
47 #include "../include/lustre_net.h"
48 #include "../include/lustre_import.h"
49 #include "../include/lustre_dlm.h"
50 #include "../include/lustre_sec.h"
51
52 #include "ptlrpc_internal.h"
53
54 static char *sec_flags2str(unsigned long flags, char *buf, int bufsize)
55 {
56         buf[0] = '\0';
57
58         if (flags & PTLRPC_SEC_FL_REVERSE)
59                 strlcat(buf, "reverse,", bufsize);
60         if (flags & PTLRPC_SEC_FL_ROOTONLY)
61                 strlcat(buf, "rootonly,", bufsize);
62         if (flags & PTLRPC_SEC_FL_UDESC)
63                 strlcat(buf, "udesc,", bufsize);
64         if (flags & PTLRPC_SEC_FL_BULK)
65                 strlcat(buf, "bulk,", bufsize);
66         if (buf[0] == '\0')
67                 strlcat(buf, "-,", bufsize);
68
69         return buf;
70 }
71
72 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
73 {
74         struct obd_device *dev = seq->private;
75         struct client_obd *cli = &dev->u.cli;
76         struct ptlrpc_sec *sec = NULL;
77         char str[32];
78
79         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
80                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
81                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
82
83         if (cli->cl_import)
84                 sec = sptlrpc_import_sec_ref(cli->cl_import);
85         if (sec == NULL)
86                 goto out;
87
88         sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str));
89
90         seq_printf(seq, "rpc flavor:    %s\n",
91                    sptlrpc_flavor2name_base(sec->ps_flvr.sf_rpc));
92         seq_printf(seq, "bulk flavor:   %s\n",
93                    sptlrpc_flavor2name_bulk(&sec->ps_flvr, str, sizeof(str)));
94         seq_printf(seq, "flags:  %s\n",
95                    sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str)));
96         seq_printf(seq, "id:        %d\n", sec->ps_id);
97         seq_printf(seq, "refcount:      %d\n",
98                    atomic_read(&sec->ps_refcount));
99         seq_printf(seq, "nctx:    %d\n", atomic_read(&sec->ps_nctx));
100         seq_printf(seq, "gc internal    %ld\n", sec->ps_gc_interval);
101         seq_printf(seq, "gc next        %ld\n",
102                    sec->ps_gc_interval ?
103                    sec->ps_gc_next - get_seconds() : 0);
104
105         sptlrpc_sec_put(sec);
106 out:
107         return 0;
108 }
109 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
110
111 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
112 {
113         struct obd_device *dev = seq->private;
114         struct client_obd *cli = &dev->u.cli;
115         struct ptlrpc_sec *sec = NULL;
116
117         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
118                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
119                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
120
121         if (cli->cl_import)
122                 sec = sptlrpc_import_sec_ref(cli->cl_import);
123         if (sec == NULL)
124                 goto out;
125
126         if (sec->ps_policy->sp_cops->display)
127                 sec->ps_policy->sp_cops->display(sec, seq);
128
129         sptlrpc_sec_put(sec);
130 out:
131         return 0;
132 }
133 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
134
135 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
136 {
137         int rc;
138
139         if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
140             strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
141             strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
142                 CERROR("can't register lproc for obd type %s\n",
143                        dev->obd_type->typ_name);
144                 return -EINVAL;
145         }
146
147         rc = ldebugfs_obd_seq_create(dev, "srpc_info", 0444,
148                                      &sptlrpc_info_lprocfs_fops, dev);
149         if (rc) {
150                 CERROR("create proc entry srpc_info for %s: %d\n",
151                        dev->obd_name, rc);
152                 return rc;
153         }
154
155         rc = ldebugfs_obd_seq_create(dev, "srpc_contexts", 0444,
156                                      &sptlrpc_ctxs_lprocfs_fops, dev);
157         if (rc) {
158                 CERROR("create proc entry srpc_contexts for %s: %d\n",
159                        dev->obd_name, rc);
160                 return rc;
161         }
162
163         return 0;
164 }
165 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
166
167 LPROC_SEQ_FOPS_RO(sptlrpc_proc_enc_pool);
168 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
169         { "encrypt_page_pools", &sptlrpc_proc_enc_pool_fops },
170         { NULL }
171 };
172
173 static struct dentry *sptlrpc_debugfs_dir;
174
175 int sptlrpc_lproc_init(void)
176 {
177         int rc;
178
179         LASSERT(sptlrpc_debugfs_dir == NULL);
180
181         sptlrpc_debugfs_dir = ldebugfs_register("sptlrpc", debugfs_lustre_root,
182                                                 sptlrpc_lprocfs_vars, NULL);
183         if (IS_ERR_OR_NULL(sptlrpc_debugfs_dir)) {
184                 rc = sptlrpc_debugfs_dir ? PTR_ERR(sptlrpc_debugfs_dir)
185                                          : -ENOMEM;
186                 sptlrpc_debugfs_dir = NULL;
187                 return rc;
188         }
189         return 0;
190 }
191
192 void sptlrpc_lproc_fini(void)
193 {
194         if (!IS_ERR_OR_NULL(sptlrpc_debugfs_dir))
195                 ldebugfs_remove(&sptlrpc_debugfs_dir);
196 }