Whamcloud - gitweb
- make HEAD from b_post_cmd3
[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  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *   Author Peter Braam <braam@clusterfs.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   You may have signed or agreed to another license before downloading
11  *   this software.  If so, you are bound by the terms and conditions
12  *   of that agreement, and the following does not apply to you.  See the
13  *   LICENSE file included with this distribution for more information.
14  *
15  *   If you did not agree to a different license, then this copy of Lustre
16  *   is open source software; you can redistribute it and/or modify it
17  *   under the terms of version 2 of the GNU General Public License as
18  *   published by the Free Software Foundation.
19  *
20  *   In either case, Lustre is distributed in the hope that it will be
21  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   license text for more details.
24  *
25  */
26
27 #ifndef EXPORT_SYMTAB
28 # define EXPORT_SYMTAB
29 #endif
30 #define DEBUG_SUBSYSTEM S_SEC
31 #ifdef __KERNEL__
32 #include <linux/init.h>
33 #include <linux/module.h>
34 #include <linux/slab.h>
35 #include <linux/dcache.h>
36 #include <linux/fs.h>
37 #include <linux/random.h>
38 #else
39 #include <liblustre.h>
40 #endif
41
42 #include <obd.h>
43 #include <obd_class.h>
44 #include <obd_support.h>
45 #include <lustre/lustre_idl.h>
46 #include <lustre_net.h>
47 #include <lustre_import.h>
48 #include <lprocfs_status.h>
49 #include <lustre_sec.h>
50
51 #include "gss_err.h"
52 #include "gss_internal.h"
53 #include "gss_api.h"
54
55 static struct proc_dir_entry *gss_proc_root = NULL;
56
57 /*
58  * statistic of "out-of-sequence-window"
59  */
60 static struct {
61         spinlock_t      oos_lock;
62         atomic_t        oos_cli_count;       /* client occurrence */
63         int             oos_cli_behind;      /* client max seqs behind */
64         atomic_t        oos_svc_replay[3];   /* server replay detected */
65         atomic_t        oos_svc_pass[3];     /* server verified ok */
66 } gss_stat_oos = {
67         .oos_lock       = SPIN_LOCK_UNLOCKED,
68         .oos_cli_count  = ATOMIC_INIT(0),
69         .oos_cli_behind = 0,
70         .oos_svc_replay = { ATOMIC_INIT(0), },
71         .oos_svc_pass   = { ATOMIC_INIT(0), },
72 };
73
74 void gss_stat_oos_record_cli(int behind)
75 {
76         atomic_inc(&gss_stat_oos.oos_cli_count);
77
78         spin_lock(&gss_stat_oos.oos_lock);
79         if (behind > gss_stat_oos.oos_cli_behind)
80                 gss_stat_oos.oos_cli_behind = behind;
81         spin_unlock(&gss_stat_oos.oos_lock);
82 }
83
84 void gss_stat_oos_record_svc(int phase, int replay)
85 {
86         LASSERT(phase >= 0 && phase <= 2);
87
88         if (replay)
89                 atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
90         else
91                 atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
92 }
93
94 static int gss_proc_read_oos(char *page, char **start, off_t off, int count,
95                              int *eof, void *data)
96 {
97         int written;
98
99         written = snprintf(page, count,
100                         "seqwin:                %u\n"
101                         "backwin:               %u\n"
102                         "client fall behind seqwin\n"
103                         "  occurrence:          %d\n"
104                         "  max seq behind:      %d\n"
105                         "server replay detected:\n"
106                         "  phase 0:             %d\n"
107                         "  phase 1:             %d\n"
108                         "  phase 2:             %d\n"
109                         "server verify ok:\n"
110                         "  phase 2:             %d\n",
111                         GSS_SEQ_WIN_MAIN,
112                         GSS_SEQ_WIN_BACK,
113                         atomic_read(&gss_stat_oos.oos_cli_count),
114                         gss_stat_oos.oos_cli_behind,
115                         atomic_read(&gss_stat_oos.oos_svc_replay[0]),
116                         atomic_read(&gss_stat_oos.oos_svc_replay[1]),
117                         atomic_read(&gss_stat_oos.oos_svc_replay[2]),
118                         atomic_read(&gss_stat_oos.oos_svc_pass[2]));
119
120         return written;
121 }
122
123 static int gss_proc_write_secinit(struct file *file, const char *buffer,
124                                   unsigned long count, void *data)
125 {
126         int rc;
127
128         rc = gss_do_ctx_init_rpc((char *) buffer, count);
129         if (rc) {
130                 LASSERT(rc < 0);
131                 return rc;
132         }
133
134         return ((int) count);
135 }
136
137 static struct lprocfs_vars gss_lprocfs_vars[] = {
138         { "replays", gss_proc_read_oos, NULL },
139         { "init_channel", NULL, gss_proc_write_secinit, NULL },
140         { NULL }
141 };
142
143 int gss_init_lproc(void)
144 {
145         int rc;
146         gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
147                                          gss_lprocfs_vars, NULL);
148
149         if (IS_ERR(gss_proc_root)) {
150                 rc = PTR_ERR(gss_proc_root);
151                 gss_proc_root = NULL;
152                 CERROR("failed to initialize lproc entries: %d\n", rc);
153                 return rc;
154         }
155
156         return 0;
157 }
158
159 void gss_exit_lproc(void)
160 {
161         if (gss_proc_root) {
162                 lprocfs_remove(&gss_proc_root);
163                 gss_proc_root = NULL;
164         }
165 }