Whamcloud - gitweb
LU-224 Move fail_loc handling from lustre to libcfs
[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
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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 (c) 2007, 2010, Oracle and/or its affiliates. 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_obd_timeout SYSCTL_HANDLER_ARGS;
60 extern unsigned int obd_dump_on_timeout;
61 extern unsigned int obd_timeout;
62 extern unsigned int ldlm_timeout;
63 extern unsigned int obd_sync_filter;
64 extern atomic_t obd_memory;
65
66 int read_build_version SYSCTL_HANDLER_ARGS;
67 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS;
68
69 SYSCTL_NODE (,                  OID_AUTO,       lustre,     CTLFLAG_RW,
70              0,                 "lustre sysctl top");
71 SYSCTL_PROC(_lustre,            OID_AUTO,       timeout, 
72             CTLTYPE_INT | CTLFLAG_RW ,          &obd_timeout,
73             0,          &proc_obd_timeout,      "I",    "obd_timeout");
74 SYSCTL_PROC(_lustre,            OID_AUTO,       build_version, 
75             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
76             0,          &read_build_version,    "A",    "lustre_build_version");
77 SYSCTL_PROC(_lustre,            OID_AUTO,       lustre_kernel_version,
78             CTLTYPE_STRING | CTLFLAG_RD ,       NULL,
79             0,          &read_lustre_kernel_version,    "A",    "lustre_build_version");
80 SYSCTL_INT(_lustre,             OID_AUTO,       dump_on_timeout, 
81            CTLTYPE_INT | CTLFLAG_RW,            &obd_dump_on_timeout,
82            0,           "lustre_dump_on_timeout");
83 SYSCTL_INT(_lustre,             OID_AUTO,       debug_peer_on_timeout, 
84            CTLTYPE_INT | CTLFLAG_RW,            &obd_debug_peer_on_timeout,
85            0,           "lustre_debug_peer_on_timeout");
86 SYSCTL_INT(_lustre,             OID_AUTO,       memused, 
87            CTLTYPE_INT | CTLFLAG_RW,            (int *)&obd_memory.counter,
88            0,           "lustre_memory_used");
89 SYSCTL_INT(_lustre,             OID_AUTO,       ldlm_timeout, 
90            CTLTYPE_INT | CTLFLAG_RW,            &ldlm_timeout,
91            0,           "ldlm_timeout");
92
93 static cfs_sysctl_table_t      parent_table[] = {
94         &sysctl__lustre,
95         &sysctl__lustre_timeout,
96         &sysctl__lustre_dump_on_timeout,
97         &sysctl__lustre_debug_peer_on_timeout,
98         &sysctl__lustre_upcall,
99         &sysctl__lustre_memused,
100         &sysctl__lustre_filter_sync_on_commit,
101         &sysctl__lustre_ldlm_timeout,
102 };
103
104 int proc_obd_timeout SYSCTL_HANDLER_ARGS
105
106         int error = 0;
107
108         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
109         if (!error && req->newptr != USER_ADDR_NULL) {
110                 if (ldlm_timeout >= obd_timeout)
111                         ldlm_timeout = max(obd_timeout / 3, 1U);
112         } else  if (req->newptr != USER_ADDR_NULL) { 
113                 printf ("sysctl fail obd_timeout: %d.\n", error);
114         } else {
115                 /* Read request */ 
116                 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
117         }
118         return error;
119 }
120
121 int read_build_version SYSCTL_HANDLER_ARGS
122 {
123         int error = 0;
124
125         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
126         if ( req->newptr != USER_ADDR_NULL) {
127                 printf("sysctl read_build_version is read-only!\n");
128         } else {
129                 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
130         }
131         return error;
132 }
133
134 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
135 {
136         int error = 0;
137
138         error = sysctl_handle_long(oidp, oidp->oid_arg1, oidp->oid_arg2, req); 
139         if ( req->newptr != NULL) {
140                 printf("sysctl lustre_kernel_version is read-only!\n");
141         } else {
142                 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
143         }
144         return error;
145 }
146
147 void obd_sysctl_init (void)
148 {
149 #if 1 
150         if ( !obd_table_header ) 
151                 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
152 #endif
153 }
154                                                                                                                                                                      
155 void obd_sysctl_clean (void)
156 {
157 #if 1 
158         if ( obd_table_header ) 
159                 cfs_unregister_sysctl_table(obd_table_header); 
160         obd_table_header = NULL;
161 #endif
162 }