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