Whamcloud - gitweb
This should fix the LOV problem. All is well.
[fs/lustre-release.git] / lustre / obdclass / sysctl.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  */
22
23 #include <linux/module.h>
24 #include <linux/autoconf.h>
25 #include <linux/sysctl.h>
26 #include <linux/sched.h>
27 #include <linux/mm.h>
28 #include <linux/sysctl.h>
29 #include <linux/swapctl.h>
30 #include <linux/proc_fs.h>
31 #include <linux/slab.h>
32 #include <linux/stat.h>
33 #include <linux/ctype.h>
34 #include <asm/bitops.h>
35 #include <asm/segment.h>
36 #include <asm/uaccess.h>
37 #include <linux/utsname.h>
38
39 #define DEBUG_SUBSYSTEM S_CLASS
40
41 #include <linux/obd_support.h>
42
43 struct ctl_table_header *obd_table_header = NULL;
44
45 static int vars[2];
46 static int index = 0;
47
48 static int obd_sctl_vars( ctl_table * table, int write, struct file *
49                           filp, void * buffer, size_t * lenp );
50 static int obd_sctl_reset( ctl_table * table, int write, struct file
51                            * filp, void * buffer, size_t * lenp );
52
53 #define OBD_SYSCTL 300
54
55 #define OBD_FAIL_LOC        1       /* control test failures instrumentation */
56 #define OBD_ENTRY           2       /* control enter/leave pattern */
57 #define OBD_VARS            3
58 #define OBD_INDEX           4
59 #define OBD_RESET           5
60 #define OBD_TIMEOUT         6       /* RPC timeout before recovery/intr */
61 /* XXX move to /proc/sys/lustre/recovery? */
62 #define OBD_UPCALL          7       /* path to recovery upcall */
63
64 #define OBD_VARS_SLOT       2
65
66 static ctl_table obd_table[] = {
67         {OBD_FAIL_LOC, "fail_loc", &obd_fail_loc, sizeof(int), 0644, NULL, &proc_dointvec},
68         {OBD_VARS, "vars", &vars[0], sizeof(int), 0644, NULL, &proc_dointvec},
69         {OBD_INDEX, "index", &index, sizeof(int), 0644, NULL, &obd_sctl_vars},
70         {OBD_RESET, "reset", NULL, 0, 0644, NULL, &obd_sctl_reset},
71         {OBD_TIMEOUT, "timeout", &obd_timeout, sizeof(int), 0644, NULL, &proc_dointvec},
72         /* XXX need to lock so we avoid update races with the recovery upcall! */
73         {OBD_UPCALL, "recovery_upcall", obd_recovery_upcall, 128, 0644, NULL,
74          &proc_dostring, &sysctl_string },
75         { 0 }
76 };
77
78 static ctl_table parent_table[] = {
79        {OBD_SYSCTL, "lustre", NULL, 0, 0555, obd_table},
80        {0}
81 };
82
83 void obd_sysctl_init (void)
84 {
85 #ifdef CONFIG_SYSCTL
86         if ( !obd_table_header )
87                 obd_table_header = register_sysctl_table(parent_table, 0); 
88 #endif
89 }
90
91 void obd_sysctl_clean (void)
92 {
93 #ifdef CONFIG_SYSCTL
94         if ( obd_table_header )
95                 unregister_sysctl_table(obd_table_header);
96         obd_table_header = NULL;
97 #endif
98 }
99
100 int obd_sctl_reset (ctl_table * table, int write, 
101                     struct file * filp, void * buffer, 
102                     size_t * lenp)
103 {
104         if ( write ) {
105                 /* do something here */
106                 vars[0]=0;
107                 vars[1]=0;
108         }
109
110         *lenp = 0;
111         return 0;
112 }
113
114 int obd_sctl_vars (ctl_table * table, int write, 
115                    struct file * filp, void * buffer, 
116                    size_t * lenp)
117 {
118         int rc;
119
120         rc = proc_dointvec(table, write, filp, buffer, lenp);
121
122         if ( rc ) 
123                 return rc;
124
125         if ( index < 0 || index > 1 ) {
126                 CERROR("Illegal index %d!\n", index);
127                 index = 0;
128         } else {
129                 obd_table[OBD_VARS_SLOT].data = &vars[index];
130         }
131
132         return rc; 
133 }