1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2006 Cluster File Systems, Inc.
5 * Author: Eric Mei <ericm@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define DEBUG_SUBSYSTEM S_SEC
28 #include <libcfs/libcfs.h>
30 #include <liblustre.h>
31 #include <libcfs/list.h>
33 #include <linux/crypto.h>
37 #include <obd_class.h>
38 #include <obd_support.h>
39 #include <lustre_net.h>
40 #include <lustre_import.h>
41 #include <lustre_dlm.h>
42 #include <lustre_sec.h>
44 #include "ptlrpc_internal.h"
48 struct proc_dir_entry *sptlrpc_proc_root = NULL;
49 EXPORT_SYMBOL(sptlrpc_proc_root);
51 void sec_flags2str(unsigned long flags, char *buf, int bufsize)
55 if (flags & PTLRPC_SEC_FL_REVERSE)
56 strncat(buf, "reverse,", bufsize);
57 if (flags & PTLRPC_SEC_FL_ROOTONLY)
58 strncat(buf, "rootonly,", bufsize);
59 if (flags & PTLRPC_SEC_FL_UDESC)
60 strncat(buf, "udesc,", bufsize);
61 if (flags & PTLRPC_SEC_FL_BULK)
62 strncat(buf, "bulk,", bufsize);
64 strncat(buf, "-,", bufsize);
66 buf[strlen(buf) - 1] = '\0';
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);
82 sec = sptlrpc_import_sec_ref(cli->cl_import);
86 sec_flags2str(sec->ps_flvr.sf_flags, flags_str, sizeof(flags_str));
88 seq_printf(seq, "rpc flavor: %s\n",
89 sptlrpc_rpcflavor2name(sec->ps_flvr.sf_rpc));
90 seq_printf(seq, "bulk flavor: %s/%s\n",
91 sptlrpc_get_hash_name(sec->ps_flvr.sf_bulk_hash),
92 sptlrpc_get_ciph_name(sec->ps_flvr.sf_bulk_ciph));
93 seq_printf(seq, "flags: %s\n", flags_str);
94 seq_printf(seq, "id: %d\n", sec->ps_id);
95 seq_printf(seq, "refcount: %d\n", atomic_read(&sec->ps_refcount));
96 seq_printf(seq, "nctx: %d\n", atomic_read(&sec->ps_nctx));
97 seq_printf(seq, "gc internal %ld\n", sec->ps_gc_interval);
98 seq_printf(seq, "gc next %ld\n",
100 sec->ps_gc_next - cfs_time_current_sec() : 0);
102 sptlrpc_sec_put(sec);
106 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
108 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
110 struct obd_device *dev = seq->private;
111 struct client_obd *cli = &dev->u.cli;
112 struct ptlrpc_sec *sec = NULL;
114 LASSERT(strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
115 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
116 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
119 sec = sptlrpc_import_sec_ref(cli->cl_import);
123 if (sec->ps_policy->sp_cops->display)
124 sec->ps_policy->sp_cops->display(sec, seq);
126 sptlrpc_sec_put(sec);
130 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
132 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
136 if (strcmp(dev->obd_type->typ_name, LUSTRE_OSC_NAME) != 0 &&
137 strcmp(dev->obd_type->typ_name, LUSTRE_MDC_NAME) != 0 &&
138 strcmp(dev->obd_type->typ_name, LUSTRE_MGC_NAME) != 0) {
139 CERROR("can't register lproc for obd type %s\n",
140 dev->obd_type->typ_name);
144 rc = lprocfs_obd_seq_create(dev, "srpc.info", 0444,
145 &sptlrpc_info_lprocfs_fops, dev);
147 CERROR("create proc entry srpc.info for %s: %d\n",
152 rc = lprocfs_obd_seq_create(dev, "srpc.contexts", 0444,
153 &sptlrpc_ctxs_lprocfs_fops, dev);
155 CERROR("create proc entry srpc.contexts for %s: %d\n",
162 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
164 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
165 { "encrypt_page_pools", sptlrpc_proc_read_enc_pool, NULL, NULL },
169 int sptlrpc_lproc_init(void)
173 LASSERT(sptlrpc_proc_root == NULL);
175 sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
176 sptlrpc_lprocfs_vars, NULL);
177 if (IS_ERR(sptlrpc_proc_root)) {
178 rc = PTR_ERR(sptlrpc_proc_root);
179 sptlrpc_proc_root = NULL;
185 void sptlrpc_lproc_fini(void)
187 if (sptlrpc_proc_root) {
188 lprocfs_remove(&sptlrpc_proc_root);
189 sptlrpc_proc_root = NULL;
193 #else /* !__KERNEL__ */
195 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
200 int sptlrpc_lproc_init(void)
205 void sptlrpc_lproc_fini(void)