btrfs: make can_nocow_extent nowait compatible
If we have NOWAIT specified on our IOCB and we're writing into a PREALLOC or NOCOW extent then we need to be able to tell can_nocow_extent that we don't want to wait on any locks or metadata IO. Fix can_nocow_extent to allow for NOWAIT. Reviewed-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Stefan Roesch <shr@fb.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
857bc13f85
commit
26ce911446
|
@ -3330,7 +3330,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
|
||||||
blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
|
blk_status_t btrfs_csum_one_bio(struct btrfs_inode *inode, struct bio *bio,
|
||||||
u64 offset, bool one_ordered);
|
u64 offset, bool one_ordered);
|
||||||
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
|
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
|
||||||
struct list_head *list, int search_commit);
|
struct list_head *list, int search_commit,
|
||||||
|
bool nowait);
|
||||||
void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
|
void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
|
||||||
const struct btrfs_path *path,
|
const struct btrfs_path *path,
|
||||||
struct btrfs_file_extent_item *fi,
|
struct btrfs_file_extent_item *fi,
|
||||||
|
@ -3358,7 +3359,7 @@ int btrfs_check_data_csum(struct inode *inode, struct btrfs_bio *bbio,
|
||||||
u32 bio_offset, struct page *page, u32 pgoff);
|
u32 bio_offset, struct page *page, u32 pgoff);
|
||||||
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
|
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
|
||||||
u64 *orig_start, u64 *orig_block_len,
|
u64 *orig_start, u64 *orig_block_len,
|
||||||
u64 *ram_bytes, bool strict);
|
u64 *ram_bytes, bool nowait, bool strict);
|
||||||
|
|
||||||
void __btrfs_del_delalloc_inode(struct btrfs_root *root,
|
void __btrfs_del_delalloc_inode(struct btrfs_root *root,
|
||||||
struct btrfs_inode *inode);
|
struct btrfs_inode *inode);
|
||||||
|
|
|
@ -2220,6 +2220,12 @@ static noinline int check_delayed_ref(struct btrfs_root *root,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mutex_trylock(&head->mutex)) {
|
if (!mutex_trylock(&head->mutex)) {
|
||||||
|
if (path->nowait) {
|
||||||
|
spin_unlock(&delayed_refs->lock);
|
||||||
|
btrfs_put_transaction(cur_trans);
|
||||||
|
return -EAGAIN;
|
||||||
|
}
|
||||||
|
|
||||||
refcount_inc(&head->refs);
|
refcount_inc(&head->refs);
|
||||||
spin_unlock(&delayed_refs->lock);
|
spin_unlock(&delayed_refs->lock);
|
||||||
|
|
||||||
|
|
|
@ -511,7 +511,8 @@ blk_status_t btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, u8 *dst
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
|
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
|
||||||
struct list_head *list, int search_commit)
|
struct list_head *list, int search_commit,
|
||||||
|
bool nowait)
|
||||||
{
|
{
|
||||||
struct btrfs_fs_info *fs_info = root->fs_info;
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
@ -533,6 +534,7 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
|
||||||
if (!path)
|
if (!path)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
path->nowait = nowait;
|
||||||
if (search_commit) {
|
if (search_commit) {
|
||||||
path->skip_locking = 1;
|
path->skip_locking = 1;
|
||||||
path->reada = READA_FORWARD;
|
path->reada = READA_FORWARD;
|
||||||
|
|
|
@ -1501,7 +1501,7 @@ int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
|
||||||
|
|
||||||
btrfs_lock_and_flush_ordered_range(inode, lockstart, lockend, NULL);
|
btrfs_lock_and_flush_ordered_range(inode, lockstart, lockend, NULL);
|
||||||
ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
|
ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
|
||||||
NULL, NULL, NULL, false);
|
NULL, NULL, NULL, false, false);
|
||||||
if (ret <= 0) {
|
if (ret <= 0) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
btrfs_drew_write_unlock(&root->snapshot_lock);
|
btrfs_drew_write_unlock(&root->snapshot_lock);
|
||||||
|
|
|
@ -1666,7 +1666,7 @@ static noinline int run_delalloc_zoned(struct btrfs_inode *inode,
|
||||||
}
|
}
|
||||||
|
|
||||||
static noinline int csum_exist_in_range(struct btrfs_fs_info *fs_info,
|
static noinline int csum_exist_in_range(struct btrfs_fs_info *fs_info,
|
||||||
u64 bytenr, u64 num_bytes)
|
u64 bytenr, u64 num_bytes, bool nowait)
|
||||||
{
|
{
|
||||||
struct btrfs_root *csum_root = btrfs_csum_root(fs_info, bytenr);
|
struct btrfs_root *csum_root = btrfs_csum_root(fs_info, bytenr);
|
||||||
struct btrfs_ordered_sum *sums;
|
struct btrfs_ordered_sum *sums;
|
||||||
|
@ -1674,7 +1674,8 @@ static noinline int csum_exist_in_range(struct btrfs_fs_info *fs_info,
|
||||||
LIST_HEAD(list);
|
LIST_HEAD(list);
|
||||||
|
|
||||||
ret = btrfs_lookup_csums_range(csum_root, bytenr,
|
ret = btrfs_lookup_csums_range(csum_root, bytenr,
|
||||||
bytenr + num_bytes - 1, &list, 0);
|
bytenr + num_bytes - 1, &list, 0,
|
||||||
|
nowait);
|
||||||
if (ret == 0 && list_empty(&list))
|
if (ret == 0 && list_empty(&list))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -1800,6 +1801,7 @@ static int can_nocow_file_extent(struct btrfs_path *path,
|
||||||
u8 extent_type;
|
u8 extent_type;
|
||||||
int can_nocow = 0;
|
int can_nocow = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
bool nowait = path->nowait;
|
||||||
|
|
||||||
fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item);
|
fi = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_file_extent_item);
|
||||||
extent_type = btrfs_file_extent_type(leaf, fi);
|
extent_type = btrfs_file_extent_type(leaf, fi);
|
||||||
|
@ -1876,7 +1878,8 @@ static int can_nocow_file_extent(struct btrfs_path *path,
|
||||||
* Force COW if csums exist in the range. This ensures that csums for a
|
* Force COW if csums exist in the range. This ensures that csums for a
|
||||||
* given extent are either valid or do not exist.
|
* given extent are either valid or do not exist.
|
||||||
*/
|
*/
|
||||||
ret = csum_exist_in_range(root->fs_info, args->disk_bytenr, args->num_bytes);
|
ret = csum_exist_in_range(root->fs_info, args->disk_bytenr, args->num_bytes,
|
||||||
|
nowait);
|
||||||
WARN_ON_ONCE(ret > 0 && is_freespace_inode);
|
WARN_ON_ONCE(ret > 0 && is_freespace_inode);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
@ -7167,7 +7170,7 @@ static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
|
||||||
*/
|
*/
|
||||||
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
|
noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
|
||||||
u64 *orig_start, u64 *orig_block_len,
|
u64 *orig_start, u64 *orig_block_len,
|
||||||
u64 *ram_bytes, bool strict)
|
u64 *ram_bytes, bool nowait, bool strict)
|
||||||
{
|
{
|
||||||
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
|
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
|
||||||
struct can_nocow_file_extent_args nocow_args = { 0 };
|
struct can_nocow_file_extent_args nocow_args = { 0 };
|
||||||
|
@ -7183,6 +7186,7 @@ noinline int can_nocow_extent(struct inode *inode, u64 offset, u64 *len,
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path)
|
if (!path)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
path->nowait = nowait;
|
||||||
|
|
||||||
ret = btrfs_lookup_file_extent(NULL, root, path,
|
ret = btrfs_lookup_file_extent(NULL, root, path,
|
||||||
btrfs_ino(BTRFS_I(inode)), offset, 0);
|
btrfs_ino(BTRFS_I(inode)), offset, 0);
|
||||||
|
@ -7452,7 +7456,7 @@ static int btrfs_get_blocks_direct_write(struct extent_map **map,
|
||||||
block_start = em->block_start + (start - em->start);
|
block_start = em->block_start + (start - em->start);
|
||||||
|
|
||||||
if (can_nocow_extent(inode, start, &len, &orig_start,
|
if (can_nocow_extent(inode, start, &len, &orig_start,
|
||||||
&orig_block_len, &ram_bytes, false) == 1) {
|
&orig_block_len, &ram_bytes, false, false) == 1) {
|
||||||
bg = btrfs_inc_nocow_writers(fs_info, block_start);
|
bg = btrfs_inc_nocow_writers(fs_info, block_start);
|
||||||
if (bg)
|
if (bg)
|
||||||
can_nocow = true;
|
can_nocow = true;
|
||||||
|
@ -11135,7 +11139,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
|
||||||
free_extent_map(em);
|
free_extent_map(em);
|
||||||
em = NULL;
|
em = NULL;
|
||||||
|
|
||||||
ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL, true);
|
ret = can_nocow_extent(inode, start, &len, NULL, NULL, NULL, false, true);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto out;
|
goto out;
|
||||||
} else if (ret) {
|
} else if (ret) {
|
||||||
|
|
|
@ -4339,7 +4339,7 @@ int btrfs_reloc_clone_csums(struct btrfs_inode *inode, u64 file_pos, u64 len)
|
||||||
disk_bytenr = file_pos + inode->index_cnt;
|
disk_bytenr = file_pos + inode->index_cnt;
|
||||||
csum_root = btrfs_csum_root(fs_info, disk_bytenr);
|
csum_root = btrfs_csum_root(fs_info, disk_bytenr);
|
||||||
ret = btrfs_lookup_csums_range(csum_root, disk_bytenr,
|
ret = btrfs_lookup_csums_range(csum_root, disk_bytenr,
|
||||||
disk_bytenr + len - 1, &list, 0);
|
disk_bytenr + len - 1, &list, 0, false);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -3229,7 +3229,7 @@ static int scrub_raid56_data_stripe_for_parity(struct scrub_ctx *sctx,
|
||||||
|
|
||||||
ret = btrfs_lookup_csums_range(csum_root, extent_start,
|
ret = btrfs_lookup_csums_range(csum_root, extent_start,
|
||||||
extent_start + extent_size - 1,
|
extent_start + extent_size - 1,
|
||||||
&sctx->csum_list, 1);
|
&sctx->csum_list, 1, false);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
scrub_parity_mark_sectors_error(sparity, extent_start,
|
scrub_parity_mark_sectors_error(sparity, extent_start,
|
||||||
extent_size);
|
extent_size);
|
||||||
|
@ -3455,7 +3455,7 @@ static int scrub_simple_mirror(struct scrub_ctx *sctx,
|
||||||
if (extent_flags & BTRFS_EXTENT_FLAG_DATA) {
|
if (extent_flags & BTRFS_EXTENT_FLAG_DATA) {
|
||||||
ret = btrfs_lookup_csums_range(csum_root, cur_logical,
|
ret = btrfs_lookup_csums_range(csum_root, cur_logical,
|
||||||
cur_logical + scrub_len - 1,
|
cur_logical + scrub_len - 1,
|
||||||
&sctx->csum_list, 1);
|
&sctx->csum_list, 1, false);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -801,7 +801,7 @@ static noinline int replay_one_extent(struct btrfs_trans_handle *trans,
|
||||||
|
|
||||||
ret = btrfs_lookup_csums_range(root->log_root,
|
ret = btrfs_lookup_csums_range(root->log_root,
|
||||||
csum_start, csum_end - 1,
|
csum_start, csum_end - 1,
|
||||||
&ordered_sums, 0);
|
&ordered_sums, 0, false);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
/*
|
/*
|
||||||
|
@ -4402,7 +4402,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
|
||||||
disk_bytenr += extent_offset;
|
disk_bytenr += extent_offset;
|
||||||
ret = btrfs_lookup_csums_range(csum_root, disk_bytenr,
|
ret = btrfs_lookup_csums_range(csum_root, disk_bytenr,
|
||||||
disk_bytenr + extent_num_bytes - 1,
|
disk_bytenr + extent_num_bytes - 1,
|
||||||
&ordered_sums, 0);
|
&ordered_sums, 0, false);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
@ -4598,7 +4598,7 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
|
||||||
ret = btrfs_lookup_csums_range(csum_root,
|
ret = btrfs_lookup_csums_range(csum_root,
|
||||||
em->block_start + csum_offset,
|
em->block_start + csum_offset,
|
||||||
em->block_start + csum_offset +
|
em->block_start + csum_offset +
|
||||||
csum_len - 1, &ordered_sums, 0);
|
csum_len - 1, &ordered_sums, 0, false);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue