Whamcloud - gitweb
- merge 0.7rc1 from b_devel to HEAD (20030612 merge point)
[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/version.h>
30 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
31 #include <linux/swapctl.h>
32 #endif
33 #include <linux/proc_fs.h>
34 #include <linux/slab.h>
35 #include <linux/stat.h>
36 #include <linux/ctype.h>
37 #include <asm/bitops.h>
38 #include <asm/segment.h>
39 #include <asm/uaccess.h>
40 #include <linux/utsname.h>
41
42 #define DEBUG_SUBSYSTEM S_CLASS
43
44 #include <linux/obd_support.h>
45
46 struct ctl_table_header *obd_table_header = NULL;
47
48 static int vars[2];
49 static int index = 0;
50
51 static int obd_sctl_vars( ctl_table * table, int write, struct file *
52                           filp, void * buffer, size_t * lenp );
53 static int obd_sctl_reset( ctl_table * table, int write, struct file
54                            * filp, void * buffer, size_t * lenp );
55
56 #define OBD_SYSCTL 300
57
58 #define OBD_FAIL_LOC        1       /* control test failures instrumentation */
59 #define OBD_ENTRY           2       /* control enter/leave pattern */
60 #define OBD_VARS            3
61 #define OBD_INDEX           4
62 #define OBD_RESET           5
63 #define OBD_TIMEOUT         6       /* RPC timeout before recovery/intr */
64 /* XXX move to /proc/sys/lustre/recovery? */
65 #define OBD_UPCALL          7       /* path to recovery upcall */
66 /* XXX temporary, as we play with sync osts.. */
67 #define OBD_SYNCFILTER      8
68
69 #define OBD_VARS_SLOT       2
70
71 static ctl_table obd_table[] = {
72         {OBD_FAIL_LOC, "fail_loc", &obd_fail_loc, sizeof(int), 0644, NULL, &proc_dointvec},
73         {OBD_VARS, "vars", &vars[0], sizeof(int), 0644, NULL, &proc_dointvec},
74         {OBD_INDEX, "index", &index, sizeof(int), 0644, NULL, &obd_sctl_vars},
75         {OBD_RESET, "reset", NULL, 0, 0644, NULL, &obd_sctl_reset},
76         {OBD_TIMEOUT, "timeout", &obd_timeout, sizeof(int), 0644, NULL, &proc_dointvec},
77         /* XXX need to lock so we avoid update races with the recovery upcall! */
78         {OBD_UPCALL, "upcall", obd_lustre_upcall, 128, 0644, NULL,
79          &proc_dostring, &sysctl_string },
80         {OBD_SYNCFILTER, "filter_sync_on_commit", &obd_sync_filter, sizeof(int),
81                 0644, NULL, &proc_dointvec},
82         { 0 }
83 };
84
85 static ctl_table parent_table[] = {
86        {OBD_SYSCTL, "lustre", NULL, 0, 0555, obd_table},
87        {0}
88 };
89
90 void obd_sysctl_init (void)
91 {
92 #ifdef CONFIG_SYSCTL
93         if ( !obd_table_header )
94                 obd_table_header = register_sysctl_table(parent_table, 0); 
95 #endif
96 }
97
98 void obd_sysctl_clean (void)
99 {
100 #ifdef CONFIG_SYSCTL
101         if ( obd_table_header )
102                 unregister_sysctl_table(obd_table_header);
103         obd_table_header = NULL;
104 #endif
105 }
106
107 int obd_sctl_reset (ctl_table * table, int write, 
108                     struct file * filp, void * buffer, 
109                     size_t * lenp)
110 {
111         if ( write ) {
112                 /* do something here */
113                 vars[0]=0;
114                 vars[1]=0;
115         }
116
117         *lenp = 0;
118         return 0;
119 }
120
121 int obd_sctl_vars (ctl_table * table, int write, 
122                    struct file * filp, void * buffer, 
123                    size_t * lenp)
124 {
125         int rc;
126
127         rc = proc_dointvec(table, write, filp, buffer, lenp);
128
129         if ( rc ) 
130                 return rc;
131
132         if ( index < 0 || index > 1 ) {
133                 CERROR("Illegal index %d!\n", index);
134                 index = 0;
135         } else {
136                 obd_table[OBD_VARS_SLOT].data = &vars[index];
137         }
138
139         return rc; 
140 }