Skip to content

Commit 50f1cff

Browse files
Christoph Hellwigkdave
authored andcommitted
btrfs: fix and document the zoned device choice in alloc_new_bio
Zone Append bios only need a valid block device in struct bio, but not the device in the btrfs_bio. Use the information from btrfs_zoned_get_device to set up bi_bdev and fix zoned writes on multi-device file system with non-homogeneous capabilities and remove the pointless btrfs_bio.device assignment. Add big fat comments explaining what is going on here. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 50ff578 commit 50f1cff

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

fs/btrfs/extent_io.c

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3334,24 +3334,37 @@ static int alloc_new_bio(struct btrfs_inode *inode,
33343334
ret = calc_bio_boundaries(bio_ctrl, inode, file_offset);
33353335
if (ret < 0)
33363336
goto error;
3337-
if (wbc) {
3338-
struct block_device *bdev;
33393337

3340-
bdev = fs_info->fs_devices->latest_dev->bdev;
3341-
bio_set_dev(bio, bdev);
3342-
wbc_init_bio(wbc, bio);
3343-
}
3344-
if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
3345-
struct btrfs_device *device;
3338+
if (wbc) {
3339+
/*
3340+
* For Zone append we need the correct block_device that we are
3341+
* going to write to set in the bio to be able to respect the
3342+
* hardware limitation. Look it up here:
3343+
*/
3344+
if (bio_op(bio) == REQ_OP_ZONE_APPEND) {
3345+
struct btrfs_device *dev;
3346+
3347+
dev = btrfs_zoned_get_device(fs_info, disk_bytenr,
3348+
fs_info->sectorsize);
3349+
if (IS_ERR(dev)) {
3350+
ret = PTR_ERR(dev);
3351+
goto error;
3352+
}
33463353

3347-
device = btrfs_zoned_get_device(fs_info, disk_bytenr,
3348-
fs_info->sectorsize);
3349-
if (IS_ERR(device)) {
3350-
ret = PTR_ERR(device);
3351-
goto error;
3354+
bio_set_dev(bio, dev->bdev);
3355+
} else {
3356+
/*
3357+
* Otherwise pick the last added device to support
3358+
* cgroup writeback. For multi-device file systems this
3359+
* means blk-cgroup policies have to always be set on the
3360+
* last added/replaced device. This is a bit odd but has
3361+
* been like that for a long time.
3362+
*/
3363+
bio_set_dev(bio, fs_info->fs_devices->latest_dev->bdev);
33523364
}
3353-
3354-
btrfs_bio(bio)->device = device;
3365+
wbc_init_bio(wbc, bio);
3366+
} else {
3367+
ASSERT(bio_op(bio) != REQ_OP_ZONE_APPEND);
33553368
}
33563369
return 0;
33573370
error:

0 commit comments

Comments
 (0)