Message ID | 20240529095206.2568162-7-yi.zhang@huaweicloud.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | iomap/xfs: fix stale data exposure when truncating realtime inodes | expand |
On Wed, May 29, 2024 at 05:52:04PM +0800, Zhang Yi wrote: > + if (xfs_inode_has_bigrtalloc(ip)) > + first_unmap_block = xfs_rtb_roundup_rtx(mp, first_unmap_block); Given that first_unmap_block is a xfs_fileoff_t and not a xfs_rtblock_t, this looks a bit confusing. I'd suggest to just open code the arithmetics in xfs_rtb_roundup_rtx. For future proofing my also use xfs_inode_alloc_unitsize() as in the hunk below instead of hard coding the rtextsize. I.e.: first_unmap_block = XFS_B_TO_FSB(mp, roundup_64(new_size, xfs_inode_alloc_unitsize(ip)));
On 2024/5/31 21:36, Christoph Hellwig wrote: > On Wed, May 29, 2024 at 05:52:04PM +0800, Zhang Yi wrote: >> + if (xfs_inode_has_bigrtalloc(ip)) >> + first_unmap_block = xfs_rtb_roundup_rtx(mp, first_unmap_block); > > Given that first_unmap_block is a xfs_fileoff_t and not a xfs_rtblock_t, > this looks a bit confusing. I'd suggest to just open code the > arithmetics in xfs_rtb_roundup_rtx. For future proofing my also > use xfs_inode_alloc_unitsize() as in the hunk below instead of hard > coding the rtextsize. I.e.: > > first_unmap_block = XFS_B_TO_FSB(mp, > roundup_64(new_size, xfs_inode_alloc_unitsize(ip))); > Sure, makes sense to me. Thanks, Yi.
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 58fb7a5062e1..db35167acef6 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -35,6 +35,7 @@ #include "xfs_trans_priv.h" #include "xfs_log.h" #include "xfs_bmap_btree.h" +#include "xfs_rtbitmap.h" #include "xfs_reflink.h" #include "xfs_ag.h" #include "xfs_log_priv.h" @@ -1512,6 +1513,8 @@ xfs_itruncate_extents_flags( * the page cache can't scale that far. */ first_unmap_block = XFS_B_TO_FSB(mp, (xfs_ufsize_t)new_size); + if (xfs_inode_has_bigrtalloc(ip)) + first_unmap_block = xfs_rtb_roundup_rtx(mp, first_unmap_block); if (!xfs_verify_fileoff(mp, first_unmap_block)) { WARN_ON_ONCE(first_unmap_block > XFS_MAX_FILEOFF); return 0; diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index d24927075022..ec7b7bdf8825 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c @@ -865,7 +865,7 @@ xfs_setattr_size( */ write_back = newsize > ip->i_disk_size && oldsize != ip->i_disk_size; if (newsize < oldsize) { - unsigned int blocksize = i_blocksize(inode); + unsigned int blocksize = xfs_inode_alloc_unitsize(ip); /* * Zeroing out the partial EOF block and the rest of the extra