Commit 093dd55d authored by Kent Overstreet's avatar Kent Overstreet

bcachefs: bch2_folio_set() -> for_each_btree_key_in_subvolume_upto

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent c95285d1
...@@ -182,18 +182,11 @@ static void __bch2_folio_set(struct folio *folio, ...@@ -182,18 +182,11 @@ static void __bch2_folio_set(struct folio *folio,
int bch2_folio_set(struct bch_fs *c, subvol_inum inum, int bch2_folio_set(struct bch_fs *c, subvol_inum inum,
struct folio **fs, unsigned nr_folios) struct folio **fs, unsigned nr_folios)
{ {
struct btree_trans *trans;
struct btree_iter iter;
struct bkey_s_c k;
struct bch_folio *s;
u64 offset = folio_sector(fs[0]); u64 offset = folio_sector(fs[0]);
unsigned folio_idx;
u32 snapshot;
bool need_set = false; bool need_set = false;
int ret;
for (folio_idx = 0; folio_idx < nr_folios; folio_idx++) { for (unsigned folio_idx = 0; folio_idx < nr_folios; folio_idx++) {
s = bch2_folio_create(fs[folio_idx], GFP_KERNEL); struct bch_folio *s = bch2_folio_create(fs[folio_idx], GFP_KERNEL);
if (!s) if (!s)
return -ENOMEM; return -ENOMEM;
...@@ -203,53 +196,40 @@ int bch2_folio_set(struct bch_fs *c, subvol_inum inum, ...@@ -203,53 +196,40 @@ int bch2_folio_set(struct bch_fs *c, subvol_inum inum,
if (!need_set) if (!need_set)
return 0; return 0;
folio_idx = 0; unsigned folio_idx = 0;
trans = bch2_trans_get(c);
retry: return bch2_trans_run(c,
bch2_trans_begin(trans); for_each_btree_key_in_subvolume_upto(trans, iter, BTREE_ID_extents,
POS(inum.inum, offset),
ret = bch2_subvolume_get_snapshot(trans, inum.subvol, &snapshot); POS(inum.inum, U64_MAX),
if (ret) inum.subvol, BTREE_ITER_slots, k, ({
goto err; unsigned nr_ptrs = bch2_bkey_nr_ptrs_fully_allocated(k);
unsigned state = bkey_to_sector_state(k);
for_each_btree_key_norestart(trans, iter, BTREE_ID_extents,
SPOS(inum.inum, offset, snapshot), while (folio_idx < nr_folios) {
BTREE_ITER_slots, k, ret) { struct folio *folio = fs[folio_idx];
unsigned nr_ptrs = bch2_bkey_nr_ptrs_fully_allocated(k); u64 folio_start = folio_sector(folio);
unsigned state = bkey_to_sector_state(k); u64 folio_end = folio_end_sector(folio);
unsigned folio_offset = max(bkey_start_offset(k.k), folio_start) -
while (folio_idx < nr_folios) { folio_start;
struct folio *folio = fs[folio_idx]; unsigned folio_len = min(k.k->p.offset, folio_end) -
u64 folio_start = folio_sector(folio); folio_offset - folio_start;
u64 folio_end = folio_end_sector(folio);
unsigned folio_offset = max(bkey_start_offset(k.k), folio_start) - BUG_ON(k.k->p.offset < folio_start);
folio_start; BUG_ON(bkey_start_offset(k.k) > folio_end);
unsigned folio_len = min(k.k->p.offset, folio_end) -
folio_offset - folio_start; if (!bch2_folio(folio)->uptodate)
__bch2_folio_set(folio, folio_offset, folio_len, nr_ptrs, state);
BUG_ON(k.k->p.offset < folio_start);
BUG_ON(bkey_start_offset(k.k) > folio_end); if (k.k->p.offset < folio_end)
break;
if (!bch2_folio(folio)->uptodate) folio_idx++;
__bch2_folio_set(folio, folio_offset, folio_len, nr_ptrs, state); }
if (k.k->p.offset < folio_end)
break;
folio_idx++;
}
if (folio_idx == nr_folios)
break;
}
offset = iter.pos.offset;
bch2_trans_iter_exit(trans, &iter);
err:
if (bch2_err_matches(ret, BCH_ERR_transaction_restart))
goto retry;
bch2_trans_put(trans);
return ret; if (folio_idx == nr_folios)
break;
0;
})));
} }
void bch2_bio_page_state_set(struct bio *bio, struct bkey_s_c k) void bch2_bio_page_state_set(struct bio *bio, struct bkey_s_c k)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment