bcache: use sysfs_strtoul_bool() to set bit-field variables
authorColy Li <colyli@suse.de>
Sat, 9 Feb 2019 04:53:03 +0000 (12:53 +0800)
committerJens Axboe <axboe@kernel.dk>
Sat, 9 Feb 2019 14:18:32 +0000 (07:18 -0700)
When setting bcache parameters via sysfs, there are some variables are
defined as bit-field value. Current bcache code in sysfs.c uses either
d_strtoul() or sysfs_strtoul() to convert the input string to unsigned
integer value and set it to the corresponded bit-field value.

The problem is, the bit-field value only takes the lowest bit of the
converted value. If input is 2, the expected value (like bool value)
of the bit-field value should be 1, but indeed it is 0.

The following sysfs files for bit-field variables have such problem,
bypass_torture_test, for dc->bypass_torture_test
writeback_metadata, for dc->writeback_metadata
writeback_running, for dc->writeback_running
verify, for c->verify
key_merging_disabled, for c->key_merging_disabled
gc_always_rewrite, for c->gc_always_rewrite
btree_shrinker_disabled,for c->shrinker_disabled
copy_gc_enabled, for c->copy_gc_enabled

This patch uses sysfs_strtoul_bool() to set such bit-field variables,
then if the converted value is non-zero, the bit-field variables will
be set to 1, like setting a bool value like expensive_debug_checks.

Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/sysfs.c

index 96b64893f2cb72c772f07a7cc48e58cc918539f9..57395e23747a2074c75e76bc2bbd02e84ef37b64 100644 (file)
@@ -277,9 +277,9 @@ STORE(__cached_dev)
 
        sysfs_strtoul(data_csum,        dc->disk.data_csum);
        d_strtoul(verify);
-       d_strtoul(bypass_torture_test);
-       d_strtoul(writeback_metadata);
-       d_strtoul(writeback_running);
+       sysfs_strtoul_bool(bypass_torture_test, dc->bypass_torture_test);
+       sysfs_strtoul_bool(writeback_metadata, dc->writeback_metadata);
+       sysfs_strtoul_bool(writeback_running, dc->writeback_running);
        d_strtoul(writeback_delay);
 
        sysfs_strtoul_clamp(writeback_percent, dc->writeback_percent,
@@ -816,12 +816,12 @@ STORE(__bch_cache_set)
        }
 
        sysfs_strtoul(journal_delay_ms,         c->journal_delay_ms);
-       sysfs_strtoul(verify,                   c->verify);
-       sysfs_strtoul(key_merging_disabled,     c->key_merging_disabled);
+       sysfs_strtoul_bool(verify,              c->verify);
+       sysfs_strtoul_bool(key_merging_disabled, c->key_merging_disabled);
        sysfs_strtoul(expensive_debug_checks,   c->expensive_debug_checks);
-       sysfs_strtoul(gc_always_rewrite,        c->gc_always_rewrite);
-       sysfs_strtoul(btree_shrinker_disabled,  c->shrinker_disabled);
-       sysfs_strtoul(copy_gc_enabled,          c->copy_gc_enabled);
+       sysfs_strtoul_bool(gc_always_rewrite,   c->gc_always_rewrite);
+       sysfs_strtoul_bool(btree_shrinker_disabled, c->shrinker_disabled);
+       sysfs_strtoul_bool(copy_gc_enabled,     c->copy_gc_enabled);
        /*
         * write gc_after_writeback here may overwrite an already set
         * BCH_DO_AUTO_GC, it doesn't matter because this flag will be