Whamcloud - gitweb
LU-2675 obd: remove dead code
[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
52 struct ctl_table_header *obd_table_header = NULL;
53
54 int proc_obd_timeout SYSCTL_HANDLER_ARGS;
55 extern unsigned int obd_dump_on_timeout;
56 extern unsigned int obd_timeout;
57 extern unsigned int ldlm_timeout;
58 extern atomic_t obd_memory;
59
60 int read_build_version SYSCTL_HANDLER_ARGS;
61
62 SYSCTL_NODE (,                  OID_AUTO,       lustre,     CTLFLAG_RW,
63              0,                 "lustre sysctl top");
64 SYSCTL_PROC(_lustre,            OID_AUTO,       timeout, 
65             CTLTYPE_INT | CTLFLAG_RW ,          &obd_timeout,
66             0,          &proc_obd_timeout,      "I",    "obd_timeout");
67 SYSCTL_PROC(_lustre,            OID_AUTO,       build_version, 
68             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
69             0,          &read_build_version,    "A",    "lustre_build_version");
70 SYSCTL_INT(_lustre,             OID_AUTO,       dump_on_timeout, 
71            CTLTYPE_INT | CTLFLAG_RW,            &obd_dump_on_timeout,
72            0,           "lustre_dump_on_timeout");
73 SYSCTL_INT(_lustre,             OID_AUTO,       debug_peer_on_timeout, 
74            CTLTYPE_INT | CTLFLAG_RW,            &obd_debug_peer_on_timeout,
75            0,           "lustre_debug_peer_on_timeout");
76 SYSCTL_INT(_lustre,             OID_AUTO,       memused, 
77            CTLTYPE_INT | CTLFLAG_RW,            (int *)&obd_memory.counter,
78            0,           "lustre_memory_used");
79 SYSCTL_INT(_lustre,             OID_AUTO,       ldlm_timeout, 
80            CTLTYPE_INT | CTLFLAG_RW,            &ldlm_timeout,
81            0,           "ldlm_timeout");
82
83 static struct ctl_table      parent_table[] = {
84         &sysctl__lustre,
85         &sysctl__lustre_timeout,
86         &sysctl__lustre_dump_on_timeout,
87         &sysctl__lustre_debug_peer_on_timeout,
88         &sysctl__lustre_upcall,
89         &sysctl__lustre_memused,
90         &sysctl__lustre_filter_sync_on_commit,
91         &sysctl__lustre_ldlm_timeout,
92 };
93
94 int proc_obd_timeout SYSCTL_HANDLER_ARGS
95
96         int error = 0;
97
98         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
99         if (!error && req->newptr != USER_ADDR_NULL) {
100                 if (ldlm_timeout >= obd_timeout)
101                         ldlm_timeout = max(obd_timeout / 3, 1U);
102         } else  if (req->newptr != USER_ADDR_NULL) { 
103                 printf ("sysctl fail obd_timeout: %d.\n", error);
104         } else {
105                 /* Read request */ 
106                 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
107         }
108         return error;
109 }
110
111 int read_build_version SYSCTL_HANDLER_ARGS
112 {
113         int error = 0;
114
115         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
116         if ( req->newptr != USER_ADDR_NULL) {
117                 printf("sysctl read_build_version is read-only!\n");
118         } else {
119                 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
120         }
121         return error;
122 }
123
124 void obd_sysctl_init (void)
125 {
126 #if 1 
127         if ( !obd_table_header ) 
128                 obd_table_header = register_sysctl_table(parent_table);
129 #endif
130 }
131                                                                                                                                                                      
132 void obd_sysctl_clean (void)
133 {
134 #if 1 
135         if ( obd_table_header ) 
136                 unregister_sysctl_table(obd_table_header);
137         obd_table_header = NULL;
138 #endif
139 }