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: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
[ refreshed on top of prop/xattr cleanups ]
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Josef Bacik 2019-04-26 16:25:50 +02:00 коммит произвёл David Sterba
Родитель 8fca955057
Коммит d7400ee1b4
1 изменённых файлов: 22 добавлений и 8 удалений

Просмотреть файл

@ -332,6 +332,7 @@ static int inherit_props(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = root->fs_info;
int ret;
int i;
bool need_reserve = false;
if (!test_bit(BTRFS_INODE_HAS_PROPS,
&BTRFS_I(parent)->runtime_flags))
@ -357,11 +358,20 @@ static int inherit_props(struct btrfs_trans_handle *trans,
if (ret)
continue;
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;
/*
* Currently callers should be reserving 1 item for properties,
* since we only have 1 property that we currently support. If
* we add more in the future we need to try and reserve more
* 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,
strlen(value), 0);
@ -375,9 +385,13 @@ static int inherit_props(struct btrfs_trans_handle *trans,
&BTRFS_I(inode)->runtime_flags);
}
btrfs_block_rsv_release(fs_info, trans->block_rsv, num_bytes);
if (ret)
return ret;
if (need_reserve) {
btrfs_block_rsv_release(fs_info, trans->block_rsv,
num_bytes);
if (ret)
return ret;
}
need_reserve = true;
}
return 0;