blob: 2fe9a3a2117bd450103a623b4fa53889cca64d88 [file] [log] [blame]
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001/*
2 * Documentation/ABI/stable/orangefs-sysfs:
3 *
4 * What: /sys/fs/orangefs/perf_counter_reset
5 * Date: June 2015
6 * Contact: Mike Marshall <hubcap@omnibond.com>
7 * Description:
8 * echo a 0 or a 1 into perf_counter_reset to
9 * reset all the counters in
10 * /sys/fs/orangefs/perf_counters
11 * except ones with PINT_PERF_PRESERVE set.
12 *
13 *
14 * What: /sys/fs/orangefs/perf_counters/...
15 * Date: Jun 2015
16 * Contact: Mike Marshall <hubcap@omnibond.com>
17 * Description:
18 * Counters and settings for various caches.
19 * Read only.
20 *
21 *
22 * What: /sys/fs/orangefs/perf_time_interval_secs
23 * Date: Jun 2015
24 * Contact: Mike Marshall <hubcap@omnibond.com>
25 * Description:
26 * Length of perf counter intervals in
27 * seconds.
28 *
29 *
30 * What: /sys/fs/orangefs/perf_history_size
31 * Date: Jun 2015
32 * Contact: Mike Marshall <hubcap@omnibond.com>
33 * Description:
34 * The perf_counters cache statistics have N, or
35 * perf_history_size, samples. The default is
36 * one.
37 *
38 * Every perf_time_interval_secs the (first)
39 * samples are reset.
40 *
41 * If N is greater than one, the "current" set
42 * of samples is reset, and the samples from the
43 * other N-1 intervals remain available.
44 *
45 *
46 * What: /sys/fs/orangefs/op_timeout_secs
47 * Date: Jun 2015
48 * Contact: Mike Marshall <hubcap@omnibond.com>
49 * Description:
50 * Service operation timeout in seconds.
51 *
52 *
53 * What: /sys/fs/orangefs/slot_timeout_secs
54 * Date: Jun 2015
55 * Contact: Mike Marshall <hubcap@omnibond.com>
56 * Description:
57 * "Slot" timeout in seconds. A "slot"
58 * is an indexed buffer in the shared
59 * memory segment used for communication
60 * between the kernel module and userspace.
61 * Slots are requested and waited for,
62 * the wait times out after slot_timeout_secs.
63 *
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040064 * What: /sys/fs/orangefs/dcache_timeout_msecs
65 * Date: Jul 2016
66 * Contact: Martin Brandenburg <martin@omnibond.com>
67 * Description:
68 * Time lookup is valid in milliseconds.
69 *
70 * What: /sys/fs/orangefs/getattr_timeout_msecs
71 * Date: Jul 2016
72 * Contact: Martin Brandenburg <martin@omnibond.com>
73 * Description:
74 * Time getattr is valid in milliseconds.
Mike Marshallf7be4ee2015-07-17 10:38:14 -040075 *
Martin Brandenburg4d20a752016-08-03 13:47:28 -040076 * What: /sys/fs/orangefs/readahead_count
77 * Date: Aug 2016
78 * Contact: Martin Brandenburg <martin@omnibond.com>
79 * Description:
80 * Readahead cache buffer count.
81 *
82 * What: /sys/fs/orangefs/readahead_size
83 * Date: Aug 2016
84 * Contact: Martin Brandenburg <martin@omnibond.com>
85 * Description:
86 * Readahead cache buffer size.
87 *
88 * What: /sys/fs/orangefs/readahead_count_size
89 * Date: Aug 2016
90 * Contact: Martin Brandenburg <martin@omnibond.com>
91 * Description:
92 * Readahead cache buffer count and size.
93 *
Mike Marshallf7be4ee2015-07-17 10:38:14 -040094 * What: /sys/fs/orangefs/acache/...
95 * Date: Jun 2015
Martin Brandenburg4cd8f312016-07-25 13:58:24 -040096 * Contact: Martin Brandenburg <martin@omnibond.com>
Mike Marshallf7be4ee2015-07-17 10:38:14 -040097 * Description:
98 * Attribute cache configurable settings.
99 *
100 *
101 * What: /sys/fs/orangefs/ncache/...
102 * Date: Jun 2015
103 * Contact: Mike Marshall <hubcap@omnibond.com>
104 * Description:
105 * Name cache configurable settings.
106 *
107 *
108 * What: /sys/fs/orangefs/capcache/...
109 * Date: Jun 2015
110 * Contact: Mike Marshall <hubcap@omnibond.com>
111 * Description:
112 * Capability cache configurable settings.
113 *
114 *
115 * What: /sys/fs/orangefs/ccache/...
116 * Date: Jun 2015
117 * Contact: Mike Marshall <hubcap@omnibond.com>
118 * Description:
119 * Credential cache configurable settings.
120 *
121 */
122
123#include <linux/fs.h>
124#include <linux/kobject.h>
125#include <linux/string.h>
126#include <linux/sysfs.h>
127#include <linux/module.h>
128#include <linux/init.h>
129
130#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -0500131#include "orangefs-kernel.h"
132#include "orangefs-sysfs.h"
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400133
134#define ORANGEFS_KOBJ_ID "orangefs"
135#define ACACHE_KOBJ_ID "acache"
136#define CAPCACHE_KOBJ_ID "capcache"
137#define CCACHE_KOBJ_ID "ccache"
138#define NCACHE_KOBJ_ID "ncache"
139#define PC_KOBJ_ID "pc"
140#define STATS_KOBJ_ID "stats"
141
142struct orangefs_obj {
143 struct kobject kobj;
144 int op_timeout_secs;
145 int perf_counter_reset;
146 int perf_history_size;
147 int perf_time_interval_secs;
148 int slot_timeout_secs;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400149 int dcache_timeout_msecs;
150 int getattr_timeout_msecs;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400151};
152
153struct acache_orangefs_obj {
154 struct kobject kobj;
155 int hard_limit;
156 int reclaim_percentage;
157 int soft_limit;
158 int timeout_msecs;
159};
160
161struct capcache_orangefs_obj {
162 struct kobject kobj;
163 int hard_limit;
164 int reclaim_percentage;
165 int soft_limit;
166 int timeout_secs;
167};
168
169struct ccache_orangefs_obj {
170 struct kobject kobj;
171 int hard_limit;
172 int reclaim_percentage;
173 int soft_limit;
174 int timeout_secs;
175};
176
177struct ncache_orangefs_obj {
178 struct kobject kobj;
179 int hard_limit;
180 int reclaim_percentage;
181 int soft_limit;
182 int timeout_msecs;
183};
184
185struct pc_orangefs_obj {
186 struct kobject kobj;
187 char *acache;
188 char *capcache;
189 char *ncache;
190};
191
192struct stats_orangefs_obj {
193 struct kobject kobj;
194 int reads;
195 int writes;
196};
197
198struct orangefs_attribute {
199 struct attribute attr;
200 ssize_t (*show)(struct orangefs_obj *orangefs_obj,
201 struct orangefs_attribute *attr,
202 char *buf);
203 ssize_t (*store)(struct orangefs_obj *orangefs_obj,
204 struct orangefs_attribute *attr,
205 const char *buf,
206 size_t count);
207};
208
209struct acache_orangefs_attribute {
210 struct attribute attr;
211 ssize_t (*show)(struct acache_orangefs_obj *acache_orangefs_obj,
212 struct acache_orangefs_attribute *attr,
213 char *buf);
214 ssize_t (*store)(struct acache_orangefs_obj *acache_orangefs_obj,
215 struct acache_orangefs_attribute *attr,
216 const char *buf,
217 size_t count);
218};
219
220struct capcache_orangefs_attribute {
221 struct attribute attr;
222 ssize_t (*show)(struct capcache_orangefs_obj *capcache_orangefs_obj,
223 struct capcache_orangefs_attribute *attr,
224 char *buf);
225 ssize_t (*store)(struct capcache_orangefs_obj *capcache_orangefs_obj,
226 struct capcache_orangefs_attribute *attr,
227 const char *buf,
228 size_t count);
229};
230
231struct ccache_orangefs_attribute {
232 struct attribute attr;
233 ssize_t (*show)(struct ccache_orangefs_obj *ccache_orangefs_obj,
234 struct ccache_orangefs_attribute *attr,
235 char *buf);
236 ssize_t (*store)(struct ccache_orangefs_obj *ccache_orangefs_obj,
237 struct ccache_orangefs_attribute *attr,
238 const char *buf,
239 size_t count);
240};
241
242struct ncache_orangefs_attribute {
243 struct attribute attr;
244 ssize_t (*show)(struct ncache_orangefs_obj *ncache_orangefs_obj,
245 struct ncache_orangefs_attribute *attr,
246 char *buf);
247 ssize_t (*store)(struct ncache_orangefs_obj *ncache_orangefs_obj,
248 struct ncache_orangefs_attribute *attr,
249 const char *buf,
250 size_t count);
251};
252
253struct pc_orangefs_attribute {
254 struct attribute attr;
255 ssize_t (*show)(struct pc_orangefs_obj *pc_orangefs_obj,
256 struct pc_orangefs_attribute *attr,
257 char *buf);
258 ssize_t (*store)(struct pc_orangefs_obj *pc_orangefs_obj,
259 struct pc_orangefs_attribute *attr,
260 const char *buf,
261 size_t count);
262};
263
264struct stats_orangefs_attribute {
265 struct attribute attr;
266 ssize_t (*show)(struct stats_orangefs_obj *stats_orangefs_obj,
267 struct stats_orangefs_attribute *attr,
268 char *buf);
269 ssize_t (*store)(struct stats_orangefs_obj *stats_orangefs_obj,
270 struct stats_orangefs_attribute *attr,
271 const char *buf,
272 size_t count);
273};
274
275static ssize_t orangefs_attr_show(struct kobject *kobj,
276 struct attribute *attr,
277 char *buf)
278{
279 struct orangefs_attribute *attribute;
280 struct orangefs_obj *orangefs_obj;
281 int rc;
282
283 attribute = container_of(attr, struct orangefs_attribute, attr);
284 orangefs_obj = container_of(kobj, struct orangefs_obj, kobj);
285
286 if (!attribute->show) {
287 rc = -EIO;
288 goto out;
289 }
290
291 rc = attribute->show(orangefs_obj, attribute, buf);
292
293out:
294 return rc;
295}
296
297static ssize_t orangefs_attr_store(struct kobject *kobj,
298 struct attribute *attr,
299 const char *buf,
300 size_t len)
301{
302 struct orangefs_attribute *attribute;
303 struct orangefs_obj *orangefs_obj;
304 int rc;
305
306 gossip_debug(GOSSIP_SYSFS_DEBUG,
307 "orangefs_attr_store: start\n");
308
309 attribute = container_of(attr, struct orangefs_attribute, attr);
310 orangefs_obj = container_of(kobj, struct orangefs_obj, kobj);
311
312 if (!attribute->store) {
313 rc = -EIO;
314 goto out;
315 }
316
317 rc = attribute->store(orangefs_obj, attribute, buf, len);
318
319out:
320 return rc;
321}
322
323static const struct sysfs_ops orangefs_sysfs_ops = {
324 .show = orangefs_attr_show,
325 .store = orangefs_attr_store,
326};
327
328static ssize_t acache_orangefs_attr_show(struct kobject *kobj,
329 struct attribute *attr,
330 char *buf)
331{
332 struct acache_orangefs_attribute *attribute;
333 struct acache_orangefs_obj *acache_orangefs_obj;
334 int rc;
335
336 attribute = container_of(attr, struct acache_orangefs_attribute, attr);
337 acache_orangefs_obj =
338 container_of(kobj, struct acache_orangefs_obj, kobj);
339
340 if (!attribute->show) {
341 rc = -EIO;
342 goto out;
343 }
344
345 rc = attribute->show(acache_orangefs_obj, attribute, buf);
346
347out:
348 return rc;
349}
350
351static ssize_t acache_orangefs_attr_store(struct kobject *kobj,
352 struct attribute *attr,
353 const char *buf,
354 size_t len)
355{
356 struct acache_orangefs_attribute *attribute;
357 struct acache_orangefs_obj *acache_orangefs_obj;
358 int rc;
359
360 gossip_debug(GOSSIP_SYSFS_DEBUG,
361 "acache_orangefs_attr_store: start\n");
362
363 attribute = container_of(attr, struct acache_orangefs_attribute, attr);
364 acache_orangefs_obj =
365 container_of(kobj, struct acache_orangefs_obj, kobj);
366
367 if (!attribute->store) {
368 rc = -EIO;
369 goto out;
370 }
371
372 rc = attribute->store(acache_orangefs_obj, attribute, buf, len);
373
374out:
375 return rc;
376}
377
378static const struct sysfs_ops acache_orangefs_sysfs_ops = {
379 .show = acache_orangefs_attr_show,
380 .store = acache_orangefs_attr_store,
381};
382
383static ssize_t capcache_orangefs_attr_show(struct kobject *kobj,
384 struct attribute *attr,
385 char *buf)
386{
387 struct capcache_orangefs_attribute *attribute;
388 struct capcache_orangefs_obj *capcache_orangefs_obj;
389 int rc;
390
391 attribute =
392 container_of(attr, struct capcache_orangefs_attribute, attr);
393 capcache_orangefs_obj =
394 container_of(kobj, struct capcache_orangefs_obj, kobj);
395
396 if (!attribute->show) {
397 rc = -EIO;
398 goto out;
399 }
400
401 rc = attribute->show(capcache_orangefs_obj, attribute, buf);
402
403out:
404 return rc;
405}
406
407static ssize_t capcache_orangefs_attr_store(struct kobject *kobj,
408 struct attribute *attr,
409 const char *buf,
410 size_t len)
411{
412 struct capcache_orangefs_attribute *attribute;
413 struct capcache_orangefs_obj *capcache_orangefs_obj;
414 int rc;
415
416 gossip_debug(GOSSIP_SYSFS_DEBUG,
417 "capcache_orangefs_attr_store: start\n");
418
419 attribute =
420 container_of(attr, struct capcache_orangefs_attribute, attr);
421 capcache_orangefs_obj =
422 container_of(kobj, struct capcache_orangefs_obj, kobj);
423
424 if (!attribute->store) {
425 rc = -EIO;
426 goto out;
427 }
428
429 rc = attribute->store(capcache_orangefs_obj, attribute, buf, len);
430
431out:
432 return rc;
433}
434
435static const struct sysfs_ops capcache_orangefs_sysfs_ops = {
436 .show = capcache_orangefs_attr_show,
437 .store = capcache_orangefs_attr_store,
438};
439
440static ssize_t ccache_orangefs_attr_show(struct kobject *kobj,
441 struct attribute *attr,
442 char *buf)
443{
444 struct ccache_orangefs_attribute *attribute;
445 struct ccache_orangefs_obj *ccache_orangefs_obj;
446 int rc;
447
448 attribute =
449 container_of(attr, struct ccache_orangefs_attribute, attr);
450 ccache_orangefs_obj =
451 container_of(kobj, struct ccache_orangefs_obj, kobj);
452
453 if (!attribute->show) {
454 rc = -EIO;
455 goto out;
456 }
457
458 rc = attribute->show(ccache_orangefs_obj, attribute, buf);
459
460out:
461 return rc;
462}
463
464static ssize_t ccache_orangefs_attr_store(struct kobject *kobj,
465 struct attribute *attr,
466 const char *buf,
467 size_t len)
468{
469 struct ccache_orangefs_attribute *attribute;
470 struct ccache_orangefs_obj *ccache_orangefs_obj;
471 int rc;
472
473 gossip_debug(GOSSIP_SYSFS_DEBUG,
474 "ccache_orangefs_attr_store: start\n");
475
476 attribute =
477 container_of(attr, struct ccache_orangefs_attribute, attr);
478 ccache_orangefs_obj =
479 container_of(kobj, struct ccache_orangefs_obj, kobj);
480
481 if (!attribute->store) {
482 rc = -EIO;
483 goto out;
484 }
485
486 rc = attribute->store(ccache_orangefs_obj, attribute, buf, len);
487
488out:
489 return rc;
490}
491
492static const struct sysfs_ops ccache_orangefs_sysfs_ops = {
493 .show = ccache_orangefs_attr_show,
494 .store = ccache_orangefs_attr_store,
495};
496
497static ssize_t ncache_orangefs_attr_show(struct kobject *kobj,
498 struct attribute *attr,
499 char *buf)
500{
501 struct ncache_orangefs_attribute *attribute;
502 struct ncache_orangefs_obj *ncache_orangefs_obj;
503 int rc;
504
505 attribute = container_of(attr, struct ncache_orangefs_attribute, attr);
506 ncache_orangefs_obj =
507 container_of(kobj, struct ncache_orangefs_obj, kobj);
508
509 if (!attribute->show) {
510 rc = -EIO;
511 goto out;
512 }
513
514 rc = attribute->show(ncache_orangefs_obj, attribute, buf);
515
516out:
517 return rc;
518}
519
520static ssize_t ncache_orangefs_attr_store(struct kobject *kobj,
521 struct attribute *attr,
522 const char *buf,
523 size_t len)
524{
525 struct ncache_orangefs_attribute *attribute;
526 struct ncache_orangefs_obj *ncache_orangefs_obj;
527 int rc;
528
529 gossip_debug(GOSSIP_SYSFS_DEBUG,
530 "ncache_orangefs_attr_store: start\n");
531
532 attribute = container_of(attr, struct ncache_orangefs_attribute, attr);
533 ncache_orangefs_obj =
534 container_of(kobj, struct ncache_orangefs_obj, kobj);
535
536 if (!attribute->store) {
537 rc = -EIO;
538 goto out;
539 }
540
541 rc = attribute->store(ncache_orangefs_obj, attribute, buf, len);
542
543out:
544 return rc;
545}
546
547static const struct sysfs_ops ncache_orangefs_sysfs_ops = {
548 .show = ncache_orangefs_attr_show,
549 .store = ncache_orangefs_attr_store,
550};
551
552static ssize_t pc_orangefs_attr_show(struct kobject *kobj,
553 struct attribute *attr,
554 char *buf)
555{
556 struct pc_orangefs_attribute *attribute;
557 struct pc_orangefs_obj *pc_orangefs_obj;
558 int rc;
559
560 attribute = container_of(attr, struct pc_orangefs_attribute, attr);
561 pc_orangefs_obj =
562 container_of(kobj, struct pc_orangefs_obj, kobj);
563
564 if (!attribute->show) {
565 rc = -EIO;
566 goto out;
567 }
568
569 rc = attribute->show(pc_orangefs_obj, attribute, buf);
570
571out:
572 return rc;
573}
574
575static const struct sysfs_ops pc_orangefs_sysfs_ops = {
576 .show = pc_orangefs_attr_show,
577};
578
579static ssize_t stats_orangefs_attr_show(struct kobject *kobj,
580 struct attribute *attr,
581 char *buf)
582{
583 struct stats_orangefs_attribute *attribute;
584 struct stats_orangefs_obj *stats_orangefs_obj;
585 int rc;
586
587 attribute = container_of(attr, struct stats_orangefs_attribute, attr);
588 stats_orangefs_obj =
589 container_of(kobj, struct stats_orangefs_obj, kobj);
590
591 if (!attribute->show) {
592 rc = -EIO;
593 goto out;
594 }
595
596 rc = attribute->show(stats_orangefs_obj, attribute, buf);
597
598out:
599 return rc;
600}
601
602static const struct sysfs_ops stats_orangefs_sysfs_ops = {
603 .show = stats_orangefs_attr_show,
604};
605
606static void orangefs_release(struct kobject *kobj)
607{
608 struct orangefs_obj *orangefs_obj;
609
610 orangefs_obj = container_of(kobj, struct orangefs_obj, kobj);
611 kfree(orangefs_obj);
612}
613
614static void acache_orangefs_release(struct kobject *kobj)
615{
616 struct acache_orangefs_obj *acache_orangefs_obj;
617
618 acache_orangefs_obj =
619 container_of(kobj, struct acache_orangefs_obj, kobj);
620 kfree(acache_orangefs_obj);
621}
622
623static void capcache_orangefs_release(struct kobject *kobj)
624{
625 struct capcache_orangefs_obj *capcache_orangefs_obj;
626
627 capcache_orangefs_obj =
628 container_of(kobj, struct capcache_orangefs_obj, kobj);
629 kfree(capcache_orangefs_obj);
630}
631
632static void ccache_orangefs_release(struct kobject *kobj)
633{
634 struct ccache_orangefs_obj *ccache_orangefs_obj;
635
636 ccache_orangefs_obj =
637 container_of(kobj, struct ccache_orangefs_obj, kobj);
638 kfree(ccache_orangefs_obj);
639}
640
641static void ncache_orangefs_release(struct kobject *kobj)
642{
643 struct ncache_orangefs_obj *ncache_orangefs_obj;
644
645 ncache_orangefs_obj =
646 container_of(kobj, struct ncache_orangefs_obj, kobj);
647 kfree(ncache_orangefs_obj);
648}
649
650static void pc_orangefs_release(struct kobject *kobj)
651{
652 struct pc_orangefs_obj *pc_orangefs_obj;
653
654 pc_orangefs_obj =
655 container_of(kobj, struct pc_orangefs_obj, kobj);
656 kfree(pc_orangefs_obj);
657}
658
659static void stats_orangefs_release(struct kobject *kobj)
660{
661 struct stats_orangefs_obj *stats_orangefs_obj;
662
663 stats_orangefs_obj =
664 container_of(kobj, struct stats_orangefs_obj, kobj);
665 kfree(stats_orangefs_obj);
666}
667
668static ssize_t sysfs_int_show(char *kobj_id, char *buf, void *attr)
669{
670 int rc = -EIO;
671 struct orangefs_attribute *orangefs_attr;
672 struct stats_orangefs_attribute *stats_orangefs_attr;
673
674 gossip_debug(GOSSIP_SYSFS_DEBUG, "sysfs_int_show: id:%s:\n", kobj_id);
675
676 if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
677 orangefs_attr = (struct orangefs_attribute *)attr;
678
679 if (!strcmp(orangefs_attr->attr.name, "op_timeout_secs")) {
680 rc = scnprintf(buf,
681 PAGE_SIZE,
682 "%d\n",
683 op_timeout_secs);
684 goto out;
685 } else if (!strcmp(orangefs_attr->attr.name,
686 "slot_timeout_secs")) {
687 rc = scnprintf(buf,
688 PAGE_SIZE,
689 "%d\n",
690 slot_timeout_secs);
691 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400692 } else if (!strcmp(orangefs_attr->attr.name,
693 "dcache_timeout_msecs")) {
694 rc = scnprintf(buf,
695 PAGE_SIZE,
696 "%d\n",
697 dcache_timeout_msecs);
698 goto out;
699 } else if (!strcmp(orangefs_attr->attr.name,
700 "getattr_timeout_msecs")) {
701 rc = scnprintf(buf,
702 PAGE_SIZE,
703 "%d\n",
704 getattr_timeout_msecs);
705 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400706 } else {
707 goto out;
708 }
709
710 } else if (!strcmp(kobj_id, STATS_KOBJ_ID)) {
711 stats_orangefs_attr = (struct stats_orangefs_attribute *)attr;
712
713 if (!strcmp(stats_orangefs_attr->attr.name, "reads")) {
714 rc = scnprintf(buf,
715 PAGE_SIZE,
716 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500717 g_orangefs_stats.reads);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400718 goto out;
719 } else if (!strcmp(stats_orangefs_attr->attr.name, "writes")) {
720 rc = scnprintf(buf,
721 PAGE_SIZE,
722 "%lu\n",
Yi Liu8bb8aef2015-11-24 15:12:14 -0500723 g_orangefs_stats.writes);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400724 goto out;
725 } else {
726 goto out;
727 }
728 }
729
730out:
731
732 return rc;
733}
734
735static ssize_t int_orangefs_show(struct orangefs_obj *orangefs_obj,
736 struct orangefs_attribute *attr,
737 char *buf)
738{
739 int rc;
740
741 gossip_debug(GOSSIP_SYSFS_DEBUG,
742 "int_orangefs_show:start attr->attr.name:%s:\n",
743 attr->attr.name);
744
745 rc = sysfs_int_show(ORANGEFS_KOBJ_ID, buf, (void *) attr);
746
747 return rc;
748}
749
750static ssize_t int_stats_show(struct stats_orangefs_obj *stats_orangefs_obj,
751 struct stats_orangefs_attribute *attr,
752 char *buf)
753{
754 int rc;
755
756 gossip_debug(GOSSIP_SYSFS_DEBUG,
757 "int_stats_show:start attr->attr.name:%s:\n",
758 attr->attr.name);
759
760 rc = sysfs_int_show(STATS_KOBJ_ID, buf, (void *) attr);
761
762 return rc;
763}
764
765static ssize_t int_store(struct orangefs_obj *orangefs_obj,
766 struct orangefs_attribute *attr,
767 const char *buf,
768 size_t count)
769{
770 int rc = 0;
771
772 gossip_debug(GOSSIP_SYSFS_DEBUG,
773 "int_store: start attr->attr.name:%s: buf:%s:\n",
774 attr->attr.name, buf);
775
776 if (!strcmp(attr->attr.name, "op_timeout_secs")) {
777 rc = kstrtoint(buf, 0, &op_timeout_secs);
778 goto out;
779 } else if (!strcmp(attr->attr.name, "slot_timeout_secs")) {
780 rc = kstrtoint(buf, 0, &slot_timeout_secs);
781 goto out;
Martin Brandenburg4cd8f312016-07-25 13:58:24 -0400782 } else if (!strcmp(attr->attr.name, "dcache_timeout_msecs")) {
783 rc = kstrtoint(buf, 0, &dcache_timeout_msecs);
784 goto out;
785 } else if (!strcmp(attr->attr.name, "getattr_timeout_msecs")) {
786 rc = kstrtoint(buf, 0, &getattr_timeout_msecs);
787 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400788 } else {
789 goto out;
790 }
791
792out:
793 if (rc)
794 rc = -EINVAL;
795 else
796 rc = count;
797
798 return rc;
799}
800
801/*
802 * obtain attribute values from userspace with a service operation.
803 */
Mike Marshall84d02152015-07-28 13:27:51 -0400804static int sysfs_service_op_show(char *kobj_id, char *buf, void *attr)
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400805{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500806 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400807 int rc = 0;
808 char *ser_op_type = NULL;
809 struct orangefs_attribute *orangefs_attr;
810 struct acache_orangefs_attribute *acache_attr;
811 struct capcache_orangefs_attribute *capcache_attr;
812 struct ccache_orangefs_attribute *ccache_attr;
813 struct ncache_orangefs_attribute *ncache_attr;
814 struct pc_orangefs_attribute *pc_attr;
815 __u32 op_alloc_type;
816
817 gossip_debug(GOSSIP_SYSFS_DEBUG,
818 "sysfs_service_op_show: id:%s:\n",
819 kobj_id);
820
821 if (strcmp(kobj_id, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500822 op_alloc_type = ORANGEFS_VFS_OP_PARAM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400823 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500824 op_alloc_type = ORANGEFS_VFS_OP_PERF_COUNT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400825
826 new_op = op_alloc(op_alloc_type);
Al Viroed42fe02016-01-22 19:47:47 -0500827 if (!new_op)
828 return -ENOMEM;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400829
830 /* Can't do a service_operation if the client is not running... */
831 rc = is_daemon_in_service();
832 if (rc) {
833 pr_info("%s: Client not running :%d:\n",
834 __func__,
835 is_daemon_in_service());
836 goto out;
837 }
838
839 if (strcmp(kobj_id, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500840 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_GET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400841
842 if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
843 orangefs_attr = (struct orangefs_attribute *)attr;
844
845 if (!strcmp(orangefs_attr->attr.name, "perf_history_size"))
846 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500847 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400848 else if (!strcmp(orangefs_attr->attr.name,
849 "perf_time_interval_secs"))
850 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500851 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400852 else if (!strcmp(orangefs_attr->attr.name,
853 "perf_counter_reset"))
854 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500855 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400856
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400857 else if (!strcmp(orangefs_attr->attr.name,
858 "readahead_count"))
859 new_op->upcall.req.param.op =
860 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
861
862 else if (!strcmp(orangefs_attr->attr.name,
863 "readahead_size"))
864 new_op->upcall.req.param.op =
865 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
866
867 else if (!strcmp(orangefs_attr->attr.name,
868 "readahead_count_size"))
869 new_op->upcall.req.param.op =
870 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400871 } else if (!strcmp(kobj_id, ACACHE_KOBJ_ID)) {
872 acache_attr = (struct acache_orangefs_attribute *)attr;
873
874 if (!strcmp(acache_attr->attr.name, "timeout_msecs"))
875 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500876 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400877
878 if (!strcmp(acache_attr->attr.name, "hard_limit"))
879 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500880 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400881
882 if (!strcmp(acache_attr->attr.name, "soft_limit"))
883 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500884 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400885
886 if (!strcmp(acache_attr->attr.name, "reclaim_percentage"))
887 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500888 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400889
890 } else if (!strcmp(kobj_id, CAPCACHE_KOBJ_ID)) {
891 capcache_attr = (struct capcache_orangefs_attribute *)attr;
892
893 if (!strcmp(capcache_attr->attr.name, "timeout_secs"))
894 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500895 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400896
897 if (!strcmp(capcache_attr->attr.name, "hard_limit"))
898 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500899 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400900
901 if (!strcmp(capcache_attr->attr.name, "soft_limit"))
902 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500903 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400904
905 if (!strcmp(capcache_attr->attr.name, "reclaim_percentage"))
906 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500907 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400908
909 } else if (!strcmp(kobj_id, CCACHE_KOBJ_ID)) {
910 ccache_attr = (struct ccache_orangefs_attribute *)attr;
911
912 if (!strcmp(ccache_attr->attr.name, "timeout_secs"))
913 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500914 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400915
916 if (!strcmp(ccache_attr->attr.name, "hard_limit"))
917 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500918 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400919
920 if (!strcmp(ccache_attr->attr.name, "soft_limit"))
921 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500922 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400923
924 if (!strcmp(ccache_attr->attr.name, "reclaim_percentage"))
925 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500926 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400927
928 } else if (!strcmp(kobj_id, NCACHE_KOBJ_ID)) {
929 ncache_attr = (struct ncache_orangefs_attribute *)attr;
930
931 if (!strcmp(ncache_attr->attr.name, "timeout_msecs"))
932 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500933 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400934
935 if (!strcmp(ncache_attr->attr.name, "hard_limit"))
936 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500937 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400938
939 if (!strcmp(ncache_attr->attr.name, "soft_limit"))
940 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500941 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400942
943 if (!strcmp(ncache_attr->attr.name, "reclaim_percentage"))
944 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500945 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400946
947 } else if (!strcmp(kobj_id, PC_KOBJ_ID)) {
948 pc_attr = (struct pc_orangefs_attribute *)attr;
949
950 if (!strcmp(pc_attr->attr.name, ACACHE_KOBJ_ID))
951 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500952 ORANGEFS_PERF_COUNT_REQUEST_ACACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400953
954 if (!strcmp(pc_attr->attr.name, CAPCACHE_KOBJ_ID))
955 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500956 ORANGEFS_PERF_COUNT_REQUEST_CAPCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400957
958 if (!strcmp(pc_attr->attr.name, NCACHE_KOBJ_ID))
959 new_op->upcall.req.perf_count.type =
Yi Liu8bb8aef2015-11-24 15:12:14 -0500960 ORANGEFS_PERF_COUNT_REQUEST_NCACHE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400961
962 } else {
963 gossip_err("sysfs_service_op_show: unknown kobj_id:%s:\n",
964 kobj_id);
965 rc = -EINVAL;
966 goto out;
967 }
968
969
970 if (strcmp(kobj_id, PC_KOBJ_ID))
Yi Liu8bb8aef2015-11-24 15:12:14 -0500971 ser_op_type = "orangefs_param";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400972 else
Yi Liu8bb8aef2015-11-24 15:12:14 -0500973 ser_op_type = "orangefs_perf_count";
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400974
975 /*
976 * The service_operation will return an errno return code on
977 * error, and zero on success.
978 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500979 rc = service_operation(new_op, ser_op_type, ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400980
981out:
982 if (!rc) {
983 if (strcmp(kobj_id, PC_KOBJ_ID)) {
Martin Brandenburg4d20a752016-08-03 13:47:28 -0400984 if (new_op->upcall.req.param.op ==
985 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE) {
986 rc = scnprintf(buf, PAGE_SIZE, "%d %d\n",
987 (int)new_op->downcall.resp.param.u.
988 value32[0],
989 (int)new_op->downcall.resp.param.u.
990 value32[1]);
991 } else {
992 rc = scnprintf(buf, PAGE_SIZE, "%d\n",
993 (int)new_op->downcall.resp.param.u.value64);
994 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -0400995 } else {
996 rc = scnprintf(
997 buf,
998 PAGE_SIZE,
999 "%s",
1000 new_op->downcall.resp.perf_count.buffer);
1001 }
1002 }
1003
Al Viroed42fe02016-01-22 19:47:47 -05001004 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001005
1006 return rc;
1007
1008}
1009
1010static ssize_t service_orangefs_show(struct orangefs_obj *orangefs_obj,
1011 struct orangefs_attribute *attr,
1012 char *buf)
1013{
1014 int rc = 0;
1015
1016 rc = sysfs_service_op_show(ORANGEFS_KOBJ_ID, buf, (void *)attr);
1017
1018 return rc;
1019}
1020
1021static ssize_t
1022 service_acache_show(struct acache_orangefs_obj *acache_orangefs_obj,
1023 struct acache_orangefs_attribute *attr,
1024 char *buf)
1025{
1026 int rc = 0;
1027
1028 rc = sysfs_service_op_show(ACACHE_KOBJ_ID, buf, (void *)attr);
1029
1030 return rc;
1031}
1032
1033static ssize_t service_capcache_show(struct capcache_orangefs_obj
1034 *capcache_orangefs_obj,
1035 struct capcache_orangefs_attribute *attr,
1036 char *buf)
1037{
1038 int rc = 0;
1039
1040 rc = sysfs_service_op_show(CAPCACHE_KOBJ_ID, buf, (void *)attr);
1041
1042 return rc;
1043}
1044
1045static ssize_t service_ccache_show(struct ccache_orangefs_obj
1046 *ccache_orangefs_obj,
1047 struct ccache_orangefs_attribute *attr,
1048 char *buf)
1049{
1050 int rc = 0;
1051
1052 rc = sysfs_service_op_show(CCACHE_KOBJ_ID, buf, (void *)attr);
1053
1054 return rc;
1055}
1056
1057static ssize_t
1058 service_ncache_show(struct ncache_orangefs_obj *ncache_orangefs_obj,
1059 struct ncache_orangefs_attribute *attr,
1060 char *buf)
1061{
1062 int rc = 0;
1063
1064 rc = sysfs_service_op_show(NCACHE_KOBJ_ID, buf, (void *)attr);
1065
1066 return rc;
1067}
1068
1069static ssize_t
1070 service_pc_show(struct pc_orangefs_obj *pc_orangefs_obj,
1071 struct pc_orangefs_attribute *attr,
1072 char *buf)
1073{
1074 int rc = 0;
1075
1076 rc = sysfs_service_op_show(PC_KOBJ_ID, buf, (void *)attr);
1077
1078 return rc;
1079}
1080
1081/*
1082 * pass attribute values back to userspace with a service operation.
1083 *
1084 * We have to do a memory allocation, an sscanf and a service operation.
1085 * And we have to evaluate what the user entered, to make sure the
1086 * value is within the range supported by the attribute. So, there's
1087 * a lot of return code checking and mapping going on here.
1088 *
1089 * We want to return 1 if we think everything went OK, and
1090 * EINVAL if not.
1091 */
Mike Marshall84d02152015-07-28 13:27:51 -04001092static int sysfs_service_op_store(char *kobj_id, const char *buf, void *attr)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001093{
Yi Liu8bb8aef2015-11-24 15:12:14 -05001094 struct orangefs_kernel_op_s *new_op = NULL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001095 int val = 0;
1096 int rc = 0;
1097 struct orangefs_attribute *orangefs_attr;
1098 struct acache_orangefs_attribute *acache_attr;
1099 struct capcache_orangefs_attribute *capcache_attr;
1100 struct ccache_orangefs_attribute *ccache_attr;
1101 struct ncache_orangefs_attribute *ncache_attr;
1102
1103 gossip_debug(GOSSIP_SYSFS_DEBUG,
1104 "sysfs_service_op_store: id:%s:\n",
1105 kobj_id);
1106
Yi Liu8bb8aef2015-11-24 15:12:14 -05001107 new_op = op_alloc(ORANGEFS_VFS_OP_PARAM);
Al Viroed42fe02016-01-22 19:47:47 -05001108 if (!new_op)
1109 return -EINVAL; /* sic */
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001110
1111 /* Can't do a service_operation if the client is not running... */
1112 rc = is_daemon_in_service();
1113 if (rc) {
1114 pr_info("%s: Client not running :%d:\n",
1115 __func__,
1116 is_daemon_in_service());
1117 goto out;
1118 }
1119
1120 /*
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001121 * The value we want to send back to userspace is in buf, unless this
1122 * there are two parameters, which is specially handled below.
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001123 */
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001124 if (strcmp(kobj_id, ORANGEFS_KOBJ_ID) ||
1125 strcmp(((struct orangefs_attribute *)attr)->attr.name,
1126 "readahead_count_size")) {
1127 rc = kstrtoint(buf, 0, &val);
1128 if (rc)
1129 goto out;
1130 }
1131
1132 new_op->upcall.req.param.type = ORANGEFS_PARAM_REQUEST_SET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001133
1134 if (!strcmp(kobj_id, ORANGEFS_KOBJ_ID)) {
1135 orangefs_attr = (struct orangefs_attribute *)attr;
1136
1137 if (!strcmp(orangefs_attr->attr.name, "perf_history_size")) {
1138 if (val > 0) {
1139 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001140 ORANGEFS_PARAM_REQUEST_OP_PERF_HISTORY_SIZE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001141 } else {
1142 rc = 0;
1143 goto out;
1144 }
1145 } else if (!strcmp(orangefs_attr->attr.name,
1146 "perf_time_interval_secs")) {
1147 if (val > 0) {
1148 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001149 ORANGEFS_PARAM_REQUEST_OP_PERF_TIME_INTERVAL_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001150 } else {
1151 rc = 0;
1152 goto out;
1153 }
1154 } else if (!strcmp(orangefs_attr->attr.name,
1155 "perf_counter_reset")) {
1156 if ((val == 0) || (val == 1)) {
1157 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001158 ORANGEFS_PARAM_REQUEST_OP_PERF_RESET;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001159 } else {
1160 rc = 0;
1161 goto out;
1162 }
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001163 } else if (!strcmp(orangefs_attr->attr.name,
1164 "readahead_count")) {
1165 if ((val >= 0)) {
1166 new_op->upcall.req.param.op =
1167 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT;
1168 } else {
1169 rc = 0;
1170 goto out;
1171 }
1172 } else if (!strcmp(orangefs_attr->attr.name,
1173 "readahead_size")) {
1174 if ((val >= 0)) {
1175 new_op->upcall.req.param.op =
1176 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_SIZE;
1177 } else {
1178 rc = 0;
1179 goto out;
1180 }
1181 } else if (!strcmp(orangefs_attr->attr.name,
1182 "readahead_count_size")) {
1183 int val1, val2;
1184 rc = sscanf(buf, "%d %d", &val1, &val2);
1185 if (rc < 2) {
1186 rc = 0;
1187 goto out;
1188 }
1189 if ((val1 >= 0) && (val2 >= 0)) {
1190 new_op->upcall.req.param.op =
1191 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
1192 } else {
1193 rc = 0;
1194 goto out;
1195 }
1196 new_op->upcall.req.param.u.value32[0] = val1;
1197 new_op->upcall.req.param.u.value32[1] = val2;
1198 goto value_set;
1199 } else if (!strcmp(orangefs_attr->attr.name,
1200 "perf_counter_reset")) {
1201 if ((val > 0)) {
1202 new_op->upcall.req.param.op =
1203 ORANGEFS_PARAM_REQUEST_OP_READAHEAD_COUNT_SIZE;
1204 } else {
1205 rc = 0;
1206 goto out;
1207 }
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001208 }
1209
1210 } else if (!strcmp(kobj_id, ACACHE_KOBJ_ID)) {
1211 acache_attr = (struct acache_orangefs_attribute *)attr;
1212
1213 if (!strcmp(acache_attr->attr.name, "hard_limit")) {
1214 if (val > -1) {
1215 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001216 ORANGEFS_PARAM_REQUEST_OP_ACACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001217 } else {
1218 rc = 0;
1219 goto out;
1220 }
1221 } else if (!strcmp(acache_attr->attr.name, "soft_limit")) {
1222 if (val > -1) {
1223 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001224 ORANGEFS_PARAM_REQUEST_OP_ACACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001225 } else {
1226 rc = 0;
1227 goto out;
1228 }
1229 } else if (!strcmp(acache_attr->attr.name,
1230 "reclaim_percentage")) {
1231 if ((val > -1) && (val < 101)) {
1232 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001233 ORANGEFS_PARAM_REQUEST_OP_ACACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001234 } else {
1235 rc = 0;
1236 goto out;
1237 }
1238 } else if (!strcmp(acache_attr->attr.name, "timeout_msecs")) {
1239 if (val > -1) {
1240 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001241 ORANGEFS_PARAM_REQUEST_OP_ACACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001242 } else {
1243 rc = 0;
1244 goto out;
1245 }
1246 }
1247
1248 } else if (!strcmp(kobj_id, CAPCACHE_KOBJ_ID)) {
1249 capcache_attr = (struct capcache_orangefs_attribute *)attr;
1250
1251 if (!strcmp(capcache_attr->attr.name, "hard_limit")) {
1252 if (val > -1) {
1253 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001254 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001255 } else {
1256 rc = 0;
1257 goto out;
1258 }
1259 } else if (!strcmp(capcache_attr->attr.name, "soft_limit")) {
1260 if (val > -1) {
1261 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001262 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001263 } else {
1264 rc = 0;
1265 goto out;
1266 }
1267 } else if (!strcmp(capcache_attr->attr.name,
1268 "reclaim_percentage")) {
1269 if ((val > -1) && (val < 101)) {
1270 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001271 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001272 } else {
1273 rc = 0;
1274 goto out;
1275 }
1276 } else if (!strcmp(capcache_attr->attr.name, "timeout_secs")) {
1277 if (val > -1) {
1278 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001279 ORANGEFS_PARAM_REQUEST_OP_CAPCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001280 } else {
1281 rc = 0;
1282 goto out;
1283 }
1284 }
1285
1286 } else if (!strcmp(kobj_id, CCACHE_KOBJ_ID)) {
1287 ccache_attr = (struct ccache_orangefs_attribute *)attr;
1288
1289 if (!strcmp(ccache_attr->attr.name, "hard_limit")) {
1290 if (val > -1) {
1291 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001292 ORANGEFS_PARAM_REQUEST_OP_CCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001293 } else {
1294 rc = 0;
1295 goto out;
1296 }
1297 } else if (!strcmp(ccache_attr->attr.name, "soft_limit")) {
1298 if (val > -1) {
1299 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001300 ORANGEFS_PARAM_REQUEST_OP_CCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001301 } else {
1302 rc = 0;
1303 goto out;
1304 }
1305 } else if (!strcmp(ccache_attr->attr.name,
1306 "reclaim_percentage")) {
1307 if ((val > -1) && (val < 101)) {
1308 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001309 ORANGEFS_PARAM_REQUEST_OP_CCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001310 } else {
1311 rc = 0;
1312 goto out;
1313 }
1314 } else if (!strcmp(ccache_attr->attr.name, "timeout_secs")) {
1315 if (val > -1) {
1316 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001317 ORANGEFS_PARAM_REQUEST_OP_CCACHE_TIMEOUT_SECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001318 } else {
1319 rc = 0;
1320 goto out;
1321 }
1322 }
1323
1324 } else if (!strcmp(kobj_id, NCACHE_KOBJ_ID)) {
1325 ncache_attr = (struct ncache_orangefs_attribute *)attr;
1326
1327 if (!strcmp(ncache_attr->attr.name, "hard_limit")) {
1328 if (val > -1) {
1329 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001330 ORANGEFS_PARAM_REQUEST_OP_NCACHE_HARD_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001331 } else {
1332 rc = 0;
1333 goto out;
1334 }
1335 } else if (!strcmp(ncache_attr->attr.name, "soft_limit")) {
1336 if (val > -1) {
1337 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001338 ORANGEFS_PARAM_REQUEST_OP_NCACHE_SOFT_LIMIT;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001339 } else {
1340 rc = 0;
1341 goto out;
1342 }
1343 } else if (!strcmp(ncache_attr->attr.name,
1344 "reclaim_percentage")) {
1345 if ((val > -1) && (val < 101)) {
1346 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001347 ORANGEFS_PARAM_REQUEST_OP_NCACHE_RECLAIM_PERCENTAGE;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001348 } else {
1349 rc = 0;
1350 goto out;
1351 }
1352 } else if (!strcmp(ncache_attr->attr.name, "timeout_msecs")) {
1353 if (val > -1) {
1354 new_op->upcall.req.param.op =
Yi Liu8bb8aef2015-11-24 15:12:14 -05001355 ORANGEFS_PARAM_REQUEST_OP_NCACHE_TIMEOUT_MSECS;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001356 } else {
1357 rc = 0;
1358 goto out;
1359 }
1360 }
1361
1362 } else {
1363 gossip_err("sysfs_service_op_store: unknown kobj_id:%s:\n",
1364 kobj_id);
1365 rc = -EINVAL;
1366 goto out;
1367 }
1368
Martin Brandenburg680908e2016-08-02 16:33:34 -04001369 new_op->upcall.req.param.u.value64 = val;
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001370value_set:
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001371
1372 /*
1373 * The service_operation will return a errno return code on
1374 * error, and zero on success.
1375 */
Yi Liu8bb8aef2015-11-24 15:12:14 -05001376 rc = service_operation(new_op, "orangefs_param", ORANGEFS_OP_INTERRUPTIBLE);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001377
1378 if (rc < 0) {
1379 gossip_err("sysfs_service_op_store: service op returned:%d:\n",
1380 rc);
1381 rc = 0;
1382 } else {
1383 rc = 1;
1384 }
1385
1386out:
Al Viroed42fe02016-01-22 19:47:47 -05001387 op_release(new_op);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001388
Al Viroed42fe02016-01-22 19:47:47 -05001389 if (rc == -ENOMEM || rc == 0)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001390 rc = -EINVAL;
1391
1392 return rc;
1393}
1394
1395static ssize_t
1396 service_orangefs_store(struct orangefs_obj *orangefs_obj,
1397 struct orangefs_attribute *attr,
1398 const char *buf,
1399 size_t count)
1400{
1401 int rc = 0;
1402
1403 rc = sysfs_service_op_store(ORANGEFS_KOBJ_ID, buf, (void *) attr);
1404
1405 /* rc should have an errno value if the service_op went bad. */
1406 if (rc == 1)
1407 rc = count;
1408
1409 return rc;
1410}
1411
1412static ssize_t
1413 service_acache_store(struct acache_orangefs_obj *acache_orangefs_obj,
1414 struct acache_orangefs_attribute *attr,
1415 const char *buf,
1416 size_t count)
1417{
1418 int rc = 0;
1419
1420 rc = sysfs_service_op_store(ACACHE_KOBJ_ID, buf, (void *) attr);
1421
1422 /* rc should have an errno value if the service_op went bad. */
1423 if (rc == 1)
1424 rc = count;
1425
1426 return rc;
1427}
1428
1429static ssize_t
1430 service_capcache_store(struct capcache_orangefs_obj
1431 *capcache_orangefs_obj,
1432 struct capcache_orangefs_attribute *attr,
1433 const char *buf,
1434 size_t count)
1435{
1436 int rc = 0;
1437
1438 rc = sysfs_service_op_store(CAPCACHE_KOBJ_ID, buf, (void *) attr);
1439
1440 /* rc should have an errno value if the service_op went bad. */
1441 if (rc == 1)
1442 rc = count;
1443
1444 return rc;
1445}
1446
1447static ssize_t service_ccache_store(struct ccache_orangefs_obj
1448 *ccache_orangefs_obj,
1449 struct ccache_orangefs_attribute *attr,
1450 const char *buf,
1451 size_t count)
1452{
1453 int rc = 0;
1454
1455 rc = sysfs_service_op_store(CCACHE_KOBJ_ID, buf, (void *) attr);
1456
1457 /* rc should have an errno value if the service_op went bad. */
1458 if (rc == 1)
1459 rc = count;
1460
1461 return rc;
1462}
1463
1464static ssize_t
1465 service_ncache_store(struct ncache_orangefs_obj *ncache_orangefs_obj,
1466 struct ncache_orangefs_attribute *attr,
1467 const char *buf,
1468 size_t count)
1469{
1470 int rc = 0;
1471
1472 rc = sysfs_service_op_store(NCACHE_KOBJ_ID, buf, (void *) attr);
1473
1474 /* rc should have an errno value if the service_op went bad. */
1475 if (rc == 1)
1476 rc = count;
1477
1478 return rc;
1479}
1480
1481static struct orangefs_attribute op_timeout_secs_attribute =
1482 __ATTR(op_timeout_secs, 0664, int_orangefs_show, int_store);
1483
1484static struct orangefs_attribute slot_timeout_secs_attribute =
1485 __ATTR(slot_timeout_secs, 0664, int_orangefs_show, int_store);
1486
Martin Brandenburg4cd8f312016-07-25 13:58:24 -04001487static struct orangefs_attribute dcache_timeout_msecs_attribute =
1488 __ATTR(dcache_timeout_msecs, 0664, int_orangefs_show, int_store);
1489
1490static struct orangefs_attribute getattr_timeout_msecs_attribute =
1491 __ATTR(getattr_timeout_msecs, 0664, int_orangefs_show, int_store);
1492
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001493static struct orangefs_attribute readahead_count_attribute =
1494 __ATTR(readahead_count, 0664, service_orangefs_show,
1495 service_orangefs_store);
1496
1497static struct orangefs_attribute readahead_size_attribute =
1498 __ATTR(readahead_size, 0664, service_orangefs_show,
1499 service_orangefs_store);
1500
1501static struct orangefs_attribute readahead_count_size_attribute =
1502 __ATTR(readahead_count_size, 0664, service_orangefs_show,
1503 service_orangefs_store);
1504
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001505static struct orangefs_attribute perf_counter_reset_attribute =
1506 __ATTR(perf_counter_reset,
1507 0664,
1508 service_orangefs_show,
1509 service_orangefs_store);
1510
1511static struct orangefs_attribute perf_history_size_attribute =
1512 __ATTR(perf_history_size,
1513 0664,
1514 service_orangefs_show,
1515 service_orangefs_store);
1516
1517static struct orangefs_attribute perf_time_interval_secs_attribute =
1518 __ATTR(perf_time_interval_secs,
1519 0664,
1520 service_orangefs_show,
1521 service_orangefs_store);
1522
1523static struct attribute *orangefs_default_attrs[] = {
1524 &op_timeout_secs_attribute.attr,
1525 &slot_timeout_secs_attribute.attr,
Martin Brandenburg4cd8f312016-07-25 13:58:24 -04001526 &dcache_timeout_msecs_attribute.attr,
1527 &getattr_timeout_msecs_attribute.attr,
Martin Brandenburg4d20a752016-08-03 13:47:28 -04001528 &readahead_count_attribute.attr,
1529 &readahead_size_attribute.attr,
1530 &readahead_count_size_attribute.attr,
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001531 &perf_counter_reset_attribute.attr,
1532 &perf_history_size_attribute.attr,
1533 &perf_time_interval_secs_attribute.attr,
1534 NULL,
1535};
1536
1537static struct kobj_type orangefs_ktype = {
1538 .sysfs_ops = &orangefs_sysfs_ops,
1539 .release = orangefs_release,
1540 .default_attrs = orangefs_default_attrs,
1541};
1542
1543static struct acache_orangefs_attribute acache_hard_limit_attribute =
1544 __ATTR(hard_limit,
1545 0664,
1546 service_acache_show,
1547 service_acache_store);
1548
1549static struct acache_orangefs_attribute acache_reclaim_percent_attribute =
1550 __ATTR(reclaim_percentage,
1551 0664,
1552 service_acache_show,
1553 service_acache_store);
1554
1555static struct acache_orangefs_attribute acache_soft_limit_attribute =
1556 __ATTR(soft_limit,
1557 0664,
1558 service_acache_show,
1559 service_acache_store);
1560
1561static struct acache_orangefs_attribute acache_timeout_msecs_attribute =
1562 __ATTR(timeout_msecs,
1563 0664,
1564 service_acache_show,
1565 service_acache_store);
1566
1567static struct attribute *acache_orangefs_default_attrs[] = {
1568 &acache_hard_limit_attribute.attr,
1569 &acache_reclaim_percent_attribute.attr,
1570 &acache_soft_limit_attribute.attr,
1571 &acache_timeout_msecs_attribute.attr,
1572 NULL,
1573};
1574
1575static struct kobj_type acache_orangefs_ktype = {
1576 .sysfs_ops = &acache_orangefs_sysfs_ops,
1577 .release = acache_orangefs_release,
1578 .default_attrs = acache_orangefs_default_attrs,
1579};
1580
1581static struct capcache_orangefs_attribute capcache_hard_limit_attribute =
1582 __ATTR(hard_limit,
1583 0664,
1584 service_capcache_show,
1585 service_capcache_store);
1586
1587static struct capcache_orangefs_attribute capcache_reclaim_percent_attribute =
1588 __ATTR(reclaim_percentage,
1589 0664,
1590 service_capcache_show,
1591 service_capcache_store);
1592
1593static struct capcache_orangefs_attribute capcache_soft_limit_attribute =
1594 __ATTR(soft_limit,
1595 0664,
1596 service_capcache_show,
1597 service_capcache_store);
1598
1599static struct capcache_orangefs_attribute capcache_timeout_secs_attribute =
1600 __ATTR(timeout_secs,
1601 0664,
1602 service_capcache_show,
1603 service_capcache_store);
1604
1605static struct attribute *capcache_orangefs_default_attrs[] = {
1606 &capcache_hard_limit_attribute.attr,
1607 &capcache_reclaim_percent_attribute.attr,
1608 &capcache_soft_limit_attribute.attr,
1609 &capcache_timeout_secs_attribute.attr,
1610 NULL,
1611};
1612
1613static struct kobj_type capcache_orangefs_ktype = {
1614 .sysfs_ops = &capcache_orangefs_sysfs_ops,
1615 .release = capcache_orangefs_release,
1616 .default_attrs = capcache_orangefs_default_attrs,
1617};
1618
1619static struct ccache_orangefs_attribute ccache_hard_limit_attribute =
1620 __ATTR(hard_limit,
1621 0664,
1622 service_ccache_show,
1623 service_ccache_store);
1624
1625static struct ccache_orangefs_attribute ccache_reclaim_percent_attribute =
1626 __ATTR(reclaim_percentage,
1627 0664,
1628 service_ccache_show,
1629 service_ccache_store);
1630
1631static struct ccache_orangefs_attribute ccache_soft_limit_attribute =
1632 __ATTR(soft_limit,
1633 0664,
1634 service_ccache_show,
1635 service_ccache_store);
1636
1637static struct ccache_orangefs_attribute ccache_timeout_secs_attribute =
1638 __ATTR(timeout_secs,
1639 0664,
1640 service_ccache_show,
1641 service_ccache_store);
1642
1643static struct attribute *ccache_orangefs_default_attrs[] = {
1644 &ccache_hard_limit_attribute.attr,
1645 &ccache_reclaim_percent_attribute.attr,
1646 &ccache_soft_limit_attribute.attr,
1647 &ccache_timeout_secs_attribute.attr,
1648 NULL,
1649};
1650
1651static struct kobj_type ccache_orangefs_ktype = {
1652 .sysfs_ops = &ccache_orangefs_sysfs_ops,
1653 .release = ccache_orangefs_release,
1654 .default_attrs = ccache_orangefs_default_attrs,
1655};
1656
1657static struct ncache_orangefs_attribute ncache_hard_limit_attribute =
1658 __ATTR(hard_limit,
1659 0664,
1660 service_ncache_show,
1661 service_ncache_store);
1662
1663static struct ncache_orangefs_attribute ncache_reclaim_percent_attribute =
1664 __ATTR(reclaim_percentage,
1665 0664,
1666 service_ncache_show,
1667 service_ncache_store);
1668
1669static struct ncache_orangefs_attribute ncache_soft_limit_attribute =
1670 __ATTR(soft_limit,
1671 0664,
1672 service_ncache_show,
1673 service_ncache_store);
1674
1675static struct ncache_orangefs_attribute ncache_timeout_msecs_attribute =
1676 __ATTR(timeout_msecs,
1677 0664,
1678 service_ncache_show,
1679 service_ncache_store);
1680
1681static struct attribute *ncache_orangefs_default_attrs[] = {
1682 &ncache_hard_limit_attribute.attr,
1683 &ncache_reclaim_percent_attribute.attr,
1684 &ncache_soft_limit_attribute.attr,
1685 &ncache_timeout_msecs_attribute.attr,
1686 NULL,
1687};
1688
1689static struct kobj_type ncache_orangefs_ktype = {
1690 .sysfs_ops = &ncache_orangefs_sysfs_ops,
1691 .release = ncache_orangefs_release,
1692 .default_attrs = ncache_orangefs_default_attrs,
1693};
1694
1695static struct pc_orangefs_attribute pc_acache_attribute =
1696 __ATTR(acache,
1697 0664,
1698 service_pc_show,
1699 NULL);
1700
1701static struct pc_orangefs_attribute pc_capcache_attribute =
1702 __ATTR(capcache,
1703 0664,
1704 service_pc_show,
1705 NULL);
1706
1707static struct pc_orangefs_attribute pc_ncache_attribute =
1708 __ATTR(ncache,
1709 0664,
1710 service_pc_show,
1711 NULL);
1712
1713static struct attribute *pc_orangefs_default_attrs[] = {
1714 &pc_acache_attribute.attr,
1715 &pc_capcache_attribute.attr,
1716 &pc_ncache_attribute.attr,
1717 NULL,
1718};
1719
1720static struct kobj_type pc_orangefs_ktype = {
1721 .sysfs_ops = &pc_orangefs_sysfs_ops,
1722 .release = pc_orangefs_release,
1723 .default_attrs = pc_orangefs_default_attrs,
1724};
1725
1726static struct stats_orangefs_attribute stats_reads_attribute =
1727 __ATTR(reads,
1728 0664,
1729 int_stats_show,
1730 NULL);
1731
1732static struct stats_orangefs_attribute stats_writes_attribute =
1733 __ATTR(writes,
1734 0664,
1735 int_stats_show,
1736 NULL);
1737
1738static struct attribute *stats_orangefs_default_attrs[] = {
1739 &stats_reads_attribute.attr,
1740 &stats_writes_attribute.attr,
1741 NULL,
1742};
1743
1744static struct kobj_type stats_orangefs_ktype = {
1745 .sysfs_ops = &stats_orangefs_sysfs_ops,
1746 .release = stats_orangefs_release,
1747 .default_attrs = stats_orangefs_default_attrs,
1748};
1749
1750static struct orangefs_obj *orangefs_obj;
1751static struct acache_orangefs_obj *acache_orangefs_obj;
1752static struct capcache_orangefs_obj *capcache_orangefs_obj;
1753static struct ccache_orangefs_obj *ccache_orangefs_obj;
1754static struct ncache_orangefs_obj *ncache_orangefs_obj;
1755static struct pc_orangefs_obj *pc_orangefs_obj;
1756static struct stats_orangefs_obj *stats_orangefs_obj;
1757
1758int orangefs_sysfs_init(void)
1759{
Mike Marshall2180c522016-03-14 15:30:39 -04001760 int rc = -EINVAL;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001761
1762 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_init: start\n");
1763
1764 /* create /sys/fs/orangefs. */
1765 orangefs_obj = kzalloc(sizeof(*orangefs_obj), GFP_KERNEL);
Mike Marshall2180c522016-03-14 15:30:39 -04001766 if (!orangefs_obj)
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001767 goto out;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001768
1769 rc = kobject_init_and_add(&orangefs_obj->kobj,
1770 &orangefs_ktype,
1771 fs_kobj,
1772 ORANGEFS_KOBJ_ID);
1773
Mike Marshall2180c522016-03-14 15:30:39 -04001774 if (rc)
1775 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001776
1777 kobject_uevent(&orangefs_obj->kobj, KOBJ_ADD);
1778
1779 /* create /sys/fs/orangefs/acache. */
1780 acache_orangefs_obj = kzalloc(sizeof(*acache_orangefs_obj), GFP_KERNEL);
1781 if (!acache_orangefs_obj) {
1782 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001783 goto ofs_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001784 }
1785
1786 rc = kobject_init_and_add(&acache_orangefs_obj->kobj,
1787 &acache_orangefs_ktype,
1788 &orangefs_obj->kobj,
1789 ACACHE_KOBJ_ID);
1790
Mike Marshall2180c522016-03-14 15:30:39 -04001791 if (rc)
1792 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001793
1794 kobject_uevent(&acache_orangefs_obj->kobj, KOBJ_ADD);
1795
1796 /* create /sys/fs/orangefs/capcache. */
1797 capcache_orangefs_obj =
1798 kzalloc(sizeof(*capcache_orangefs_obj), GFP_KERNEL);
1799 if (!capcache_orangefs_obj) {
1800 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001801 goto acache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001802 }
1803
1804 rc = kobject_init_and_add(&capcache_orangefs_obj->kobj,
1805 &capcache_orangefs_ktype,
1806 &orangefs_obj->kobj,
1807 CAPCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001808 if (rc)
1809 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001810
1811 kobject_uevent(&capcache_orangefs_obj->kobj, KOBJ_ADD);
1812
1813 /* create /sys/fs/orangefs/ccache. */
1814 ccache_orangefs_obj =
1815 kzalloc(sizeof(*ccache_orangefs_obj), GFP_KERNEL);
1816 if (!ccache_orangefs_obj) {
1817 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001818 goto capcache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001819 }
1820
1821 rc = kobject_init_and_add(&ccache_orangefs_obj->kobj,
1822 &ccache_orangefs_ktype,
1823 &orangefs_obj->kobj,
1824 CCACHE_KOBJ_ID);
Mike Marshall2180c522016-03-14 15:30:39 -04001825 if (rc)
1826 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001827
1828 kobject_uevent(&ccache_orangefs_obj->kobj, KOBJ_ADD);
1829
1830 /* create /sys/fs/orangefs/ncache. */
1831 ncache_orangefs_obj = kzalloc(sizeof(*ncache_orangefs_obj), GFP_KERNEL);
1832 if (!ncache_orangefs_obj) {
1833 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001834 goto ccache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001835 }
1836
1837 rc = kobject_init_and_add(&ncache_orangefs_obj->kobj,
1838 &ncache_orangefs_ktype,
1839 &orangefs_obj->kobj,
1840 NCACHE_KOBJ_ID);
1841
Mike Marshall2180c522016-03-14 15:30:39 -04001842 if (rc)
1843 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001844
1845 kobject_uevent(&ncache_orangefs_obj->kobj, KOBJ_ADD);
1846
1847 /* create /sys/fs/orangefs/perf_counters. */
1848 pc_orangefs_obj = kzalloc(sizeof(*pc_orangefs_obj), GFP_KERNEL);
1849 if (!pc_orangefs_obj) {
1850 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001851 goto ncache_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001852 }
1853
1854 rc = kobject_init_and_add(&pc_orangefs_obj->kobj,
1855 &pc_orangefs_ktype,
1856 &orangefs_obj->kobj,
1857 "perf_counters");
1858
Mike Marshall2180c522016-03-14 15:30:39 -04001859 if (rc)
1860 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001861
1862 kobject_uevent(&pc_orangefs_obj->kobj, KOBJ_ADD);
1863
1864 /* create /sys/fs/orangefs/stats. */
1865 stats_orangefs_obj = kzalloc(sizeof(*stats_orangefs_obj), GFP_KERNEL);
1866 if (!stats_orangefs_obj) {
1867 rc = -EINVAL;
Mike Marshall2180c522016-03-14 15:30:39 -04001868 goto pc_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001869 }
1870
1871 rc = kobject_init_and_add(&stats_orangefs_obj->kobj,
1872 &stats_orangefs_ktype,
1873 &orangefs_obj->kobj,
1874 STATS_KOBJ_ID);
1875
Mike Marshall2180c522016-03-14 15:30:39 -04001876 if (rc)
1877 goto stats_obj_bail;
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001878
1879 kobject_uevent(&stats_orangefs_obj->kobj, KOBJ_ADD);
Mike Marshall2180c522016-03-14 15:30:39 -04001880 goto out;
1881
1882stats_obj_bail:
1883 kobject_put(&stats_orangefs_obj->kobj);
1884
1885pc_obj_bail:
1886 kobject_put(&pc_orangefs_obj->kobj);
1887
1888ncache_obj_bail:
1889 kobject_put(&ncache_orangefs_obj->kobj);
1890
1891ccache_obj_bail:
1892 kobject_put(&ccache_orangefs_obj->kobj);
1893
1894capcache_obj_bail:
1895 kobject_put(&capcache_orangefs_obj->kobj);
1896
1897acache_obj_bail:
1898 kobject_put(&acache_orangefs_obj->kobj);
1899
1900ofs_obj_bail:
1901 kobject_put(&orangefs_obj->kobj);
Mike Marshallf7be4ee2015-07-17 10:38:14 -04001902out:
1903 return rc;
1904}
1905
1906void orangefs_sysfs_exit(void)
1907{
1908 gossip_debug(GOSSIP_SYSFS_DEBUG, "orangefs_sysfs_exit: start\n");
1909
1910 kobject_put(&acache_orangefs_obj->kobj);
1911 kobject_put(&capcache_orangefs_obj->kobj);
1912 kobject_put(&ccache_orangefs_obj->kobj);
1913 kobject_put(&ncache_orangefs_obj->kobj);
1914 kobject_put(&pc_orangefs_obj->kobj);
1915 kobject_put(&stats_orangefs_obj->kobj);
1916
1917 kobject_put(&orangefs_obj->kobj);
1918}