Commit 98686ffc authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: simplify code flow in btrfs_delayed_inode_reserve_metadata

btrfs_block_rsv_add can return only ENOSPC since it's called with
NO_FLUSH modifier. This so simplify the logic in
btrfs_delayed_inode_reserve_metadata to exploit this invariant.
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
[ add assert and comment ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8e3c9d3c
...@@ -632,29 +632,14 @@ static int btrfs_delayed_inode_reserve_metadata( ...@@ -632,29 +632,14 @@ static int btrfs_delayed_inode_reserve_metadata(
return ret; return ret;
ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes, ret = btrfs_block_rsv_add(root, dst_rsv, num_bytes,
BTRFS_RESERVE_NO_FLUSH); BTRFS_RESERVE_NO_FLUSH);
/* /* NO_FLUSH could only fail with -ENOSPC */
* Since we're under a transaction reserve_metadata_bytes could ASSERT(ret == 0 || ret == -ENOSPC);
* try to commit the transaction which will make it return if (ret)
* EAGAIN to make us stop the transaction we have, so return
* ENOSPC instead so that btrfs_dirty_inode knows what to do.
*/
if (ret == -EAGAIN) {
ret = -ENOSPC;
btrfs_qgroup_free_meta_prealloc(root, num_bytes); btrfs_qgroup_free_meta_prealloc(root, num_bytes);
}
if (!ret) {
node->bytes_reserved = num_bytes;
trace_btrfs_space_reservation(fs_info,
"delayed_inode",
node->inode_id,
num_bytes, 1);
} else { } else {
btrfs_qgroup_free_meta_prealloc(root, num_bytes); ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes, true);
}
return ret;
} }
ret = btrfs_block_rsv_migrate(src_rsv, dst_rsv, num_bytes, true);
if (!ret) { if (!ret) {
trace_btrfs_space_reservation(fs_info, "delayed_inode", trace_btrfs_space_reservation(fs_info, "delayed_inode",
node->inode_id, num_bytes, 1); node->inode_id, num_bytes, 1);
......
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