sysfs.c (5461999848e0462c14f306a62923d22de820a59c) sysfs.c (a59ff6ccc2bf2e2934b31bbf734f0bc04b5ec78a)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * bcache sysfs interfaces
4 *
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
7 */
8
9#include "bcache.h"
10#include "sysfs.h"
11#include "btree.h"
12#include "request.h"
13#include "writeback.h"
14
15#include <linux/blkdev.h>
16#include <linux/sort.h>
17#include <linux/sched/clock.h>
18
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * bcache sysfs interfaces
4 *
5 * Copyright 2010, 2011 Kent Overstreet <kent.overstreet@gmail.com>
6 * Copyright 2012 Google, Inc.
7 */
8
9#include "bcache.h"
10#include "sysfs.h"
11#include "btree.h"
12#include "request.h"
13#include "writeback.h"
14
15#include <linux/blkdev.h>
16#include <linux/sort.h>
17#include <linux/sched/clock.h>
18
19extern bool bcache_is_reboot;
20
19/* Default is 0 ("writethrough") */
20static const char * const bch_cache_modes[] = {
21 "writethrough",
22 "writeback",
23 "writearound",
24 "none"
25};
26

--- 235 unchanged lines hidden (view full) ---

262STORE(__cached_dev)
263{
264 struct cached_dev *dc = container_of(kobj, struct cached_dev,
265 disk.kobj);
266 ssize_t v;
267 struct cache_set *c;
268 struct kobj_uevent_env *env;
269
21/* Default is 0 ("writethrough") */
22static const char * const bch_cache_modes[] = {
23 "writethrough",
24 "writeback",
25 "writearound",
26 "none"
27};
28

--- 235 unchanged lines hidden (view full) ---

264STORE(__cached_dev)
265{
266 struct cached_dev *dc = container_of(kobj, struct cached_dev,
267 disk.kobj);
268 ssize_t v;
269 struct cache_set *c;
270 struct kobj_uevent_env *env;
271
272 /* no user space access if system is rebooting */
273 if (bcache_is_reboot)
274 return -EBUSY;
275
270#define d_strtoul(var) sysfs_strtoul(var, dc->var)
271#define d_strtoul_nonzero(var) sysfs_strtoul_clamp(var, dc->var, 1, INT_MAX)
272#define d_strtoi_h(var) sysfs_hatoi(var, dc->var)
273
274 sysfs_strtoul(data_csum, dc->disk.data_csum);
275 d_strtoul(verify);
276 sysfs_strtoul_bool(bypass_torture_test, dc->bypass_torture_test);
277 sysfs_strtoul_bool(writeback_metadata, dc->writeback_metadata);

--- 124 unchanged lines hidden (view full) ---

402 return size;
403}
404
405STORE(bch_cached_dev)
406{
407 struct cached_dev *dc = container_of(kobj, struct cached_dev,
408 disk.kobj);
409
276#define d_strtoul(var) sysfs_strtoul(var, dc->var)
277#define d_strtoul_nonzero(var) sysfs_strtoul_clamp(var, dc->var, 1, INT_MAX)
278#define d_strtoi_h(var) sysfs_hatoi(var, dc->var)
279
280 sysfs_strtoul(data_csum, dc->disk.data_csum);
281 d_strtoul(verify);
282 sysfs_strtoul_bool(bypass_torture_test, dc->bypass_torture_test);
283 sysfs_strtoul_bool(writeback_metadata, dc->writeback_metadata);

--- 124 unchanged lines hidden (view full) ---

408 return size;
409}
410
411STORE(bch_cached_dev)
412{
413 struct cached_dev *dc = container_of(kobj, struct cached_dev,
414 disk.kobj);
415
416 /* no user space access if system is rebooting */
417 if (bcache_is_reboot)
418 return -EBUSY;
419
410 mutex_lock(&bch_register_lock);
411 size = __cached_dev_store(kobj, attr, buf, size);
412
413 if (attr == &sysfs_writeback_running) {
414 /* dc->writeback_running changed in __cached_dev_store() */
415 if (IS_ERR_OR_NULL(dc->writeback_thread)) {
416 /*
417 * reject setting it to 1 via sysfs if writeback

--- 87 unchanged lines hidden (view full) ---

505}
506
507STORE(__bch_flash_dev)
508{
509 struct bcache_device *d = container_of(kobj, struct bcache_device,
510 kobj);
511 struct uuid_entry *u = &d->c->uuids[d->id];
512
420 mutex_lock(&bch_register_lock);
421 size = __cached_dev_store(kobj, attr, buf, size);
422
423 if (attr == &sysfs_writeback_running) {
424 /* dc->writeback_running changed in __cached_dev_store() */
425 if (IS_ERR_OR_NULL(dc->writeback_thread)) {
426 /*
427 * reject setting it to 1 via sysfs if writeback

--- 87 unchanged lines hidden (view full) ---

515}
516
517STORE(__bch_flash_dev)
518{
519 struct bcache_device *d = container_of(kobj, struct bcache_device,
520 kobj);
521 struct uuid_entry *u = &d->c->uuids[d->id];
522
523 /* no user space access if system is rebooting */
524 if (bcache_is_reboot)
525 return -EBUSY;
526
513 sysfs_strtoul(data_csum, d->data_csum);
514
515 if (attr == &sysfs_size) {
516 uint64_t v;
517
518 strtoi_h_or_return(buf, v);
519
520 u->sectors = v >> 9;

--- 219 unchanged lines hidden (view full) ---

740}
741SHOW_LOCKED(bch_cache_set)
742
743STORE(__bch_cache_set)
744{
745 struct cache_set *c = container_of(kobj, struct cache_set, kobj);
746 ssize_t v;
747
527 sysfs_strtoul(data_csum, d->data_csum);
528
529 if (attr == &sysfs_size) {
530 uint64_t v;
531
532 strtoi_h_or_return(buf, v);
533
534 u->sectors = v >> 9;

--- 219 unchanged lines hidden (view full) ---

754}
755SHOW_LOCKED(bch_cache_set)
756
757STORE(__bch_cache_set)
758{
759 struct cache_set *c = container_of(kobj, struct cache_set, kobj);
760 ssize_t v;
761
762 /* no user space access if system is rebooting */
763 if (bcache_is_reboot)
764 return -EBUSY;
765
748 if (attr == &sysfs_unregister)
749 bch_cache_set_unregister(c);
750
751 if (attr == &sysfs_stop)
752 bch_cache_set_stop(c);
753
754 if (attr == &sysfs_synchronous) {
755 bool sync = strtoul_or_return(buf);

--- 103 unchanged lines hidden (view full) ---

859
860 return bch_cache_set_show(&c->kobj, attr, buf);
861}
862
863STORE(bch_cache_set_internal)
864{
865 struct cache_set *c = container_of(kobj, struct cache_set, internal);
866
766 if (attr == &sysfs_unregister)
767 bch_cache_set_unregister(c);
768
769 if (attr == &sysfs_stop)
770 bch_cache_set_stop(c);
771
772 if (attr == &sysfs_synchronous) {
773 bool sync = strtoul_or_return(buf);

--- 103 unchanged lines hidden (view full) ---

877
878 return bch_cache_set_show(&c->kobj, attr, buf);
879}
880
881STORE(bch_cache_set_internal)
882{
883 struct cache_set *c = container_of(kobj, struct cache_set, internal);
884
885 /* no user space access if system is rebooting */
886 if (bcache_is_reboot)
887 return -EBUSY;
888
867 return bch_cache_set_store(&c->kobj, attr, buf, size);
868}
869
870static void bch_cache_set_internal_release(struct kobject *k)
871{
872}
873
874static struct attribute *bch_cache_set_files[] = {

--- 169 unchanged lines hidden (view full) ---

1044}
1045SHOW_LOCKED(bch_cache)
1046
1047STORE(__bch_cache)
1048{
1049 struct cache *ca = container_of(kobj, struct cache, kobj);
1050 ssize_t v;
1051
889 return bch_cache_set_store(&c->kobj, attr, buf, size);
890}
891
892static void bch_cache_set_internal_release(struct kobject *k)
893{
894}
895
896static struct attribute *bch_cache_set_files[] = {

--- 169 unchanged lines hidden (view full) ---

1066}
1067SHOW_LOCKED(bch_cache)
1068
1069STORE(__bch_cache)
1070{
1071 struct cache *ca = container_of(kobj, struct cache, kobj);
1072 ssize_t v;
1073
1074 /* no user space access if system is rebooting */
1075 if (bcache_is_reboot)
1076 return -EBUSY;
1077
1052 if (attr == &sysfs_discard) {
1053 bool v = strtoul_or_return(buf);
1054
1055 if (blk_queue_discard(bdev_get_queue(ca->bdev)))
1056 ca->discard = v;
1057
1058 if (v != CACHE_DISCARD(&ca->sb)) {
1059 SET_CACHE_DISCARD(&ca->sb, v);

--- 45 unchanged lines hidden ---
1078 if (attr == &sysfs_discard) {
1079 bool v = strtoul_or_return(buf);
1080
1081 if (blk_queue_discard(bdev_get_queue(ca->bdev)))
1082 ca->discard = v;
1083
1084 if (v != CACHE_DISCARD(&ca->sb)) {
1085 SET_CACHE_DISCARD(&ca->sb, v);

--- 45 unchanged lines hidden ---