cleanup buftarg lookup
Hi all,
this series merges our two helpers to look up the data device for a given file, and uses that helper in a few more places.
PATCH 1/3 xfs: add a xfs_inode_buftarg helper
Add a new xfs_inode_buftarg helper that gets the data I/O buftarg for a given inode. Replace the existing xfs_find_bdev_for_inode and xfs_find_daxdev_for_inode helpers with this new general one and cleanup some of the callers.
--- fs/xfs/xfs_aops.c | 34 +++++----------------------------- fs/xfs/xfs_aops.h | 3 --- fs/xfs/xfs_bmap_util.c | 15 ++++++++------- fs/xfs/xfs_file.c | 14 +++++++------- fs/xfs/xfs_inode.h | 7 +++++++ fs/xfs/xfs_ioctl.c | 7 +++---- fs/xfs/xfs_iomap.c | 11 +++++++---- fs/xfs/xfs_iops.c | 2 +- 8 files changed, 38 insertions(+), 55 deletions(-)
fs/xfs/xfs_aops.c +5 -29
@@ -30,32 +30,6 @@ XFS_WPC(struct iomap_writepage_ctx *ctx) return container_of(ctx, struct xfs_writepage_ctx, ctx); } -struct block_device * -xfs_find_bdev_for_inode ( -struct inode *inode) -{ -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; - -if (XFS_IS_REALTIME_INODE (ip)) -return mp->m_rtdev_targp->bt_bdev; -else -return mp->m_ddev_targp->bt_bdev; -} - -struct dax_device * -xfs_find_daxdev_for_inode ( -struct inode *inode) -{ -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; - -if (XFS_IS_REALTIME_INODE (ip)) -return mp->m_rtdev_targp->bt_daxdev; -else -return mp->m_ddev_targp->bt_daxdev; -} -/* * Fast and loose check if this write could update the on-disk inode size. */
@@ -609,9 +583,11 @@ xfs_dax_writepages(struct address_space *mapping, struct writeback_control *wbc) { - xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED); + struct xfs_inode *ip = XFS_I(mapping->host); + +xfs_iflags_clear (ip,XFS_ITRUNCATED );return dax_writeback_mapping_range (mapping, -xfs_find_bdev_for_inode (mapping->host), wbc); +xfs_inode_buftarg (ip)->bt_bdev, wbc); }STATIC sector_t
@@ -661,7 +637,7 @@ xfs_iomap_swapfile_activate(struct file *swap_file, sector_t *span) { - sis->bdev = xfs_find_bdev_for_inode(file_inode(swap_file)); + sis->bdev = xfs_inode_buftarg(XFS_I(file_inode(swap_file)))->bt_bdev;return iomap_swapfile_activate (sis, swap_file, span, &xfs_read_iomap_ops); }
fs/xfs/xfs_aops.h +0 -3
@@ -11,7 +11,4 @@ extern const struct address_space_operations xfs_dax_aops;int xfs_setfilesize (struct xfs_inode *ip,xfs_off_t offset,size_t size); -extern struct block_device *xfs_find_bdev_for_inode (struct inode *); -extern struct dax_device *xfs_find_daxdev_for_inode (struct inode *); -#endif /* __XFS_AOPS_H__ */
fs/xfs/xfs_bmap_util.c +8 -7
@@ -53,15 +53,16 @@ xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb)*/ int xfs_zero_extent ( -struct xfs_inode *ip, -xfs_fsblock_t start_fsb, -xfs_off_t count_fsb) +struct xfs_inode *ip, +xfs_fsblock_t start_fsb, +xfs_off_t count_fsb) { -struct xfs_mount *mp = ip->i_mount; -xfs_daddr_t sector =xfs_fsb_to_db (ip, start_fsb); -sector_t block =XFS_BB_TO_FSBT (mp, sector); +struct xfs_mount *mp = ip->i_mount; +struct xfs_buftarg *target =xfs_inode_buftarg (ip); +xfs_daddr_t sector =xfs_fsb_to_db (ip, start_fsb); +sector_t block =XFS_BB_TO_FSBT (mp, sector); -return blkdev_issue_zeroout (xfs_find_bdev_for_inode (VFS_I (ip)), +return blkdev_issue_zeroout (target->bt_bdev, block << (mp->m_super->s_blocksize_bits -9 ), count_fsb << (mp->m_super->s_blocksize_bits -9 ),GFP_NOFS ,0 );
fs/xfs/xfs_file.c +7 -7
@@ -1229,22 +1229,22 @@ static const struct vm_operations_struct xfs_file_vm_ops = { STATIC intxfs_file_mmap ( -struct file *filp, -struct vm_area_struct *vma) +struct file *file, +struct vm_area_struct *vma) { -struct dax_device *dax_dev; +struct inode *inode =file_inode (file); +struct xfs_buftarg *target =xfs_inode_buftarg (XFS_I (inode)); - dax_dev =xfs_find_daxdev_for_inode (file_inode (filp));/* * We don't support synchronous mappings for non-DAX files and * for DAX files if underneath dax_device is not synchronous. */ -if (!daxdev_mapping_supported (vma, dax_dev)) +if (!daxdev_mapping_supported (vma, target->bt_daxdev))return -EOPNOTSUPP ; -file_accessed (filp); +file_accessed (file); vma->vm_ops = &xfs_file_vm_ops; -if (IS_DAX (file_inode (filp))) +if (IS_DAX (inode)) vma->vm_flags |=VM_HUGEPAGE ;return 0 ; }
fs/xfs/xfs_inode.h +7 -0
@@ -219,6 +219,13 @@ static inline bool xfs_inode_has_cow_data(struct xfs_inode *ip)return ip->i_cowfp && ip->i_cowfp->if_bytes; } +/* +* Return the buftarg used for data allocations on a given inode. +*/ +#define xfs_inode_buftarg (ip) \ + (XFS_IS_REALTIME_INODE(ip) ? \ + (ip)->i_mount->m_rtdev_targp : (ip)->i_mount->m_ddev_targp) +/* * In-core inode flags. */
fs/xfs/xfs_ioctl.c +3 -4
@@ -1311,10 +1311,9 @@ xfs_ioctl_setattr_dax_invalidate(* have to check the device for dax support or flush pagecache. */ if (fa->fsx_xflags &FS_XFLAG_DAX ) { -if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) -return -EINVAL ; -if (!bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), - sb->s_blocksize)) +struct xfs_buftarg *target =xfs_inode_buftarg (ip); + +if (!bdev_dax_supported (target->bt_bdev, sb->s_blocksize))return -EINVAL ; }
fs/xfs/xfs_iomap.c +7 -4
@@ -57,6 +57,7 @@ xfs_bmbt_to_iomap( u16 flags) {struct xfs_mount *mp = ip->i_mount; +struct xfs_buftarg *target =xfs_inode_buftarg (ip);if (unlikely (!xfs_valid_startblock (ip, imap->br_startblock)))return xfs_alert_fsblock_zero (ip, imap);
@@ -77,8 +78,8 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); - iomap->bdev =xfs_find_bdev_for_inode (VFS_I (ip)); - iomap->dax_dev =xfs_find_daxdev_for_inode (VFS_I (ip)); + iomap->bdev = target->bt_bdev; + iomap->dax_dev = target->bt_daxdev; iomap->flags = flags; if (xfs_ipincount(ip) &&
@@ -94,12 +95,14 @@ xfs_hole_to_iomap( xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb) { +struct xfs_buftarg *target =xfs_inode_buftarg (ip); + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_HOLE ; iomap->offset =XFS_FSB_TO_B (ip->i_mount, offset_fsb); iomap->length =XFS_FSB_TO_B (ip->i_mount, end_fsb - offset_fsb); - iomap->bdev =xfs_find_bdev_for_inode (VFS_I (ip)); - iomap->dax_dev =xfs_find_daxdev_for_inode (VFS_I (ip)); + iomap->bdev = target->bt_bdev; + iomap->dax_dev = target->bt_daxdev; } static inline xfs_fileoff_t
fs/xfs/xfs_iops.c +1 -1
@@ -1227,7 +1227,7 @@ xfs_inode_supports_dax(return false;/* Device has to support DAX too. */ -return xfs_find_daxdev_for_inode (VFS_I (ip)) !=NULL ; +return xfs_inode_buftarg (ip)->bt_daxdev !=NULL ; }STATIC void
Signature · 1 line
2.20.1
Re: [PATCH 1/3] xfs: add a xfs_inode_buftarg helper
Quoted 6 lines · Christoph Hellwig
Add a new
xfs_inode_buftarghelper that gets the data I/O buftarg for a given inode. Replace the existingxfs_find_bdev_for_inodeandxfs_find_daxdev_for_inodehelpers with this new general one and cleanup some of the callers.Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
--D
Quoted 168 lines
--- fs/xfs/xfs_aops.c | 34 +++++----------------------------- fs/xfs/xfs_aops.h | 3 --- fs/xfs/xfs_bmap_util.c | 15 ++++++++------- fs/xfs/xfs_file.c | 14 +++++++------- fs/xfs/xfs_inode.h | 7 +++++++ fs/xfs/xfs_ioctl.c | 7 +++---- fs/xfs/xfs_iomap.c | 11 +++++++---- fs/xfs/xfs_iops.c | 2 +- 8 files changed, 38 insertions(+), 55 deletions(-)fs/xfs/xfs_aops.c +5
-29@@ -30,32 +30,6 @@ XFS_WPC(struct iomap_writepage_ctx *ctx) return container_of(ctx, struct xfs_writepage_ctx, ctx); } -struct block_device * -xfs_find_bdev_for_inode ( -struct inode *inode) -{ -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; - -if (XFS_IS_REALTIME_INODE (ip)) -return mp->m_rtdev_targp->bt_bdev; -else -return mp->m_ddev_targp->bt_bdev; -} - -struct dax_device * -xfs_find_daxdev_for_inode ( -struct inode *inode) -{ -struct xfs_inode *ip =XFS_I (inode); -struct xfs_mount *mp = ip->i_mount; - -if (XFS_IS_REALTIME_INODE (ip)) -return mp->m_rtdev_targp->bt_daxdev; -else -return mp->m_ddev_targp->bt_daxdev; -} -/* * Fast and loose check if this write could update the on-disk inode size. */ @@ -609,9 +583,11 @@ xfs_dax_writepages(struct address_space *mapping, struct writeback_control *wbc) { - xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED); + struct xfs_inode *ip = XFS_I(mapping->host); + +xfs_iflags_clear (ip,XFS_ITRUNCATED );return dax_writeback_mapping_range (mapping, -xfs_find_bdev_for_inode (mapping->host), wbc); +xfs_inode_buftarg (ip)->bt_bdev, wbc); }STATIC sector_t@@ -661,7 +637,7 @@ xfs_iomap_swapfile_activate(struct file *swap_file, sector_t *span) { - sis->bdev = xfs_find_bdev_for_inode(file_inode(swap_file)); + sis->bdev = xfs_inode_buftarg(XFS_I(file_inode(swap_file)))->bt_bdev;return iomap_swapfile_activate (sis, swap_file, span, &xfs_read_iomap_ops); }fs/xfs/xfs_aops.h +0
-3@@ -11,7 +11,4 @@ extern const struct address_space_operations xfs_dax_aops;int xfs_setfilesize (struct xfs_inode *ip,xfs_off_t offset,size_t size); -extern struct block_device *xfs_find_bdev_for_inode (struct inode *); -extern struct dax_device *xfs_find_daxdev_for_inode (struct inode *); -#endif /* __XFS_AOPS_H__ */ fs/xfs/xfs_bmap_util.c +8
-7@@ -53,15 +53,16 @@ xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb)*/ int xfs_zero_extent ( -struct xfs_inode *ip, -xfs_fsblock_t start_fsb, -xfs_off_t count_fsb) +struct xfs_inode *ip, +xfs_fsblock_t start_fsb, +xfs_off_t count_fsb) { -struct xfs_mount *mp = ip->i_mount; -xfs_daddr_t sector =xfs_fsb_to_db (ip, start_fsb); -sector_t block =XFS_BB_TO_FSBT (mp, sector); +struct xfs_mount *mp = ip->i_mount; +struct xfs_buftarg *target =xfs_inode_buftarg (ip); +xfs_daddr_t sector =xfs_fsb_to_db (ip, start_fsb); +sector_t block =XFS_BB_TO_FSBT (mp, sector); -return blkdev_issue_zeroout (xfs_find_bdev_for_inode (VFS_I (ip)), +return blkdev_issue_zeroout (target->bt_bdev, block << (mp->m_super->s_blocksize_bits -9 ), count_fsb << (mp->m_super->s_blocksize_bits -9 ),GFP_NOFS ,0 );fs/xfs/xfs_file.c +7
-7@@ -1229,22 +1229,22 @@ static const struct vm_operations_struct xfs_file_vm_ops = { STATIC intxfs_file_mmap ( -struct file *filp, -struct vm_area_struct *vma) +struct file *file, +struct vm_area_struct *vma) { -struct dax_device *dax_dev; +struct inode *inode =file_inode (file); +struct xfs_buftarg *target =xfs_inode_buftarg (XFS_I (inode)); - dax_dev =xfs_find_daxdev_for_inode (file_inode (filp));/* * We don't support synchronous mappings for non-DAX files and * for DAX files if underneath dax_device is not synchronous. */ -if (!daxdev_mapping_supported (vma, dax_dev)) +if (!daxdev_mapping_supported (vma, target->bt_daxdev))return -EOPNOTSUPP ; -file_accessed (filp); +file_accessed (file); vma->vm_ops = &xfs_file_vm_ops; -if (IS_DAX (file_inode (filp))) +if (IS_DAX (inode)) vma->vm_flags |=VM_HUGEPAGE ;return 0 ; }fs/xfs/xfs_inode.h +7
-0@@ -219,6 +219,13 @@ static inline bool xfs_inode_has_cow_data(struct xfs_inode *ip)return ip->i_cowfp && ip->i_cowfp->if_bytes; } +/* +* Return the buftarg used for data allocations on a given inode. +*/ +#define xfs_inode_buftarg (ip) \ + (XFS_IS_REALTIME_INODE(ip) ? \ + (ip)->i_mount->m_rtdev_targp : (ip)->i_mount->m_ddev_targp) +/* * In-core inode flags. */ fs/xfs/xfs_ioctl.c +0
-0
fs/xfs/xfs_ioctl.c xfs_ioctl_setattr_dax_invalidate( · line 1315
Quoted 5 lines
fs/xfs/xfs_ioctl.c +0
-2@@ -1311,10 +1311,9 @@ xfs_ioctl_setattr_dax_invalidate(* have to check the device for dax support or flush pagecache. */ if (fa->fsx_xflags &FS_XFLAG_DAX ) { -if (!(S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode))) -return -EINVAL ;
Um... why are we're removing this mode check?
--D
Quoted 64 lines
fs/xfs/xfs_ioctl.c +3
-2-if (!bdev_dax_supported (xfs_find_bdev_for_inode (VFS_I (ip)), - sb->s_blocksize)) +struct xfs_buftarg *target =xfs_inode_buftarg (ip); + +if (!bdev_dax_supported (target->bt_bdev, sb->s_blocksize))return -EINVAL ; }fs/xfs/xfs_iomap.c +7
-4@@ -57,6 +57,7 @@ xfs_bmbt_to_iomap( u16 flags) {struct xfs_mount *mp = ip->i_mount; +struct xfs_buftarg *target =xfs_inode_buftarg (ip);if (unlikely (!xfs_valid_startblock (ip, imap->br_startblock)))return xfs_alert_fsblock_zero (ip, imap);@@ -77,8 +78,8 @@ xfs_bmbt_to_iomap( } iomap->offset =XFS_FSB_TO_B (mp, imap->br_startoff); iomap->length =XFS_FSB_TO_B (mp, imap->br_blockcount); - iomap->bdev =xfs_find_bdev_for_inode (VFS_I (ip)); - iomap->dax_dev =xfs_find_daxdev_for_inode (VFS_I (ip)); + iomap->bdev = target->bt_bdev; + iomap->dax_dev = target->bt_daxdev; iomap->flags = flags; if (xfs_ipincount(ip) &&@@ -94,12 +95,14 @@ xfs_hole_to_iomap( xfs_fileoff_t offset_fsb, xfs_fileoff_t end_fsb) { +struct xfs_buftarg *target =xfs_inode_buftarg (ip); + iomap->addr =IOMAP_NULL_ADDR ; iomap->type =IOMAP_HOLE ; iomap->offset =XFS_FSB_TO_B (ip->i_mount, offset_fsb); iomap->length =XFS_FSB_TO_B (ip->i_mount, end_fsb - offset_fsb); - iomap->bdev =xfs_find_bdev_for_inode (VFS_I (ip)); - iomap->dax_dev =xfs_find_daxdev_for_inode (VFS_I (ip)); + iomap->bdev = target->bt_bdev; + iomap->dax_dev = target->bt_daxdev; } static inline xfs_fileoff_tfs/xfs/xfs_iops.c +1
-1@@ -1227,7 +1227,7 @@ xfs_inode_supports_dax(return false;/* Device has to support DAX too. */ -return xfs_find_daxdev_for_inode (VFS_I (ip)) !=NULL ; +return xfs_inode_buftarg (ip)->bt_daxdev !=NULL ; }STATIC voidSignature · 1 line
2.20.1
PATCH 2/3 xfs: use xfs_inode_buftarg in xfs_file_dio_aio_write
In reply to Christoph Hellwig--- fs/xfs/xfs_file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/xfs/xfs_file.c +1 -2
@@ -487,8 +487,7 @@ xfs_file_dio_aio_write(int unaligned_io =0 ;int iolock;size_t count =iov_iter_count (from); -struct xfs_buftarg *target =XFS_IS_REALTIME_INODE (ip) ? - mp->m_rtdev_targp : mp->m_ddev_targp; +struct xfs_buftarg *target =xfs_inode_buftarg (ip);/* DIO must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)
Signature · 1 line
2.20.1
Re: [PATCH 2/3] xfs: use xfs_inode_buftarg in xfs_file_dio_aio_write
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
--D
Quoted 21 lines
--- fs/xfs/xfs_file.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/xfs/xfs_file.c +1
-2@@ -487,8 +487,7 @@ xfs_file_dio_aio_write(int unaligned_io =0 ;int iolock;size_t count =iov_iter_count (from); -struct xfs_buftarg *target =XFS_IS_REALTIME_INODE (ip) ? - mp->m_rtdev_targp : mp->m_ddev_targp; +struct xfs_buftarg *target =xfs_inode_buftarg (ip);/* DIO must be aligned to device logical sector size */ if ((iocb->ki_pos | count) & target->bt_logical_sectormask)Signature · 1 line
2.20.1
PATCH 3/3 xfs: use xfs_inode_buftarg in xfs_file_ioctl
In reply to Christoph Hellwig--- fs/xfs/xfs_ioctl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/xfs/xfs_ioctl.c +2 -4
@@ -2135,10 +2135,8 @@ xfs_file_ioctl(return xfs_ioc_space (filp, cmd, &bf); }case XFS_IOC_DIOINFO : { -struct dioattr da; -xfs_buftarg_t *target = -XFS_IS_REALTIME_INODE (ip) ? - mp->m_rtdev_targp : mp->m_ddev_targp; +struct xfs_buftarg *target =xfs_inode_buftarg (ip); +struct dioattr da; da.d_mem = da.d_miniosz = target->bt_logical_sectorsize; da.d_maxiosz =INT_MAX & ~(da.d_miniosz -1 );
Signature · 1 line
2.20.1
Re: [PATCH 3/3] xfs: use xfs_inode_buftarg in xfs_file_ioctl
Quoted 1 line · Christoph Hellwig
Signed-off-by Christoph Hellwig <[email protected]>
Looks ok,
--D
Quoted 24 lines
--- fs/xfs/xfs_ioctl.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)fs/xfs/xfs_ioctl.c +2
-4@@ -2135,10 +2135,8 @@ xfs_file_ioctl(return xfs_ioc_space (filp, cmd, &bf); }case XFS_IOC_DIOINFO : { -struct dioattr da; -xfs_buftarg_t *target = -XFS_IS_REALTIME_INODE (ip) ? - mp->m_rtdev_targp : mp->m_ddev_targp; +struct xfs_buftarg *target =xfs_inode_buftarg (ip); +struct dioattr da; da.d_mem = da.d_miniosz = target->bt_logical_sectorsize; da.d_maxiosz =INT_MAX & ~(da.d_miniosz -1 );Signature · 1 line
2.20.1