Whamcloud - gitweb
LU-3319 procfs: move ptlrpc proc handling over to seq_file
[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  * Copyright (c) 2012, Intel Corporation.
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 #define DEBUG_SUBSYSTEM S_SEC
38 #ifdef __KERNEL__
39 #include <linux/init.h>
40 #include <linux/module.h>
41 #include <linux/slab.h>
42 #include <linux/dcache.h>
43 #include <linux/fs.h>
44 #include <linux/mutex.h>
45 #else
46 #include <liblustre.h>
47 #endif
48
49 #include <obd.h>
50 #include <obd_class.h>
51 #include <obd_support.h>
52 #include <lustre/lustre_idl.h>
53 #include <lustre_net.h>
54 #include <lustre_import.h>
55 #include <lprocfs_status.h>
56 #include <lustre_sec.h>
57
58 #include "gss_err.h"
59 #include "gss_internal.h"
60 #include "gss_api.h"
61
62 static struct proc_dir_entry *gss_proc_root = NULL;
63 static struct proc_dir_entry *gss_proc_lk = NULL;
64
65 /*
66  * statistic of "out-of-sequence-window"
67  */
68 static struct {
69         spinlock_t  oos_lock;
70         cfs_atomic_t    oos_cli_count;       /* client occurrence */
71         int             oos_cli_behind;      /* client max seqs behind */
72         cfs_atomic_t    oos_svc_replay[3];   /* server replay detected */
73         cfs_atomic_t    oos_svc_pass[3];     /* server verified ok */
74 } gss_stat_oos = {
75         .oos_cli_count  = CFS_ATOMIC_INIT(0),
76         .oos_cli_behind = 0,
77         .oos_svc_replay = { CFS_ATOMIC_INIT(0), },
78         .oos_svc_pass   = { CFS_ATOMIC_INIT(0), },
79 };
80
81 void gss_stat_oos_record_cli(int behind)
82 {
83         cfs_atomic_inc(&gss_stat_oos.oos_cli_count);
84
85         spin_lock(&gss_stat_oos.oos_lock);
86         if (behind > gss_stat_oos.oos_cli_behind)
87                 gss_stat_oos.oos_cli_behind = behind;
88         spin_unlock(&gss_stat_oos.oos_lock);
89 }
90
91 void gss_stat_oos_record_svc(int phase, int replay)
92 {
93         LASSERT(phase >= 0 && phase <= 2);
94
95         if (replay)
96                 cfs_atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
97         else
98                 cfs_atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
99 }
100
101 static int gss_proc_oos_seq_show(struct seq_file *m, void *v)
102 {
103         return seq_printf(m,
104                         "seqwin:                %u\n"
105                         "backwin:               %u\n"
106                         "client fall behind seqwin\n"
107                         "  occurrence:          %d\n"
108                         "  max seq behind:      %d\n"
109                         "server replay detected:\n"
110                         "  phase 0:             %d\n"
111                         "  phase 1:             %d\n"
112                         "  phase 2:             %d\n"
113                         "server verify ok:\n"
114                         "  phase 2:             %d\n",
115                         GSS_SEQ_WIN_MAIN,
116                         GSS_SEQ_WIN_BACK,
117                         cfs_atomic_read(&gss_stat_oos.oos_cli_count),
118                         gss_stat_oos.oos_cli_behind,
119                         cfs_atomic_read(&gss_stat_oos.oos_svc_replay[0]),
120                         cfs_atomic_read(&gss_stat_oos.oos_svc_replay[1]),
121                         cfs_atomic_read(&gss_stat_oos.oos_svc_replay[2]),
122                         cfs_atomic_read(&gss_stat_oos.oos_svc_pass[2]));
123 }
124 LPROC_SEQ_FOPS_RO(gss_proc_oos);
125
126 static ssize_t
127 gss_proc_write_secinit(struct file *file, const char *buffer,
128                                   size_t count, loff_t *off)
129 {
130         int rc;
131
132         rc = gss_do_ctx_init_rpc((char *) buffer, count);
133         if (rc) {
134                 LASSERT(rc < 0);
135                 return rc;
136         }
137         return count;
138 }
139
140 static const struct file_operations gss_proc_secinit = {
141         .write = gss_proc_write_secinit,
142 };
143
144 static struct lprocfs_seq_vars gss_lprocfs_vars[] = {
145         { .name =       "replays",
146           .fops =       &gss_proc_oos_fops      },
147         { .name =       "init_channel",
148           .fops =       &gss_proc_secinit,
149           .proc_mode =  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_dl_seq_show(struct seq_file *m, void *v)
161 {
162         return seq_printf(m, "%u\n", gss_lk_debug_level);
163 }
164
165 static ssize_t
166 gss_lk_proc_dl_seq_write(struct file *file, const char *buffer,
167                                 size_t count, loff_t *off)
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 LPROC_SEQ_FOPS(gss_lk_proc_dl);
182
183 static struct lprocfs_seq_vars gss_lk_lprocfs_vars[] = {
184         { .name =       "debug_level",
185           .fops =       &gss_lk_proc_dl_fops    },
186         { NULL }
187 };
188
189 void gss_exit_lproc(void)
190 {
191         if (gss_proc_lk) {
192                 lprocfs_remove(&gss_proc_lk);
193                 gss_proc_lk = NULL;
194         }
195
196         if (gss_proc_root) {
197                 lprocfs_remove(&gss_proc_root);
198                 gss_proc_root = NULL;
199         }
200 }
201
202 int gss_init_lproc(void)
203 {
204         int     rc;
205
206         spin_lock_init(&gss_stat_oos.oos_lock);
207
208         gss_proc_root = lprocfs_seq_register("gss", sptlrpc_proc_root,
209                                                 gss_lprocfs_vars, NULL);
210         if (IS_ERR(gss_proc_root)) {
211                 rc = PTR_ERR(gss_proc_root);
212                 gss_proc_root = NULL;
213                 GOTO(out, rc);
214         }
215
216         gss_proc_lk = lprocfs_seq_register("lgss_keyring", gss_proc_root,
217                                                 gss_lk_lprocfs_vars, NULL);
218         if (IS_ERR(gss_proc_lk)) {
219                 rc = PTR_ERR(gss_proc_lk);
220                 gss_proc_lk = NULL;
221                 GOTO(out, rc);
222         }
223
224         return 0;
225
226 out:
227         CERROR("failed to initialize gss lproc entries: %d\n", rc);
228         gss_exit_lproc();
229
230         return rc;
231 }