Skip to contentSkip to conversation

implement generic xfs_btree_getrec

PATCH In review Christoph Hellwig 2 participants 3 messages Aug 4, 2008 – Aug 5, 2008 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 24/26 implement generic xfs_btree_getrec

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.

fs/xfs/xfs_btree.c +40 -0
Index: linux-2.6-xfs/fs/xfs/xfs_btree.c
===================================================================
@@ -3579,3 +3579,43 @@ error0:
 	XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
 	return error;
 }
+
+/*
+ * Get the data from the pointed-to record.
+ */
+int					/* error */
+xfs_btree_getrec(
+	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 */
+	int			ptr;	/* record number */
+#ifdef DEBUG
+	int			error;	/* error return value */
+#endif
+
+	ptr = cur->bc_ptrs[0];
+	block = XFS_BUF_TO_BLOCK(cur->bc_bufs[0]);
+
+#ifdef DEBUG
+	error = xfs_btree_check_block(cur, block, 0, cur->bc_bufs[0]);
+	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 = cur->bc_ops->rec_addr(cur, ptr, block);
+	*stat = 1;
+	return 0;
+}
fs/xfs/xfs_btree.h +1 -0
Index: linux-2.6-xfs/fs/xfs/xfs_btree.h
===================================================================
@@ -603,6 +603,7 @@ int xfs_btree_iroot_to_root(struct xfs_b
 int xfs_btree_root_to_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_getrec(struct xfs_btree_cur *, union xfs_btree_rec **, int *);
 
 
 /*
fs/xfs/xfs_alloc_btree.c +0 -44

50 lines not on this page · raw message

fs/xfs/xfs_alloc.c +21 -0
Index: linux-2.6-xfs/fs/xfs/xfs_alloc.c
===================================================================
@@ -155,6 +155,27 @@ xfs_alloc_update(
 }
 
 /*
+ * 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_getrec(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.
  */
fs/xfs/xfs_alloc_btree.h +0 -6
Index: linux-2.6-xfs/fs/xfs/xfs_alloc_btree.h
===================================================================
@@ -94,12 +94,6 @@ typedef	struct xfs_btree_sblock xfs_allo
 #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 *,
fs/xfs/xfs_ialloc.c +23 -0
Index: linux-2.6-xfs/fs/xfs/xfs_ialloc.c
===================================================================
@@ -192,6 +192,29 @@ xfs_inobt_update(
 }
 
 /*
+ * 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_getrec(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.
  */
fs/xfs/xfs_ialloc_btree.c +0 -45

51 lines not on this page · raw message

fs/xfs/xfs_ialloc_btree.h +0 -7
Index: linux-2.6-xfs/fs/xfs/xfs_ialloc_btree.h
===================================================================
@@ -116,13 +116,6 @@ typedef	struct xfs_btree_sblock xfs_inob
 	(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);
 
fs/xfs/xfs_ialloc.h +5 -0
Index: linux-2.6-xfs/fs/xfs/xfs_ialloc.h
===================================================================
@@ -168,6 +168,11 @@ int xfs_inobt_lookup_ge(struct xfs_btree
 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__ */
 
#1 lore raw
Quoted 3 lines · Christoph Hellwig

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.

....

Quoted 4 lines
fs/xfs/xfs_btree.c +4 -0
+int					/* error */
+xfs_btree_getrec(
+	struct xfs_btree_cur	*cur,	/* btree cursor */
+	union xfs_btree_rec	**recp,	/* output: btree record */

fs/xfs/xfs_btree.c error0: · line 3599

Quoted 10 lines
fs/xfs/xfs_btree.c +10 -0
+	int			*stat)	/* output: success/failure */
+{
+	struct xfs_btree_block	*block;	/* btree block */
+	int			ptr;	/* record number */
+#ifdef DEBUG
+	int			error;	/* error return value */
+#endif
+
+	ptr = cur->bc_ptrs[0];
+	block = XFS_BUF_TO_BLOCK(cur->bc_bufs[0]);

Would it make more sense to use:

	block = xfs_btree_get_block(cur, 0, &bp);

fs/xfs/xfs_btree.c error0: · line 3602

Quoted 3 lines
fs/xfs/xfs_btree.c +3 -0
+
+#ifdef DEBUG
+	error = xfs_btree_check_block(cur, block, 0, cur->bc_bufs[0]);

and then pass bp here? I'd rather use the helpers to do this than open code it like everything else does....

Otherwise it looks good.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 22 lines · Dave Chinner
Quoted 3 lines · Christoph Hellwig

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.

....

Quoted 4 lines
fs/xfs/xfs_btree.c +4 -0
+int					/* error */
+xfs_btree_getrec(
+	struct xfs_btree_cur	*cur,	/* btree cursor */
+	union xfs_btree_rec	**recp,	/* output: btree record */

fs/xfs/xfs_btree.c error0: · line 3599

Quoted 10 lines
fs/xfs/xfs_btree.c +10 -0
+	int			*stat)	/* output: success/failure */
+{
+	struct xfs_btree_block	*block;	/* btree block */
+	int			ptr;	/* record number */
+#ifdef DEBUG
+	int			error;	/* error return value */
+#endif
+
+	ptr = cur->bc_ptrs[0];
+	block = XFS_BUF_TO_BLOCK(cur->bc_bufs[0]);

Would it make more sense to use:

Quoted 8 lines
	block = xfs_btree_get_block(cur, 0, &bp);

fs/xfs/xfs_btree.c error0: · line 3602

Quoted 3 lines
fs/xfs/xfs_btree.c +3 -0
+
+#ifdef DEBUG
+	error = xfs_btree_check_block(cur, block, 0, cur->bc_bufs[0]);

and then pass bp here? I'd rather use the helpers to do this than open code it like everything else does....

Thanks, updated.