@@ -55,6 +55,7 @@
#include "zoned.h"
#include "subpage.h"
#include "inode-item.h"
+#include "raid-stripe-tree.h"
struct btrfs_iget_args {
u64 ino;
@@ -9901,6 +9902,11 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent(
if (qgroup_released < 0)
return ERR_PTR(qgroup_released);
+ ret = btrfs_insert_preallocated_raid_stripe(inode->root->fs_info,
+ start, len);
+ if (ret)
+ goto free_qgroup;
+
if (trans) {
ret = insert_reserved_file_extent(trans, inode,
file_offset, &stack_fi,
@@ -124,6 +124,40 @@ void btrfs_remove_ordered_stripe(struct btrfs_fs_info *fs_info,
kfree(stripe);
}
+int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info,
+ u64 start, u64 len)
+{
+ struct btrfs_io_context *bioc = NULL;
+ struct btrfs_ordered_stripe *stripe;
+ u64 map_length = len;
+ int ret;
+
+ if (!fs_info->stripe_root)
+ return 0;
+
+ ret = btrfs_map_block(fs_info, BTRFS_MAP_WRITE, start, &map_length,
+ &bioc, 0);
+ if (ret)
+ return ret;
+
+ stripe = btrfs_lookup_ordered_stripe(fs_info, start);
+ if (!stripe) {
+ stripe = btrfs_add_ordered_stripe(fs_info, start, len,
+ bioc->num_stripes,
+ bioc->stripes);
+ if (IS_ERR(stripe))
+ return PTR_ERR(stripe);
+ } else {
+ spin_lock(&stripe->lock);
+ memcpy(stripe->stripes, bioc->stripes,
+ bioc->num_stripes * sizeof(struct btrfs_io_stripe));
+ spin_unlock(&stripe->lock);
+ btrfs_put_ordered_stripe(fs_info, stripe);
+ }
+
+ return 0;
+}
+
int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_ordered_stripe *stripe)
{
@@ -18,6 +18,8 @@ struct btrfs_ordered_stripe {
int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_ordered_stripe *stripe);
+int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info,
+ u64 start, u64 len);
void btrfs_raid_stripe_update(struct work_struct *work);
struct btrfs_ordered_stripe *btrfs_lookup_ordered_stripe(
struct btrfs_fs_info *fs_info,
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> --- fs/btrfs/inode.c | 6 ++++++ fs/btrfs/raid-stripe-tree.c | 34 ++++++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 2 ++ 3 files changed, 42 insertions(+)