diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-08-19 04:13:44 +0300 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-23 00:10:11 +0300 |
commit | fa5bed376a184f2dcb48dba5c076583ed6c61340 (patch) | |
tree | 7c778be9c3346af83354448185354438034872bc /fs/bcachefs/snapshot.c | |
parent | 7573041ab958a14407621ef9756be49548f937e6 (diff) | |
download | linux-fa5bed376a184f2dcb48dba5c076583ed6c61340.tar.xz |
bcachefs: move check_pos_snapshot_overwritten() to snapshot.c
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/snapshot.c')
-rw-r--r-- | fs/bcachefs/snapshot.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/fs/bcachefs/snapshot.c b/fs/bcachefs/snapshot.c index ad7991ad87a9..0284250ac6cc 100644 --- a/fs/bcachefs/snapshot.c +++ b/fs/bcachefs/snapshot.c @@ -1336,6 +1336,40 @@ int bch2_delete_dead_snapshots_hook(struct btree_trans *trans, return 0; } +int __bch2_key_has_snapshot_overwrites(struct btree_trans *trans, + enum btree_id id, + struct bpos pos) +{ + struct bch_fs *c = trans->c; + struct btree_iter iter; + struct bkey_s_c k; + int ret; + + bch2_trans_iter_init(trans, &iter, id, pos, + BTREE_ITER_NOT_EXTENTS| + BTREE_ITER_ALL_SNAPSHOTS); + while (1) { + k = bch2_btree_iter_prev(&iter); + ret = bkey_err(k); + if (ret) + break; + + if (!k.k) + break; + + if (!bkey_eq(pos, k.k->p)) + break; + + if (bch2_snapshot_is_ancestor(c, k.k->p.snapshot, pos.snapshot)) { + ret = 1; + break; + } + } + bch2_trans_iter_exit(trans, &iter); + + return ret; +} + int bch2_snapshots_read(struct bch_fs *c) { struct btree_iter iter; |