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, 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,
59 static cfs_sysctl_table_t parent_table[] = {
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,
70 extern cfs_waitq_t obd_race_waitq;
72 int proc_fail_loc SYSCTL_HANDLER_ARGS
75 int old_fail_loc = obd_fail_loc;
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);
86 error = SYSCTL_OUT(req, &obd_fail_loc, sizeof obd_fail_loc);
91 int proc_obd_timeout SYSCTL_HANDLER_ARGS
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);
103 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
108 int read_build_version SYSCTL_HANDLER_ARGS
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");
116 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
121 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
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");
129 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
134 void obd_sysctl_init (void)
137 if ( !obd_table_header )
138 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
142 void obd_sysctl_clean (void)
145 if ( obd_table_header )
146 cfs_unregister_sysctl_table(obd_table_header);
147 obd_table_header = NULL;