Whamcloud - gitweb
branch: HEAD
[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  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 #define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_SEC
26
27 #include <libcfs/libcfs.h>
28 #ifndef __KERNEL__
29 #include <liblustre.h>
30 #include <libcfs/list.h>
31 #else
32 #include <linux/crypto.h>
33 #endif
34
35 #include <obd.h>
36 #include <obd_class.h>
37 #include <obd_support.h>
38 #include <lustre_net.h>
39 #include <lustre_import.h>
40 #include <lustre_dlm.h>
41 #include <lustre_sec.h>
42
43 #include "ptlrpc_internal.h"
44
45 #ifdef __KERNEL__
46
47 struct proc_dir_entry *sptlrpc_proc_root = NULL;
48 EXPORT_SYMBOL(sptlrpc_proc_root);
49
50 void sec_flags2str(unsigned long flags, char *buf, int bufsize)
51 {
52         buf[0] = '\0';
53
54         if (flags & PTLRPC_SEC_FL_REVERSE)
55                 strncat(buf, "reverse,", bufsize);
56         if (flags & PTLRPC_SEC_FL_ROOTONLY)
57                 strncat(buf, "rootonly,", bufsize);
58         if (flags & PTLRPC_SEC_FL_BULK)
59                 strncat(buf, "bulk,", bufsize);
60         if (buf[0] == '\0')
61                 strncat(buf, "-,", bufsize);
62
63         buf[strlen(buf) - 1] = '\0';
64
65 }
66
67 int sptlrpc_lprocfs_rd(char *page, char **start, off_t off, int count,
68                        int *eof, void *data)
69 {
70         struct obd_device        *obd = data;
71         struct sec_flavor_config *conf = &obd->u.cli.cl_sec_conf;
72         struct ptlrpc_sec        *sec = NULL;
73         char                      flags_str[32];
74         int                       written;
75
76         if (obd == NULL)
77                 return 0;
78
79         LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
80                 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
81                 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
82         LASSERT(conf->sfc_bulk_csum < BULK_CSUM_ALG_MAX);
83         LASSERT(conf->sfc_bulk_priv < BULK_PRIV_ALG_MAX);
84
85         if (obd->u.cli.cl_import)
86                 sec = obd->u.cli.cl_import->imp_sec;
87
88         if (sec == NULL) {
89                 written = snprintf(page, count, "\n");
90                 goto out;
91         }
92
93         sec_flags2str(sec->ps_flags, flags_str, sizeof(flags_str));
94
95         written = snprintf(page, count,
96                         "rpc msg flavor:        %s\n"
97                         "bulk checksum:         %s\n"
98                         "bulk encrypt:          %s\n"
99                         "flags:                 %s\n"
100                         "ctx cache busy         %d\n"
101                         "gc interval            %lu\n"
102                         "gc next                %ld\n",
103                         sptlrpc_flavor2name(sec->ps_flavor),
104                         sptlrpc_bulk_csum_alg2name(conf->sfc_bulk_csum),
105                         sptlrpc_bulk_priv_alg2name(conf->sfc_bulk_priv),
106                         flags_str,
107                         atomic_read(&sec->ps_busy),
108                         sec->ps_gc_interval,
109                         sec->ps_gc_interval ?
110                                 sec->ps_gc_next - cfs_time_current_sec() : 0
111                           );
112
113         if (sec->ps_policy->sp_cops->display) {
114                 written += sec->ps_policy->sp_cops->display(
115                                         sec, page + written, count - written);
116         }
117 #if 0
118         /*
119          * list contexts
120          */
121         if (sec->ps_policy->sp_policy != SPTLRPC_POLICY_GSS)
122                 goto out;
123
124         written += snprintf(page + written, count - written,
125                             "GSS contexts ==>\n");
126
127         spin_lock(&sec->ps_lock);
128         for (i = 0; i < sec->ps_ccache_size; i++) {
129                 hlist_for_each_entry_safe(ctx, pos, next,
130                                           &sec->ps_ccache[i], cc_hash) {
131                         if (written >= count)
132                                 break;
133                         written += sptlrpc_cli_ctx_display(ctx, page + written,
134                                                            count - written);
135                 }
136         }
137         spin_unlock(&sec->ps_lock);
138 #endif
139
140 out:
141         return written;
142 }
143 EXPORT_SYMBOL(sptlrpc_lprocfs_rd);
144
145 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
146         { "enc_pool", sptlrpc_proc_read_enc_pool, NULL, NULL },
147         { NULL }
148 };
149
150 int sptlrpc_lproc_init(void)
151 {
152         int     rc;
153
154         LASSERT(sptlrpc_proc_root == NULL);
155
156         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
157                                              sptlrpc_lprocfs_vars, NULL);
158         if (IS_ERR(sptlrpc_proc_root)) {
159                 rc = PTR_ERR(sptlrpc_proc_root);
160                 sptlrpc_proc_root = NULL;
161                 return rc;
162         }
163         return 0;
164 }
165
166 void sptlrpc_lproc_fini(void)
167 {
168         if (sptlrpc_proc_root) {
169                 lprocfs_remove(&sptlrpc_proc_root);
170                 sptlrpc_proc_root = NULL;
171         }
172 }
173
174 #else /* !__KERNEL__ */
175
176 int sptlrpc_lproc_init(void)
177 {
178         return 0;
179 }
180
181 void sptlrpc_lproc_fini(void)
182 {
183 }
184
185 #endif