]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
[XFS] make btree root in inode support generic
authorChristoph Hellwig <hch@infradead.org>
Thu, 30 Oct 2008 05:54:22 +0000 (16:54 +1100)
committerLachlan McIlroy <lachlan@sgi.com>
Thu, 30 Oct 2008 05:54:22 +0000 (16:54 +1100)
The bmap btree is rooted in the inode and not in a disk block. Make the
support for this feature more generic by adding a btree flag to for this
feature instead of relying on the XFS_BTNUM_BMAP btnum check.

Also clean up xfs_btree_get_block where this new flag is used.

Based upon a patch from Dave Chinner.

SGI-PV: 985583

SGI-Modid: xfs-linux-melb:xfs-kern:32180a

Signed-off-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Lachlan McIlroy <lachlan@sgi.com>
Signed-off-by: Bill O'Donnell <billodo@sgi.com>
Signed-off-by: David Chinner <david@fromorbit.com>
fs/xfs/xfs_bmap_btree.c
fs/xfs/xfs_btree.c
fs/xfs/xfs_btree.h

index cfbdd00045cfcbc8bbd66f8ee2aedaa75519b2f6..d9bbed676e0c0c84cff7a76f4d1fcd8c47142b0e 100644 (file)
@@ -2656,6 +2656,7 @@ xfs_bmbt_init_cursor(
        cur->bc_blocklog = mp->m_sb.sb_blocklog;
 
        cur->bc_ops = &xfs_bmbt_ops;
+       cur->bc_flags = XFS_BTREE_ROOT_IN_INODE;
 
        cur->bc_private.b.forksize = XFS_IFORK_SIZE(ip, whichfork);
        cur->bc_private.b.ip = ip;
index 074f7f6aa27cf375503485716c878821c556a083..57e858fbf683ce3d5cb67c892e225c0d093e535b 100644 (file)
@@ -421,33 +421,40 @@ xfs_btree_dup_cursor(
        return 0;
 }
 
+/*
+ * Get a the root block which is stored in the inode.
+ *
+ * For now this btree implementation assumes the btree root is always
+ * stored in the if_broot field of an inode fork.
+ */
+STATIC struct xfs_btree_block *
+xfs_btree_get_iroot(
+       struct xfs_btree_cur    *cur)
+{
+       struct xfs_ifork        *ifp;
+
+       ifp = XFS_IFORK_PTR(cur->bc_private.b.ip, cur->bc_private.b.whichfork);
+       return (struct xfs_btree_block *)ifp->if_broot;
+}
+
 /*
  * Retrieve the block pointer from the cursor at the given level.
- * This may be a bmap btree root or from a buffer.
+ * This may be an inode btree root or from a buffer.
  */
-STATIC xfs_btree_block_t *             /* generic btree block pointer */
+STATIC struct xfs_btree_block *                /* generic btree block pointer */
 xfs_btree_get_block(
-       xfs_btree_cur_t         *cur,   /* btree cursor */
+       struct xfs_btree_cur    *cur,   /* btree cursor */
        int                     level,  /* level in btree */
-       xfs_buf_t               **bpp)  /* buffer containing the block */
+       struct xfs_buf          **bpp)  /* buffer containing the block */
 {
-       xfs_btree_block_t       *block; /* return value */
-       xfs_buf_t               *bp;    /* return buffer */
-       xfs_ifork_t             *ifp;   /* inode fork pointer */
-       int                     whichfork; /* data or attr fork */
-
-       if (cur->bc_btnum == XFS_BTNUM_BMAP && level == cur->bc_nlevels - 1) {
-               whichfork = cur->bc_private.b.whichfork;
-               ifp = XFS_IFORK_PTR(cur->bc_private.b.ip, whichfork);
-               block = (xfs_btree_block_t *)ifp->if_broot;
-               bp = NULL;
-       } else {
-               bp = cur->bc_bufs[level];
-               block = XFS_BUF_TO_BLOCK(bp);
+       if ((cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) &&
+           (level == cur->bc_nlevels - 1)) {
+               *bpp = NULL;
+               return xfs_btree_get_iroot(cur);
        }
-       ASSERT(block != NULL);
-       *bpp = bp;
-       return block;
+
+       *bpp = cur->bc_bufs[level];
+       return XFS_BUF_TO_BLOCK(*bpp);
 }
 
 /*
index 428e81f0e27eede4eb7325da0b61f376b39e9469..fefbc69e500ea355868a2b79b741340c8177fdca 100644 (file)
@@ -170,6 +170,7 @@ typedef struct xfs_btree_cur
        struct xfs_trans        *bc_tp; /* transaction we're in, if any */
        struct xfs_mount        *bc_mp; /* file system mount struct */
        const struct xfs_btree_ops *bc_ops;
+       uint                    bc_flags; /* btree features - below */
        union {
                xfs_alloc_rec_incore_t  a;
                xfs_bmbt_irec_t         b;
@@ -201,6 +202,10 @@ typedef struct xfs_btree_cur
        }               bc_private;     /* per-btree type data */
 } xfs_btree_cur_t;
 
+/* cursor flags */
+#define XFS_BTREE_ROOT_IN_INODE                (1<<1)  /* root may be variable size */
+
+
 #define        XFS_BTREE_NOERROR       0
 #define        XFS_BTREE_ERROR         1