2019-08-16 13:59:56 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#include "bcachefs.h"
|
2020-12-17 20:08:58 +00:00
|
|
|
#include "bkey_buf.h"
|
2019-08-16 13:59:56 +00:00
|
|
|
#include "btree_update.h"
|
2021-05-17 04:08:06 +00:00
|
|
|
#include "buckets.h"
|
2023-12-03 20:54:45 +00:00
|
|
|
#include "error.h"
|
2019-08-16 13:59:56 +00:00
|
|
|
#include "extents.h"
|
2019-10-10 16:47:22 +00:00
|
|
|
#include "inode.h"
|
2023-09-10 22:05:17 +00:00
|
|
|
#include "io_misc.h"
|
|
|
|
#include "io_write.h"
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
#include "rebalance.h"
|
2019-08-16 13:59:56 +00:00
|
|
|
#include "reflink.h"
|
2021-03-16 04:28:17 +00:00
|
|
|
#include "subvolume.h"
|
2023-09-10 22:05:17 +00:00
|
|
|
#include "super-io.h"
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
#include <linux/sched/signal.h>
|
|
|
|
|
2020-10-24 23:51:34 +00:00
|
|
|
static inline unsigned bkey_type_to_indirect(const struct bkey *k)
|
|
|
|
{
|
|
|
|
switch (k->type) {
|
|
|
|
case KEY_TYPE_extent:
|
|
|
|
return KEY_TYPE_reflink_v;
|
|
|
|
case KEY_TYPE_inline_data:
|
|
|
|
return KEY_TYPE_indirect_inline_data;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-16 13:59:56 +00:00
|
|
|
/* reflink pointers */
|
|
|
|
|
2023-10-25 00:44:36 +00:00
|
|
|
int bch2_reflink_p_invalid(struct bch_fs *c, struct bkey_s_c k,
|
2024-05-08 22:40:42 +00:00
|
|
|
enum bch_validate_flags flags,
|
2023-07-07 01:16:10 +00:00
|
|
|
struct printbuf *err)
|
2019-08-16 13:59:56 +00:00
|
|
|
{
|
|
|
|
struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
|
2024-01-04 04:29:02 +00:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
bkey_fsck_err_on(le64_to_cpu(p.v->idx) < le32_to_cpu(p.v->front_pad),
|
|
|
|
c, err, reflink_p_front_pad_bad,
|
|
|
|
"idx < front_pad (%llu < %u)",
|
|
|
|
le64_to_cpu(p.v->idx), le32_to_cpu(p.v->front_pad));
|
|
|
|
fsck_err:
|
|
|
|
return ret;
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bch2_reflink_p_to_text(struct printbuf *out, struct bch_fs *c,
|
|
|
|
struct bkey_s_c k)
|
|
|
|
{
|
|
|
|
struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
|
|
|
|
|
2023-02-04 02:01:40 +00:00
|
|
|
prt_printf(out, "idx %llu front_pad %u back_pad %u",
|
2021-11-13 22:44:13 +00:00
|
|
|
le64_to_cpu(p.v->idx),
|
|
|
|
le32_to_cpu(p.v->front_pad),
|
|
|
|
le32_to_cpu(p.v->back_pad));
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
2021-04-29 03:49:30 +00:00
|
|
|
bool bch2_reflink_p_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r)
|
2019-08-16 13:59:56 +00:00
|
|
|
{
|
|
|
|
struct bkey_s_reflink_p l = bkey_s_to_reflink_p(_l);
|
2021-04-29 03:49:30 +00:00
|
|
|
struct bkey_s_c_reflink_p r = bkey_s_c_to_reflink_p(_r);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2021-04-29 03:49:30 +00:00
|
|
|
/*
|
|
|
|
* Disabled for now, the triggers code needs to be reworked for merging
|
|
|
|
* of reflink pointers to work:
|
|
|
|
*/
|
|
|
|
return false;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2021-04-29 03:49:30 +00:00
|
|
|
if (le64_to_cpu(l.v->idx) + l.k->size != le64_to_cpu(r.v->idx))
|
|
|
|
return false;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
bch2_key_resize(l.k, l.k->size + r.k->size);
|
2021-04-29 03:49:30 +00:00
|
|
|
return true;
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
static int trans_trigger_reflink_p_segment(struct btree_trans *trans,
|
2024-04-07 22:05:34 +00:00
|
|
|
struct bkey_s_c_reflink_p p, u64 *idx,
|
|
|
|
enum btree_iter_update_trigger_flags flags)
|
2023-12-03 20:54:45 +00:00
|
|
|
{
|
|
|
|
struct bch_fs *c = trans->c;
|
|
|
|
struct btree_iter iter;
|
|
|
|
struct bkey_i *k;
|
|
|
|
__le64 *refcount;
|
2024-04-07 22:05:34 +00:00
|
|
|
int add = !(flags & BTREE_TRIGGER_overwrite) ? 1 : -1;
|
2023-12-03 20:54:45 +00:00
|
|
|
struct printbuf buf = PRINTBUF;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
k = bch2_bkey_get_mut_noupdate(trans, &iter,
|
|
|
|
BTREE_ID_reflink, POS(0, *idx),
|
2024-04-07 22:05:34 +00:00
|
|
|
BTREE_ITER_with_updates);
|
2023-12-03 20:54:45 +00:00
|
|
|
ret = PTR_ERR_OR_ZERO(k);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-12-28 04:19:09 +00:00
|
|
|
refcount = bkey_refcount(bkey_i_to_s(k));
|
2023-12-03 20:54:45 +00:00
|
|
|
if (!refcount) {
|
|
|
|
bch2_bkey_val_to_text(&buf, c, p.s_c);
|
|
|
|
bch2_trans_inconsistent(trans,
|
|
|
|
"nonexistent indirect extent at %llu while marking\n %s",
|
|
|
|
*idx, buf.buf);
|
|
|
|
ret = -EIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2024-04-07 22:05:34 +00:00
|
|
|
if (!*refcount && (flags & BTREE_TRIGGER_overwrite)) {
|
2023-12-03 20:54:45 +00:00
|
|
|
bch2_bkey_val_to_text(&buf, c, p.s_c);
|
|
|
|
bch2_trans_inconsistent(trans,
|
|
|
|
"indirect extent refcount underflow at %llu while marking\n %s",
|
|
|
|
*idx, buf.buf);
|
|
|
|
ret = -EIO;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2024-04-07 22:05:34 +00:00
|
|
|
if (flags & BTREE_TRIGGER_insert) {
|
2023-12-03 20:54:45 +00:00
|
|
|
struct bch_reflink_p *v = (struct bch_reflink_p *) p.v;
|
|
|
|
u64 pad;
|
|
|
|
|
|
|
|
pad = max_t(s64, le32_to_cpu(v->front_pad),
|
|
|
|
le64_to_cpu(v->idx) - bkey_start_offset(&k->k));
|
|
|
|
BUG_ON(pad > U32_MAX);
|
|
|
|
v->front_pad = cpu_to_le32(pad);
|
|
|
|
|
|
|
|
pad = max_t(s64, le32_to_cpu(v->back_pad),
|
|
|
|
k->k.p.offset - p.k->size - le64_to_cpu(v->idx));
|
|
|
|
BUG_ON(pad > U32_MAX);
|
|
|
|
v->back_pad = cpu_to_le32(pad);
|
|
|
|
}
|
|
|
|
|
|
|
|
le64_add_cpu(refcount, add);
|
|
|
|
|
|
|
|
bch2_btree_iter_set_pos_to_extent_start(&iter);
|
|
|
|
ret = bch2_trans_update(trans, &iter, k, 0);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
*idx = k->k.p.offset;
|
|
|
|
err:
|
|
|
|
bch2_trans_iter_exit(trans, &iter);
|
|
|
|
printbuf_exit(&buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
static s64 gc_trigger_reflink_p_segment(struct btree_trans *trans,
|
2024-04-07 22:05:34 +00:00
|
|
|
struct bkey_s_c_reflink_p p, u64 *idx,
|
|
|
|
enum btree_iter_update_trigger_flags flags,
|
|
|
|
size_t r_idx)
|
2023-12-03 20:54:45 +00:00
|
|
|
{
|
|
|
|
struct bch_fs *c = trans->c;
|
|
|
|
struct reflink_gc *r;
|
2024-04-07 22:05:34 +00:00
|
|
|
int add = !(flags & BTREE_TRIGGER_overwrite) ? 1 : -1;
|
2023-12-28 05:15:58 +00:00
|
|
|
u64 start = le64_to_cpu(p.v->idx);
|
|
|
|
u64 end = le64_to_cpu(p.v->idx) + p.k->size;
|
|
|
|
u64 next_idx = end + le32_to_cpu(p.v->back_pad);
|
2023-12-03 20:54:45 +00:00
|
|
|
s64 ret = 0;
|
|
|
|
struct printbuf buf = PRINTBUF;
|
|
|
|
|
|
|
|
if (r_idx >= c->reflink_gc_nr)
|
|
|
|
goto not_found;
|
|
|
|
|
|
|
|
r = genradix_ptr(&c->reflink_gc_table, r_idx);
|
|
|
|
next_idx = min(next_idx, r->offset - r->size);
|
|
|
|
if (*idx < next_idx)
|
|
|
|
goto not_found;
|
|
|
|
|
|
|
|
BUG_ON((s64) r->refcount + add < 0);
|
|
|
|
|
2024-04-07 23:47:31 +00:00
|
|
|
if (flags & BTREE_TRIGGER_gc)
|
|
|
|
r->refcount += add;
|
2023-12-03 20:54:45 +00:00
|
|
|
*idx = r->offset;
|
|
|
|
return 0;
|
|
|
|
not_found:
|
2024-04-07 23:47:31 +00:00
|
|
|
BUG_ON(!(flags & BTREE_TRIGGER_check_repair));
|
|
|
|
|
2023-12-03 20:54:45 +00:00
|
|
|
if (fsck_err(c, reflink_p_to_missing_reflink_v,
|
|
|
|
"pointer to missing indirect extent\n"
|
|
|
|
" %s\n"
|
|
|
|
" missing range %llu-%llu",
|
|
|
|
(bch2_bkey_val_to_text(&buf, c, p.s_c), buf.buf),
|
|
|
|
*idx, next_idx)) {
|
2023-12-28 05:15:58 +00:00
|
|
|
struct bkey_i *update = bch2_bkey_make_mut_noupdate(trans, p.s_c);
|
|
|
|
ret = PTR_ERR_OR_ZERO(update);
|
2023-12-03 20:54:45 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
if (next_idx <= start) {
|
|
|
|
bkey_i_to_reflink_p(update)->v.front_pad = cpu_to_le32(start - next_idx);
|
|
|
|
} else if (*idx >= end) {
|
|
|
|
bkey_i_to_reflink_p(update)->v.back_pad = cpu_to_le32(*idx - end);
|
|
|
|
} else {
|
|
|
|
bkey_error_init(update);
|
|
|
|
update->k.p = p.k->p;
|
2024-03-26 22:46:20 +00:00
|
|
|
update->k.size = p.k->size;
|
2023-12-28 05:15:58 +00:00
|
|
|
set_bkey_val_u64s(&update->k, 0);
|
|
|
|
}
|
|
|
|
|
2024-04-07 22:05:34 +00:00
|
|
|
ret = bch2_btree_insert_trans(trans, BTREE_ID_extents, update, BTREE_TRIGGER_norun);
|
2023-12-03 20:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*idx = next_idx;
|
|
|
|
err:
|
|
|
|
fsck_err:
|
|
|
|
printbuf_exit(&buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
static int __trigger_reflink_p(struct btree_trans *trans,
|
2024-04-07 22:05:34 +00:00
|
|
|
enum btree_id btree_id, unsigned level, struct bkey_s_c k,
|
|
|
|
enum btree_iter_update_trigger_flags flags)
|
2023-12-03 20:54:45 +00:00
|
|
|
{
|
|
|
|
struct bch_fs *c = trans->c;
|
|
|
|
struct bkey_s_c_reflink_p p = bkey_s_c_to_reflink_p(k);
|
|
|
|
int ret = 0;
|
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
u64 idx = le64_to_cpu(p.v->idx) - le32_to_cpu(p.v->front_pad);
|
|
|
|
u64 end = le64_to_cpu(p.v->idx) + p.k->size + le32_to_cpu(p.v->back_pad);
|
2023-12-03 20:54:45 +00:00
|
|
|
|
2024-04-07 22:05:34 +00:00
|
|
|
if (flags & BTREE_TRIGGER_transactional) {
|
2023-12-28 05:15:58 +00:00
|
|
|
while (idx < end && !ret)
|
|
|
|
ret = trans_trigger_reflink_p_segment(trans, p, &idx, flags);
|
2023-12-03 20:54:45 +00:00
|
|
|
}
|
|
|
|
|
2024-04-07 23:47:31 +00:00
|
|
|
if (flags & (BTREE_TRIGGER_check_repair|BTREE_TRIGGER_gc)) {
|
2023-12-28 05:15:58 +00:00
|
|
|
size_t l = 0, r = c->reflink_gc_nr;
|
2023-12-03 20:54:45 +00:00
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
while (l < r) {
|
|
|
|
size_t m = l + (r - l) / 2;
|
|
|
|
struct reflink_gc *ref = genradix_ptr(&c->reflink_gc_table, m);
|
|
|
|
if (ref->offset <= idx)
|
|
|
|
l = m + 1;
|
|
|
|
else
|
|
|
|
r = m;
|
|
|
|
}
|
2023-12-03 20:54:45 +00:00
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
while (idx < end && !ret)
|
|
|
|
ret = gc_trigger_reflink_p_segment(trans, p, &idx, flags, l++);
|
|
|
|
}
|
2023-12-03 20:54:45 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-12-28 05:15:58 +00:00
|
|
|
int bch2_trigger_reflink_p(struct btree_trans *trans,
|
|
|
|
enum btree_id btree_id, unsigned level,
|
|
|
|
struct bkey_s_c old,
|
|
|
|
struct bkey_s new,
|
2024-04-07 22:05:34 +00:00
|
|
|
enum btree_iter_update_trigger_flags flags)
|
2023-12-03 20:54:45 +00:00
|
|
|
{
|
2024-04-07 22:05:34 +00:00
|
|
|
if ((flags & BTREE_TRIGGER_transactional) &&
|
|
|
|
(flags & BTREE_TRIGGER_insert)) {
|
2023-12-28 05:15:58 +00:00
|
|
|
struct bch_reflink_p *v = bkey_s_to_reflink_p(new).v;
|
|
|
|
|
|
|
|
v->front_pad = v->back_pad = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return trigger_run_overwrite_then_insert(__trigger_reflink_p, trans, btree_id, level, old, new, flags);
|
2023-12-03 20:54:45 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 13:59:56 +00:00
|
|
|
/* indirect extents */
|
|
|
|
|
2023-10-25 00:44:36 +00:00
|
|
|
int bch2_reflink_v_invalid(struct bch_fs *c, struct bkey_s_c k,
|
2024-05-08 22:40:42 +00:00
|
|
|
enum bch_validate_flags flags,
|
2023-07-07 01:16:10 +00:00
|
|
|
struct printbuf *err)
|
2019-08-16 13:59:56 +00:00
|
|
|
{
|
2022-12-21 00:58:16 +00:00
|
|
|
return bch2_bkey_ptrs_invalid(c, k, flags, err);
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bch2_reflink_v_to_text(struct printbuf *out, struct bch_fs *c,
|
|
|
|
struct bkey_s_c k)
|
|
|
|
{
|
|
|
|
struct bkey_s_c_reflink_v r = bkey_s_c_to_reflink_v(k);
|
|
|
|
|
2023-02-04 02:01:40 +00:00
|
|
|
prt_printf(out, "refcount: %llu ", le64_to_cpu(r.v->refcount));
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
bch2_bkey_ptrs_to_text(out, c, k);
|
|
|
|
}
|
|
|
|
|
2023-09-12 22:41:22 +00:00
|
|
|
#if 0
|
|
|
|
Currently disabled, needs to be debugged:
|
|
|
|
|
2021-05-15 19:04:08 +00:00
|
|
|
bool bch2_reflink_v_merge(struct bch_fs *c, struct bkey_s _l, struct bkey_s_c _r)
|
|
|
|
{
|
|
|
|
struct bkey_s_reflink_v l = bkey_s_to_reflink_v(_l);
|
|
|
|
struct bkey_s_c_reflink_v r = bkey_s_c_to_reflink_v(_r);
|
|
|
|
|
|
|
|
return l.v->refcount == r.v->refcount && bch2_extent_merge(c, _l, _r);
|
|
|
|
}
|
2023-09-12 22:41:22 +00:00
|
|
|
#endif
|
2021-05-15 19:04:08 +00:00
|
|
|
|
bcachefs: Fix type of flags parameter for some ->trigger() implementations
When building with clang's -Wincompatible-function-pointer-types-strict
(a warning designed to catch potential kCFI failures at build time),
there are several warnings along the lines of:
fs/bcachefs/bkey_methods.c:118:2: error: incompatible function pointer types initializing 'int (*)(struct btree_trans *, enum btree_id, unsigned int, struct bkey_s_c, struct bkey_s, enum btree_iter_update_trigger_flags)' with an expression of type 'int (struct btree_trans *, enum btree_id, unsigned int, struct bkey_s_c, struct bkey_s, unsigned int)' [-Werror,-Wincompatible-function-pointer-types-strict]
118 | BCH_BKEY_TYPES()
| ^~~~~~~~~~~~~~~~
fs/bcachefs/bcachefs_format.h:394:2: note: expanded from macro 'BCH_BKEY_TYPES'
394 | x(inode, 8) \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
fs/bcachefs/bkey_methods.c:117:41: note: expanded from macro 'x'
117 | #define x(name, nr) [KEY_TYPE_##name] = bch2_bkey_ops_##name,
| ^~~~~~~~~~~~~~~~~~~~
<scratch space>:277:1: note: expanded from here
277 | bch2_bkey_ops_inode
| ^~~~~~~~~~~~~~~~~~~
fs/bcachefs/inode.h:26:13: note: expanded from macro 'bch2_bkey_ops_inode'
26 | .trigger = bch2_trigger_inode, \
| ^~~~~~~~~~~~~~~~~~
There are several functions that did not have their flags parameter
converted to 'enum btree_iter_update_trigger_flags' in the recent
unification, which will cause kCFI failures at runtime because the
types, while ABI compatible (hence no warning from the non-strict
version of this warning), do not match exactly.
Fix up these functions (as well as a few other obvious functions that
should have it, even if there are no warnings currently) to resolve the
warnings and potential kCFI runtime failures.
Fixes: 31e4ef3280c8 ("bcachefs: iter/update/trigger/str_hash flag cleanup")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-04-23 18:58:09 +00:00
|
|
|
static inline void
|
|
|
|
check_indirect_extent_deleting(struct bkey_s new,
|
|
|
|
enum btree_iter_update_trigger_flags *flags)
|
2023-06-23 00:18:12 +00:00
|
|
|
{
|
2024-04-07 22:05:34 +00:00
|
|
|
if ((*flags & BTREE_TRIGGER_insert) && !*bkey_refcount(new)) {
|
2023-12-28 04:19:09 +00:00
|
|
|
new.k->type = KEY_TYPE_deleted;
|
|
|
|
new.k->size = 0;
|
|
|
|
set_bkey_val_u64s(new.k, 0);
|
2024-04-07 22:05:34 +00:00
|
|
|
*flags &= ~BTREE_TRIGGER_insert;
|
2023-06-23 00:18:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-07 22:14:46 +00:00
|
|
|
int bch2_trigger_reflink_v(struct btree_trans *trans,
|
|
|
|
enum btree_id btree_id, unsigned level,
|
|
|
|
struct bkey_s_c old, struct bkey_s new,
|
2024-04-07 22:05:34 +00:00
|
|
|
enum btree_iter_update_trigger_flags flags)
|
2022-03-31 04:03:37 +00:00
|
|
|
{
|
2024-04-07 22:05:34 +00:00
|
|
|
if ((flags & BTREE_TRIGGER_transactional) &&
|
|
|
|
(flags & BTREE_TRIGGER_insert))
|
2024-01-01 02:01:06 +00:00
|
|
|
check_indirect_extent_deleting(new, &flags);
|
2022-03-31 04:03:37 +00:00
|
|
|
|
2023-12-28 07:11:00 +00:00
|
|
|
return bch2_trigger_extent(trans, btree_id, level, old, new, flags);
|
2022-03-31 04:03:37 +00:00
|
|
|
}
|
|
|
|
|
2020-10-24 23:51:34 +00:00
|
|
|
/* indirect inline data */
|
|
|
|
|
2023-10-25 00:44:36 +00:00
|
|
|
int bch2_indirect_inline_data_invalid(struct bch_fs *c, struct bkey_s_c k,
|
2024-05-08 22:40:42 +00:00
|
|
|
enum bch_validate_flags flags,
|
2023-07-07 01:16:10 +00:00
|
|
|
struct printbuf *err)
|
2020-10-24 23:51:34 +00:00
|
|
|
{
|
2022-04-03 21:50:01 +00:00
|
|
|
return 0;
|
2020-10-24 23:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void bch2_indirect_inline_data_to_text(struct printbuf *out,
|
2023-06-23 00:18:12 +00:00
|
|
|
struct bch_fs *c, struct bkey_s_c k)
|
2020-10-24 23:51:34 +00:00
|
|
|
{
|
|
|
|
struct bkey_s_c_indirect_inline_data d = bkey_s_c_to_indirect_inline_data(k);
|
|
|
|
unsigned datalen = bkey_inline_data_bytes(k.k);
|
|
|
|
|
2023-02-04 02:01:40 +00:00
|
|
|
prt_printf(out, "refcount %llu datalen %u: %*phN",
|
2020-10-24 23:51:34 +00:00
|
|
|
le64_to_cpu(d.v->refcount), datalen,
|
|
|
|
min(datalen, 32U), d.v->data);
|
|
|
|
}
|
|
|
|
|
2024-01-07 22:14:46 +00:00
|
|
|
int bch2_trigger_indirect_inline_data(struct btree_trans *trans,
|
2022-04-01 01:44:55 +00:00
|
|
|
enum btree_id btree_id, unsigned level,
|
2023-12-28 04:19:09 +00:00
|
|
|
struct bkey_s_c old, struct bkey_s new,
|
bcachefs: Fix type of flags parameter for some ->trigger() implementations
When building with clang's -Wincompatible-function-pointer-types-strict
(a warning designed to catch potential kCFI failures at build time),
there are several warnings along the lines of:
fs/bcachefs/bkey_methods.c:118:2: error: incompatible function pointer types initializing 'int (*)(struct btree_trans *, enum btree_id, unsigned int, struct bkey_s_c, struct bkey_s, enum btree_iter_update_trigger_flags)' with an expression of type 'int (struct btree_trans *, enum btree_id, unsigned int, struct bkey_s_c, struct bkey_s, unsigned int)' [-Werror,-Wincompatible-function-pointer-types-strict]
118 | BCH_BKEY_TYPES()
| ^~~~~~~~~~~~~~~~
fs/bcachefs/bcachefs_format.h:394:2: note: expanded from macro 'BCH_BKEY_TYPES'
394 | x(inode, 8) \
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
fs/bcachefs/bkey_methods.c:117:41: note: expanded from macro 'x'
117 | #define x(name, nr) [KEY_TYPE_##name] = bch2_bkey_ops_##name,
| ^~~~~~~~~~~~~~~~~~~~
<scratch space>:277:1: note: expanded from here
277 | bch2_bkey_ops_inode
| ^~~~~~~~~~~~~~~~~~~
fs/bcachefs/inode.h:26:13: note: expanded from macro 'bch2_bkey_ops_inode'
26 | .trigger = bch2_trigger_inode, \
| ^~~~~~~~~~~~~~~~~~
There are several functions that did not have their flags parameter
converted to 'enum btree_iter_update_trigger_flags' in the recent
unification, which will cause kCFI failures at runtime because the
types, while ABI compatible (hence no warning from the non-strict
version of this warning), do not match exactly.
Fix up these functions (as well as a few other obvious functions that
should have it, even if there are no warnings currently) to resolve the
warnings and potential kCFI runtime failures.
Fixes: 31e4ef3280c8 ("bcachefs: iter/update/trigger/str_hash flag cleanup")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2024-04-23 18:58:09 +00:00
|
|
|
enum btree_iter_update_trigger_flags flags)
|
2022-03-31 04:03:37 +00:00
|
|
|
{
|
2023-06-23 00:18:12 +00:00
|
|
|
check_indirect_extent_deleting(new, &flags);
|
2022-03-31 04:03:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-08-16 13:59:56 +00:00
|
|
|
static int bch2_make_extent_indirect(struct btree_trans *trans,
|
|
|
|
struct btree_iter *extent_iter,
|
2020-10-24 23:51:34 +00:00
|
|
|
struct bkey_i *orig)
|
2019-08-16 13:59:56 +00:00
|
|
|
{
|
|
|
|
struct bch_fs *c = trans->c;
|
2021-08-30 19:18:31 +00:00
|
|
|
struct btree_iter reflink_iter = { NULL };
|
2019-08-16 13:59:56 +00:00
|
|
|
struct bkey_s_c k;
|
2020-10-24 23:51:34 +00:00
|
|
|
struct bkey_i *r_v;
|
2019-08-16 13:59:56 +00:00
|
|
|
struct bkey_i_reflink_p *r_p;
|
2020-10-24 23:51:34 +00:00
|
|
|
__le64 *refcount;
|
2019-08-16 13:59:56 +00:00
|
|
|
int ret;
|
|
|
|
|
2020-10-24 23:51:34 +00:00
|
|
|
if (orig->k.type == KEY_TYPE_inline_data)
|
|
|
|
bch2_check_set_feature(c, BCH_FEATURE_reflink_inline_data);
|
|
|
|
|
2023-05-26 03:37:06 +00:00
|
|
|
bch2_trans_iter_init(trans, &reflink_iter, BTREE_ID_reflink, POS_MAX,
|
2024-04-07 22:05:34 +00:00
|
|
|
BTREE_ITER_intent);
|
2023-05-26 03:37:06 +00:00
|
|
|
k = bch2_btree_iter_peek_prev(&reflink_iter);
|
|
|
|
ret = bkey_err(k);
|
2019-08-16 13:59:56 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2021-06-10 17:21:39 +00:00
|
|
|
r_v = bch2_trans_kmalloc(trans, sizeof(__le64) + bkey_bytes(&orig->k));
|
2019-08-16 13:59:56 +00:00
|
|
|
ret = PTR_ERR_OR_ZERO(r_v);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2020-10-24 23:51:34 +00:00
|
|
|
bkey_init(&r_v->k);
|
|
|
|
r_v->k.type = bkey_type_to_indirect(&orig->k);
|
2021-08-30 19:18:31 +00:00
|
|
|
r_v->k.p = reflink_iter.pos;
|
2020-10-24 23:51:34 +00:00
|
|
|
bch2_key_resize(&r_v->k, orig->k.size);
|
|
|
|
r_v->k.version = orig->k.version;
|
|
|
|
|
|
|
|
set_bkey_val_bytes(&r_v->k, sizeof(__le64) + bkey_val_bytes(&orig->k));
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2023-12-28 04:19:09 +00:00
|
|
|
refcount = bkey_refcount(bkey_i_to_s(r_v));
|
2020-10-24 23:51:34 +00:00
|
|
|
*refcount = 0;
|
|
|
|
memcpy(refcount + 1, &orig->v, bkey_val_bytes(&orig->k));
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2021-08-30 19:18:31 +00:00
|
|
|
ret = bch2_trans_update(trans, &reflink_iter, r_v, 0);
|
2021-05-19 03:17:03 +00:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2021-10-18 15:32:06 +00:00
|
|
|
/*
|
|
|
|
* orig is in a bkey_buf which statically allocates 5 64s for the val,
|
|
|
|
* so we know it will be big enough:
|
|
|
|
*/
|
2020-10-24 23:51:34 +00:00
|
|
|
orig->k.type = KEY_TYPE_reflink_p;
|
|
|
|
r_p = bkey_i_to_reflink_p(orig);
|
2019-08-16 13:59:56 +00:00
|
|
|
set_bkey_val_bytes(&r_p->k, sizeof(r_p->v));
|
2023-03-05 04:05:55 +00:00
|
|
|
|
|
|
|
/* FORTIFY_SOURCE is broken here, and doesn't provide unsafe_memset() */
|
|
|
|
#if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
|
|
|
|
__underlying_memset(&r_p->v, 0, sizeof(r_p->v));
|
|
|
|
#else
|
2021-10-18 15:32:06 +00:00
|
|
|
memset(&r_p->v, 0, sizeof(r_p->v));
|
2023-03-05 04:05:55 +00:00
|
|
|
#endif
|
2021-10-18 15:32:06 +00:00
|
|
|
|
2019-08-16 13:59:56 +00:00
|
|
|
r_p->v.idx = cpu_to_le64(bkey_start_offset(&r_v->k));
|
|
|
|
|
2021-11-29 21:36:50 +00:00
|
|
|
ret = bch2_trans_update(trans, extent_iter, &r_p->k_i,
|
2024-04-07 22:05:34 +00:00
|
|
|
BTREE_UPDATE_internal_snapshot_node);
|
2019-08-16 13:59:56 +00:00
|
|
|
err:
|
2021-08-30 19:18:31 +00:00
|
|
|
bch2_trans_iter_exit(trans, &reflink_iter);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bkey_s_c get_next_src(struct btree_iter *iter, struct bpos end)
|
|
|
|
{
|
2021-03-21 02:14:10 +00:00
|
|
|
struct bkey_s_c k;
|
2019-10-05 00:40:47 +00:00
|
|
|
int ret;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2022-11-13 23:59:01 +00:00
|
|
|
for_each_btree_key_upto_continue_norestart(*iter, end, 0, k, ret) {
|
|
|
|
if (bkey_extent_is_unwritten(k))
|
|
|
|
continue;
|
|
|
|
|
2020-10-24 23:51:34 +00:00
|
|
|
if (bkey_extent_is_data(k.k))
|
2021-03-21 02:14:10 +00:00
|
|
|
return k;
|
2022-11-13 23:59:01 +00:00
|
|
|
}
|
2019-10-05 00:40:47 +00:00
|
|
|
|
2022-11-24 08:12:22 +00:00
|
|
|
if (bkey_ge(iter->pos, end))
|
2021-07-24 23:50:40 +00:00
|
|
|
bch2_btree_iter_set_pos(iter, end);
|
|
|
|
return ret ? bkey_s_c_err(ret) : bkey_s_c_null;
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s64 bch2_remap_range(struct bch_fs *c,
|
2021-03-16 04:28:17 +00:00
|
|
|
subvol_inum dst_inum, u64 dst_offset,
|
|
|
|
subvol_inum src_inum, u64 src_offset,
|
2021-11-05 19:17:13 +00:00
|
|
|
u64 remap_sectors,
|
2019-10-10 16:47:22 +00:00
|
|
|
u64 new_i_size, s64 *i_sectors_delta)
|
2019-08-16 13:59:56 +00:00
|
|
|
{
|
2023-09-12 21:16:02 +00:00
|
|
|
struct btree_trans *trans;
|
2021-08-30 19:18:31 +00:00
|
|
|
struct btree_iter dst_iter, src_iter;
|
2019-08-16 13:59:56 +00:00
|
|
|
struct bkey_s_c src_k;
|
2020-12-17 20:08:58 +00:00
|
|
|
struct bkey_buf new_dst, new_src;
|
2021-03-16 04:28:17 +00:00
|
|
|
struct bpos dst_start = POS(dst_inum.inum, dst_offset);
|
|
|
|
struct bpos src_start = POS(src_inum.inum, src_offset);
|
2019-08-16 13:59:56 +00:00
|
|
|
struct bpos dst_end = dst_start, src_end = src_start;
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
struct bch_io_opts opts;
|
2021-03-21 02:14:10 +00:00
|
|
|
struct bpos src_want;
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
u64 dst_done = 0;
|
2021-03-13 01:30:39 +00:00
|
|
|
u32 dst_snapshot, src_snapshot;
|
2019-10-10 16:47:22 +00:00
|
|
|
int ret = 0, ret2 = 0;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2023-02-09 17:21:45 +00:00
|
|
|
if (!bch2_write_ref_tryget(c, BCH_WRITE_REF_reflink))
|
2022-12-12 01:37:11 +00:00
|
|
|
return -BCH_ERR_erofs_no_writes;
|
2019-10-19 23:03:23 +00:00
|
|
|
|
2019-12-29 01:17:06 +00:00
|
|
|
bch2_check_set_feature(c, BCH_FEATURE_reflink);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
dst_end.offset += remap_sectors;
|
|
|
|
src_end.offset += remap_sectors;
|
|
|
|
|
2020-12-17 20:08:58 +00:00
|
|
|
bch2_bkey_buf_init(&new_dst);
|
|
|
|
bch2_bkey_buf_init(&new_src);
|
2023-09-12 21:16:02 +00:00
|
|
|
trans = bch2_trans_get(c);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
ret = bch2_inum_opts_get(trans, src_inum, &opts);
|
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_iter_init(trans, &src_iter, BTREE_ID_extents, src_start,
|
2024-04-07 22:05:34 +00:00
|
|
|
BTREE_ITER_intent);
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_iter_init(trans, &dst_iter, BTREE_ID_extents, dst_start,
|
2024-04-07 22:05:34 +00:00
|
|
|
BTREE_ITER_intent);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2022-07-18 03:06:38 +00:00
|
|
|
while ((ret == 0 ||
|
|
|
|
bch2_err_matches(ret, BCH_ERR_transaction_restart)) &&
|
2022-11-24 08:12:22 +00:00
|
|
|
bkey_lt(dst_iter.pos, dst_end)) {
|
2021-05-17 04:08:06 +00:00
|
|
|
struct disk_reservation disk_res = { 0 };
|
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_begin(trans);
|
2019-12-20 21:35:24 +00:00
|
|
|
|
2019-08-16 13:59:56 +00:00
|
|
|
if (fatal_signal_pending(current)) {
|
|
|
|
ret = -EINTR;
|
2021-03-20 00:29:11 +00:00
|
|
|
break;
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
ret = bch2_subvolume_get_snapshot(trans, src_inum.subvol,
|
2021-03-13 01:30:39 +00:00
|
|
|
&src_snapshot);
|
2021-03-16 04:28:17 +00:00
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
|
2021-03-13 01:30:39 +00:00
|
|
|
bch2_btree_iter_set_snapshot(&src_iter, src_snapshot);
|
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
ret = bch2_subvolume_get_snapshot(trans, dst_inum.subvol,
|
2021-03-13 01:30:39 +00:00
|
|
|
&dst_snapshot);
|
2021-03-16 04:28:17 +00:00
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
|
2021-03-13 01:30:39 +00:00
|
|
|
bch2_btree_iter_set_snapshot(&dst_iter, dst_snapshot);
|
|
|
|
|
2024-01-11 04:47:04 +00:00
|
|
|
if (dst_inum.inum < src_inum.inum) {
|
|
|
|
/* Avoid some lock cycle transaction restarts */
|
|
|
|
ret = bch2_btree_iter_traverse(&dst_iter);
|
|
|
|
if (ret)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-08-30 19:18:31 +00:00
|
|
|
dst_done = dst_iter.pos.offset - dst_start.offset;
|
2021-03-21 02:14:10 +00:00
|
|
|
src_want = POS(src_start.inode, src_start.offset + dst_done);
|
2021-08-30 19:18:31 +00:00
|
|
|
bch2_btree_iter_set_pos(&src_iter, src_want);
|
2021-03-21 02:14:10 +00:00
|
|
|
|
2021-08-30 19:18:31 +00:00
|
|
|
src_k = get_next_src(&src_iter, src_end);
|
2019-08-16 13:59:56 +00:00
|
|
|
ret = bkey_err(src_k);
|
|
|
|
if (ret)
|
2021-03-20 00:29:11 +00:00
|
|
|
continue;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2022-11-24 08:12:22 +00:00
|
|
|
if (bkey_lt(src_want, src_iter.pos)) {
|
2023-09-12 21:16:02 +00:00
|
|
|
ret = bch2_fpunch_at(trans, &dst_iter, dst_inum,
|
2021-03-13 01:30:39 +00:00
|
|
|
min(dst_end.offset,
|
|
|
|
dst_iter.pos.offset +
|
|
|
|
src_iter.pos.offset - src_want.offset),
|
2021-11-05 19:17:13 +00:00
|
|
|
i_sectors_delta);
|
2019-08-16 13:59:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-10-24 23:51:34 +00:00
|
|
|
if (src_k.k->type != KEY_TYPE_reflink_p) {
|
2021-08-30 19:18:31 +00:00
|
|
|
bch2_btree_iter_set_pos_to_extent_start(&src_iter);
|
2021-06-14 22:16:10 +00:00
|
|
|
|
2020-12-17 20:08:58 +00:00
|
|
|
bch2_bkey_buf_reassemble(&new_src, c, src_k);
|
2019-11-09 21:01:15 +00:00
|
|
|
src_k = bkey_i_to_s_c(new_src.k);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
ret = bch2_make_extent_indirect(trans, &src_iter,
|
2020-10-24 23:51:34 +00:00
|
|
|
new_src.k);
|
2019-08-16 13:59:56 +00:00
|
|
|
if (ret)
|
2021-03-20 00:29:11 +00:00
|
|
|
continue;
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
BUG_ON(src_k.k->type != KEY_TYPE_reflink_p);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src_k.k->type == KEY_TYPE_reflink_p) {
|
|
|
|
struct bkey_s_c_reflink_p src_p =
|
|
|
|
bkey_s_c_to_reflink_p(src_k);
|
|
|
|
struct bkey_i_reflink_p *dst_p =
|
2020-12-17 20:08:58 +00:00
|
|
|
bkey_reflink_p_init(new_dst.k);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
|
|
|
u64 offset = le64_to_cpu(src_p.v->idx) +
|
2021-03-21 02:14:10 +00:00
|
|
|
(src_want.offset -
|
2019-08-16 13:59:56 +00:00
|
|
|
bkey_start_offset(src_k.k));
|
|
|
|
|
|
|
|
dst_p->v.idx = cpu_to_le64(offset);
|
|
|
|
} else {
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
|
2021-08-30 19:18:31 +00:00
|
|
|
new_dst.k->k.p = dst_iter.pos;
|
2020-12-17 20:08:58 +00:00
|
|
|
bch2_key_resize(&new_dst.k->k,
|
2021-03-21 02:14:10 +00:00
|
|
|
min(src_k.k->p.offset - src_want.offset,
|
2021-08-30 19:18:31 +00:00
|
|
|
dst_end.offset - dst_iter.pos.offset));
|
2021-03-13 01:30:39 +00:00
|
|
|
|
2024-01-16 21:20:21 +00:00
|
|
|
ret = bch2_bkey_set_needs_rebalance(c, new_dst.k, &opts) ?:
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
bch2_extent_update(trans, dst_inum, &dst_iter,
|
|
|
|
new_dst.k, &disk_res,
|
|
|
|
new_i_size, i_sectors_delta,
|
|
|
|
true);
|
2021-05-17 04:08:06 +00:00
|
|
|
bch2_disk_reservation_put(c, &disk_res);
|
2019-08-16 13:59:56 +00:00
|
|
|
}
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_iter_exit(trans, &dst_iter);
|
|
|
|
bch2_trans_iter_exit(trans, &src_iter);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2022-11-24 08:12:22 +00:00
|
|
|
BUG_ON(!ret && !bkey_eq(dst_iter.pos, dst_end));
|
|
|
|
BUG_ON(bkey_gt(dst_iter.pos, dst_end));
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2021-08-30 19:18:31 +00:00
|
|
|
dst_done = dst_iter.pos.offset - dst_start.offset;
|
|
|
|
new_i_size = min(dst_iter.pos.offset << 9, new_i_size);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2019-10-10 16:47:22 +00:00
|
|
|
do {
|
|
|
|
struct bch_inode_unpacked inode_u;
|
2021-08-30 19:18:31 +00:00
|
|
|
struct btree_iter inode_iter = { NULL };
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_begin(trans);
|
2021-07-25 00:24:10 +00:00
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
ret2 = bch2_inode_peek(trans, &inode_iter, &inode_u,
|
2024-04-07 22:05:34 +00:00
|
|
|
dst_inum, BTREE_ITER_intent);
|
2019-08-16 13:59:56 +00:00
|
|
|
|
2019-10-10 16:47:22 +00:00
|
|
|
if (!ret2 &&
|
2019-11-05 03:22:13 +00:00
|
|
|
inode_u.bi_size < new_i_size) {
|
|
|
|
inode_u.bi_size = new_i_size;
|
2023-09-12 21:16:02 +00:00
|
|
|
ret2 = bch2_inode_write(trans, &inode_iter, &inode_u) ?:
|
|
|
|
bch2_trans_commit(trans, NULL, NULL,
|
2023-11-11 21:31:50 +00:00
|
|
|
BCH_TRANS_COMMIT_no_enospc);
|
2019-11-05 03:22:13 +00:00
|
|
|
}
|
2021-03-20 00:29:11 +00:00
|
|
|
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_iter_exit(trans, &inode_iter);
|
2022-07-18 03:06:38 +00:00
|
|
|
} while (bch2_err_matches(ret2, BCH_ERR_transaction_restart));
|
bcachefs: rebalance_work
This adds a new btree, rebalance_work, to eliminate scanning required
for finding extents that need work done on them in the background - i.e.
for the background_target and background_compression options.
rebalance_work is a bitset btree, where a KEY_TYPE_set corresponds to an
extent in the extents or reflink btree at the same pos.
A new extent field is added, bch_extent_rebalance, which indicates that
this extent has work that needs to be done in the background - and which
options to use. This allows per-inode options to be propagated to
indirect extents - at least in some circumstances. In this patch,
changing IO options on a file will not propagate the new options to
indirect extents pointed to by that file.
Updating (setting/clearing) the rebalance_work btree is done by the
extent trigger, which looks at the bch_extent_rebalance field.
Scanning is still requrired after changing IO path options - either just
for a given inode, or for the whole filesystem. We indicate that
scanning is required by adding a KEY_TYPE_cookie key to the
rebalance_work btree: the cookie counter is so that we can detect that
scanning is still required when an option has been flipped mid-way
through an existing scan.
Future possible work:
- Propagate options to indirect extents when being changed
- Add other IO path options - nr_replicas, ec, to rebalance_work so
they can be applied in the background when they change
- Add a counter, for bcachefs fs usage output, showing the pending
amount of rebalance work: we'll probably want to do this after the
disk space accounting rewrite (moving it to a new btree)
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
2023-10-20 17:33:14 +00:00
|
|
|
err:
|
2023-09-12 21:16:02 +00:00
|
|
|
bch2_trans_put(trans);
|
2020-12-17 20:08:58 +00:00
|
|
|
bch2_bkey_buf_exit(&new_src, c);
|
|
|
|
bch2_bkey_buf_exit(&new_dst, c);
|
2019-10-10 16:47:22 +00:00
|
|
|
|
2023-02-09 17:21:45 +00:00
|
|
|
bch2_write_ref_put(c, BCH_WRITE_REF_reflink);
|
2019-10-19 23:03:23 +00:00
|
|
|
|
2019-10-10 16:47:22 +00:00
|
|
|
return dst_done ?: ret ?: ret2;
|
|
|
|
}
|