blob: a772d26ad9d99ac3e51602eee1248c50241148e3 [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
159 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400160 if (!attribute->show)
161 return -EIO;
162 return attribute->show(kobj, attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400163}
164
165static ssize_t orangefs_attr_store(struct kobject *kobj,
166 struct attribute *attr,
167 const char *buf,
168 size_t len)
169{
170 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400171
Martin Brandenburg4a343662016-08-15 15:01:30 -0400172 if (!strcmp(kobj->name, PC_KOBJ_ID) ||
173 !strcmp(kobj->name, STATS_KOBJ_ID))
174 return -EPERM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400175
176 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400177 if (!attribute->store)
178 return -EIO;
179 return attribute->store(kobj, attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400180}
181
182static const struct sysfs_ops orangefs_sysfs_ops = {
183 .show = orangefs_attr_show,
184 .store = orangefs_attr_store,
185};
186
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400187static ssize_t sysfs_int_show(struct kobject *kobj,
188 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400189{
190 int rc = -EIO;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400191
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400192 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
193 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400194
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400195 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
196 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400197 rc = scnprintf(buf,
198 PAGE_SIZE,
199 "%d\n",
200 op_timeout_secs);
201 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400202 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400203 "slot_timeout_secs")) {
204 rc = scnprintf(buf,
205 PAGE_SIZE,
206 "%d\n",
207 slot_timeout_secs);
208 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400209 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400210 "dcache_timeout_msecs")) {
211 rc = scnprintf(buf,
212 PAGE_SIZE,
213 "%d\n",
214 dcache_timeout_msecs);
215 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400216 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400217 "getattr_timeout_msecs")) {
218 rc = scnprintf(buf,
219 PAGE_SIZE,
220 "%d\n",
221 getattr_timeout_msecs);
222 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400223 } else {
224 goto out;
225 }
226
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400227 } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
228 if (!strcmp(attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400229 rc = scnprintf(buf,
230 PAGE_SIZE,
231 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500232 g_orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400233 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400234 } else if (!strcmp(attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400235 rc = scnprintf(buf,
236 PAGE_SIZE,
237 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500238 g_orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400239 goto out;
240 } else {
241 goto out;
242 }
243 }
244
245out:
246
247 return rc;
248}
249
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400250static ssize_t sysfs_int_store(struct kobject *kobj,
251 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400252{
253 int rc = 0;
254
255 gossip_debug(GOSSIP_SYSFS_DEBUG,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400256 "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400257 attr->attr.name, buf);
258
259 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
260 rc = kstrtoint(buf, 0, &op_timeout_secs);
261 goto out;
262 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
263 rc = kstrtoint(buf, 0, &slot_timeout_secs);
264 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400265 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
266 rc = kstrtoint(buf, 0, &dcache_timeout_msecs);
267 goto out;
268 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
269 rc = kstrtoint(buf, 0, &getattr_timeout_msecs);
270 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400271 } else {
272 goto out;
273 }
274
275out:
276 if (rc)
277 rc = -EINVAL;
278 else
279 rc = count;
280
281 return rc;
282}
283
284/*
285 * obtain attribute values from userspace with a service operation.
286 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400287static ssize_t sysfs_service_op_show(struct kobject *kobj,
288 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400289{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500290 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400291 int rc = 0;
292 char *ser_op_type = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400293 __u32 op_alloc_type;
294
295 gossip_debug(GOSSIP_SYSFS_DEBUG,
296 "sysfs_service_op_show: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400297 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400298
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400299 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500300 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400301 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500302 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400303
304 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500305 if (!new_op)
306 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400307
308 /* Can't do a service_operation if the client is not running... */
309 rc = is_daemon_in_service();
310 if (rc) {
311 pr_info("%s: Client not running :%d:\n",
312 __func__,
313 is_daemon_in_service());
314 goto out;
315 }
316
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400317 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500318 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400319
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400320 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
321 if (!strcmp(attr->attr.name, "perf_history_size"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400322 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500323 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400324 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400325 "perf_time_interval_secs"))
326 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500327 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400328 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400329 "perf_counter_reset"))
330 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500331 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400332
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400333 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400334 "readahead_count"))
335 new_op->upcall.req.param.op =
336 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
337
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400338 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400339 "readahead_size"))
340 new_op->upcall.req.param.op =
341 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
342
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400343 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400344 "readahead_count_size"))
345 new_op->upcall.req.param.op =
346 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400347 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
348 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400349 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500350 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400351
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400352 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400353 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500354 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400355
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400356 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400357 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500358 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400359
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400360 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400361 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500362 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400363
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400364 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
365 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400366 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500367 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400368
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400369 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400370 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500371 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400372
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400373 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400374 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500375 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400376
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400377 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400378 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500379 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400380
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400381 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
382 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400383 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500384 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400385
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400386 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400387 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500388 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400389
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400390 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400391 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500392 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400393
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400394 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400395 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500396 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400397
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400398 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
399 if (!strcmp(attr->attr.name, "timeout_msecs"))
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_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400402
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400403 if (!strcmp(attr->attr.name, "hard_limit"))
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_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400406
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400407 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400408 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500409 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400410
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400411 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400412 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500413 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400414
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400415 } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
416 if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400417 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500418 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400419
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400420 if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400421 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500422 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400423
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400424 if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400425 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500426 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400427
428 } else {
429 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400430 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400431 rc = -EINVAL;
432 goto out;
433 }
434
435
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400436 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500437 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400438 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500439 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400440
441 /*
442 * The service_operation will return an errno return code on
443 * error, and zero on success.
444 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500445 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400446
447out:
448 if (!rc) {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400449 if (strcmp(kobj->name, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400450 if (new_op->upcall.req.param.op ==
451 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
452 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
453 (int)new_op->downcall.resp.param.u.
454 value32[0],
455 (int)new_op->downcall.resp.param.u.
456 value32[1]);
457 } else {
458 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
459 (int)new_op->downcall.resp.param.u.value64);
460 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400461 } else {
462 rc = scnprintf(
463 buf,
464 PAGE_SIZE,
465 "%s",
466 new_op->downcall.resp.perf_count.buffer);
467 }
468 }
469
Al Viroed42fe02016-01-22 19:47:47 -0500470 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400471
472 return rc;
473
474}
475
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400476/*
477 * pass attribute values back to userspace with a service operation.
478 *
479 * We have to do a memory allocation, an sscanf and a service operation.
480 * And we have to evaluate what the user entered, to make sure the
481 * value is within the range supported by the attribute. So, there's
482 * a lot of return code checking and mapping going on here.
483 *
484 * We want to return 1 if we think everything went OK, and
485 * EINVAL if not.
486 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400487static ssize_t sysfs_service_op_store(struct kobject *kobj,
488 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400489{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500490 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400491 int val = 0;
492 int rc = 0;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400493
494 gossip_debug(GOSSIP_SYSFS_DEBUG,
495 "sysfs_service_op_store: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400496 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400497
Yi Liu8bb8aef2015-11-24 15:12:14 -0500498 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500499 if (!new_op)
500 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400501
502 /* Can't do a service_operation if the client is not running... */
503 rc = is_daemon_in_service();
504 if (rc) {
505 pr_info("%s: Client not running :%d:\n",
506 __func__,
507 is_daemon_in_service());
508 goto out;
509 }
510
511 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400512 * The value we want to send back to userspace is in buf, unless this
513 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400514 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400515 if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
516 strcmp(attr->attr.name, "readahead_count_size")) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400517 rc = kstrtoint(buf, 0, &val);
518 if (rc)
519 goto out;
520 }
521
522 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400523
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400524 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
525 if (!strcmp(attr->attr.name, "perf_history_size")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400526 if (val > 0) {
527 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500528 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400529 } else {
530 rc = 0;
531 goto out;
532 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400533 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400534 "perf_time_interval_secs")) {
535 if (val > 0) {
536 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500537 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400538 } else {
539 rc = 0;
540 goto out;
541 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400542 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400543 "perf_counter_reset")) {
544 if ((val == 0) || (val == 1)) {
545 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500546 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400547 } else {
548 rc = 0;
549 goto out;
550 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400551 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400552 "readahead_count")) {
553 if ((val >= 0)) {
554 new_op->upcall.req.param.op =
555 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
556 } else {
557 rc = 0;
558 goto out;
559 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400560 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400561 "readahead_size")) {
562 if ((val >= 0)) {
563 new_op->upcall.req.param.op =
564 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
565 } else {
566 rc = 0;
567 goto out;
568 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400569 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400570 "readahead_count_size")) {
571 int val1, val2;
572 rc = sscanf(buf, "%d %d", &val1, &val2);
573 if (rc < 2) {
574 rc = 0;
575 goto out;
576 }
577 if ((val1 >= 0) && (val2 >= 0)) {
578 new_op->upcall.req.param.op =
579 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
580 } else {
581 rc = 0;
582 goto out;
583 }
584 new_op->upcall.req.param.u.value32[0] = val1;
585 new_op->upcall.req.param.u.value32[1] = val2;
586 goto value_set;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400587 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400588 "perf_counter_reset")) {
589 if ((val > 0)) {
590 new_op->upcall.req.param.op =
591 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
592 } else {
593 rc = 0;
594 goto out;
595 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400596 }
597
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400598 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
599 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400600 if (val > -1) {
601 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500602 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400603 } else {
604 rc = 0;
605 goto out;
606 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400607 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400608 if (val > -1) {
609 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500610 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400611 } else {
612 rc = 0;
613 goto out;
614 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400615 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400616 "reclaim_percentage")) {
617 if ((val > -1) && (val < 101)) {
618 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500619 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400620 } else {
621 rc = 0;
622 goto out;
623 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400624 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400625 if (val > -1) {
626 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500627 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400628 } else {
629 rc = 0;
630 goto out;
631 }
632 }
633
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400634 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
635 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400636 if (val > -1) {
637 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500638 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400639 } else {
640 rc = 0;
641 goto out;
642 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400643 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400644 if (val > -1) {
645 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500646 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400647 } else {
648 rc = 0;
649 goto out;
650 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400651 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400652 "reclaim_percentage")) {
653 if ((val > -1) && (val < 101)) {
654 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500655 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400656 } else {
657 rc = 0;
658 goto out;
659 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400660 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400661 if (val > -1) {
662 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500663 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400664 } else {
665 rc = 0;
666 goto out;
667 }
668 }
669
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400670 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
671 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400672 if (val > -1) {
673 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500674 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400675 } else {
676 rc = 0;
677 goto out;
678 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400679 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400680 if (val > -1) {
681 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500682 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400683 } else {
684 rc = 0;
685 goto out;
686 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400687 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400688 "reclaim_percentage")) {
689 if ((val > -1) && (val < 101)) {
690 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500691 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400692 } else {
693 rc = 0;
694 goto out;
695 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400696 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400697 if (val > -1) {
698 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500699 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400700 } else {
701 rc = 0;
702 goto out;
703 }
704 }
705
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400706 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
707 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400708 if (val > -1) {
709 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500710 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400711 } else {
712 rc = 0;
713 goto out;
714 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400715 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400716 if (val > -1) {
717 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500718 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400719 } else {
720 rc = 0;
721 goto out;
722 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400723 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400724 "reclaim_percentage")) {
725 if ((val > -1) && (val < 101)) {
726 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500727 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400728 } else {
729 rc = 0;
730 goto out;
731 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400732 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
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_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400736 } else {
737 rc = 0;
738 goto out;
739 }
740 }
741
742 } else {
743 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400744 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400745 rc = -EINVAL;
746 goto out;
747 }
748
Martin Brandenburg680908e2016-08-02 16:33:34 -0400749 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400750value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400751
752 /*
753 * The service_operation will return a errno return code on
754 * error, and zero on success.
755 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500756 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400757
758 if (rc < 0) {
759 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
760 rc);
761 rc = 0;
762 } else {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400763 rc = count;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400764 }
765
766out:
Al Viroed42fe02016-01-22 19:47:47 -0500767 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400768
Al Viroed42fe02016-01-22 19:47:47 -0500769 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400770 rc = -EINVAL;
771
772 return rc;
773}
774
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400775static struct orangefs_attribute op_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400776 __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400777
778static struct orangefs_attribute slot_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400779 __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400780
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400781static struct orangefs_attribute dcache_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400782 __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400783
784static struct orangefs_attribute getattr_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400785 __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400786
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400787static struct orangefs_attribute readahead_count_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400788 __ATTR(readahead_count, 0664, sysfs_service_op_show,
789 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400790
791static struct orangefs_attribute readahead_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400792 __ATTR(readahead_size, 0664, sysfs_service_op_show,
793 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400794
795static struct orangefs_attribute readahead_count_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400796 __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
797 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400798
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400799static struct orangefs_attribute perf_counter_reset_attribute =
800 __ATTR(perf_counter_reset,
801 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400802 sysfs_service_op_show,
803 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400804
805static struct orangefs_attribute perf_history_size_attribute =
806 __ATTR(perf_history_size,
807 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400808 sysfs_service_op_show,
809 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400810
811static struct orangefs_attribute perf_time_interval_secs_attribute =
812 __ATTR(perf_time_interval_secs,
813 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400814 sysfs_service_op_show,
815 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400816
817static struct attribute *orangefs_default_attrs[] = {
818 &op_timeout_secs_attribute.attr,
819 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400820 &dcache_timeout_msecs_attribute.attr,
821 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400822 &readahead_count_attribute.attr,
823 &readahead_size_attribute.attr,
824 &readahead_count_size_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400825 &perf_counter_reset_attribute.attr,
826 &perf_history_size_attribute.attr,
827 &perf_time_interval_secs_attribute.attr,
828 NULL,
829};
830
831static struct kobj_type orangefs_ktype = {
832 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400833 .default_attrs = orangefs_default_attrs,
834};
835
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400836static struct orangefs_attribute acache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400837 __ATTR(hard_limit,
838 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400839 sysfs_service_op_show,
840 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400841
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400842static struct orangefs_attribute acache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400843 __ATTR(reclaim_percentage,
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
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400848static struct orangefs_attribute acache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400849 __ATTR(soft_limit,
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
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400854static struct orangefs_attribute acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400855 __ATTR(timeout_msecs,
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 *acache_orangefs_default_attrs[] = {
861 &acache_hard_limit_attribute.attr,
862 &acache_reclaim_percent_attribute.attr,
863 &acache_soft_limit_attribute.attr,
864 &acache_timeout_msecs_attribute.attr,
865 NULL,
866};
867
868static struct kobj_type acache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400869 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400870 .default_attrs = acache_orangefs_default_attrs,
871};
872
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400873static struct orangefs_attribute capcache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400874 __ATTR(hard_limit,
875 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400876 sysfs_service_op_show,
877 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400878
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400879static struct orangefs_attribute capcache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400880 __ATTR(reclaim_percentage,
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 capcache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400886 __ATTR(soft_limit,
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 capcache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400892 __ATTR(timeout_secs,
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
897static struct attribute *capcache_orangefs_default_attrs[] = {
898 &capcache_hard_limit_attribute.attr,
899 &capcache_reclaim_percent_attribute.attr,
900 &capcache_soft_limit_attribute.attr,
901 &capcache_timeout_secs_attribute.attr,
902 NULL,
903};
904
905static struct kobj_type capcache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400906 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400907 .default_attrs = capcache_orangefs_default_attrs,
908};
909
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400910static struct orangefs_attribute ccache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400911 __ATTR(hard_limit,
912 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400913 sysfs_service_op_show,
914 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400915
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400916static struct orangefs_attribute ccache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400917 __ATTR(reclaim_percentage,
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 ccache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400923 __ATTR(soft_limit,
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 ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400929 __ATTR(timeout_secs,
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
934static struct attribute *ccache_orangefs_default_attrs[] = {
935 &ccache_hard_limit_attribute.attr,
936 &ccache_reclaim_percent_attribute.attr,
937 &ccache_soft_limit_attribute.attr,
938 &ccache_timeout_secs_attribute.attr,
939 NULL,
940};
941
942static struct kobj_type ccache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400943 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400944 .default_attrs = ccache_orangefs_default_attrs,
945};
946
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400947static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400948 __ATTR(hard_limit,
949 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400950 sysfs_service_op_show,
951 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400952
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400953static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400954 __ATTR(reclaim_percentage,
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 ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400960 __ATTR(soft_limit,
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 ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400966 __ATTR(timeout_msecs,
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
971static struct attribute *ncache_orangefs_default_attrs[] = {
972 &ncache_hard_limit_attribute.attr,
973 &ncache_reclaim_percent_attribute.attr,
974 &ncache_soft_limit_attribute.attr,
975 &ncache_timeout_msecs_attribute.attr,
976 NULL,
977};
978
979static struct kobj_type ncache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400980 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400981 .default_attrs = ncache_orangefs_default_attrs,
982};
983
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400984static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400985 __ATTR(acache,
986 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400987 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400988 NULL);
989
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400990static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400991 __ATTR(capcache,
992 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400993 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400994 NULL);
995
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400996static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400997 __ATTR(ncache,
998 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400999 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001000 NULL);
1001
1002static struct attribute *pc_orangefs_default_attrs[] = {
1003 &pc_acache_attribute.attr,
1004 &pc_capcache_attribute.attr,
1005 &pc_ncache_attribute.attr,
1006 NULL,
1007};
1008
1009static struct kobj_type pc_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001010 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001011 .default_attrs = pc_orangefs_default_attrs,
1012};
1013
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001014static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001015 __ATTR(reads,
1016 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001017 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001018 NULL);
1019
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001020static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001021 __ATTR(writes,
1022 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001023 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001024 NULL);
1025
1026static struct attribute *stats_orangefs_default_attrs[] = {
1027 &stats_reads_attribute.attr,
1028 &stats_writes_attribute.attr,
1029 NULL,
1030};
1031
1032static struct kobj_type stats_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001033 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001034 .default_attrs = stats_orangefs_default_attrs,
1035};
1036
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001037static struct kobject *orangefs_obj;
1038static struct kobject *acache_orangefs_obj;
1039static struct kobject *capcache_orangefs_obj;
1040static struct kobject *ccache_orangefs_obj;
1041static struct kobject *ncache_orangefs_obj;
1042static struct kobject *pc_orangefs_obj;
1043static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001044
1045int orangefs_sysfs_init(void)
1046{
Mike Marshall2180c522016-03-14 15:30:39 -04001047 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001048
1049 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1050
1051 /* create /sys/fs/orangefs. */
1052 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001053 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001054 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001055
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001056 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001057 &orangefs_ktype,
1058 fs_kobj,
1059 ORANGEFS_KOBJ_ID);
1060
Mike Marshall2180c522016-03-14 15:30:39 -04001061 if (rc)
1062 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001063
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001064 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001065
1066 /* create /sys/fs/orangefs/acache. */
1067 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1068 if (!acache_orangefs_obj) {
1069 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001070 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001071 }
1072
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001073 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001074 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001075 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001076 ACACHE_KOBJ_ID);
1077
Mike Marshall2180c522016-03-14 15:30:39 -04001078 if (rc)
1079 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001080
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001081 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001082
1083 /* create /sys/fs/orangefs/capcache. */
1084 capcache_orangefs_obj =
1085 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1086 if (!capcache_orangefs_obj) {
1087 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001088 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001089 }
1090
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001091 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001092 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001093 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001094 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001095 if (rc)
1096 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001097
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001098 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001099
1100 /* create /sys/fs/orangefs/ccache. */
1101 ccache_orangefs_obj =
1102 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1103 if (!ccache_orangefs_obj) {
1104 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001105 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001106 }
1107
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001108 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001109 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001110 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001111 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001112 if (rc)
1113 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001114
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001115 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001116
1117 /* create /sys/fs/orangefs/ncache. */
1118 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1119 if (!ncache_orangefs_obj) {
1120 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001121 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001122 }
1123
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001124 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001125 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001126 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001127 NCACHE_KOBJ_ID);
1128
Mike Marshall2180c522016-03-14 15:30:39 -04001129 if (rc)
1130 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001131
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001132 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001133
1134 /* create /sys/fs/orangefs/perf_counters. */
1135 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1136 if (!pc_orangefs_obj) {
1137 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001138 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001139 }
1140
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001141 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001142 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001143 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001144 "perf_counters");
1145
Mike Marshall2180c522016-03-14 15:30:39 -04001146 if (rc)
1147 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001148
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001149 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001150
1151 /* create /sys/fs/orangefs/stats. */
1152 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1153 if (!stats_orangefs_obj) {
1154 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001155 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001156 }
1157
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001158 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001159 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001160 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001161 STATS_KOBJ_ID);
1162
Mike Marshall2180c522016-03-14 15:30:39 -04001163 if (rc)
1164 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001165
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001166 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001167 goto out;
1168
1169stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001170 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001171pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001172 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001173ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001174 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001175ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001176 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001177capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001178 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001179acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001180 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001181ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001182 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001183out:
1184 return rc;
1185}
1186
1187void orangefs_sysfs_exit(void)
1188{
1189 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001190 kobject_put(acache_orangefs_obj);
1191 kobject_put(capcache_orangefs_obj);
1192 kobject_put(ccache_orangefs_obj);
1193 kobject_put(ncache_orangefs_obj);
1194 kobject_put(pc_orangefs_obj);
1195 kobject_put(stats_orangefs_obj);
1196 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001197}