em->block_start = merge->block_start;
merge->in_tree = 0;
if (merge->generation > em->generation) {
+ em->mod_start = em->start;
+ em->mod_len = em->len;
em->generation = merge->generation;
list_move(&em->list, &tree->modified_extents);
}
rb_erase(&merge->rb_node, &tree->map);
merge->in_tree = 0;
if (merge->generation > em->generation) {
+ em->mod_len = em->len;
em->generation = merge->generation;
list_move(&em->list, &tree->modified_extents);
}
{
int ret = 0;
struct extent_map *em;
+ bool prealloc = false;
write_lock(&tree->lock);
em = lookup_extent_mapping(tree, start, len);
list_move(&em->list, &tree->modified_extents);
em->generation = gen;
clear_bit(EXTENT_FLAG_PINNED, &em->flags);
+ em->mod_start = em->start;
+ em->mod_len = em->len;
+
+ if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) {
+ prealloc = true;
+ clear_bit(EXTENT_FLAG_PREALLOC, &em->flags);
+ }
try_merge_map(tree, em);
+
+ if (prealloc) {
+ em->mod_start = em->start;
+ em->mod_len = em->len;
+ }
+
free_extent_map(em);
out:
write_unlock(&tree->lock);
}
atomic_inc(&em->refs);
+ em->mod_start = em->start;
+ em->mod_len = em->len;
+
try_merge_map(tree, em);
out:
return ret;
em->block_start = disk_bytenr;
em->bdev = root->fs_info->fs_devices->latest_bdev;
set_bit(EXTENT_FLAG_PINNED, &em->flags);
+ set_bit(EXTENT_FLAG_PREALLOC, &em->flags);
while (1) {
write_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, em);
struct btrfs_root *log = root->log_root;
struct btrfs_file_extent_item *fi;
struct btrfs_key key;
- u64 start = em->start;
- u64 len = em->len;
+ u64 start = em->mod_start;
+ u64 len = em->mod_len;
u64 num_bytes;
int nritems;
int ret;
* sequential then we need to copy the items we have and redo
* our search
*/
- if (args.nr && em->start != args.next_offset) {
+ if (args.nr && em->mod_start != args.next_offset) {
ret = copy_items(trans, log, dst_path, args.src,
args.start_slot, args.nr,
LOG_INODE_ALL);