Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso...
[cascardo/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.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*
27  * This file is part of Lustre, http://www.lustre.org/
28  * Lustre is a trademark of Sun Microsystems, Inc.
29  *
30  * lustre/ptlrpc/sec_lproc.c
31  *
32  * Author: Eric Mei <ericm@clusterfs.com>
33  */
34
35 #define DEBUG_SUBSYSTEM S_SEC
36
37 #include "../../include/linux/libcfs/libcfs.h"
38 #include <linux/crypto.h>
39
40 #include "../include/obd.h"
41 #include "../include/obd_class.h"
42 #include "../include/obd_support.h"
43 #include "../include/lustre_net.h"
44 #include "../include/lustre_import.h"
45 #include "../include/lustre_dlm.h"
46 #include "../include/lustre_sec.h"
47
48 #include "ptlrpc_internal.h"
49
50 static char *sec_flags2str(unsigned long flags, char *buf, int bufsize)
51 {
52         buf[0] = '\0';
53
54         if (flags & PTLRPC_SEC_FL_REVERSE)
55                 strlcat(buf, "reverse,", bufsize);
56         if (flags & PTLRPC_SEC_FL_ROOTONLY)
57                 strlcat(buf, "rootonly,", bufsize);
58         if (flags & PTLRPC_SEC_FL_UDESC)
59                 strlcat(buf, "udesc,", bufsize);
60         if (flags & PTLRPC_SEC_FL_BULK)
61                 strlcat(buf, "bulk,", bufsize);
62         if (buf[0] == '\0')
63                 strlcat(buf, "-,", bufsize);
64
65         return buf;
66 }
67
68 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
69 {
70         struct obd_device *dev = seq->private;
71         struct client_obd *cli = &dev->u.cli;
72         struct ptlrpc_sec *sec = NULL;
73         char str[32];
74
75         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
76                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
77                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
78
79         if (cli->cl_import)
80                 sec = sptlrpc_import_sec_ref(cli->cl_import);
81         if (!sec)
82                 goto out;
83
84         sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str));
85
86         seq_printf(seq, "rpc flavor:    %s\n",
87                    sptlrpc_flavor2name_base(sec->ps_flvr.sf_rpc));
88         seq_printf(seq, "bulk flavor:   %s\n",
89                    sptlrpc_flavor2name_bulk(&sec->ps_flvr, str, sizeof(str)));
90         seq_printf(seq, "flags:  %s\n",
91                    sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str)));
92         seq_printf(seq, "id:        %d\n", sec->ps_id);
93         seq_printf(seq, "refcount:      %d\n",
94                    atomic_read(&sec->ps_refcount));
95         seq_printf(seq, "nctx:    %d\n", atomic_read(&sec->ps_nctx));
96         seq_printf(seq, "gc internal    %ld\n", sec->ps_gc_interval);
97         seq_printf(seq, "gc next        %lld\n",
98                    sec->ps_gc_interval ?
99                    (s64)(sec->ps_gc_next - ktime_get_real_seconds()) : 0ll);
100
101         sptlrpc_sec_put(sec);
102 out:
103         return 0;
104 }
105
106 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
107
108 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
109 {
110         struct obd_device *dev = seq->private;
111         struct client_obd *cli = &dev->u.cli;
112         struct ptlrpc_sec *sec = NULL;
113
114         LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
115                 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
116                 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
117
118         if (cli->cl_import)
119                 sec = sptlrpc_import_sec_ref(cli->cl_import);
120         if (!sec)
121                 goto out;
122
123         if (sec->ps_policy->sp_cops->display)
124                 sec->ps_policy->sp_cops->display(sec, seq);
125
126         sptlrpc_sec_put(sec);
127 out:
128         return 0;
129 }
130
131 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
132
133 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
134 {
135         int rc;
136
137         if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
138             strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
139             strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
140                 CERROR("can't register lproc for obd type %s\n",
141                        dev->obd_type->typ_name);
142                 return -EINVAL;
143         }
144
145         rc = ldebugfs_obd_seq_create(dev, "srpc_info", 0444,
146                                      &sptlrpc_info_lprocfs_fops, dev);
147         if (rc) {
148                 CERROR("create proc entry srpc_info for %s: %d\n",
149                        dev->obd_name, rc);
150                 return rc;
151         }
152
153         rc = ldebugfs_obd_seq_create(dev, "srpc_contexts", 0444,
154                                      &sptlrpc_ctxs_lprocfs_fops, dev);
155         if (rc) {
156                 CERROR("create proc entry srpc_contexts for %s: %d\n",
157                        dev->obd_name, rc);
158                 return rc;
159         }
160
161         return 0;
162 }
163 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
164
165 LPROC_SEQ_FOPS_RO(sptlrpc_proc_enc_pool);
166 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
167         { "encrypt_page_pools", &sptlrpc_proc_enc_pool_fops },
168         { NULL }
169 };
170
171 static struct dentry *sptlrpc_debugfs_dir;
172
173 int sptlrpc_lproc_init(void)
174 {
175         int rc;
176
177         LASSERT(!sptlrpc_debugfs_dir);
178
179         sptlrpc_debugfs_dir = ldebugfs_register("sptlrpc", debugfs_lustre_root,
180                                                 sptlrpc_lprocfs_vars, NULL);
181         if (IS_ERR_OR_NULL(sptlrpc_debugfs_dir)) {
182                 rc = sptlrpc_debugfs_dir ? PTR_ERR(sptlrpc_debugfs_dir)
183                                          : -ENOMEM;
184                 sptlrpc_debugfs_dir = NULL;
185                 return rc;
186         }
187         return 0;
188 }
189
190 void sptlrpc_lproc_fini(void)
191 {
192         if (!IS_ERR_OR_NULL(sptlrpc_debugfs_dir))
193                 ldebugfs_remove(&sptlrpc_debugfs_dir);
194 }