Whamcloud - gitweb
land b1_5 onto HEAD
[fs/lustre-release.git] / lustre / obdclass / darwin / darwin-sysctl.c
1 #include <sys/param.h>
2 #include <sys/kernel.h>
3 #include <sys/malloc.h>
4 #include <sys/systm.h>
5 #include <sys/sysctl.h>
6 #include <sys/proc.h>
7 #include <sys/unistd.h>
8 #include <mach/mach_types.h>
9 #include <linux/lustre_build_version.h>
10
11 #define DEBUG_SUBSYSTEM S_CLASS
12                                                                                                                                                                      
13 #include <libcfs/libcfs.h>
14 #ifndef BUILD_VERSION   
15 #define BUILD_VERSION           "Unknown"
16 #endif
17 #ifndef LUSTRE_KERNEL_VERSION
18 #define LUSTRE_KERNEL_VERSION   "Unknown Darwin version"
19 #endif
20
21 cfs_sysctl_table_header_t *obd_table_header = NULL;
22
23 int proc_fail_loc SYSCTL_HANDLER_ARGS;
24 int proc_obd_timeout SYSCTL_HANDLER_ARGS;
25 extern unsigned int obd_fail_loc;
26 extern unsigned int obd_dump_on_timeout;
27 extern unsigned int obd_timeout;
28 extern unsigned int ldlm_timeout;
29 extern unsigned int obd_sync_filter;
30 extern atomic_t obd_memory;
31
32 int read_build_version SYSCTL_HANDLER_ARGS;
33 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS;
34
35 SYSCTL_NODE (,                  OID_AUTO,       lustre,     CTLFLAG_RW,
36              0,                 "lustre sysctl top");
37 SYSCTL_PROC(_lustre,            OID_AUTO,       fail_loc, 
38             CTLTYPE_INT | CTLFLAG_RW ,          &obd_fail_loc,
39             0,          &proc_fail_loc,         "I",    "obd_fail_loc");
40 SYSCTL_PROC(_lustre,            OID_AUTO,       timeout, 
41             CTLTYPE_INT | CTLFLAG_RW ,          &obd_timeout,
42             0,          &proc_obd_timeout,      "I",    "obd_timeout");
43 SYSCTL_PROC(_lustre,            OID_AUTO,       build_version, 
44             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
45             0,          &read_build_version,    "A",    "lustre_build_version");
46 SYSCTL_PROC(_lustre,            OID_AUTO,       lustre_kernel_version,
47             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
48             0,          &read_lustre_kernel_version,    "A",    "lustre_build_version");
49 SYSCTL_INT(_lustre,             OID_AUTO,       dump_on_timeout, 
50            CTLTYPE_INT | CTLFLAG_RW,            &obd_dump_on_timeout,
51            0,           "lustre_dump_on_timeout");
52 SYSCTL_INT(_lustre,             OID_AUTO,       memused, 
53            CTLTYPE_INT | CTLFLAG_RW,            (int *)&obd_memory.counter,
54            0,           "lustre_memory_used");
55 SYSCTL_INT(_lustre,             OID_AUTO,       ldlm_timeout, 
56            CTLTYPE_INT | CTLFLAG_RW,            &ldlm_timeout,
57            0,           "ldlm_timeout");
58
59 static cfs_sysctl_table_t      parent_table[] = {
60         &sysctl__lustre,
61         &sysctl__lustre_fail_loc,
62         &sysctl__lustre_timeout,
63         &sysctl__lustre_dump_on_timeout,
64         &sysctl__lustre_upcall,
65         &sysctl__lustre_memused,
66         &sysctl__lustre_filter_sync_on_commit,
67         &sysctl__lustre_ldlm_timeout,
68 };
69
70 extern cfs_waitq_t obd_race_waitq;
71
72 int proc_fail_loc SYSCTL_HANDLER_ARGS
73
74         int error = 0; 
75         int old_fail_loc = obd_fail_loc;
76         
77         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
78         if (!error && req->newptr != USER_ADDR_NULL) {
79                 if (old_fail_loc != obd_fail_loc) 
80                         cfs_waitq_signal(&obd_race_waitq);
81         } else  if (req->newptr != USER_ADDR_NULL) { 
82                 /* Something was wrong with the write request */ 
83                 printf ("sysctl fail loc fault: %d.\n", error);
84         } else { 
85                 /* Read request */ 
86                 error = SYSCTL_OUT(req, &obd_fail_loc, sizeof obd_fail_loc);
87         }
88         return error;
89 }
90
91 int proc_obd_timeout SYSCTL_HANDLER_ARGS
92
93         int error = 0;
94
95         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
96         if (!error && req->newptr != USER_ADDR_NULL) {
97                 if (ldlm_timeout >= obd_timeout)
98                         ldlm_timeout = max(obd_timeout / 3, 1U);
99         } else  if (req->newptr != USER_ADDR_NULL) { 
100                 printf ("sysctl fail obd_timeout: %d.\n", error);
101         } else {
102                 /* Read request */ 
103                 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
104         }
105         return error;
106 }
107
108 int read_build_version SYSCTL_HANDLER_ARGS
109 {
110         int error = 0;
111
112         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
113         if ( req->newptr != USER_ADDR_NULL) {
114                 printf("sysctl read_build_version is read-only!\n");
115         } else {
116                 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
117         }
118         return error;
119 }
120
121 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
122 {
123         int error = 0;
124
125         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
126         if ( req->newptr != NULL) {
127                 printf("sysctl lustre_kernel_version is read-only!\n");
128         } else {
129                 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
130         }
131         return error;
132 }
133
134 void obd_sysctl_init (void)
135 {
136 #if 1 
137         if ( !obd_table_header ) 
138                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
139 #endif
140 }
141                                                                                                                                                                      
142 void obd_sysctl_clean (void)
143 {
144 #if 1 
145         if ( obd_table_header ) 
146                 cfs_unregister_sysctl_table(obd_table_header); 
147         obd_table_header = NULL;
148 #endif
149 }
150