Whamcloud - gitweb
Branch 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 <lustre/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 long 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,       debug_peer_on_timeout, 
53            CTLTYPE_INT | CTLFLAG_RW,            &obd_debug_peer_on_timeout,
54            0,           "lustre_debug_peer_on_timeout");
55 SYSCTL_INT(_lustre,             OID_AUTO,       memused, 
56            CTLTYPE_INT | CTLFLAG_RW,            (int *)&obd_memory.counter,
57            0,           "lustre_memory_used");
58 SYSCTL_INT(_lustre,             OID_AUTO,       ldlm_timeout, 
59            CTLTYPE_INT | CTLFLAG_RW,            &ldlm_timeout,
60            0,           "ldlm_timeout");
61
62 static cfs_sysctl_table_t      parent_table[] = {
63         &sysctl__lustre,
64         &sysctl__lustre_fail_loc,
65         &sysctl__lustre_timeout,
66         &sysctl__lustre_dump_on_timeout,
67         &sysctl__lustre_debug_peer_on_timeout,
68         &sysctl__lustre_upcall,
69         &sysctl__lustre_memused,
70         &sysctl__lustre_filter_sync_on_commit,
71         &sysctl__lustre_ldlm_timeout,
72 };
73
74 extern cfs_waitq_t obd_race_waitq;
75
76 int proc_fail_loc SYSCTL_HANDLER_ARGS
77
78         int error = 0; 
79         long old_fail_loc = obd_fail_loc;
80         
81         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
82         if (!error && req->newptr != USER_ADDR_NULL) {
83                 if (old_fail_loc != obd_fail_loc) 
84                         cfs_waitq_signal(&obd_race_waitq);
85         } else  if (req->newptr != USER_ADDR_NULL) { 
86                 /* Something was wrong with the write request */ 
87                 printf ("sysctl fail loc fault: %d.\n", error);
88         } else { 
89                 /* Read request */ 
90                 error = SYSCTL_OUT(req, &obd_fail_loc, sizeof obd_fail_loc);
91         }
92         return error;
93 }
94
95 int proc_obd_timeout SYSCTL_HANDLER_ARGS
96
97         int error = 0;
98
99         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
100         if (!error && req->newptr != USER_ADDR_NULL) {
101                 if (ldlm_timeout >= obd_timeout)
102                         ldlm_timeout = max(obd_timeout / 3, 1U);
103         } else  if (req->newptr != USER_ADDR_NULL) { 
104                 printf ("sysctl fail obd_timeout: %d.\n", error);
105         } else {
106                 /* Read request */ 
107                 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
108         }
109         return error;
110 }
111
112 int read_build_version SYSCTL_HANDLER_ARGS
113 {
114         int error = 0;
115
116         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
117         if ( req->newptr != USER_ADDR_NULL) {
118                 printf("sysctl read_build_version is read-only!\n");
119         } else {
120                 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
121         }
122         return error;
123 }
124
125 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
126 {
127         int error = 0;
128
129         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
130         if ( req->newptr != NULL) {
131                 printf("sysctl lustre_kernel_version is read-only!\n");
132         } else {
133                 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
134         }
135         return error;
136 }
137
138 void obd_sysctl_init (void)
139 {
140 #if 1 
141         if ( !obd_table_header ) 
142                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
143 #endif
144 }
145                                                                                                                                                                      
146 void obd_sysctl_clean (void)
147 {
148 #if 1 
149         if ( obd_table_header ) 
150                 cfs_unregister_sysctl_table(obd_table_header); 
151         obd_table_header = NULL;
152 #endif
153 }
154