diff options
Diffstat (limited to 'fs/bcachefs/rebalance.h')
-rw-r--r-- | fs/bcachefs/rebalance.h | 52 |
1 files changed, 38 insertions, 14 deletions
diff --git a/fs/bcachefs/rebalance.h b/fs/bcachefs/rebalance.h index 24bafa42f070..e6dd9a7db26c 100644 --- a/fs/bcachefs/rebalance.h +++ b/fs/bcachefs/rebalance.h @@ -7,10 +7,14 @@ #include "opts.h" #include "rebalance_types.h" +int bch2_extent_rebalance_validate(struct bch_fs *, struct bkey_s_c, + struct bkey_validate_context, + const struct bch_extent_rebalance *); + static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_fs *c, struct bch_inode_opts *opts) { - struct bch_extent_rebalance r = { + return (struct bch_extent_rebalance) { .type = BIT(BCH_EXTENT_ENTRY_rebalance), #define x(_name) \ ._name = opts->_name, \ @@ -18,22 +22,36 @@ static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_f BCH_REBALANCE_OPTS() #undef x }; - - if (r.background_target && - !bch2_target_accepts_data(c, BCH_DATA_user, r.background_target)) - r.background_target = 0; - - return r; }; void bch2_extent_rebalance_to_text(struct printbuf *, struct bch_fs *, const struct bch_extent_rebalance *); -int bch2_trigger_extent_rebalance(struct btree_trans *, - struct bkey_s_c, struct bkey_s_c, - enum btree_iter_update_trigger_flags); +const struct bch_extent_rebalance *bch2_bkey_rebalance_opts(struct bkey_s_c); + +static inline int bch2_bkey_needs_rb(struct bkey_s_c k) +{ + const struct bch_extent_rebalance *r = bch2_bkey_rebalance_opts(k); + return r ? r->need_rb : 0; +} + +int __bch2_trigger_extent_rebalance(struct btree_trans *, + struct bkey_s_c, struct bkey_s_c, + unsigned, unsigned, + enum btree_iter_update_trigger_flags); -u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c); +static inline int bch2_trigger_extent_rebalance(struct btree_trans *trans, + struct bkey_s_c old, struct bkey_s_c new, + enum btree_iter_update_trigger_flags flags) +{ + unsigned old_r = bch2_bkey_needs_rb(old); + unsigned new_r = bch2_bkey_needs_rb(new); + + return old_r != new_r || + (old.k->size != new.k->size && (old_r|new_r)) + ? __bch2_trigger_extent_rebalance(trans, old, new, old_r, new_r, flags) + : 0; +} enum set_needs_rebalance_ctx { SET_NEEDS_REBALANCE_opt_change, @@ -42,9 +60,6 @@ enum set_needs_rebalance_ctx { SET_NEEDS_REBALANCE_other, }; -int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bch_inode_opts *, - struct bkey_i *, enum set_needs_rebalance_ctx, u32); - /* Inodes in different snapshots may have different IO options: */ struct snapshot_io_opts_entry { u32 snapshot; @@ -53,6 +68,10 @@ struct snapshot_io_opts_entry { struct per_snapshot_io_opts { u64 cur_inum; + bool fs_scan_cookie; + bool inum_scan_cookie; + struct bch_devs_mask dev_cookie; + struct bch_inode_opts fs_io_opts; DARRAY(struct snapshot_io_opts_entry) d; }; @@ -68,6 +87,10 @@ static inline void per_snapshot_io_opts_exit(struct per_snapshot_io_opts *io_opt darray_exit(&io_opts->d); } +int bch2_bkey_set_needs_rebalance(struct btree_trans *, + struct per_snapshot_io_opts *, struct bch_inode_opts *, + struct bkey_i *, enum set_needs_rebalance_ctx, u32); + struct bch_inode_opts *bch2_extent_get_apply_io_opts(struct btree_trans *, struct per_snapshot_io_opts *, struct bpos, struct btree_iter *, struct bkey_s_c, @@ -82,6 +105,7 @@ int bch2_extent_get_apply_io_opts_one(struct btree_trans *, struct bch_inode_opt int bch2_set_rebalance_needs_scan_trans(struct btree_trans *, u64); int bch2_set_rebalance_needs_scan(struct bch_fs *, u64 inum); +int bch2_set_rebalance_needs_scan_device(struct bch_fs *, unsigned); int bch2_set_fs_needs_rebalance(struct bch_fs *); static inline void bch2_rebalance_wakeup(struct bch_fs *c) |