4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2014, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ptlrpc/sec_lproc.c
34 * Author: Eric Mei <ericm@clusterfs.com>
37 #define DEBUG_SUBSYSTEM S_SEC
39 #include <libcfs/libcfs.h>
40 #include <linux/crypto.h>
43 #include <obd_class.h>
44 #include <obd_support.h>
45 #include <lustre_net.h>
46 #include <lustre_import.h>
47 #include <lustre_dlm.h>
48 #include <lustre_sec.h>
50 #include "ptlrpc_internal.h"
52 static char *sec_flags2str(unsigned long flags, char *buf, int bufsize)
56 if (flags & PTLRPC_SEC_FL_REVERSE)
57 strlcat(buf, "reverse,", bufsize);
58 if (flags & PTLRPC_SEC_FL_ROOTONLY)
59 strlcat(buf, "rootonly,", bufsize);
60 if (flags & PTLRPC_SEC_FL_UDESC)
61 strlcat(buf, "udesc,", bufsize);
62 if (flags & PTLRPC_SEC_FL_BULK)
63 strlcat(buf, "bulk,", bufsize);
65 strlcat(buf, "-,", bufsize);
70 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
72 struct obd_device *dev = seq->private;
73 struct client_obd *cli = &dev->u.cli;
74 struct ptlrpc_sec *sec = NULL;
77 LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
78 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
79 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0 ||
80 strcmp(dev->obd_type->typ_name, LUSTRE_LWP_NAME) == 0 ||
81 strcmp(dev->obd_type->typ_name, LUSTRE_OSP_NAME) == 0);
84 sec = sptlrpc_import_sec_ref(cli->cl_import);
88 sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str));
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 %lld\n", sec->ps_gc_interval);
101 seq_printf(seq, "gc next %lld\n",
102 sec->ps_gc_interval ?
103 (s64)(sec->ps_gc_next - ktime_get_real_seconds()) : 0ll);
105 sptlrpc_sec_put(sec);
110 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
112 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
114 struct obd_device *dev = seq->private;
115 struct client_obd *cli = &dev->u.cli;
116 struct ptlrpc_sec *sec = NULL;
118 LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
119 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
120 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0 ||
121 strcmp(dev->obd_type->typ_name, LUSTRE_LWP_NAME) == 0 ||
122 strcmp(dev->obd_type->typ_name, LUSTRE_OSP_NAME) == 0);
125 sec = sptlrpc_import_sec_ref(cli->cl_import);
129 if (sec->ps_policy->sp_cops->display)
130 sec->ps_policy->sp_cops->display(sec, seq);
132 sptlrpc_sec_put(sec);
137 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
140 lprocfs_sptlrpc_sepol_seq_write(struct file *file, const char __user *buffer,
141 size_t count, void *data)
143 struct seq_file *seq = file->private_data;
144 struct obd_device *dev = seq->private;
145 struct client_obd *cli = &dev->u.cli;
146 struct obd_import *imp = cli->cl_import;
147 struct sepol_downcall_data *param;
148 int size = sizeof(*param);
152 CERROR("%s: invalid data count = %lu, size = %d\n",
153 dev->obd_name, (unsigned long) count, size);
157 OBD_ALLOC(param, size);
161 if (copy_from_user(param, buffer, size)) {
162 CERROR("%s: bad sepol data\n", dev->obd_name);
163 GOTO(out, rc = -EFAULT);
166 if (param->sdd_magic != SEPOL_DOWNCALL_MAGIC) {
167 CERROR("%s: sepol downcall bad params\n",
169 GOTO(out, rc = -EINVAL);
172 if (param->sdd_sepol_len == 0 ||
173 param->sdd_sepol_len >= sizeof(imp->imp_sec->ps_sepol)) {
174 CERROR("%s: invalid sepol data returned\n",
176 GOTO(out, rc = -EINVAL);
178 rc = param->sdd_sepol_len; /* save sdd_sepol_len */
179 OBD_FREE(param, size);
180 size = offsetof(struct sepol_downcall_data,
183 /* alloc again with real size */
185 OBD_ALLOC(param, size);
189 if (copy_from_user(param, buffer, size)) {
190 CERROR("%s: bad sepol data\n", dev->obd_name);
191 GOTO(out, rc = -EFAULT);
194 spin_lock(&imp->imp_sec->ps_lock);
195 snprintf(imp->imp_sec->ps_sepol, param->sdd_sepol_len + 1, "%s",
197 imp->imp_sec->ps_sepol_mtime = param->sdd_sepol_mtime;
198 spin_unlock(&imp->imp_sec->ps_lock);
202 OBD_FREE(param, size);
204 return rc ? rc : count;
206 LPROC_SEQ_FOPS_WR_ONLY(srpc, sptlrpc_sepol);
208 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
212 if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
213 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
214 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0 &&
215 strcmp(dev->obd_type->typ_name, LUSTRE_LWP_NAME) != 0 &&
216 strcmp(dev->obd_type->typ_name, LUSTRE_OSP_NAME) != 0) {
217 CERROR("can't register lproc for obd type %s\n",
218 dev->obd_type->typ_name);
222 rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "srpc_info", 0444,
223 &sptlrpc_info_lprocfs_fops, dev);
225 CERROR("create proc entry srpc_info for %s: %d\n",
230 rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "srpc_contexts",
231 0444, &sptlrpc_ctxs_lprocfs_fops, dev);
233 CERROR("create proc entry srpc_contexts for %s: %d\n",
238 rc = ldebugfs_seq_create(dev->obd_debugfs_entry, "srpc_sepol",
239 0200, &srpc_sptlrpc_sepol_fops, dev);
241 CERROR("create proc entry srpc_sepol for %s: %d\n",
248 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
250 LDEBUGFS_SEQ_FOPS_RO(sptlrpc_proc_enc_pool);
252 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
253 { .name = "encrypt_page_pools",
254 .fops = &sptlrpc_proc_enc_pool_fops },
258 struct dentry *sptlrpc_debugfs_dir;
259 EXPORT_SYMBOL(sptlrpc_debugfs_dir);
261 struct proc_dir_entry *sptlrpc_lprocfs_dir;
262 EXPORT_SYMBOL(sptlrpc_lprocfs_dir);
264 int sptlrpc_lproc_init(void)
268 LASSERT(sptlrpc_debugfs_dir == NULL);
270 sptlrpc_debugfs_dir = ldebugfs_register("sptlrpc", debugfs_lustre_root,
271 sptlrpc_lprocfs_vars, NULL);
272 if (IS_ERR_OR_NULL(sptlrpc_debugfs_dir)) {
273 rc = sptlrpc_debugfs_dir ? PTR_ERR(sptlrpc_debugfs_dir)
275 sptlrpc_debugfs_dir = NULL;
279 sptlrpc_lprocfs_dir = lprocfs_register("sptlrpc", proc_lustre_root,
281 if (IS_ERR_OR_NULL(sptlrpc_lprocfs_dir)) {
282 rc = PTR_ERR(sptlrpc_lprocfs_dir);
283 rc = sptlrpc_lprocfs_dir ? PTR_ERR(sptlrpc_lprocfs_dir)
285 sptlrpc_lprocfs_dir = NULL;
290 void sptlrpc_lproc_fini(void)
292 debugfs_remove_recursive(sptlrpc_debugfs_dir);
293 sptlrpc_debugfs_dir = NULL;
295 if (!IS_ERR_OR_NULL(sptlrpc_lprocfs_dir))
296 lprocfs_remove(&sptlrpc_lprocfs_dir);