@@ -158,6 +158,40 @@ static int update_raid_extent_item(struct btrfs_trans_handle *trans,
return ret;
}
+int btrfs_insert_dummy_raid_extent(struct btrfs_trans_handle *trans,
+ u64 logical, u64 length)
+{
+ struct btrfs_fs_info *fs_info = trans->fs_info;
+ struct btrfs_key stripe_key;
+ struct btrfs_root *stripe_root = fs_info->stripe_root;
+ struct btrfs_path *path;
+ int ret;
+
+ path = btrfs_alloc_path();
+ if (!path)
+ return -ENOMEM;
+
+ stripe_key.objectid = logical;
+ stripe_key.type = BTRFS_RAID_STRIPE_DUMMY_KEY;
+ stripe_key.offset = length;
+
+ ret = btrfs_insert_empty_item(trans, stripe_root, path, &stripe_key, 0);
+ if (ret == -EEXIST) {
+ struct extent_buffer *leaf = path->nodes[0];
+ int slot = path->slots[0];
+ struct btrfs_key found_key;
+
+ btrfs_item_key_to_cpu(leaf, &found_key, slot);
+ found_key.objectid = logical;
+ found_key.offset = length;
+ btrfs_mark_buffer_dirty(trans, leaf);
+ ret = 0;
+ }
+ btrfs_free_path(path);
+
+ return ret;
+}
+
static int btrfs_insert_one_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_io_context *bioc)
{
@@ -305,6 +339,15 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
if (end > found_end)
*length -= end - found_end;
+ /*
+ * If we have a BTRFS_RAID_STRIPE_DUMMY_KEY it means we've hit
+ * an entry for a preallocated extent. Noone will ever check
+ * the physical, only logical and length, so we're good to
+ * bail out from here.
+ */
+ if (found_key.type == BTRFS_RAID_STRIPE_DUMMY_KEY)
+ goto out;
+
num_stripes = btrfs_num_raid_stripes(btrfs_item_size(leaf, slot));
stripe_extent = btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent);
@@ -27,6 +27,8 @@ int btrfs_get_raid_extent_offset(struct btrfs_fs_info *fs_info,
u32 stripe_index, struct btrfs_io_stripe *stripe);
int btrfs_insert_raid_extent(struct btrfs_trans_handle *trans,
struct btrfs_ordered_extent *ordered_extent);
+int btrfs_insert_dummy_raid_extent(struct btrfs_trans_handle *trans,
+ u64 logical, u64 length);
static inline bool btrfs_need_stripe_tree_update(struct btrfs_fs_info *fs_info,
u64 map_type)
@@ -281,6 +281,7 @@
#define BTRFS_CHUNK_ITEM_KEY 228
#define BTRFS_RAID_STRIPE_KEY 230
+#define BTRFS_RAID_STRIPE_DUMMY_KEY 231
/*
* Records the overall state of the qgroups.