Whamcloud - gitweb
branch: HEAD
[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) 2006 Cluster File Systems, Inc.
5  *   Author Eric Mei <ericm@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 #include <linux/mutex.h>
39 #else
40 #include <liblustre.h>
41 #endif
42
43 #include <obd.h>
44 #include <obd_class.h>
45 #include <obd_support.h>
46 #include <lustre/lustre_idl.h>
47 #include <lustre_net.h>
48 #include <lustre_import.h>
49 #include <lprocfs_status.h>
50 #include <lustre_sec.h>
51
52 #include "gss_err.h"
53 #include "gss_internal.h"
54 #include "gss_api.h"
55
56 static struct proc_dir_entry *gss_proc_root = NULL;
57
58 /*
59  * statistic of "out-of-sequence-window"
60  */
61 static struct {
62         spinlock_t      oos_lock;
63         atomic_t        oos_cli_count;       /* client occurrence */
64         int             oos_cli_behind;      /* client max seqs behind */
65         atomic_t        oos_svc_replay[3];   /* server replay detected */
66         atomic_t        oos_svc_pass[3];     /* server verified ok */
67 } gss_stat_oos = {
68         .oos_lock       = SPIN_LOCK_UNLOCKED,
69         .oos_cli_count  = ATOMIC_INIT(0),
70         .oos_cli_behind = 0,
71         .oos_svc_replay = { ATOMIC_INIT(0), },
72         .oos_svc_pass   = { ATOMIC_INIT(0), },
73 };
74
75 void gss_stat_oos_record_cli(int behind)
76 {
77         atomic_inc(&gss_stat_oos.oos_cli_count);
78
79         spin_lock(&gss_stat_oos.oos_lock);
80         if (behind > gss_stat_oos.oos_cli_behind)
81                 gss_stat_oos.oos_cli_behind = behind;
82         spin_unlock(&gss_stat_oos.oos_lock);
83 }
84
85 void gss_stat_oos_record_svc(int phase, int replay)
86 {
87         LASSERT(phase >= 0 && phase <= 2);
88
89         if (replay)
90                 atomic_inc(&gss_stat_oos.oos_svc_replay[phase]);
91         else
92                 atomic_inc(&gss_stat_oos.oos_svc_pass[phase]);
93 }
94
95 static int gss_proc_read_oos(char *page, char **start, off_t off, int count,
96                              int *eof, void *data)
97 {
98         int written;
99
100         written = snprintf(page, count,
101                         "seqwin:                %u\n"
102                         "backwin:               %u\n"
103                         "client fall behind seqwin\n"
104                         "  occurrence:          %d\n"
105                         "  max seq behind:      %d\n"
106                         "server replay detected:\n"
107                         "  phase 0:             %d\n"
108                         "  phase 1:             %d\n"
109                         "  phase 2:             %d\n"
110                         "server verify ok:\n"
111                         "  phase 2:             %d\n",
112                         GSS_SEQ_WIN_MAIN,
113                         GSS_SEQ_WIN_BACK,
114                         atomic_read(&gss_stat_oos.oos_cli_count),
115                         gss_stat_oos.oos_cli_behind,
116                         atomic_read(&gss_stat_oos.oos_svc_replay[0]),
117                         atomic_read(&gss_stat_oos.oos_svc_replay[1]),
118                         atomic_read(&gss_stat_oos.oos_svc_replay[2]),
119                         atomic_read(&gss_stat_oos.oos_svc_pass[2]));
120
121         return written;
122 }
123
124 static int gss_proc_write_secinit(struct file *file, const char *buffer,
125                                   unsigned long count, void *data)
126 {
127         int rc;
128
129         rc = gss_do_ctx_init_rpc((char *) buffer, count);
130         if (rc) {
131                 LASSERT(rc < 0);
132                 return rc;
133         }
134
135         return ((int) count);
136 }
137
138 static struct lprocfs_vars gss_lprocfs_vars[] = {
139         { "replays", gss_proc_read_oos, NULL },
140         { "init_channel", NULL, gss_proc_write_secinit, NULL },
141         { NULL }
142 };
143
144 int gss_init_lproc(void)
145 {
146         struct proc_dir_entry  *ent;
147         int                     rc;
148
149         gss_proc_root = lprocfs_register("gss", sptlrpc_proc_root,
150                                          gss_lprocfs_vars, NULL);
151
152         if (IS_ERR(gss_proc_root)) {
153                 rc = PTR_ERR(gss_proc_root);
154                 gss_proc_root = NULL;
155                 CERROR("failed to initialize lproc entries: %d\n", rc);
156                 return rc;
157         }
158
159         /* FIXME
160          * here we should hold proc_subdir_lock which is not exported
161          */
162         ent = gss_proc_root->subdir;
163         while (ent != NULL) {
164                 if (strcmp(ent->name, "init_channel") == 0) {
165                         ent->mode |= 0222;
166                         break;
167                 }
168         }
169         
170         return 0;
171 }
172
173 void gss_exit_lproc(void)
174 {
175         if (gss_proc_root) {
176                 lprocfs_remove(&gss_proc_root);
177                 gss_proc_root = NULL;
178         }
179 }