Skip to content

Commit ecb37ce

Browse files
andy-shevaxboe
authored andcommitted
bcache: Move couple of functions to sysfs.c
There is couple of functions that are used exclusively in sysfs.c. Move it to there and make them static. Besides above, it will allow further clean up. No functional change intended. Signed-off-by: Andy Shevchenko <[email protected]> Signed-off-by: Coly Li <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 04cbc21 commit ecb37ce

File tree

3 files changed

+35
-40
lines changed

3 files changed

+35
-40
lines changed

drivers/md/bcache/sysfs.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,41 @@ rw_attribute(btree_shrinker_disabled);
132132
rw_attribute(copy_gc_enabled);
133133
rw_attribute(size);
134134

135+
static ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[],
136+
size_t selected)
137+
{
138+
char *out = buf;
139+
size_t i;
140+
141+
for (i = 0; list[i]; i++)
142+
out += snprintf(out, buf + size - out,
143+
i == selected ? "[%s] " : "%s ", list[i]);
144+
145+
out[-1] = '\n';
146+
return out - buf;
147+
}
148+
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+
135170
SHOW(__bch_cached_dev)
136171
{
137172
struct cached_dev *dc = container_of(kobj, struct cached_dev,

drivers/md/bcache/util.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -120,41 +120,6 @@ ssize_t bch_hprint(char *buf, int64_t v)
120120
return sprintf(buf, "%llu.%i%c", q, t * 10 / 1024, units[u]);
121121
}
122122

123-
ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[],
124-
size_t selected)
125-
{
126-
char *out = buf;
127-
size_t i;
128-
129-
for (i = 0; list[i]; i++)
130-
out += snprintf(out, buf + size - out,
131-
i == selected ? "[%s] " : "%s ", list[i]);
132-
133-
out[-1] = '\n';
134-
return out - buf;
135-
}
136-
137-
ssize_t bch_read_string_list(const char *buf, const char * const list[])
138-
{
139-
size_t i;
140-
char *s, *d = kstrndup(buf, PAGE_SIZE - 1, GFP_KERNEL);
141-
if (!d)
142-
return -ENOMEM;
143-
144-
s = strim(d);
145-
146-
for (i = 0; list[i]; i++)
147-
if (!strcmp(list[i], s))
148-
break;
149-
150-
kfree(d);
151-
152-
if (!list[i])
153-
return -EINVAL;
154-
155-
return i;
156-
}
157-
158123
bool bch_is_zero(const char *p, size_t n)
159124
{
160125
size_t i;

drivers/md/bcache/util.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,6 @@ ssize_t bch_hprint(char *buf, int64_t v);
365365
bool bch_is_zero(const char *p, size_t n);
366366
int bch_parse_uuid(const char *s, char *uuid);
367367

368-
ssize_t bch_snprint_string_list(char *buf, size_t size, const char * const list[],
369-
size_t selected);
370-
371-
ssize_t bch_read_string_list(const char *buf, const char * const list[]);
372-
373368
struct time_stats {
374369
spinlock_t lock;
375370
/*

0 commit comments

Comments
 (0)