Skip to contentSkip to conversation

implement generic xfs_btree_updkey

PATCH In review Christoph Hellwig 1 participant 1 message Jul 23, 2008 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 14/15 implement generic xfs_btree_updkey

From: Dave Chinner <[email protected]>

Note that there are many > 80 char lines introduced due to the xfs_btree_key casts. But the places where this happens is throw-away code once the whole btree code gets merged into a common implementation.

The same is true for the temporary xfs_alloc_log_keys define to the new name. All old users will be gone after a few patches.

[hch: split out from bigger patch and minor adaptions]

fs/xfs/xfs_btree.c +47 -0
Index: linux-2.6-xfs/fs/xfs/xfs_btree.c
===================================================================
@@ -1370,3 +1370,50 @@ error0:
 	XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
 	return error;
 }
+
+/*
+ * Update keys at all levels from here to the root along the cursor's path.
+ */
+int
+xfs_btree_updkey(
+	struct xfs_btree_cur	*cur,
+	union xfs_btree_key	*keyp,
+	int			level)
+{
+	struct xfs_btree_block	*block;
+	struct xfs_buf		*bp;
+	union xfs_btree_key	*kp;
+	int			ptr;
+#ifdef DEBUG
+	int			error;
+#endif
+
+	XFS_BTREE_TRACE_CURSOR(cur, XBT_ENTRY);
+	XFS_BTREE_TRACE_ARGIK(cur, level, keyp);
+
+	ASSERT(!(cur->bc_flags & XFS_BTREE_ROOT_IN_INODE) || level >= 1);
+
+	/*
+	 * Go up the tree from this level toward the root.
+	 * At each level, update the key value to the value input.
+	 * Stop when we reach a level where the cursor isn't pointing
+	 * at the first entry in the block.
+	 */
+	for (ptr = 1; ptr == 1 && level < cur->bc_nlevels; level++) {
+		block = xfs_btree_get_block(cur, level, &bp);
+#ifdef DEBUG
+		error = xfs_btree_check_block(cur, block, level, bp);
+		if (error) {
+			XFS_BTREE_TRACE_CURSOR(cur, XBT_ERROR);
+			return error;
+		}
+#endif
+		ptr = cur->bc_ptrs[level];
+		kp = cur->bc_ops->key_addr(cur, ptr, block);
+		cur->bc_ops->copy_keys(cur, keyp, kp, 1);
+		cur->bc_ops->log_keys(cur, bp, ptr, ptr);
+	}
+
+	XFS_BTREE_TRACE_CURSOR(cur, XBT_EXIT);
+	return 0;
+}
fs/xfs/xfs_btree.h +11 -0
Index: linux-2.6-xfs/fs/xfs/xfs_btree.h
===================================================================
@@ -210,6 +210,16 @@ struct xfs_btree_ops {
 	__int64_t (*key_diff)(struct xfs_btree_cur *cur,
 			      union xfs_btree_key *key);
 
+	/* copy bits of btree blocks between blocks */
+	void	(*copy_keys)(struct xfs_btree_cur *cur,
+			     union xfs_btree_key *src_key,
+			     union xfs_btree_key *dst_key, int numkeys);
+
+	/* log changes to btree structures */
+	void	(*log_keys)(struct xfs_btree_cur *cur, struct xfs_buf *bp,
+			    int first, int last);
+
+
 	/* btree tracing */
 #ifdef XFS_BTREE_TRACE
 	void		(*trace_enter)(struct xfs_btree_cur *, const char *,
@@ -528,6 +538,7 @@ xfs_btree_setbuf(
 int xfs_btree_increment(struct xfs_btree_cur *, int, int *);
 int xfs_btree_decrement(struct xfs_btree_cur *, int, int *);
 int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *);
+int xfs_btree_updkey(struct xfs_btree_cur *, union xfs_btree_key *, int);
 
 
 /*
fs/xfs/xfs_alloc_btree.c +50 -68

190 lines not on this page · raw message

fs/xfs/xfs_ialloc_btree.c +46 -67

179 lines not on this page · raw message

fs/xfs/xfs_bmap_btree.c +50 -80

190 lines not on this page · raw message