Skip to content

Commit

Permalink
Fix incorrect deletion order in range_tree_add_impl gap case
Browse files Browse the repository at this point in the history
After a side-effectful call like add or remove, references to range 
segs stored in btrees can no longer be used safely.  We move the 
remove call to just before the reinsertion call so that the seg 
remains valid for as long as we need it.

Reviewed-by: Matthew Ahrens <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Paul Dagnelie <[email protected]>
Closes #11044 
Closes #11056
  • Loading branch information
pcd1193182 authored Oct 14, 2020
1 parent 47a7e99 commit 6a60ef8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion module/zfs/range_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ range_tree_add_impl(void *arg, uint64_t start, uint64_t size, uint64_t fill)
return;
}

zfs_btree_remove(&rt->rt_root, rs);
if (rt->rt_ops != NULL && rt->rt_ops->rtop_remove != NULL)
rt->rt_ops->rtop_remove(rt, rs, rt->rt_arg);

Expand All @@ -326,6 +325,7 @@ range_tree_add_impl(void *arg, uint64_t start, uint64_t size, uint64_t fill)
end = MAX(end, rend);
size = end - start;

zfs_btree_remove(&rt->rt_root, rs);
range_tree_add_impl(rt, start, size, fill);
return;
}
Expand Down

0 comments on commit 6a60ef8

Please sign in to comment.