[XFS] implement generic xfs_btree_get_rec
authorChristoph Hellwig <hch@infradead.org>
Thu, 30 Oct 2008 05:58:11 +0000 (16:58 +1100)
committerLachlan McIlroy <lachlan@sgi.com>
Thu, 30 Oct 2008 05:58:11 +0000 (16:58 +1100)
Not really much reason to make it generic given that it's so small, but
this is the last non-method in xfs_alloc_btree.c and xfs_ialloc_btree.c,
so it makes the whole btree implementation more structured.

SGI-PV: 985583

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

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_alloc.c
fs/xfs/xfs_alloc_btree.c
fs/xfs/xfs_alloc_btree.h
fs/xfs/xfs_btree.c
fs/xfs/xfs_btree.h
fs/xfs/xfs_ialloc.c
fs/xfs/xfs_ialloc.h
fs/xfs/xfs_ialloc_btree.c
fs/xfs/xfs_ialloc_btree.h

index e9c70249d2c5cb338aee050b1946fbc9cc736667..54fa69e277610fd14e20678e89ae81fca2ccd8f6 100644 (file)
@@ -154,6 +154,27 @@ xfs_alloc_update(
        return xfs_btree_update(cur, &rec);
 }
 
+/*
+ * Get the data from the pointed-to record.
+ */
+STATIC int                             /* error */
+xfs_alloc_get_rec(
+       struct xfs_btree_cur    *cur,   /* btree cursor */
+       xfs_agblock_t           *bno,   /* output: starting block of extent */
+       xfs_extlen_t            *len,   /* output: length of extent */
+       int                     *stat)  /* output: success/failure */
+{
+       union xfs_btree_rec     *rec;
+       int                     error;
+
+       error = xfs_btree_get_rec(cur, &rec, stat);
+       if (!error && *stat == 1) {
+               *bno = be32_to_cpu(rec->alloc.ar_startblock);
+               *len = be32_to_cpu(rec->alloc.ar_blockcount);
+       }
+       return error;
+}
+
 /*
  * Compute aligned version of the found extent.
  * Takes alignment and min length into account.
index d256b51f913d677f4165b8fda0f6d05dfd886108..4d44f03858b05c36548099d6a307d3cf6140d425 100644 (file)
 #include "xfs_error.h"
 
 
-/*
- * Get the data from the pointed-to record.
- */
-int                                    /* error */
-xfs_alloc_get_rec(
-       xfs_btree_cur_t         *cur,   /* btree cursor */
-       xfs_agblock_t           *bno,   /* output: starting block of extent */
-       xfs_extlen_t            *len,   /* output: length of extent */
-       int                     *stat)  /* output: success/failure */
-{
-       xfs_alloc_block_t       *block; /* btree block */
-#ifdef DEBUG
-       int                     error;  /* error return value */
-#endif
-       int                     ptr;    /* record number */
-
-       ptr = cur->bc_ptrs[0];
-       block = XFS_BUF_TO_ALLOC_BLOCK(cur->bc_bufs[0]);
-#ifdef DEBUG
-       if ((error = xfs_btree_check_sblock(cur, block, 0, cur->bc_bufs[0])))
-               return error;
-#endif
-       /*
-        * Off the right end or left end, return failure.
-        */
-       if (ptr > be16_to_cpu(block->bb_numrecs) || ptr <= 0) {
-               *stat = 0;
-               return 0;
-       }
-       /*
-        * Point to the record and extract its data.
-        */
-       {
-               xfs_alloc_rec_t         *rec;   /* record data */
-
-               rec = XFS_ALLOC_REC_ADDR(block, ptr, cur);
-               *bno = be32_to_cpu(rec->ar_startblock);
-               *len = be32_to_cpu(rec->ar_blockcount);
-       }
-       *stat = 1;
-       return 0;
-}
-
-
 STATIC struct xfs_btree_cur *
 xfs_allocbt_dup_cursor(
        struct xfs_btree_cur    *cur)
index 8d2e3ec21fd01ca86cfc9c32a14c0bd2244c1071..22f1d709af7bd76bf462e3ff8816ff139aec2731 100644 (file)
@@ -94,12 +94,6 @@ typedef      struct xfs_btree_sblock xfs_alloc_block_t;
 #define        XFS_ALLOC_PTR_ADDR(bb,i,cur)    \
        XFS_BTREE_PTR_ADDR(xfs_alloc, bb, i, XFS_ALLOC_BLOCK_MAXRECS(1, cur))
 
-/*
- * Get the data from the pointed-to record.
- */
-extern int xfs_alloc_get_rec(struct xfs_btree_cur *cur,        xfs_agblock_t *bno,
-                               xfs_extlen_t *len, int *stat);
-
 
 extern struct xfs_btree_cur *xfs_allocbt_init_cursor(struct xfs_mount *,
                struct xfs_trans *, struct xfs_buf *,
index 28cc7681834399f8bed1ff1b7ed67f36dd8bd7b5..8503ed5d10a0e5ad7e7892c2c687f9b1785403dc 100644 (file)
@@ -3764,3 +3764,44 @@ error0:
        XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
        return error;
 }
+
+/*
+ * Get the data from the pointed-to record.
+ */
+int                                    /* error */
+xfs_btree_get_rec(
+       struct xfs_btree_cur    *cur,   /* btree cursor */
+       union xfs_btree_rec     **recp, /* output: btree record */
+       int                     *stat)  /* output: success/failure */
+{
+       struct xfs_btree_block  *block; /* btree block */
+       struct xfs_buf          *bp;    /* buffer pointer */
+       int                     ptr;    /* record number */
+#ifdef DEBUG
+       int                     error;  /* error return value */
+#endif
+
+       ptr = cur->bc_ptrs[0];
+       block = xfs_btree_get_block(cur, 0, &bp);
+
+#ifdef DEBUG
+       error = xfs_btree_check_block(cur, block, 0, bp);
+       if (error)
+               return error;
+#endif
+
+       /*
+        * Off the right end or left end, return failure.
+        */
+       if (ptr > xfs_btree_get_numrecs(block) || ptr <= 0) {
+               *stat = 0;
+               return 0;
+       }
+
+       /*
+        * Point to the record and extract its data.
+        */
+       *recp = xfs_btree_rec_addr(cur, ptr, block);
+       *stat = 1;
+       return 0;
+}
index 06ef792e0aac9df49e3cf79d9ac94f28b4e38d8f..cee3684d871ea65dce220912eb254c2c6f6d5840 100644 (file)
@@ -567,6 +567,7 @@ int xfs_btree_new_iroot(struct xfs_btree_cur *, int *, int *);
 int xfs_btree_kill_iroot(struct xfs_btree_cur *);
 int xfs_btree_insert(struct xfs_btree_cur *, int *);
 int xfs_btree_delete(struct xfs_btree_cur *, int *);
+int xfs_btree_get_rec(struct xfs_btree_cur *, union xfs_btree_rec **, int *);
 
 /*
  * Helpers.
index f13f59b13cc869476f6e47098b845309cbffe071..c8a56c529642f39928d058719b44dd03d454d198 100644 (file)
@@ -191,6 +191,29 @@ xfs_inobt_update(
        return xfs_btree_update(cur, &rec);
 }
 
+/*
+ * Get the data from the pointed-to record.
+ */
+int                                    /* error */
+xfs_inobt_get_rec(
+       struct xfs_btree_cur    *cur,   /* btree cursor */
+       xfs_agino_t             *ino,   /* output: starting inode of chunk */
+       __int32_t               *fcnt,  /* output: number of free inodes */
+       xfs_inofree_t           *free,  /* output: free inode mask */
+       int                     *stat)  /* output: success/failure */
+{
+       union xfs_btree_rec     *rec;
+       int                     error;
+
+       error = xfs_btree_get_rec(cur, &rec, stat);
+       if (!error && *stat == 1) {
+               *ino = be32_to_cpu(rec->inobt.ir_startino);
+               *fcnt = be32_to_cpu(rec->inobt.ir_freecount);
+               *free = be64_to_cpu(rec->inobt.ir_free);
+       }
+       return error;
+}
+
 /*
  * Allocate new inodes in the allocation group specified by agbp.
  * Return 0 for success, else error code.
index 4026578bc26471689a2a61f79e8ca1f9b414ec41..c5745f6d94ecb89ff97bb509214046a04c19af87 100644 (file)
@@ -168,6 +168,11 @@ int xfs_inobt_lookup_ge(struct xfs_btree_cur *cur, xfs_agino_t ino,
 int xfs_inobt_lookup_le(struct xfs_btree_cur *cur, xfs_agino_t ino,
                __int32_t fcnt, xfs_inofree_t free, int *stat);
 
+/*
+ * Get the data from the pointed-to record.
+ */
+extern int xfs_inobt_get_rec(struct xfs_btree_cur *cur, xfs_agino_t *ino,
+                            __int32_t *fcnt, xfs_inofree_t *free, int *stat);
 
 #endif /* __KERNEL__ */
 
index 6c0a07d1fed37dca66d0f395162791dd849f3359..9f4e33c945c2789274557f2e422df8b6fb3ffa82 100644 (file)
 #include "xfs_error.h"
 
 
-/*
- * Get the data from the pointed-to record.
- */
-int                                    /* error */
-xfs_inobt_get_rec(
-       xfs_btree_cur_t         *cur,   /* btree cursor */
-       xfs_agino_t             *ino,   /* output: starting inode of chunk */
-       __int32_t               *fcnt,  /* output: number of free inodes */
-       xfs_inofree_t           *free,  /* output: free inode mask */
-       int                     *stat)  /* output: success/failure */
-{
-       xfs_inobt_block_t       *block; /* btree block */
-       xfs_buf_t               *bp;    /* buffer containing btree block */
-#ifdef DEBUG
-       int                     error;  /* error return value */
-#endif
-       int                     ptr;    /* record number */
-       xfs_inobt_rec_t         *rec;   /* record data */
-
-       bp = cur->bc_bufs[0];
-       ptr = cur->bc_ptrs[0];
-       block = XFS_BUF_TO_INOBT_BLOCK(bp);
-#ifdef DEBUG
-       if ((error = xfs_btree_check_sblock(cur, block, 0, bp)))
-               return error;
-#endif
-       /*
-        * Off the right end or left end, return failure.
-        */
-       if (ptr > be16_to_cpu(block->bb_numrecs) || ptr <= 0) {
-               *stat = 0;
-               return 0;
-       }
-       /*
-        * Point to the record and extract its data.
-        */
-       rec = XFS_INOBT_REC_ADDR(block, ptr, cur);
-       *ino = be32_to_cpu(rec->ir_startino);
-       *fcnt = be32_to_cpu(rec->ir_freecount);
-       *free = be64_to_cpu(rec->ir_free);
-       *stat = 1;
-       return 0;
-}
-
 STATIC int
 xfs_inobt_get_minrecs(
        struct xfs_btree_cur    *cur,
index 3eff3b6e5fa4c0c4223588e5c8cbcc4055999f9f..ff7406b4bac35cbdf54148dff933bfb329dd191a 100644 (file)
@@ -116,13 +116,6 @@ typedef    struct xfs_btree_sblock xfs_inobt_block_t;
        (XFS_BTREE_PTR_ADDR(xfs_inobt, bb, \
                                i, XFS_INOBT_BLOCK_MAXRECS(1, cur)))
 
-/*
- * Get the data from the pointed-to record.
- */
-extern int xfs_inobt_get_rec(struct xfs_btree_cur *cur, xfs_agino_t *ino,
-                            __int32_t *fcnt, xfs_inofree_t *free, int *stat);
-
-
 extern struct xfs_btree_cur *xfs_inobt_init_cursor(struct xfs_mount *,
                struct xfs_trans *, struct xfs_buf *, xfs_agnumber_t);
 
This page took 0.030907 seconds and 5 git commands to generate.