Skip to content

Commit 08f5000

Browse files
author
Kent Overstreet
committed
bcachefs: Run check_key_has_snapshot in snapshot_delete_keys()
delete_dead_snapshots now runs before the main fsck.c passes which check for keys for invalid snapshots; thus, it needs those checks as well. Signed-off-by: Kent Overstreet <[email protected]>
1 parent 82af5ce commit 08f5000

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

fs/bcachefs/fsck.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -766,25 +766,6 @@ static int get_visible_inodes(struct btree_trans *trans,
766766
return ret;
767767
}
768768

769-
static int check_key_has_snapshot(struct btree_trans *trans,
770-
struct btree_iter *iter,
771-
struct bkey_s_c k)
772-
{
773-
struct bch_fs *c = trans->c;
774-
struct printbuf buf = PRINTBUF;
775-
int ret = 0;
776-
777-
if (mustfix_fsck_err_on(!bch2_snapshot_equiv(c, k.k->p.snapshot), c,
778-
bkey_in_missing_snapshot,
779-
"key in missing snapshot: %s",
780-
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
781-
ret = bch2_btree_delete_at(trans, iter,
782-
BTREE_UPDATE_internal_snapshot_node) ?: 1;
783-
fsck_err:
784-
printbuf_exit(&buf);
785-
return ret;
786-
}
787-
788769
static int hash_redo_key(struct btree_trans *trans,
789770
const struct bch_hash_desc desc,
790771
struct bch_hash_info *hash_info,
@@ -979,7 +960,7 @@ static int check_inode(struct btree_trans *trans,
979960
bool do_update = false;
980961
int ret;
981962

982-
ret = check_key_has_snapshot(trans, iter, k);
963+
ret = bch2_check_key_has_snapshot(trans, iter, k);
983964
if (ret < 0)
984965
goto err;
985966
if (ret)
@@ -1483,7 +1464,7 @@ static int check_extent(struct btree_trans *trans, struct btree_iter *iter,
14831464
struct printbuf buf = PRINTBUF;
14841465
int ret = 0;
14851466

1486-
ret = check_key_has_snapshot(trans, iter, k);
1467+
ret = bch2_check_key_has_snapshot(trans, iter, k);
14871468
if (ret) {
14881469
ret = ret < 0 ? ret : 0;
14891470
goto out;
@@ -2006,7 +1987,7 @@ static int check_dirent(struct btree_trans *trans, struct btree_iter *iter,
20061987
struct printbuf buf = PRINTBUF;
20071988
int ret = 0;
20081989

2009-
ret = check_key_has_snapshot(trans, iter, k);
1990+
ret = bch2_check_key_has_snapshot(trans, iter, k);
20101991
if (ret) {
20111992
ret = ret < 0 ? ret : 0;
20121993
goto out;
@@ -2161,7 +2142,7 @@ static int check_xattr(struct btree_trans *trans, struct btree_iter *iter,
21612142
struct inode_walker_entry *i;
21622143
int ret;
21632144

2164-
ret = check_key_has_snapshot(trans, iter, k);
2145+
ret = bch2_check_key_has_snapshot(trans, iter, k);
21652146
if (ret < 0)
21662147
return ret;
21672148
if (ret)

fs/bcachefs/snapshot.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,25 @@ int bch2_reconstruct_snapshots(struct bch_fs *c)
10421042
return ret;
10431043
}
10441044

1045+
int bch2_check_key_has_snapshot(struct btree_trans *trans,
1046+
struct btree_iter *iter,
1047+
struct bkey_s_c k)
1048+
{
1049+
struct bch_fs *c = trans->c;
1050+
struct printbuf buf = PRINTBUF;
1051+
int ret = 0;
1052+
1053+
if (fsck_err_on(!bch2_snapshot_equiv(c, k.k->p.snapshot), c,
1054+
bkey_in_missing_snapshot,
1055+
"key in missing snapshot %s, delete?",
1056+
(bch2_bkey_val_to_text(&buf, c, k), buf.buf)))
1057+
ret = bch2_btree_delete_at(trans, iter,
1058+
BTREE_UPDATE_internal_snapshot_node) ?: 1;
1059+
fsck_err:
1060+
printbuf_exit(&buf);
1061+
return ret;
1062+
}
1063+
10451064
/*
10461065
* Mark a snapshot as deleted, for future cleanup:
10471066
*/
@@ -1358,6 +1377,10 @@ static int delete_dead_snapshots_process_key(struct btree_trans *trans,
13581377
snapshot_id_list *equiv_seen,
13591378
struct bpos *last_pos)
13601379
{
1380+
int ret = bch2_check_key_has_snapshot(trans, iter, k);
1381+
if (ret)
1382+
return ret < 0 ? ret : 0;
1383+
13611384
struct bch_fs *c = trans->c;
13621385
u32 equiv = bch2_snapshot_equiv(c, k.k->p.snapshot);
13631386
if (!equiv) /* key for invalid snapshot node, but we chose not to delete */
@@ -1377,7 +1400,7 @@ static int delete_dead_snapshots_process_key(struct btree_trans *trans,
13771400

13781401
*last_pos = k.k->p;
13791402

1380-
int ret = snapshot_list_add_nodup(c, equiv_seen, equiv);
1403+
ret = snapshot_list_add_nodup(c, equiv_seen, equiv);
13811404
if (ret)
13821405
return ret;
13831406

fs/bcachefs/snapshot.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ int bch2_snapshot_node_create(struct btree_trans *, u32,
242242
int bch2_check_snapshot_trees(struct bch_fs *);
243243
int bch2_check_snapshots(struct bch_fs *);
244244
int bch2_reconstruct_snapshots(struct bch_fs *);
245+
int bch2_check_key_has_snapshot(struct btree_trans *, struct btree_iter *, struct bkey_s_c);
245246

246247
int bch2_snapshot_node_set_deleted(struct btree_trans *, u32);
247248
void bch2_delete_dead_snapshots_work(struct work_struct *);

0 commit comments

Comments
 (0)