Skip to content

Commit 4be214c

Browse files
author
Kent Overstreet
committed
bcachefs: bch2_bkey_sectors_need_rebalance() now only depends on bch_extent_rebalance
Previously, bch2_bkey_sectors_need_rebalance() called bch2_target_accepts_data(), checking whether the target is writable. However, this means that adding or removing devices from a target would change the value of bch2_bkey_sectors_need_rebalance() for an existing extent; this needs to be invariant so that the extent trigger can correctly maintain rebalance_work accounting. Instead, check target_accepts_data() in io_opts_to_rebalance_opts(), before creating the bch_extent_rebalance entry. This fixes (one?) cause of rebalance_work accounting being off. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 3539880 commit 4be214c

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

fs/bcachefs/inode.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,14 @@ void bch2_inode_opts_get(struct bch_io_opts *, struct bch_fs *,
285285
struct bch_inode_unpacked *);
286286
int bch2_inum_opts_get(struct btree_trans*, subvol_inum, struct bch_io_opts *);
287287

288+
#include "rebalance.h"
289+
288290
static inline struct bch_extent_rebalance
289291
bch2_inode_rebalance_opts_get(struct bch_fs *c, struct bch_inode_unpacked *inode)
290292
{
291293
struct bch_io_opts io_opts;
292294
bch2_inode_opts_get(&io_opts, c, inode);
293-
return io_opts_to_rebalance_opts(&io_opts);
295+
return io_opts_to_rebalance_opts(c, &io_opts);
294296
}
295297

296298
int bch2_inode_rm_snapshot(struct btree_trans *, u64, u32);

fs/bcachefs/opts.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -659,18 +659,4 @@ static inline void bch2_io_opts_fixups(struct bch_io_opts *opts)
659659
struct bch_io_opts bch2_opts_to_inode_opts(struct bch_opts);
660660
bool bch2_opt_is_inode_opt(enum bch_opt_id);
661661

662-
/* rebalance opts: */
663-
664-
static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_io_opts *opts)
665-
{
666-
return (struct bch_extent_rebalance) {
667-
.type = BIT(BCH_EXTENT_ENTRY_rebalance),
668-
#define x(_name) \
669-
._name = opts->_name, \
670-
._name##_from_inode = opts->_name##_from_inode,
671-
BCH_REBALANCE_OPTS()
672-
#undef x
673-
};
674-
};
675-
676662
#endif /* _BCACHEFS_OPTS_H */

fs/bcachefs/rebalance.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,10 @@ u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *c, struct bkey_s_c k)
121121
}
122122
}
123123
incompressible:
124-
if (opts->background_target &&
125-
bch2_target_accepts_data(c, BCH_DATA_user, opts->background_target)) {
124+
if (opts->background_target)
126125
bkey_for_each_ptr_decode(k.k, ptrs, p, entry)
127126
if (!p.ptr.cached && !bch2_dev_in_target(c, p.ptr.dev, opts->background_target))
128127
sectors += p.crc.compressed_size;
129-
}
130128

131129
return sectors;
132130
}
@@ -140,7 +138,7 @@ static bool bch2_bkey_rebalance_needs_update(struct bch_fs *c, struct bch_io_opt
140138
const struct bch_extent_rebalance *old = bch2_bkey_rebalance_opts(k);
141139

142140
if (k.k->type == KEY_TYPE_reflink_v || bch2_bkey_ptrs_need_rebalance(c, opts, k)) {
143-
struct bch_extent_rebalance new = io_opts_to_rebalance_opts(opts);
141+
struct bch_extent_rebalance new = io_opts_to_rebalance_opts(c, opts);
144142
return old == NULL || memcmp(old, &new, sizeof(new));
145143
} else {
146144
return old != NULL;
@@ -163,7 +161,7 @@ int bch2_bkey_set_needs_rebalance(struct bch_fs *c, struct bch_io_opts *opts,
163161
k.k->u64s += sizeof(*old) / sizeof(u64);
164162
}
165163

166-
*old = io_opts_to_rebalance_opts(opts);
164+
*old = io_opts_to_rebalance_opts(c, opts);
167165
} else {
168166
if (old)
169167
extent_entry_drop(k, (union bch_extent_entry *) old);

fs/bcachefs/rebalance.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,28 @@
44

55
#include "compress.h"
66
#include "disk_groups.h"
7+
#include "opts.h"
78
#include "rebalance_types.h"
89

10+
static inline struct bch_extent_rebalance io_opts_to_rebalance_opts(struct bch_fs *c,
11+
struct bch_io_opts *opts)
12+
{
13+
struct bch_extent_rebalance r = {
14+
.type = BIT(BCH_EXTENT_ENTRY_rebalance),
15+
#define x(_name) \
16+
._name = opts->_name, \
17+
._name##_from_inode = opts->_name##_from_inode,
18+
BCH_REBALANCE_OPTS()
19+
#undef x
20+
};
21+
22+
if (r.background_target &&
23+
!bch2_target_accepts_data(c, BCH_DATA_user, r.background_target))
24+
r.background_target = 0;
25+
26+
return r;
27+
};
28+
929
u64 bch2_bkey_sectors_need_rebalance(struct bch_fs *, struct bkey_s_c);
1030
int bch2_bkey_set_needs_rebalance(struct bch_fs *, struct bch_io_opts *, struct bkey_i *);
1131
int bch2_get_update_rebalance_opts(struct btree_trans *,

0 commit comments

Comments
 (0)