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