Skip to content

Commit 1600514

Browse files
author
Kent Overstreet
committed
bcachefs: Don't delete open files in online fsck
If a file is unlinked but still open, we don't want online fsck to delete it - or fun inconsistencies will happen. koverstreet/bcachefs#727 Signed-off-by: Kent Overstreet <[email protected]>
1 parent 2c377d8 commit 1600514

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

fs/bcachefs/fs.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,14 @@ static unsigned bch2_inode_hash(subvol_inum inum)
177177
return jhash_3words(inum.subvol, inum.inum >> 32, inum.inum, JHASH_INITVAL);
178178
}
179179

180+
struct bch_inode_info *__bch2_inode_hash_find(struct bch_fs *c, subvol_inum inum)
181+
{
182+
return to_bch_ei(ilookup5_nowait(c->vfs_sb,
183+
bch2_inode_hash(inum),
184+
bch2_iget5_test,
185+
&inum));
186+
}
187+
180188
static struct bch_inode_info *bch2_inode_insert(struct bch_fs *c, struct bch_inode_info *inode)
181189
{
182190
subvol_inum inum = inode_inum(inode);

fs/bcachefs/fs.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static inline subvol_inum inode_inum(struct bch_inode_info *inode)
5656
};
5757
}
5858

59+
struct bch_inode_info *__bch2_inode_hash_find(struct bch_fs *, subvol_inum);
60+
5961
/*
6062
* Set if we've gotten a btree error for this inode, and thus the vfs inode and
6163
* btree inode may be inconsistent:
@@ -194,6 +196,11 @@ int bch2_vfs_init(void);
194196

195197
#define bch2_inode_update_after_write(_trans, _inode, _inode_u, _fields) ({ do {} while (0); })
196198

199+
static inline struct bch_inode_info *__bch2_inode_hash_find(struct bch_fs *c, subvol_inum inum)
200+
{
201+
return NULL;
202+
}
203+
197204
static inline void bch2_evict_subvolume_inodes(struct bch_fs *c,
198205
snapshot_id_list *s) {}
199206
static inline void bch2_vfs_exit(void) {}

fs/bcachefs/fsck.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "darray.h"
99
#include "dirent.h"
1010
#include "error.h"
11+
#include "fs.h"
1112
#include "fs-common.h"
1213
#include "fsck.h"
1314
#include "inode.h"
@@ -962,6 +963,22 @@ static int check_inode_dirent_inode(struct btree_trans *trans, struct bkey_s_c i
962963
return ret;
963964
}
964965

966+
static bool bch2_inode_open(struct bch_fs *c, struct bpos p)
967+
{
968+
subvol_inum inum = {
969+
.subvol = snapshot_t(c, p.snapshot)->subvol,
970+
.inum = p.offset,
971+
};
972+
973+
/* snapshot tree corruption, can't safely delete */
974+
if (!inum.subvol) {
975+
bch_err_ratelimited(c, "%s(): snapshot %u has no subvol", __func__, p.snapshot);
976+
return true;
977+
}
978+
979+
return __bch2_inode_hash_find(c, inum) != NULL;
980+
}
981+
965982
static int check_inode(struct btree_trans *trans,
966983
struct btree_iter *iter,
967984
struct bkey_s_c k,
@@ -1040,6 +1057,7 @@ static int check_inode(struct btree_trans *trans,
10401057
}
10411058

10421059
if (u.bi_flags & BCH_INODE_unlinked &&
1060+
!bch2_inode_open(c, k.k->p) &&
10431061
(!c->sb.clean ||
10441062
fsck_err(trans, inode_unlinked_but_clean,
10451063
"filesystem marked clean, but inode %llu unlinked",

0 commit comments

Comments
 (0)