xfs
[Top] [All Lists]

[PATCH 06/53] libxfs: refactor the btree size calculator code

To: david@xxxxxxxxxxxxx, darrick.wong@xxxxxxxxxx
Subject: [PATCH 06/53] libxfs: refactor the btree size calculator code
From: "Darrick J. Wong" <darrick.wong@xxxxxxxxxx>
Date: Sat, 19 Dec 2015 01:05:29 -0800
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <20151219090450.14255.48364.stgit@xxxxxxxxxxxxxxxx>
References: <20151219090450.14255.48364.stgit@xxxxxxxxxxxxxxxx>
User-agent: StGit/0.17.1-dirty
Create a macro to generate btree height calculator functions.
This will be used (much) later when we get to the refcount
btree.

Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx>
---
 libxfs/xfs_bmap.c       |   18 +-----------------
 libxfs/xfs_bmap_btree.c |    2 ++
 libxfs/xfs_bmap_btree.h |    2 ++
 libxfs/xfs_inode_fork.c |    1 +
 libxfs/xfs_shared.h     |   29 +++++++++++++++++++++++++++++
 5 files changed, 35 insertions(+), 17 deletions(-)


diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
index aef7cf3..ad383b4 100644
--- a/libxfs/xfs_bmap.c
+++ b/libxfs/xfs_bmap.c
@@ -172,25 +172,9 @@ xfs_bmap_worst_indlen(
        xfs_inode_t     *ip,            /* incore inode pointer */
        xfs_filblks_t   len)            /* delayed extent length */
 {
-       int             level;          /* btree level number */
-       int             maxrecs;        /* maximum record count at this level */
-       xfs_mount_t     *mp;            /* mount structure */
        xfs_filblks_t   rval;           /* return value */
 
-       mp = ip->i_mount;
-       maxrecs = mp->m_bmap_dmxr[0];
-       for (level = 0, rval = 0;
-            level < XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK);
-            level++) {
-               len += maxrecs - 1;
-               do_div(len, maxrecs);
-               rval += len;
-               if (len == 1)
-                       return rval + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) -
-                               level - 1;
-               if (level == 0)
-                       maxrecs = mp->m_bmap_dmxr[1];
-       }
+       rval = xfs_bmbt_calc_btree_size(ip->i_mount, len);
        return rval;
 }
 
diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c
index 2ef1836..a21f774 100644
--- a/libxfs/xfs_bmap_btree.c
+++ b/libxfs/xfs_bmap_btree.c
@@ -880,3 +880,5 @@ xfs_bmbt_change_owner(
        xfs_btree_del_cursor(cur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
        return error;
 }
+
+DEFINE_BTREE_SIZE_FN(bmbt, m_bmap_dmxr, XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK))
diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h
index 819a8a4..7165a1b 100644
--- a/libxfs/xfs_bmap_btree.h
+++ b/libxfs/xfs_bmap_btree.h
@@ -140,4 +140,6 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, 
struct xfs_inode *ip,
 extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
                struct xfs_trans *, struct xfs_inode *, int);
 
+DECLARE_BTREE_SIZE_FN(bmbt);
+
 #endif /* __XFS_BMAP_BTREE_H__ */
diff --git a/libxfs/xfs_inode_fork.c b/libxfs/xfs_inode_fork.c
index e1968b4..96a633e 100644
--- a/libxfs/xfs_inode_fork.c
+++ b/libxfs/xfs_inode_fork.c
@@ -17,6 +17,7 @@
  */
 #include "libxfs_priv.h"
 #include "xfs_fs.h"
+#include "xfs_shared.h"
 #include "xfs_format.h"
 #include "xfs_log_format.h"
 #include "xfs_trans_resv.h"
diff --git a/libxfs/xfs_shared.h b/libxfs/xfs_shared.h
index 5be5297..544d0e9 100644
--- a/libxfs/xfs_shared.h
+++ b/libxfs/xfs_shared.h
@@ -234,4 +234,33 @@ bool xfs_symlink_hdr_ok(xfs_ino_t ino, uint32_t offset,
 void xfs_symlink_local_to_remote(struct xfs_trans *tp, struct xfs_buf *bp,
                                 struct xfs_inode *ip, struct xfs_ifork *ifp);
 
+/* btree size calculator templates */
+#define DECLARE_BTREE_SIZE_FN(btree) \
+xfs_filblks_t xfs_##btree##_calc_btree_size(struct xfs_mount *mp, \
+               unsigned long len);
+
+#define DEFINE_BTREE_SIZE_FN(btree, limitfield, maxlevels) \
+xfs_filblks_t \
+xfs_##btree##_calc_btree_size( \
+       struct xfs_mount        *mp, \
+       unsigned long           len) \
+{ \
+       int                     level; \
+       int                     maxrecs; \
+       xfs_filblks_t           rval; \
+\
+       maxrecs = mp->limitfield[0]; \
+       for (level = 0, rval = 0; level < maxlevels; level++) { \
+               len += maxrecs - 1; \
+               do_div(len, maxrecs); \
+               rval += len; \
+               if (len == 1) \
+                       return rval + maxlevels - \
+                               level - 1; \
+               if (level == 0) \
+                       maxrecs = mp->limitfield[1]; \
+       } \
+       return rval; \
+}
+
 #endif /* __XFS_SHARED_H__ */

<Prev in Thread] Current Thread [Next in Thread>