xfs: create a helper to count per-device inode block usage
authorDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:30:53 +0000 (12:30 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Thu, 22 Feb 2024 20:30:53 +0000 (12:30 -0800)
Create a helper to compute the number of blocks that a file has
allocated from the data realtime volumes.  This patch was
split out to reduce the size of the upcoming quotacheck patch.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_inode.c
fs/xfs/xfs_inode.h

index 110077ca3d2a9ba825cf1f5b39149a24bd3df85d..d6635d219527b5ae967eb3d7ba5c7cbc1bce7e43 100644 (file)
@@ -3755,3 +3755,19 @@ xfs_ifork_zapped(
                return false;
        }
 }
+
+/* Compute the number of data and realtime blocks used by a file. */
+void
+xfs_inode_count_blocks(
+       struct xfs_trans        *tp,
+       struct xfs_inode        *ip,
+       xfs_filblks_t           *dblocks,
+       xfs_filblks_t           *rblocks)
+{
+       struct xfs_ifork        *ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK);
+
+       *rblocks = 0;
+       if (XFS_IS_REALTIME_INODE(ip))
+               xfs_bmap_count_leaves(ifp, rblocks);
+       *dblocks = ip->i_nblocks - *rblocks;
+}
index 796d11065fe2727b4e8258f74cbc5ecca638c5aa..7bbdc7009e7d0d869414988c691e569331d7390c 100644 (file)
@@ -623,5 +623,7 @@ int xfs_inode_reload_unlinked_bucket(struct xfs_trans *tp, struct xfs_inode *ip)
 int xfs_inode_reload_unlinked(struct xfs_inode *ip);
 
 bool xfs_ifork_zapped(const struct xfs_inode *ip, int whichfork);
+void xfs_inode_count_blocks(struct xfs_trans *tp, struct xfs_inode *ip,
+               xfs_filblks_t *dblocks, xfs_filblks_t *rblocks);
 
 #endif /* __XFS_INODE_H__ */