1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/sec_lproc.c
38 * Author: Eric Mei <ericm@clusterfs.com>
44 #define DEBUG_SUBSYSTEM S_SEC
46 #include <libcfs/libcfs.h>
48 #include <liblustre.h>
49 #include <libcfs/list.h>
51 #include <linux/crypto.h>
55 #include <obd_class.h>
56 #include <obd_support.h>
57 #include <lustre_net.h>
58 #include <lustre_import.h>
59 #include <lustre_dlm.h>
60 #include <lustre_sec.h>
62 #include "ptlrpc_internal.h"
66 struct proc_dir_entry *sptlrpc_proc_root = NULL;
67 EXPORT_SYMBOL(sptlrpc_proc_root);
69 char *sec_flags2str(unsigned long flags, char *buf, int bufsize)
73 if (flags & PTLRPC_SEC_FL_REVERSE)
74 strncat(buf, "reverse,", bufsize);
75 if (flags & PTLRPC_SEC_FL_ROOTONLY)
76 strncat(buf, "rootonly,", bufsize);
77 if (flags & PTLRPC_SEC_FL_UDESC)
78 strncat(buf, "udesc,", bufsize);
79 if (flags & PTLRPC_SEC_FL_BULK)
80 strncat(buf, "bulk,", bufsize);
82 strncat(buf, "-,", bufsize);
84 buf[strlen(buf) - 1] = '\0';
88 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
90 struct obd_device *dev = seq->private;
91 struct client_obd *cli = &dev->u.cli;
92 struct ptlrpc_sec *sec = NULL;
95 LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
96 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
97 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
100 sec = sptlrpc_import_sec_ref(cli->cl_import);
104 sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str));
106 seq_printf(seq, "rpc flavor: %s\n",
107 sptlrpc_flavor2name_base(sec->ps_flvr.sf_rpc));
108 seq_printf(seq, "bulk flavor: %s\n",
109 sptlrpc_flavor2name_bulk(&sec->ps_flvr, str, sizeof(str)));
110 seq_printf(seq, "flags: %s\n",
111 sec_flags2str(sec->ps_flvr.sf_flags, str, sizeof(str)));
112 seq_printf(seq, "id: %d\n", sec->ps_id);
113 seq_printf(seq, "refcount: %d\n", atomic_read(&sec->ps_refcount));
114 seq_printf(seq, "nctx: %d\n", atomic_read(&sec->ps_nctx));
115 seq_printf(seq, "gc internal %ld\n", sec->ps_gc_interval);
116 seq_printf(seq, "gc next %ld\n",
117 sec->ps_gc_interval ?
118 sec->ps_gc_next - cfs_time_current_sec() : 0);
120 sptlrpc_sec_put(sec);
124 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
126 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
128 struct obd_device *dev = seq->private;
129 struct client_obd *cli = &dev->u.cli;
130 struct ptlrpc_sec *sec = NULL;
132 LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
133 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
134 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
137 sec = sptlrpc_import_sec_ref(cli->cl_import);
141 if (sec->ps_policy->sp_cops->display)
142 sec->ps_policy->sp_cops->display(sec, seq);
144 sptlrpc_sec_put(sec);
148 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
150 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
154 if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
155 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
156 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
157 CERROR("can't register lproc for obd type %s\n",
158 dev->obd_type->typ_name);
162 rc = lprocfs_obd_seq_create(dev, "srpc_info", 0444,
163 &sptlrpc_info_lprocfs_fops, dev);
165 CERROR("create proc entry srpc_info for %s: %d\n",
170 rc = lprocfs_obd_seq_create(dev, "srpc_contexts", 0444,
171 &sptlrpc_ctxs_lprocfs_fops, dev);
173 CERROR("create proc entry srpc_contexts for %s: %d\n",
180 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
182 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
183 { "encrypt_page_pools", sptlrpc_proc_read_enc_pool, NULL, NULL },
187 int sptlrpc_lproc_init(void)
191 LASSERT(sptlrpc_proc_root == NULL);
193 sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
194 sptlrpc_lprocfs_vars, NULL);
195 if (IS_ERR(sptlrpc_proc_root)) {
196 rc = PTR_ERR(sptlrpc_proc_root);
197 sptlrpc_proc_root = NULL;
203 void sptlrpc_lproc_fini(void)
205 if (sptlrpc_proc_root) {
206 lprocfs_remove(&sptlrpc_proc_root);
207 sptlrpc_proc_root = NULL;
211 #else /* !__KERNEL__ */
213 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
218 int sptlrpc_lproc_init(void)
223 void sptlrpc_lproc_fini(void)