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,
143 struct client_obd *cli = &obd->u.cli;
144 struct obd_import *imp = cli->cl_import;
145 struct sepol_downcall_data_old *param;
146 int size = sizeof(*param);
152 CERROR("%s: invalid data count = %lu, size = %d: rc = %d\n",
153 obd->obd_name, (unsigned long) count, size, rc);
157 OBD_ALLOC(param, size);
161 if (copy_from_user(param, buffer, size)) {
163 CERROR("%s: bad sepol data: rc = %d\n", obd->obd_name, rc);
167 if (param->sdd_magic != SEPOL_DOWNCALL_MAGIC_OLD) {
169 CERROR("%s: sepol downcall bad params: rc = %d\n",
174 if (param->sdd_sepol_len == 0 ||
175 param->sdd_sepol_len >= sizeof(imp->imp_sec->ps_sepol)) {
177 CERROR("%s: invalid sepol data returned: rc = %d\n",
181 len = param->sdd_sepol_len; /* save sdd_sepol_len */
182 OBD_FREE(param, size);
183 size = offsetof(struct sepol_downcall_data_old,
188 CERROR("%s: invalid sepol count = %lu, size = %d: rc = %d\n",
189 obd->obd_name, (unsigned long) count, size, rc);
193 /* alloc again with real size */
194 OBD_ALLOC(param, size);
198 if (copy_from_user(param, buffer, size)) {
200 CERROR("%s: cannot copy sepol data: rc = %d\n",
205 spin_lock(&imp->imp_sec->ps_lock);
206 snprintf(imp->imp_sec->ps_sepol, param->sdd_sepol_len + 1, "%s",
208 imp->imp_sec->ps_sepol_mtime = ktime_set(param->sdd_sepol_mtime, 0);
209 spin_unlock(&imp->imp_sec->ps_lock);
213 OBD_FREE(param, size);
215 return rc ? rc : count;
220 ldebugfs_sptlrpc_sepol_seq_write(struct file *file, const char __user *buffer,
221 size_t count, void *data)
223 struct seq_file *seq = file->private_data;
224 struct obd_device *obd = seq->private;
225 struct client_obd *cli = &obd->u.cli;
226 struct obd_import *imp = cli->cl_import;
227 struct sepol_downcall_data *param;
229 int size = sizeof(magic);
235 CERROR("%s: invalid buffer count = %lu, size = %d: rc = %d\n",
236 obd->obd_name, (unsigned long) count, size, rc);
240 if (copy_from_user(&magic, buffer, size)) {
242 CERROR("%s: bad sepol magic: rc = %d\n", obd->obd_name, rc);
246 if (magic != SEPOL_DOWNCALL_MAGIC) {
247 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 16, 53, 0)
248 if (magic == SEPOL_DOWNCALL_MAGIC_OLD) {
249 return sepol_seq_write_old(obd, buffer, count);
253 CERROR("%s: sepol downcall bad magic '%#08x': rc = %d\n",
254 obd->obd_name, magic, rc);
258 size = sizeof(*param);
261 CERROR("%s: invalid data count = %lu, size = %d: rc = %d\n",
262 obd->obd_name, (unsigned long) count, size, rc);
266 OBD_ALLOC(param, size);
270 if (copy_from_user(param, buffer, size)) {
272 CERROR("%s: bad sepol data: rc = %d\n", obd->obd_name, rc);
276 if (param->sdd_sepol_len == 0 ||
277 param->sdd_sepol_len >= sizeof(imp->imp_sec->ps_sepol)) {
279 CERROR("%s: invalid sepol data returned: rc = %d\n",
283 len = param->sdd_sepol_len; /* save sdd_sepol_len */
284 OBD_FREE(param, size);
285 size = offsetof(struct sepol_downcall_data,
288 /* alloc again with real size */
289 OBD_ALLOC(param, size);
293 if (copy_from_user(param, buffer, size)) {
295 CERROR("%s: cannot copy sepol data: rc = %d\n",
300 spin_lock(&imp->imp_sec->ps_lock);
301 snprintf(imp->imp_sec->ps_sepol, param->sdd_sepol_len + 1, "%s",
303 imp->imp_sec->ps_sepol_mtime = ktime_set(param->sdd_sepol_mtime, 0);
304 spin_unlock(&imp->imp_sec->ps_lock);
308 OBD_FREE(param, size);
310 return rc ? rc : count;
312 LDEBUGFS_FOPS_WR_ONLY(srpc, sptlrpc_sepol);
314 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *obd)
316 if (strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
317 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
318 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) != 0 &&
319 strcmp(obd->obd_type->typ_name, LUSTRE_LWP_NAME) != 0 &&
320 strcmp(obd->obd_type->typ_name, LUSTRE_OSP_NAME) != 0) {
321 CERROR("can't register lproc for obd type %s\n",
322 obd->obd_type->typ_name);
326 debugfs_create_file("srpc_info", 0444, obd->obd_debugfs_entry, obd,
327 &sptlrpc_info_lprocfs_fops);
329 debugfs_create_file("srpc_contexts", 0444, obd->obd_debugfs_entry, obd,
330 &sptlrpc_ctxs_lprocfs_fops);
332 debugfs_create_file("srpc_sepol", 0200, obd->obd_debugfs_entry, obd,
333 &srpc_sptlrpc_sepol_fops);
337 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
339 LDEBUGFS_SEQ_FOPS_RO(sptlrpc_proc_enc_pool);
341 static struct ldebugfs_vars sptlrpc_lprocfs_vars[] = {
342 { .name = "encrypt_page_pools",
343 .fops = &sptlrpc_proc_enc_pool_fops },
347 struct dentry *sptlrpc_debugfs_dir;
348 EXPORT_SYMBOL(sptlrpc_debugfs_dir);
350 struct proc_dir_entry *sptlrpc_lprocfs_dir;
351 EXPORT_SYMBOL(sptlrpc_lprocfs_dir);
353 int sptlrpc_lproc_init(void)
357 LASSERT(sptlrpc_debugfs_dir == NULL);
359 sptlrpc_debugfs_dir = debugfs_create_dir("sptlrpc",
360 debugfs_lustre_root);
361 ldebugfs_add_vars(sptlrpc_debugfs_dir, sptlrpc_lprocfs_vars, NULL);
363 sptlrpc_lprocfs_dir = lprocfs_register("sptlrpc", proc_lustre_root,
365 if (IS_ERR_OR_NULL(sptlrpc_lprocfs_dir)) {
366 rc = PTR_ERR(sptlrpc_lprocfs_dir);
367 rc = sptlrpc_lprocfs_dir ? PTR_ERR(sptlrpc_lprocfs_dir)
369 sptlrpc_lprocfs_dir = NULL;
374 void sptlrpc_lproc_fini(void)
376 debugfs_remove_recursive(sptlrpc_debugfs_dir);
377 sptlrpc_debugfs_dir = NULL;
379 if (!IS_ERR_OR_NULL(sptlrpc_lprocfs_dir))
380 lprocfs_remove(&sptlrpc_lprocfs_dir);