|
@@ -7782,10 +7782,12 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- * this will cow the extent, reset the len in case we changed
|
|
|
|
- * it above
|
|
|
|
|
|
+ * this will cow the extent, if em is within [start, len], then
|
|
|
|
+ * probably we've found a preallocated/existing extent, let's
|
|
|
|
+ * give it a chance to use preallocated space.
|
|
*/
|
|
*/
|
|
- len = bh_result->b_size;
|
|
|
|
|
|
+ len = min_t(u64, bh_result->b_size, em->len - (start - em->start));
|
|
|
|
+ len = ALIGN(len, root->sectorsize);
|
|
free_extent_map(em);
|
|
free_extent_map(em);
|
|
em = btrfs_new_extent_direct(inode, start, len);
|
|
em = btrfs_new_extent_direct(inode, start, len);
|
|
if (IS_ERR(em)) {
|
|
if (IS_ERR(em)) {
|