blob: de80b62553bb17ab643b389516f0ed24dfb614b2 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Mike Marshallf7be4ee2015-07-17 10:38:14 -04002/*
Mauro Carvalho Chehab44348e8a2018-06-14 12:34:32 -03003 * Documentation/ABI/stable/sysfs-fs-orangefs:
Mike Marshallf7be4ee2015-07-17 10:38:14 -04004 *
5 * What: /sys/fs/orangefs/perf_counter_reset
6 * Date: June 2015
7 * Contact: Mike Marshall <hubcap@omnibond.com>
8 * Description:
9 * echo a 0 or a 1 into perf_counter_reset to
10 * reset all the counters in
11 * /sys/fs/orangefs/perf_counters
12 * except ones with PINT_PERF_PRESERVE set.
13 *
14 *
15 * What: /sys/fs/orangefs/perf_counters/...
16 * Date: Jun 2015
17 * Contact: Mike Marshall <hubcap@omnibond.com>
18 * Description:
19 * Counters and settings for various caches.
20 * Read only.
21 *
22 *
23 * What: /sys/fs/orangefs/perf_time_interval_secs
24 * Date: Jun 2015
25 * Contact: Mike Marshall <hubcap@omnibond.com>
26 * Description:
27 * Length of perf counter intervals in
28 * seconds.
29 *
30 *
31 * What: /sys/fs/orangefs/perf_history_size
32 * Date: Jun 2015
33 * Contact: Mike Marshall <hubcap@omnibond.com>
34 * Description:
35 * The perf_counters cache statistics have N, or
36 * perf_history_size, samples. The default is
37 * one.
38 *
39 * Every perf_time_interval_secs the (first)
40 * samples are reset.
41 *
42 * If N is greater than one, the "current" set
43 * of samples is reset, and the samples from the
44 * other N-1 intervals remain available.
45 *
46 *
47 * What: /sys/fs/orangefs/op_timeout_secs
48 * Date: Jun 2015
49 * Contact: Mike Marshall <hubcap@omnibond.com>
50 * Description:
51 * Service operation timeout in seconds.
52 *
53 *
54 * What: /sys/fs/orangefs/slot_timeout_secs
55 * Date: Jun 2015
56 * Contact: Mike Marshall <hubcap@omnibond.com>
57 * Description:
58 * "Slot" timeout in seconds. A "slot"
59 * is an indexed buffer in the shared
60 * memory segment used for communication
61 * between the kernel module and userspace.
62 * Slots are requested and waited for,
63 * the wait times out after slot_timeout_secs.
64 *
Martin Brandenburg8f04e1b2019-02-12 20:19:06 +000065 * What: /sys/fs/orangefs/cache_timeout_msecs
66 * Date: Mar 2018
67 * Contact: Martin Brandenburg <martin@omnibond.com>
68 * Description:
69 * Time in milliseconds between which
70 * orangefs_revalidate_mapping will invalidate the page
71 * cache.
72 *
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040073 * What: /sys/fs/orangefs/dcache_timeout_msecs
74 * Date: Jul 2016
75 * Contact: Martin Brandenburg <martin@omnibond.com>
76 * Description:
77 * Time lookup is valid in milliseconds.
78 *
79 * What: /sys/fs/orangefs/getattr_timeout_msecs
80 * Date: Jul 2016
81 * Contact: Martin Brandenburg <martin@omnibond.com>
82 * Description:
83 * Time getattr is valid in milliseconds.
Mike Marshallf7be4ee2015-07-17 10:38:14 -040084 *
Martin Brandenburg4d20a752016-08-03 13:47:28 -040085 * What: /sys/fs/orangefs/readahead_count
86 * Date: Aug 2016
87 * Contact: Martin Brandenburg <martin@omnibond.com>
88 * Description:
89 * Readahead cache buffer count.
90 *
91 * What: /sys/fs/orangefs/readahead_size
92 * Date: Aug 2016
93 * Contact: Martin Brandenburg <martin@omnibond.com>
94 * Description:
95 * Readahead cache buffer size.
96 *
97 * What: /sys/fs/orangefs/readahead_count_size
98 * Date: Aug 2016
99 * Contact: Martin Brandenburg <martin@omnibond.com>
100 * Description:
101 * Readahead cache buffer count and size.
102 *
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500103 * What: /sys/fs/orangefs/readahead_readcnt
104 * Date: Jan 2017
105 * Contact: Martin Brandenburg <martin@omnibond.com>
106 * Description:
107 * Number of buffers (in multiples of readahead_size)
108 * which can be read ahead for a single file at once.
109 *
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400110 * What: /sys/fs/orangefs/acache/...
111 * Date: Jun 2015
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400112 * Contact: Martin Brandenburg <martin@omnibond.com>
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400113 * Description:
114 * Attribute cache configurable settings.
115 *
116 *
117 * What: /sys/fs/orangefs/ncache/...
118 * Date: Jun 2015
119 * Contact: Mike Marshall <hubcap@omnibond.com>
120 * Description:
121 * Name cache configurable settings.
122 *
123 *
124 * What: /sys/fs/orangefs/capcache/...
125 * Date: Jun 2015
126 * Contact: Mike Marshall <hubcap@omnibond.com>
127 * Description:
128 * Capability cache configurable settings.
129 *
130 *
131 * What: /sys/fs/orangefs/ccache/...
132 * Date: Jun 2015
133 * Contact: Mike Marshall <hubcap@omnibond.com>
134 * Description:
135 * Credential cache configurable settings.
136 *
137 */
138
139#include <linux/fs.h>
140#include <linux/kobject.h>
141#include <linux/string.h>
142#include <linux/sysfs.h>
143#include <linux/module.h>
144#include <linux/init.h>
145
146#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -0500147#include "orangefs-kernel.h"
148#include "orangefs-sysfs.h"
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400149
150#define ORANGEFS_KOBJ_ID "orangefs"
151#define ACACHE_KOBJ_ID "acache"
152#define CAPCACHE_KOBJ_ID "capcache"
153#define CCACHE_KOBJ_ID "ccache"
154#define NCACHE_KOBJ_ID "ncache"
155#define PC_KOBJ_ID "pc"
156#define STATS_KOBJ_ID "stats"
157
Martin Brandenburgc27889cd2016-08-15 15:11:32 -0400158/*
159 * Every item calls orangefs_attr_show and orangefs_attr_store through
160 * orangefs_sysfs_ops. They look at the orangefs_attributes further below to
161 * call one of sysfs_int_show, sysfs_int_store, sysfs_service_op_show, or
162 * sysfs_service_op_store.
163 */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400164
165struct orangefs_attribute {
166 struct attribute attr;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400167 ssize_t (*show)(struct kobject *kobj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400168 struct orangefs_attribute *attr,
169 char *buf);
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400170 ssize_t (*store)(struct kobject *kobj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400171 struct orangefs_attribute *attr,
172 const char *buf,
173 size_t count);
174};
175
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400176static ssize_t orangefs_attr_show(struct kobject *kobj,
177 struct attribute *attr,
178 char *buf)
179{
180 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400181
182 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400183 if (!attribute->show)
184 return -EIO;
185 return attribute->show(kobj, attribute, buf);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400186}
187
188static ssize_t orangefs_attr_store(struct kobject *kobj,
189 struct attribute *attr,
190 const char *buf,
191 size_t len)
192{
193 struct orangefs_attribute *attribute;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400194
Martin Brandenburg4a343662016-08-15 15:01:30 -0400195 if (!strcmp(kobj->name, PC_KOBJ_ID) ||
196 !strcmp(kobj->name, STATS_KOBJ_ID))
197 return -EPERM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400198
199 attribute = container_of(attr, struct orangefs_attribute, attr);
Martin Brandenburg4a343662016-08-15 15:01:30 -0400200 if (!attribute->store)
201 return -EIO;
202 return attribute->store(kobj, attribute, buf, len);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400203}
204
205static const struct sysfs_ops orangefs_sysfs_ops = {
206 .show = orangefs_attr_show,
207 .store = orangefs_attr_store,
208};
209
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400210static ssize_t sysfs_int_show(struct kobject *kobj,
211 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400212{
213 int rc = -EIO;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400214
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400215 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n",
216 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400217
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400218 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
219 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400220 rc = scnprintf(buf,
221 PAGE_SIZE,
222 "%d\n",
223 op_timeout_secs);
224 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400225 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400226 "slot_timeout_secs")) {
227 rc = scnprintf(buf,
228 PAGE_SIZE,
229 "%d\n",
230 slot_timeout_secs);
231 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400232 } else if (!strcmp(attr->attr.name,
Martin Brandenburg8f04e1b2019-02-12 20:19:06 +0000233 "cache_timeout_msecs")) {
234 rc = scnprintf(buf,
235 PAGE_SIZE,
236 "%d\n",
237 orangefs_cache_timeout_msecs);
238 goto out;
239 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400240 "dcache_timeout_msecs")) {
241 rc = scnprintf(buf,
242 PAGE_SIZE,
243 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400244 orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400245 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400246 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400247 "getattr_timeout_msecs")) {
248 rc = scnprintf(buf,
249 PAGE_SIZE,
250 "%d\n",
Martin Brandenburg1d503612016-08-16 11:38:14 -0400251 orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400252 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400253 } else {
254 goto out;
255 }
256
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400257 } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) {
258 if (!strcmp(attr->attr.name, "reads")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400259 rc = scnprintf(buf,
260 PAGE_SIZE,
261 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400262 orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400263 goto out;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400264 } else if (!strcmp(attr->attr.name, "writes")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400265 rc = scnprintf(buf,
266 PAGE_SIZE,
267 "%lu\n",
Martin Brandenburg889d5f12016-08-15 15:33:42 -0400268 orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400269 goto out;
270 } else {
271 goto out;
272 }
273 }
274
275out:
276
277 return rc;
278}
279
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400280static ssize_t sysfs_int_store(struct kobject *kobj,
281 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400282{
283 int rc = 0;
284
285 gossip_debug(GOSSIP_SYSFS_DEBUG,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400286 "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400287 attr->attr.name, buf);
288
289 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
290 rc = kstrtoint(buf, 0, &op_timeout_secs);
291 goto out;
292 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
293 rc = kstrtoint(buf, 0, &slot_timeout_secs);
294 goto out;
Martin Brandenburg8f04e1b2019-02-12 20:19:06 +0000295 } else if (!strcmp(attr->attr.name, "cache_timeout_msecs")) {
296 rc = kstrtoint(buf, 0, &orangefs_cache_timeout_msecs);
297 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400298 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400299 rc = kstrtoint(buf, 0, &orangefs_dcache_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400300 goto out;
301 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
Martin Brandenburg1d503612016-08-16 11:38:14 -0400302 rc = kstrtoint(buf, 0, &orangefs_getattr_timeout_msecs);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400303 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400304 } else {
305 goto out;
306 }
307
308out:
309 if (rc)
310 rc = -EINVAL;
311 else
312 rc = count;
313
314 return rc;
315}
316
317/*
318 * obtain attribute values from userspace with a service operation.
319 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400320static ssize_t sysfs_service_op_show(struct kobject *kobj,
321 struct orangefs_attribute *attr, char *buf)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400322{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500323 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400324 int rc = 0;
325 char *ser_op_type = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400326 __u32 op_alloc_type;
327
328 gossip_debug(GOSSIP_SYSFS_DEBUG,
329 "sysfs_service_op_show: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400330 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400331
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400332 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500333 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400334 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500335 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400336
337 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500338 if (!new_op)
339 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400340
341 /* Can't do a service_operation if the client is not running... */
342 rc = is_daemon_in_service();
343 if (rc) {
Colin Ian King2978d872018-09-05 15:54:01 +0100344 pr_info_ratelimited("%s: Client not running :%d:\n",
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400345 __func__,
346 is_daemon_in_service());
347 goto out;
348 }
349
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400350 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500351 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400352
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400353 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400354 /* Drop unsupported requests first. */
355 if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
Martin Brandenburgb78b1192016-09-28 14:50:46 -0400356 (!strcmp(attr->attr.name, "readahead_count") ||
357 !strcmp(attr->attr.name, "readahead_size") ||
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500358 !strcmp(attr->attr.name, "readahead_count_size") ||
359 !strcmp(attr->attr.name, "readahead_readcnt"))) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400360 rc = -EINVAL;
361 goto out;
362 }
363
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400364 if (!strcmp(attr->attr.name, "perf_history_size"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400365 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500366 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400367 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400368 "perf_time_interval_secs"))
369 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500370 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400371 else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400372 "perf_counter_reset"))
373 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500374 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400375
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400376 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400377 "readahead_count"))
378 new_op->upcall.req.param.op =
379 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
380
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400381 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400382 "readahead_size"))
383 new_op->upcall.req.param.op =
384 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
385
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400386 else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400387 "readahead_count_size"))
388 new_op->upcall.req.param.op =
389 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500390
391 else if (!strcmp(attr->attr.name,
392 "readahead_readcnt"))
393 new_op->upcall.req.param.op =
394 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT;
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400395 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
396 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400397 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500398 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400399
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400400 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400401 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500402 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400403
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400404 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400405 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500406 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400407
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400408 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400409 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500410 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400411
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400412 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
413 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400414 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500415 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400416
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400417 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400418 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500419 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400420
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400421 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400422 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500423 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400424
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400425 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400426 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500427 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400428
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400429 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
430 if (!strcmp(attr->attr.name, "timeout_secs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400431 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500432 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400433
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400434 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400435 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500436 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400437
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400438 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400439 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500440 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400441
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400442 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400443 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500444 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400445
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400446 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
447 if (!strcmp(attr->attr.name, "timeout_msecs"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400448 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500449 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400450
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400451 if (!strcmp(attr->attr.name, "hard_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400452 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500453 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400454
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400455 if (!strcmp(attr->attr.name, "soft_limit"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400456 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500457 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400458
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400459 if (!strcmp(attr->attr.name, "reclaim_percentage"))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400460 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500461 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400462
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400463 } else if (!strcmp(kobj->name, PC_KOBJ_ID)) {
464 if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400465 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500466 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400467
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400468 if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400469 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500470 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400471
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400472 if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID))
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400473 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500474 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400475
476 } else {
477 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400478 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400479 rc = -EINVAL;
480 goto out;
481 }
482
483
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400484 if (strcmp(kobj->name, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500485 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400486 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500487 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400488
489 /*
490 * The service_operation will return an errno return code on
491 * error, and zero on success.
492 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500493 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400494
495out:
496 if (!rc) {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400497 if (strcmp(kobj->name, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400498 if (new_op->upcall.req.param.op ==
499 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
500 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
501 (int)new_op->downcall.resp.param.u.
502 value32[0],
503 (int)new_op->downcall.resp.param.u.
504 value32[1]);
505 } else {
506 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
507 (int)new_op->downcall.resp.param.u.value64);
508 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400509 } else {
510 rc = scnprintf(
511 buf,
512 PAGE_SIZE,
513 "%s",
514 new_op->downcall.resp.perf_count.buffer);
515 }
516 }
517
Al Viroed42fe02016-01-22 19:47:47 -0500518 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400519
520 return rc;
521
522}
523
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400524/*
525 * pass attribute values back to userspace with a service operation.
526 *
527 * We have to do a memory allocation, an sscanf and a service operation.
528 * And we have to evaluate what the user entered, to make sure the
529 * value is within the range supported by the attribute. So, there's
530 * a lot of return code checking and mapping going on here.
531 *
532 * We want to return 1 if we think everything went OK, and
533 * EINVAL if not.
534 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400535static ssize_t sysfs_service_op_store(struct kobject *kobj,
536 struct orangefs_attribute *attr, const char *buf, size_t count)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400537{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500538 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400539 int val = 0;
540 int rc = 0;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400541
542 gossip_debug(GOSSIP_SYSFS_DEBUG,
543 "sysfs_service_op_store: id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400544 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400545
Yi Liu8bb8aef2015-11-24 15:12:14 -0500546 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -0500547 if (!new_op)
548 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400549
550 /* Can't do a service_operation if the client is not running... */
551 rc = is_daemon_in_service();
552 if (rc) {
553 pr_info("%s: Client not running :%d:\n",
554 __func__,
555 is_daemon_in_service());
556 goto out;
557 }
558
559 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400560 * The value we want to send back to userspace is in buf, unless this
561 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400562 */
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400563 if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) ||
564 strcmp(attr->attr.name, "readahead_count_size")) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400565 rc = kstrtoint(buf, 0, &val);
566 if (rc)
567 goto out;
568 }
569
570 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400571
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400572 if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400573 /* Drop unsupported requests first. */
574 if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) &&
Martin Brandenburgb78b1192016-09-28 14:50:46 -0400575 (!strcmp(attr->attr.name, "readahead_count") ||
576 !strcmp(attr->attr.name, "readahead_size") ||
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500577 !strcmp(attr->attr.name, "readahead_count_size") ||
578 !strcmp(attr->attr.name, "readahead_readcnt"))) {
Martin Brandenburgc51e0122016-08-12 16:12:09 -0400579 rc = -EINVAL;
580 goto out;
581 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400582
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400583 if (!strcmp(attr->attr.name, "perf_history_size")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400584 if (val > 0) {
585 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500586 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400587 } else {
588 rc = 0;
589 goto out;
590 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400591 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400592 "perf_time_interval_secs")) {
593 if (val > 0) {
594 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500595 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400596 } else {
597 rc = 0;
598 goto out;
599 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400600 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400601 "perf_counter_reset")) {
602 if ((val == 0) || (val == 1)) {
603 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500604 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400605 } else {
606 rc = 0;
607 goto out;
608 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400609 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400610 "readahead_count")) {
611 if ((val >= 0)) {
612 new_op->upcall.req.param.op =
613 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
614 } else {
615 rc = 0;
616 goto out;
617 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400618 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400619 "readahead_size")) {
620 if ((val >= 0)) {
621 new_op->upcall.req.param.op =
622 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
623 } else {
624 rc = 0;
625 goto out;
626 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400627 } else if (!strcmp(attr->attr.name,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400628 "readahead_count_size")) {
629 int val1, val2;
630 rc = sscanf(buf, "%d %d", &val1, &val2);
631 if (rc < 2) {
632 rc = 0;
633 goto out;
634 }
635 if ((val1 >= 0) && (val2 >= 0)) {
636 new_op->upcall.req.param.op =
637 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
638 } else {
639 rc = 0;
640 goto out;
641 }
642 new_op->upcall.req.param.u.value32[0] = val1;
643 new_op->upcall.req.param.u.value32[1] = val2;
644 goto value_set;
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500645 } else if (!strcmp(attr->attr.name,
646 "readahead_readcnt")) {
647 if ((val >= 0)) {
648 new_op->upcall.req.param.op =
649 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT;
650 } else {
651 rc = 0;
652 goto out;
653 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400654 }
655
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400656 } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) {
657 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400658 if (val > -1) {
659 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500660 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400661 } else {
662 rc = 0;
663 goto out;
664 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400665 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400666 if (val > -1) {
667 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500668 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400669 } else {
670 rc = 0;
671 goto out;
672 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400673 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400674 "reclaim_percentage")) {
675 if ((val > -1) && (val < 101)) {
676 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500677 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
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, "timeout_msecs")) {
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_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400686 } else {
687 rc = 0;
688 goto out;
689 }
690 }
691
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400692 } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) {
693 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400694 if (val > -1) {
695 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500696 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400697 } else {
698 rc = 0;
699 goto out;
700 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400701 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400702 if (val > -1) {
703 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500704 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400705 } else {
706 rc = 0;
707 goto out;
708 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400709 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400710 "reclaim_percentage")) {
711 if ((val > -1) && (val < 101)) {
712 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500713 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
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, "timeout_secs")) {
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_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400722 } else {
723 rc = 0;
724 goto out;
725 }
726 }
727
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400728 } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) {
729 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400730 if (val > -1) {
731 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500732 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400733 } else {
734 rc = 0;
735 goto out;
736 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400737 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400738 if (val > -1) {
739 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500740 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400741 } else {
742 rc = 0;
743 goto out;
744 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400745 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400746 "reclaim_percentage")) {
747 if ((val > -1) && (val < 101)) {
748 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500749 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
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, "timeout_secs")) {
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_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400758 } else {
759 rc = 0;
760 goto out;
761 }
762 }
763
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400764 } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) {
765 if (!strcmp(attr->attr.name, "hard_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400766 if (val > -1) {
767 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500768 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400769 } else {
770 rc = 0;
771 goto out;
772 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400773 } else if (!strcmp(attr->attr.name, "soft_limit")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400774 if (val > -1) {
775 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500776 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400777 } else {
778 rc = 0;
779 goto out;
780 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400781 } else if (!strcmp(attr->attr.name,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400782 "reclaim_percentage")) {
783 if ((val > -1) && (val < 101)) {
784 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500785 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400786 } else {
787 rc = 0;
788 goto out;
789 }
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400790 } else if (!strcmp(attr->attr.name, "timeout_msecs")) {
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400791 if (val > -1) {
792 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500793 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400794 } else {
795 rc = 0;
796 goto out;
797 }
798 }
799
800 } else {
801 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400802 kobj->name);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400803 rc = -EINVAL;
804 goto out;
805 }
806
Martin Brandenburg680908e2016-08-02 16:33:34 -0400807 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400808value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400809
810 /*
811 * The service_operation will return a errno return code on
812 * error, and zero on success.
813 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500814 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400815
816 if (rc < 0) {
817 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
818 rc);
819 rc = 0;
820 } else {
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400821 rc = count;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400822 }
823
824out:
Al Viroed42fe02016-01-22 19:47:47 -0500825 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400826
Al Viroed42fe02016-01-22 19:47:47 -0500827 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400828 rc = -EINVAL;
829
830 return rc;
831}
832
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400833static struct orangefs_attribute op_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400834 __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400835
836static struct orangefs_attribute slot_timeout_secs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400837 __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400838
Martin Brandenburg8f04e1b2019-02-12 20:19:06 +0000839static struct orangefs_attribute cache_timeout_msecs_attribute =
840 __ATTR(cache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
841
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400842static struct orangefs_attribute dcache_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400843 __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400844
845static struct orangefs_attribute getattr_timeout_msecs_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400846 __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store);
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400847
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400848static struct orangefs_attribute readahead_count_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400849 __ATTR(readahead_count, 0664, sysfs_service_op_show,
850 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400851
852static struct orangefs_attribute readahead_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400853 __ATTR(readahead_size, 0664, sysfs_service_op_show,
854 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400855
856static struct orangefs_attribute readahead_count_size_attribute =
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400857 __ATTR(readahead_count_size, 0664, sysfs_service_op_show,
858 sysfs_service_op_store);
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400859
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500860static struct orangefs_attribute readahead_readcnt_attribute =
861 __ATTR(readahead_readcnt, 0664, sysfs_service_op_show,
862 sysfs_service_op_store);
863
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400864static struct orangefs_attribute perf_counter_reset_attribute =
865 __ATTR(perf_counter_reset,
866 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400867 sysfs_service_op_show,
868 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400869
870static struct orangefs_attribute perf_history_size_attribute =
871 __ATTR(perf_history_size,
872 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400873 sysfs_service_op_show,
874 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400875
876static struct orangefs_attribute perf_time_interval_secs_attribute =
877 __ATTR(perf_time_interval_secs,
878 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400879 sysfs_service_op_show,
880 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400881
882static struct attribute *orangefs_default_attrs[] = {
883 &op_timeout_secs_attribute.attr,
884 &slot_timeout_secs_attribute.attr,
Martin Brandenburg8f04e1b2019-02-12 20:19:06 +0000885 &cache_timeout_msecs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400886 &dcache_timeout_msecs_attribute.attr,
887 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400888 &readahead_count_attribute.attr,
889 &readahead_size_attribute.attr,
890 &readahead_count_size_attribute.attr,
Martin Brandenburg31c829f2017-01-26 10:25:30 -0500891 &readahead_readcnt_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400892 &perf_counter_reset_attribute.attr,
893 &perf_history_size_attribute.attr,
894 &perf_time_interval_secs_attribute.attr,
895 NULL,
896};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +0100897ATTRIBUTE_GROUPS(orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400898
899static struct kobj_type orangefs_ktype = {
900 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +0100901 .default_groups = orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400902};
903
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400904static struct orangefs_attribute acache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400905 __ATTR(hard_limit,
906 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400907 sysfs_service_op_show,
908 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400909
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400910static struct orangefs_attribute acache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400911 __ATTR(reclaim_percentage,
912 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400913 sysfs_service_op_show,
914 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400915
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400916static struct orangefs_attribute acache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400917 __ATTR(soft_limit,
918 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400919 sysfs_service_op_show,
920 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400921
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400922static struct orangefs_attribute acache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400923 __ATTR(timeout_msecs,
924 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400925 sysfs_service_op_show,
926 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400927
928static struct attribute *acache_orangefs_default_attrs[] = {
929 &acache_hard_limit_attribute.attr,
930 &acache_reclaim_percent_attribute.attr,
931 &acache_soft_limit_attribute.attr,
932 &acache_timeout_msecs_attribute.attr,
933 NULL,
934};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +0100935ATTRIBUTE_GROUPS(acache_orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400936
937static struct kobj_type acache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400938 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +0100939 .default_groups = acache_orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400940};
941
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400942static struct orangefs_attribute capcache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400943 __ATTR(hard_limit,
944 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400945 sysfs_service_op_show,
946 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400947
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400948static struct orangefs_attribute capcache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400949 __ATTR(reclaim_percentage,
950 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400951 sysfs_service_op_show,
952 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400953
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400954static struct orangefs_attribute capcache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400955 __ATTR(soft_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 capcache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400961 __ATTR(timeout_secs,
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
966static struct attribute *capcache_orangefs_default_attrs[] = {
967 &capcache_hard_limit_attribute.attr,
968 &capcache_reclaim_percent_attribute.attr,
969 &capcache_soft_limit_attribute.attr,
970 &capcache_timeout_secs_attribute.attr,
971 NULL,
972};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +0100973ATTRIBUTE_GROUPS(capcache_orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400974
975static struct kobj_type capcache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -0400976 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +0100977 .default_groups = capcache_orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400978};
979
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400980static struct orangefs_attribute ccache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400981 __ATTR(hard_limit,
982 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400983 sysfs_service_op_show,
984 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400985
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400986static struct orangefs_attribute ccache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400987 __ATTR(reclaim_percentage,
988 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400989 sysfs_service_op_show,
990 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400991
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400992static struct orangefs_attribute ccache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400993 __ATTR(soft_limit,
994 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -0400995 sysfs_service_op_show,
996 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400997
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -0400998static struct orangefs_attribute ccache_timeout_secs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400999 __ATTR(timeout_secs,
1000 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001001 sysfs_service_op_show,
1002 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001003
1004static struct attribute *ccache_orangefs_default_attrs[] = {
1005 &ccache_hard_limit_attribute.attr,
1006 &ccache_reclaim_percent_attribute.attr,
1007 &ccache_soft_limit_attribute.attr,
1008 &ccache_timeout_secs_attribute.attr,
1009 NULL,
1010};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001011ATTRIBUTE_GROUPS(ccache_orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001012
1013static struct kobj_type ccache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001014 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001015 .default_groups = ccache_orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001016};
1017
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001018static struct orangefs_attribute ncache_hard_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001019 __ATTR(hard_limit,
1020 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001021 sysfs_service_op_show,
1022 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001023
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001024static struct orangefs_attribute ncache_reclaim_percent_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001025 __ATTR(reclaim_percentage,
1026 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001027 sysfs_service_op_show,
1028 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001029
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001030static struct orangefs_attribute ncache_soft_limit_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001031 __ATTR(soft_limit,
1032 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001033 sysfs_service_op_show,
1034 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001035
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001036static struct orangefs_attribute ncache_timeout_msecs_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001037 __ATTR(timeout_msecs,
1038 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001039 sysfs_service_op_show,
1040 sysfs_service_op_store);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001041
1042static struct attribute *ncache_orangefs_default_attrs[] = {
1043 &ncache_hard_limit_attribute.attr,
1044 &ncache_reclaim_percent_attribute.attr,
1045 &ncache_soft_limit_attribute.attr,
1046 &ncache_timeout_msecs_attribute.attr,
1047 NULL,
1048};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001049ATTRIBUTE_GROUPS(ncache_orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001050
1051static struct kobj_type ncache_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001052 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001053 .default_groups = ncache_orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001054};
1055
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001056static struct orangefs_attribute pc_acache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001057 __ATTR(acache,
1058 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001059 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001060 NULL);
1061
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001062static struct orangefs_attribute pc_capcache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001063 __ATTR(capcache,
1064 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001065 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001066 NULL);
1067
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001068static struct orangefs_attribute pc_ncache_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001069 __ATTR(ncache,
1070 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001071 sysfs_service_op_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001072 NULL);
1073
1074static struct attribute *pc_orangefs_default_attrs[] = {
1075 &pc_acache_attribute.attr,
1076 &pc_capcache_attribute.attr,
1077 &pc_ncache_attribute.attr,
1078 NULL,
1079};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001080ATTRIBUTE_GROUPS(pc_orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001081
1082static struct kobj_type pc_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001083 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001084 .default_groups = pc_orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001085};
1086
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001087static struct orangefs_attribute stats_reads_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001088 __ATTR(reads,
1089 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001090 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001091 NULL);
1092
Martin Brandenburg2e9f80d2016-08-15 14:02:39 -04001093static struct orangefs_attribute stats_writes_attribute =
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001094 __ATTR(writes,
1095 0664,
Martin Brandenburg7b0cae62016-08-15 14:51:31 -04001096 sysfs_int_show,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001097 NULL);
1098
1099static struct attribute *stats_orangefs_default_attrs[] = {
1100 &stats_reads_attribute.attr,
1101 &stats_writes_attribute.attr,
1102 NULL,
1103};
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001104ATTRIBUTE_GROUPS(stats_orangefs_default);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001105
1106static struct kobj_type stats_orangefs_ktype = {
Martin Brandenburg4a343662016-08-15 15:01:30 -04001107 .sysfs_ops = &orangefs_sysfs_ops,
Greg Kroah-Hartman063e4582021-12-28 15:44:07 +01001108 .default_groups = stats_orangefs_default_groups,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001109};
1110
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001111static struct kobject *orangefs_obj;
1112static struct kobject *acache_orangefs_obj;
1113static struct kobject *capcache_orangefs_obj;
1114static struct kobject *ccache_orangefs_obj;
1115static struct kobject *ncache_orangefs_obj;
1116static struct kobject *pc_orangefs_obj;
1117static struct kobject *stats_orangefs_obj;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001118
1119int orangefs_sysfs_init(void)
1120{
Mike Marshall2180c522016-03-14 15:30:39 -04001121 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001122
1123 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1124
1125 /* create /sys/fs/orangefs. */
1126 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001127 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001128 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001129
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001130 rc = kobject_init_and_add(orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001131 &orangefs_ktype,
1132 fs_kobj,
1133 ORANGEFS_KOBJ_ID);
1134
Mike Marshall2180c522016-03-14 15:30:39 -04001135 if (rc)
1136 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001137
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001138 kobject_uevent(orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001139
1140 /* create /sys/fs/orangefs/acache. */
1141 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1142 if (!acache_orangefs_obj) {
1143 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001144 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001145 }
1146
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001147 rc = kobject_init_and_add(acache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001148 &acache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001149 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001150 ACACHE_KOBJ_ID);
1151
Mike Marshall2180c522016-03-14 15:30:39 -04001152 if (rc)
1153 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001154
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001155 kobject_uevent(acache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001156
1157 /* create /sys/fs/orangefs/capcache. */
1158 capcache_orangefs_obj =
1159 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1160 if (!capcache_orangefs_obj) {
1161 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001162 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001163 }
1164
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001165 rc = kobject_init_and_add(capcache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001166 &capcache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001167 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001168 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001169 if (rc)
1170 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001171
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001172 kobject_uevent(capcache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001173
1174 /* create /sys/fs/orangefs/ccache. */
1175 ccache_orangefs_obj =
1176 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1177 if (!ccache_orangefs_obj) {
1178 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001179 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001180 }
1181
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001182 rc = kobject_init_and_add(ccache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001183 &ccache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001184 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001185 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001186 if (rc)
1187 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001188
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001189 kobject_uevent(ccache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001190
1191 /* create /sys/fs/orangefs/ncache. */
1192 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1193 if (!ncache_orangefs_obj) {
1194 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001195 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001196 }
1197
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001198 rc = kobject_init_and_add(ncache_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001199 &ncache_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001200 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001201 NCACHE_KOBJ_ID);
1202
Mike Marshall2180c522016-03-14 15:30:39 -04001203 if (rc)
1204 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001205
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001206 kobject_uevent(ncache_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001207
1208 /* create /sys/fs/orangefs/perf_counters. */
1209 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1210 if (!pc_orangefs_obj) {
1211 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001212 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001213 }
1214
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001215 rc = kobject_init_and_add(pc_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001216 &pc_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001217 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001218 "perf_counters");
1219
Mike Marshall2180c522016-03-14 15:30:39 -04001220 if (rc)
1221 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001222
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001223 kobject_uevent(pc_orangefs_obj, KOBJ_ADD);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001224
1225 /* create /sys/fs/orangefs/stats. */
1226 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1227 if (!stats_orangefs_obj) {
1228 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001229 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001230 }
1231
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001232 rc = kobject_init_and_add(stats_orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001233 &stats_orangefs_ktype,
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001234 orangefs_obj,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001235 STATS_KOBJ_ID);
1236
Mike Marshall2180c522016-03-14 15:30:39 -04001237 if (rc)
1238 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001239
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001240 kobject_uevent(stats_orangefs_obj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001241 goto out;
1242
1243stats_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001244 kobject_put(stats_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001245pc_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001246 kobject_put(pc_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001247ncache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001248 kobject_put(ncache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001249ccache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001250 kobject_put(ccache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001251capcache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001252 kobject_put(capcache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001253acache_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001254 kobject_put(acache_orangefs_obj);
Mike Marshall2180c522016-03-14 15:30:39 -04001255ofs_obj_bail:
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001256 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001257out:
1258 return rc;
1259}
1260
1261void orangefs_sysfs_exit(void)
1262{
1263 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
Martin Brandenburgdc3012a2016-08-15 13:28:51 -04001264 kobject_put(acache_orangefs_obj);
1265 kobject_put(capcache_orangefs_obj);
1266 kobject_put(ccache_orangefs_obj);
1267 kobject_put(ncache_orangefs_obj);
1268 kobject_put(pc_orangefs_obj);
1269 kobject_put(stats_orangefs_obj);
1270 kobject_put(orangefs_obj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001271}