2 #include <sys/kernel.h>
3 #include <sys/malloc.h>
5 #include <sys/sysctl.h>
7 #include <sys/unistd.h>
8 #include <mach/mach_types.h>
9 #include <linux/lustre_build_version.h>
11 #define DEBUG_SUBSYSTEM S_CLASS
13 #include <libcfs/libcfs.h>
15 #define BUILD_VERSION "Unknown"
17 #ifndef LUSTRE_KERNEL_VERSION
18 #define LUSTRE_KERNEL_VERSION "Unknown Darwin version"
21 cfs_sysctl_table_header_t *obd_table_header = NULL;
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;
32 int read_build_version SYSCTL_HANDLER_ARGS;
33 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS;
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,
62 static cfs_sysctl_table_t parent_table[] = {
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,
74 extern cfs_waitq_t obd_race_waitq;
76 int proc_fail_loc SYSCTL_HANDLER_ARGS
79 int old_fail_loc = obd_fail_loc;
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);
90 error = SYSCTL_OUT(req, &obd_fail_loc, sizeof obd_fail_loc);
95 int proc_obd_timeout SYSCTL_HANDLER_ARGS
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);
107 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
112 int read_build_version SYSCTL_HANDLER_ARGS
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");
120 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
125 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
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");
133 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
138 void obd_sysctl_init (void)
141 if ( !obd_table_header )
142 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
146 void obd_sysctl_clean (void)
149 if ( obd_table_header )
150 cfs_unregister_sysctl_table(obd_table_header);
151 obd_table_header = NULL;