From: Anuj Gupta Enable write streams on non-zoned realtime volumes that have realtime groups, partitioning RTGs among the streams as the AG side does. Stream based RTG selection applies to the first allocation of a file; later ones keep using the adjacent-allocation hint so the file stays contiguous. Directory with realtime inherit flag reports and allocates from the realtime pool, so that streams queried or allocated through a directory can be used for the files created in it. Signed-off-by: Anuj Gupta Signed-off-by: Kanchan Joshi --- fs/xfs/xfs_ioctl.c | 24 ++++++++++++++++++++---- fs/xfs/xfs_rtalloc.c | 28 ++++++++++++++++++++++++++++ fs/xfs/xfs_super.c | 7 +++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 48195143b812..5c07c6eb7cce 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -560,7 +560,8 @@ xfs_ioctl_setattr_xflags( /* refuse a filestream/realtime flag change while a stream is attached */ if (READ_ONCE(VFS_I(ip)->i_write_stream) && - ((fa->fsx_xflags & FS_XFLAG_FILESTREAM) || rtflag)) + ((fa->fsx_xflags & FS_XFLAG_FILESTREAM) || + rtflag != XFS_IS_REALTIME_INODE(ip))) return -EINVAL; if (rtflag != XFS_IS_REALTIME_INODE(ip)) { @@ -1442,17 +1443,32 @@ xfs_ioc_free_eofblocks( return xfs_blockgc_free_space(mp, &icw); } -/* Pool for the data of @inode, or NULL if it cannot use write streams. */ +/* + * Pool for the data of @inode, or NULL if it cannot use write streams. A + * directory that passes the realtime flag on to new files uses the realtime + * pool, so that streams allocated through it can be set on those files. + */ static struct write_stream_pool * xfs_write_stream_pool( struct inode *inode) { struct xfs_inode *ip = XFS_I(inode); + struct xfs_mount *mp = ip->i_mount; struct write_stream_pool *pool = NULL; + bool rt; xfs_ilock(ip, XFS_ILOCK_SHARED); - if (!xfs_inode_is_filestream(ip) && !XFS_IS_REALTIME_INODE(ip)) - pool = &ip->i_mount->m_ddev_targp->bt_stream_pool; + if (xfs_inode_is_filestream(ip)) + goto out_unlock; + + rt = XFS_IS_REALTIME_INODE(ip) || + (S_ISDIR(inode->i_mode) && + (ip->i_diflags & XFS_DIFLAG_RTINHERIT) && mp->m_rtdev_targp); + if (!rt) + pool = &mp->m_ddev_targp->bt_stream_pool; + else if (!xfs_has_zoned(mp)) + pool = &mp->m_rtdev_targp->bt_stream_pool; +out_unlock: xfs_iunlock(ip, XFS_ILOCK_SHARED); return pool; } diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c index 84efe5a8fb11..c7c3098182bb 100644 --- a/fs/xfs/xfs_rtalloc.c +++ b/fs/xfs/xfs_rtalloc.c @@ -2160,6 +2160,29 @@ xfs_rtallocate_align( return 0; } +static xfs_rtblock_t +xfs_bmap_write_stream_rtbno( + struct xfs_inode *ip, + unsigned int stream_id) +{ + struct xfs_mount *mp = ip->i_mount; + unsigned int nr_rtgs = mp->m_sb.sb_rgcount; + unsigned int nr_streams = + write_stream_pool_count(&mp->m_rtdev_targp->bt_stream_pool); + unsigned int set_size = nr_rtgs / nr_streams; + xfs_rgnumber_t start_rgno, target_rgno; + xfs_ino_t ino = I_INO(ip); + + stream_id -= 1; /* convert from 1-based to 0-based */ + start_rgno = stream_id * set_size; + if (stream_id == nr_streams - 1) + set_size = nr_rtgs - start_rgno; + target_rgno = start_rgno + do_div(ino, set_size); + + return (xfs_rtblock_t)target_rgno << + mp->m_groups[XG_TYPE_RTG].blklog; +} + int xfs_bmap_rtalloc( struct xfs_bmalloca *ap) @@ -2174,10 +2197,13 @@ xfs_bmap_rtalloc( bool noalign = false; bool initial_user_data = ap->datatype & XFS_ALLOC_INITIAL_USER_DATA; + unsigned int stream_id; int error; ASSERT(!xfs_has_zoned(ap->tp->t_mountp)); + stream_id = READ_ONCE(VFS_I(ap->ip)->i_write_stream); + retry: error = xfs_rtallocate_align(ap, &ralen, &raminlen, &prod, &noalign); if (error) @@ -2185,6 +2211,8 @@ xfs_bmap_rtalloc( if (xfs_bmap_adjacent(ap)) bno_hint = ap->blkno; + else if (stream_id && xfs_has_rtgroups(ap->ip->i_mount)) + bno_hint = xfs_bmap_write_stream_rtbno(ap->ip, stream_id); if (xfs_has_rtgroups(ap->ip->i_mount)) { error = xfs_rtallocate_rtgs(ap->tp, bno_hint, raminlen, ralen, diff --git a/fs/xfs/xfs_super.c b/fs/xfs/xfs_super.c index a541e97b580f..0a0a08eb3eb1 100644 --- a/fs/xfs/xfs_super.c +++ b/fs/xfs/xfs_super.c @@ -637,6 +637,13 @@ xfs_setup_devices( if (error) return error; xfs_update_bdi_rahead(mp); + + if (xfs_has_rtgroups(mp) && !xfs_has_zoned(mp)) { + error = xfs_buftarg_init_streams(mp->m_rtdev_targp, + mp->m_sb.sb_rgcount); + if (error) + return error; + } } return 0; -- 2.25.1