Whamcloud - gitweb
LU-1346 libcfs: replace libcfs wrappers with kernel API
[fs/lustre-release.git] / lustre / ptlrpc / gss / lproc_gss.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  */
34
35 #define DEBUG_SUBSYSTEM S_SEC
36 #ifdef __KERNEL__
37 #include <linux/init.h>
38 #include <linux/module.h>
39 #include <linux/slab.h>
40 #include <linux/dcache.h>
41 #include <linux/fs.h>
42 #include <linux/mutex.h>
43 #else
44 #include <liblustre.h>
45 #endif
46
47 #include <obd.h>
48 #include <obd_class.h>
49 #include <obd_support.h>
50 #include <lustre/lustre_idl.h>
51 #include <lustre_net.h>
52 #include <lustre_import.h>
53 #include <lprocfs_status.h>
54 #include <lustre_sec.h>
55
56 #include "gss_err.h"
57 #include "gss_internal.h"
58 #include "gss_api.h"
59
60 static struct proc_dir_entry *gss_proc_root = NULL;
61 static struct proc_dir_entry *gss_proc_lk = NULL;
62
63 /*
64  * statistic of "out-of-sequence-window"
65  */
66 static struct {
67         spinlock_t  oos_lock;
68         cfs_atomic_t    oos_cli_count;       /* client occurrence */
69         int             oos_cli_behind;      /* client max seqs behind */
70         cfs_atomic_t    oos_svc_replay[3];   /* server replay detected */
71         cfs_atomic_t    oos_svc_pass[3];     /* server verified ok */
72 } gss_stat_oos = {
73         .oos_cli_count  = CFS_ATOMIC_INIT(0),
74         .oos_cli_behind = 0,
75         .oos_svc_replay = { CFS_ATOMIC_INIT(0), },
76         .oos_svc_pass   = { CFS_ATOMIC_INIT(0), },
77 };
78
79 void gss_stat_oos_record_cli(int behind)
80 {
81         cfs_atomic_inc(&gss_stat_oos.oos_cli_count);
82
83         spin_lock(&gss_stat_oos.oos_lock);
84         if (behind > gss_stat_oos.oos_cli_behind)
85                 gss_stat_oos.oos_cli_behind = behind;
86         spin_unlock(&gss_stat_oos.oos_lock);
87 }
88
89 void gss_stat_oos_record_svc(int phase, int replay)
90 {
91         LASSERT(phase >= 0 && phase <= 2);
92
93         if (replay)
94                 cfs_atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
95         else
96                 cfs_atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
97 }
98
99 static int gss_proc_read_oos(char *page, char **start, off_t off, int count,
100                              int *eof, void *data)
101 {
102         int written;
103
104         written = snprintf(page, count,
105                         "seqwin:                %u\n"
106                         "backwin:               %u\n"
107                         "client fall behind seqwin\n"
108                         "  occurrence:          %d\n"
109                         "  max seq behind:      %d\n"
110                         "server replay detected:\n"
111                         "  phase 0:             %d\n"
112                         "  phase 1:             %d\n"
113                         "  phase 2:             %d\n"
114                         "server verify ok:\n"
115                         "  phase 2:             %d\n",
116                         GSS_SEQ_WIN_MAIN,
117                         GSS_SEQ_WIN_BACK,
118                         cfs_atomic_read(&gss_stat_oos.oos_cli_count),
119                         gss_stat_oos.oos_cli_behind,
120                         cfs_atomic_read(&gss_stat_oos.oos_svc_replay[0]),
121                         cfs_atomic_read(&gss_stat_oos.oos_svc_replay[1]),
122                         cfs_atomic_read(&gss_stat_oos.oos_svc_replay[2]),
123                         cfs_atomic_read(&gss_stat_oos.oos_svc_pass[2]));
124
125         return written;
126 }
127
128 static int gss_proc_write_secinit(struct file *file, const char *buffer,
129                                   unsigned long count, void *data)
130 {
131         int rc;
132
133         rc = gss_do_ctx_init_rpc((char *) buffer, count);
134         if (rc) {
135                 LASSERT(rc < 0);
136                 return rc;
137         }
138
139         return ((int) count);
140 }
141
142 static struct lprocfs_vars gss_lprocfs_vars[] = {
143         { "replays", gss_proc_read_oos, NULL },
144         { "init_channel", NULL, gss_proc_write_secinit, NULL, NULL, 0222 },
145         { NULL }
146 };
147
148 /*
149  * for userspace helper lgss_keyring.
150  *
151  * debug_level: [0, 4], defined in utils/gss/lgss_utils.h
152  */
153 static int gss_lk_debug_level = 1;
154
155 static int gss_lk_proc_read_dl(char *page, char **start, off_t off,
156                                int count, int *eof, void *data)
157 {
158         return snprintf(page, count, "%u\n", gss_lk_debug_level);
159 }
160
161 static int gss_lk_proc_write_dl(struct file *file, const char *buffer,
162                                 unsigned long count, void *data)
163 {
164         int     val, rc;
165
166         rc = lprocfs_write_helper(buffer, count, &val);
167         if (rc < 0)
168                 return rc;
169
170         if (val < 0 || val > 4)
171                 return -ERANGE;
172
173         gss_lk_debug_level = val;
174         return count;
175 }
176
177 static struct lprocfs_vars gss_lk_lprocfs_vars[] = {
178         { "debug_level", gss_lk_proc_read_dl, gss_lk_proc_write_dl, NULL },
179         { NULL }
180 };
181
182 void gss_exit_lproc(void)
183 {
184         if (gss_proc_lk) {
185                 lprocfs_remove(&gss_proc_lk);
186                 gss_proc_lk = NULL;
187         }
188
189         if (gss_proc_root) {
190                 lprocfs_remove(&gss_proc_root);
191                 gss_proc_root = NULL;
192         }
193 }
194
195 int gss_init_lproc(void)
196 {
197         int     rc;
198
199         spin_lock_init(&gss_stat_oos.oos_lock);
200
201         gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
202                                          gss_lprocfs_vars, NULL);
203         if (IS_ERR(gss_proc_root)) {
204                 gss_proc_root = NULL;
205                 GOTO(err_out, rc = PTR_ERR(gss_proc_root));
206         }
207
208         gss_proc_lk = lprocfs_register("lgss_keyring", gss_proc_root,
209                                        gss_lk_lprocfs_vars, NULL);
210         if (IS_ERR(gss_proc_lk)) {
211                 gss_proc_lk = NULL;
212                 GOTO(err_out, rc = PTR_ERR(gss_proc_root));
213         }
214
215         return 0;
216
217 err_out:
218         CERROR("failed to initialize gss lproc entries: %d\n", rc);
219         gss_exit_lproc();
220         return rc;
221 }