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