@@ -1608,9 +1608,6 @@ static int btrfs_discard_extent(struct btrfs_root *root, u64 bytenr,
struct btrfs_bio_stripe *stripe = multi->stripes;
int i;
- if (map_length > num_bytes)
- map_length = num_bytes;
-
for (i = 0; i < multi->num_stripes; i++, stripe++) {
btrfs_issue_discard(stripe->dev->bdev,
stripe->physical,
@@ -1402,20 +1402,19 @@ int btrfs_merge_bio_hook(struct page *page, unsigned long offset,
struct btrfs_root *root = BTRFS_I(page->mapping->host)->root;
struct btrfs_mapping_tree *map_tree;
u64 logical = (u64)bio->bi_sector << 9;
- u64 length = 0;
+ u64 length = bio->bi_size + size;
u64 map_length;
int ret;
if (bio_flags & EXTENT_BIO_COMPRESSED)
return 0;
- length = bio->bi_size;
map_tree = &root->fs_info->mapping_tree;
map_length = length;
ret = btrfs_map_block(map_tree, READ, logical,
&map_length, NULL, 0);
- if (map_length < length + size)
+ if (ret || map_length < length)
return 1;
return 0;
}
@@ -2711,14 +2711,15 @@ again:
/* stripe_offset is the offset of this block in its stripe*/
stripe_offset = offset - stripe_offset;
+ /* return smaller of input length or remaining contiguous length */
if (map->type & (BTRFS_BLOCK_GROUP_RAID0 |
BTRFS_BLOCK_GROUP_RAID10)) {
- /* we limit the length of each bio to what fits in a stripe */
- *length = min_t(u64, em->len - offset,
- map->stripe_len - stripe_offset);
+ /* only the length that fits in one stripe is contiguous */
+ *length = min(*length, min_t(u64, em->len - offset,
+ map->stripe_len - stripe_offset));
} else {
/* RAID1, DUP, and simple disk stripes are all contiguous */
- *length = em->len - offset;
+ *length = min(*length, em->len - offset);
}
if (!multi_ret && !unplug_page)