Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / obdclass / darwin / darwin-sysctl.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  */
36
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/systm.h>
41 #include <sys/sysctl.h>
42 #include <sys/proc.h>
43 #include <sys/unistd.h>
44 #include <mach/mach_types.h>
45 #include <lustre/lustre_build_version.h>
46
47 #define DEBUG_SUBSYSTEM S_CLASS
48                                                                                                                                                                      
49 #include <libcfs/libcfs.h>
50 #ifndef BUILD_VERSION   
51 #define BUILD_VERSION           "Unknown"
52 #endif
53 #ifndef LUSTRE_KERNEL_VERSION
54 #define LUSTRE_KERNEL_VERSION   "Unknown Darwin version"
55 #endif
56
57 cfs_sysctl_table_header_t *obd_table_header = NULL;
58
59 int proc_fail_loc SYSCTL_HANDLER_ARGS;
60 int proc_obd_timeout SYSCTL_HANDLER_ARGS;
61 extern unsigned long obd_fail_loc;
62 extern unsigned int obd_dump_on_timeout;
63 extern unsigned int obd_timeout;
64 extern unsigned int ldlm_timeout;
65 extern unsigned int obd_sync_filter;
66 extern atomic_t obd_memory;
67
68 int read_build_version SYSCTL_HANDLER_ARGS;
69 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS;
70
71 SYSCTL_NODE (,                  OID_AUTO,       lustre,     CTLFLAG_RW,
72              0,                 "lustre sysctl top");
73 SYSCTL_PROC(_lustre,            OID_AUTO,       fail_loc, 
74             CTLTYPE_INT | CTLFLAG_RW ,          &obd_fail_loc,
75             0,          &proc_fail_loc,         "I",    "obd_fail_loc");
76 SYSCTL_PROC(_lustre,            OID_AUTO,       timeout, 
77             CTLTYPE_INT | CTLFLAG_RW ,          &obd_timeout,
78             0,          &proc_obd_timeout,      "I",    "obd_timeout");
79 SYSCTL_PROC(_lustre,            OID_AUTO,       build_version, 
80             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
81             0,          &read_build_version,    "A",    "lustre_build_version");
82 SYSCTL_PROC(_lustre,            OID_AUTO,       lustre_kernel_version,
83             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
84             0,          &read_lustre_kernel_version,    "A",    "lustre_build_version");
85 SYSCTL_INT(_lustre,             OID_AUTO,       dump_on_timeout, 
86            CTLTYPE_INT | CTLFLAG_RW,            &obd_dump_on_timeout,
87            0,           "lustre_dump_on_timeout");
88 SYSCTL_INT(_lustre,             OID_AUTO,       debug_peer_on_timeout, 
89            CTLTYPE_INT | CTLFLAG_RW,            &obd_debug_peer_on_timeout,
90            0,           "lustre_debug_peer_on_timeout");
91 SYSCTL_INT(_lustre,             OID_AUTO,       memused, 
92            CTLTYPE_INT | CTLFLAG_RW,            (int *)&obd_memory.counter,
93            0,           "lustre_memory_used");
94 SYSCTL_INT(_lustre,             OID_AUTO,       ldlm_timeout, 
95            CTLTYPE_INT | CTLFLAG_RW,            &ldlm_timeout,
96            0,           "ldlm_timeout");
97
98 static cfs_sysctl_table_t      parent_table[] = {
99         &sysctl__lustre,
100         &sysctl__lustre_fail_loc,
101         &sysctl__lustre_timeout,
102         &sysctl__lustre_dump_on_timeout,
103         &sysctl__lustre_debug_peer_on_timeout,
104         &sysctl__lustre_upcall,
105         &sysctl__lustre_memused,
106         &sysctl__lustre_filter_sync_on_commit,
107         &sysctl__lustre_ldlm_timeout,
108 };
109
110 extern cfs_waitq_t obd_race_waitq;
111
112 int proc_fail_loc SYSCTL_HANDLER_ARGS
113
114         int error = 0; 
115         long old_fail_loc = obd_fail_loc;
116         
117         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
118         if (!error && req->newptr != USER_ADDR_NULL) {
119                 if (old_fail_loc != obd_fail_loc) 
120                         cfs_waitq_signal(&obd_race_waitq);
121         } else  if (req->newptr != USER_ADDR_NULL) { 
122                 /* Something was wrong with the write request */ 
123                 printf ("sysctl fail loc fault: %d.\n", error);
124         } else { 
125                 /* Read request */ 
126                 error = SYSCTL_OUT(req, &obd_fail_loc, sizeof obd_fail_loc);
127         }
128         return error;
129 }
130
131 int proc_obd_timeout SYSCTL_HANDLER_ARGS
132
133         int error = 0;
134
135         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
136         if (!error && req->newptr != USER_ADDR_NULL) {
137                 if (ldlm_timeout >= obd_timeout)
138                         ldlm_timeout = max(obd_timeout / 3, 1U);
139         } else  if (req->newptr != USER_ADDR_NULL) { 
140                 printf ("sysctl fail obd_timeout: %d.\n", error);
141         } else {
142                 /* Read request */ 
143                 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
144         }
145         return error;
146 }
147
148 int read_build_version SYSCTL_HANDLER_ARGS
149 {
150         int error = 0;
151
152         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
153         if ( req->newptr != USER_ADDR_NULL) {
154                 printf("sysctl read_build_version is read-only!\n");
155         } else {
156                 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
157         }
158         return error;
159 }
160
161 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
162 {
163         int error = 0;
164
165         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
166         if ( req->newptr != NULL) {
167                 printf("sysctl lustre_kernel_version is read-only!\n");
168         } else {
169                 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
170         }
171         return error;
172 }
173
174 void obd_sysctl_init (void)
175 {
176 #if 1 
177         if ( !obd_table_header ) 
178                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
179 #endif
180 }
181                                                                                                                                                                      
182 void obd_sysctl_clean (void)
183 {
184 #if 1 
185         if ( obd_table_header ) 
186                 cfs_unregister_sysctl_table(obd_table_header); 
187         obd_table_header = NULL;
188 #endif
189 }
190