Whamcloud - gitweb
branch: b_new_cmd
[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 (flags & PTLRPC_SEC_FL_PAG)
61                 strncat(buf, "pag,", bufsize);
62         if (buf[0] == '\0')
63                 strncat(buf, "-,", bufsize);
64
65         buf[strlen(buf) - 1] = '\0';
66
67 }
68
69 int sptlrpc_lprocfs_rd(char *page, char **start, off_t off, int count,
70                        int *eof, void *data)
71 {
72         struct obd_device        *obd = data;
73         struct sec_flavor_config *conf = &obd->u.cli.cl_sec_conf;
74         struct ptlrpc_sec        *sec = NULL;
75         struct ptlrpc_cli_ctx    *ctx;
76         struct hlist_node        *pos, *next;
77         char                      flags_str[32];
78         int                       written, i;
79
80         if (obd == NULL)
81                 return 0;
82
83         LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
84                 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
85                 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
86         LASSERT(conf->sfc_bulk_csum < BULK_CSUM_ALG_MAX);
87         LASSERT(conf->sfc_bulk_priv < BULK_PRIV_ALG_MAX);
88
89         if (obd->u.cli.cl_import)
90                 sec = obd->u.cli.cl_import->imp_sec;
91
92         if (sec == NULL) {
93                 written = snprintf(page, count, "\n");
94                 goto out;
95         }
96
97         sec_flags2str(sec->ps_flags, flags_str, sizeof(flags_str));
98
99         written = snprintf(page, count,
100                         "rpc msg flavor:        %s\n"
101                         "bulk checksum:         %s\n"
102                         "bulk encrypt:          %s\n"
103                         "flags:                 %s\n"
104                         "ctx cache size         %u\n"
105                         "ctx cache busy         %d\n"
106                         "gc interval            %lu\n"
107                         "gc next                %ld\n",
108                         sptlrpc_flavor2name(sec->ps_flavor),
109                         sptlrpc_bulk_csum_alg2name(conf->sfc_bulk_csum),
110                         sptlrpc_bulk_priv_alg2name(conf->sfc_bulk_priv),
111                         flags_str,
112                         sec->ps_ccache_size,
113                         atomic_read(&sec->ps_busy),
114                         sec->ps_gc_interval,
115                         sec->ps_gc_interval ?
116                                 sec->ps_gc_next - cfs_time_current_sec() : 0
117                           );
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_ctx_display(ctx, page + written,
134                                                        count - written);
135                 }
136         }
137         spin_unlock(&sec->ps_lock);
138
139 out:
140         return written;
141 }
142 EXPORT_SYMBOL(sptlrpc_lprocfs_rd);
143
144 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
145         { "enc_pool", sptlrpc_proc_read_enc_pool, NULL, NULL },
146         { NULL }
147 };
148
149 int sptlrpc_lproc_init(void)
150 {
151         int     rc;
152
153         LASSERT(sptlrpc_proc_root == NULL);
154
155         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
156                                              sptlrpc_lprocfs_vars, NULL);
157         if (IS_ERR(sptlrpc_proc_root)) {
158                 rc = PTR_ERR(sptlrpc_proc_root);
159                 sptlrpc_proc_root = NULL;
160                 return rc;
161         }
162         return 0;
163 }
164
165 void sptlrpc_lproc_fini(void)
166 {
167         if (sptlrpc_proc_root) {
168                 lprocfs_remove(sptlrpc_proc_root);
169                 sptlrpc_proc_root = NULL;
170         }
171 }
172
173 #else /* !__KERNEL__ */
174
175 int sptlrpc_lproc_init(void)
176 {
177         return 0;
178 }
179
180 void sptlrpc_lproc_fini(void)
181 {
182 }
183
184 #endif