bcachefs: Track whether filesystem has errors in superblock

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet 2019-03-28 09:34:55 -04:00 committed by Kent Overstreet
parent a6d90385e6
commit 0bc166ff56
6 changed files with 26 additions and 33 deletions

View File

@ -473,14 +473,6 @@ struct bch_dev {
struct io_count __percpu *io_done; struct io_count __percpu *io_done;
}; };
/*
* Flag bits for what phase of startup/shutdown the cache set is at, how we're
* shutting down, etc.:
*
* BCH_FS_UNREGISTERING means we're not just shutting down, we're detaching
* all the backing devices first (their cached data gets invalidated, and they
* won't automatically reattach).
*/
enum { enum {
/* startup: */ /* startup: */
BCH_FS_ALLOC_READ_DONE, BCH_FS_ALLOC_READ_DONE,
@ -497,11 +489,10 @@ enum {
/* errors: */ /* errors: */
BCH_FS_ERROR, BCH_FS_ERROR,
BCH_FS_ERRORS_FIXED,
/* misc: */ /* misc: */
BCH_FS_BDEV_MOUNTED, BCH_FS_BDEV_MOUNTED,
BCH_FS_FSCK_FIXED_ERRORS,
BCH_FS_FSCK_UNFIXED_ERRORS,
BCH_FS_FIXED_GENS, BCH_FS_FIXED_GENS,
BCH_FS_REBUILD_REPLICAS, BCH_FS_REBUILD_REPLICAS,
BCH_FS_HOLD_BTREE_WRITES, BCH_FS_HOLD_BTREE_WRITES,

View File

@ -1241,7 +1241,9 @@ LE64_BITMASK(BCH_SB_USRQUOTA, struct bch_sb, flags[0], 57, 58);
LE64_BITMASK(BCH_SB_GRPQUOTA, struct bch_sb, flags[0], 58, 59); LE64_BITMASK(BCH_SB_GRPQUOTA, struct bch_sb, flags[0], 58, 59);
LE64_BITMASK(BCH_SB_PRJQUOTA, struct bch_sb, flags[0], 59, 60); LE64_BITMASK(BCH_SB_PRJQUOTA, struct bch_sb, flags[0], 59, 60);
/* 60-64 unused */ LE64_BITMASK(BCH_SB_HAS_ERRORS, struct bch_sb, flags[0], 60, 61);
/* 61-64 unused */
LE64_BITMASK(BCH_SB_STR_HASH_TYPE, struct bch_sb, flags[1], 0, 4); LE64_BITMASK(BCH_SB_STR_HASH_TYPE, struct bch_sb, flags[1], 0, 4);
LE64_BITMASK(BCH_SB_COMPRESSION_TYPE, struct bch_sb, flags[1], 4, 8); LE64_BITMASK(BCH_SB_COMPRESSION_TYPE, struct bch_sb, flags[1], 4, 8);

View File

@ -72,12 +72,9 @@ enum fsck_err_ret bch2_fsck_err(struct bch_fs *c, unsigned flags,
vprintk(fmt, args); vprintk(fmt, args);
va_end(args); va_end(args);
if (c->opts.errors == BCH_ON_ERROR_CONTINUE && return bch2_inconsistent_error(c)
flags & FSCK_CAN_FIX) ? FSCK_ERR_EXIT
return FSCK_ERR_FIX; : FSCK_ERR_FIX;
bch2_inconsistent_error(c);
return FSCK_ERR_EXIT;
} }
mutex_lock(&c->fsck_error_lock); mutex_lock(&c->fsck_error_lock);
@ -110,11 +107,7 @@ print:
if (c->opts.fix_errors == FSCK_OPT_EXIT) { if (c->opts.fix_errors == FSCK_OPT_EXIT) {
bch_err(c, "%s, exiting", buf); bch_err(c, "%s, exiting", buf);
mutex_unlock(&c->fsck_error_lock); } else if (flags & FSCK_CAN_FIX) {
return FSCK_ERR_EXIT;
}
if (flags & FSCK_CAN_FIX) {
if (c->opts.fix_errors == FSCK_OPT_ASK) { if (c->opts.fix_errors == FSCK_OPT_ASK) {
printk(KERN_ERR "%s: fix?", buf); printk(KERN_ERR "%s: fix?", buf);
fix = ask_yn(); fix = ask_yn();
@ -142,13 +135,16 @@ print:
mutex_unlock(&c->fsck_error_lock); mutex_unlock(&c->fsck_error_lock);
set_bit(fix if (fix) {
? BCH_FS_FSCK_FIXED_ERRORS set_bit(BCH_FS_ERRORS_FIXED, &c->flags);
: BCH_FS_FSCK_UNFIXED_ERRORS, &c->flags); return FSCK_ERR_FIX;
} else {
return fix ? FSCK_ERR_FIX set_bit(BCH_FS_ERROR, &c->flags);
: flags & FSCK_CAN_IGNORE ? FSCK_ERR_IGNORE return c->opts.fix_errors == FSCK_OPT_EXIT ||
: FSCK_ERR_EXIT; !(flags & FSCK_CAN_IGNORE)
? FSCK_ERR_EXIT
: FSCK_ERR_IGNORE;
}
} }
void bch2_flush_fsck_errs(struct bch_fs *c) void bch2_flush_fsck_errs(struct bch_fs *c)

View File

@ -365,8 +365,11 @@ int bch2_fs_recovery(struct bch_fs *c)
c->disk_sb.sb->version = le16_to_cpu(bcachefs_metadata_version_current); c->disk_sb.sb->version = le16_to_cpu(bcachefs_metadata_version_current);
} }
if (!test_bit(BCH_FS_FSCK_UNFIXED_ERRORS, &c->flags)) if (c->opts.fsck &&
!test_bit(BCH_FS_ERROR, &c->flags)) {
c->disk_sb.sb->features[0] |= 1ULL << BCH_FEATURE_ATOMIC_NLINK; c->disk_sb.sb->features[0] |= 1ULL << BCH_FEATURE_ATOMIC_NLINK;
SET_BCH_SB_HAS_ERRORS(c->disk_sb.sb, 0);
}
mutex_unlock(&c->sb_lock); mutex_unlock(&c->sb_lock);
if (enabled_qtypes(c)) { if (enabled_qtypes(c)) {

View File

@ -707,6 +707,9 @@ int bch2_write_super(struct bch_fs *c)
le64_add_cpu(&c->disk_sb.sb->seq, 1); le64_add_cpu(&c->disk_sb.sb->seq, 1);
if (test_bit(BCH_FS_ERROR, &c->flags))
SET_BCH_SB_HAS_ERRORS(c->disk_sb.sb, 1);
for_each_online_member(ca, c, i) for_each_online_member(ca, c, i)
bch2_sb_from_fs(c, ca); bch2_sb_from_fs(c, ca);
@ -719,8 +722,7 @@ int bch2_write_super(struct bch_fs *c)
} }
} }
if (c->opts.nochanges || if (c->opts.nochanges)
test_bit(BCH_FS_ERROR, &c->flags))
goto out; goto out;
for_each_online_member(ca, c, i) { for_each_online_member(ca, c, i) {

View File

@ -843,7 +843,6 @@ err:
} }
BUG_ON(!err); BUG_ON(!err);
set_bit(BCH_FS_ERROR, &c->flags);
goto out; goto out;
} }