blob: afd2f523b2837988ae30975c231d83a21869c533 [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 *
Martin Brandenburg31c829f2017-01-26 10:25:30 -050094 * What: /sys/fs/orangefs/readahead_readcnt
95 * Date: Jan 2017
96 * Contact: Martin Brandenburg <martin@omnibond.com>
97 * Description:
98 * Number of buffers (in multiples of readahead_size)
99 * which can be read ahead for a single file at once.
100 *
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400101 * What: /sys/fs/orangefs/acache/...
102 * Date: Jun 2015
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400103 * Contact: Martin Brandenburg <martin@omnibond.com>
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400104 * Description:
105 * Attribute cache configurable settings.
106 *
107 *
108 * What: /sys/fs/orangefs/ncache/...
109 * Date: Jun 2015
110 * Contact: Mike Marshall <hubcap@omnibond.com>
111 * Description:
112 * Name cache configurable settings.
113 *
114 *
115 * What: /sys/fs/orangefs/capcache/...
116 * Date: Jun 2015
117 * Contact: Mike Marshall <hubcap@omnibond.com>
118 * Description:
119 * Capability cache configurable settings.
120 *
121 *
122 * What: /sys/fs/orangefs/ccache/...
123 * Date: Jun 2015
124 * Contact: Mike Marshall <hubcap@omnibond.com>
125 * Description:
126 * Credential cache configurable settings.
127 *
128 */
129
130#include <linux/fs.h>
131#include <linux/kobject.h>
132#include <linux/string.h>
133#include <linux/sysfs.h>
134#include <linux/module.h>
135#include <linux/init.h>
136
137#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -0500138#include "orangefs-kernel.h"
139#include "orangefs-sysfs.h"
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400140
141#define ORANGEFS_KOBJ_ID "orangefs"
142#define ACACHE_KOBJ_ID "acache"
143#define CAPCACHE_KOBJ_ID "capcache"
144#define CCACHE_KOBJ_ID "ccache"
145#define NCACHE_KOBJ_ID "ncache"
146#define PC_KOBJ_ID "pc"
147#define STATS_KOBJ_ID "stats"
148
Martin Brandenburgc27889c2016-08-15 15:11:32 -0400149/*
150 * Every item calls orangefs_attr_show and orangefs_attr_store through
151 * orangefs_sysfs_ops. They look at the orangefs_attributes further below to
152 * call one of sysfs_int_show, sysfs_int_store, sysfs_service_op_show, or
153 * sysfs_service_op_store.
154 */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400155
156struct orangefs_attribute {
157 struct attribute attr;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400158 ssize_t (*show)(struct kobject *kobj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400159 struct orangefs_attribute *attr,
160 char *buf);
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400161 ssize_t (*store)(struct kobject *kobj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400162 struct orangefs_attribute *attr,
163 const char *buf,
164 size_t count);
165};
166
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400167static ssize_t orangefs_attr_show(struct kobject *kobj,
168 struct attribute *attr,
169 char *buf)
170{
171 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400172
173 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400174 if (!attribute->show)
175 return -EIO;
176 return attribute->show(kobj, attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400177}
178
179static ssize_t orangefs_attr_store(struct kobject *kobj,
180 struct attribute *attr,
181 const char *buf,
182 size_t len)
183{
184 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400185
Martin Brandenburg4a343662016-08-15 15:01:30 -0400186 if (!strcmp(kobj->name, PC_KOBJ_ID) ||
187 !strcmp(kobj->name, STATS_KOBJ_ID))
188 return -EPERM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400189
190 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400191 if (!attribute->store)
192 return -EIO;
193 return attribute->store(kobj, attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400194}
195
196static const struct sysfs_ops orangefs_sysfs_ops = {
197 .show = orangefs_attr_show,
198 .store = orangefs_attr_store,
199};
200
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400201static ssize_t sysfs_int_show(struct kobject *kobj,
202 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400203{
204 int rc = -EIO;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400205
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400206 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
207 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400208
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400209 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
210 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400211 rc = scnprintf(buf,
212 PAGE_SIZE,
213 "%d\n",
214 op_timeout_secs);
215 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400216 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400217 "slot_timeout_secs")) {
218 rc = scnprintf(buf,
219 PAGE_SIZE,
220 "%d\n",
221 slot_timeout_secs);
222 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400223 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400224 "dcache_timeout_msecs")) {
225 rc = scnprintf(buf,
226 PAGE_SIZE,
227 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400228 orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400229 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400230 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400231 "getattr_timeout_msecs")) {
232 rc = scnprintf(buf,
233 PAGE_SIZE,
234 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400235 orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400236 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400237 } else {
238 goto out;
239 }
240
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400241 } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
242 if (!strcmp(attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400243 rc = scnprintf(buf,
244 PAGE_SIZE,
245 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400246 orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400247 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400248 } else if (!strcmp(attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400249 rc = scnprintf(buf,
250 PAGE_SIZE,
251 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400252 orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400253 goto out;
254 } else {
255 goto out;
256 }
257 }
258
259out:
260
261 return rc;
262}
263
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400264static ssize_t sysfs_int_store(struct kobject *kobj,
265 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400266{
267 int rc = 0;
268
269 gossip_debug(GOSSIP_SYSFS_DEBUG,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400270 "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400271 attr->attr.name, buf);
272
273 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
274 rc = kstrtoint(buf, 0, &op_timeout_secs);
275 goto out;
276 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
277 rc = kstrtoint(buf, 0, &slot_timeout_secs);
278 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400279 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400280 rc = kstrtoint(buf, 0, &orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400281 goto out;
282 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400283 rc = kstrtoint(buf, 0, &orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400284 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400285 } else {
286 goto out;
287 }
288
289out:
290 if (rc)
291 rc = -EINVAL;
292 else
293 rc = count;
294
295 return rc;
296}
297
298/*
299 * obtain attribute values from userspace with a service operation.
300 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400301static ssize_t sysfs_service_op_show(struct kobject *kobj,
302 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400303{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500304 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400305 int rc = 0;
306 char *ser_op_type = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400307 __u32 op_alloc_type;
308
309 gossip_debug(GOSSIP_SYSFS_DEBUG,
310 "sysfs_service_op_show: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400311 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400312
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400313 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500314 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400315 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500316 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400317
318 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500319 if (!new_op)
320 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400321
322 /* Can't do a service_operation if the client is not running... */
323 rc = is_daemon_in_service();
324 if (rc) {
325 pr_info("%s: Client not running :%d:\n",
326 __func__,
327 is_daemon_in_service());
328 goto out;
329 }
330
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400331 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500332 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400333
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400334 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400335 /* Drop unsupported requests first. */
336 if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
Martin Brandenburgb78b1192016-09-28 14:50:46 -0400337 (!strcmp(attr->attr.name, "readahead_count") ||
338 !strcmp(attr->attr.name, "readahead_size") ||
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500339 !strcmp(attr->attr.name, "readahead_count_size") ||
340 !strcmp(attr->attr.name, "readahead_readcnt"))) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400341 rc = -EINVAL;
342 goto out;
343 }
344
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400345 if (!strcmp(attr->attr.name, "perf_history_size"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400346 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500347 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400348 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400349 "perf_time_interval_secs"))
350 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500351 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400352 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400353 "perf_counter_reset"))
354 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500355 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400356
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400357 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400358 "readahead_count"))
359 new_op->upcall.req.param.op =
360 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
361
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400362 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400363 "readahead_size"))
364 new_op->upcall.req.param.op =
365 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
366
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400367 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400368 "readahead_count_size"))
369 new_op->upcall.req.param.op =
370 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500371
372 else if (!strcmp(attr->attr.name,
373 "readahead_readcnt"))
374 new_op->upcall.req.param.op =
375 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400376 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
377 if (!strcmp(attr->attr.name, "timeout_msecs"))
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_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400380
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400381 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400382 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500383 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400384
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400385 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400386 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500387 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400388
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400389 if (!strcmp(attr->attr.name, "reclaim_percentage"))
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_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400392
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400393 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
394 if (!strcmp(attr->attr.name, "timeout_secs"))
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_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400397
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400398 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400399 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500400 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400401
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400402 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400403 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500404 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400405
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400406 if (!strcmp(attr->attr.name, "reclaim_percentage"))
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_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400409
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400410 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
411 if (!strcmp(attr->attr.name, "timeout_secs"))
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_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400414
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400415 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400416 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500417 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400418
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400419 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400420 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500421 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400422
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400423 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400424 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500425 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400426
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400427 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
428 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400429 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500430 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400431
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400432 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400433 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500434 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400435
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400436 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400437 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500438 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400439
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400440 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400441 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500442 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400443
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400444 } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
445 if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400446 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500447 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400448
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400449 if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400450 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500451 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400452
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400453 if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400454 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500455 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400456
457 } else {
458 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400459 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400460 rc = -EINVAL;
461 goto out;
462 }
463
464
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400465 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500466 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400467 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500468 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400469
470 /*
471 * The service_operation will return an errno return code on
472 * error, and zero on success.
473 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500474 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400475
476out:
477 if (!rc) {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400478 if (strcmp(kobj->name, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400479 if (new_op->upcall.req.param.op ==
480 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
481 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
482 (int)new_op->downcall.resp.param.u.
483 value32[0],
484 (int)new_op->downcall.resp.param.u.
485 value32[1]);
486 } else {
487 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
488 (int)new_op->downcall.resp.param.u.value64);
489 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400490 } else {
491 rc = scnprintf(
492 buf,
493 PAGE_SIZE,
494 "%s",
495 new_op->downcall.resp.perf_count.buffer);
496 }
497 }
498
Al Viroed42fe02016-01-22 19:47:47 -0500499 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400500
501 return rc;
502
503}
504
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400505/*
506 * pass attribute values back to userspace with a service operation.
507 *
508 * We have to do a memory allocation, an sscanf and a service operation.
509 * And we have to evaluate what the user entered, to make sure the
510 * value is within the range supported by the attribute. So, there's
511 * a lot of return code checking and mapping going on here.
512 *
513 * We want to return 1 if we think everything went OK, and
514 * EINVAL if not.
515 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400516static ssize_t sysfs_service_op_store(struct kobject *kobj,
517 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400518{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500519 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400520 int val = 0;
521 int rc = 0;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400522
523 gossip_debug(GOSSIP_SYSFS_DEBUG,
524 "sysfs_service_op_store: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400525 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400526
Yi Liu8bb8aef2015-11-24 15:12:14 -0500527 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500528 if (!new_op)
529 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400530
531 /* Can't do a service_operation if the client is not running... */
532 rc = is_daemon_in_service();
533 if (rc) {
534 pr_info("%s: Client not running :%d:\n",
535 __func__,
536 is_daemon_in_service());
537 goto out;
538 }
539
540 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400541 * The value we want to send back to userspace is in buf, unless this
542 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400543 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400544 if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
545 strcmp(attr->attr.name, "readahead_count_size")) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400546 rc = kstrtoint(buf, 0, &val);
547 if (rc)
548 goto out;
549 }
550
551 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400552
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400553 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400554 /* Drop unsupported requests first. */
555 if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
Martin Brandenburgb78b1192016-09-28 14:50:46 -0400556 (!strcmp(attr->attr.name, "readahead_count") ||
557 !strcmp(attr->attr.name, "readahead_size") ||
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500558 !strcmp(attr->attr.name, "readahead_count_size") ||
559 !strcmp(attr->attr.name, "readahead_readcnt"))) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400560 rc = -EINVAL;
561 goto out;
562 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400563
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400564 if (!strcmp(attr->attr.name, "perf_history_size")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400565 if (val > 0) {
566 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500567 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400568 } else {
569 rc = 0;
570 goto out;
571 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400572 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400573 "perf_time_interval_secs")) {
574 if (val > 0) {
575 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500576 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400577 } else {
578 rc = 0;
579 goto out;
580 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400581 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400582 "perf_counter_reset")) {
583 if ((val == 0) || (val == 1)) {
584 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500585 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400586 } else {
587 rc = 0;
588 goto out;
589 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400590 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400591 "readahead_count")) {
592 if ((val >= 0)) {
593 new_op->upcall.req.param.op =
594 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
595 } else {
596 rc = 0;
597 goto out;
598 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400599 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400600 "readahead_size")) {
601 if ((val >= 0)) {
602 new_op->upcall.req.param.op =
603 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
604 } else {
605 rc = 0;
606 goto out;
607 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400608 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400609 "readahead_count_size")) {
610 int val1, val2;
611 rc = sscanf(buf, "%d %d", &val1, &val2);
612 if (rc < 2) {
613 rc = 0;
614 goto out;
615 }
616 if ((val1 >= 0) && (val2 >= 0)) {
617 new_op->upcall.req.param.op =
618 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
619 } else {
620 rc = 0;
621 goto out;
622 }
623 new_op->upcall.req.param.u.value32[0] = val1;
624 new_op->upcall.req.param.u.value32[1] = val2;
625 goto value_set;
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500626 } else if (!strcmp(attr->attr.name,
627 "readahead_readcnt")) {
628 if ((val >= 0)) {
629 new_op->upcall.req.param.op =
630 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT;
631 } else {
632 rc = 0;
633 goto out;
634 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400635 }
636
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400637 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
638 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400639 if (val > -1) {
640 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500641 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400642 } else {
643 rc = 0;
644 goto out;
645 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400646 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400647 if (val > -1) {
648 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500649 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400650 } else {
651 rc = 0;
652 goto out;
653 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400654 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400655 "reclaim_percentage")) {
656 if ((val > -1) && (val < 101)) {
657 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500658 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400659 } else {
660 rc = 0;
661 goto out;
662 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400663 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400664 if (val > -1) {
665 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500666 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400667 } else {
668 rc = 0;
669 goto out;
670 }
671 }
672
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400673 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
674 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400675 if (val > -1) {
676 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500677 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400678 } else {
679 rc = 0;
680 goto out;
681 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400682 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400683 if (val > -1) {
684 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500685 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400686 } else {
687 rc = 0;
688 goto out;
689 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400690 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400691 "reclaim_percentage")) {
692 if ((val > -1) && (val < 101)) {
693 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500694 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400695 } else {
696 rc = 0;
697 goto out;
698 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400699 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400700 if (val > -1) {
701 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500702 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400703 } else {
704 rc = 0;
705 goto out;
706 }
707 }
708
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400709 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
710 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400711 if (val > -1) {
712 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500713 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400714 } else {
715 rc = 0;
716 goto out;
717 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400718 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400719 if (val > -1) {
720 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500721 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400722 } else {
723 rc = 0;
724 goto out;
725 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400726 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400727 "reclaim_percentage")) {
728 if ((val > -1) && (val < 101)) {
729 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500730 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400731 } else {
732 rc = 0;
733 goto out;
734 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400735 } else if (!strcmp(attr->attr.name, "timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400736 if (val > -1) {
737 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500738 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400739 } else {
740 rc = 0;
741 goto out;
742 }
743 }
744
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400745 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
746 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400747 if (val > -1) {
748 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500749 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400750 } else {
751 rc = 0;
752 goto out;
753 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400754 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400755 if (val > -1) {
756 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500757 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400758 } else {
759 rc = 0;
760 goto out;
761 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400762 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400763 "reclaim_percentage")) {
764 if ((val > -1) && (val < 101)) {
765 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500766 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400767 } else {
768 rc = 0;
769 goto out;
770 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400771 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400772 if (val > -1) {
773 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500774 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400775 } else {
776 rc = 0;
777 goto out;
778 }
779 }
780
781 } else {
782 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400783 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400784 rc = -EINVAL;
785 goto out;
786 }
787
Martin Brandenburg680908e2016-08-02 16:33:34 -0400788 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400789value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400790
791 /*
792 * The service_operation will return a errno return code on
793 * error, and zero on success.
794 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500795 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400796
797 if (rc < 0) {
798 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
799 rc);
800 rc = 0;
801 } else {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400802 rc = count;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400803 }
804
805out:
Al Viroed42fe02016-01-22 19:47:47 -0500806 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400807
Al Viroed42fe02016-01-22 19:47:47 -0500808 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400809 rc = -EINVAL;
810
811 return rc;
812}
813
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400814static struct orangefs_attribute op_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400815 __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400816
817static struct orangefs_attribute slot_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400818 __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400819
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400820static struct orangefs_attribute dcache_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400821 __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400822
823static struct orangefs_attribute getattr_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400824 __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400825
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400826static struct orangefs_attribute readahead_count_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400827 __ATTR(readahead_count, 0664, sysfs_service_op_show,
828 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400829
830static struct orangefs_attribute readahead_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400831 __ATTR(readahead_size, 0664, sysfs_service_op_show,
832 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400833
834static struct orangefs_attribute readahead_count_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400835 __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
836 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400837
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500838static struct orangefs_attribute readahead_readcnt_attribute =
839 __ATTR(readahead_readcnt, 0664, sysfs_service_op_show,
840 sysfs_service_op_store);
841
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400842static struct orangefs_attribute perf_counter_reset_attribute =
843 __ATTR(perf_counter_reset,
844 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400845 sysfs_service_op_show,
846 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400847
848static struct orangefs_attribute perf_history_size_attribute =
849 __ATTR(perf_history_size,
850 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400851 sysfs_service_op_show,
852 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400853
854static struct orangefs_attribute perf_time_interval_secs_attribute =
855 __ATTR(perf_time_interval_secs,
856 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400857 sysfs_service_op_show,
858 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400859
860static struct attribute *orangefs_default_attrs[] = {
861 &op_timeout_secs_attribute.attr,
862 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400863 &dcache_timeout_msecs_attribute.attr,
864 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400865 &readahead_count_attribute.attr,
866 &readahead_size_attribute.attr,
867 &readahead_count_size_attribute.attr,
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500868 &readahead_readcnt_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400869 &perf_counter_reset_attribute.attr,
870 &perf_history_size_attribute.attr,
871 &perf_time_interval_secs_attribute.attr,
872 NULL,
873};
874
875static struct kobj_type orangefs_ktype = {
876 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400877 .default_attrs = orangefs_default_attrs,
878};
879
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400880static struct orangefs_attribute acache_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 acache_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 acache_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 acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400899 __ATTR(timeout_msecs,
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 *acache_orangefs_default_attrs[] = {
905 &acache_hard_limit_attribute.attr,
906 &acache_reclaim_percent_attribute.attr,
907 &acache_soft_limit_attribute.attr,
908 &acache_timeout_msecs_attribute.attr,
909 NULL,
910};
911
912static struct kobj_type acache_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 = acache_orangefs_default_attrs,
915};
916
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400917static struct orangefs_attribute capcache_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 capcache_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 capcache_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 capcache_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 *capcache_orangefs_default_attrs[] = {
942 &capcache_hard_limit_attribute.attr,
943 &capcache_reclaim_percent_attribute.attr,
944 &capcache_soft_limit_attribute.attr,
945 &capcache_timeout_secs_attribute.attr,
946 NULL,
947};
948
949static struct kobj_type capcache_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 = capcache_orangefs_default_attrs,
952};
953
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400954static struct orangefs_attribute ccache_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 ccache_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 ccache_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 ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400973 __ATTR(timeout_secs,
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 *ccache_orangefs_default_attrs[] = {
979 &ccache_hard_limit_attribute.attr,
980 &ccache_reclaim_percent_attribute.attr,
981 &ccache_soft_limit_attribute.attr,
982 &ccache_timeout_secs_attribute.attr,
983 NULL,
984};
985
986static struct kobj_type ccache_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 = ccache_orangefs_default_attrs,
989};
990
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400991static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400992 __ATTR(hard_limit,
993 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400994 sysfs_service_op_show,
995 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400996
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400997static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400998 __ATTR(reclaim_percentage,
999 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001000 sysfs_service_op_show,
1001 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001002
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001003static struct orangefs_attribute ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001004 __ATTR(soft_limit,
1005 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001006 sysfs_service_op_show,
1007 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001008
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001009static struct orangefs_attribute ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001010 __ATTR(timeout_msecs,
1011 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001012 sysfs_service_op_show,
1013 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001014
1015static struct attribute *ncache_orangefs_default_attrs[] = {
1016 &ncache_hard_limit_attribute.attr,
1017 &ncache_reclaim_percent_attribute.attr,
1018 &ncache_soft_limit_attribute.attr,
1019 &ncache_timeout_msecs_attribute.attr,
1020 NULL,
1021};
1022
1023static struct kobj_type ncache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001024 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001025 .default_attrs = ncache_orangefs_default_attrs,
1026};
1027
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001028static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001029 __ATTR(acache,
1030 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001031 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001032 NULL);
1033
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001034static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001035 __ATTR(capcache,
1036 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001037 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001038 NULL);
1039
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001040static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001041 __ATTR(ncache,
1042 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001043 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001044 NULL);
1045
1046static struct attribute *pc_orangefs_default_attrs[] = {
1047 &pc_acache_attribute.attr,
1048 &pc_capcache_attribute.attr,
1049 &pc_ncache_attribute.attr,
1050 NULL,
1051};
1052
1053static struct kobj_type pc_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001054 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001055 .default_attrs = pc_orangefs_default_attrs,
1056};
1057
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001058static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001059 __ATTR(reads,
1060 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001061 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001062 NULL);
1063
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001064static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001065 __ATTR(writes,
1066 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001067 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001068 NULL);
1069
1070static struct attribute *stats_orangefs_default_attrs[] = {
1071 &stats_reads_attribute.attr,
1072 &stats_writes_attribute.attr,
1073 NULL,
1074};
1075
1076static struct kobj_type stats_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001077 .sysfs_ops = &orangefs_sysfs_ops,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001078 .default_attrs = stats_orangefs_default_attrs,
1079};
1080
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001081static struct kobject *orangefs_obj;
1082static struct kobject *acache_orangefs_obj;
1083static struct kobject *capcache_orangefs_obj;
1084static struct kobject *ccache_orangefs_obj;
1085static struct kobject *ncache_orangefs_obj;
1086static struct kobject *pc_orangefs_obj;
1087static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001088
1089int orangefs_sysfs_init(void)
1090{
Mike Marshall2180c522016-03-14 15:30:39 -04001091 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001092
1093 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1094
1095 /* create /sys/fs/orangefs. */
1096 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001097 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001098 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001099
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001100 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001101 &orangefs_ktype,
1102 fs_kobj,
1103 ORANGEFS_KOBJ_ID);
1104
Mike Marshall2180c522016-03-14 15:30:39 -04001105 if (rc)
1106 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001107
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001108 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001109
1110 /* create /sys/fs/orangefs/acache. */
1111 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1112 if (!acache_orangefs_obj) {
1113 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001114 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001115 }
1116
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001117 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001118 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001119 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001120 ACACHE_KOBJ_ID);
1121
Mike Marshall2180c522016-03-14 15:30:39 -04001122 if (rc)
1123 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001124
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001125 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001126
1127 /* create /sys/fs/orangefs/capcache. */
1128 capcache_orangefs_obj =
1129 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1130 if (!capcache_orangefs_obj) {
1131 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001132 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001133 }
1134
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001135 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001136 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001137 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001138 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001139 if (rc)
1140 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001141
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001142 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001143
1144 /* create /sys/fs/orangefs/ccache. */
1145 ccache_orangefs_obj =
1146 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1147 if (!ccache_orangefs_obj) {
1148 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001149 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001150 }
1151
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001152 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001153 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001154 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001155 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001156 if (rc)
1157 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001158
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001159 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001160
1161 /* create /sys/fs/orangefs/ncache. */
1162 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1163 if (!ncache_orangefs_obj) {
1164 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001165 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001166 }
1167
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001168 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001169 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001170 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001171 NCACHE_KOBJ_ID);
1172
Mike Marshall2180c522016-03-14 15:30:39 -04001173 if (rc)
1174 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001175
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001176 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001177
1178 /* create /sys/fs/orangefs/perf_counters. */
1179 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1180 if (!pc_orangefs_obj) {
1181 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001182 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001183 }
1184
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001185 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001186 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001187 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001188 "perf_counters");
1189
Mike Marshall2180c522016-03-14 15:30:39 -04001190 if (rc)
1191 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001192
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001193 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001194
1195 /* create /sys/fs/orangefs/stats. */
1196 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1197 if (!stats_orangefs_obj) {
1198 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001199 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001200 }
1201
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001202 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001203 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001204 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001205 STATS_KOBJ_ID);
1206
Mike Marshall2180c522016-03-14 15:30:39 -04001207 if (rc)
1208 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001209
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001210 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001211 goto out;
1212
1213stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001214 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001215pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001216 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001217ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001218 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001219ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001220 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001221capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001222 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001223acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001224 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001225ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001226 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001227out:
1228 return rc;
1229}
1230
1231void orangefs_sysfs_exit(void)
1232{
1233 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001234 kobject_put(acache_orangefs_obj);
1235 kobject_put(capcache_orangefs_obj);
1236 kobject_put(ccache_orangefs_obj);
1237 kobject_put(ncache_orangefs_obj);
1238 kobject_put(pc_orangefs_obj);
1239 kobject_put(stats_orangefs_obj);
1240 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001241}