18
18
19
19
/* Default is -1; we skip past it for struct cached_dev's cache mode */
20
20
static const char * const bch_cache_modes [] = {
21
- "default" ,
22
21
"writethrough" ,
23
22
"writeback" ,
24
23
"writearound" ,
@@ -28,7 +27,6 @@ static const char * const bch_cache_modes[] = {
28
27
29
28
/* Default is -1; we skip past it for stop_when_cache_set_failed */
30
29
static const char * const bch_stop_on_failure_modes [] = {
31
- "default" ,
32
30
"auto" ,
33
31
"always" ,
34
32
NULL
@@ -146,27 +144,6 @@ static ssize_t bch_snprint_string_list(char *buf, size_t size, const char * cons
146
144
return out - buf ;
147
145
}
148
146
149
- static ssize_t bch_read_string_list (const char * buf , const char * const list [])
150
- {
151
- size_t i ;
152
- char * s , * d = kstrndup (buf , PAGE_SIZE - 1 , GFP_KERNEL );
153
- if (!d )
154
- return - ENOMEM ;
155
-
156
- s = strim (d );
157
-
158
- for (i = 0 ; list [i ]; i ++ )
159
- if (!strcmp (list [i ], s ))
160
- break ;
161
-
162
- kfree (d );
163
-
164
- if (!list [i ])
165
- return - EINVAL ;
166
-
167
- return i ;
168
- }
169
-
170
147
SHOW (__bch_cached_dev )
171
148
{
172
149
struct cached_dev * dc = container_of (kobj , struct cached_dev ,
@@ -177,12 +154,12 @@ SHOW(__bch_cached_dev)
177
154
178
155
if (attr == & sysfs_cache_mode )
179
156
return bch_snprint_string_list (buf , PAGE_SIZE ,
180
- bch_cache_modes + 1 ,
157
+ bch_cache_modes ,
181
158
BDEV_CACHE_MODE (& dc -> sb ));
182
159
183
160
if (attr == & sysfs_stop_when_cache_set_failed )
184
161
return bch_snprint_string_list (buf , PAGE_SIZE ,
185
- bch_stop_on_failure_modes + 1 ,
162
+ bch_stop_on_failure_modes ,
186
163
dc -> stop_when_cache_set_failed );
187
164
188
165
@@ -306,8 +283,7 @@ STORE(__cached_dev)
306
283
bch_cached_dev_run (dc );
307
284
308
285
if (attr == & sysfs_cache_mode ) {
309
- v = bch_read_string_list (buf , bch_cache_modes + 1 );
310
-
286
+ v = __sysfs_match_string (bch_cache_modes , -1 , buf );
311
287
if (v < 0 )
312
288
return v ;
313
289
@@ -318,8 +294,7 @@ STORE(__cached_dev)
318
294
}
319
295
320
296
if (attr == & sysfs_stop_when_cache_set_failed ) {
321
- v = bch_read_string_list (buf , bch_stop_on_failure_modes + 1 );
322
-
297
+ v = __sysfs_match_string (bch_stop_on_failure_modes , -1 , buf );
323
298
if (v < 0 )
324
299
return v ;
325
300
@@ -688,6 +663,7 @@ SHOW_LOCKED(bch_cache_set)
688
663
STORE (__bch_cache_set )
689
664
{
690
665
struct cache_set * c = container_of (kobj , struct cache_set , kobj );
666
+ ssize_t v ;
691
667
692
668
if (attr == & sysfs_unregister )
693
669
bch_cache_set_unregister (c );
@@ -751,8 +727,7 @@ STORE(__bch_cache_set)
751
727
c -> congested_write_threshold_us );
752
728
753
729
if (attr == & sysfs_errors ) {
754
- ssize_t v = bch_read_string_list (buf , error_actions );
755
-
730
+ v = __sysfs_match_string (error_actions , -1 , buf );
756
731
if (v < 0 )
757
732
return v ;
758
733
@@ -767,8 +742,7 @@ STORE(__bch_cache_set)
767
742
c -> error_decay = strtoul_or_return (buf ) / 88 ;
768
743
769
744
if (attr == & sysfs_io_disable ) {
770
- int v = strtoul_or_return (buf );
771
-
745
+ v = strtoul_or_return (buf );
772
746
if (v ) {
773
747
if (test_and_set_bit (CACHE_SET_IO_DISABLE ,
774
748
& c -> flags ))
@@ -982,6 +956,7 @@ SHOW_LOCKED(bch_cache)
982
956
STORE (__bch_cache )
983
957
{
984
958
struct cache * ca = container_of (kobj , struct cache , kobj );
959
+ ssize_t v ;
985
960
986
961
if (attr == & sysfs_discard ) {
987
962
bool v = strtoul_or_return (buf );
@@ -996,8 +971,7 @@ STORE(__bch_cache)
996
971
}
997
972
998
973
if (attr == & sysfs_cache_replacement_policy ) {
999
- ssize_t v = bch_read_string_list (buf , cache_replacement_policies );
1000
-
974
+ v = __sysfs_match_string (cache_replacement_policies , -1 , buf );
1001
975
if (v < 0 )
1002
976
return v ;
1003
977
0 commit comments