Commit 8ef231bd authored by Kent Overstreet's avatar Kent Overstreet Committed by Kent Overstreet

bcachefs: convert fcollapse to bch2_extent_update()

Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent 5f461e01
...@@ -2424,7 +2424,6 @@ static long bch2_fcollapse(struct bch_inode_info *inode, ...@@ -2424,7 +2424,6 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
struct btree_iter *src, *dst; struct btree_iter *src, *dst;
BKEY_PADDED(k) copy; BKEY_PADDED(k) copy;
struct bkey_s_c k; struct bkey_s_c k;
struct i_sectors_hook i_sectors_hook = i_sectors_hook_init(inode, 0);
loff_t new_size; loff_t new_size;
int ret; int ret;
...@@ -2432,16 +2431,7 @@ static long bch2_fcollapse(struct bch_inode_info *inode, ...@@ -2432,16 +2431,7 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
return -EINVAL; return -EINVAL;
bch2_trans_init(&trans, c); bch2_trans_init(&trans, c);
bch2_trans_preload_iters(&trans);
dst = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
POS(inode->v.i_ino, offset >> 9),
BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
BUG_ON(IS_ERR(dst));
/* position will be set from dst iter's position: */
src = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS, POS_MIN,
BTREE_ITER_SLOTS);
BUG_ON(IS_ERR(src));
/* /*
* We need i_mutex to keep the page cache consistent with the extents * We need i_mutex to keep the page cache consistent with the extents
...@@ -2466,15 +2456,24 @@ static long bch2_fcollapse(struct bch_inode_info *inode, ...@@ -2466,15 +2456,24 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
if (ret) if (ret)
goto err; goto err;
ret = i_sectors_dirty_start(c, &i_sectors_hook); dst = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
if (ret) POS(inode->v.i_ino, offset >> 9),
goto err; BTREE_ITER_SLOTS|BTREE_ITER_INTENT);
BUG_ON(IS_ERR_OR_NULL(dst));
src = bch2_trans_get_iter(&trans, BTREE_ID_EXTENTS,
POS_MIN, BTREE_ITER_SLOTS);
BUG_ON(IS_ERR_OR_NULL(src));
while (bkey_cmp(dst->pos, while (bkey_cmp(dst->pos,
POS(inode->v.i_ino, POS(inode->v.i_ino,
round_up(new_size, PAGE_SIZE) >> 9)) < 0) { round_up(new_size, PAGE_SIZE) >> 9)) < 0) {
struct disk_reservation disk_res; struct disk_reservation disk_res;
ret = bch2_btree_iter_traverse(dst);
if (ret)
goto btree_iter_err;
bch2_btree_iter_set_pos(src, bch2_btree_iter_set_pos(src,
POS(dst->pos.inode, dst->pos.offset + (len >> 9))); POS(dst->pos.inode, dst->pos.offset + (len >> 9)));
...@@ -2487,10 +2486,6 @@ static long bch2_fcollapse(struct bch_inode_info *inode, ...@@ -2487,10 +2486,6 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
bch2_cut_front(src->pos, &copy.k); bch2_cut_front(src->pos, &copy.k);
copy.k.k.p.offset -= len >> 9; copy.k.k.p.offset -= len >> 9;
ret = bch2_btree_iter_traverse(dst);
if (ret)
goto btree_iter_err;
bch2_extent_trim_atomic(&copy.k, dst); bch2_extent_trim_atomic(&copy.k, dst);
BUG_ON(bkey_cmp(dst->pos, bkey_start_pos(&copy.k.k))); BUG_ON(bkey_cmp(dst->pos, bkey_start_pos(&copy.k.k)));
...@@ -2500,19 +2495,16 @@ static long bch2_fcollapse(struct bch_inode_info *inode, ...@@ -2500,19 +2495,16 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
BCH_DISK_RESERVATION_NOFAIL); BCH_DISK_RESERVATION_NOFAIL);
BUG_ON(ret); BUG_ON(ret);
ret = bch2_btree_insert_at(c, &disk_res, &i_sectors_hook.hook, ret = bch2_extent_update(&trans, inode,
&inode->ei_journal_seq, &disk_res, NULL,
BTREE_INSERT_ATOMIC| dst, &copy.k,
BTREE_INSERT_NOFAIL, 0, true, true, NULL);
BTREE_INSERT_ENTRY(dst, &copy.k));
bch2_disk_reservation_put(c, &disk_res); bch2_disk_reservation_put(c, &disk_res);
btree_iter_err: btree_iter_err:
if (ret == -EINTR) if (ret == -EINTR)
ret = 0; ret = 0;
if (ret) { if (ret)
bch2_trans_exit(&trans); goto err;
goto err_put_sectors_dirty;
}
/* /*
* XXX: if we error here we've left data with multiple * XXX: if we error here we've left data with multiple
* pointers... which isn't a _super_ serious problem... * pointers... which isn't a _super_ serious problem...
...@@ -2520,20 +2512,21 @@ static long bch2_fcollapse(struct bch_inode_info *inode, ...@@ -2520,20 +2512,21 @@ static long bch2_fcollapse(struct bch_inode_info *inode,
bch2_btree_iter_cond_resched(src); bch2_btree_iter_cond_resched(src);
} }
bch2_trans_unlock(&trans);
bch2_trans_exit(&trans); ret = __bch2_fpunch(c, inode,
round_up(new_size, block_bytes(c)) >> 9,
ret = bch2_inode_truncate(c, inode->v.i_ino, U64_MAX, &inode->ei_journal_seq);
round_up(new_size, block_bytes(c)) >> 9,
&i_sectors_hook.hook,
&inode->ei_journal_seq);
if (ret) if (ret)
goto err_put_sectors_dirty; goto err;
i_sectors_hook.new_i_size = new_size; i_size_write(&inode->v, new_size);
err_put_sectors_dirty: mutex_lock(&inode->ei_update_lock);
ret = i_sectors_dirty_finish(c, &i_sectors_hook) ?: ret; ret = bch2_write_inode_size(c, inode, new_size,
ATTR_MTIME|ATTR_CTIME);
mutex_unlock(&inode->ei_update_lock);
err: err:
bch2_trans_exit(&trans);
bch2_pagecache_block_put(&inode->ei_pagecache_lock); bch2_pagecache_block_put(&inode->ei_pagecache_lock);
inode_unlock(&inode->v); inode_unlock(&inode->v);
return ret; return ret;
......
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