Whamcloud - gitweb
115eae6c75f0814e0a9922f01736dd29f6c0a212
[fs/lustre-release.git] / lustre / ptlrpc / sec_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2006 Cluster File Systems, Inc.
5  *   Author: Eric Mei <ericm@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef EXPORT_SYMTAB
24 #define EXPORT_SYMTAB
25 #endif
26 #define DEBUG_SUBSYSTEM S_SEC
27
28 #include <libcfs/libcfs.h>
29 #ifndef __KERNEL__
30 #include <liblustre.h>
31 #include <libcfs/list.h>
32 #else
33 #include <linux/crypto.h>
34 #endif
35
36 #include <obd.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>
43
44 #include "ptlrpc_internal.h"
45
46 #ifdef __KERNEL__
47
48 struct proc_dir_entry *sptlrpc_proc_root = NULL;
49 EXPORT_SYMBOL(sptlrpc_proc_root);
50
51 void sec_flags2str(unsigned long flags, char *buf, int bufsize)
52 {
53         buf[0] = '\0';
54
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);
63         if (buf[0] == '\0')
64                 strncat(buf, "-,", bufsize);
65
66         buf[strlen(buf) - 1] = '\0';
67
68 }
69
70 static int sptlrpc_info_lprocfs_seq_show(struct seq_file *seq, void *v)
71 {
72         struct obd_device *dev = seq->private;
73         struct client_obd *cli = &dev->u.cli;
74         struct ptlrpc_sec *sec = NULL;
75         char               flags_str[32];
76
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
81         if (cli->cl_import)
82                 sec = sptlrpc_import_sec_ref(cli->cl_import);
83         if (sec == NULL)
84                 goto out;
85
86         sec_flags2str(sec->ps_flvr.sf_flags, flags_str, sizeof(flags_str));
87
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_bulk_csum_alg2name(sec->ps_flvr.sf_bulk_csum),
92                    sptlrpc_bulk_priv_alg2name(sec->ps_flvr.sf_bulk_priv));
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",
99                    sec->ps_gc_interval ?
100                    sec->ps_gc_next - cfs_time_current_sec() : 0);
101
102         sptlrpc_sec_put(sec);
103 out:
104         return 0;
105 }
106 LPROC_SEQ_FOPS_RO(sptlrpc_info_lprocfs);
107
108 static int sptlrpc_ctxs_lprocfs_seq_show(struct seq_file *seq, void *v)
109 {
110         struct obd_device *dev = seq->private;
111         struct client_obd *cli = &dev->u.cli;
112         struct ptlrpc_sec *sec = NULL;
113
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);
117
118         if (cli->cl_import)
119                 sec = sptlrpc_import_sec_ref(cli->cl_import);
120         if (sec == NULL)
121                 goto out;
122
123         if (sec->ps_policy->sp_cops->display)
124                 sec->ps_policy->sp_cops->display(sec, seq);
125
126         sptlrpc_sec_put(sec);
127 out:
128         return 0;
129 }
130 LPROC_SEQ_FOPS_RO(sptlrpc_ctxs_lprocfs);
131
132 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
133 {
134         int     rc;
135
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);
141                 return -EINVAL;
142         }
143
144         rc = lprocfs_obd_seq_create(dev, "srpc.info", 0444,
145                                     &sptlrpc_info_lprocfs_fops, dev);
146         if (rc) {
147                 CERROR("create proc entry srpc.info for %s: %d\n",
148                        dev->obd_name, rc);
149                 return rc;
150         }
151
152         rc = lprocfs_obd_seq_create(dev, "srpc.contexts", 0444,
153                                     &sptlrpc_ctxs_lprocfs_fops, dev);
154         if (rc) {
155                 CERROR("create proc entry srpc.contexts for %s: %d\n",
156                        dev->obd_name, rc);
157                 return rc;
158         }
159
160         return 0;
161 }
162 EXPORT_SYMBOL(sptlrpc_lprocfs_cliobd_attach);
163
164 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
165         { "encrypt_page_pools", sptlrpc_proc_read_enc_pool, NULL, NULL },
166         { NULL }
167 };
168
169 int sptlrpc_lproc_init(void)
170 {
171         int     rc;
172
173         LASSERT(sptlrpc_proc_root == NULL);
174
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;
180                 return rc;
181         }
182         return 0;
183 }
184
185 void sptlrpc_lproc_fini(void)
186 {
187         if (sptlrpc_proc_root) {
188                 lprocfs_remove(&sptlrpc_proc_root);
189                 sptlrpc_proc_root = NULL;
190         }
191 }
192
193 #else /* !__KERNEL__ */
194
195 int sptlrpc_lprocfs_cliobd_attach(struct obd_device *dev)
196 {
197         return 0;
198 }
199
200 int sptlrpc_lproc_init(void)
201 {
202         return 0;
203 }
204
205 void sptlrpc_lproc_fini(void)
206 {
207 }
208
209 #endif