Use the stream count reported by the data and realtime block devices where they have one, falling back to the geometry-derived count. The count is capped at the group count so that every stream backs onto at least one group; a device with more streams than the filesystem groups loses the excess, so mkfs should create at least as many groups as the device has streams. It is also capped at U8_MAX, the most streams the block layer can tag. Set iomap->write_stream from the inode so that the id reaches the device, but only when the device has write streams. Signed-off-by: Kanchan Joshi Signed-off-by: Anuj Gupta --- fs/xfs/xfs_buf.c | 8 +++++++- fs/xfs/xfs_iomap.c | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fs/xfs/xfs_buf.c b/fs/xfs/xfs_buf.c index d8ce03a9f49c..41c543e132cb 100644 --- a/fs/xfs/xfs_buf.c +++ b/fs/xfs/xfs_buf.c @@ -1711,8 +1711,14 @@ xfs_buftarg_init_streams( unsigned int nr_groups) { unsigned int nr_streams; + unsigned int hw_streams; - nr_streams = xfs_sw_write_stream_count(nr_groups); + hw_streams = bdev_max_write_streams(btp->bt_bdev); + if (hw_streams) + nr_streams = min3(hw_streams, nr_groups, + XFS_MAX_WRITE_STREAMS); + else + nr_streams = xfs_sw_write_stream_count(nr_groups); return write_stream_pool_init(&btp->bt_stream_pool, nr_streams); } diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 329c745e3120..f0d191891a06 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -144,6 +144,11 @@ xfs_bmbt_to_iomap( } iomap->offset = XFS_FSB_TO_B(mp, imap->br_startoff); iomap->length = XFS_FSB_TO_B(mp, imap->br_blockcount); + /* software stream ids must not reach a device without streams */ + if (bdev_max_write_streams(target->bt_bdev)) + iomap->write_stream = READ_ONCE(VFS_I(ip)->i_write_stream); + else + iomap->write_stream = WRITE_STREAM_NOT_SET; if (mapping_flags & IOMAP_DAX) { iomap->dax_dev = target->bt_daxdev; } else { -- 2.25.1