bcachefs: Make sure to go rw if lazy in fsck
authorKent Overstreet <kent.overstreet@gmail.com>
Mon, 24 Aug 2020 19:16:32 +0000 (15:16 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:44 +0000 (17:08 -0400)
The paths where we delete or truncate inodes don't pass commit flags for
BTREE_INSERT_LAZY_RW, so just go rw if necessary in the fsck code.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fsck.c
fs/bcachefs/super.h

index c6ca5968a2e072d8d1d6d01c670072c4e9fb8b76..5a6df3d1973a9dedbfab51e1a5b667a7da3751df 100644 (file)
@@ -1265,6 +1265,8 @@ static int check_inode(struct btree_trans *trans,
                      u.bi_inum))) {
                bch_verbose(c, "deleting inode %llu", u.bi_inum);
 
+               bch2_fs_lazy_rw(c);
+
                ret = bch2_inode_rm(c, u.bi_inum);
                if (ret)
                        bch_err(c, "error in fsck: error %i while deleting inode", ret);
@@ -1277,6 +1279,8 @@ static int check_inode(struct btree_trans *trans,
                      u.bi_inum))) {
                bch_verbose(c, "truncating inode %llu", u.bi_inum);
 
+               bch2_fs_lazy_rw(c);
+
                /*
                 * XXX: need to truncate partial blocks too here - or ideally
                 * just switch units to bytes and that issue goes away
index b948cb0428c7ebc5a3e1e87dd2568af4febff2b8..fab4bee9c90e7e4c2236961abc1ed9c2e738deae 100644 (file)
@@ -221,6 +221,15 @@ void bch2_fs_read_only(struct bch_fs *);
 int bch2_fs_read_write(struct bch_fs *);
 int bch2_fs_read_write_early(struct bch_fs *);
 
+/*
+ * Only for use in the recovery/fsck path:
+ */
+static inline void bch2_fs_lazy_rw(struct bch_fs *c)
+{
+       if (percpu_ref_is_zero(&c->writes))
+               bch2_fs_read_write_early(c);
+}
+
 void bch2_fs_stop(struct bch_fs *);
 
 int bch2_fs_start(struct bch_fs *);