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 | |
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')
-rw-r--r-- | fs/bcachefs/btree_update.c | 53 | ||||
-rw-r--r-- | fs/bcachefs/snapshot.c | 34 | ||||
-rw-r--r-- | fs/bcachefs/snapshot.h | 13 |
3 files changed, 51 insertions, 49 deletions
diff --git a/fs/bcachefs/btree_update.c b/fs/bcachefs/btree_update.c index a7fa20727d4b..880ce7431894 100644 --- a/fs/bcachefs/btree_update.c +++ b/fs/bcachefs/btree_update.c @@ -28,51 +28,6 @@ bch2_trans_update_by_path(struct btree_trans *, struct btree_path *, struct bkey_i *, enum btree_update_flags, unsigned long ip); -static noinline int __check_pos_snapshot_overwritten(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; -} - -static inline int check_pos_snapshot_overwritten(struct btree_trans *trans, - enum btree_id id, - struct bpos pos) -{ - if (!btree_type_has_snapshots(id) || - bch2_snapshot_is_leaf(trans->c, pos.snapshot)) - return 0; - - return __check_pos_snapshot_overwritten(trans, id, pos); -} - static noinline int extent_front_merge(struct btree_trans *trans, struct btree_iter *iter, struct bkey_s_c k, @@ -91,8 +46,8 @@ static noinline int extent_front_merge(struct btree_trans *trans, if (!bch2_bkey_merge(c, bkey_i_to_s(update), bkey_i_to_s_c(*insert))) return 0; - ret = check_pos_snapshot_overwritten(trans, iter->btree_id, k.k->p) ?: - check_pos_snapshot_overwritten(trans, iter->btree_id, (*insert)->k.p); + ret = bch2_key_has_snapshot_overwrites(trans, iter->btree_id, k.k->p) ?: + bch2_key_has_snapshot_overwrites(trans, iter->btree_id, (*insert)->k.p); if (ret < 0) return ret; if (ret) @@ -114,8 +69,8 @@ static noinline int extent_back_merge(struct btree_trans *trans, struct bch_fs *c = trans->c; int ret; - ret = check_pos_snapshot_overwritten(trans, iter->btree_id, insert->k.p) ?: - check_pos_snapshot_overwritten(trans, iter->btree_id, k.k->p); + ret = bch2_key_has_snapshot_overwrites(trans, iter->btree_id, insert->k.p) ?: + bch2_key_has_snapshot_overwrites(trans, iter->btree_id, k.k->p); if (ret < 0) return ret; if (ret) 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; diff --git a/fs/bcachefs/snapshot.h b/fs/bcachefs/snapshot.h index 826bff2ff7be..624a42d1c8b7 100644 --- a/fs/bcachefs/snapshot.h +++ b/fs/bcachefs/snapshot.h @@ -250,6 +250,19 @@ int bch2_delete_dead_snapshots_hook(struct btree_trans *, struct btree_trans_commit_hook *); void bch2_delete_dead_snapshots_work(struct work_struct *); +int __bch2_key_has_snapshot_overwrites(struct btree_trans *, enum btree_id, struct bpos); + +static inline int bch2_key_has_snapshot_overwrites(struct btree_trans *trans, + enum btree_id id, + struct bpos pos) +{ + if (!btree_type_has_snapshots(id) || + bch2_snapshot_is_leaf(trans->c, pos.snapshot)) + return 0; + + return __bch2_key_has_snapshot_overwrites(trans, id, pos); +} + int bch2_snapshots_read(struct bch_fs *); void bch2_fs_snapshots_exit(struct bch_fs *); |