@@ -3211,6 +3211,14 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
}
}
+ if (is_data) {
+ ret = btrfs_delete_raid_extent(trans, bytenr, num_bytes);
+ if (ret) {
+ btrfs_abort_transaction(trans, ret);
+ return ret;
+ }
+ }
+
ret = btrfs_del_items(trans, extent_root, path, path->slots[0],
num_to_del);
if (ret) {
@@ -109,6 +109,37 @@ void btrfs_put_ordered_stripe(struct btrfs_fs_info *fs_info,
mutex_unlock(&fs_info->stripe_update_lock);
}
+int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start,
+ u64 length)
+{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
+ struct btrfs_root *stripe_root = fs_info->stripe_root;
+ struct btrfs_path *path;
+ struct btrfs_key stripe_key;
+ int ret;
+
+ if (!stripe_root)
+ return 0;
+
+ stripe_key.objectid = start;
+ stripe_key.type = BTRFS_RAID_STRIPE_KEY;
+ stripe_key.offset = length;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ ret = btrfs_search_slot(trans, stripe_root, &stripe_key, path, -1, 1);
+ if (ret < 0)
+ goto out;
+
+ ret = btrfs_del_item(trans, stripe_root, path);
+out:
+ btrfs_free_path(path);
+ return ret;
+
+}
+
int btrfs_insert_preallocated_raid_stripe(struct btrfs_fs_info *fs_info,
u64 start, u64 len)
{
@@ -16,6 +16,8 @@ struct btrfs_ordered_stripe {
refcount_t ref;
};
+int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start,
+ u64 length);
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,
As each stripe extent is tied to an extent item, delete the stripe extent once the corresponding extent item is deleted. Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> --- fs/btrfs/extent-tree.c | 8 ++++++++ fs/btrfs/raid-stripe-tree.c | 31 +++++++++++++++++++++++++++++++ fs/btrfs/raid-stripe-tree.h | 2 ++ 3 files changed, 41 insertions(+)