bcache patches for 4.18
Subsystems (2)
v2 cover bcache patches for 4.18
Hi Jens,
Here are the first wave bcache patches for linux v4.18, not too much changes.
- Andy Shevchenko contributes several clean up patches for bcache.
- A reviewed patch from me, about the bcache device failure improvement series.
There are still some patches waiting for peer review. Once they get reviewed and it is still in good timing, I will submit them in next waves.
Thanks in advance.
Coly Li
---
Andy Shevchenko (3):
bcache: Move couple of string arrays to sysfs.c
bcache: Move couple of functions to sysfs.c
bcache: Replace bch_read_string_list() by __sysfs_match_string()
Coly Li (1):
bcache: stop bcache device when backing device is offline
drivers/md/bcache/bcache.h | 4 +-- drivers/md/bcache/super.c | 71 ++++++++++++++++++++++++++++---------- drivers/md/bcache/sysfs.c | 51 ++++++++++++++++++++------- drivers/md/bcache/util.c | 35 ------------------- drivers/md/bcache/util.h | 5 --- 5 files changed, 94 insertions(+), 72 deletions(-)
Signature · 1 line
2.17.0
PATCH v2 1/4 bcache: stop bcache device when backing device is offline
Currently bcache does not handle backing device failure, if backing device is offline and disconnected from system, its bcache device can still be accessible. If the bcache device is in writeback mode, I/O requests even can success if the requests hit on cache device. That is to say, when and how bcache handles offline backing device is undefined.
This patch tries to handle backing device offline in a rather simple way,
- Add cached_dev->status_update_thread kernel thread to update backing device status in every 1 second.
- Add cached_dev->offline_seconds to record how many seconds the backing device is observed to be offline. If the backing device is offline for BACKING_DEV_OFFLINE_TIMEOUT (30) seconds, set dc->io_disable to 1 and call bcache_device_stop() to stop the bache device which linked to the offline backing device.
Now if a backing device is offline for BACKING_DEV_OFFLINE_TIMEOUT seconds, its bcache device will be removed, then user space application writing on it will get error immediately, and handler the device failure in time.
This patch is quite simple, does not handle more complicated situations. Once the bcache device is stopped, users need to recovery the backing device, register and attach it manually.
Changelog:
v3: call wait_for_kthread_stop() before exits kernel thread.
v2: remove "bcache: " prefix when calling pr_warn().
v1: initial version.
--- drivers/md/bcache/bcache.h | 2 ++ drivers/md/bcache/super.c | 53 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+)
drivers/md/bcache/bcache.h +2 -0
@@ -345,6 +345,7 @@ struct cached_dev {struct keybuf writeback_keys; +struct task_struct *status_update_thread;/* * Order the write-half of writeback operations strongly in dispatch * order. (Maintain LBA order; don't allow reads completing out of
@@ -392,6 +393,7 @@ struct cached_dev {#define DEFAULT_CACHED_DEV_ERROR_LIMIT 64atomic_t io_errors;unsigned error_limit; +unsigned offline_seconds;char backing_dev_name[BDEVNAME_SIZE ]; };
drivers/md/bcache/super.c +53 -0
77 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v2 2/4 bcache: Move couple of string arrays to sysfs.c
In reply to Coly LiFrom: Andy Shevchenko <[email protected]>
There is couple of string arrays 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.
--- drivers/md/bcache/bcache.h | 2 -- drivers/md/bcache/super.c | 18 ------------------ drivers/md/bcache/sysfs.c | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-)
drivers/md/bcache/bcache.h +0 -2
@@ -958,8 +958,6 @@ void bch_prio_write(struct cache *);void bch_write_bdev_super (struct cached_dev *,struct closure *);extern struct workqueue_struct *bcache_wq; -extern const char *const bch_cache_modes[]; -extern const char *const bch_stop_on_failure_modes[];extern struct mutex bch_register_lock;extern struct list_head bch_cache_sets;
drivers/md/bcache/super.c +0 -18
@@ -37,24 +37,6 @@ static const char invalid_uuid[] = { 0xc8, 0x50, 0xfc, 0x5e, 0xcb, 0x16, 0xcd, 0x99 }; -/* Default is -1; we skip past it for struct cached_dev's cache mode */ -const char *const bch_cache_modes[] = { -"default" , -"writethrough" , -"writeback" , -"writearound" , -"none" , -NULL -}; - -/* Default is -1; we skip past it for stop_when_cache_set_failed */ -const char *const bch_stop_on_failure_modes[] = { -"default" , -"auto" , -"always" , -NULL -}; -static struct kobject *bcache_kobj;struct mutex bch_register_lock;LIST_HEAD (bch_cache_sets);
drivers/md/bcache/sysfs.c +18 -0
@@ -16,6 +16,24 @@#include <linux/sort.h> #include <linux/sched/clock.h> +/* Default is -1; we skip past it for struct cached_dev's cache mode */ +static const char *const bch_cache_modes[] = { +"default" , +"writethrough" , +"writeback" , +"writearound" , +"none" , +NULL +}; + +/* Default is -1; we skip past it for stop_when_cache_set_failed */ +static const char *const bch_stop_on_failure_modes[] = { +"default" , +"auto" , +"always" , +NULL +}; +static const char *const cache_replacement_policies[] = {"lru" ,"fifo" ,
Signature · 1 line
2.17.0
Re: [PATCH 2/4] bcache: Move couple of string arrays to sysfs.c
Quoted 9 lines · On Mon, 28 May 2018 15:37:42 +0800 Coly Li <[email protected]> wrote:
From: Andy Shevchenko <[email protected]>
There is couple of string arrays 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.
Quoted 8 lines
Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Coly Li <[email protected]>--- drivers/md/bcache/bcache.h | 2 -- drivers/md/bcache/super.c | 18 ------------------ drivers/md/bcache/sysfs.c | 18 ++++++++++++++++++ 3 files changed, 18 insertions(+), 20 deletions(-)
Cheers,
Hannes
PATCH v2 3/4 bcache: Move couple of functions to sysfs.c
In reply to Coly LiFrom: Andy Shevchenko <[email protected]>
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.
--- drivers/md/bcache/sysfs.c | 35 +++++++++++++++++++++++++++++++++++ drivers/md/bcache/util.c | 35 ----------------------------------- drivers/md/bcache/util.h | 5 ----- 3 files changed, 35 insertions(+), 40 deletions(-)
drivers/md/bcache/sysfs.c +35 -0
@@ -132,6 +132,41 @@ rw_attribute(btree_shrinker_disabled);rw_attribute (copy_gc_enabled);rw_attribute (size); +static ssize_t bch_snprint_string_list (char *buf,size_t size,const char *const list[], +size_t selected) +{ +char *out = buf; +size_t i; + +for (i =0 ; list[i]; i++) + out +=snprintf (out, buf + size - out, + i == selected ?"[%s] " :"%s " , list[i]); + + out[-1 ] ='\n' ; +return out - buf; +} + +static ssize_t bch_read_string_list (const char *buf,const char *const list[]) +{ +size_t i; +char *s, *d =kstrndup (buf,PAGE_SIZE -1 ,GFP_KERNEL ); +if (!d) +return -ENOMEM ; + + s =strim (d); + +for (i =0 ; list[i]; i++) +if (!strcmp (list[i], s)) +break ; + +kfree (d); + +if (!list[i]) +return -EINVAL ; + +return i; +} +SHOW (__bch_cached_dev) { struct cached_dev *dc = container_of(kobj, struct cached_dev,
drivers/md/bcache/util.c +0 -35
@@ -120,41 +120,6 @@ ssize_t bch_hprint(char *buf, int64_t v)return sprintf (buf,"%llu.%i%c" , q, t *10 /1024 , units[u]); } -ssize_t bch_snprint_string_list (char *buf,size_t size,const char *const list[], -size_t selected) -{ -char *out = buf; -size_t i; - -for (i =0 ; list[i]; i++) - out +=snprintf (out, buf + size - out, - i == selected ?"[%s] " :"%s " , list[i]); - - out[-1 ] ='\n' ; -return out - buf; -} - -ssize_t bch_read_string_list (const char *buf,const char *const list[]) -{ -size_t i; -char *s, *d =kstrndup (buf,PAGE_SIZE -1 ,GFP_KERNEL ); -if (!d) -return -ENOMEM ; - - s =strim (d); - -for (i =0 ; list[i]; i++) -if (!strcmp (list[i], s)) -break ; - -kfree (d); - -if (!list[i]) -return -EINVAL ; - -return i; -} -bool bch_is_zero (const char *p,size_t n) {size_t i;
drivers/md/bcache/util.h +0 -5
@@ -365,11 +365,6 @@ ssize_t bch_hprint(char *buf, int64_t v);bool bch_is_zero (const char *p,size_t n);int bch_parse_uuid (const char *s,char *uuid); -ssize_t bch_snprint_string_list (char *buf,size_t size,const char *const list[], -size_t selected); - -ssize_t bch_read_string_list (const char *buf,const char *const list[]); -struct time_stats {spinlock_t lock;/*
Signature · 1 line
2.17.0
Re: [PATCH 3/4] bcache: Move couple of functions to sysfs.c
Quoted 9 lines · On Mon, 28 May 2018 15:37:43 +0800 Coly Li <[email protected]> wrote:
From: Andy Shevchenko <[email protected]>
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.
Quoted 8 lines
Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Coly Li <[email protected]>--- drivers/md/bcache/sysfs.c | 35 +++++++++++++++++++++++++++++++++++ drivers/md/bcache/util.c | 35 ----------------------------------- drivers/md/bcache/util.h | 5 ----- 3 files changed, 35 insertions(+), 40 deletions(-)
Cheers,
Hannes
PATCH v2 4/4 bcache: Replace bch_read_string_list() by __sysfs_match_string()
In reply to Coly LiFrom: Andy Shevchenko <[email protected]>
Kernel library has a common function to match user input from sysfs against an array of strings. Thus, replace bch_read_string_list() by __sysfs_match_string().
--- drivers/md/bcache/sysfs.c | 44 ++++++++------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-)
drivers/md/bcache/sysfs.c +9 -35
@@ -18,7 +18,6 @@/* Default is -1; we skip past it for struct cached_dev's cache mode */ static const char *const bch_cache_modes[] = { -"default" ,"writethrough" ,"writeback" ,"writearound" ,
@@ -28,7 +27,6 @@ static const char * const bch_cache_modes[] = {/* Default is -1; we skip past it for stop_when_cache_set_failed */ static const char *const bch_stop_on_failure_modes[] = { -"default" ,"auto" ,"always" ,NULL
@@ -146,27 +144,6 @@ static ssize_t bch_snprint_string_list(char *buf, size_t size, const char * consreturn out - buf; } -static ssize_t bch_read_string_list (const char *buf,const char *const list[]) -{ -size_t i; -char *s, *d =kstrndup (buf,PAGE_SIZE -1 ,GFP_KERNEL ); -if (!d) -return -ENOMEM ; - - s =strim (d); - -for (i =0 ; list[i]; i++) -if (!strcmp (list[i], s)) -break ; - -kfree (d); - -if (!list[i]) -return -EINVAL ; - -return i; -} -SHOW (__bch_cached_dev) { struct cached_dev *dc = container_of(kobj, struct cached_dev,
@@ -177,12 +154,12 @@ SHOW(__bch_cached_dev)if (attr == &sysfs_cache_mode)return bch_snprint_string_list (buf,PAGE_SIZE , - bch_cache_modes +1 , + bch_cache_modes,BDEV_CACHE_MODE (&dc->sb));if (attr == &sysfs_stop_when_cache_set_failed)return bch_snprint_string_list (buf,PAGE_SIZE , - bch_stop_on_failure_modes +1 , + bch_stop_on_failure_modes, dc->stop_when_cache_set_failed);
@@ -306,8 +283,7 @@ STORE(__cached_dev)bch_cached_dev_run (dc);if (attr == &sysfs_cache_mode) { - v =bch_read_string_list (buf, bch_cache_modes +1 ); - + v =__sysfs_match_string (bch_cache_modes,-1 , buf);if (v <0 )return v;
@@ -318,8 +294,7 @@ STORE(__cached_dev) }if (attr == &sysfs_stop_when_cache_set_failed) { - v =bch_read_string_list (buf, bch_stop_on_failure_modes +1 ); - + v =__sysfs_match_string (bch_stop_on_failure_modes,-1 , buf);if (v <0 )return v;
@@ -688,6 +663,7 @@ SHOW_LOCKED(bch_cache_set)STORE (__bch_cache_set) { struct cache_set *c = container_of(kobj, struct cache_set, kobj); +ssize_t v;if (attr == &sysfs_unregister)bch_cache_set_unregister (c);
@@ -751,8 +727,7 @@ STORE(__bch_cache_set) c->congested_write_threshold_us);if (attr == &sysfs_errors) { -ssize_t v =bch_read_string_list (buf, error_actions); - + v =__sysfs_match_string (error_actions,-1 , buf);if (v <0 )return v;
@@ -767,8 +742,7 @@ STORE(__bch_cache_set) c->error_decay =strtoul_or_return (buf) /88 ;if (attr == &sysfs_io_disable) { -int v =strtoul_or_return (buf); - + v =strtoul_or_return (buf);if (v) {if (test_and_set_bit (CACHE_SET_IO_DISABLE , &c->flags))
@@ -982,6 +956,7 @@ SHOW_LOCKED(bch_cache)STORE (__bch_cache) { struct cache *ca = container_of(kobj, struct cache, kobj); +ssize_t v;if (attr == &sysfs_discard) {bool v =strtoul_or_return (buf);
@@ -996,8 +971,7 @@ STORE(__bch_cache) }if (attr == &sysfs_cache_replacement_policy) { -ssize_t v =bch_read_string_list (buf, cache_replacement_policies); - + v =__sysfs_match_string (cache_replacement_policies,-1 , buf);if (v <0 )return v;
Signature · 1 line
2.17.0
Re: [PATCH 4/4] bcache: Replace bch_read_string_list() by __sysfs_match_string()
Quoted 6 lines · On Mon, 28 May 2018 15:37:44 +0800 Coly Li <[email protected]> wrote:
From: Andy Shevchenko <[email protected]>
Kernel library has a common function to match user input from sysfs against an array of strings. Thus, replace
bch_read_string_list()by__sysfs_match_string().
Quoted 7 lines
Signed-off-by Andy Shevchenko <[email protected]>Signed-off-by Coly Li <[email protected]>--- drivers/md/bcache/sysfs.c | 44++++++++------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-)
Cheers,
Hannes
Quoted 11 lines · Coly Li
Hi Jens,
Here are the first wave bcache patches for linux v4.18, not too much changes.
- Andy Shevchenko contributes several clean up patches for bcache.
- A reviewed patch from me, about the bcache device failure improvement series.There are still some patches waiting for peer review. Once they get reviewed and it is still in good timing, I will submit them in next waves.
Applied, thanks Coly.
Signature · 1 line
Jens Axboe