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/
31 * lustre/ptlrpc/sec_lproc.c
33 * Author: Eric Mei <ericm@clusterfs.com>
36 #define DEBUG_SUBSYSTEM S_SEC
38 #include <libcfs/libcfs.h>
39 #include <linux/crypto.h>
42 #include <obd_class.h>
43 #include <obd_support.h>
44 #include <lustre_net.h>
45 #include <lustre_import.h>
46 #include <lustre_dlm.h>
47 #include <lustre_sec.h>
49 #include "ptlrpc_internal.h"
51 static char *sec_flags2str(unsigned long flags, char *buf, int bufsize)
55 if (flags & PTLRPC_SEC_FL_REVERSE)
56 strlcat(buf, "reverse,", bufsize);
57 if (flags & PTLRPC_SEC_FL_ROOTONLY)
58 strlcat(buf, "rootonly,", bufsize);
59 if (flags & PTLRPC_SEC_FL_UDESC)
60 strlcat(buf, "udesc,", bufsize);
61 if (flags & PTLRPC_SEC_FL_BULK)
62 strlcat(buf, "bulk,", bufsize);
64 strlcat(buf, "-,", bufsize);
69 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
71 struct obd_device *obd = seq->private;
72 struct client_obd *cli = &obd->u.cli;
73 struct ptlrpc_sec *sec = NULL;
76 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
77 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
78 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) == 0 ||
79 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0 ||
80 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0);
83 sec = sptlrpc_import_sec_ref(cli->cl_import);
87 sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str));
89 seq_printf(seq, "rpc flavor: %s\n",
90 sptlrpc_flavor2name_base(sec->ps_flvr.sf_rpc));
91 seq_printf(seq, "bulk flavor: %s\n",
92 sptlrpc_flavor2name_bulk(&sec->ps_flvr, str, sizeof(str)));
93 seq_printf(seq, "flags: %s\n",
94 sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str)));
95 seq_printf(seq, "id: %d\n", sec->ps_id);
96 seq_printf(seq, "refcount: %d\n",
97 atomic_read(&sec->ps_refcount));
98 seq_printf(seq, "nctx: %d\n", atomic_read(&sec->ps_nctx));
99 seq_printf(seq, "gc internal %lld\n", sec->ps_gc_interval);
100 seq_printf(seq, "gc next %lld\n",
101 sec->ps_gc_interval ?
102 (s64)(sec->ps_gc_next - ktime_get_real_seconds()) : 0ll);
104 sptlrpc_sec_put(sec);
109 LDEBUGFS_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
111 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
113 struct obd_device *obd = seq->private;
114 struct client_obd *cli = &obd->u.cli;
115 struct ptlrpc_sec *sec = NULL;
117 LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
118 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
119 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) == 0 ||
120 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) == 0 ||
121 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) == 0);
124 sec = sptlrpc_import_sec_ref(cli->cl_import);
128 if (sec->ps_policy->sp_cops->display)
129 sec->ps_policy->sp_cops->display(sec, seq);
131 sptlrpc_sec_put(sec);
136 LDEBUGFS_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
138 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
139 static ssize_t sepol_seq_write_old(struct obd_device *obd,
140 const char __user *buffer, size_t count)
142 struct client_obd *cli = &obd->u.cli;
143 struct obd_import *imp = cli->cl_import;
144 struct sepol_downcall_data_old *param;
145 size_t maxlen = sizeof(imp->imp_sec->ps_sepol);
146 size_t size = sizeof(*param);
147 size_t maxparam = sizeof(*param) + maxlen;
153 CERROR("%s: invalid data count %zu <= size %zu: rc = %d\n",
154 obd->obd_name, count, size, rc);
158 OBD_ALLOC(param, maxparam);
162 if (copy_from_user(param, buffer, min(count, maxparam))) {
164 CERROR("%s: bad sepol data: rc = %d\n", obd->obd_name, rc);
168 if (param->sdd_magic != SEPOL_DOWNCALL_MAGIC_OLD) {
170 CERROR("%s: sepol downcall bad magic %#08x != %#08x: rc = %d\n",
171 obd->obd_name, param->sdd_magic,
172 SEPOL_DOWNCALL_MAGIC_OLD, rc);
176 len = param->sdd_sepol_len;
177 if (len == 0 || len >= maxlen) {
179 CERROR("%s: bad sepol len %u >= maxlen %zu: rc = %d\n",
180 obd->obd_name, len, maxlen, rc);
183 size = offsetof(typeof(*param), sdd_sepol[len]);
187 CERROR("%s: bad sepol count %zu < total size %zu: rc = %d\n",
188 obd->obd_name, count, size, rc);
192 spin_lock(&imp->imp_sec->ps_lock);
193 memcpy(imp->imp_sec->ps_sepol, param->sdd_sepol, len);
194 imp->imp_sec->ps_sepol[len + 1] = '\0';
195 imp->imp_sec->ps_sepol_mtime = ktime_set(param->sdd_sepol_mtime, 0);
196 spin_unlock(&imp->imp_sec->ps_lock);
199 OBD_FREE(param, maxparam);
206 ldebugfs_sptlrpc_sepol_seq_write(struct file *file, const char __user *buffer,
207 size_t count, void *data)
209 struct seq_file *seq = file->private_data;
210 struct obd_device *obd = seq->private;
211 struct client_obd *cli = &obd->u.cli;
212 struct obd_import *imp = cli->cl_import;
213 struct sepol_downcall_data *param;
214 size_t maxlen = sizeof(imp->imp_sec->ps_sepol);
215 size_t size = sizeof(*param);
216 size_t maxparam = size + maxlen;
222 CERROR("%s: invalid data count %zu <= size %zu: rc = %d\n",
223 obd->obd_name, count, size, rc);
227 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
231 if (copy_from_user(&magic, buffer, sizeof(magic))) {
233 CERROR("%s: bad sepol magic data: rc = %d\n",
238 if (unlikely(magic == SEPOL_DOWNCALL_MAGIC_OLD))
239 return sepol_seq_write_old(obd, buffer, count);
243 OBD_ALLOC(param, maxparam);
247 if (copy_from_user(param, buffer, min(count, maxparam))) {
249 CERROR("%s: bad sepol data: rc = %d\n", obd->obd_name, rc);
253 if (param->sdd_magic != SEPOL_DOWNCALL_MAGIC) {
255 CERROR("%s: sepol downcall bad magic %#08x != %#08x: rc = %d\n",
256 obd->obd_name, param->sdd_magic,
257 SEPOL_DOWNCALL_MAGIC, rc);
261 len = param->sdd_sepol_len;
262 if (len == 0 || len >= maxlen) {
264 CERROR("%s: bad sepol len %u >= maxlen %zu: rc = %d\n",
265 obd->obd_name, len, maxlen, rc);
268 size = offsetof(typeof(*param), sdd_sepol[len]);
272 CERROR("%s: bad sepol count %zu < total size %zu: rc = %d\n",
273 obd->obd_name, count, size, rc);
277 spin_lock(&imp->imp_sec->ps_lock);
278 memcpy(imp->imp_sec->ps_sepol, param->sdd_sepol, len);
279 imp->imp_sec->ps_sepol[len + 1] = '\0';
280 imp->imp_sec->ps_sepol_mtime = ktime_set(param->sdd_sepol_mtime, 0);
281 spin_unlock(&imp->imp_sec->ps_lock);
284 OBD_FREE(param, maxparam);
288 LDEBUGFS_FOPS_WR_ONLY(srpc, sptlrpc_sepol);
290 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *obd)
292 if (strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
293 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
294 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) != 0 &&
295 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) != 0 &&
296 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) != 0) {
297 CERROR("can't register lproc for obd type %s\n",
298 obd->obd_type->typ_name);
302 debugfs_create_file("srpc_info", 0444, obd->obd_debugfs_entry, obd,
303 &sptlrpc_info_lprocfs_fops);
305 debugfs_create_file("srpc_contexts", 0444, obd->obd_debugfs_entry, obd,
306 &sptlrpc_ctxs_lprocfs_fops);
308 debugfs_create_file("srpc_sepol", 0200, obd->obd_debugfs_entry, obd,
309 &srpc_sptlrpc_sepol_fops);
313 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
315 LDEBUGFS_SEQ_FOPS_RO(sptlrpc_proc_enc_pool);
317 static struct ldebugfs_vars sptlrpc_lprocfs_vars[] = {
318 { .name = "encrypt_page_pools",
319 .fops = &sptlrpc_proc_enc_pool_fops },
323 struct dentry *sptlrpc_debugfs_dir;
324 EXPORT_SYMBOL(sptlrpc_debugfs_dir);
326 struct proc_dir_entry *sptlrpc_lprocfs_dir;
327 EXPORT_SYMBOL(sptlrpc_lprocfs_dir);
329 int sptlrpc_lproc_init(void)
333 LASSERT(sptlrpc_debugfs_dir == NULL);
335 sptlrpc_debugfs_dir = debugfs_create_dir("sptlrpc",
336 debugfs_lustre_root);
337 ldebugfs_add_vars(sptlrpc_debugfs_dir, sptlrpc_lprocfs_vars, NULL);
339 sptlrpc_lprocfs_dir = lprocfs_register("sptlrpc", proc_lustre_root,
341 if (IS_ERR_OR_NULL(sptlrpc_lprocfs_dir)) {
342 rc = PTR_ERR(sptlrpc_lprocfs_dir);
343 rc = sptlrpc_lprocfs_dir ? PTR_ERR(sptlrpc_lprocfs_dir)
345 sptlrpc_lprocfs_dir = NULL;
350 void sptlrpc_lproc_fini(void)
352 debugfs_remove_recursive(sptlrpc_debugfs_dir);
353 sptlrpc_debugfs_dir = NULL;
355 if (!IS_ERR_OR_NULL(sptlrpc_lprocfs_dir))
356 lprocfs_remove(&sptlrpc_lprocfs_dir);