Commit e641e323 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: pass a btrfs_inode to btrfs_wait_ordered_range()

Instead of passing a (VFS) inode pointer argument, pass a btrfs_inode
instead, as this is generally what we do for internal APIs, making it
more consistent with most of the code base. This will later allow to
help to remove a lot of BTRFS_I() calls in btrfs_sync_file().
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent cef2daba
...@@ -1884,7 +1884,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -1884,7 +1884,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
* to wait for the IO to stabilize the logical address. * to wait for the IO to stabilize the logical address.
*/ */
if (full_sync || btrfs_is_zoned(fs_info)) { if (full_sync || btrfs_is_zoned(fs_info)) {
ret = btrfs_wait_ordered_range(inode, start, len); ret = btrfs_wait_ordered_range(BTRFS_I(inode), start, len);
clear_bit(BTRFS_INODE_COW_WRITE_ERROR, &BTRFS_I(inode)->runtime_flags); clear_bit(BTRFS_INODE_COW_WRITE_ERROR, &BTRFS_I(inode)->runtime_flags);
} else { } else {
/* /*
...@@ -1909,7 +1909,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -1909,7 +1909,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
*/ */
if (test_and_clear_bit(BTRFS_INODE_COW_WRITE_ERROR, if (test_and_clear_bit(BTRFS_INODE_COW_WRITE_ERROR,
&BTRFS_I(inode)->runtime_flags)) &BTRFS_I(inode)->runtime_flags))
ret = btrfs_wait_ordered_range(inode, start, len); ret = btrfs_wait_ordered_range(BTRFS_I(inode), start, len);
} }
if (ret) if (ret)
...@@ -2014,7 +2014,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2014,7 +2014,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
ret = btrfs_end_transaction(trans); ret = btrfs_end_transaction(trans);
if (ret) if (ret)
goto out; goto out;
ret = btrfs_wait_ordered_range(inode, start, len); ret = btrfs_wait_ordered_range(BTRFS_I(inode), start, len);
if (ret) if (ret)
goto out; goto out;
...@@ -2814,7 +2814,7 @@ static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len) ...@@ -2814,7 +2814,7 @@ static int btrfs_punch_hole(struct file *file, loff_t offset, loff_t len)
btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_MMAP); btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
ret = btrfs_wait_ordered_range(inode, offset, len); ret = btrfs_wait_ordered_range(BTRFS_I(inode), offset, len);
if (ret) if (ret)
goto out_only_mutex; goto out_only_mutex;
...@@ -3309,7 +3309,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -3309,7 +3309,7 @@ static long btrfs_fallocate(struct file *file, int mode,
* the file range and, due to the previous locking we did, we know there * the file range and, due to the previous locking we did, we know there
* can't be more delalloc or ordered extents in the range. * can't be more delalloc or ordered extents in the range.
*/ */
ret = btrfs_wait_ordered_range(inode, alloc_start, ret = btrfs_wait_ordered_range(BTRFS_I(inode), alloc_start,
alloc_end - alloc_start); alloc_end - alloc_start);
if (ret) if (ret)
goto out; goto out;
......
...@@ -1268,7 +1268,7 @@ static int flush_dirty_cache(struct inode *inode) ...@@ -1268,7 +1268,7 @@ static int flush_dirty_cache(struct inode *inode)
{ {
int ret; int ret;
ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); ret = btrfs_wait_ordered_range(BTRFS_I(inode), 0, (u64)-1);
if (ret) if (ret)
clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1, clear_extent_bit(&BTRFS_I(inode)->io_tree, 0, inode->i_size - 1,
EXTENT_DELALLOC, NULL); EXTENT_DELALLOC, NULL);
......
...@@ -5081,7 +5081,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) ...@@ -5081,7 +5081,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
struct btrfs_fs_info *fs_info = inode_to_fs_info(inode); struct btrfs_fs_info *fs_info = inode_to_fs_info(inode);
if (btrfs_is_zoned(fs_info)) { if (btrfs_is_zoned(fs_info)) {
ret = btrfs_wait_ordered_range(inode, ret = btrfs_wait_ordered_range(BTRFS_I(inode),
ALIGN(newsize, fs_info->sectorsize), ALIGN(newsize, fs_info->sectorsize),
(u64)-1); (u64)-1);
if (ret) if (ret)
...@@ -5111,7 +5111,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) ...@@ -5111,7 +5111,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
* wait for disk_i_size to be stable and then update the * wait for disk_i_size to be stable and then update the
* in-memory size to match. * in-memory size to match.
*/ */
err = btrfs_wait_ordered_range(inode, 0, (u64)-1); err = btrfs_wait_ordered_range(BTRFS_I(inode), 0, (u64)-1);
if (err) if (err)
return err; return err;
i_size_write(inode, BTRFS_I(inode)->disk_i_size); i_size_write(inode, BTRFS_I(inode)->disk_i_size);
...@@ -7955,7 +7955,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, ...@@ -7955,7 +7955,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
* if we have delalloc in those ranges. * if we have delalloc in those ranges.
*/ */
if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) { if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) {
ret = btrfs_wait_ordered_range(inode, 0, LLONG_MAX); ret = btrfs_wait_ordered_range(btrfs_inode, 0, LLONG_MAX);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -7969,7 +7969,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, ...@@ -7969,7 +7969,7 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
* possible a new write may have happened in between those two steps. * possible a new write may have happened in between those two steps.
*/ */
if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) { if (fieinfo->fi_flags & FIEMAP_FLAG_SYNC) {
ret = btrfs_wait_ordered_range(inode, 0, LLONG_MAX); ret = btrfs_wait_ordered_range(btrfs_inode, 0, LLONG_MAX);
if (ret) { if (ret) {
btrfs_inode_unlock(btrfs_inode, BTRFS_ILOCK_SHARED); btrfs_inode_unlock(btrfs_inode, BTRFS_ILOCK_SHARED);
return ret; return ret;
...@@ -8238,7 +8238,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback) ...@@ -8238,7 +8238,7 @@ static int btrfs_truncate(struct btrfs_inode *inode, bool skip_writeback)
const u64 min_size = btrfs_calc_metadata_size(fs_info, 1); const u64 min_size = btrfs_calc_metadata_size(fs_info, 1);
if (!skip_writeback) { if (!skip_writeback) {
ret = btrfs_wait_ordered_range(&inode->vfs_inode, ret = btrfs_wait_ordered_range(inode,
inode->vfs_inode.i_size & (~mask), inode->vfs_inode.i_size & (~mask),
(u64)-1); (u64)-1);
if (ret) if (ret)
...@@ -10062,7 +10062,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter, ...@@ -10062,7 +10062,7 @@ ssize_t btrfs_encoded_read(struct kiocb *iocb, struct iov_iter *iter,
for (;;) { for (;;) {
struct btrfs_ordered_extent *ordered; struct btrfs_ordered_extent *ordered;
ret = btrfs_wait_ordered_range(&inode->vfs_inode, start, ret = btrfs_wait_ordered_range(inode, start,
lockend - start + 1); lockend - start + 1);
if (ret) if (ret)
goto out_unlock_inode; goto out_unlock_inode;
...@@ -10305,7 +10305,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -10305,7 +10305,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
for (;;) { for (;;) {
struct btrfs_ordered_extent *ordered; struct btrfs_ordered_extent *ordered;
ret = btrfs_wait_ordered_range(&inode->vfs_inode, start, num_bytes); ret = btrfs_wait_ordered_range(inode, start, num_bytes);
if (ret) if (ret)
goto out_folios; goto out_folios;
ret = invalidate_inode_pages2_range(inode->vfs_inode.i_mapping, ret = invalidate_inode_pages2_range(inode->vfs_inode.i_mapping,
...@@ -10578,7 +10578,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file, ...@@ -10578,7 +10578,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
* file changes again after this, the user is doing something stupid and * file changes again after this, the user is doing something stupid and
* we don't really care. * we don't really care.
*/ */
ret = btrfs_wait_ordered_range(inode, 0, (u64)-1); ret = btrfs_wait_ordered_range(BTRFS_I(inode), 0, (u64)-1);
if (ret) if (ret)
return ret; return ret;
......
...@@ -840,7 +840,7 @@ void btrfs_start_ordered_extent(struct btrfs_ordered_extent *entry) ...@@ -840,7 +840,7 @@ void btrfs_start_ordered_extent(struct btrfs_ordered_extent *entry)
/* /*
* Used to wait on ordered extents across a large range of bytes. * Used to wait on ordered extents across a large range of bytes.
*/ */
int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len) int btrfs_wait_ordered_range(struct btrfs_inode *inode, u64 start, u64 len)
{ {
int ret = 0; int ret = 0;
int ret_wb = 0; int ret_wb = 0;
...@@ -859,7 +859,7 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len) ...@@ -859,7 +859,7 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
/* start IO across the range first to instantiate any delalloc /* start IO across the range first to instantiate any delalloc
* extents * extents
*/ */
ret = btrfs_fdatawrite_range(BTRFS_I(inode), start, orig_end); ret = btrfs_fdatawrite_range(inode, start, orig_end);
if (ret) if (ret)
return ret; return ret;
...@@ -870,11 +870,11 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len) ...@@ -870,11 +870,11 @@ int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len)
* before the ordered extents complete - to avoid failures (-EEXIST) * before the ordered extents complete - to avoid failures (-EEXIST)
* when adding the new ordered extents to the ordered tree. * when adding the new ordered extents to the ordered tree.
*/ */
ret_wb = filemap_fdatawait_range(inode->i_mapping, start, orig_end); ret_wb = filemap_fdatawait_range(inode->vfs_inode.i_mapping, start, orig_end);
end = orig_end; end = orig_end;
while (1) { while (1) {
ordered = btrfs_lookup_first_ordered_extent(BTRFS_I(inode), end); ordered = btrfs_lookup_first_ordered_extent(inode, end);
if (!ordered) if (!ordered)
break; break;
if (ordered->file_offset > orig_end) { if (ordered->file_offset > orig_end) {
......
...@@ -181,7 +181,7 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry, ...@@ -181,7 +181,7 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry,
struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *inode, struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct btrfs_inode *inode,
u64 file_offset); u64 file_offset);
void btrfs_start_ordered_extent(struct btrfs_ordered_extent *entry); void btrfs_start_ordered_extent(struct btrfs_ordered_extent *entry);
int btrfs_wait_ordered_range(struct inode *inode, u64 start, u64 len); int btrfs_wait_ordered_range(struct btrfs_inode *inode, u64 start, u64 len);
struct btrfs_ordered_extent * struct btrfs_ordered_extent *
btrfs_lookup_first_ordered_extent(struct btrfs_inode *inode, u64 file_offset); btrfs_lookup_first_ordered_extent(struct btrfs_inode *inode, u64 file_offset);
struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range( struct btrfs_ordered_extent *btrfs_lookup_first_ordered_range(
......
...@@ -733,7 +733,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, ...@@ -733,7 +733,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
* we found the previous extent covering eof and before we * we found the previous extent covering eof and before we
* attempted to increment its reference count). * attempted to increment its reference count).
*/ */
ret = btrfs_wait_ordered_range(inode, wb_start, ret = btrfs_wait_ordered_range(BTRFS_I(inode), wb_start,
destoff - wb_start); destoff - wb_start);
if (ret) if (ret)
return ret; return ret;
...@@ -755,7 +755,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, ...@@ -755,7 +755,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
* range, so wait for writeback to complete before truncating pages * range, so wait for writeback to complete before truncating pages
* from the page cache. This is a rare case. * from the page cache. This is a rare case.
*/ */
wb_ret = btrfs_wait_ordered_range(inode, destoff, len); wb_ret = btrfs_wait_ordered_range(BTRFS_I(inode), destoff, len);
ret = ret ? ret : wb_ret; ret = ret ? ret : wb_ret;
/* /*
* Truncate page cache pages so that future reads will see the cloned * Truncate page cache pages so that future reads will see the cloned
...@@ -835,11 +835,11 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in, ...@@ -835,11 +835,11 @@ static int btrfs_remap_file_range_prep(struct file *file_in, loff_t pos_in,
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = btrfs_wait_ordered_range(inode_in, ALIGN_DOWN(pos_in, bs), ret = btrfs_wait_ordered_range(BTRFS_I(inode_in), ALIGN_DOWN(pos_in, bs),
wb_len); wb_len);
if (ret < 0) if (ret < 0)
return ret; return ret;
ret = btrfs_wait_ordered_range(inode_out, ALIGN_DOWN(pos_out, bs), ret = btrfs_wait_ordered_range(BTRFS_I(inode_out), ALIGN_DOWN(pos_out, bs),
wb_len); wb_len);
if (ret < 0) if (ret < 0)
return ret; return ret;
......
...@@ -4149,7 +4149,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start) ...@@ -4149,7 +4149,7 @@ int btrfs_relocate_block_group(struct btrfs_fs_info *fs_info, u64 group_start)
* out of the loop if we hit an error. * out of the loop if we hit an error.
*/ */
if (rc->stage == MOVE_DATA_EXTENTS && rc->found_file_extent) { if (rc->stage == MOVE_DATA_EXTENTS && rc->found_file_extent) {
ret = btrfs_wait_ordered_range(rc->data_inode, 0, ret = btrfs_wait_ordered_range(BTRFS_I(rc->data_inode), 0,
(u64)-1); (u64)-1);
if (ret) if (ret)
err = ret; err = 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