Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
f7be4ee0 | 2 | /* |
44348e8a | 3 | * Documentation/ABI/stable/sysfs-fs-orangefs: |
f7be4ee0 MM |
4 | * |
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 | * | |
8f04e1be MB |
65 | * 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 | * | |
4cd8f319 MB |
73 | * 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. | |
f7be4ee0 | 84 | * |
4d20a756 MB |
85 | * 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 | * | |
31c829f3 MB |
103 | * 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 | * | |
f7be4ee0 MM |
110 | * What: /sys/fs/orangefs/acache/... |
111 | * Date: Jun 2015 | |
4cd8f319 | 112 | * Contact: Martin Brandenburg <martin@omnibond.com> |
f7be4ee0 MM |
113 | * 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" | |
575e9461 MM |
147 | #include "orangefs-kernel.h" |
148 | #include "orangefs-sysfs.h" | |
f7be4ee0 MM |
149 | |
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 | ||
c27889cd MB |
158 | /* |
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 | */ | |
f7be4ee0 MM |
164 | |
165 | struct orangefs_attribute { | |
166 | struct attribute attr; | |
7b0cae60 | 167 | ssize_t (*show)(struct kobject *kobj, |
f7be4ee0 MM |
168 | struct orangefs_attribute *attr, |
169 | char *buf); | |
7b0cae60 | 170 | ssize_t (*store)(struct kobject *kobj, |
f7be4ee0 MM |
171 | struct orangefs_attribute *attr, |
172 | const char *buf, | |
173 | size_t count); | |
174 | }; | |
175 | ||
f7be4ee0 MM |
176 | static ssize_t orangefs_attr_show(struct kobject *kobj, |
177 | struct attribute *attr, | |
178 | char *buf) | |
179 | { | |
180 | struct orangefs_attribute *attribute; | |
f7be4ee0 MM |
181 | |
182 | attribute = container_of(attr, struct orangefs_attribute, attr); | |
4a343664 MB |
183 | if (!attribute->show) |
184 | return -EIO; | |
185 | return attribute->show(kobj, attribute, buf); | |
f7be4ee0 MM |
186 | } |
187 | ||
188 | static 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; | |
f7be4ee0 | 194 | |
4a343664 MB |
195 | if (!strcmp(kobj->name, PC_KOBJ_ID) || |
196 | !strcmp(kobj->name, STATS_KOBJ_ID)) | |
197 | return -EPERM; | |
f7be4ee0 MM |
198 | |
199 | attribute = container_of(attr, struct orangefs_attribute, attr); | |
4a343664 MB |
200 | if (!attribute->store) |
201 | return -EIO; | |
202 | return attribute->store(kobj, attribute, buf, len); | |
f7be4ee0 MM |
203 | } |
204 | ||
205 | static const struct sysfs_ops orangefs_sysfs_ops = { | |
206 | .show = orangefs_attr_show, | |
207 | .store = orangefs_attr_store, | |
208 | }; | |
209 | ||
7b0cae60 MB |
210 | static ssize_t sysfs_int_show(struct kobject *kobj, |
211 | struct orangefs_attribute *attr, char *buf) | |
f7be4ee0 MM |
212 | { |
213 | int rc = -EIO; | |
f7be4ee0 | 214 | |
7b0cae60 MB |
215 | gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n", |
216 | kobj->name); | |
f7be4ee0 | 217 | |
7b0cae60 MB |
218 | if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) { |
219 | if (!strcmp(attr->attr.name, "op_timeout_secs")) { | |
f7be4ee0 MM |
220 | rc = scnprintf(buf, |
221 | PAGE_SIZE, | |
222 | "%d\n", | |
223 | op_timeout_secs); | |
224 | goto out; | |
7b0cae60 | 225 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
226 | "slot_timeout_secs")) { |
227 | rc = scnprintf(buf, | |
228 | PAGE_SIZE, | |
229 | "%d\n", | |
230 | slot_timeout_secs); | |
231 | goto out; | |
8f04e1be MB |
232 | } else if (!strcmp(attr->attr.name, |
233 | "cache_timeout_msecs")) { | |
234 | rc = scnprintf(buf, | |
235 | PAGE_SIZE, | |
236 | "%d\n", | |
237 | orangefs_cache_timeout_msecs); | |
238 | goto out; | |
7b0cae60 | 239 | } else if (!strcmp(attr->attr.name, |
4cd8f319 MB |
240 | "dcache_timeout_msecs")) { |
241 | rc = scnprintf(buf, | |
242 | PAGE_SIZE, | |
243 | "%d\n", | |
1d503617 | 244 | orangefs_dcache_timeout_msecs); |
4cd8f319 | 245 | goto out; |
7b0cae60 | 246 | } else if (!strcmp(attr->attr.name, |
4cd8f319 MB |
247 | "getattr_timeout_msecs")) { |
248 | rc = scnprintf(buf, | |
249 | PAGE_SIZE, | |
250 | "%d\n", | |
1d503617 | 251 | orangefs_getattr_timeout_msecs); |
4cd8f319 | 252 | goto out; |
f7be4ee0 MM |
253 | } else { |
254 | goto out; | |
255 | } | |
256 | ||
7b0cae60 MB |
257 | } else if (!strcmp(kobj->name, STATS_KOBJ_ID)) { |
258 | if (!strcmp(attr->attr.name, "reads")) { | |
f7be4ee0 MM |
259 | rc = scnprintf(buf, |
260 | PAGE_SIZE, | |
261 | "%lu\n", | |
889d5f1b | 262 | orangefs_stats.reads); |
f7be4ee0 | 263 | goto out; |
7b0cae60 | 264 | } else if (!strcmp(attr->attr.name, "writes")) { |
f7be4ee0 MM |
265 | rc = scnprintf(buf, |
266 | PAGE_SIZE, | |
267 | "%lu\n", | |
889d5f1b | 268 | orangefs_stats.writes); |
f7be4ee0 MM |
269 | goto out; |
270 | } else { | |
271 | goto out; | |
272 | } | |
273 | } | |
274 | ||
275 | out: | |
276 | ||
277 | return rc; | |
278 | } | |
279 | ||
7b0cae60 MB |
280 | static ssize_t sysfs_int_store(struct kobject *kobj, |
281 | struct orangefs_attribute *attr, const char *buf, size_t count) | |
f7be4ee0 MM |
282 | { |
283 | int rc = 0; | |
284 | ||
285 | gossip_debug(GOSSIP_SYSFS_DEBUG, | |
7b0cae60 | 286 | "sysfs_int_store: start attr->attr.name:%s: buf:%s:\n", |
f7be4ee0 MM |
287 | 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; | |
8f04e1be MB |
295 | } else if (!strcmp(attr->attr.name, "cache_timeout_msecs")) { |
296 | rc = kstrtoint(buf, 0, &orangefs_cache_timeout_msecs); | |
297 | goto out; | |
4cd8f319 | 298 | } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) { |
1d503617 | 299 | rc = kstrtoint(buf, 0, &orangefs_dcache_timeout_msecs); |
4cd8f319 MB |
300 | goto out; |
301 | } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) { | |
1d503617 | 302 | rc = kstrtoint(buf, 0, &orangefs_getattr_timeout_msecs); |
4cd8f319 | 303 | goto out; |
f7be4ee0 MM |
304 | } else { |
305 | goto out; | |
306 | } | |
307 | ||
308 | out: | |
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 | */ | |
7b0cae60 MB |
320 | static ssize_t sysfs_service_op_show(struct kobject *kobj, |
321 | struct orangefs_attribute *attr, char *buf) | |
f7be4ee0 | 322 | { |
8bb8aefd | 323 | struct orangefs_kernel_op_s *new_op = NULL; |
f7be4ee0 MM |
324 | int rc = 0; |
325 | char *ser_op_type = NULL; | |
f7be4ee0 MM |
326 | __u32 op_alloc_type; |
327 | ||
328 | gossip_debug(GOSSIP_SYSFS_DEBUG, | |
329 | "sysfs_service_op_show: id:%s:\n", | |
7b0cae60 | 330 | kobj->name); |
f7be4ee0 | 331 | |
7b0cae60 | 332 | if (strcmp(kobj->name, PC_KOBJ_ID)) |
8bb8aefd | 333 | op_alloc_type = ORANGEFS_VFS_OP_PARAM; |
f7be4ee0 | 334 | else |
8bb8aefd | 335 | op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT; |
f7be4ee0 MM |
336 | |
337 | new_op = op_alloc(op_alloc_type); | |
ed42fe05 AV |
338 | if (!new_op) |
339 | return -ENOMEM; | |
f7be4ee0 MM |
340 | |
341 | /* Can't do a service_operation if the client is not running... */ | |
342 | rc = is_daemon_in_service(); | |
343 | if (rc) { | |
2978d873 | 344 | pr_info_ratelimited("%s: Client not running :%d:\n", |
f7be4ee0 MM |
345 | __func__, |
346 | is_daemon_in_service()); | |
347 | goto out; | |
348 | } | |
349 | ||
7b0cae60 | 350 | if (strcmp(kobj->name, PC_KOBJ_ID)) |
8bb8aefd | 351 | new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET; |
f7be4ee0 | 352 | |
7b0cae60 | 353 | if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) { |
c51e0129 MB |
354 | /* Drop unsupported requests first. */ |
355 | if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) && | |
b78b1198 MB |
356 | (!strcmp(attr->attr.name, "readahead_count") || |
357 | !strcmp(attr->attr.name, "readahead_size") || | |
31c829f3 MB |
358 | !strcmp(attr->attr.name, "readahead_count_size") || |
359 | !strcmp(attr->attr.name, "readahead_readcnt"))) { | |
c51e0129 MB |
360 | rc = -EINVAL; |
361 | goto out; | |
362 | } | |
363 | ||
7b0cae60 | 364 | if (!strcmp(attr->attr.name, "perf_history_size")) |
f7be4ee0 | 365 | new_op->upcall.req.param.op = |
8bb8aefd | 366 | ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE; |
7b0cae60 | 367 | else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
368 | "perf_time_interval_secs")) |
369 | new_op->upcall.req.param.op = | |
8bb8aefd | 370 | ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS; |
7b0cae60 | 371 | else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
372 | "perf_counter_reset")) |
373 | new_op->upcall.req.param.op = | |
8bb8aefd | 374 | ORANGEFS_PARAM_REQUEST_OP_PERF_RESET; |
f7be4ee0 | 375 | |
7b0cae60 | 376 | else if (!strcmp(attr->attr.name, |
4d20a756 MB |
377 | "readahead_count")) |
378 | new_op->upcall.req.param.op = | |
379 | ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT; | |
380 | ||
7b0cae60 | 381 | else if (!strcmp(attr->attr.name, |
4d20a756 MB |
382 | "readahead_size")) |
383 | new_op->upcall.req.param.op = | |
384 | ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE; | |
385 | ||
7b0cae60 | 386 | else if (!strcmp(attr->attr.name, |
4d20a756 MB |
387 | "readahead_count_size")) |
388 | new_op->upcall.req.param.op = | |
389 | ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE; | |
31c829f3 MB |
390 | |
391 | else if (!strcmp(attr->attr.name, | |
392 | "readahead_readcnt")) | |
393 | new_op->upcall.req.param.op = | |
394 | ORANGEFS_PARAM_REQUEST_OP_READAHEAD_READCNT; | |
7b0cae60 MB |
395 | } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) { |
396 | if (!strcmp(attr->attr.name, "timeout_msecs")) | |
f7be4ee0 | 397 | new_op->upcall.req.param.op = |
8bb8aefd | 398 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS; |
f7be4ee0 | 399 | |
7b0cae60 | 400 | if (!strcmp(attr->attr.name, "hard_limit")) |
f7be4ee0 | 401 | new_op->upcall.req.param.op = |
8bb8aefd | 402 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT; |
f7be4ee0 | 403 | |
7b0cae60 | 404 | if (!strcmp(attr->attr.name, "soft_limit")) |
f7be4ee0 | 405 | new_op->upcall.req.param.op = |
8bb8aefd | 406 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT; |
f7be4ee0 | 407 | |
7b0cae60 | 408 | if (!strcmp(attr->attr.name, "reclaim_percentage")) |
f7be4ee0 | 409 | new_op->upcall.req.param.op = |
8bb8aefd | 410 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 | 411 | |
7b0cae60 MB |
412 | } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) { |
413 | if (!strcmp(attr->attr.name, "timeout_secs")) | |
f7be4ee0 | 414 | new_op->upcall.req.param.op = |
8bb8aefd | 415 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS; |
f7be4ee0 | 416 | |
7b0cae60 | 417 | if (!strcmp(attr->attr.name, "hard_limit")) |
f7be4ee0 | 418 | new_op->upcall.req.param.op = |
8bb8aefd | 419 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT; |
f7be4ee0 | 420 | |
7b0cae60 | 421 | if (!strcmp(attr->attr.name, "soft_limit")) |
f7be4ee0 | 422 | new_op->upcall.req.param.op = |
8bb8aefd | 423 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT; |
f7be4ee0 | 424 | |
7b0cae60 | 425 | if (!strcmp(attr->attr.name, "reclaim_percentage")) |
f7be4ee0 | 426 | new_op->upcall.req.param.op = |
8bb8aefd | 427 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 | 428 | |
7b0cae60 MB |
429 | } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) { |
430 | if (!strcmp(attr->attr.name, "timeout_secs")) | |
f7be4ee0 | 431 | new_op->upcall.req.param.op = |
8bb8aefd | 432 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS; |
f7be4ee0 | 433 | |
7b0cae60 | 434 | if (!strcmp(attr->attr.name, "hard_limit")) |
f7be4ee0 | 435 | new_op->upcall.req.param.op = |
8bb8aefd | 436 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT; |
f7be4ee0 | 437 | |
7b0cae60 | 438 | if (!strcmp(attr->attr.name, "soft_limit")) |
f7be4ee0 | 439 | new_op->upcall.req.param.op = |
8bb8aefd | 440 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT; |
f7be4ee0 | 441 | |
7b0cae60 | 442 | if (!strcmp(attr->attr.name, "reclaim_percentage")) |
f7be4ee0 | 443 | new_op->upcall.req.param.op = |
8bb8aefd | 444 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 | 445 | |
7b0cae60 MB |
446 | } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) { |
447 | if (!strcmp(attr->attr.name, "timeout_msecs")) | |
f7be4ee0 | 448 | new_op->upcall.req.param.op = |
8bb8aefd | 449 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS; |
f7be4ee0 | 450 | |
7b0cae60 | 451 | if (!strcmp(attr->attr.name, "hard_limit")) |
f7be4ee0 | 452 | new_op->upcall.req.param.op = |
8bb8aefd | 453 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT; |
f7be4ee0 | 454 | |
7b0cae60 | 455 | if (!strcmp(attr->attr.name, "soft_limit")) |
f7be4ee0 | 456 | new_op->upcall.req.param.op = |
8bb8aefd | 457 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT; |
f7be4ee0 | 458 | |
7b0cae60 | 459 | if (!strcmp(attr->attr.name, "reclaim_percentage")) |
f7be4ee0 | 460 | new_op->upcall.req.param.op = |
8bb8aefd | 461 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 | 462 | |
7b0cae60 MB |
463 | } else if (!strcmp(kobj->name, PC_KOBJ_ID)) { |
464 | if (!strcmp(attr->attr.name, ACACHE_KOBJ_ID)) | |
f7be4ee0 | 465 | new_op->upcall.req.perf_count.type = |
8bb8aefd | 466 | ORANGEFS_PERF_COUNT_REQUEST_ACACHE; |
f7be4ee0 | 467 | |
7b0cae60 | 468 | if (!strcmp(attr->attr.name, CAPCACHE_KOBJ_ID)) |
f7be4ee0 | 469 | new_op->upcall.req.perf_count.type = |
8bb8aefd | 470 | ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE; |
f7be4ee0 | 471 | |
7b0cae60 | 472 | if (!strcmp(attr->attr.name, NCACHE_KOBJ_ID)) |
f7be4ee0 | 473 | new_op->upcall.req.perf_count.type = |
8bb8aefd | 474 | ORANGEFS_PERF_COUNT_REQUEST_NCACHE; |
f7be4ee0 MM |
475 | |
476 | } else { | |
477 | gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n", | |
7b0cae60 | 478 | kobj->name); |
f7be4ee0 MM |
479 | rc = -EINVAL; |
480 | goto out; | |
481 | } | |
482 | ||
483 | ||
7b0cae60 | 484 | if (strcmp(kobj->name, PC_KOBJ_ID)) |
8bb8aefd | 485 | ser_op_type = "orangefs_param"; |
f7be4ee0 | 486 | else |
8bb8aefd | 487 | ser_op_type = "orangefs_perf_count"; |
f7be4ee0 MM |
488 | |
489 | /* | |
490 | * The service_operation will return an errno return code on | |
491 | * error, and zero on success. | |
492 | */ | |
8bb8aefd | 493 | rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE); |
f7be4ee0 MM |
494 | |
495 | out: | |
496 | if (!rc) { | |
7b0cae60 | 497 | if (strcmp(kobj->name, PC_KOBJ_ID)) { |
4d20a756 MB |
498 | 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 | } | |
f7be4ee0 MM |
509 | } else { |
510 | rc = scnprintf( | |
511 | buf, | |
512 | PAGE_SIZE, | |
513 | "%s", | |
514 | new_op->downcall.resp.perf_count.buffer); | |
515 | } | |
516 | } | |
517 | ||
ed42fe05 | 518 | op_release(new_op); |
f7be4ee0 MM |
519 | |
520 | return rc; | |
521 | ||
522 | } | |
523 | ||
f7be4ee0 MM |
524 | /* |
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 | */ | |
7b0cae60 MB |
535 | static ssize_t sysfs_service_op_store(struct kobject *kobj, |
536 | struct orangefs_attribute *attr, const char *buf, size_t count) | |
f7be4ee0 | 537 | { |
8bb8aefd | 538 | struct orangefs_kernel_op_s *new_op = NULL; |
f7be4ee0 MM |
539 | int val = 0; |
540 | int rc = 0; | |
f7be4ee0 MM |
541 | |
542 | gossip_debug(GOSSIP_SYSFS_DEBUG, | |
543 | "sysfs_service_op_store: id:%s:\n", | |
7b0cae60 | 544 | kobj->name); |
f7be4ee0 | 545 | |
8bb8aefd | 546 | new_op = op_alloc(ORANGEFS_VFS_OP_PARAM); |
ed42fe05 AV |
547 | if (!new_op) |
548 | return -EINVAL; /* sic */ | |
f7be4ee0 MM |
549 | |
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 | /* | |
4d20a756 MB |
560 | * The value we want to send back to userspace is in buf, unless this |
561 | * there are two parameters, which is specially handled below. | |
f7be4ee0 | 562 | */ |
7b0cae60 MB |
563 | if (strcmp(kobj->name, ORANGEFS_KOBJ_ID) || |
564 | strcmp(attr->attr.name, "readahead_count_size")) { | |
4d20a756 MB |
565 | rc = kstrtoint(buf, 0, &val); |
566 | if (rc) | |
567 | goto out; | |
568 | } | |
569 | ||
570 | new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET; | |
f7be4ee0 | 571 | |
7b0cae60 | 572 | if (!strcmp(kobj->name, ORANGEFS_KOBJ_ID)) { |
c51e0129 MB |
573 | /* Drop unsupported requests first. */ |
574 | if (!(orangefs_features & ORANGEFS_FEATURE_READAHEAD) && | |
b78b1198 MB |
575 | (!strcmp(attr->attr.name, "readahead_count") || |
576 | !strcmp(attr->attr.name, "readahead_size") || | |
31c829f3 MB |
577 | !strcmp(attr->attr.name, "readahead_count_size") || |
578 | !strcmp(attr->attr.name, "readahead_readcnt"))) { | |
c51e0129 MB |
579 | rc = -EINVAL; |
580 | goto out; | |
581 | } | |
f7be4ee0 | 582 | |
7b0cae60 | 583 | if (!strcmp(attr->attr.name, "perf_history_size")) { |
f7be4ee0 MM |
584 | if (val > 0) { |
585 | new_op->upcall.req.param.op = | |
8bb8aefd | 586 | ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE; |
f7be4ee0 MM |
587 | } else { |
588 | rc = 0; | |
589 | goto out; | |
590 | } | |
7b0cae60 | 591 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
592 | "perf_time_interval_secs")) { |
593 | if (val > 0) { | |
594 | new_op->upcall.req.param.op = | |
8bb8aefd | 595 | ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS; |
f7be4ee0 MM |
596 | } else { |
597 | rc = 0; | |
598 | goto out; | |
599 | } | |
7b0cae60 | 600 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
601 | "perf_counter_reset")) { |
602 | if ((val == 0) || (val == 1)) { | |
603 | new_op->upcall.req.param.op = | |
8bb8aefd | 604 | ORANGEFS_PARAM_REQUEST_OP_PERF_RESET; |
f7be4ee0 MM |
605 | } else { |
606 | rc = 0; | |
607 | goto out; | |
608 | } | |
7b0cae60 | 609 | } else if (!strcmp(attr->attr.name, |
4d20a756 MB |
610 | "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 | } | |
7b0cae60 | 618 | } else if (!strcmp(attr->attr.name, |
4d20a756 MB |
619 | "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 | } | |
7b0cae60 | 627 | } else if (!strcmp(attr->attr.name, |
4d20a756 MB |
628 | "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; | |
31c829f3 MB |
645 | } 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 | } | |
f7be4ee0 MM |
654 | } |
655 | ||
7b0cae60 MB |
656 | } else if (!strcmp(kobj->name, ACACHE_KOBJ_ID)) { |
657 | if (!strcmp(attr->attr.name, "hard_limit")) { | |
f7be4ee0 MM |
658 | if (val > -1) { |
659 | new_op->upcall.req.param.op = | |
8bb8aefd | 660 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT; |
f7be4ee0 MM |
661 | } else { |
662 | rc = 0; | |
663 | goto out; | |
664 | } | |
7b0cae60 | 665 | } else if (!strcmp(attr->attr.name, "soft_limit")) { |
f7be4ee0 MM |
666 | if (val > -1) { |
667 | new_op->upcall.req.param.op = | |
8bb8aefd | 668 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT; |
f7be4ee0 MM |
669 | } else { |
670 | rc = 0; | |
671 | goto out; | |
672 | } | |
7b0cae60 | 673 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
674 | "reclaim_percentage")) { |
675 | if ((val > -1) && (val < 101)) { | |
676 | new_op->upcall.req.param.op = | |
8bb8aefd | 677 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 MM |
678 | } else { |
679 | rc = 0; | |
680 | goto out; | |
681 | } | |
7b0cae60 | 682 | } else if (!strcmp(attr->attr.name, "timeout_msecs")) { |
f7be4ee0 MM |
683 | if (val > -1) { |
684 | new_op->upcall.req.param.op = | |
8bb8aefd | 685 | ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS; |
f7be4ee0 MM |
686 | } else { |
687 | rc = 0; | |
688 | goto out; | |
689 | } | |
690 | } | |
691 | ||
7b0cae60 MB |
692 | } else if (!strcmp(kobj->name, CAPCACHE_KOBJ_ID)) { |
693 | if (!strcmp(attr->attr.name, "hard_limit")) { | |
f7be4ee0 MM |
694 | if (val > -1) { |
695 | new_op->upcall.req.param.op = | |
8bb8aefd | 696 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT; |
f7be4ee0 MM |
697 | } else { |
698 | rc = 0; | |
699 | goto out; | |
700 | } | |
7b0cae60 | 701 | } else if (!strcmp(attr->attr.name, "soft_limit")) { |
f7be4ee0 MM |
702 | if (val > -1) { |
703 | new_op->upcall.req.param.op = | |
8bb8aefd | 704 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT; |
f7be4ee0 MM |
705 | } else { |
706 | rc = 0; | |
707 | goto out; | |
708 | } | |
7b0cae60 | 709 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
710 | "reclaim_percentage")) { |
711 | if ((val > -1) && (val < 101)) { | |
712 | new_op->upcall.req.param.op = | |
8bb8aefd | 713 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 MM |
714 | } else { |
715 | rc = 0; | |
716 | goto out; | |
717 | } | |
7b0cae60 | 718 | } else if (!strcmp(attr->attr.name, "timeout_secs")) { |
f7be4ee0 MM |
719 | if (val > -1) { |
720 | new_op->upcall.req.param.op = | |
8bb8aefd | 721 | ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS; |
f7be4ee0 MM |
722 | } else { |
723 | rc = 0; | |
724 | goto out; | |
725 | } | |
726 | } | |
727 | ||
7b0cae60 MB |
728 | } else if (!strcmp(kobj->name, CCACHE_KOBJ_ID)) { |
729 | if (!strcmp(attr->attr.name, "hard_limit")) { | |
f7be4ee0 MM |
730 | if (val > -1) { |
731 | new_op->upcall.req.param.op = | |
8bb8aefd | 732 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT; |
f7be4ee0 MM |
733 | } else { |
734 | rc = 0; | |
735 | goto out; | |
736 | } | |
7b0cae60 | 737 | } else if (!strcmp(attr->attr.name, "soft_limit")) { |
f7be4ee0 MM |
738 | if (val > -1) { |
739 | new_op->upcall.req.param.op = | |
8bb8aefd | 740 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT; |
f7be4ee0 MM |
741 | } else { |
742 | rc = 0; | |
743 | goto out; | |
744 | } | |
7b0cae60 | 745 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
746 | "reclaim_percentage")) { |
747 | if ((val > -1) && (val < 101)) { | |
748 | new_op->upcall.req.param.op = | |
8bb8aefd | 749 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 MM |
750 | } else { |
751 | rc = 0; | |
752 | goto out; | |
753 | } | |
7b0cae60 | 754 | } else if (!strcmp(attr->attr.name, "timeout_secs")) { |
f7be4ee0 MM |
755 | if (val > -1) { |
756 | new_op->upcall.req.param.op = | |
8bb8aefd | 757 | ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS; |
f7be4ee0 MM |
758 | } else { |
759 | rc = 0; | |
760 | goto out; | |
761 | } | |
762 | } | |
763 | ||
7b0cae60 MB |
764 | } else if (!strcmp(kobj->name, NCACHE_KOBJ_ID)) { |
765 | if (!strcmp(attr->attr.name, "hard_limit")) { | |
f7be4ee0 MM |
766 | if (val > -1) { |
767 | new_op->upcall.req.param.op = | |
8bb8aefd | 768 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT; |
f7be4ee0 MM |
769 | } else { |
770 | rc = 0; | |
771 | goto out; | |
772 | } | |
7b0cae60 | 773 | } else if (!strcmp(attr->attr.name, "soft_limit")) { |
f7be4ee0 MM |
774 | if (val > -1) { |
775 | new_op->upcall.req.param.op = | |
8bb8aefd | 776 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT; |
f7be4ee0 MM |
777 | } else { |
778 | rc = 0; | |
779 | goto out; | |
780 | } | |
7b0cae60 | 781 | } else if (!strcmp(attr->attr.name, |
f7be4ee0 MM |
782 | "reclaim_percentage")) { |
783 | if ((val > -1) && (val < 101)) { | |
784 | new_op->upcall.req.param.op = | |
8bb8aefd | 785 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE; |
f7be4ee0 MM |
786 | } else { |
787 | rc = 0; | |
788 | goto out; | |
789 | } | |
7b0cae60 | 790 | } else if (!strcmp(attr->attr.name, "timeout_msecs")) { |
f7be4ee0 MM |
791 | if (val > -1) { |
792 | new_op->upcall.req.param.op = | |
8bb8aefd | 793 | ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS; |
f7be4ee0 MM |
794 | } else { |
795 | rc = 0; | |
796 | goto out; | |
797 | } | |
798 | } | |
799 | ||
800 | } else { | |
801 | gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n", | |
7b0cae60 | 802 | kobj->name); |
f7be4ee0 MM |
803 | rc = -EINVAL; |
804 | goto out; | |
805 | } | |
806 | ||
680908e5 | 807 | new_op->upcall.req.param.u.value64 = val; |
4d20a756 | 808 | value_set: |
f7be4ee0 MM |
809 | |
810 | /* | |
811 | * The service_operation will return a errno return code on | |
812 | * error, and zero on success. | |
813 | */ | |
8bb8aefd | 814 | rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE); |
f7be4ee0 MM |
815 | |
816 | if (rc < 0) { | |
817 | gossip_err("sysfs_service_op_store: service op returned:%d:\n", | |
818 | rc); | |
819 | rc = 0; | |
820 | } else { | |
7b0cae60 | 821 | rc = count; |
f7be4ee0 MM |
822 | } |
823 | ||
824 | out: | |
ed42fe05 | 825 | op_release(new_op); |
f7be4ee0 | 826 | |
ed42fe05 | 827 | if (rc == -ENOMEM || rc == 0) |
f7be4ee0 MM |
828 | rc = -EINVAL; |
829 | ||
830 | return rc; | |
831 | } | |
832 | ||
f7be4ee0 | 833 | static struct orangefs_attribute op_timeout_secs_attribute = |
7b0cae60 | 834 | __ATTR(op_timeout_secs, 0664, sysfs_int_show, sysfs_int_store); |
f7be4ee0 MM |
835 | |
836 | static struct orangefs_attribute slot_timeout_secs_attribute = | |
7b0cae60 | 837 | __ATTR(slot_timeout_secs, 0664, sysfs_int_show, sysfs_int_store); |
f7be4ee0 | 838 | |
8f04e1be MB |
839 | static struct orangefs_attribute cache_timeout_msecs_attribute = |
840 | __ATTR(cache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store); | |
841 | ||
4cd8f319 | 842 | static struct orangefs_attribute dcache_timeout_msecs_attribute = |
7b0cae60 | 843 | __ATTR(dcache_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store); |
4cd8f319 MB |
844 | |
845 | static struct orangefs_attribute getattr_timeout_msecs_attribute = | |
7b0cae60 | 846 | __ATTR(getattr_timeout_msecs, 0664, sysfs_int_show, sysfs_int_store); |
4cd8f319 | 847 | |
4d20a756 | 848 | static struct orangefs_attribute readahead_count_attribute = |
7b0cae60 MB |
849 | __ATTR(readahead_count, 0664, sysfs_service_op_show, |
850 | sysfs_service_op_store); | |
4d20a756 MB |
851 | |
852 | static struct orangefs_attribute readahead_size_attribute = | |
7b0cae60 MB |
853 | __ATTR(readahead_size, 0664, sysfs_service_op_show, |
854 | sysfs_service_op_store); | |
4d20a756 MB |
855 | |
856 | static struct orangefs_attribute readahead_count_size_attribute = | |
7b0cae60 MB |
857 | __ATTR(readahead_count_size, 0664, sysfs_service_op_show, |
858 | sysfs_service_op_store); | |
4d20a756 | 859 | |
31c829f3 MB |
860 | static struct orangefs_attribute readahead_readcnt_attribute = |
861 | __ATTR(readahead_readcnt, 0664, sysfs_service_op_show, | |
862 | sysfs_service_op_store); | |
863 | ||
f7be4ee0 MM |
864 | static struct orangefs_attribute perf_counter_reset_attribute = |
865 | __ATTR(perf_counter_reset, | |
866 | 0664, | |
7b0cae60 MB |
867 | sysfs_service_op_show, |
868 | sysfs_service_op_store); | |
f7be4ee0 MM |
869 | |
870 | static struct orangefs_attribute perf_history_size_attribute = | |
871 | __ATTR(perf_history_size, | |
872 | 0664, | |
7b0cae60 MB |
873 | sysfs_service_op_show, |
874 | sysfs_service_op_store); | |
f7be4ee0 MM |
875 | |
876 | static struct orangefs_attribute perf_time_interval_secs_attribute = | |
877 | __ATTR(perf_time_interval_secs, | |
878 | 0664, | |
7b0cae60 MB |
879 | sysfs_service_op_show, |
880 | sysfs_service_op_store); | |
f7be4ee0 MM |
881 | |
882 | static struct attribute *orangefs_default_attrs[] = { | |
883 | &op_timeout_secs_attribute.attr, | |
884 | &slot_timeout_secs_attribute.attr, | |
8f04e1be | 885 | &cache_timeout_msecs_attribute.attr, |
4cd8f319 MB |
886 | &dcache_timeout_msecs_attribute.attr, |
887 | &getattr_timeout_msecs_attribute.attr, | |
4d20a756 MB |
888 | &readahead_count_attribute.attr, |
889 | &readahead_size_attribute.attr, | |
890 | &readahead_count_size_attribute.attr, | |
31c829f3 | 891 | &readahead_readcnt_attribute.attr, |
f7be4ee0 MM |
892 | &perf_counter_reset_attribute.attr, |
893 | &perf_history_size_attribute.attr, | |
894 | &perf_time_interval_secs_attribute.attr, | |
895 | NULL, | |
896 | }; | |
063e458c | 897 | ATTRIBUTE_GROUPS(orangefs_default); |
f7be4ee0 | 898 | |
1f2c0e8a ZX |
899 | static struct kobject *orangefs_obj; |
900 | ||
901 | static void orangefs_obj_release(struct kobject *kobj) | |
902 | { | |
903 | kfree(orangefs_obj); | |
904 | orangefs_obj = NULL; | |
905 | } | |
906 | ||
96319dac | 907 | static const struct kobj_type orangefs_ktype = { |
f7be4ee0 | 908 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 909 | .default_groups = orangefs_default_groups, |
1f2c0e8a | 910 | .release = orangefs_obj_release, |
f7be4ee0 MM |
911 | }; |
912 | ||
2e9f80da | 913 | static struct orangefs_attribute acache_hard_limit_attribute = |
f7be4ee0 MM |
914 | __ATTR(hard_limit, |
915 | 0664, | |
7b0cae60 MB |
916 | sysfs_service_op_show, |
917 | sysfs_service_op_store); | |
f7be4ee0 | 918 | |
2e9f80da | 919 | static struct orangefs_attribute acache_reclaim_percent_attribute = |
f7be4ee0 MM |
920 | __ATTR(reclaim_percentage, |
921 | 0664, | |
7b0cae60 MB |
922 | sysfs_service_op_show, |
923 | sysfs_service_op_store); | |
f7be4ee0 | 924 | |
2e9f80da | 925 | static struct orangefs_attribute acache_soft_limit_attribute = |
f7be4ee0 MM |
926 | __ATTR(soft_limit, |
927 | 0664, | |
7b0cae60 MB |
928 | sysfs_service_op_show, |
929 | sysfs_service_op_store); | |
f7be4ee0 | 930 | |
2e9f80da | 931 | static struct orangefs_attribute acache_timeout_msecs_attribute = |
f7be4ee0 MM |
932 | __ATTR(timeout_msecs, |
933 | 0664, | |
7b0cae60 MB |
934 | sysfs_service_op_show, |
935 | sysfs_service_op_store); | |
f7be4ee0 MM |
936 | |
937 | static struct attribute *acache_orangefs_default_attrs[] = { | |
938 | &acache_hard_limit_attribute.attr, | |
939 | &acache_reclaim_percent_attribute.attr, | |
940 | &acache_soft_limit_attribute.attr, | |
941 | &acache_timeout_msecs_attribute.attr, | |
942 | NULL, | |
943 | }; | |
063e458c | 944 | ATTRIBUTE_GROUPS(acache_orangefs_default); |
f7be4ee0 | 945 | |
1f2c0e8a ZX |
946 | static struct kobject *acache_orangefs_obj; |
947 | ||
948 | static void acache_orangefs_obj_release(struct kobject *kobj) | |
949 | { | |
950 | kfree(acache_orangefs_obj); | |
951 | acache_orangefs_obj = NULL; | |
952 | } | |
953 | ||
96319dac | 954 | static const struct kobj_type acache_orangefs_ktype = { |
4a343664 | 955 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 956 | .default_groups = acache_orangefs_default_groups, |
1f2c0e8a | 957 | .release = acache_orangefs_obj_release, |
f7be4ee0 MM |
958 | }; |
959 | ||
2e9f80da | 960 | static struct orangefs_attribute capcache_hard_limit_attribute = |
f7be4ee0 MM |
961 | __ATTR(hard_limit, |
962 | 0664, | |
7b0cae60 MB |
963 | sysfs_service_op_show, |
964 | sysfs_service_op_store); | |
f7be4ee0 | 965 | |
2e9f80da | 966 | static struct orangefs_attribute capcache_reclaim_percent_attribute = |
f7be4ee0 MM |
967 | __ATTR(reclaim_percentage, |
968 | 0664, | |
7b0cae60 MB |
969 | sysfs_service_op_show, |
970 | sysfs_service_op_store); | |
f7be4ee0 | 971 | |
2e9f80da | 972 | static struct orangefs_attribute capcache_soft_limit_attribute = |
f7be4ee0 MM |
973 | __ATTR(soft_limit, |
974 | 0664, | |
7b0cae60 MB |
975 | sysfs_service_op_show, |
976 | sysfs_service_op_store); | |
f7be4ee0 | 977 | |
2e9f80da | 978 | static struct orangefs_attribute capcache_timeout_secs_attribute = |
f7be4ee0 MM |
979 | __ATTR(timeout_secs, |
980 | 0664, | |
7b0cae60 MB |
981 | sysfs_service_op_show, |
982 | sysfs_service_op_store); | |
f7be4ee0 MM |
983 | |
984 | static struct attribute *capcache_orangefs_default_attrs[] = { | |
985 | &capcache_hard_limit_attribute.attr, | |
986 | &capcache_reclaim_percent_attribute.attr, | |
987 | &capcache_soft_limit_attribute.attr, | |
988 | &capcache_timeout_secs_attribute.attr, | |
989 | NULL, | |
990 | }; | |
063e458c | 991 | ATTRIBUTE_GROUPS(capcache_orangefs_default); |
f7be4ee0 | 992 | |
1f2c0e8a ZX |
993 | static struct kobject *capcache_orangefs_obj; |
994 | ||
995 | static void capcache_orangefs_obj_release(struct kobject *kobj) | |
996 | { | |
997 | kfree(capcache_orangefs_obj); | |
998 | capcache_orangefs_obj = NULL; | |
999 | } | |
1000 | ||
96319dac | 1001 | static const struct kobj_type capcache_orangefs_ktype = { |
4a343664 | 1002 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 1003 | .default_groups = capcache_orangefs_default_groups, |
1f2c0e8a | 1004 | .release = capcache_orangefs_obj_release, |
f7be4ee0 MM |
1005 | }; |
1006 | ||
2e9f80da | 1007 | static struct orangefs_attribute ccache_hard_limit_attribute = |
f7be4ee0 MM |
1008 | __ATTR(hard_limit, |
1009 | 0664, | |
7b0cae60 MB |
1010 | sysfs_service_op_show, |
1011 | sysfs_service_op_store); | |
f7be4ee0 | 1012 | |
2e9f80da | 1013 | static struct orangefs_attribute ccache_reclaim_percent_attribute = |
f7be4ee0 MM |
1014 | __ATTR(reclaim_percentage, |
1015 | 0664, | |
7b0cae60 MB |
1016 | sysfs_service_op_show, |
1017 | sysfs_service_op_store); | |
f7be4ee0 | 1018 | |
2e9f80da | 1019 | static struct orangefs_attribute ccache_soft_limit_attribute = |
f7be4ee0 MM |
1020 | __ATTR(soft_limit, |
1021 | 0664, | |
7b0cae60 MB |
1022 | sysfs_service_op_show, |
1023 | sysfs_service_op_store); | |
f7be4ee0 | 1024 | |
2e9f80da | 1025 | static struct orangefs_attribute ccache_timeout_secs_attribute = |
f7be4ee0 MM |
1026 | __ATTR(timeout_secs, |
1027 | 0664, | |
7b0cae60 MB |
1028 | sysfs_service_op_show, |
1029 | sysfs_service_op_store); | |
f7be4ee0 MM |
1030 | |
1031 | static struct attribute *ccache_orangefs_default_attrs[] = { | |
1032 | &ccache_hard_limit_attribute.attr, | |
1033 | &ccache_reclaim_percent_attribute.attr, | |
1034 | &ccache_soft_limit_attribute.attr, | |
1035 | &ccache_timeout_secs_attribute.attr, | |
1036 | NULL, | |
1037 | }; | |
063e458c | 1038 | ATTRIBUTE_GROUPS(ccache_orangefs_default); |
f7be4ee0 | 1039 | |
1f2c0e8a ZX |
1040 | static struct kobject *ccache_orangefs_obj; |
1041 | ||
1042 | static void ccache_orangefs_obj_release(struct kobject *kobj) | |
1043 | { | |
1044 | kfree(ccache_orangefs_obj); | |
1045 | ccache_orangefs_obj = NULL; | |
1046 | } | |
1047 | ||
96319dac | 1048 | static const struct kobj_type ccache_orangefs_ktype = { |
4a343664 | 1049 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 1050 | .default_groups = ccache_orangefs_default_groups, |
1f2c0e8a | 1051 | .release = ccache_orangefs_obj_release, |
f7be4ee0 MM |
1052 | }; |
1053 | ||
2e9f80da | 1054 | static struct orangefs_attribute ncache_hard_limit_attribute = |
f7be4ee0 MM |
1055 | __ATTR(hard_limit, |
1056 | 0664, | |
7b0cae60 MB |
1057 | sysfs_service_op_show, |
1058 | sysfs_service_op_store); | |
f7be4ee0 | 1059 | |
2e9f80da | 1060 | static struct orangefs_attribute ncache_reclaim_percent_attribute = |
f7be4ee0 MM |
1061 | __ATTR(reclaim_percentage, |
1062 | 0664, | |
7b0cae60 MB |
1063 | sysfs_service_op_show, |
1064 | sysfs_service_op_store); | |
f7be4ee0 | 1065 | |
2e9f80da | 1066 | static struct orangefs_attribute ncache_soft_limit_attribute = |
f7be4ee0 MM |
1067 | __ATTR(soft_limit, |
1068 | 0664, | |
7b0cae60 MB |
1069 | sysfs_service_op_show, |
1070 | sysfs_service_op_store); | |
f7be4ee0 | 1071 | |
2e9f80da | 1072 | static struct orangefs_attribute ncache_timeout_msecs_attribute = |
f7be4ee0 MM |
1073 | __ATTR(timeout_msecs, |
1074 | 0664, | |
7b0cae60 MB |
1075 | sysfs_service_op_show, |
1076 | sysfs_service_op_store); | |
f7be4ee0 MM |
1077 | |
1078 | static struct attribute *ncache_orangefs_default_attrs[] = { | |
1079 | &ncache_hard_limit_attribute.attr, | |
1080 | &ncache_reclaim_percent_attribute.attr, | |
1081 | &ncache_soft_limit_attribute.attr, | |
1082 | &ncache_timeout_msecs_attribute.attr, | |
1083 | NULL, | |
1084 | }; | |
063e458c | 1085 | ATTRIBUTE_GROUPS(ncache_orangefs_default); |
f7be4ee0 | 1086 | |
1f2c0e8a ZX |
1087 | static struct kobject *ncache_orangefs_obj; |
1088 | ||
1089 | static void ncache_orangefs_obj_release(struct kobject *kobj) | |
1090 | { | |
1091 | kfree(ncache_orangefs_obj); | |
1092 | ncache_orangefs_obj = NULL; | |
1093 | } | |
1094 | ||
96319dac | 1095 | static const struct kobj_type ncache_orangefs_ktype = { |
4a343664 | 1096 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 1097 | .default_groups = ncache_orangefs_default_groups, |
1f2c0e8a | 1098 | .release = ncache_orangefs_obj_release, |
f7be4ee0 MM |
1099 | }; |
1100 | ||
2e9f80da | 1101 | static struct orangefs_attribute pc_acache_attribute = |
f7be4ee0 MM |
1102 | __ATTR(acache, |
1103 | 0664, | |
7b0cae60 | 1104 | sysfs_service_op_show, |
f7be4ee0 MM |
1105 | NULL); |
1106 | ||
2e9f80da | 1107 | static struct orangefs_attribute pc_capcache_attribute = |
f7be4ee0 MM |
1108 | __ATTR(capcache, |
1109 | 0664, | |
7b0cae60 | 1110 | sysfs_service_op_show, |
f7be4ee0 MM |
1111 | NULL); |
1112 | ||
2e9f80da | 1113 | static struct orangefs_attribute pc_ncache_attribute = |
f7be4ee0 MM |
1114 | __ATTR(ncache, |
1115 | 0664, | |
7b0cae60 | 1116 | sysfs_service_op_show, |
f7be4ee0 MM |
1117 | NULL); |
1118 | ||
1119 | static struct attribute *pc_orangefs_default_attrs[] = { | |
1120 | &pc_acache_attribute.attr, | |
1121 | &pc_capcache_attribute.attr, | |
1122 | &pc_ncache_attribute.attr, | |
1123 | NULL, | |
1124 | }; | |
063e458c | 1125 | ATTRIBUTE_GROUPS(pc_orangefs_default); |
f7be4ee0 | 1126 | |
1f2c0e8a ZX |
1127 | static struct kobject *pc_orangefs_obj; |
1128 | ||
1129 | static void pc_orangefs_obj_release(struct kobject *kobj) | |
1130 | { | |
1131 | kfree(pc_orangefs_obj); | |
1132 | pc_orangefs_obj = NULL; | |
1133 | } | |
1134 | ||
96319dac | 1135 | static const struct kobj_type pc_orangefs_ktype = { |
4a343664 | 1136 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 1137 | .default_groups = pc_orangefs_default_groups, |
1f2c0e8a | 1138 | .release = pc_orangefs_obj_release, |
f7be4ee0 MM |
1139 | }; |
1140 | ||
2e9f80da | 1141 | static struct orangefs_attribute stats_reads_attribute = |
f7be4ee0 MM |
1142 | __ATTR(reads, |
1143 | 0664, | |
7b0cae60 | 1144 | sysfs_int_show, |
f7be4ee0 MM |
1145 | NULL); |
1146 | ||
2e9f80da | 1147 | static struct orangefs_attribute stats_writes_attribute = |
f7be4ee0 MM |
1148 | __ATTR(writes, |
1149 | 0664, | |
7b0cae60 | 1150 | sysfs_int_show, |
f7be4ee0 MM |
1151 | NULL); |
1152 | ||
1153 | static struct attribute *stats_orangefs_default_attrs[] = { | |
1154 | &stats_reads_attribute.attr, | |
1155 | &stats_writes_attribute.attr, | |
1156 | NULL, | |
1157 | }; | |
063e458c | 1158 | ATTRIBUTE_GROUPS(stats_orangefs_default); |
f7be4ee0 | 1159 | |
1f2c0e8a ZX |
1160 | static struct kobject *stats_orangefs_obj; |
1161 | ||
1162 | static void stats_orangefs_obj_release(struct kobject *kobj) | |
1163 | { | |
1164 | kfree(stats_orangefs_obj); | |
1165 | stats_orangefs_obj = NULL; | |
1166 | } | |
1167 | ||
96319dac | 1168 | static const struct kobj_type stats_orangefs_ktype = { |
4a343664 | 1169 | .sysfs_ops = &orangefs_sysfs_ops, |
063e458c | 1170 | .default_groups = stats_orangefs_default_groups, |
1f2c0e8a | 1171 | .release = stats_orangefs_obj_release, |
f7be4ee0 MM |
1172 | }; |
1173 | ||
f7be4ee0 MM |
1174 | int orangefs_sysfs_init(void) |
1175 | { | |
2180c52c | 1176 | int rc = -EINVAL; |
f7be4ee0 MM |
1177 | |
1178 | gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n"); | |
1179 | ||
1180 | /* create /sys/fs/orangefs. */ | |
1181 | orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL); | |
2180c52c | 1182 | if (!orangefs_obj) |
f7be4ee0 | 1183 | goto out; |
f7be4ee0 | 1184 | |
dc3012a7 | 1185 | rc = kobject_init_and_add(orangefs_obj, |
f7be4ee0 MM |
1186 | &orangefs_ktype, |
1187 | fs_kobj, | |
1188 | ORANGEFS_KOBJ_ID); | |
1189 | ||
2180c52c MM |
1190 | if (rc) |
1191 | goto ofs_obj_bail; | |
f7be4ee0 | 1192 | |
dc3012a7 | 1193 | kobject_uevent(orangefs_obj, KOBJ_ADD); |
f7be4ee0 MM |
1194 | |
1195 | /* create /sys/fs/orangefs/acache. */ | |
1196 | acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL); | |
1197 | if (!acache_orangefs_obj) { | |
1198 | rc = -EINVAL; | |
2180c52c | 1199 | goto ofs_obj_bail; |
f7be4ee0 MM |
1200 | } |
1201 | ||
dc3012a7 | 1202 | rc = kobject_init_and_add(acache_orangefs_obj, |
f7be4ee0 | 1203 | &acache_orangefs_ktype, |
dc3012a7 | 1204 | orangefs_obj, |
f7be4ee0 MM |
1205 | ACACHE_KOBJ_ID); |
1206 | ||
2180c52c MM |
1207 | if (rc) |
1208 | goto acache_obj_bail; | |
f7be4ee0 | 1209 | |
dc3012a7 | 1210 | kobject_uevent(acache_orangefs_obj, KOBJ_ADD); |
f7be4ee0 MM |
1211 | |
1212 | /* create /sys/fs/orangefs/capcache. */ | |
1213 | capcache_orangefs_obj = | |
1214 | kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL); | |
1215 | if (!capcache_orangefs_obj) { | |
1216 | rc = -EINVAL; | |
2180c52c | 1217 | goto acache_obj_bail; |
f7be4ee0 MM |
1218 | } |
1219 | ||
dc3012a7 | 1220 | rc = kobject_init_and_add(capcache_orangefs_obj, |
f7be4ee0 | 1221 | &capcache_orangefs_ktype, |
dc3012a7 | 1222 | orangefs_obj, |
f7be4ee0 | 1223 | CAPCACHE_KOBJ_ID); |
2180c52c MM |
1224 | if (rc) |
1225 | goto capcache_obj_bail; | |
f7be4ee0 | 1226 | |
dc3012a7 | 1227 | kobject_uevent(capcache_orangefs_obj, KOBJ_ADD); |
f7be4ee0 MM |
1228 | |
1229 | /* create /sys/fs/orangefs/ccache. */ | |
1230 | ccache_orangefs_obj = | |
1231 | kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL); | |
1232 | if (!ccache_orangefs_obj) { | |
1233 | rc = -EINVAL; | |
2180c52c | 1234 | goto capcache_obj_bail; |
f7be4ee0 MM |
1235 | } |
1236 | ||
dc3012a7 | 1237 | rc = kobject_init_and_add(ccache_orangefs_obj, |
f7be4ee0 | 1238 | &ccache_orangefs_ktype, |
dc3012a7 | 1239 | orangefs_obj, |
f7be4ee0 | 1240 | CCACHE_KOBJ_ID); |
2180c52c MM |
1241 | if (rc) |
1242 | goto ccache_obj_bail; | |
f7be4ee0 | 1243 | |
dc3012a7 | 1244 | kobject_uevent(ccache_orangefs_obj, KOBJ_ADD); |
f7be4ee0 MM |
1245 | |
1246 | /* create /sys/fs/orangefs/ncache. */ | |
1247 | ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL); | |
1248 | if (!ncache_orangefs_obj) { | |
1249 | rc = -EINVAL; | |
2180c52c | 1250 | goto ccache_obj_bail; |
f7be4ee0 MM |
1251 | } |
1252 | ||
dc3012a7 | 1253 | rc = kobject_init_and_add(ncache_orangefs_obj, |
f7be4ee0 | 1254 | &ncache_orangefs_ktype, |
dc3012a7 | 1255 | orangefs_obj, |
f7be4ee0 MM |
1256 | NCACHE_KOBJ_ID); |
1257 | ||
2180c52c MM |
1258 | if (rc) |
1259 | goto ncache_obj_bail; | |
f7be4ee0 | 1260 | |
dc3012a7 | 1261 | kobject_uevent(ncache_orangefs_obj, KOBJ_ADD); |
f7be4ee0 MM |
1262 | |
1263 | /* create /sys/fs/orangefs/perf_counters. */ | |
1264 | pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL); | |
1265 | if (!pc_orangefs_obj) { | |
1266 | rc = -EINVAL; | |
2180c52c | 1267 | goto ncache_obj_bail; |
f7be4ee0 MM |
1268 | } |
1269 | ||
dc3012a7 | 1270 | rc = kobject_init_and_add(pc_orangefs_obj, |
f7be4ee0 | 1271 | &pc_orangefs_ktype, |
dc3012a7 | 1272 | orangefs_obj, |
f7be4ee0 MM |
1273 | "perf_counters"); |
1274 | ||
2180c52c MM |
1275 | if (rc) |
1276 | goto pc_obj_bail; | |
f7be4ee0 | 1277 | |
dc3012a7 | 1278 | kobject_uevent(pc_orangefs_obj, KOBJ_ADD); |
f7be4ee0 MM |
1279 | |
1280 | /* create /sys/fs/orangefs/stats. */ | |
1281 | stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL); | |
1282 | if (!stats_orangefs_obj) { | |
1283 | rc = -EINVAL; | |
2180c52c | 1284 | goto pc_obj_bail; |
f7be4ee0 MM |
1285 | } |
1286 | ||
dc3012a7 | 1287 | rc = kobject_init_and_add(stats_orangefs_obj, |
f7be4ee0 | 1288 | &stats_orangefs_ktype, |
dc3012a7 | 1289 | orangefs_obj, |
f7be4ee0 MM |
1290 | STATS_KOBJ_ID); |
1291 | ||
2180c52c MM |
1292 | if (rc) |
1293 | goto stats_obj_bail; | |
f7be4ee0 | 1294 | |
dc3012a7 | 1295 | kobject_uevent(stats_orangefs_obj, KOBJ_ADD); |
2180c52c MM |
1296 | goto out; |
1297 | ||
1298 | stats_obj_bail: | |
dc3012a7 | 1299 | kobject_put(stats_orangefs_obj); |
2180c52c | 1300 | pc_obj_bail: |
dc3012a7 | 1301 | kobject_put(pc_orangefs_obj); |
2180c52c | 1302 | ncache_obj_bail: |
dc3012a7 | 1303 | kobject_put(ncache_orangefs_obj); |
2180c52c | 1304 | ccache_obj_bail: |
dc3012a7 | 1305 | kobject_put(ccache_orangefs_obj); |
2180c52c | 1306 | capcache_obj_bail: |
dc3012a7 | 1307 | kobject_put(capcache_orangefs_obj); |
2180c52c | 1308 | acache_obj_bail: |
dc3012a7 | 1309 | kobject_put(acache_orangefs_obj); |
2180c52c | 1310 | ofs_obj_bail: |
dc3012a7 | 1311 | kobject_put(orangefs_obj); |
f7be4ee0 MM |
1312 | out: |
1313 | return rc; | |
1314 | } | |
1315 | ||
1316 | void orangefs_sysfs_exit(void) | |
1317 | { | |
1318 | gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n"); | |
dc3012a7 MB |
1319 | kobject_put(acache_orangefs_obj); |
1320 | kobject_put(capcache_orangefs_obj); | |
1321 | kobject_put(ccache_orangefs_obj); | |
1322 | kobject_put(ncache_orangefs_obj); | |
1323 | kobject_put(pc_orangefs_obj); | |
1324 | kobject_put(stats_orangefs_obj); | |
1325 | kobject_put(orangefs_obj); | |
f7be4ee0 | 1326 | } |