4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #include <linux/module.h>
34 #include <linux/sched.h>
36 #include <linux/slab.h>
37 #include <linux/stat.h>
38 #include <linux/ctype.h>
39 #include <linux/bitops.h>
40 #include <linux/uaccess.h>
41 #include <linux/utsname.h>
43 #define DEBUG_SUBSYSTEM S_CLASS
45 #include <obd_support.h>
46 #include <lprocfs_status.h>
47 #include <obd_class.h>
49 struct static_lustre_uintvalue_attr {
51 struct attribute attr;
52 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
54 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
55 const char *buf, size_t len);
60 static ssize_t static_uintvalue_show(struct kobject *kobj,
61 struct attribute *attr,
64 struct static_lustre_uintvalue_attr *lattr = (void *)attr;
66 return sprintf(buf, "%d\n", *lattr->value);
69 static ssize_t static_uintvalue_store(struct kobject *kobj,
70 struct attribute *attr,
71 const char *buffer, size_t count)
73 struct static_lustre_uintvalue_attr *lattr = (void *)attr;
77 rc = kstrtouint(buffer, 10, &val);
86 #define LUSTRE_STATIC_UINT_ATTR(name, value) \
87 static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
89 static_uintvalue_show, \
90 static_uintvalue_store),\
93 LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
95 static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
98 return sprintf(buf, "%lu\n",
99 obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT)));
102 static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
103 const char *buffer, size_t count)
108 rc = kstrtoul(buffer, 10, &val);
112 val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
114 if (val > ((totalram_pages / 10) * 9)) {
115 /* Somebody wants to assign too much memory to dirty pages */
119 if (val < 4 << (20 - PAGE_SHIFT)) {
120 /* Less than 4 Mb for dirty cache is also bad */
124 obd_max_dirty_pages = val;
128 LUSTRE_RW_ATTR(max_dirty_mb);
130 LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
131 LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
132 LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
133 LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
134 LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
135 LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
136 LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
137 LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
139 #ifdef HAVE_SERVER_SUPPORT
140 LUSTRE_STATIC_UINT_ATTR(ldlm_timeout, &ldlm_timeout);
141 LUSTRE_STATIC_UINT_ATTR(bulk_timeout, &bulk_timeout);
144 static ssize_t memused_show(struct kobject *kobj, struct attribute *attr,
147 return sprintf(buf, "%llu\n", obd_memory_sum());
149 LUSTRE_RO_ATTR(memused);
151 static ssize_t memused_max_show(struct kobject *kobj, struct attribute *attr,
154 return sprintf(buf, "%llu\n", obd_memory_max());
156 LUSTRE_RO_ATTR(memused_max);
158 static struct attribute *lustre_attrs[] = {
159 &lustre_sattr_timeout.u.attr,
160 &lustre_attr_max_dirty_mb.attr,
161 &lustre_sattr_debug_peer_on_timeout.u.attr,
162 &lustre_sattr_dump_on_timeout.u.attr,
163 &lustre_sattr_dump_on_eviction.u.attr,
164 &lustre_sattr_at_min.u.attr,
165 &lustre_sattr_at_max.u.attr,
166 &lustre_sattr_at_extra.u.attr,
167 &lustre_sattr_at_early_margin.u.attr,
168 &lustre_sattr_at_history.u.attr,
169 &lustre_attr_memused_max.attr,
170 &lustre_attr_memused.attr,
171 #ifdef HAVE_SERVER_SUPPORT
172 &lustre_sattr_ldlm_timeout.u.attr,
173 &lustre_sattr_bulk_timeout.u.attr,
178 static struct attribute_group lustre_attr_group = {
179 .attrs = lustre_attrs,
182 int obd_sysctl_init(void)
184 return sysfs_create_group(lustre_kobj, &lustre_attr_group);
187 void obd_sysctl_clean(void)
189 sysfs_remove_group(lustre_kobj, &lustre_attr_group);