Skip to content

Commit 04f0847

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: don't rely on unchanging ->bi_bdev for zone append remaps
btrfs_record_physical_zoned relies on a bio->bi_bdev samples in the bio_end_io handler to find the reverse map for remapping the zone append write, but stacked block device drivers can and usually do change bi_bdev when sending on the bio to a lower device. This can happen e.g. with the nvme-multipath driver when a NVMe SSD sets the shared namespace bit. But there is no real need for the bdev in btrfs_record_physical_zoned, as it is only passed to btrfs_rmap_block, which uses it to pick the mapping to report if there are multiple reverse mappings. As zone writes can only do simple non-mirror writes right now, and anything more complex will use the stripe tree there is no chance of the multiple mappings case actually happening. Instead open code the subset of btrfs_rmap_block in btrfs_record_physical_zoned, which also removes a memory allocation and remove the bdev field in the ordered extent. Fixes: d8e3fb1 ("btrfs: zoned: use ZONE_APPEND write for zoned mode") Reviewed-by: Josef Bacik <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent fdf9a37 commit 04f0847

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

fs/btrfs/inode.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,8 +3162,8 @@ int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
31623162
goto out;
31633163
}
31643164

3165-
/* A valid bdev implies a write on a sequential zone */
3166-
if (ordered_extent->bdev) {
3165+
/* A valid ->physical implies a write on a sequential zone. */
3166+
if (ordered_extent->physical != (u64)-1) {
31673167
btrfs_rewrite_logical_zoned(ordered_extent);
31683168
btrfs_zone_finish_endio(fs_info, ordered_extent->disk_bytenr,
31693169
ordered_extent->disk_num_bytes);

fs/btrfs/ordered-data.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,6 @@ struct btrfs_ordered_extent {
157157
* command in a workqueue context
158158
*/
159159
u64 physical;
160-
struct block_device *bdev;
161160
};
162161

163162
static inline void

fs/btrfs/zoned.c

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,8 +1676,6 @@ void btrfs_record_physical_zoned(struct btrfs_bio *bbio)
16761676
return;
16771677

16781678
ordered->physical = physical;
1679-
ordered->bdev = bbio->bio.bi_bdev;
1680-
16811679
btrfs_put_ordered_extent(ordered);
16821680
}
16831681

@@ -1689,43 +1687,46 @@ void btrfs_rewrite_logical_zoned(struct btrfs_ordered_extent *ordered)
16891687
struct extent_map *em;
16901688
struct btrfs_ordered_sum *sum;
16911689
u64 orig_logical = ordered->disk_bytenr;
1692-
u64 *logical = NULL;
1693-
int nr, stripe_len;
1690+
struct map_lookup *map;
1691+
u64 physical = ordered->physical;
1692+
u64 chunk_start_phys;
1693+
u64 logical;
16941694

1695-
/* Zoned devices should not have partitions. So, we can assume it is 0 */
1696-
ASSERT(!bdev_is_partition(ordered->bdev));
1697-
if (WARN_ON(!ordered->bdev))
1695+
em = btrfs_get_chunk_map(fs_info, orig_logical, 1);
1696+
if (IS_ERR(em))
16981697
return;
1698+
map = em->map_lookup;
1699+
chunk_start_phys = map->stripes[0].physical;
16991700

1700-
if (WARN_ON(btrfs_rmap_block(fs_info, orig_logical, ordered->bdev,
1701-
ordered->physical, &logical, &nr,
1702-
&stripe_len)))
1703-
goto out;
1704-
1705-
WARN_ON(nr != 1);
1701+
if (WARN_ON_ONCE(map->num_stripes > 1) ||
1702+
WARN_ON_ONCE((map->type & BTRFS_BLOCK_GROUP_PROFILE_MASK) != 0) ||
1703+
WARN_ON_ONCE(physical < chunk_start_phys) ||
1704+
WARN_ON_ONCE(physical > chunk_start_phys + em->orig_block_len)) {
1705+
free_extent_map(em);
1706+
return;
1707+
}
1708+
logical = em->start + (physical - map->stripes[0].physical);
1709+
free_extent_map(em);
17061710

1707-
if (orig_logical == *logical)
1708-
goto out;
1711+
if (orig_logical == logical)
1712+
return;
17091713

1710-
ordered->disk_bytenr = *logical;
1714+
ordered->disk_bytenr = logical;
17111715

17121716
em_tree = &inode->extent_tree;
17131717
write_lock(&em_tree->lock);
17141718
em = search_extent_mapping(em_tree, ordered->file_offset,
17151719
ordered->num_bytes);
1716-
em->block_start = *logical;
1720+
em->block_start = logical;
17171721
free_extent_map(em);
17181722
write_unlock(&em_tree->lock);
17191723

17201724
list_for_each_entry(sum, &ordered->list, list) {
1721-
if (*logical < orig_logical)
1722-
sum->bytenr -= orig_logical - *logical;
1725+
if (logical < orig_logical)
1726+
sum->bytenr -= orig_logical - logical;
17231727
else
1724-
sum->bytenr += *logical - orig_logical;
1728+
sum->bytenr += logical - orig_logical;
17251729
}
1726-
1727-
out:
1728-
kfree(logical);
17291730
}
17301731

17311732
bool btrfs_check_meta_write_pointer(struct btrfs_fs_info *fs_info,

0 commit comments

Comments
 (0)