]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: hoist extent size helpers to libxfs
authorDarrick J. Wong <djwong@kernel.org>
Wed, 2 Oct 2024 01:08:53 +0000 (18:08 -0700)
committerAndrey Albershteyn <aalbersh@redhat.com>
Fri, 4 Oct 2024 10:42:07 +0000 (12:42 +0200)
Source kernel commit: acdddbe168040372a8b6b9b5876b92b715322910

Move the extent size helpers to xfs_bmap.c in libxfs since they're used
there already.

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

index 9bbf372251973cde77ef3dcef6bea63b4a988b1c..ec4eada81642d44b42e479a894aa73d7e4f2c1c9 100644 (file)
@@ -345,6 +345,11 @@ static inline bool xfs_inode_has_bigrtalloc(struct xfs_inode *ip)
        return XFS_IS_REALTIME_INODE(ip) && ip->i_mount->m_sb.sb_rextsize > 1;
 }
 
+static inline bool xfs_is_always_cow_inode(struct xfs_inode *ip)
+{
+       return false;
+}
+
 /* Always set the child's GID to this value, even if the parent is setgid. */
 #define CRED_FORCE_GID (1U << 0)
 struct cred {
@@ -370,4 +375,6 @@ extern int  libxfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
                                uint, struct xfs_inode **);
 extern void    libxfs_irele(struct xfs_inode *ip);
 
+#define XFS_DEFAULT_COWEXTSZ_HINT      32
+
 #endif /* __XFS_INODE_H__ */
index 5d1aa23c7051e56cb6e5ad7dd5f975001e1896ec..0bf0c54ac2f7bec7dd046c115f0e0d3cf31e2e5e 100644 (file)
@@ -468,8 +468,6 @@ xfs_buf_readahead(
 
 #define xfs_rotorstep                          1
 #define xfs_bmap_rtalloc(a)                    (-ENOSYS)
-#define xfs_get_extsz_hint(ip)                 (0)
-#define xfs_get_cowextsz_hint(ip)              (0)
 #define xfs_inode_is_filestream(ip)            (0)
 #define xfs_filestream_lookup_ag(ip)           (0)
 #define xfs_filestream_new_ag(ip,ag)           (0)
index e60d114708f3f8ada70544d847903eeb6a006d5a..befbe0b0721b3ad06b10fab9c3e439eb24782a07 100644 (file)
@@ -6448,3 +6448,45 @@ xfs_bmap_query_all(
 
        return xfs_btree_query_all(cur, xfs_bmap_query_range_helper, &query);
 }
+
+/* Helper function to extract extent size hint from inode */
+xfs_extlen_t
+xfs_get_extsz_hint(
+       struct xfs_inode        *ip)
+{
+       /*
+        * No point in aligning allocations if we need to COW to actually
+        * write to them.
+        */
+       if (xfs_is_always_cow_inode(ip))
+               return 0;
+       if ((ip->i_diflags & XFS_DIFLAG_EXTSIZE) && ip->i_extsize)
+               return ip->i_extsize;
+       if (XFS_IS_REALTIME_INODE(ip) &&
+           ip->i_mount->m_sb.sb_rextsize > 1)
+               return ip->i_mount->m_sb.sb_rextsize;
+       return 0;
+}
+
+/*
+ * Helper function to extract CoW extent size hint from inode.
+ * Between the extent size hint and the CoW extent size hint, we
+ * return the greater of the two.  If the value is zero (automatic),
+ * use the default size.
+ */
+xfs_extlen_t
+xfs_get_cowextsz_hint(
+       struct xfs_inode        *ip)
+{
+       xfs_extlen_t            a, b;
+
+       a = 0;
+       if (ip->i_diflags2 & XFS_DIFLAG2_COWEXTSIZE)
+               a = ip->i_cowextsize;
+       b = xfs_get_extsz_hint(ip);
+
+       a = max(a, b);
+       if (a == 0)
+               return XFS_DEFAULT_COWEXTSZ_HINT;
+       return a;
+}
index 667b0c2b33d1d566dec92cf9913b4451818a4034..7592d46e97c661136e53978e0052d7f7caa799b8 100644 (file)
@@ -296,4 +296,7 @@ typedef int (*xfs_bmap_query_range_fn)(
 int xfs_bmap_query_all(struct xfs_btree_cur *cur, xfs_bmap_query_range_fn fn,
                void *priv);
 
+xfs_extlen_t   xfs_get_extsz_hint(struct xfs_inode *ip);
+xfs_extlen_t   xfs_get_cowextsz_hint(struct xfs_inode *ip);
+
 #endif /* __XFS_BMAP_H__ */