blob: 084954448f1868840cbf3291cbb226206c2ffd51 [file] [log] [blame]
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001/*
2 * Documentation/ABI/stable/orangefs-sysfs:
3 *
4 * What: /sys/fs/orangefs/perf_counter_reset
5 * Date: June 2015
6 * Contact: Mike Marshall <hubcap@omnibond.com>
7 * Description:
8 * echo a 0 or a 1 into perf_counter_reset to
9 * reset all the counters in
10 * /sys/fs/orangefs/perf_counters
11 * except ones with PINT_PERF_PRESERVE set.
12 *
13 *
14 * What: /sys/fs/orangefs/perf_counters/...
15 * Date: Jun 2015
16 * Contact: Mike Marshall <hubcap@omnibond.com>
17 * Description:
18 * Counters and settings for various caches.
19 * Read only.
20 *
21 *
22 * What: /sys/fs/orangefs/perf_time_interval_secs
23 * Date: Jun 2015
24 * Contact: Mike Marshall <hubcap@omnibond.com>
25 * Description:
26 * Length of perf counter intervals in
27 * seconds.
28 *
29 *
30 * What: /sys/fs/orangefs/perf_history_size
31 * Date: Jun 2015
32 * Contact: Mike Marshall <hubcap@omnibond.com>
33 * Description:
34 * The perf_counters cache statistics have N, or
35 * perf_history_size, samples. The default is
36 * one.
37 *
38 * Every perf_time_interval_secs the (first)
39 * samples are reset.
40 *
41 * If N is greater than one, the "current" set
42 * of samples is reset, and the samples from the
43 * other N-1 intervals remain available.
44 *
45 *
46 * What: /sys/fs/orangefs/op_timeout_secs
47 * Date: Jun 2015
48 * Contact: Mike Marshall <hubcap@omnibond.com>
49 * Description:
50 * Service operation timeout in seconds.
51 *
52 *
53 * What: /sys/fs/orangefs/slot_timeout_secs
54 * Date: Jun 2015
55 * Contact: Mike Marshall <hubcap@omnibond.com>
56 * Description:
57 * "Slot" timeout in seconds. A "slot"
58 * is an indexed buffer in the shared
59 * memory segment used for communication
60 * between the kernel module and userspace.
61 * Slots are requested and waited for,
62 * the wait times out after slot_timeout_secs.
63 *
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040064 * What: /sys/fs/orangefs/dcache_timeout_msecs
65 * Date: Jul 2016
66 * Contact: Martin Brandenburg <martin@omnibond.com>
67 * Description:
68 * Time lookup is valid in milliseconds.
69 *
70 * What: /sys/fs/orangefs/getattr_timeout_msecs
71 * Date: Jul 2016
72 * Contact: Martin Brandenburg <martin@omnibond.com>
73 * Description:
74 * Time getattr is valid in milliseconds.
Mike Marshallf7be4ee2015-07-17 10:38:14 -040075 *
Martin Brandenburg4d20a752016-08-03 13:47:28 -040076 * What: /sys/fs/orangefs/readahead_count
77 * Date: Aug 2016
78 * Contact: Martin Brandenburg <martin@omnibond.com>
79 * Description:
80 * Readahead cache buffer count.
81 *
82 * What: /sys/fs/orangefs/readahead_size
83 * Date: Aug 2016
84 * Contact: Martin Brandenburg <martin@omnibond.com>
85 * Description:
86 * Readahead cache buffer size.
87 *
88 * What: /sys/fs/orangefs/readahead_count_size
89 * Date: Aug 2016
90 * Contact: Martin Brandenburg <martin@omnibond.com>
91 * Description:
92 * Readahead cache buffer count and size.
93 *
Mike Marshallf7be4ee2015-07-17 10:38:14 -040094 * What: /sys/fs/orangefs/acache/...
95 * Date: Jun 2015
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040096 * Contact: Martin Brandenburg <martin@omnibond.com>
Mike Marshallf7be4ee2015-07-17 10:38:14 -040097 * Description:
98 * Attribute cache configurable settings.
99 *
100 *
101 * What: /sys/fs/orangefs/ncache/...
102 * Date: Jun 2015
103 * Contact: Mike Marshall <hubcap@omnibond.com>
104 * Description:
105 * Name cache configurable settings.
106 *
107 *
108 * What: /sys/fs/orangefs/capcache/...
109 * Date: Jun 2015
110 * Contact: Mike Marshall <hubcap@omnibond.com>
111 * Description:
112 * Capability cache configurable settings.
113 *
114 *
115 * What: /sys/fs/orangefs/ccache/...
116 * Date: Jun 2015
117 * Contact: Mike Marshall <hubcap@omnibond.com>
118 * Description:
119 * Credential cache configurable settings.
120 *
121 */
122
123#include <linux/fs.h>
124#include <linux/kobject.h>
125#include <linux/string.h>
126#include <linux/sysfs.h>
127#include <linux/module.h>
128#include <linux/init.h>
129
130#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -0500131#include "orangefs-kernel.h"
132#include "orangefs-sysfs.h"
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400133
134#define ORANGEFS_KOBJ_ID "orangefs"
135#define ACACHE_KOBJ_ID "acache"
136#define CAPCACHE_KOBJ_ID "capcache"
137#define CCACHE_KOBJ_ID "ccache"
138#define NCACHE_KOBJ_ID "ncache"
139#define PC_KOBJ_ID "pc"
140#define STATS_KOBJ_ID "stats"
141
Martin Brandenburgc27889cd2016-08-15 15:11:32 -0400142/*
143 * Every item calls orangefs_attr_show and orangefs_attr_store through
144 * orangefs_sysfs_ops. They look at the orangefs_attributes further below to
145 * call one of sysfs_int_show, sysfs_int_store, sysfs_service_op_show, or
146 * sysfs_service_op_store.
147 */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400148
149struct orangefs_attribute {
150 struct attribute attr;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400151 ssize_t (*show)(struct kobject *kobj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400152 struct orangefs_attribute *attr,
153 char *buf);
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400154 ssize_t (*store)(struct kobject *kobj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400155 struct orangefs_attribute *attr,
156 const char *buf,
157 size_t count);
158};
159
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400160static ssize_t orangefs_attr_show(struct kobject *kobj,
161 struct attribute *attr,
162 char *buf)
163{
164 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400165
166 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400167 if (!attribute->show)
168 return -EIO;
169 return attribute->show(kobj, attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400170}
171
172static ssize_t orangefs_attr_store(struct kobject *kobj,
173 struct attribute *attr,
174 const char *buf,
175 size_t len)
176{
177 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400178
Martin Brandenburg4a343662016-08-15 15:01:30 -0400179 if (!strcmp(kobj->name, PC_KOBJ_ID) ||
180 !strcmp(kobj->name, STATS_KOBJ_ID))
181 return -EPERM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400182
183 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400184 if (!attribute->store)
185 return -EIO;
186 return attribute->store(kobj, attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400187}
188
189static const struct sysfs_ops orangefs_sysfs_ops = {
190 .show = orangefs_attr_show,
191 .store = orangefs_attr_store,
192};
193
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400194static ssize_t sysfs_int_show(struct kobject *kobj,
195 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400196{
197 int rc = -EIO;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400198
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400199 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
200 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400201
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400202 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
203 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400204 rc = scnprintf(buf,
205 PAGE_SIZE,
206 "%d\n",
207 op_timeout_secs);
208 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400209 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400210 "slot_timeout_secs")) {
211 rc = scnprintf(buf,
212 PAGE_SIZE,
213 "%d\n",
214 slot_timeout_secs);
215 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400216 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400217 "dcache_timeout_msecs")) {
218 rc = scnprintf(buf,
219 PAGE_SIZE,
220 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400221 orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400222 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400223 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400224 "getattr_timeout_msecs")) {
225 rc = scnprintf(buf,
226 PAGE_SIZE,
227 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400228 orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400229 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400230 } else {
231 goto out;
232 }
233
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400234 } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
235 if (!strcmp(attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400236 rc = scnprintf(buf,
237 PAGE_SIZE,
238 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400239 orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400240 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400241 } else if (!strcmp(attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400242 rc = scnprintf(buf,
243 PAGE_SIZE,
244 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400245 orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400246 goto out;
247 } else {
248 goto out;
249 }
250 }
251
252out:
253
254 return rc;
255}
256
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400257static ssize_t sysfs_int_store(struct kobject *kobj,
258 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400259{
260 int rc = 0;
261
262 gossip_debug(GOSSIP_SYSFS_DEBUG,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400263 "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400264 attr->attr.name, buf);
265
266 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
267 rc = kstrtoint(buf, 0, &op_timeout_secs);
268 goto out;
269 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
270 rc = kstrtoint(buf, 0, &slot_timeout_secs);
271 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400272 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400273 rc = kstrtoint(buf, 0, &orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400274 goto out;
275 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400276 rc = kstrtoint(buf, 0, &orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400277 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400278 } else {
279 goto out;
280 }
281
282out:
283 if (rc)
284 rc = -EINVAL;
285 else
286 rc = count;
287
288 return rc;
289}
290
291/*
292 * obtain attribute values from userspace with a service operation.
293 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400294static ssize_t sysfs_service_op_show(struct kobject *kobj,
295 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400296{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500297 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400298 int rc = 0;
299 char *ser_op_type = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400300 __u32 op_alloc_type;
301
302 gossip_debug(GOSSIP_SYSFS_DEBUG,
303 "sysfs_service_op_show: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400304 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400305
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400306 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500307 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400308 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500309 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400310
311 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500312 if (!new_op)
313 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400314
315 /* Can't do a service_operation if the client is not running... */
316 rc = is_daemon_in_service();
317 if (rc) {
318 pr_info("%s: Client not running :%d:\n",
319 __func__,
320 is_daemon_in_service());
321 goto out;
322 }
323
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400324 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500325 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400326
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400327 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400328 /* Drop unsupported requests first. */
329 if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
Martin Brandenburgb78b1192016-09-28 14:50:46 -0400330 (!strcmp(attr->attr.name, "readahead_count") ||
331 !strcmp(attr->attr.name, "readahead_size") ||
332 !strcmp(attr->attr.name, "readahead_count_size"))) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400333 rc = -EINVAL;
334 goto out;
335 }
336
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400337 if (!strcmp(attr->attr.name, "perf_history_size"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400338 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500339 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400340 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400341 "perf_time_interval_secs"))
342 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500343 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400344 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400345 "perf_counter_reset"))
346 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500347 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400348
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400349 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400350 "readahead_count"))
351 new_op->upcall.req.param.op =
352 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
353
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400354 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400355 "readahead_size"))
356 new_op->upcall.req.param.op =
357 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
358
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400359 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400360 "readahead_count_size"))
361 new_op->upcall.req.param.op =
362 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400363 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
364 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400365 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500366 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400367
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400368 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400369 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500370 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400371
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400372 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400373 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500374 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400375
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400376 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400377 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500378 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400379
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400380 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
381 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400382 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500383 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400384
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400385 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400386 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500387 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400388
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400389 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400390 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500391 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400392
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400393 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400394 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500395 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400396
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400397 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
398 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400399 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500400 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400401
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400402 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400403 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500404 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400405
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400406 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400407 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500408 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400409
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400410 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400411 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500412 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400413
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400414 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
415 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400416 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500417 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400418
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400419 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400420 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500421 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400422
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400423 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400424 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500425 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400426
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400427 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400428 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500429 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400430
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400431 } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
432 if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400433 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500434 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400435
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400436 if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400437 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500438 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400439
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400440 if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400441 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500442 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400443
444 } else {
445 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400446 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400447 rc = -EINVAL;
448 goto out;
449 }
450
451
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400452 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500453 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400454 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500455 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400456
457 /*
458 * The service_operation will return an errno return code on
459 * error, and zero on success.
460 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500461 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400462
463out:
464 if (!rc) {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400465 if (strcmp(kobj->name, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400466 if (new_op->upcall.req.param.op ==
467 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
468 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
469 (int)new_op->downcall.resp.param.u.
470 value32[0],
471 (int)new_op->downcall.resp.param.u.
472 value32[1]);
473 } else {
474 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
475 (int)new_op->downcall.resp.param.u.value64);
476 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400477 } else {
478 rc = scnprintf(
479 buf,
480 PAGE_SIZE,
481 "%s",
482 new_op->downcall.resp.perf_count.buffer);
483 }
484 }
485
Al Viroed42fe02016-01-22 19:47:47 -0500486 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400487
488 return rc;
489
490}
491
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400492/*
493 * pass attribute values back to userspace with a service operation.
494 *
495 * We have to do a memory allocation, an sscanf and a service operation.
496 * And we have to evaluate what the user entered, to make sure the
497 * value is within the range supported by the attribute. So, there's
498 * a lot of return code checking and mapping going on here.
499 *
500 * We want to return 1 if we think everything went OK, and
501 * EINVAL if not.
502 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400503static ssize_t sysfs_service_op_store(struct kobject *kobj,
504 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400505{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500506 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400507 int val = 0;
508 int rc = 0;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400509
510 gossip_debug(GOSSIP_SYSFS_DEBUG,
511 "sysfs_service_op_store: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400512 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400513
Yi Liu8bb8aef2015-11-24 15:12:14 -0500514 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500515 if (!new_op)
516 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400517
518 /* Can't do a service_operation if the client is not running... */
519 rc = is_daemon_in_service();
520 if (rc) {
521 pr_info("%s: Client not running :%d:\n",
522 __func__,
523 is_daemon_in_service());
524 goto out;
525 }
526
527 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400528 * The value we want to send back to userspace is in buf, unless this
529 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400530 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400531 if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
532 strcmp(attr->attr.name, "readahead_count_size")) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400533 rc = kstrtoint(buf, 0, &val);
534 if (rc)
535 goto out;
536 }
537
538 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400539
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400540 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400541 /* Drop unsupported requests first. */
542 if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
Martin Brandenburgb78b1192016-09-28 14:50:46 -0400543 (!strcmp(attr->attr.name, "readahead_count") ||
544 !strcmp(attr->attr.name, "readahead_size") ||
545 !strcmp(attr->attr.name, "readahead_count_size"))) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400546 rc = -EINVAL;
547 goto out;
548 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400549
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400550 if (!strcmp(attr->attr.name, "perf_history_size")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400551 if (val > 0) {
552 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500553 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400554 } else {
555 rc = 0;
556 goto out;
557 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400558 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400559 "perf_time_interval_secs")) {
560 if (val > 0) {
561 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500562 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400563 } else {
564 rc = 0;
565 goto out;
566 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400567 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400568 "perf_counter_reset")) {
569 if ((val == 0) || (val == 1)) {
570 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500571 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400572 } else {
573 rc = 0;
574 goto out;
575 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400576 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400577 "readahead_count")) {
578 if ((val >= 0)) {
579 new_op->upcall.req.param.op =
580 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
581 } else {
582 rc = 0;
583 goto out;
584 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400585 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400586 "readahead_size")) {
587 if ((val >= 0)) {
588 new_op->upcall.req.param.op =
589 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
590 } else {
591 rc = 0;
592 goto out;
593 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400594 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400595 "readahead_count_size")) {
596 int val1, val2;
597 rc = sscanf(buf, "%d %d", &val1, &val2);
598 if (rc < 2) {
599 rc = 0;
600 goto out;
601 }
602 if ((val1 >= 0) && (val2 >= 0)) {
603 new_op->upcall.req.param.op =
604 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
605 } else {
606 rc = 0;
607 goto out;
608 }
609 new_op->upcall.req.param.u.value32[0] = val1;
610 new_op->upcall.req.param.u.value32[1] = val2;
611 goto value_set;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400612 }
613
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400614 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
615 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400616 if (val > -1) {
617 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500618 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400619 } else {
620 rc = 0;
621 goto out;
622 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400623 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400624 if (val > -1) {
625 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500626 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400627 } else {
628 rc = 0;
629 goto out;
630 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400631 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400632 "reclaim_percentage")) {
633 if ((val > -1) && (val < 101)) {
634 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500635 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400636 } else {
637 rc = 0;
638 goto out;
639 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400640 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400641 if (val > -1) {
642 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500643 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400644 } else {
645 rc = 0;
646 goto out;
647 }
648 }
649
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400650 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
651 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400652 if (val > -1) {
653 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500654 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400655 } else {
656 rc = 0;
657 goto out;
658 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400659 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400660 if (val > -1) {
661 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500662 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400663 } else {
664 rc = 0;
665 goto out;
666 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400667 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400668 "reclaim_percentage")) {
669 if ((val > -1) && (val < 101)) {
670 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500671 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400672 } else {
673 rc = 0;
674 goto out;
675 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400676 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400677 if (val > -1) {
678 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500679 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400680 } else {
681 rc = 0;
682 goto out;
683 }
684 }
685
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400686 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
687 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400688 if (val > -1) {
689 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500690 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400691 } else {
692 rc = 0;
693 goto out;
694 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400695 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400696 if (val > -1) {
697 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500698 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400699 } else {
700 rc = 0;
701 goto out;
702 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400703 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400704 "reclaim_percentage")) {
705 if ((val > -1) && (val < 101)) {
706 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500707 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400708 } else {
709 rc = 0;
710 goto out;
711 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400712 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400713 if (val > -1) {
714 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500715 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400716 } else {
717 rc = 0;
718 goto out;
719 }
720 }
721
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400722 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
723 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400724 if (val > -1) {
725 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500726 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400727 } else {
728 rc = 0;
729 goto out;
730 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400731 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400732 if (val > -1) {
733 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500734 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400735 } else {
736 rc = 0;
737 goto out;
738 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400739 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400740 "reclaim_percentage")) {
741 if ((val > -1) && (val < 101)) {
742 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500743 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400744 } else {
745 rc = 0;
746 goto out;
747 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400748 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400749 if (val > -1) {
750 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500751 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400752 } else {
753 rc = 0;
754 goto out;
755 }
756 }
757
758 } else {
759 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400760 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400761 rc = -EINVAL;
762 goto out;
763 }
764
Martin Brandenburg680908e2016-08-02 16:33:34 -0400765 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400766value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400767
768 /*
769 * The service_operation will return a errno return code on
770 * error, and zero on success.
771 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500772 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400773
774 if (rc < 0) {
775 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
776 rc);
777 rc = 0;
778 } else {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400779 rc = count;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400780 }
781
782out:
Al Viroed42fe02016-01-22 19:47:47 -0500783 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400784
Al Viroed42fe02016-01-22 19:47:47 -0500785 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400786 rc = -EINVAL;
787
788 return rc;
789}
790
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400791static struct orangefs_attribute op_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400792 __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400793
794static struct orangefs_attribute slot_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400795 __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400796
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400797static struct orangefs_attribute dcache_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400798 __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400799
800static struct orangefs_attribute getattr_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400801 __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400802
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400803static struct orangefs_attribute readahead_count_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400804 __ATTR(readahead_count, 0664, sysfs_service_op_show,
805 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400806
807static struct orangefs_attribute readahead_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400808 __ATTR(readahead_size, 0664, sysfs_service_op_show,
809 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400810
811static struct orangefs_attribute readahead_count_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400812 __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
813 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400814
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400815static struct orangefs_attribute perf_counter_reset_attribute =
816 __ATTR(perf_counter_reset,
817 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400818 sysfs_service_op_show,
819 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400820
821static struct orangefs_attribute perf_history_size_attribute =
822 __ATTR(perf_history_size,
823 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400824 sysfs_service_op_show,
825 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400826
827static struct orangefs_attribute perf_time_interval_secs_attribute =
828 __ATTR(perf_time_interval_secs,
829 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400830 sysfs_service_op_show,
831 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400832
833static struct attribute *orangefs_default_attrs[] = {
834 &op_timeout_secs_attribute.attr,
835 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400836 &dcache_timeout_msecs_attribute.attr,
837 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400838 &readahead_count_attribute.attr,
839 &readahead_size_attribute.attr,
840 &readahead_count_size_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400841 &perf_counter_reset_attribute.attr,
842 &perf_history_size_attribute.attr,
843 &perf_time_interval_secs_attribute.attr,
844 NULL,
845};
846
847static struct kobj_type orangefs_ktype = {
848 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400849 .default_attrs = orangefs_default_attrs,
850};
851
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400852static struct orangefs_attribute acache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400853 __ATTR(hard_limit,
854 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400855 sysfs_service_op_show,
856 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400857
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400858static struct orangefs_attribute acache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400859 __ATTR(reclaim_percentage,
860 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400861 sysfs_service_op_show,
862 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400863
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400864static struct orangefs_attribute acache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400865 __ATTR(soft_limit,
866 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400867 sysfs_service_op_show,
868 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400869
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400870static struct orangefs_attribute acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400871 __ATTR(timeout_msecs,
872 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400873 sysfs_service_op_show,
874 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400875
876static struct attribute *acache_orangefs_default_attrs[] = {
877 &acache_hard_limit_attribute.attr,
878 &acache_reclaim_percent_attribute.attr,
879 &acache_soft_limit_attribute.attr,
880 &acache_timeout_msecs_attribute.attr,
881 NULL,
882};
883
884static struct kobj_type acache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400885 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400886 .default_attrs = acache_orangefs_default_attrs,
887};
888
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400889static struct orangefs_attribute capcache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400890 __ATTR(hard_limit,
891 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400892 sysfs_service_op_show,
893 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400894
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400895static struct orangefs_attribute capcache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400896 __ATTR(reclaim_percentage,
897 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400898 sysfs_service_op_show,
899 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400900
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400901static struct orangefs_attribute capcache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400902 __ATTR(soft_limit,
903 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400904 sysfs_service_op_show,
905 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400906
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400907static struct orangefs_attribute capcache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400908 __ATTR(timeout_secs,
909 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400910 sysfs_service_op_show,
911 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400912
913static struct attribute *capcache_orangefs_default_attrs[] = {
914 &capcache_hard_limit_attribute.attr,
915 &capcache_reclaim_percent_attribute.attr,
916 &capcache_soft_limit_attribute.attr,
917 &capcache_timeout_secs_attribute.attr,
918 NULL,
919};
920
921static struct kobj_type capcache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400922 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400923 .default_attrs = capcache_orangefs_default_attrs,
924};
925
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400926static struct orangefs_attribute ccache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400927 __ATTR(hard_limit,
928 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400929 sysfs_service_op_show,
930 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400931
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400932static struct orangefs_attribute ccache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400933 __ATTR(reclaim_percentage,
934 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400935 sysfs_service_op_show,
936 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400937
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400938static struct orangefs_attribute ccache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400939 __ATTR(soft_limit,
940 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400941 sysfs_service_op_show,
942 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400943
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400944static struct orangefs_attribute ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400945 __ATTR(timeout_secs,
946 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400947 sysfs_service_op_show,
948 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400949
950static struct attribute *ccache_orangefs_default_attrs[] = {
951 &ccache_hard_limit_attribute.attr,
952 &ccache_reclaim_percent_attribute.attr,
953 &ccache_soft_limit_attribute.attr,
954 &ccache_timeout_secs_attribute.attr,
955 NULL,
956};
957
958static struct kobj_type ccache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400959 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400960 .default_attrs = ccache_orangefs_default_attrs,
961};
962
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400963static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400964 __ATTR(hard_limit,
965 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400966 sysfs_service_op_show,
967 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400968
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400969static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400970 __ATTR(reclaim_percentage,
971 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400972 sysfs_service_op_show,
973 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400974
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400975static struct orangefs_attribute ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400976 __ATTR(soft_limit,
977 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400978 sysfs_service_op_show,
979 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400980
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400981static struct orangefs_attribute ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400982 __ATTR(timeout_msecs,
983 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400984 sysfs_service_op_show,
985 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400986
987static struct attribute *ncache_orangefs_default_attrs[] = {
988 &ncache_hard_limit_attribute.attr,
989 &ncache_reclaim_percent_attribute.attr,
990 &ncache_soft_limit_attribute.attr,
991 &ncache_timeout_msecs_attribute.attr,
992 NULL,
993};
994
995static struct kobj_type ncache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400996 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400997 .default_attrs = ncache_orangefs_default_attrs,
998};
999
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001000static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001001 __ATTR(acache,
1002 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001003 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001004 NULL);
1005
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001006static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001007 __ATTR(capcache,
1008 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001009 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001010 NULL);
1011
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001012static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001013 __ATTR(ncache,
1014 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001015 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001016 NULL);
1017
1018static struct attribute *pc_orangefs_default_attrs[] = {
1019 &pc_acache_attribute.attr,
1020 &pc_capcache_attribute.attr,
1021 &pc_ncache_attribute.attr,
1022 NULL,
1023};
1024
1025static struct kobj_type pc_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001026 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001027 .default_attrs = pc_orangefs_default_attrs,
1028};
1029
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001030static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001031 __ATTR(reads,
1032 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001033 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001034 NULL);
1035
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001036static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001037 __ATTR(writes,
1038 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001039 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001040 NULL);
1041
1042static struct attribute *stats_orangefs_default_attrs[] = {
1043 &stats_reads_attribute.attr,
1044 &stats_writes_attribute.attr,
1045 NULL,
1046};
1047
1048static struct kobj_type stats_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001049 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001050 .default_attrs = stats_orangefs_default_attrs,
1051};
1052
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001053static struct kobject *orangefs_obj;
1054static struct kobject *acache_orangefs_obj;
1055static struct kobject *capcache_orangefs_obj;
1056static struct kobject *ccache_orangefs_obj;
1057static struct kobject *ncache_orangefs_obj;
1058static struct kobject *pc_orangefs_obj;
1059static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001060
1061int orangefs_sysfs_init(void)
1062{
Mike Marshall2180c522016-03-14 15:30:39 -04001063 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001064
1065 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1066
1067 /* create /sys/fs/orangefs. */
1068 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001069 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001070 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001071
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001072 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001073 &orangefs_ktype,
1074 fs_kobj,
1075 ORANGEFS_KOBJ_ID);
1076
Mike Marshall2180c522016-03-14 15:30:39 -04001077 if (rc)
1078 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001079
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001080 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001081
1082 /* create /sys/fs/orangefs/acache. */
1083 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1084 if (!acache_orangefs_obj) {
1085 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001086 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001087 }
1088
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001089 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001090 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001091 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001092 ACACHE_KOBJ_ID);
1093
Mike Marshall2180c522016-03-14 15:30:39 -04001094 if (rc)
1095 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001096
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001097 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001098
1099 /* create /sys/fs/orangefs/capcache. */
1100 capcache_orangefs_obj =
1101 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1102 if (!capcache_orangefs_obj) {
1103 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001104 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001105 }
1106
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001107 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001108 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001109 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001110 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001111 if (rc)
1112 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001113
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001114 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001115
1116 /* create /sys/fs/orangefs/ccache. */
1117 ccache_orangefs_obj =
1118 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1119 if (!ccache_orangefs_obj) {
1120 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001121 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001122 }
1123
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001124 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001125 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001126 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001127 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001128 if (rc)
1129 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001130
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001131 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001132
1133 /* create /sys/fs/orangefs/ncache. */
1134 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1135 if (!ncache_orangefs_obj) {
1136 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001137 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001138 }
1139
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001140 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001141 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001142 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001143 NCACHE_KOBJ_ID);
1144
Mike Marshall2180c522016-03-14 15:30:39 -04001145 if (rc)
1146 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001147
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001148 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001149
1150 /* create /sys/fs/orangefs/perf_counters. */
1151 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1152 if (!pc_orangefs_obj) {
1153 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001154 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001155 }
1156
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001157 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001158 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001159 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001160 "perf_counters");
1161
Mike Marshall2180c522016-03-14 15:30:39 -04001162 if (rc)
1163 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001164
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001165 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001166
1167 /* create /sys/fs/orangefs/stats. */
1168 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1169 if (!stats_orangefs_obj) {
1170 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001171 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001172 }
1173
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001174 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001175 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001176 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001177 STATS_KOBJ_ID);
1178
Mike Marshall2180c522016-03-14 15:30:39 -04001179 if (rc)
1180 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001181
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001182 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001183 goto out;
1184
1185stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001186 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001187pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001188 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001189ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001190 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001191ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001192 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001193capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001194 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001195acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001196 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001197ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001198 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001199out:
1200 return rc;
1201}
1202
1203void orangefs_sysfs_exit(void)
1204{
1205 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001206 kobject_put(acache_orangefs_obj);
1207 kobject_put(capcache_orangefs_obj);
1208 kobject_put(ccache_orangefs_obj);
1209 kobject_put(ncache_orangefs_obj);
1210 kobject_put(pc_orangefs_obj);
1211 kobject_put(stats_orangefs_obj);
1212 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001213}