blob: 2642cb2f26b222d6c62963966bd3244059704d7a [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
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400142struct orangefs_attribute {
143 struct attribute attr;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400144 ssize_t (*show)(struct kobject *kobj,
145 struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400146 char *buf);
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400147 ssize_t (*store)(struct kobject *kobj,
148 struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400149 const char *buf,
150 size_t count);
151};
152
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400153static ssize_t orangefs_attr_show(struct kobject *kobj,
154 struct attribute *attr,
155 char *buf)
156{
157 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400158 int rc;
159
160 attribute = container_of(attr, struct orangefs_attribute, attr);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400161
162 if (!attribute->show) {
163 rc = -EIO;
164 goto out;
165 }
166
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400167 rc = attribute->show(kobj, attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400168
169out:
170 return rc;
171}
172
173static ssize_t orangefs_attr_store(struct kobject *kobj,
174 struct attribute *attr,
175 const char *buf,
176 size_t len)
177{
178 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400179 int rc;
180
181 gossip_debug(GOSSIP_SYSFS_DEBUG,
182 "orangefs_attr_store: start\n");
183
184 attribute = container_of(attr, struct orangefs_attribute, attr);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400185
186 if (!attribute->store) {
187 rc = -EIO;
188 goto out;
189 }
190
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400191 rc = attribute->store(kobj, attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400192
193out:
194 return rc;
195}
196
197static const struct sysfs_ops orangefs_sysfs_ops = {
198 .show = orangefs_attr_show,
199 .store = orangefs_attr_store,
200};
201
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400202static const struct sysfs_ops acache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400203 .show = orangefs_attr_show,
204 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400205};
206
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400207static const struct sysfs_ops capcache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400208 .show = orangefs_attr_show,
209 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400210};
211
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400212static const struct sysfs_ops ccache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400213 .show = orangefs_attr_show,
214 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400215};
216
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400217static const struct sysfs_ops ncache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400218 .show = orangefs_attr_show,
219 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400220};
221
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400222static const struct sysfs_ops pc_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400223 .show = orangefs_attr_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400224};
225
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400226static const struct sysfs_ops stats_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400227 .show = orangefs_attr_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400228};
229
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400230static ssize_t sysfs_int_show(struct kobject *kobj,
231 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400232{
233 int rc = -EIO;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400234
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400235 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
236 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400237
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400238 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
239 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400240 rc = scnprintf(buf,
241 PAGE_SIZE,
242 "%d\n",
243 op_timeout_secs);
244 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400245 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400246 "slot_timeout_secs")) {
247 rc = scnprintf(buf,
248 PAGE_SIZE,
249 "%d\n",
250 slot_timeout_secs);
251 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400252 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400253 "dcache_timeout_msecs")) {
254 rc = scnprintf(buf,
255 PAGE_SIZE,
256 "%d\n",
257 dcache_timeout_msecs);
258 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400259 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400260 "getattr_timeout_msecs")) {
261 rc = scnprintf(buf,
262 PAGE_SIZE,
263 "%d\n",
264 getattr_timeout_msecs);
265 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400266 } else {
267 goto out;
268 }
269
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400270 } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
271 if (!strcmp(attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400272 rc = scnprintf(buf,
273 PAGE_SIZE,
274 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500275 g_orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400276 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400277 } else if (!strcmp(attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400278 rc = scnprintf(buf,
279 PAGE_SIZE,
280 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500281 g_orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400282 goto out;
283 } else {
284 goto out;
285 }
286 }
287
288out:
289
290 return rc;
291}
292
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400293static ssize_t sysfs_int_store(struct kobject *kobj,
294 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400295{
296 int rc = 0;
297
298 gossip_debug(GOSSIP_SYSFS_DEBUG,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400299 "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400300 attr->attr.name, buf);
301
302 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
303 rc = kstrtoint(buf, 0, &op_timeout_secs);
304 goto out;
305 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
306 rc = kstrtoint(buf, 0, &slot_timeout_secs);
307 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400308 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
309 rc = kstrtoint(buf, 0, &dcache_timeout_msecs);
310 goto out;
311 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
312 rc = kstrtoint(buf, 0, &getattr_timeout_msecs);
313 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400314 } else {
315 goto out;
316 }
317
318out:
319 if (rc)
320 rc = -EINVAL;
321 else
322 rc = count;
323
324 return rc;
325}
326
327/*
328 * obtain attribute values from userspace with a service operation.
329 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400330static ssize_t sysfs_service_op_show(struct kobject *kobj,
331 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400332{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500333 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400334 int rc = 0;
335 char *ser_op_type = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400336 __u32 op_alloc_type;
337
338 gossip_debug(GOSSIP_SYSFS_DEBUG,
339 "sysfs_service_op_show: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400340 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400341
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400342 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500343 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400344 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500345 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400346
347 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500348 if (!new_op)
349 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400350
351 /* Can't do a service_operation if the client is not running... */
352 rc = is_daemon_in_service();
353 if (rc) {
354 pr_info("%s: Client not running :%d:\n",
355 __func__,
356 is_daemon_in_service());
357 goto out;
358 }
359
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400360 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500361 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400362
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400363 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
364 if (!strcmp(attr->attr.name, "perf_history_size"))
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_PERF_HISTORY_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400367 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400368 "perf_time_interval_secs"))
369 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500370 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400371 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400372 "perf_counter_reset"))
373 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500374 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400375
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400376 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400377 "readahead_count"))
378 new_op->upcall.req.param.op =
379 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
380
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400381 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400382 "readahead_size"))
383 new_op->upcall.req.param.op =
384 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
385
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400386 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400387 "readahead_count_size"))
388 new_op->upcall.req.param.op =
389 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400390 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
391 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400392 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500393 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400394
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400395 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400396 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500397 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400398
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400399 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400400 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500401 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400402
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400403 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400404 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500405 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400406
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400407 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
408 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400409 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500410 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400411
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400412 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400413 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500414 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400415
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400416 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400417 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500418 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400419
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400420 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400421 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500422 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400423
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400424 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
425 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400426 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500427 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400428
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400429 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400430 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500431 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400432
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400433 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400434 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500435 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400436
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400437 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400438 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500439 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400440
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400441 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
442 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400443 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500444 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400445
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400446 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400447 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500448 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400449
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400450 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400451 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500452 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400453
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400454 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400455 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500456 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400457
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400458 } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
459 if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400460 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500461 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400462
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400463 if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400464 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500465 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400466
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400467 if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400468 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500469 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400470
471 } else {
472 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400473 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400474 rc = -EINVAL;
475 goto out;
476 }
477
478
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400479 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500480 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400481 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500482 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400483
484 /*
485 * The service_operation will return an errno return code on
486 * error, and zero on success.
487 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500488 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400489
490out:
491 if (!rc) {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400492 if (strcmp(kobj->name, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400493 if (new_op->upcall.req.param.op ==
494 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
495 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
496 (int)new_op->downcall.resp.param.u.
497 value32[0],
498 (int)new_op->downcall.resp.param.u.
499 value32[1]);
500 } else {
501 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
502 (int)new_op->downcall.resp.param.u.value64);
503 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400504 } else {
505 rc = scnprintf(
506 buf,
507 PAGE_SIZE,
508 "%s",
509 new_op->downcall.resp.perf_count.buffer);
510 }
511 }
512
Al Viroed42fe02016-01-22 19:47:47 -0500513 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400514
515 return rc;
516
517}
518
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400519/*
520 * pass attribute values back to userspace with a service operation.
521 *
522 * We have to do a memory allocation, an sscanf and a service operation.
523 * And we have to evaluate what the user entered, to make sure the
524 * value is within the range supported by the attribute. So, there's
525 * a lot of return code checking and mapping going on here.
526 *
527 * We want to return 1 if we think everything went OK, and
528 * EINVAL if not.
529 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400530static ssize_t sysfs_service_op_store(struct kobject *kobj,
531 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400532{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500533 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400534 int val = 0;
535 int rc = 0;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400536
537 gossip_debug(GOSSIP_SYSFS_DEBUG,
538 "sysfs_service_op_store: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400539 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400540
Yi Liu8bb8aef2015-11-24 15:12:14 -0500541 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500542 if (!new_op)
543 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400544
545 /* Can't do a service_operation if the client is not running... */
546 rc = is_daemon_in_service();
547 if (rc) {
548 pr_info("%s: Client not running :%d:\n",
549 __func__,
550 is_daemon_in_service());
551 goto out;
552 }
553
554 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400555 * The value we want to send back to userspace is in buf, unless this
556 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400557 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400558 if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
559 strcmp(attr->attr.name, "readahead_count_size")) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400560 rc = kstrtoint(buf, 0, &val);
561 if (rc)
562 goto out;
563 }
564
565 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400566
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400567 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
568 if (!strcmp(attr->attr.name, "perf_history_size")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400569 if (val > 0) {
570 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500571 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
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,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400577 "perf_time_interval_secs")) {
578 if (val > 0) {
579 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500580 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400581 } else {
582 rc = 0;
583 goto out;
584 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400585 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400586 "perf_counter_reset")) {
587 if ((val == 0) || (val == 1)) {
588 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500589 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400590 } 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")) {
596 if ((val >= 0)) {
597 new_op->upcall.req.param.op =
598 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
599 } else {
600 rc = 0;
601 goto out;
602 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400603 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400604 "readahead_size")) {
605 if ((val >= 0)) {
606 new_op->upcall.req.param.op =
607 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
608 } else {
609 rc = 0;
610 goto out;
611 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400612 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400613 "readahead_count_size")) {
614 int val1, val2;
615 rc = sscanf(buf, "%d %d", &val1, &val2);
616 if (rc < 2) {
617 rc = 0;
618 goto out;
619 }
620 if ((val1 >= 0) && (val2 >= 0)) {
621 new_op->upcall.req.param.op =
622 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
623 } else {
624 rc = 0;
625 goto out;
626 }
627 new_op->upcall.req.param.u.value32[0] = val1;
628 new_op->upcall.req.param.u.value32[1] = val2;
629 goto value_set;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400630 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400631 "perf_counter_reset")) {
632 if ((val > 0)) {
633 new_op->upcall.req.param.op =
634 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
635 } else {
636 rc = 0;
637 goto out;
638 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400639 }
640
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400641 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
642 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400643 if (val > -1) {
644 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500645 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400646 } else {
647 rc = 0;
648 goto out;
649 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400650 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400651 if (val > -1) {
652 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500653 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400654 } else {
655 rc = 0;
656 goto out;
657 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400658 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400659 "reclaim_percentage")) {
660 if ((val > -1) && (val < 101)) {
661 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500662 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
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, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400668 if (val > -1) {
669 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500670 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400671 } else {
672 rc = 0;
673 goto out;
674 }
675 }
676
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400677 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
678 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400679 if (val > -1) {
680 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500681 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400682 } else {
683 rc = 0;
684 goto out;
685 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400686 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400687 if (val > -1) {
688 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500689 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400690 } else {
691 rc = 0;
692 goto out;
693 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400694 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400695 "reclaim_percentage")) {
696 if ((val > -1) && (val < 101)) {
697 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500698 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
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, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400704 if (val > -1) {
705 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500706 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400707 } else {
708 rc = 0;
709 goto out;
710 }
711 }
712
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400713 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
714 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400715 if (val > -1) {
716 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500717 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400718 } else {
719 rc = 0;
720 goto out;
721 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400722 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400723 if (val > -1) {
724 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500725 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400726 } else {
727 rc = 0;
728 goto out;
729 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400730 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400731 "reclaim_percentage")) {
732 if ((val > -1) && (val < 101)) {
733 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500734 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
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, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400740 if (val > -1) {
741 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500742 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400743 } else {
744 rc = 0;
745 goto out;
746 }
747 }
748
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400749 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
750 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400751 if (val > -1) {
752 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500753 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400754 } else {
755 rc = 0;
756 goto out;
757 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400758 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400759 if (val > -1) {
760 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500761 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400762 } else {
763 rc = 0;
764 goto out;
765 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400766 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400767 "reclaim_percentage")) {
768 if ((val > -1) && (val < 101)) {
769 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500770 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400771 } else {
772 rc = 0;
773 goto out;
774 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400775 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400776 if (val > -1) {
777 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500778 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400779 } else {
780 rc = 0;
781 goto out;
782 }
783 }
784
785 } else {
786 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400787 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400788 rc = -EINVAL;
789 goto out;
790 }
791
Martin Brandenburg680908e2016-08-02 16:33:34 -0400792 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400793value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400794
795 /*
796 * The service_operation will return a errno return code on
797 * error, and zero on success.
798 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500799 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400800
801 if (rc < 0) {
802 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
803 rc);
804 rc = 0;
805 } else {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400806 rc = count;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400807 }
808
809out:
Al Viroed42fe02016-01-22 19:47:47 -0500810 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400811
Al Viroed42fe02016-01-22 19:47:47 -0500812 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400813 rc = -EINVAL;
814
815 return rc;
816}
817
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400818static struct orangefs_attribute op_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400819 __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400820
821static struct orangefs_attribute slot_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400822 __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400823
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400824static struct orangefs_attribute dcache_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400825 __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400826
827static struct orangefs_attribute getattr_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400828 __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400829
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400830static struct orangefs_attribute readahead_count_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400831 __ATTR(readahead_count, 0664, sysfs_service_op_show,
832 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400833
834static struct orangefs_attribute readahead_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400835 __ATTR(readahead_size, 0664, sysfs_service_op_show,
836 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400837
838static struct orangefs_attribute readahead_count_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400839 __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
840 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400841
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400842static struct orangefs_attribute perf_counter_reset_attribute =
843 __ATTR(perf_counter_reset,
844 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400845 sysfs_service_op_show,
846 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400847
848static struct orangefs_attribute perf_history_size_attribute =
849 __ATTR(perf_history_size,
850 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400851 sysfs_service_op_show,
852 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400853
854static struct orangefs_attribute perf_time_interval_secs_attribute =
855 __ATTR(perf_time_interval_secs,
856 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400857 sysfs_service_op_show,
858 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400859
860static struct attribute *orangefs_default_attrs[] = {
861 &op_timeout_secs_attribute.attr,
862 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400863 &dcache_timeout_msecs_attribute.attr,
864 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400865 &readahead_count_attribute.attr,
866 &readahead_size_attribute.attr,
867 &readahead_count_size_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400868 &perf_counter_reset_attribute.attr,
869 &perf_history_size_attribute.attr,
870 &perf_time_interval_secs_attribute.attr,
871 NULL,
872};
873
874static struct kobj_type orangefs_ktype = {
875 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400876 .default_attrs = orangefs_default_attrs,
877};
878
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400879static struct orangefs_attribute acache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400880 __ATTR(hard_limit,
881 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400882 sysfs_service_op_show,
883 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400884
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400885static struct orangefs_attribute acache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400886 __ATTR(reclaim_percentage,
887 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400888 sysfs_service_op_show,
889 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400890
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400891static struct orangefs_attribute acache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400892 __ATTR(soft_limit,
893 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400894 sysfs_service_op_show,
895 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400896
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400897static struct orangefs_attribute acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400898 __ATTR(timeout_msecs,
899 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400900 sysfs_service_op_show,
901 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400902
903static struct attribute *acache_orangefs_default_attrs[] = {
904 &acache_hard_limit_attribute.attr,
905 &acache_reclaim_percent_attribute.attr,
906 &acache_soft_limit_attribute.attr,
907 &acache_timeout_msecs_attribute.attr,
908 NULL,
909};
910
911static struct kobj_type acache_orangefs_ktype = {
912 .sysfs_ops = &acache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400913 .default_attrs = acache_orangefs_default_attrs,
914};
915
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400916static struct orangefs_attribute capcache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400917 __ATTR(hard_limit,
918 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400919 sysfs_service_op_show,
920 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400921
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400922static struct orangefs_attribute capcache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400923 __ATTR(reclaim_percentage,
924 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400925 sysfs_service_op_show,
926 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400927
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400928static struct orangefs_attribute capcache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400929 __ATTR(soft_limit,
930 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400931 sysfs_service_op_show,
932 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400933
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400934static struct orangefs_attribute capcache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400935 __ATTR(timeout_secs,
936 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400937 sysfs_service_op_show,
938 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400939
940static struct attribute *capcache_orangefs_default_attrs[] = {
941 &capcache_hard_limit_attribute.attr,
942 &capcache_reclaim_percent_attribute.attr,
943 &capcache_soft_limit_attribute.attr,
944 &capcache_timeout_secs_attribute.attr,
945 NULL,
946};
947
948static struct kobj_type capcache_orangefs_ktype = {
949 .sysfs_ops = &capcache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400950 .default_attrs = capcache_orangefs_default_attrs,
951};
952
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400953static struct orangefs_attribute ccache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400954 __ATTR(hard_limit,
955 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400956 sysfs_service_op_show,
957 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400958
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400959static struct orangefs_attribute ccache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400960 __ATTR(reclaim_percentage,
961 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400962 sysfs_service_op_show,
963 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400964
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400965static struct orangefs_attribute ccache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400966 __ATTR(soft_limit,
967 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400968 sysfs_service_op_show,
969 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400970
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400971static struct orangefs_attribute ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400972 __ATTR(timeout_secs,
973 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400974 sysfs_service_op_show,
975 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400976
977static struct attribute *ccache_orangefs_default_attrs[] = {
978 &ccache_hard_limit_attribute.attr,
979 &ccache_reclaim_percent_attribute.attr,
980 &ccache_soft_limit_attribute.attr,
981 &ccache_timeout_secs_attribute.attr,
982 NULL,
983};
984
985static struct kobj_type ccache_orangefs_ktype = {
986 .sysfs_ops = &ccache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400987 .default_attrs = ccache_orangefs_default_attrs,
988};
989
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400990static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400991 __ATTR(hard_limit,
992 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400993 sysfs_service_op_show,
994 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400995
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400996static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400997 __ATTR(reclaim_percentage,
998 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400999 sysfs_service_op_show,
1000 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001001
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001002static struct orangefs_attribute ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001003 __ATTR(soft_limit,
1004 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001005 sysfs_service_op_show,
1006 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001007
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001008static struct orangefs_attribute ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001009 __ATTR(timeout_msecs,
1010 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001011 sysfs_service_op_show,
1012 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001013
1014static struct attribute *ncache_orangefs_default_attrs[] = {
1015 &ncache_hard_limit_attribute.attr,
1016 &ncache_reclaim_percent_attribute.attr,
1017 &ncache_soft_limit_attribute.attr,
1018 &ncache_timeout_msecs_attribute.attr,
1019 NULL,
1020};
1021
1022static struct kobj_type ncache_orangefs_ktype = {
1023 .sysfs_ops = &ncache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001024 .default_attrs = ncache_orangefs_default_attrs,
1025};
1026
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001027static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001028 __ATTR(acache,
1029 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001030 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001031 NULL);
1032
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001033static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001034 __ATTR(capcache,
1035 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001036 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001037 NULL);
1038
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001039static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001040 __ATTR(ncache,
1041 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001042 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001043 NULL);
1044
1045static struct attribute *pc_orangefs_default_attrs[] = {
1046 &pc_acache_attribute.attr,
1047 &pc_capcache_attribute.attr,
1048 &pc_ncache_attribute.attr,
1049 NULL,
1050};
1051
1052static struct kobj_type pc_orangefs_ktype = {
1053 .sysfs_ops = &pc_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001054 .default_attrs = pc_orangefs_default_attrs,
1055};
1056
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001057static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001058 __ATTR(reads,
1059 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001060 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001061 NULL);
1062
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001063static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001064 __ATTR(writes,
1065 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001066 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001067 NULL);
1068
1069static struct attribute *stats_orangefs_default_attrs[] = {
1070 &stats_reads_attribute.attr,
1071 &stats_writes_attribute.attr,
1072 NULL,
1073};
1074
1075static struct kobj_type stats_orangefs_ktype = {
1076 .sysfs_ops = &stats_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001077 .default_attrs = stats_orangefs_default_attrs,
1078};
1079
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001080static struct kobject *orangefs_obj;
1081static struct kobject *acache_orangefs_obj;
1082static struct kobject *capcache_orangefs_obj;
1083static struct kobject *ccache_orangefs_obj;
1084static struct kobject *ncache_orangefs_obj;
1085static struct kobject *pc_orangefs_obj;
1086static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001087
1088int orangefs_sysfs_init(void)
1089{
Mike Marshall2180c522016-03-14 15:30:39 -04001090 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001091
1092 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1093
1094 /* create /sys/fs/orangefs. */
1095 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001096 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001097 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001098
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001099 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001100 &orangefs_ktype,
1101 fs_kobj,
1102 ORANGEFS_KOBJ_ID);
1103
Mike Marshall2180c522016-03-14 15:30:39 -04001104 if (rc)
1105 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001106
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001107 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001108
1109 /* create /sys/fs/orangefs/acache. */
1110 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1111 if (!acache_orangefs_obj) {
1112 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001113 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001114 }
1115
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001116 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001117 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001118 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001119 ACACHE_KOBJ_ID);
1120
Mike Marshall2180c522016-03-14 15:30:39 -04001121 if (rc)
1122 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001123
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001124 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001125
1126 /* create /sys/fs/orangefs/capcache. */
1127 capcache_orangefs_obj =
1128 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1129 if (!capcache_orangefs_obj) {
1130 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001131 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001132 }
1133
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001134 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001135 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001136 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001137 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001138 if (rc)
1139 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001140
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001141 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001142
1143 /* create /sys/fs/orangefs/ccache. */
1144 ccache_orangefs_obj =
1145 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1146 if (!ccache_orangefs_obj) {
1147 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001148 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001149 }
1150
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001151 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001152 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001153 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001154 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001155 if (rc)
1156 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001157
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001158 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001159
1160 /* create /sys/fs/orangefs/ncache. */
1161 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1162 if (!ncache_orangefs_obj) {
1163 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001164 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001165 }
1166
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001167 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001168 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001169 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001170 NCACHE_KOBJ_ID);
1171
Mike Marshall2180c522016-03-14 15:30:39 -04001172 if (rc)
1173 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001174
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001175 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001176
1177 /* create /sys/fs/orangefs/perf_counters. */
1178 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1179 if (!pc_orangefs_obj) {
1180 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001181 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001182 }
1183
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001184 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001185 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001186 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001187 "perf_counters");
1188
Mike Marshall2180c522016-03-14 15:30:39 -04001189 if (rc)
1190 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001191
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001192 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001193
1194 /* create /sys/fs/orangefs/stats. */
1195 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1196 if (!stats_orangefs_obj) {
1197 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001198 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001199 }
1200
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001201 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001202 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001203 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001204 STATS_KOBJ_ID);
1205
Mike Marshall2180c522016-03-14 15:30:39 -04001206 if (rc)
1207 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001208
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001209 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001210 goto out;
1211
1212stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001213 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001214pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001215 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001216ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001217 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001218ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001219 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001220capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001221 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001222acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001223 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001224ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001225 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001226out:
1227 return rc;
1228}
1229
1230void orangefs_sysfs_exit(void)
1231{
1232 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001233 kobject_put(acache_orangefs_obj);
1234 kobject_put(capcache_orangefs_obj);
1235 kobject_put(ccache_orangefs_obj);
1236 kobject_put(ncache_orangefs_obj);
1237 kobject_put(pc_orangefs_obj);
1238 kobject_put(stats_orangefs_obj);
1239 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001240}