blob: 6cbc2468f5ba42851d3b84c77a6c898d5ad69236 [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 Brandenburgdc3012a2016-08-15 13:28:51 -0400144 ssize_t (*show)(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400145 char *buf);
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400146 ssize_t (*store)(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400147 const char *buf,
148 size_t count);
149};
150
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400151static ssize_t orangefs_attr_show(struct kobject *kobj,
152 struct attribute *attr,
153 char *buf)
154{
155 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400156 int rc;
157
158 attribute = container_of(attr, struct orangefs_attribute, attr);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400159
160 if (!attribute->show) {
161 rc = -EIO;
162 goto out;
163 }
164
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400165 rc = attribute->show(attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400166
167out:
168 return rc;
169}
170
171static ssize_t orangefs_attr_store(struct kobject *kobj,
172 struct attribute *attr,
173 const char *buf,
174 size_t len)
175{
176 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400177 int rc;
178
179 gossip_debug(GOSSIP_SYSFS_DEBUG,
180 "orangefs_attr_store: start\n");
181
182 attribute = container_of(attr, struct orangefs_attribute, attr);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400183
184 if (!attribute->store) {
185 rc = -EIO;
186 goto out;
187 }
188
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400189 rc = attribute->store(attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400190
191out:
192 return rc;
193}
194
195static const struct sysfs_ops orangefs_sysfs_ops = {
196 .show = orangefs_attr_show,
197 .store = orangefs_attr_store,
198};
199
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400200static const struct sysfs_ops acache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400201 .show = orangefs_attr_show,
202 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400203};
204
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400205static const struct sysfs_ops capcache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400206 .show = orangefs_attr_show,
207 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400208};
209
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400210static const struct sysfs_ops ccache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400211 .show = orangefs_attr_show,
212 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400213};
214
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400215static const struct sysfs_ops ncache_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400216 .show = orangefs_attr_show,
217 .store = orangefs_attr_store,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400218};
219
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400220static const struct sysfs_ops pc_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400221 .show = orangefs_attr_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400222};
223
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400224static const struct sysfs_ops stats_orangefs_sysfs_ops = {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400225 .show = orangefs_attr_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400226};
227
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400228static ssize_t sysfs_int_show(char *kobj_id, char *buf, void *attr)
229{
230 int rc = -EIO;
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400231 struct orangefs_attribute *orangefs_attr = attr;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400232
233 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n", kobj_id);
234
235 if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400236 if (!strcmp(orangefs_attr->attr.name, "op_timeout_secs")) {
237 rc = scnprintf(buf,
238 PAGE_SIZE,
239 "%d\n",
240 op_timeout_secs);
241 goto out;
242 } else if (!strcmp(orangefs_attr->attr.name,
243 "slot_timeout_secs")) {
244 rc = scnprintf(buf,
245 PAGE_SIZE,
246 "%d\n",
247 slot_timeout_secs);
248 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400249 } else if (!strcmp(orangefs_attr->attr.name,
250 "dcache_timeout_msecs")) {
251 rc = scnprintf(buf,
252 PAGE_SIZE,
253 "%d\n",
254 dcache_timeout_msecs);
255 goto out;
256 } else if (!strcmp(orangefs_attr->attr.name,
257 "getattr_timeout_msecs")) {
258 rc = scnprintf(buf,
259 PAGE_SIZE,
260 "%d\n",
261 getattr_timeout_msecs);
262 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400263 } else {
264 goto out;
265 }
266
267 } else if (!strcmp(kobj_id, STATS_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400268 if (!strcmp(orangefs_attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400269 rc = scnprintf(buf,
270 PAGE_SIZE,
271 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500272 g_orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400273 goto out;
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400274 } else if (!strcmp(orangefs_attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400275 rc = scnprintf(buf,
276 PAGE_SIZE,
277 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500278 g_orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400279 goto out;
280 } else {
281 goto out;
282 }
283 }
284
285out:
286
287 return rc;
288}
289
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400290static ssize_t int_orangefs_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400291 char *buf)
292{
293 int rc;
294
295 gossip_debug(GOSSIP_SYSFS_DEBUG,
296 "int_orangefs_show:start attr->attr.name:%s:\n",
297 attr->attr.name);
298
299 rc = sysfs_int_show(ORANGEFS_KOBJ_ID, buf, (void *) attr);
300
301 return rc;
302}
303
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400304static ssize_t int_stats_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400305 char *buf)
306{
307 int rc;
308
309 gossip_debug(GOSSIP_SYSFS_DEBUG,
310 "int_stats_show:start attr->attr.name:%s:\n",
311 attr->attr.name);
312
313 rc = sysfs_int_show(STATS_KOBJ_ID, buf, (void *) attr);
314
315 return rc;
316}
317
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400318static ssize_t int_store(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400319 const char *buf,
320 size_t count)
321{
322 int rc = 0;
323
324 gossip_debug(GOSSIP_SYSFS_DEBUG,
325 "int_store: start attr->attr.name:%s: buf:%s:\n",
326 attr->attr.name, buf);
327
328 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
329 rc = kstrtoint(buf, 0, &op_timeout_secs);
330 goto out;
331 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
332 rc = kstrtoint(buf, 0, &slot_timeout_secs);
333 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400334 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
335 rc = kstrtoint(buf, 0, &dcache_timeout_msecs);
336 goto out;
337 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
338 rc = kstrtoint(buf, 0, &getattr_timeout_msecs);
339 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400340 } else {
341 goto out;
342 }
343
344out:
345 if (rc)
346 rc = -EINVAL;
347 else
348 rc = count;
349
350 return rc;
351}
352
353/*
354 * obtain attribute values from userspace with a service operation.
355 */
Mike Marshall84d02152015-07-28 13:27:51 -0400356static int sysfs_service_op_show(char *kobj_id, char *buf, void *attr)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400357{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500358 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400359 int rc = 0;
360 char *ser_op_type = NULL;
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400361 struct orangefs_attribute *orangefs_attr = attr;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400362 __u32 op_alloc_type;
363
364 gossip_debug(GOSSIP_SYSFS_DEBUG,
365 "sysfs_service_op_show: id:%s:\n",
366 kobj_id);
367
368 if (strcmp(kobj_id, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500369 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400370 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500371 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400372
373 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500374 if (!new_op)
375 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400376
377 /* Can't do a service_operation if the client is not running... */
378 rc = is_daemon_in_service();
379 if (rc) {
380 pr_info("%s: Client not running :%d:\n",
381 __func__,
382 is_daemon_in_service());
383 goto out;
384 }
385
386 if (strcmp(kobj_id, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500387 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400388
389 if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400390 if (!strcmp(orangefs_attr->attr.name, "perf_history_size"))
391 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500392 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400393 else if (!strcmp(orangefs_attr->attr.name,
394 "perf_time_interval_secs"))
395 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500396 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400397 else if (!strcmp(orangefs_attr->attr.name,
398 "perf_counter_reset"))
399 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500400 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400401
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400402 else if (!strcmp(orangefs_attr->attr.name,
403 "readahead_count"))
404 new_op->upcall.req.param.op =
405 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
406
407 else if (!strcmp(orangefs_attr->attr.name,
408 "readahead_size"))
409 new_op->upcall.req.param.op =
410 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
411
412 else if (!strcmp(orangefs_attr->attr.name,
413 "readahead_count_size"))
414 new_op->upcall.req.param.op =
415 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400416 } else if (!strcmp(kobj_id, ACACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400417 if (!strcmp(orangefs_attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400418 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500419 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400420
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400421 if (!strcmp(orangefs_attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400422 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500423 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400424
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400425 if (!strcmp(orangefs_attr->attr.name, "soft_limit"))
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_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400428
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400429 if (!strcmp(orangefs_attr->attr.name, "reclaim_percentage"))
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_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400432
433 } else if (!strcmp(kobj_id, CAPCACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400434 if (!strcmp(orangefs_attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400435 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500436 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400437
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400438 if (!strcmp(orangefs_attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400439 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500440 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400441
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400442 if (!strcmp(orangefs_attr->attr.name, "soft_limit"))
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_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400445
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400446 if (!strcmp(orangefs_attr->attr.name, "reclaim_percentage"))
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_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400449
450 } else if (!strcmp(kobj_id, CCACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400451 if (!strcmp(orangefs_attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400452 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500453 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400454
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400455 if (!strcmp(orangefs_attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400456 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500457 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400458
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400459 if (!strcmp(orangefs_attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400460 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500461 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400462
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400463 if (!strcmp(orangefs_attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400464 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500465 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400466
467 } else if (!strcmp(kobj_id, NCACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400468 if (!strcmp(orangefs_attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400469 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500470 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400471
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400472 if (!strcmp(orangefs_attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400473 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500474 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400475
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400476 if (!strcmp(orangefs_attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400477 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500478 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400479
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400480 if (!strcmp(orangefs_attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400481 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500482 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400483
484 } else if (!strcmp(kobj_id, PC_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400485 if (!strcmp(orangefs_attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400486 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500487 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400488
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400489 if (!strcmp(orangefs_attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400490 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500491 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400492
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400493 if (!strcmp(orangefs_attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400494 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500495 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400496
497 } else {
498 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
499 kobj_id);
500 rc = -EINVAL;
501 goto out;
502 }
503
504
505 if (strcmp(kobj_id, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500506 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400507 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500508 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400509
510 /*
511 * The service_operation will return an errno return code on
512 * error, and zero on success.
513 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500514 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400515
516out:
517 if (!rc) {
518 if (strcmp(kobj_id, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400519 if (new_op->upcall.req.param.op ==
520 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
521 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
522 (int)new_op->downcall.resp.param.u.
523 value32[0],
524 (int)new_op->downcall.resp.param.u.
525 value32[1]);
526 } else {
527 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
528 (int)new_op->downcall.resp.param.u.value64);
529 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400530 } else {
531 rc = scnprintf(
532 buf,
533 PAGE_SIZE,
534 "%s",
535 new_op->downcall.resp.perf_count.buffer);
536 }
537 }
538
Al Viroed42fe02016-01-22 19:47:47 -0500539 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400540
541 return rc;
542
543}
544
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400545static ssize_t service_orangefs_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400546 char *buf)
547{
548 int rc = 0;
549
550 rc = sysfs_service_op_show(ORANGEFS_KOBJ_ID, buf, (void *)attr);
551
552 return rc;
553}
554
555static ssize_t
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400556 service_acache_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400557 char *buf)
558{
559 int rc = 0;
560
561 rc = sysfs_service_op_show(ACACHE_KOBJ_ID, buf, (void *)attr);
562
563 return rc;
564}
565
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400566static ssize_t service_capcache_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400567 char *buf)
568{
569 int rc = 0;
570
571 rc = sysfs_service_op_show(CAPCACHE_KOBJ_ID, buf, (void *)attr);
572
573 return rc;
574}
575
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400576static ssize_t service_ccache_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400577 char *buf)
578{
579 int rc = 0;
580
581 rc = sysfs_service_op_show(CCACHE_KOBJ_ID, buf, (void *)attr);
582
583 return rc;
584}
585
586static ssize_t
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400587 service_ncache_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400588 char *buf)
589{
590 int rc = 0;
591
592 rc = sysfs_service_op_show(NCACHE_KOBJ_ID, buf, (void *)attr);
593
594 return rc;
595}
596
597static ssize_t
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400598 service_pc_show(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400599 char *buf)
600{
601 int rc = 0;
602
603 rc = sysfs_service_op_show(PC_KOBJ_ID, buf, (void *)attr);
604
605 return rc;
606}
607
608/*
609 * pass attribute values back to userspace with a service operation.
610 *
611 * We have to do a memory allocation, an sscanf and a service operation.
612 * And we have to evaluate what the user entered, to make sure the
613 * value is within the range supported by the attribute. So, there's
614 * a lot of return code checking and mapping going on here.
615 *
616 * We want to return 1 if we think everything went OK, and
617 * EINVAL if not.
618 */
Mike Marshall84d02152015-07-28 13:27:51 -0400619static int sysfs_service_op_store(char *kobj_id, const char *buf, void *attr)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400620{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500621 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400622 int val = 0;
623 int rc = 0;
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400624 struct orangefs_attribute *orangefs_attr = attr;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400625
626 gossip_debug(GOSSIP_SYSFS_DEBUG,
627 "sysfs_service_op_store: id:%s:\n",
628 kobj_id);
629
Yi Liu8bb8aef2015-11-24 15:12:14 -0500630 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500631 if (!new_op)
632 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400633
634 /* Can't do a service_operation if the client is not running... */
635 rc = is_daemon_in_service();
636 if (rc) {
637 pr_info("%s: Client not running :%d:\n",
638 __func__,
639 is_daemon_in_service());
640 goto out;
641 }
642
643 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400644 * The value we want to send back to userspace is in buf, unless this
645 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400646 */
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400647 if (strcmp(kobj_id, ORANGEFS_KOBJ_ID) ||
648 strcmp(((struct orangefs_attribute *)attr)->attr.name,
649 "readahead_count_size")) {
650 rc = kstrtoint(buf, 0, &val);
651 if (rc)
652 goto out;
653 }
654
655 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400656
657 if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400658 if (!strcmp(orangefs_attr->attr.name, "perf_history_size")) {
659 if (val > 0) {
660 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500661 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400662 } else {
663 rc = 0;
664 goto out;
665 }
666 } else if (!strcmp(orangefs_attr->attr.name,
667 "perf_time_interval_secs")) {
668 if (val > 0) {
669 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500670 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400671 } else {
672 rc = 0;
673 goto out;
674 }
675 } else if (!strcmp(orangefs_attr->attr.name,
676 "perf_counter_reset")) {
677 if ((val == 0) || (val == 1)) {
678 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500679 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400680 } else {
681 rc = 0;
682 goto out;
683 }
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400684 } else if (!strcmp(orangefs_attr->attr.name,
685 "readahead_count")) {
686 if ((val >= 0)) {
687 new_op->upcall.req.param.op =
688 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
689 } else {
690 rc = 0;
691 goto out;
692 }
693 } else if (!strcmp(orangefs_attr->attr.name,
694 "readahead_size")) {
695 if ((val >= 0)) {
696 new_op->upcall.req.param.op =
697 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
698 } else {
699 rc = 0;
700 goto out;
701 }
702 } else if (!strcmp(orangefs_attr->attr.name,
703 "readahead_count_size")) {
704 int val1, val2;
705 rc = sscanf(buf, "%d %d", &val1, &val2);
706 if (rc < 2) {
707 rc = 0;
708 goto out;
709 }
710 if ((val1 >= 0) && (val2 >= 0)) {
711 new_op->upcall.req.param.op =
712 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
713 } else {
714 rc = 0;
715 goto out;
716 }
717 new_op->upcall.req.param.u.value32[0] = val1;
718 new_op->upcall.req.param.u.value32[1] = val2;
719 goto value_set;
720 } else if (!strcmp(orangefs_attr->attr.name,
721 "perf_counter_reset")) {
722 if ((val > 0)) {
723 new_op->upcall.req.param.op =
724 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
725 } else {
726 rc = 0;
727 goto out;
728 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400729 }
730
731 } else if (!strcmp(kobj_id, ACACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400732 if (!strcmp(orangefs_attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400733 if (val > -1) {
734 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500735 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400736 } else {
737 rc = 0;
738 goto out;
739 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400740 } else if (!strcmp(orangefs_attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400741 if (val > -1) {
742 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500743 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400744 } else {
745 rc = 0;
746 goto out;
747 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400748 } else if (!strcmp(orangefs_attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400749 "reclaim_percentage")) {
750 if ((val > -1) && (val < 101)) {
751 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500752 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400753 } else {
754 rc = 0;
755 goto out;
756 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400757 } else if (!strcmp(orangefs_attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400758 if (val > -1) {
759 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500760 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400761 } else {
762 rc = 0;
763 goto out;
764 }
765 }
766
767 } else if (!strcmp(kobj_id, CAPCACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400768 if (!strcmp(orangefs_attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400769 if (val > -1) {
770 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500771 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400772 } else {
773 rc = 0;
774 goto out;
775 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400776 } else if (!strcmp(orangefs_attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400777 if (val > -1) {
778 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500779 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400780 } else {
781 rc = 0;
782 goto out;
783 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400784 } else if (!strcmp(orangefs_attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400785 "reclaim_percentage")) {
786 if ((val > -1) && (val < 101)) {
787 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500788 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400789 } else {
790 rc = 0;
791 goto out;
792 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400793 } else if (!strcmp(orangefs_attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400794 if (val > -1) {
795 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500796 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400797 } else {
798 rc = 0;
799 goto out;
800 }
801 }
802
803 } else if (!strcmp(kobj_id, CCACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400804 if (!strcmp(orangefs_attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400805 if (val > -1) {
806 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500807 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400808 } else {
809 rc = 0;
810 goto out;
811 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400812 } else if (!strcmp(orangefs_attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400813 if (val > -1) {
814 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500815 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400816 } else {
817 rc = 0;
818 goto out;
819 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400820 } else if (!strcmp(orangefs_attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400821 "reclaim_percentage")) {
822 if ((val > -1) && (val < 101)) {
823 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500824 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400825 } else {
826 rc = 0;
827 goto out;
828 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400829 } else if (!strcmp(orangefs_attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400830 if (val > -1) {
831 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500832 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400833 } else {
834 rc = 0;
835 goto out;
836 }
837 }
838
839 } else if (!strcmp(kobj_id, NCACHE_KOBJ_ID)) {
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400840 if (!strcmp(orangefs_attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400841 if (val > -1) {
842 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500843 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400844 } else {
845 rc = 0;
846 goto out;
847 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400848 } else if (!strcmp(orangefs_attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400849 if (val > -1) {
850 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500851 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400852 } else {
853 rc = 0;
854 goto out;
855 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400856 } else if (!strcmp(orangefs_attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400857 "reclaim_percentage")) {
858 if ((val > -1) && (val < 101)) {
859 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500860 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400861 } else {
862 rc = 0;
863 goto out;
864 }
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400865 } else if (!strcmp(orangefs_attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400866 if (val > -1) {
867 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500868 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400869 } else {
870 rc = 0;
871 goto out;
872 }
873 }
874
875 } else {
876 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
877 kobj_id);
878 rc = -EINVAL;
879 goto out;
880 }
881
Martin Brandenburg680908e2016-08-02 16:33:34 -0400882 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400883value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400884
885 /*
886 * The service_operation will return a errno return code on
887 * error, and zero on success.
888 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500889 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400890
891 if (rc < 0) {
892 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
893 rc);
894 rc = 0;
895 } else {
896 rc = 1;
897 }
898
899out:
Al Viroed42fe02016-01-22 19:47:47 -0500900 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400901
Al Viroed42fe02016-01-22 19:47:47 -0500902 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400903 rc = -EINVAL;
904
905 return rc;
906}
907
908static ssize_t
Martin Brandenburgdc3012a2016-08-15 13:28:51 -0400909 service_orangefs_store(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400910 const char *buf,
911 size_t count)
912{
913 int rc = 0;
914
915 rc = sysfs_service_op_store(ORANGEFS_KOBJ_ID, buf, (void *) attr);
916
917 /* rc should have an errno value if the service_op went bad. */
918 if (rc == 1)
919 rc = count;
920
921 return rc;
922}
923
924static ssize_t
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400925 service_acache_store(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400926 const char *buf,
927 size_t count)
928{
929 int rc = 0;
930
931 rc = sysfs_service_op_store(ACACHE_KOBJ_ID, buf, (void *) attr);
932
933 /* rc should have an errno value if the service_op went bad. */
934 if (rc == 1)
935 rc = count;
936
937 return rc;
938}
939
940static ssize_t
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400941 service_capcache_store(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400942 const char *buf,
943 size_t count)
944{
945 int rc = 0;
946
947 rc = sysfs_service_op_store(CAPCACHE_KOBJ_ID, buf, (void *) attr);
948
949 /* rc should have an errno value if the service_op went bad. */
950 if (rc == 1)
951 rc = count;
952
953 return rc;
954}
955
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400956static ssize_t service_ccache_store(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400957 const char *buf,
958 size_t count)
959{
960 int rc = 0;
961
962 rc = sysfs_service_op_store(CCACHE_KOBJ_ID, buf, (void *) attr);
963
964 /* rc should have an errno value if the service_op went bad. */
965 if (rc == 1)
966 rc = count;
967
968 return rc;
969}
970
971static ssize_t
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400972 service_ncache_store(struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400973 const char *buf,
974 size_t count)
975{
976 int rc = 0;
977
978 rc = sysfs_service_op_store(NCACHE_KOBJ_ID, buf, (void *) attr);
979
980 /* rc should have an errno value if the service_op went bad. */
981 if (rc == 1)
982 rc = count;
983
984 return rc;
985}
986
987static struct orangefs_attribute op_timeout_secs_attribute =
988 __ATTR(op_timeout_secs, 0664, int_orangefs_show, int_store);
989
990static struct orangefs_attribute slot_timeout_secs_attribute =
991 __ATTR(slot_timeout_secs, 0664, int_orangefs_show, int_store);
992
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400993static struct orangefs_attribute dcache_timeout_msecs_attribute =
994 __ATTR(dcache_timeout_msecs, 0664, int_orangefs_show, int_store);
995
996static struct orangefs_attribute getattr_timeout_msecs_attribute =
997 __ATTR(getattr_timeout_msecs, 0664, int_orangefs_show, int_store);
998
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400999static struct orangefs_attribute readahead_count_attribute =
1000 __ATTR(readahead_count, 0664, service_orangefs_show,
1001 service_orangefs_store);
1002
1003static struct orangefs_attribute readahead_size_attribute =
1004 __ATTR(readahead_size, 0664, service_orangefs_show,
1005 service_orangefs_store);
1006
1007static struct orangefs_attribute readahead_count_size_attribute =
1008 __ATTR(readahead_count_size, 0664, service_orangefs_show,
1009 service_orangefs_store);
1010
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001011static struct orangefs_attribute perf_counter_reset_attribute =
1012 __ATTR(perf_counter_reset,
1013 0664,
1014 service_orangefs_show,
1015 service_orangefs_store);
1016
1017static struct orangefs_attribute perf_history_size_attribute =
1018 __ATTR(perf_history_size,
1019 0664,
1020 service_orangefs_show,
1021 service_orangefs_store);
1022
1023static struct orangefs_attribute perf_time_interval_secs_attribute =
1024 __ATTR(perf_time_interval_secs,
1025 0664,
1026 service_orangefs_show,
1027 service_orangefs_store);
1028
1029static struct attribute *orangefs_default_attrs[] = {
1030 &op_timeout_secs_attribute.attr,
1031 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -04001032 &dcache_timeout_msecs_attribute.attr,
1033 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001034 &readahead_count_attribute.attr,
1035 &readahead_size_attribute.attr,
1036 &readahead_count_size_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001037 &perf_counter_reset_attribute.attr,
1038 &perf_history_size_attribute.attr,
1039 &perf_time_interval_secs_attribute.attr,
1040 NULL,
1041};
1042
1043static struct kobj_type orangefs_ktype = {
1044 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001045 .default_attrs = orangefs_default_attrs,
1046};
1047
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001048static struct orangefs_attribute acache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001049 __ATTR(hard_limit,
1050 0664,
1051 service_acache_show,
1052 service_acache_store);
1053
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001054static struct orangefs_attribute acache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001055 __ATTR(reclaim_percentage,
1056 0664,
1057 service_acache_show,
1058 service_acache_store);
1059
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001060static struct orangefs_attribute acache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001061 __ATTR(soft_limit,
1062 0664,
1063 service_acache_show,
1064 service_acache_store);
1065
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001066static struct orangefs_attribute acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001067 __ATTR(timeout_msecs,
1068 0664,
1069 service_acache_show,
1070 service_acache_store);
1071
1072static struct attribute *acache_orangefs_default_attrs[] = {
1073 &acache_hard_limit_attribute.attr,
1074 &acache_reclaim_percent_attribute.attr,
1075 &acache_soft_limit_attribute.attr,
1076 &acache_timeout_msecs_attribute.attr,
1077 NULL,
1078};
1079
1080static struct kobj_type acache_orangefs_ktype = {
1081 .sysfs_ops = &acache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001082 .default_attrs = acache_orangefs_default_attrs,
1083};
1084
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001085static struct orangefs_attribute capcache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001086 __ATTR(hard_limit,
1087 0664,
1088 service_capcache_show,
1089 service_capcache_store);
1090
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001091static struct orangefs_attribute capcache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001092 __ATTR(reclaim_percentage,
1093 0664,
1094 service_capcache_show,
1095 service_capcache_store);
1096
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001097static struct orangefs_attribute capcache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001098 __ATTR(soft_limit,
1099 0664,
1100 service_capcache_show,
1101 service_capcache_store);
1102
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001103static struct orangefs_attribute capcache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001104 __ATTR(timeout_secs,
1105 0664,
1106 service_capcache_show,
1107 service_capcache_store);
1108
1109static struct attribute *capcache_orangefs_default_attrs[] = {
1110 &capcache_hard_limit_attribute.attr,
1111 &capcache_reclaim_percent_attribute.attr,
1112 &capcache_soft_limit_attribute.attr,
1113 &capcache_timeout_secs_attribute.attr,
1114 NULL,
1115};
1116
1117static struct kobj_type capcache_orangefs_ktype = {
1118 .sysfs_ops = &capcache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001119 .default_attrs = capcache_orangefs_default_attrs,
1120};
1121
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001122static struct orangefs_attribute ccache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001123 __ATTR(hard_limit,
1124 0664,
1125 service_ccache_show,
1126 service_ccache_store);
1127
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001128static struct orangefs_attribute ccache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001129 __ATTR(reclaim_percentage,
1130 0664,
1131 service_ccache_show,
1132 service_ccache_store);
1133
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001134static struct orangefs_attribute ccache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001135 __ATTR(soft_limit,
1136 0664,
1137 service_ccache_show,
1138 service_ccache_store);
1139
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001140static struct orangefs_attribute ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001141 __ATTR(timeout_secs,
1142 0664,
1143 service_ccache_show,
1144 service_ccache_store);
1145
1146static struct attribute *ccache_orangefs_default_attrs[] = {
1147 &ccache_hard_limit_attribute.attr,
1148 &ccache_reclaim_percent_attribute.attr,
1149 &ccache_soft_limit_attribute.attr,
1150 &ccache_timeout_secs_attribute.attr,
1151 NULL,
1152};
1153
1154static struct kobj_type ccache_orangefs_ktype = {
1155 .sysfs_ops = &ccache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001156 .default_attrs = ccache_orangefs_default_attrs,
1157};
1158
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001159static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001160 __ATTR(hard_limit,
1161 0664,
1162 service_ncache_show,
1163 service_ncache_store);
1164
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001165static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001166 __ATTR(reclaim_percentage,
1167 0664,
1168 service_ncache_show,
1169 service_ncache_store);
1170
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001171static struct orangefs_attribute ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001172 __ATTR(soft_limit,
1173 0664,
1174 service_ncache_show,
1175 service_ncache_store);
1176
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001177static struct orangefs_attribute ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001178 __ATTR(timeout_msecs,
1179 0664,
1180 service_ncache_show,
1181 service_ncache_store);
1182
1183static struct attribute *ncache_orangefs_default_attrs[] = {
1184 &ncache_hard_limit_attribute.attr,
1185 &ncache_reclaim_percent_attribute.attr,
1186 &ncache_soft_limit_attribute.attr,
1187 &ncache_timeout_msecs_attribute.attr,
1188 NULL,
1189};
1190
1191static struct kobj_type ncache_orangefs_ktype = {
1192 .sysfs_ops = &ncache_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001193 .default_attrs = ncache_orangefs_default_attrs,
1194};
1195
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001196static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001197 __ATTR(acache,
1198 0664,
1199 service_pc_show,
1200 NULL);
1201
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001202static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001203 __ATTR(capcache,
1204 0664,
1205 service_pc_show,
1206 NULL);
1207
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001208static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001209 __ATTR(ncache,
1210 0664,
1211 service_pc_show,
1212 NULL);
1213
1214static struct attribute *pc_orangefs_default_attrs[] = {
1215 &pc_acache_attribute.attr,
1216 &pc_capcache_attribute.attr,
1217 &pc_ncache_attribute.attr,
1218 NULL,
1219};
1220
1221static struct kobj_type pc_orangefs_ktype = {
1222 .sysfs_ops = &pc_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001223 .default_attrs = pc_orangefs_default_attrs,
1224};
1225
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001226static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001227 __ATTR(reads,
1228 0664,
1229 int_stats_show,
1230 NULL);
1231
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001232static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001233 __ATTR(writes,
1234 0664,
1235 int_stats_show,
1236 NULL);
1237
1238static struct attribute *stats_orangefs_default_attrs[] = {
1239 &stats_reads_attribute.attr,
1240 &stats_writes_attribute.attr,
1241 NULL,
1242};
1243
1244static struct kobj_type stats_orangefs_ktype = {
1245 .sysfs_ops = &stats_orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001246 .default_attrs = stats_orangefs_default_attrs,
1247};
1248
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001249static struct kobject *orangefs_obj;
1250static struct kobject *acache_orangefs_obj;
1251static struct kobject *capcache_orangefs_obj;
1252static struct kobject *ccache_orangefs_obj;
1253static struct kobject *ncache_orangefs_obj;
1254static struct kobject *pc_orangefs_obj;
1255static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001256
1257int orangefs_sysfs_init(void)
1258{
Mike Marshall2180c522016-03-14 15:30:39 -04001259 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001260
1261 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1262
1263 /* create /sys/fs/orangefs. */
1264 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001265 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001266 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001267
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001268 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001269 &orangefs_ktype,
1270 fs_kobj,
1271 ORANGEFS_KOBJ_ID);
1272
Mike Marshall2180c522016-03-14 15:30:39 -04001273 if (rc)
1274 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001275
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001276 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001277
1278 /* create /sys/fs/orangefs/acache. */
1279 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1280 if (!acache_orangefs_obj) {
1281 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001282 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001283 }
1284
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001285 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001286 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001287 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001288 ACACHE_KOBJ_ID);
1289
Mike Marshall2180c522016-03-14 15:30:39 -04001290 if (rc)
1291 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001292
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001293 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001294
1295 /* create /sys/fs/orangefs/capcache. */
1296 capcache_orangefs_obj =
1297 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1298 if (!capcache_orangefs_obj) {
1299 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001300 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001301 }
1302
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001303 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001304 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001305 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001306 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001307 if (rc)
1308 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001309
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001310 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001311
1312 /* create /sys/fs/orangefs/ccache. */
1313 ccache_orangefs_obj =
1314 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1315 if (!ccache_orangefs_obj) {
1316 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001317 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001318 }
1319
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001320 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001321 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001322 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001323 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001324 if (rc)
1325 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001326
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001327 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001328
1329 /* create /sys/fs/orangefs/ncache. */
1330 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1331 if (!ncache_orangefs_obj) {
1332 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001333 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001334 }
1335
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001336 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001337 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001338 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001339 NCACHE_KOBJ_ID);
1340
Mike Marshall2180c522016-03-14 15:30:39 -04001341 if (rc)
1342 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001343
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001344 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001345
1346 /* create /sys/fs/orangefs/perf_counters. */
1347 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1348 if (!pc_orangefs_obj) {
1349 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001350 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001351 }
1352
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001353 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001354 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001355 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001356 "perf_counters");
1357
Mike Marshall2180c522016-03-14 15:30:39 -04001358 if (rc)
1359 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001360
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001361 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001362
1363 /* create /sys/fs/orangefs/stats. */
1364 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1365 if (!stats_orangefs_obj) {
1366 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001367 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001368 }
1369
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001370 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001371 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001372 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001373 STATS_KOBJ_ID);
1374
Mike Marshall2180c522016-03-14 15:30:39 -04001375 if (rc)
1376 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001377
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001378 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001379 goto out;
1380
1381stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001382 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001383pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001384 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001385ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001386 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001387ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001388 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001389capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001390 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001391acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001392 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001393ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001394 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001395out:
1396 return rc;
1397}
1398
1399void orangefs_sysfs_exit(void)
1400{
1401 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001402 kobject_put(acache_orangefs_obj);
1403 kobject_put(capcache_orangefs_obj);
1404 kobject_put(ccache_orangefs_obj);
1405 kobject_put(ncache_orangefs_obj);
1406 kobject_put(pc_orangefs_obj);
1407 kobject_put(stats_orangefs_obj);
1408 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001409}