Skip to content

Commit 77c320e

Browse files
author
Kent Overstreet
committed
bcache: Add on error panic/unregister setting
Works kind of like the ext4 setting, to panic or remount read only on errors. Signed-off-by: Kent Overstreet <kmo@daterainc.com>
1 parent 49b1212 commit 77c320e

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

‎drivers/md/bcache/bcache.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,8 +843,14 @@ struct cache_set {
843843
atomic_long_t cache_read_races;
844844
atomic_long_t writeback_keys_done;
845845
atomic_long_t writeback_keys_failed;
846+
847+
enum {
848+
ON_ERROR_UNREGISTER,
849+
ON_ERROR_PANIC,
850+
} on_error;
846851
unsigned error_limit;
847852
unsigned error_decay;
853+
848854
unsigned short journal_delay_ms;
849855
unsigned verify:1;
850856
unsigned key_merging_disabled:1;

‎drivers/md/bcache/journal.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,9 @@ int bch_journal_replay(struct cache_set *s, struct list_head *list,
305305
list_for_each_entry(i, list, list) {
306306
BUG_ON(i->pin && atomic_read(i->pin) != 1);
307307

308-
if (n != i->j.seq)
309-
pr_err(
310-
"journal entries %llu-%llu missing! (replaying %llu-%llu)\n",
311-
n, i->j.seq - 1, start, end);
308+
cache_set_err_on(n != i->j.seq, s,
309+
"bcache: journal entries %llu-%llu missing! (replaying %llu-%llu)",
310+
n, i->j.seq - 1, start, end);
312311

313312
for (k = i->j.start;
314313
k < end(&i->j);

‎drivers/md/bcache/super.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,8 @@ bool bch_cache_set_error(struct cache_set *c, const char *fmt, ...)
12601260
{
12611261
va_list args;
12621262

1263-
if (test_bit(CACHE_SET_STOPPING, &c->flags))
1263+
if (c->on_error != ON_ERROR_PANIC &&
1264+
test_bit(CACHE_SET_STOPPING, &c->flags))
12641265
return false;
12651266

12661267
/* XXX: we can be called from atomic context
@@ -1275,6 +1276,9 @@ bool bch_cache_set_error(struct cache_set *c, const char *fmt, ...)
12751276

12761277
printk(", disabling caching\n");
12771278

1279+
if (c->on_error == ON_ERROR_PANIC)
1280+
panic("panic forced after error\n");
1281+
12781282
bch_cache_set_unregister(c);
12791283
return true;
12801284
}

‎drivers/md/bcache/sysfs.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ static const char * const cache_replacement_policies[] = {
2121
NULL
2222
};
2323

24+
static const char * const error_actions[] = {
25+
"unregister",
26+
"panic",
27+
NULL
28+
};
29+
2430
write_attribute(attach);
2531
write_attribute(detach);
2632
write_attribute(unregister);
@@ -90,6 +96,7 @@ rw_attribute(discard);
9096
rw_attribute(running);
9197
rw_attribute(label);
9298
rw_attribute(readahead);
99+
rw_attribute(errors);
93100
rw_attribute(io_error_limit);
94101
rw_attribute(io_error_halflife);
95102
rw_attribute(verify);
@@ -492,6 +499,10 @@ SHOW(__bch_cache_set)
492499
sysfs_print(writeback_keys_failed,
493500
atomic_long_read(&c->writeback_keys_failed));
494501

502+
if (attr == &sysfs_errors)
503+
return bch_snprint_string_list(buf, PAGE_SIZE, error_actions,
504+
c->on_error);
505+
495506
/* See count_io_errors for why 88 */
496507
sysfs_print(io_error_halflife, c->error_decay * 88);
497508
sysfs_print(io_error_limit, c->error_limit >> IO_ERROR_SHIFT);
@@ -569,6 +580,15 @@ STORE(__bch_cache_set)
569580
sysfs_strtoul(congested_write_threshold_us,
570581
c->congested_write_threshold_us);
571582

583+
if (attr == &sysfs_errors) {
584+
ssize_t v = bch_read_string_list(buf, error_actions);
585+
586+
if (v < 0)
587+
return v;
588+
589+
c->on_error = v;
590+
}
591+
572592
if (attr == &sysfs_io_error_limit)
573593
c->error_limit = strtoul_or_return(buf) << IO_ERROR_SHIFT;
574594

@@ -620,6 +640,7 @@ static struct attribute *bch_cache_set_files[] = {
620640
&sysfs_average_key_size,
621641
&sysfs_dirty_data,
622642

643+
&sysfs_errors,
623644
&sysfs_io_error_limit,
624645
&sysfs_io_error_halflife,
625646
&sysfs_congested,

0 commit comments

Comments
 (0)