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