1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
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>
43 #include <sys/unistd.h>
44 #include <mach/mach_types.h>
45 #include <lustre/lustre_build_version.h>
47 #define DEBUG_SUBSYSTEM S_CLASS
49 #include <libcfs/libcfs.h>
51 #define BUILD_VERSION "Unknown"
53 #ifndef LUSTRE_KERNEL_VERSION
54 #define LUSTRE_KERNEL_VERSION "Unknown Darwin version"
57 cfs_sysctl_table_header_t *obd_table_header = NULL;
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;
68 int read_build_version SYSCTL_HANDLER_ARGS;
69 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS;
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,
98 static cfs_sysctl_table_t parent_table[] = {
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,
110 extern cfs_waitq_t obd_race_waitq;
112 int proc_fail_loc SYSCTL_HANDLER_ARGS
115 long old_fail_loc = obd_fail_loc;
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);
126 error = SYSCTL_OUT(req, &obd_fail_loc, sizeof obd_fail_loc);
131 int proc_obd_timeout SYSCTL_HANDLER_ARGS
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);
143 error = SYSCTL_OUT(req, &obd_timeout, sizeof obd_timeout);
148 int read_build_version SYSCTL_HANDLER_ARGS
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");
156 error = SYSCTL_OUT(req, BUILD_VERSION, strlen(BUILD_VERSION));
161 int read_lustre_kernel_version SYSCTL_HANDLER_ARGS
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");
169 error = SYSCTL_OUT(req, LUSTRE_KERNEL_VERSION, strlen(LUSTRE_KERNEL_VERSION));
174 void obd_sysctl_init (void)
177 if ( !obd_table_header )
178 obd_table_header = cfs_register_sysctl_table(parent_table, 0);
182 void obd_sysctl_clean (void)
185 if ( obd_table_header )
186 cfs_unregister_sysctl_table(obd_table_header);
187 obd_table_header = NULL;