Whamcloud - gitweb
- make HEAD from b_post_cmd3
[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         struct ptlrpc_cli_ctx    *ctx;
74         struct hlist_node        *pos, *next;
75         char                      flags_str[32];
76         int                       written, i;
77
78         if (obd == NULL)
79                 return 0;
80
81         LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
82                 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
83                 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
84         LASSERT(conf->sfc_bulk_csum < BULK_CSUM_ALG_MAX);
85         LASSERT(conf->sfc_bulk_priv < BULK_PRIV_ALG_MAX);
86
87         if (obd->u.cli.cl_import)
88                 sec = obd->u.cli.cl_import->imp_sec;
89
90         if (sec == NULL) {
91                 written = snprintf(page, count, "\n");
92                 goto out;
93         }
94
95         sec_flags2str(sec->ps_flags, flags_str, sizeof(flags_str));
96
97         written = snprintf(page, count,
98                         "rpc msg flavor:        %s\n"
99                         "bulk checksum:         %s\n"
100                         "bulk encrypt:          %s\n"
101                         "flags:                 %s\n"
102                         "ctx cache size         %u\n"
103                         "ctx cache busy         %d\n"
104                         "gc interval            %lu\n"
105                         "gc next                %ld\n",
106                         sptlrpc_flavor2name(sec->ps_flavor),
107                         sptlrpc_bulk_csum_alg2name(conf->sfc_bulk_csum),
108                         sptlrpc_bulk_priv_alg2name(conf->sfc_bulk_priv),
109                         flags_str,
110                         sec->ps_ccache_size,
111                         atomic_read(&sec->ps_busy),
112                         sec->ps_gc_interval,
113                         sec->ps_gc_interval ?
114                                 sec->ps_gc_next - cfs_time_current_sec() : 0
115                           );
116         /*
117          * list contexts
118          */
119         if (sec->ps_policy->sp_policy != SPTLRPC_POLICY_GSS)
120                 goto out;
121
122         written += snprintf(page + written, count - written,
123                             "GSS contexts ==>\n");
124
125         spin_lock(&sec->ps_lock);
126         for (i = 0; i < sec->ps_ccache_size; i++) {
127                 hlist_for_each_entry_safe(ctx, pos, next,
128                                           &sec->ps_ccache[i], cc_hash) {
129                         if (written >= count)
130                                 break;
131                         written += sptlrpc_ctx_display(ctx, page + written,
132                                                        count - written);
133                 }
134         }
135         spin_unlock(&sec->ps_lock);
136
137 out:
138         return written;
139 }
140 EXPORT_SYMBOL(sptlrpc_lprocfs_rd);
141
142 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
143         { "enc_pool", sptlrpc_proc_read_enc_pool, NULL, NULL },
144         { NULL }
145 };
146
147 int sptlrpc_lproc_init(void)
148 {
149         int     rc;
150
151         LASSERT(sptlrpc_proc_root == NULL);
152
153         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
154                                              sptlrpc_lprocfs_vars, NULL);
155         if (IS_ERR(sptlrpc_proc_root)) {
156                 rc = PTR_ERR(sptlrpc_proc_root);
157                 sptlrpc_proc_root = NULL;
158                 return rc;
159         }
160         return 0;
161 }
162
163 void sptlrpc_lproc_fini(void)
164 {
165         if (sptlrpc_proc_root) {
166                 lprocfs_remove(&sptlrpc_proc_root);
167                 sptlrpc_proc_root = NULL;
168         }
169 }
170
171 #else /* !__KERNEL__ */
172
173 int sptlrpc_lproc_init(void)
174 {
175         return 0;
176 }
177
178 void sptlrpc_lproc_fini(void)
179 {
180 }
181
182 #endif