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