Commit | Line | Data |
---|---|---|
d7e09d03 PT |
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) 1999, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
1dc563a6 | 30 | * Copyright (c) 2011, 2015, Intel Corporation. |
d7e09d03 PT |
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 <linux/module.h> | |
38 | #include <linux/sysctl.h> | |
39 | #include <linux/sched.h> | |
40 | #include <linux/mm.h> | |
d7e09d03 PT |
41 | #include <linux/slab.h> |
42 | #include <linux/stat.h> | |
43 | #include <linux/ctype.h> | |
87822e41 AS |
44 | #include <linux/bitops.h> |
45 | #include <linux/uaccess.h> | |
d7e09d03 PT |
46 | #include <linux/utsname.h> |
47 | ||
48 | #define DEBUG_SUBSYSTEM S_CLASS | |
49 | ||
610f7377 GKH |
50 | #include "../../include/obd_support.h" |
51 | #include "../../include/lprocfs_status.h" | |
d7e09d03 | 52 | |
e2424a12 OD |
53 | struct static_lustre_uintvalue_attr { |
54 | struct { | |
55 | struct attribute attr; | |
56 | ssize_t (*show)(struct kobject *kobj, struct attribute *attr, | |
57 | char *buf); | |
58 | ssize_t (*store)(struct kobject *kobj, struct attribute *attr, | |
59 | const char *buf, size_t len); | |
60 | } u; | |
61 | int *value; | |
62 | }; | |
63 | ||
64 | static ssize_t static_uintvalue_show(struct kobject *kobj, | |
926d6fb2 OD |
65 | struct attribute *attr, |
66 | char *buf) | |
d7e09d03 | 67 | { |
e2424a12 OD |
68 | struct static_lustre_uintvalue_attr *lattr = (void *)attr; |
69 | ||
70 | return sprintf(buf, "%d\n", *lattr->value); | |
71 | } | |
72 | ||
73 | static ssize_t static_uintvalue_store(struct kobject *kobj, | |
926d6fb2 OD |
74 | struct attribute *attr, |
75 | const char *buffer, size_t count) | |
e2424a12 OD |
76 | { |
77 | struct static_lustre_uintvalue_attr *lattr = (void *)attr; | |
d7e09d03 | 78 | int rc; |
e2424a12 | 79 | unsigned int val; |
d7e09d03 | 80 | |
e2424a12 OD |
81 | rc = kstrtouint(buffer, 10, &val); |
82 | if (rc) | |
83 | return rc; | |
84 | ||
85 | *lattr->value = val; | |
86 | ||
87 | return count; | |
d7e09d03 PT |
88 | } |
89 | ||
e2424a12 OD |
90 | #define LUSTRE_STATIC_UINT_ATTR(name, value) \ |
91 | static struct static_lustre_uintvalue_attr lustre_sattr_##name = \ | |
92 | {__ATTR(name, 0644, \ | |
93 | static_uintvalue_show, \ | |
94 | static_uintvalue_store),\ | |
95 | value } | |
96 | ||
97 | LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout); | |
98 | ||
df476a4d OD |
99 | static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr, |
100 | char *buf) | |
d7e09d03 | 101 | { |
df476a4d | 102 | return sprintf(buf, "%ul\n", |
09cbfeaf | 103 | obd_max_dirty_pages / (1 << (20 - PAGE_SHIFT))); |
df476a4d OD |
104 | } |
105 | ||
106 | static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr, | |
107 | const char *buffer, size_t count) | |
108 | { | |
109 | int rc; | |
110 | unsigned long val; | |
111 | ||
112 | rc = kstrtoul(buffer, 10, &val); | |
113 | if (rc) | |
114 | return rc; | |
115 | ||
09cbfeaf | 116 | val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */ |
d7e09d03 | 117 | |
df476a4d OD |
118 | if (val > ((totalram_pages / 10) * 9)) { |
119 | /* Somebody wants to assign too much memory to dirty pages */ | |
120 | return -EINVAL; | |
d7e09d03 | 121 | } |
df476a4d | 122 | |
09cbfeaf | 123 | if (val < 4 << (20 - PAGE_SHIFT)) { |
df476a4d OD |
124 | /* Less than 4 Mb for dirty cache is also bad */ |
125 | return -EINVAL; | |
d7e09d03 | 126 | } |
df476a4d OD |
127 | |
128 | obd_max_dirty_pages = val; | |
129 | ||
130 | return count; | |
d7e09d03 | 131 | } |
df476a4d | 132 | LUSTRE_RW_ATTR(max_dirty_mb); |
d7e09d03 | 133 | |
9e7fa149 OD |
134 | LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout); |
135 | LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout); | |
136 | LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction); | |
bcef118e OD |
137 | LUSTRE_STATIC_UINT_ATTR(at_min, &at_min); |
138 | LUSTRE_STATIC_UINT_ATTR(at_max, &at_max); | |
139 | LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra); | |
140 | LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin); | |
141 | LUSTRE_STATIC_UINT_ATTR(at_history, &at_history); | |
9e7fa149 | 142 | |
e2424a12 OD |
143 | static struct attribute *lustre_attrs[] = { |
144 | &lustre_sattr_timeout.u.attr, | |
df476a4d | 145 | &lustre_attr_max_dirty_mb.attr, |
9e7fa149 OD |
146 | &lustre_sattr_debug_peer_on_timeout.u.attr, |
147 | &lustre_sattr_dump_on_timeout.u.attr, | |
148 | &lustre_sattr_dump_on_eviction.u.attr, | |
bcef118e OD |
149 | &lustre_sattr_at_min.u.attr, |
150 | &lustre_sattr_at_max.u.attr, | |
151 | &lustre_sattr_at_extra.u.attr, | |
152 | &lustre_sattr_at_early_margin.u.attr, | |
153 | &lustre_sattr_at_history.u.attr, | |
e2424a12 OD |
154 | NULL, |
155 | }; | |
156 | ||
157 | static struct attribute_group lustre_attr_group = { | |
158 | .attrs = lustre_attrs, | |
159 | }; | |
160 | ||
161 | int obd_sysctl_init(void) | |
d7e09d03 | 162 | { |
e2424a12 | 163 | return sysfs_create_group(lustre_kobj, &lustre_attr_group); |
d7e09d03 | 164 | } |