Commit d7400ee1 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: use the existing reserved items for our first prop for inheritance

We're now reserving an extra items worth of space for property
inheritance.  We only have one property at the moment so this covers us,
but if we add more in the future this will allow us to not get bitten by
the extra space reservation.  If we do add more properties in the future
we should re-visit how we calculate the space reservation needs by the
callers.
Reviewed-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
[ refreshed on top of prop/xattr cleanups ]
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 8fca9550
...@@ -332,6 +332,7 @@ static int inherit_props(struct btrfs_trans_handle *trans, ...@@ -332,6 +332,7 @@ static int inherit_props(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
int ret; int ret;
int i; int i;
bool need_reserve = false;
if (!test_bit(BTRFS_INODE_HAS_PROPS, if (!test_bit(BTRFS_INODE_HAS_PROPS,
&BTRFS_I(parent)->runtime_flags)) &BTRFS_I(parent)->runtime_flags))
...@@ -357,11 +358,20 @@ static int inherit_props(struct btrfs_trans_handle *trans, ...@@ -357,11 +358,20 @@ static int inherit_props(struct btrfs_trans_handle *trans,
if (ret) if (ret)
continue; continue;
num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1); /*
ret = btrfs_block_rsv_add(root, trans->block_rsv, * Currently callers should be reserving 1 item for properties,
num_bytes, BTRFS_RESERVE_NO_FLUSH); * since we only have 1 property that we currently support. If
if (ret) * we add more in the future we need to try and reserve more
return ret; * space for them. But we should also revisit how we do space
* reservations if we do add more properties in the future.
*/
if (need_reserve) {
num_bytes = btrfs_calc_trans_metadata_size(fs_info, 1);
ret = btrfs_block_rsv_add(root, trans->block_rsv,
num_bytes, BTRFS_RESERVE_NO_FLUSH);
if (ret)
return ret;
}
ret = btrfs_setxattr(trans, inode, h->xattr_name, value, ret = btrfs_setxattr(trans, inode, h->xattr_name, value,
strlen(value), 0); strlen(value), 0);
...@@ -375,9 +385,13 @@ static int inherit_props(struct btrfs_trans_handle *trans, ...@@ -375,9 +385,13 @@ static int inherit_props(struct btrfs_trans_handle *trans,
&BTRFS_I(inode)->runtime_flags); &BTRFS_I(inode)->runtime_flags);
} }
btrfs_block_rsv_release(fs_info, trans->block_rsv, num_bytes); if (need_reserve) {
if (ret) btrfs_block_rsv_release(fs_info, trans->block_rsv,
return ret; num_bytes);
if (ret)
return ret;
}
need_reserve = true;
} }
return 0; return 0;
......
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