staging: delete non-required instances of include <linux/init.h>
[deliverable/linux.git] / drivers / staging / lustre / lustre / ptlrpc / gss / lproc_gss.c
CommitLineData
d7e09d03
PT
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
d7e09d03
PT
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
44#include <obd.h>
45#include <obd_class.h>
46#include <obd_support.h>
47#include <lustre/lustre_idl.h>
48#include <lustre_net.h>
49#include <lustre_import.h>
50#include <lprocfs_status.h>
51#include <lustre_sec.h>
52
53#include "gss_err.h"
54#include "gss_internal.h"
55#include "gss_api.h"
56
57static struct proc_dir_entry *gss_proc_root = NULL;
58static struct proc_dir_entry *gss_proc_lk = NULL;
59
60/*
61 * statistic of "out-of-sequence-window"
62 */
63static struct {
64 spinlock_t oos_lock;
65 atomic_t oos_cli_count; /* client occurrence */
66 int oos_cli_behind; /* client max seqs behind */
67 atomic_t oos_svc_replay[3]; /* server replay detected */
68 atomic_t oos_svc_pass[3]; /* server verified ok */
69} gss_stat_oos = {
70 .oos_cli_count = ATOMIC_INIT(0),
71 .oos_cli_behind = 0,
72 .oos_svc_replay = { ATOMIC_INIT(0), },
73 .oos_svc_pass = { ATOMIC_INIT(0), },
74};
75
76void gss_stat_oos_record_cli(int behind)
77{
78 atomic_inc(&gss_stat_oos.oos_cli_count);
79
80 spin_lock(&gss_stat_oos.oos_lock);
81 if (behind > gss_stat_oos.oos_cli_behind)
82 gss_stat_oos.oos_cli_behind = behind;
83 spin_unlock(&gss_stat_oos.oos_lock);
84}
85
86void gss_stat_oos_record_svc(int phase, int replay)
87{
88 LASSERT(phase >= 0 && phase <= 2);
89
90 if (replay)
91 atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
92 else
93 atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
94}
95
73bb1da6 96static int gss_proc_oos_seq_show(struct seq_file *m, void *v)
d7e09d03 97{
73bb1da6 98 return seq_printf(m,
d7e09d03
PT
99 "seqwin: %u\n"
100 "backwin: %u\n"
101 "client fall behind seqwin\n"
102 " occurrence: %d\n"
103 " max seq behind: %d\n"
104 "server replay detected:\n"
105 " phase 0: %d\n"
106 " phase 1: %d\n"
107 " phase 2: %d\n"
108 "server verify ok:\n"
109 " phase 2: %d\n",
110 GSS_SEQ_WIN_MAIN,
111 GSS_SEQ_WIN_BACK,
112 atomic_read(&gss_stat_oos.oos_cli_count),
113 gss_stat_oos.oos_cli_behind,
114 atomic_read(&gss_stat_oos.oos_svc_replay[0]),
115 atomic_read(&gss_stat_oos.oos_svc_replay[1]),
116 atomic_read(&gss_stat_oos.oos_svc_replay[2]),
117 atomic_read(&gss_stat_oos.oos_svc_pass[2]));
d7e09d03 118}
73bb1da6 119LPROC_SEQ_FOPS_RO(gss_proc_oos);
d7e09d03
PT
120
121static int gss_proc_write_secinit(struct file *file, const char *buffer,
73bb1da6 122 size_t count, off_t *off)
d7e09d03
PT
123{
124 int rc;
125
126 rc = gss_do_ctx_init_rpc((char *) buffer, count);
127 if (rc) {
128 LASSERT(rc < 0);
129 return rc;
130 }
131
73bb1da6 132 return count;
d7e09d03
PT
133}
134
73bb1da6
PT
135static const struct file_operations gss_proc_secinit = {
136 .write = gss_proc_write_secinit,
137};
138
d7e09d03 139static struct lprocfs_vars gss_lprocfs_vars[] = {
73bb1da6
PT
140 { "replays", &gss_proc_oos_fops },
141 { "init_channel", &gss_proc_secinit, NULL, 0222 },
d7e09d03
PT
142 { NULL }
143};
144
145/*
146 * for userspace helper lgss_keyring.
147 *
148 * debug_level: [0, 4], defined in utils/gss/lgss_utils.h
149 */
150static int gss_lk_debug_level = 1;
151
73bb1da6 152static int gss_lk_proc_dl_seq_show(struct seq_file *m, void *v)
d7e09d03 153{
73bb1da6 154 return seq_printf(m, "%u\n", gss_lk_debug_level);
d7e09d03
PT
155}
156
73bb1da6
PT
157static int gss_lk_proc_dl_seq_write(struct file *file, const char *buffer,
158 size_t count, off_t *off)
d7e09d03
PT
159{
160 int val, rc;
161
162 rc = lprocfs_write_helper(buffer, count, &val);
163 if (rc < 0)
164 return rc;
165
166 if (val < 0 || val > 4)
167 return -ERANGE;
168
169 gss_lk_debug_level = val;
170 return count;
171}
73bb1da6 172LPROC_SEQ_FOPS(gss_lk_proc_dl);
d7e09d03
PT
173
174static struct lprocfs_vars gss_lk_lprocfs_vars[] = {
73bb1da6 175 { "debug_level", &gss_lk_proc_dl_fops },
d7e09d03
PT
176 { NULL }
177};
178
179void gss_exit_lproc(void)
180{
181 if (gss_proc_lk) {
182 lprocfs_remove(&gss_proc_lk);
183 gss_proc_lk = NULL;
184 }
185
186 if (gss_proc_root) {
187 lprocfs_remove(&gss_proc_root);
188 gss_proc_root = NULL;
189 }
190}
191
192int gss_init_lproc(void)
193{
194 int rc;
195
196 spin_lock_init(&gss_stat_oos.oos_lock);
197
198 gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
199 gss_lprocfs_vars, NULL);
200 if (IS_ERR(gss_proc_root)) {
5907838a 201 rc = PTR_ERR(gss_proc_root);
d7e09d03 202 gss_proc_root = NULL;
5907838a 203 GOTO(err_out, rc);
d7e09d03
PT
204 }
205
206 gss_proc_lk = lprocfs_register("lgss_keyring", gss_proc_root,
207 gss_lk_lprocfs_vars, NULL);
208 if (IS_ERR(gss_proc_lk)) {
5907838a 209 rc = PTR_ERR(gss_proc_lk);
d7e09d03 210 gss_proc_lk = NULL;
5907838a 211 GOTO(err_out, rc);
d7e09d03
PT
212 }
213
214 return 0;
215
216err_out:
217 CERROR("failed to initialize gss lproc entries: %d\n", rc);
218 gss_exit_lproc();
219 return rc;
220}
This page took 0.10176 seconds and 5 git commands to generate.