blob: e88370540cb4677502fefc61e758594d0866feb3 [file] [log] [blame]
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001/*
2 * Documentation/ABI/stable/orangefs-sysfs:
3 *
4 * What: /sys/fs/orangefs/perf_counter_reset
5 * Date: June 2015
6 * Contact: Mike Marshall <hubcap@omnibond.com>
7 * Description:
8 * echo a 0 or a 1 into perf_counter_reset to
9 * reset all the counters in
10 * /sys/fs/orangefs/perf_counters
11 * except ones with PINT_PERF_PRESERVE set.
12 *
13 *
14 * What: /sys/fs/orangefs/perf_counters/...
15 * Date: Jun 2015
16 * Contact: Mike Marshall <hubcap@omnibond.com>
17 * Description:
18 * Counters and settings for various caches.
19 * Read only.
20 *
21 *
22 * What: /sys/fs/orangefs/perf_time_interval_secs
23 * Date: Jun 2015
24 * Contact: Mike Marshall <hubcap@omnibond.com>
25 * Description:
26 * Length of perf counter intervals in
27 * seconds.
28 *
29 *
30 * What: /sys/fs/orangefs/perf_history_size
31 * Date: Jun 2015
32 * Contact: Mike Marshall <hubcap@omnibond.com>
33 * Description:
34 * The perf_counters cache statistics have N, or
35 * perf_history_size, samples. The default is
36 * one.
37 *
38 * Every perf_time_interval_secs the (first)
39 * samples are reset.
40 *
41 * If N is greater than one, the "current" set
42 * of samples is reset, and the samples from the
43 * other N-1 intervals remain available.
44 *
45 *
46 * What: /sys/fs/orangefs/op_timeout_secs
47 * Date: Jun 2015
48 * Contact: Mike Marshall <hubcap@omnibond.com>
49 * Description:
50 * Service operation timeout in seconds.
51 *
52 *
53 * What: /sys/fs/orangefs/slot_timeout_secs
54 * Date: Jun 2015
55 * Contact: Mike Marshall <hubcap@omnibond.com>
56 * Description:
57 * "Slot" timeout in seconds. A "slot"
58 * is an indexed buffer in the shared
59 * memory segment used for communication
60 * between the kernel module and userspace.
61 * Slots are requested and waited for,
62 * the wait times out after slot_timeout_secs.
63 *
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040064 * What: /sys/fs/orangefs/dcache_timeout_msecs
65 * Date: Jul 2016
66 * Contact: Martin Brandenburg <martin@omnibond.com>
67 * Description:
68 * Time lookup is valid in milliseconds.
69 *
70 * What: /sys/fs/orangefs/getattr_timeout_msecs
71 * Date: Jul 2016
72 * Contact: Martin Brandenburg <martin@omnibond.com>
73 * Description:
74 * Time getattr is valid in milliseconds.
Mike Marshallf7be4ee2015-07-17 10:38:14 -040075 *
Martin Brandenburg4d20a752016-08-03 13:47:28 -040076 * What: /sys/fs/orangefs/readahead_count
77 * Date: Aug 2016
78 * Contact: Martin Brandenburg <martin@omnibond.com>
79 * Description:
80 * Readahead cache buffer count.
81 *
82 * What: /sys/fs/orangefs/readahead_size
83 * Date: Aug 2016
84 * Contact: Martin Brandenburg <martin@omnibond.com>
85 * Description:
86 * Readahead cache buffer size.
87 *
88 * What: /sys/fs/orangefs/readahead_count_size
89 * Date: Aug 2016
90 * Contact: Martin Brandenburg <martin@omnibond.com>
91 * Description:
92 * Readahead cache buffer count and size.
93 *
Mike Marshallf7be4ee2015-07-17 10:38:14 -040094 * What: /sys/fs/orangefs/acache/...
95 * Date: Jun 2015
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040096 * Contact: Martin Brandenburg <martin@omnibond.com>
Mike Marshallf7be4ee2015-07-17 10:38:14 -040097 * Description:
98 * Attribute cache configurable settings.
99 *
100 *
101 * What: /sys/fs/orangefs/ncache/...
102 * Date: Jun 2015
103 * Contact: Mike Marshall <hubcap@omnibond.com>
104 * Description:
105 * Name cache configurable settings.
106 *
107 *
108 * What: /sys/fs/orangefs/capcache/...
109 * Date: Jun 2015
110 * Contact: Mike Marshall <hubcap@omnibond.com>
111 * Description:
112 * Capability cache configurable settings.
113 *
114 *
115 * What: /sys/fs/orangefs/ccache/...
116 * Date: Jun 2015
117 * Contact: Mike Marshall <hubcap@omnibond.com>
118 * Description:
119 * Credential cache configurable settings.
120 *
121 */
122
123#include <linux/fs.h>
124#include <linux/kobject.h>
125#include <linux/string.h>
126#include <linux/sysfs.h>
127#include <linux/module.h>
128#include <linux/init.h>
129
130#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -0500131#include "orangefs-kernel.h"
132#include "orangefs-sysfs.h"
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400133
134#define ORANGEFS_KOBJ_ID "orangefs"
135#define ACACHE_KOBJ_ID "acache"
136#define CAPCACHE_KOBJ_ID "capcache"
137#define CCACHE_KOBJ_ID "ccache"
138#define NCACHE_KOBJ_ID "ncache"
139#define PC_KOBJ_ID "pc"
140#define STATS_KOBJ_ID "stats"
141
Martin Brandenburgc27889c2016-08-15 15:11:32 -0400142/*
143 * Every item calls orangefs_attr_show and orangefs_attr_store through
144 * orangefs_sysfs_ops. They look at the orangefs_attributes further below to
145 * call one of sysfs_int_show, sysfs_int_store, sysfs_service_op_show, or
146 * sysfs_service_op_store.
147 */
148
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400149struct orangefs_attribute {
150 struct attribute attr;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400151 ssize_t (*show)(struct kobject *kobj,
152 struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400153 char *buf);
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400154 ssize_t (*store)(struct kobject *kobj,
155 struct orangefs_attribute *attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400156 const char *buf,
157 size_t count);
158};
159
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400160static ssize_t orangefs_attr_show(struct kobject *kobj,
161 struct attribute *attr,
162 char *buf)
163{
164 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400165
166 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400167 if (!attribute->show)
168 return -EIO;
169 return attribute->show(kobj, attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400170}
171
172static ssize_t orangefs_attr_store(struct kobject *kobj,
173 struct attribute *attr,
174 const char *buf,
175 size_t len)
176{
177 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400178
Martin Brandenburg4a343662016-08-15 15:01:30 -0400179 if (!strcmp(kobj->name, PC_KOBJ_ID) ||
180 !strcmp(kobj->name, STATS_KOBJ_ID))
181 return -EPERM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400182
183 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400184 if (!attribute->store)
185 return -EIO;
186 return attribute->store(kobj, attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400187}
188
189static const struct sysfs_ops orangefs_sysfs_ops = {
190 .show = orangefs_attr_show,
191 .store = orangefs_attr_store,
192};
193
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400194static ssize_t sysfs_int_show(struct kobject *kobj,
195 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400196{
197 int rc = -EIO;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400198
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400199 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
200 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400201
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400202 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
203 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400204 rc = scnprintf(buf,
205 PAGE_SIZE,
206 "%d\n",
207 op_timeout_secs);
208 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400209 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400210 "slot_timeout_secs")) {
211 rc = scnprintf(buf,
212 PAGE_SIZE,
213 "%d\n",
214 slot_timeout_secs);
215 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400216 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400217 "dcache_timeout_msecs")) {
218 rc = scnprintf(buf,
219 PAGE_SIZE,
220 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400221 orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400222 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400223 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400224 "getattr_timeout_msecs")) {
225 rc = scnprintf(buf,
226 PAGE_SIZE,
227 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400228 orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400229 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400230 } else {
231 goto out;
232 }
233
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400234 } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
235 if (!strcmp(attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400236 rc = scnprintf(buf,
237 PAGE_SIZE,
238 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400239 orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400240 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400241 } else if (!strcmp(attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400242 rc = scnprintf(buf,
243 PAGE_SIZE,
244 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400245 orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400246 goto out;
247 } else {
248 goto out;
249 }
250 }
251
252out:
253
254 return rc;
255}
256
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400257static ssize_t sysfs_int_store(struct kobject *kobj,
258 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400259{
260 int rc = 0;
261
262 gossip_debug(GOSSIP_SYSFS_DEBUG,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400263 "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400264 attr->attr.name, buf);
265
266 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
267 rc = kstrtoint(buf, 0, &op_timeout_secs);
268 goto out;
269 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
270 rc = kstrtoint(buf, 0, &slot_timeout_secs);
271 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400272 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400273 rc = kstrtoint(buf, 0, &orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400274 goto out;
275 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400276 rc = kstrtoint(buf, 0, &orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400277 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400278 } else {
279 goto out;
280 }
281
282out:
283 if (rc)
284 rc = -EINVAL;
285 else
286 rc = count;
287
288 return rc;
289}
290
291/*
292 * obtain attribute values from userspace with a service operation.
293 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400294static ssize_t sysfs_service_op_show(struct kobject *kobj,
295 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400296{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500297 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400298 int rc = 0;
299 char *ser_op_type = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400300 __u32 op_alloc_type;
301
302 gossip_debug(GOSSIP_SYSFS_DEBUG,
303 "sysfs_service_op_show: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400304 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400305
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400306 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500307 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400308 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500309 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400310
311 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500312 if (!new_op)
313 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400314
315 /* Can't do a service_operation if the client is not running... */
316 rc = is_daemon_in_service();
317 if (rc) {
318 pr_info("%s: Client not running :%d:\n",
319 __func__,
320 is_daemon_in_service());
321 goto out;
322 }
323
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400324 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500325 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400326
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400327 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
328 if (!strcmp(attr->attr.name, "perf_history_size"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400329 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500330 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400331 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400332 "perf_time_interval_secs"))
333 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500334 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400335 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400336 "perf_counter_reset"))
337 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500338 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400339
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400340 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400341 "readahead_count"))
342 new_op->upcall.req.param.op =
343 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
344
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400345 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400346 "readahead_size"))
347 new_op->upcall.req.param.op =
348 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
349
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400350 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400351 "readahead_count_size"))
352 new_op->upcall.req.param.op =
353 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400354 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
355 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400356 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500357 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400358
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400359 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400360 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500361 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400362
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400363 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400364 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500365 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400366
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400367 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400368 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500369 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400370
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400371 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
372 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400373 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500374 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400375
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400376 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400377 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500378 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400379
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400380 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400381 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500382 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400383
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400384 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400385 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500386 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400387
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400388 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
389 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400390 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500391 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400392
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400393 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400394 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500395 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400396
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400397 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400398 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500399 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400400
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400401 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400402 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500403 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400404
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400405 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
406 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400407 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500408 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400409
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400410 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400411 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500412 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400413
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400414 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400415 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500416 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400417
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400418 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400419 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500420 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400421
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400422 } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
423 if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400424 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500425 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400426
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400427 if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400428 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500429 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400430
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400431 if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400432 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500433 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400434
435 } else {
436 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400437 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400438 rc = -EINVAL;
439 goto out;
440 }
441
442
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400443 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500444 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400445 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500446 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400447
448 /*
449 * The service_operation will return an errno return code on
450 * error, and zero on success.
451 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500452 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400453
454out:
455 if (!rc) {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400456 if (strcmp(kobj->name, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400457 if (new_op->upcall.req.param.op ==
458 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
459 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
460 (int)new_op->downcall.resp.param.u.
461 value32[0],
462 (int)new_op->downcall.resp.param.u.
463 value32[1]);
464 } else {
465 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
466 (int)new_op->downcall.resp.param.u.value64);
467 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400468 } else {
469 rc = scnprintf(
470 buf,
471 PAGE_SIZE,
472 "%s",
473 new_op->downcall.resp.perf_count.buffer);
474 }
475 }
476
Al Viroed42fe02016-01-22 19:47:47 -0500477 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400478
479 return rc;
480
481}
482
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400483/*
484 * pass attribute values back to userspace with a service operation.
485 *
486 * We have to do a memory allocation, an sscanf and a service operation.
487 * And we have to evaluate what the user entered, to make sure the
488 * value is within the range supported by the attribute. So, there's
489 * a lot of return code checking and mapping going on here.
490 *
491 * We want to return 1 if we think everything went OK, and
492 * EINVAL if not.
493 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400494static ssize_t sysfs_service_op_store(struct kobject *kobj,
495 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400496{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500497 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400498 int val = 0;
499 int rc = 0;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400500
501 gossip_debug(GOSSIP_SYSFS_DEBUG,
502 "sysfs_service_op_store: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400503 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400504
Yi Liu8bb8aef2015-11-24 15:12:14 -0500505 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500506 if (!new_op)
507 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400508
509 /* Can't do a service_operation if the client is not running... */
510 rc = is_daemon_in_service();
511 if (rc) {
512 pr_info("%s: Client not running :%d:\n",
513 __func__,
514 is_daemon_in_service());
515 goto out;
516 }
517
518 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400519 * The value we want to send back to userspace is in buf, unless this
520 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400521 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400522 if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
523 strcmp(attr->attr.name, "readahead_count_size")) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400524 rc = kstrtoint(buf, 0, &val);
525 if (rc)
526 goto out;
527 }
528
529 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400530
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400531 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
532 if (!strcmp(attr->attr.name, "perf_history_size")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400533 if (val > 0) {
534 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500535 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400536 } else {
537 rc = 0;
538 goto out;
539 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400540 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400541 "perf_time_interval_secs")) {
542 if (val > 0) {
543 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500544 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400545 } else {
546 rc = 0;
547 goto out;
548 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400549 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400550 "perf_counter_reset")) {
551 if ((val == 0) || (val == 1)) {
552 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500553 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400554 } else {
555 rc = 0;
556 goto out;
557 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400558 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400559 "readahead_count")) {
560 if ((val >= 0)) {
561 new_op->upcall.req.param.op =
562 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
563 } else {
564 rc = 0;
565 goto out;
566 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400567 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400568 "readahead_size")) {
569 if ((val >= 0)) {
570 new_op->upcall.req.param.op =
571 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
572 } else {
573 rc = 0;
574 goto out;
575 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400576 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400577 "readahead_count_size")) {
578 int val1, val2;
579 rc = sscanf(buf, "%d %d", &val1, &val2);
580 if (rc < 2) {
581 rc = 0;
582 goto out;
583 }
584 if ((val1 >= 0) && (val2 >= 0)) {
585 new_op->upcall.req.param.op =
586 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
587 } else {
588 rc = 0;
589 goto out;
590 }
591 new_op->upcall.req.param.u.value32[0] = val1;
592 new_op->upcall.req.param.u.value32[1] = val2;
593 goto value_set;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400594 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400595 "perf_counter_reset")) {
596 if ((val > 0)) {
597 new_op->upcall.req.param.op =
598 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
599 } else {
600 rc = 0;
601 goto out;
602 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400603 }
604
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400605 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
606 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400607 if (val > -1) {
608 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500609 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400610 } else {
611 rc = 0;
612 goto out;
613 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400614 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400615 if (val > -1) {
616 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500617 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400618 } else {
619 rc = 0;
620 goto out;
621 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400622 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400623 "reclaim_percentage")) {
624 if ((val > -1) && (val < 101)) {
625 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500626 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400627 } else {
628 rc = 0;
629 goto out;
630 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400631 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400632 if (val > -1) {
633 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500634 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400635 } else {
636 rc = 0;
637 goto out;
638 }
639 }
640
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400641 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
642 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400643 if (val > -1) {
644 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500645 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400646 } else {
647 rc = 0;
648 goto out;
649 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400650 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400651 if (val > -1) {
652 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500653 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400654 } else {
655 rc = 0;
656 goto out;
657 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400658 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400659 "reclaim_percentage")) {
660 if ((val > -1) && (val < 101)) {
661 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500662 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400663 } else {
664 rc = 0;
665 goto out;
666 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400667 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400668 if (val > -1) {
669 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500670 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400671 } else {
672 rc = 0;
673 goto out;
674 }
675 }
676
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400677 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
678 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400679 if (val > -1) {
680 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500681 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400682 } else {
683 rc = 0;
684 goto out;
685 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400686 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400687 if (val > -1) {
688 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500689 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400690 } else {
691 rc = 0;
692 goto out;
693 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400694 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400695 "reclaim_percentage")) {
696 if ((val > -1) && (val < 101)) {
697 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500698 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400699 } else {
700 rc = 0;
701 goto out;
702 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400703 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400704 if (val > -1) {
705 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500706 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400707 } else {
708 rc = 0;
709 goto out;
710 }
711 }
712
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400713 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
714 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400715 if (val > -1) {
716 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500717 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400718 } else {
719 rc = 0;
720 goto out;
721 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400722 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400723 if (val > -1) {
724 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500725 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400726 } else {
727 rc = 0;
728 goto out;
729 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400730 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400731 "reclaim_percentage")) {
732 if ((val > -1) && (val < 101)) {
733 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500734 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400735 } else {
736 rc = 0;
737 goto out;
738 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400739 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400740 if (val > -1) {
741 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500742 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400743 } else {
744 rc = 0;
745 goto out;
746 }
747 }
748
749 } else {
750 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400751 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400752 rc = -EINVAL;
753 goto out;
754 }
755
Martin Brandenburg680908e2016-08-02 16:33:34 -0400756 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400757value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400758
759 /*
760 * The service_operation will return a errno return code on
761 * error, and zero on success.
762 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500763 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400764
765 if (rc < 0) {
766 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
767 rc);
768 rc = 0;
769 } else {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400770 rc = count;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400771 }
772
773out:
Al Viroed42fe02016-01-22 19:47:47 -0500774 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400775
Al Viroed42fe02016-01-22 19:47:47 -0500776 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400777 rc = -EINVAL;
778
779 return rc;
780}
781
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400782static struct orangefs_attribute op_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400783 __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400784
785static struct orangefs_attribute slot_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400786 __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400787
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400788static struct orangefs_attribute dcache_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400789 __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400790
791static struct orangefs_attribute getattr_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400792 __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400793
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400794static struct orangefs_attribute readahead_count_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400795 __ATTR(readahead_count, 0664, sysfs_service_op_show,
796 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400797
798static struct orangefs_attribute readahead_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400799 __ATTR(readahead_size, 0664, sysfs_service_op_show,
800 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400801
802static struct orangefs_attribute readahead_count_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400803 __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
804 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400805
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400806static struct orangefs_attribute perf_counter_reset_attribute =
807 __ATTR(perf_counter_reset,
808 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400809 sysfs_service_op_show,
810 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400811
812static struct orangefs_attribute perf_history_size_attribute =
813 __ATTR(perf_history_size,
814 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400815 sysfs_service_op_show,
816 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400817
818static struct orangefs_attribute perf_time_interval_secs_attribute =
819 __ATTR(perf_time_interval_secs,
820 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400821 sysfs_service_op_show,
822 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400823
824static struct attribute *orangefs_default_attrs[] = {
825 &op_timeout_secs_attribute.attr,
826 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400827 &dcache_timeout_msecs_attribute.attr,
828 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400829 &readahead_count_attribute.attr,
830 &readahead_size_attribute.attr,
831 &readahead_count_size_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400832 &perf_counter_reset_attribute.attr,
833 &perf_history_size_attribute.attr,
834 &perf_time_interval_secs_attribute.attr,
835 NULL,
836};
837
838static struct kobj_type orangefs_ktype = {
839 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400840 .default_attrs = orangefs_default_attrs,
841};
842
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400843static struct orangefs_attribute acache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400844 __ATTR(hard_limit,
845 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400846 sysfs_service_op_show,
847 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400848
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400849static struct orangefs_attribute acache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400850 __ATTR(reclaim_percentage,
851 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400852 sysfs_service_op_show,
853 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400854
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400855static struct orangefs_attribute acache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400856 __ATTR(soft_limit,
857 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400858 sysfs_service_op_show,
859 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400860
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400861static struct orangefs_attribute acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400862 __ATTR(timeout_msecs,
863 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400864 sysfs_service_op_show,
865 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400866
867static struct attribute *acache_orangefs_default_attrs[] = {
868 &acache_hard_limit_attribute.attr,
869 &acache_reclaim_percent_attribute.attr,
870 &acache_soft_limit_attribute.attr,
871 &acache_timeout_msecs_attribute.attr,
872 NULL,
873};
874
875static struct kobj_type acache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400876 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400877 .default_attrs = acache_orangefs_default_attrs,
878};
879
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400880static struct orangefs_attribute capcache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400881 __ATTR(hard_limit,
882 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400883 sysfs_service_op_show,
884 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400885
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400886static struct orangefs_attribute capcache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400887 __ATTR(reclaim_percentage,
888 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400889 sysfs_service_op_show,
890 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400891
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400892static struct orangefs_attribute capcache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400893 __ATTR(soft_limit,
894 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400895 sysfs_service_op_show,
896 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400897
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400898static struct orangefs_attribute capcache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400899 __ATTR(timeout_secs,
900 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400901 sysfs_service_op_show,
902 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400903
904static struct attribute *capcache_orangefs_default_attrs[] = {
905 &capcache_hard_limit_attribute.attr,
906 &capcache_reclaim_percent_attribute.attr,
907 &capcache_soft_limit_attribute.attr,
908 &capcache_timeout_secs_attribute.attr,
909 NULL,
910};
911
912static struct kobj_type capcache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400913 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400914 .default_attrs = capcache_orangefs_default_attrs,
915};
916
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400917static struct orangefs_attribute ccache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400918 __ATTR(hard_limit,
919 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400920 sysfs_service_op_show,
921 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400922
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400923static struct orangefs_attribute ccache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400924 __ATTR(reclaim_percentage,
925 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400926 sysfs_service_op_show,
927 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400928
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400929static struct orangefs_attribute ccache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400930 __ATTR(soft_limit,
931 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400932 sysfs_service_op_show,
933 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400934
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400935static struct orangefs_attribute ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400936 __ATTR(timeout_secs,
937 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400938 sysfs_service_op_show,
939 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400940
941static struct attribute *ccache_orangefs_default_attrs[] = {
942 &ccache_hard_limit_attribute.attr,
943 &ccache_reclaim_percent_attribute.attr,
944 &ccache_soft_limit_attribute.attr,
945 &ccache_timeout_secs_attribute.attr,
946 NULL,
947};
948
949static struct kobj_type ccache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400950 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400951 .default_attrs = ccache_orangefs_default_attrs,
952};
953
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400954static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400955 __ATTR(hard_limit,
956 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400957 sysfs_service_op_show,
958 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400959
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400960static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400961 __ATTR(reclaim_percentage,
962 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400963 sysfs_service_op_show,
964 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400965
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400966static struct orangefs_attribute ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400967 __ATTR(soft_limit,
968 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400969 sysfs_service_op_show,
970 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400971
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400972static struct orangefs_attribute ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400973 __ATTR(timeout_msecs,
974 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400975 sysfs_service_op_show,
976 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400977
978static struct attribute *ncache_orangefs_default_attrs[] = {
979 &ncache_hard_limit_attribute.attr,
980 &ncache_reclaim_percent_attribute.attr,
981 &ncache_soft_limit_attribute.attr,
982 &ncache_timeout_msecs_attribute.attr,
983 NULL,
984};
985
986static struct kobj_type ncache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400987 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400988 .default_attrs = ncache_orangefs_default_attrs,
989};
990
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400991static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400992 __ATTR(acache,
993 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400994 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400995 NULL);
996
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400997static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400998 __ATTR(capcache,
999 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001000 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001001 NULL);
1002
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001003static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001004 __ATTR(ncache,
1005 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001006 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001007 NULL);
1008
1009static struct attribute *pc_orangefs_default_attrs[] = {
1010 &pc_acache_attribute.attr,
1011 &pc_capcache_attribute.attr,
1012 &pc_ncache_attribute.attr,
1013 NULL,
1014};
1015
1016static struct kobj_type pc_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001017 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001018 .default_attrs = pc_orangefs_default_attrs,
1019};
1020
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001021static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001022 __ATTR(reads,
1023 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001024 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001025 NULL);
1026
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001027static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001028 __ATTR(writes,
1029 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001030 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001031 NULL);
1032
1033static struct attribute *stats_orangefs_default_attrs[] = {
1034 &stats_reads_attribute.attr,
1035 &stats_writes_attribute.attr,
1036 NULL,
1037};
1038
1039static struct kobj_type stats_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001040 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001041 .default_attrs = stats_orangefs_default_attrs,
1042};
1043
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001044static struct kobject *orangefs_obj;
1045static struct kobject *acache_orangefs_obj;
1046static struct kobject *capcache_orangefs_obj;
1047static struct kobject *ccache_orangefs_obj;
1048static struct kobject *ncache_orangefs_obj;
1049static struct kobject *pc_orangefs_obj;
1050static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001051
1052int orangefs_sysfs_init(void)
1053{
Mike Marshall2180c522016-03-14 15:30:39 -04001054 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001055
1056 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1057
1058 /* create /sys/fs/orangefs. */
1059 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001060 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001061 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001062
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001063 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001064 &orangefs_ktype,
1065 fs_kobj,
1066 ORANGEFS_KOBJ_ID);
1067
Mike Marshall2180c522016-03-14 15:30:39 -04001068 if (rc)
1069 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001070
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001071 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001072
1073 /* create /sys/fs/orangefs/acache. */
1074 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1075 if (!acache_orangefs_obj) {
1076 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001077 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001078 }
1079
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001080 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001081 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001082 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001083 ACACHE_KOBJ_ID);
1084
Mike Marshall2180c522016-03-14 15:30:39 -04001085 if (rc)
1086 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001087
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001088 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001089
1090 /* create /sys/fs/orangefs/capcache. */
1091 capcache_orangefs_obj =
1092 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1093 if (!capcache_orangefs_obj) {
1094 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001095 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001096 }
1097
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001098 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001099 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001100 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001101 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001102 if (rc)
1103 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001104
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001105 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001106
1107 /* create /sys/fs/orangefs/ccache. */
1108 ccache_orangefs_obj =
1109 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1110 if (!ccache_orangefs_obj) {
1111 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001112 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001113 }
1114
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001115 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001116 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001117 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001118 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001119 if (rc)
1120 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001121
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001122 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001123
1124 /* create /sys/fs/orangefs/ncache. */
1125 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1126 if (!ncache_orangefs_obj) {
1127 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001128 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001129 }
1130
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001131 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001132 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001133 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001134 NCACHE_KOBJ_ID);
1135
Mike Marshall2180c522016-03-14 15:30:39 -04001136 if (rc)
1137 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001138
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001139 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001140
1141 /* create /sys/fs/orangefs/perf_counters. */
1142 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1143 if (!pc_orangefs_obj) {
1144 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001145 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001146 }
1147
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001148 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001149 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001150 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001151 "perf_counters");
1152
Mike Marshall2180c522016-03-14 15:30:39 -04001153 if (rc)
1154 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001155
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001156 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001157
1158 /* create /sys/fs/orangefs/stats. */
1159 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1160 if (!stats_orangefs_obj) {
1161 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001162 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001163 }
1164
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001165 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001166 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001167 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001168 STATS_KOBJ_ID);
1169
Mike Marshall2180c522016-03-14 15:30:39 -04001170 if (rc)
1171 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001172
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001173 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001174 goto out;
1175
1176stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001177 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001178pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001179 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001180ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001181 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001182ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001183 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001184capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001185 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001186acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001187 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001188ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001189 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001190out:
1191 return rc;
1192}
1193
1194void orangefs_sysfs_exit(void)
1195{
1196 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001197 kobject_put(acache_orangefs_obj);
1198 kobject_put(capcache_orangefs_obj);
1199 kobject_put(ccache_orangefs_obj);
1200 kobject_put(ncache_orangefs_obj);
1201 kobject_put(pc_orangefs_obj);
1202 kobject_put(stats_orangefs_obj);
1203 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001204}