Whamcloud - gitweb
5feaccfef6a3f0c110f72ff32960b6df312cc53b
[fs/lustre-release.git] / lustre / obdclass / sysctl.c
1 #include <linux/autoconf.h>
2 #include <linux/sysctl.h>
3 #include <linux/sched.h>
4 #include <linux/mm.h>
5 #include <linux/sysctl.h>
6 #include <linux/swapctl.h>
7 #include <linux/proc_fs.h>
8 #include <linux/malloc.h>
9 #include <linux/stat.h>
10 #include <linux/ctype.h>
11 #include <asm/bitops.h>
12 #include <asm/segment.h>
13 #include <asm/uaccess.h>
14 #include <linux/utsname.h>
15
16 #include <linux/obd_support.h>
17
18 struct ctl_table_header *obd_table_header = NULL;
19
20 static int vars[2];
21 static int index = 0;
22
23 static int obd_sctl_vars( ctl_table * table, int write, struct file *
24                           filp, void * buffer, size_t * lenp );
25 static int obd_sctl_reset( ctl_table * table, int write, struct file
26                            * filp, void * buffer, size_t * lenp );
27
28
29
30 #define OBD_SYSCTL 300
31
32 #define OBD_DEBUG           1       /* control debugging */
33 #define OBD_ENTRY           2       /* control enter/leave pattern */
34 #define OBD_TIMEOUT         3       /* timeout on upcalls to become intrble */
35 #define OBD_HARD            4       /* mount type "hard" or "soft" */
36 #define OBD_VARS            5       
37 #define OBD_INDEX           6
38 #define OBD_RESET           7
39
40 #define OBD_VARS_SLOT       2
41
42 static ctl_table obd_table[] = {
43         {OBD_DEBUG, "debug", &obd_debug_level, sizeof(int), 0644, NULL, &proc_dointvec},
44         {OBD_ENTRY, "trace", &obd_print_entry, sizeof(int), 0644, NULL, &proc_dointvec},
45         {OBD_VARS, "vars", &vars[0], sizeof(int), 0644, NULL, &proc_dointvec},
46         {OBD_INDEX, "index", &index, sizeof(int), 0644, NULL, &obd_sctl_vars},
47         {OBD_RESET, "reset", NULL, 0, 0644, NULL, &obd_sctl_reset},
48         { 0 }
49 };
50
51 static ctl_table parent_table[] = {
52        {OBD_SYSCTL, "obd",    NULL, 0, 0555, obd_table},
53        {0}
54 };
55
56 void obd_sysctl_init (void)
57 {
58 #ifdef CONFIG_SYSCTL
59         if ( !obd_table_header )
60                 obd_table_header = register_sysctl_table(parent_table, 0); 
61 #endif
62 }
63
64 void obd_sysctl_clean (void)
65 {
66 #ifdef CONFIG_SYSCTL
67         if ( obd_table_header )
68                 unregister_sysctl_table(obd_table_header);
69         obd_table_header = NULL;
70 #endif
71 }
72
73 int obd_sctl_reset (ctl_table * table, int write, 
74                     struct file * filp, void * buffer, 
75                     size_t * lenp)
76 {
77         if ( write ) {
78                 /* do something here */
79                 vars[0]=0;
80                 vars[1]=0;
81         }
82
83         *lenp = 0;
84         return 0;
85 }
86
87 int obd_sctl_vars (ctl_table * table, int write, 
88                    struct file * filp, void * buffer, 
89                    size_t * lenp)
90 {
91         int rc;
92
93         rc = proc_dointvec(table, write, filp, buffer, lenp);
94
95         if ( rc ) 
96                 return rc;
97
98         if ( index < 0 || index > 1 ) {
99                 printk(KERN_WARNING __FUNCTION__ "Illegal index %d!\n", index);
100                 index = 0;
101         } else {
102                 obd_table[OBD_VARS_SLOT].data = &vars[index];
103         }
104
105         return rc; 
106 }