Merge remote-tracking branch 'staging/staging-next'
[deliverable/linux.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
6a5b99a4 18 * http://www.gnu.org/licenses/gpl-2.0.html
d7e09d03 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"
e6264147 48#include "../../include/obd_class.h"
d7e09d03 49
e2424a12
OD
50struct static_lustre_uintvalue_attr {
51 struct {
52 struct attribute attr;
53 ssize_t (*show)(struct kobject *kobj, struct attribute *attr,
54 char *buf);
55 ssize_t (*store)(struct kobject *kobj, struct attribute *attr,
56 const char *buf, size_t len);
57 } u;
58 int *value;
59};
60
61static ssize_t static_uintvalue_show(struct kobject *kobj,
926d6fb2
OD
62 struct attribute *attr,
63 char *buf)
d7e09d03 64{
e2424a12
OD
65 struct static_lustre_uintvalue_attr *lattr = (void *)attr;
66
67 return sprintf(buf, "%d\n", *lattr->value);
68}
69
70static ssize_t static_uintvalue_store(struct kobject *kobj,
926d6fb2
OD
71 struct attribute *attr,
72 const char *buffer, size_t count)
e2424a12
OD
73{
74 struct static_lustre_uintvalue_attr *lattr = (void *)attr;
d7e09d03 75 int rc;
e2424a12 76 unsigned int val;
d7e09d03 77
e2424a12
OD
78 rc = kstrtouint(buffer, 10, &val);
79 if (rc)
80 return rc;
81
82 *lattr->value = val;
83
84 return count;
d7e09d03
PT
85}
86
e2424a12
OD
87#define LUSTRE_STATIC_UINT_ATTR(name, value) \
88static struct static_lustre_uintvalue_attr lustre_sattr_##name = \
89 {__ATTR(name, 0644, \
90 static_uintvalue_show, \
91 static_uintvalue_store),\
92 value }
93
94LUSTRE_STATIC_UINT_ATTR(timeout, &obd_timeout);
95
df476a4d
OD
96static ssize_t max_dirty_mb_show(struct kobject *kobj, struct attribute *attr,
97 char *buf)
d7e09d03 98{
44fae22b
OD
99 return sprintf(buf, "%lu\n",
100 (unsigned long)obd_max_dirty_pages /
101 (1 << (20 - PAGE_SHIFT)));
df476a4d
OD
102}
103
104static ssize_t max_dirty_mb_store(struct kobject *kobj, struct attribute *attr,
105 const char *buffer, size_t count)
106{
107 int rc;
108 unsigned long val;
109
110 rc = kstrtoul(buffer, 10, &val);
111 if (rc)
112 return rc;
113
09cbfeaf 114 val *= 1 << (20 - PAGE_SHIFT); /* convert to pages */
d7e09d03 115
df476a4d
OD
116 if (val > ((totalram_pages / 10) * 9)) {
117 /* Somebody wants to assign too much memory to dirty pages */
118 return -EINVAL;
d7e09d03 119 }
df476a4d 120
09cbfeaf 121 if (val < 4 << (20 - PAGE_SHIFT)) {
df476a4d
OD
122 /* Less than 4 Mb for dirty cache is also bad */
123 return -EINVAL;
d7e09d03 124 }
df476a4d
OD
125
126 obd_max_dirty_pages = val;
127
128 return count;
d7e09d03 129}
df476a4d 130LUSTRE_RW_ATTR(max_dirty_mb);
d7e09d03 131
9e7fa149
OD
132LUSTRE_STATIC_UINT_ATTR(debug_peer_on_timeout, &obd_debug_peer_on_timeout);
133LUSTRE_STATIC_UINT_ATTR(dump_on_timeout, &obd_dump_on_timeout);
134LUSTRE_STATIC_UINT_ATTR(dump_on_eviction, &obd_dump_on_eviction);
bcef118e
OD
135LUSTRE_STATIC_UINT_ATTR(at_min, &at_min);
136LUSTRE_STATIC_UINT_ATTR(at_max, &at_max);
137LUSTRE_STATIC_UINT_ATTR(at_extra, &at_extra);
138LUSTRE_STATIC_UINT_ATTR(at_early_margin, &at_early_margin);
139LUSTRE_STATIC_UINT_ATTR(at_history, &at_history);
9e7fa149 140
e2424a12
OD
141static struct attribute *lustre_attrs[] = {
142 &lustre_sattr_timeout.u.attr,
df476a4d 143 &lustre_attr_max_dirty_mb.attr,
9e7fa149
OD
144 &lustre_sattr_debug_peer_on_timeout.u.attr,
145 &lustre_sattr_dump_on_timeout.u.attr,
146 &lustre_sattr_dump_on_eviction.u.attr,
bcef118e
OD
147 &lustre_sattr_at_min.u.attr,
148 &lustre_sattr_at_max.u.attr,
149 &lustre_sattr_at_extra.u.attr,
150 &lustre_sattr_at_early_margin.u.attr,
151 &lustre_sattr_at_history.u.attr,
e2424a12
OD
152 NULL,
153};
154
155static struct attribute_group lustre_attr_group = {
156 .attrs = lustre_attrs,
157};
158
159int obd_sysctl_init(void)
d7e09d03 160{
e2424a12 161 return sysfs_create_group(lustre_kobj, &lustre_attr_group);
d7e09d03 162}
This page took 0.441651 seconds and 5 git commands to generate.