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