xfs_btree.h 17.3 KB
Newer Older
L
Linus Torvalds 已提交
1
/*
2 3
 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
 * All Rights Reserved.
L
Linus Torvalds 已提交
4
 *
5 6
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
L
Linus Torvalds 已提交
7 8
 * published by the Free Software Foundation.
 *
9 10 11 12
 * This program is distributed in the hope that it would be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
L
Linus Torvalds 已提交
13
 *
14 15 16
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write the Free Software Foundation,
 * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
L
Linus Torvalds 已提交
17 18 19 20 21 22 23 24 25 26
 */
#ifndef __XFS_BTREE_H__
#define	__XFS_BTREE_H__

struct xfs_buf;
struct xfs_bmap_free;
struct xfs_inode;
struct xfs_mount;
struct xfs_trans;

D
David Chinner 已提交
27 28
extern kmem_zone_t	*xfs_btree_cur_zone;

C
Christoph Hellwig 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
/*
 * Generic key, ptr and record wrapper structures.
 *
 * These are disk format structures, and are converted where necessary
 * by the btree specific code that needs to interpret them.
 */
union xfs_btree_ptr {
	__be32			s;	/* short form ptr */
	__be64			l;	/* long form ptr */
};

union xfs_btree_key {
	xfs_bmbt_key_t		bmbt;
	xfs_bmdr_key_t		bmbr;	/* bmbt root block */
	xfs_alloc_key_t		alloc;
	xfs_inobt_key_t		inobt;
};

47 48 49 50 51 52 53 54 55 56 57 58 59 60
/*
 * In-core key that holds both low and high keys for overlapped btrees.
 * The two keys are packed next to each other on disk, so do the same
 * in memory.  Preserve the existing xfs_btree_key as a single key to
 * avoid the mental model breakage that would happen if we passed a
 * bigkey into a function that operates on a single key.
 */
union xfs_btree_bigkey {
	struct xfs_bmbt_key		bmbt;
	xfs_bmdr_key_t			bmbr;	/* bmbt root block */
	xfs_alloc_key_t			alloc;
	struct xfs_inobt_key		inobt;
};

C
Christoph Hellwig 已提交
61 62 63 64 65 66 67
union xfs_btree_rec {
	xfs_bmbt_rec_t		bmbt;
	xfs_bmdr_rec_t		bmbr;	/* bmbt root block */
	xfs_alloc_rec_t		alloc;
	xfs_inobt_rec_t		inobt;
};

68 69 70 71 72 73 74 75 76 77 78
/*
 * This nonsense is to make -wlint happy.
 */
#define	XFS_LOOKUP_EQ	((xfs_lookup_t)XFS_LOOKUP_EQi)
#define	XFS_LOOKUP_LE	((xfs_lookup_t)XFS_LOOKUP_LEi)
#define	XFS_LOOKUP_GE	((xfs_lookup_t)XFS_LOOKUP_GEi)

#define	XFS_BTNUM_BNO	((xfs_btnum_t)XFS_BTNUM_BNOi)
#define	XFS_BTNUM_CNT	((xfs_btnum_t)XFS_BTNUM_CNTi)
#define	XFS_BTNUM_BMAP	((xfs_btnum_t)XFS_BTNUM_BMAPi)
#define	XFS_BTNUM_INO	((xfs_btnum_t)XFS_BTNUM_INOi)
79
#define	XFS_BTNUM_FINO	((xfs_btnum_t)XFS_BTNUM_FINOi)
80

L
Linus Torvalds 已提交
81 82 83
/*
 * For logging record fields.
 */
84 85 86 87 88 89 90 91 92
#define	XFS_BB_MAGIC		(1 << 0)
#define	XFS_BB_LEVEL		(1 << 1)
#define	XFS_BB_NUMRECS		(1 << 2)
#define	XFS_BB_LEFTSIB		(1 << 3)
#define	XFS_BB_RIGHTSIB		(1 << 4)
#define	XFS_BB_BLKNO		(1 << 5)
#define	XFS_BB_LSN		(1 << 6)
#define	XFS_BB_UUID		(1 << 7)
#define	XFS_BB_OWNER		(1 << 8)
L
Linus Torvalds 已提交
93 94
#define	XFS_BB_NUM_BITS		5
#define	XFS_BB_ALL_BITS		((1 << XFS_BB_NUM_BITS) - 1)
95
#define	XFS_BB_NUM_BITS_CRC	9
96
#define	XFS_BB_ALL_BITS_CRC	((1 << XFS_BB_NUM_BITS_CRC) - 1)
L
Linus Torvalds 已提交
97

D
David Chinner 已提交
98 99 100
/*
 * Generic stats interface
 */
101 102 103
#define __XFS_BTREE_STATS_INC(mp, type, stat) \
	XFS_STATS_INC(mp, xs_ ## type ## _2_ ## stat)
#define XFS_BTREE_STATS_INC(cur, stat)	\
D
David Chinner 已提交
104
do {    \
105
	struct xfs_mount *__mp = cur->bc_mp; \
D
David Chinner 已提交
106
	switch (cur->bc_btnum) {  \
107 108 109 110 111
	case XFS_BTNUM_BNO: __XFS_BTREE_STATS_INC(__mp, abtb, stat); break; \
	case XFS_BTNUM_CNT: __XFS_BTREE_STATS_INC(__mp, abtc, stat); break; \
	case XFS_BTNUM_BMAP: __XFS_BTREE_STATS_INC(__mp, bmbt, stat); break; \
	case XFS_BTNUM_INO: __XFS_BTREE_STATS_INC(__mp, ibt, stat); break; \
	case XFS_BTNUM_FINO: __XFS_BTREE_STATS_INC(__mp, fibt, stat); break; \
D
David Chinner 已提交
112 113 114 115
	case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break;	\
	}       \
} while (0)

116 117
#define __XFS_BTREE_STATS_ADD(mp, type, stat, val) \
	XFS_STATS_ADD(mp, xs_ ## type ## _2_ ## stat, val)
D
David Chinner 已提交
118 119
#define XFS_BTREE_STATS_ADD(cur, stat, val)  \
do {    \
120
	struct xfs_mount *__mp = cur->bc_mp; \
D
David Chinner 已提交
121
	switch (cur->bc_btnum) {  \
122 123 124 125 126 127 128 129 130 131 132
	case XFS_BTNUM_BNO:	\
		__XFS_BTREE_STATS_ADD(__mp, abtb, stat, val); break; \
	case XFS_BTNUM_CNT:	\
		__XFS_BTREE_STATS_ADD(__mp, abtc, stat, val); break; \
	case XFS_BTNUM_BMAP:	\
		__XFS_BTREE_STATS_ADD(__mp, bmbt, stat, val); break; \
	case XFS_BTNUM_INO:	\
		__XFS_BTREE_STATS_ADD(__mp, ibt, stat, val); break; \
	case XFS_BTNUM_FINO:	\
		__XFS_BTREE_STATS_ADD(__mp, fibt, stat, val); break; \
	case XFS_BTNUM_MAX: ASSERT(0); /* fucking gcc */ ; break; \
D
David Chinner 已提交
133 134
	}       \
} while (0)
L
Linus Torvalds 已提交
135 136 137

#define	XFS_BTREE_MAXLEVELS	8	/* max of all btrees */

138
struct xfs_btree_ops {
139 140 141 142
	/* size of the key and record structures */
	size_t	key_len;
	size_t	rec_len;

143 144
	/* cursor operations */
	struct xfs_btree_cur *(*dup_cursor)(struct xfs_btree_cur *);
145 146
	void	(*update_cursor)(struct xfs_btree_cur *src,
				 struct xfs_btree_cur *dst);
147

148 149
	/* update btree root pointer */
	void	(*set_root)(struct xfs_btree_cur *cur,
150
			    union xfs_btree_ptr *nptr, int level_change);
151

152 153 154 155
	/* block allocation / freeing */
	int	(*alloc_block)(struct xfs_btree_cur *cur,
			       union xfs_btree_ptr *start_bno,
			       union xfs_btree_ptr *new_bno,
156
			       int *stat);
157
	int	(*free_block)(struct xfs_btree_cur *cur, struct xfs_buf *bp);
158

159 160 161 162 163 164
	/* update last record information */
	void	(*update_lastrec)(struct xfs_btree_cur *cur,
				  struct xfs_btree_block *block,
				  union xfs_btree_rec *rec,
				  int ptr, int reason);

165
	/* records in block/level */
166
	int	(*get_minrecs)(struct xfs_btree_cur *cur, int level);
167 168
	int	(*get_maxrecs)(struct xfs_btree_cur *cur, int level);

169 170 171
	/* records on disk.  Matter for the root in inode case. */
	int	(*get_dmaxrecs)(struct xfs_btree_cur *cur, int level);

172 173 174
	/* init values of btree structures */
	void	(*init_key_from_rec)(union xfs_btree_key *key,
				     union xfs_btree_rec *rec);
175 176
	void	(*init_rec_from_cur)(struct xfs_btree_cur *cur,
				     union xfs_btree_rec *rec);
177 178
	void	(*init_ptr_from_cur)(struct xfs_btree_cur *cur,
				     union xfs_btree_ptr *ptr);
179 180
	void	(*init_high_key_from_rec)(union xfs_btree_key *key,
					  union xfs_btree_rec *rec);
181 182 183 184 185

	/* difference between key value and cursor value */
	__int64_t (*key_diff)(struct xfs_btree_cur *cur,
			      union xfs_btree_key *key);

186 187 188 189 190 191 192 193
	/*
	 * Difference between key2 and key1 -- positive if key1 > key2,
	 * negative if key1 < key2, and zero if equal.
	 */
	__int64_t (*diff_two_keys)(struct xfs_btree_cur *cur,
				   union xfs_btree_key *key1,
				   union xfs_btree_key *key2);

194
	const struct xfs_buf_ops	*buf_ops;
195

D
Dave Chinner 已提交
196
#if defined(DEBUG) || defined(XFS_WARN)
197 198 199 200 201 202 203 204 205 206
	/* check that k1 is lower than k2 */
	int	(*keys_inorder)(struct xfs_btree_cur *cur,
				union xfs_btree_key *k1,
				union xfs_btree_key *k2);

	/* check that r1 is lower than r2 */
	int	(*recs_inorder)(struct xfs_btree_cur *cur,
				union xfs_btree_rec *r1,
				union xfs_btree_rec *r2);
#endif
207 208 209 210 211 212 213 214 215 216 217 218 219

	/* derive the low & high keys from the records in a leaf block */
	void	(*get_leaf_keys)(struct xfs_btree_cur *cur,
				 struct xfs_btree_block *block,
				 union xfs_btree_key *key);

	/* derive the low & high keys from the keys in a node block */
	void	(*get_node_keys)(struct xfs_btree_cur *cur,
				 struct xfs_btree_block *block,
				 union xfs_btree_key *key);

	/* update the parent keys of given btree level */
	int	(*update_keys)(struct xfs_btree_cur *cur, int level);
220 221
};

222 223 224 225
/*
 * Reasons for the update_lastrec method to be called.
 */
#define LASTREC_UPDATE	0
226
#define LASTREC_INSREC	1
227
#define LASTREC_DELREC	2
228 229


230 231 232 233 234 235
union xfs_btree_irec {
	struct xfs_alloc_rec_incore	a;
	struct xfs_bmbt_irec		b;
	struct xfs_inobt_rec_incore	i;
};

L
Linus Torvalds 已提交
236 237 238 239 240 241 242 243
/*
 * Btree cursor structure.
 * This collects all information needed by the btree code in one place.
 */
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 */
244
	const struct xfs_btree_ops *bc_ops;
245
	uint			bc_flags; /* btree features - below */
246
	union xfs_btree_irec	bc_rec;	/* current insert/search record value */
L
Linus Torvalds 已提交
247 248 249 250 251 252 253 254 255
	struct xfs_buf	*bc_bufs[XFS_BTREE_MAXLEVELS];	/* buf ptr per level */
	int		bc_ptrs[XFS_BTREE_MAXLEVELS];	/* key/record # */
	__uint8_t	bc_ra[XFS_BTREE_MAXLEVELS];	/* readahead bits */
#define	XFS_BTCUR_LEFTRA	1	/* left sibling has been read-ahead */
#define	XFS_BTCUR_RIGHTRA	2	/* right sibling has been read-ahead */
	__uint8_t	bc_nlevels;	/* number of levels in the tree */
	__uint8_t	bc_blocklog;	/* log2(blocksize) of btree blocks */
	xfs_btnum_t	bc_btnum;	/* identifies which btree type */
	union {
256 257
		struct {			/* needed for BNO, CNT, INO */
			struct xfs_buf	*agbp;	/* agf/agi buffer pointer */
L
Linus Torvalds 已提交
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
			xfs_agnumber_t	agno;	/* ag number */
		} a;
		struct {			/* needed for BMAP */
			struct xfs_inode *ip;	/* pointer to our inode */
			struct xfs_bmap_free *flist;	/* list to free after */
			xfs_fsblock_t	firstblock;	/* 1st blk allocated */
			int		allocated;	/* count of alloced */
			short		forksize;	/* fork's inode space */
			char		whichfork;	/* data or attr fork */
			char		flags;		/* flags */
#define	XFS_BTCUR_BPRV_WASDEL	1			/* was delayed */
		} b;
	}		bc_private;	/* per-btree type data */
} xfs_btree_cur_t;

273
/* cursor flags */
274
#define XFS_BTREE_LONG_PTRS		(1<<0)	/* pointers are 64bits long */
275
#define XFS_BTREE_ROOT_IN_INODE		(1<<1)	/* root may be variable size */
276
#define XFS_BTREE_LASTREC_UPDATE	(1<<2)	/* track last rec externally */
277
#define XFS_BTREE_CRC_BLOCKS		(1<<3)	/* uses extended btree blocks */
278
#define XFS_BTREE_OVERLAPPING		(1<<4)	/* overlapping intervals */
279 280


L
Linus Torvalds 已提交
281 282 283 284 285 286
#define	XFS_BTREE_NOERROR	0
#define	XFS_BTREE_ERROR		1

/*
 * Convert from buffer to btree block header.
 */
287
#define	XFS_BUF_TO_BLOCK(bp)	((struct xfs_btree_block *)((bp)->b_addr))
L
Linus Torvalds 已提交
288 289 290


/*
291
 * Check that block header is ok.
L
Linus Torvalds 已提交
292
 */
293 294 295 296
int
xfs_btree_check_block(
	struct xfs_btree_cur	*cur,	/* btree cursor */
	struct xfs_btree_block	*block,	/* generic btree block pointer */
L
Linus Torvalds 已提交
297 298 299 300
	int			level,	/* level of the btree block */
	struct xfs_buf		*bp);	/* buffer containing block, if any */

/*
301
 * Check that (long) pointer is ok.
L
Linus Torvalds 已提交
302 303 304
 */
int					/* error (0 or EFSCORRUPTED) */
xfs_btree_check_lptr(
305
	struct xfs_btree_cur	*cur,	/* btree cursor */
C
Christoph Hellwig 已提交
306
	xfs_fsblock_t		ptr,	/* btree block disk address */
L
Linus Torvalds 已提交
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
	int			level);	/* btree block level */

/*
 * Delete the btree cursor.
 */
void
xfs_btree_del_cursor(
	xfs_btree_cur_t		*cur,	/* btree cursor */
	int			error);	/* del because of error */

/*
 * Duplicate the btree cursor.
 * Allocate a new one, copy the record, re-get the buffers.
 */
int					/* error */
xfs_btree_dup_cursor(
	xfs_btree_cur_t		*cur,	/* input cursor */
	xfs_btree_cur_t		**ncur);/* output cursor */

/*
 * Get a buffer for the block, return it with no data read.
 * Long-form addressing.
 */
struct xfs_buf *				/* buffer for fsbno */
xfs_btree_get_bufl(
	struct xfs_mount	*mp,	/* file system mount point */
	struct xfs_trans	*tp,	/* transaction pointer */
	xfs_fsblock_t		fsbno,	/* file system block number */
	uint			lock);	/* lock flags for get_buf */

/*
 * Get a buffer for the block, return it with no data read.
 * Short-form addressing.
 */
struct xfs_buf *				/* buffer for agno/agbno */
xfs_btree_get_bufs(
	struct xfs_mount	*mp,	/* file system mount point */
	struct xfs_trans	*tp,	/* transaction pointer */
	xfs_agnumber_t		agno,	/* allocation group number */
	xfs_agblock_t		agbno,	/* allocation group block number */
	uint			lock);	/* lock flags for get_buf */

/*
 * Check for the cursor referring to the last block at the given level.
 */
int					/* 1=is last block, 0=not last block */
xfs_btree_islastblock(
	xfs_btree_cur_t		*cur,	/* btree cursor */
	int			level);	/* level to check */

/*
 * Compute first and last byte offsets for the fields given.
 * Interprets the offsets table, which contains struct field offsets.
 */
void
xfs_btree_offsets(
	__int64_t		fields,	/* bitmask of fields */
	const short		*offsets,/* table of field offsets */
	int			nbits,	/* number of bits to inspect */
	int			*first,	/* output: first byte offset */
	int			*last);	/* output: last byte offset */

/*
 * Get a buffer for the block, return it read in.
 * Long-form addressing.
 */
int					/* error */
xfs_btree_read_bufl(
	struct xfs_mount	*mp,	/* file system mount point */
	struct xfs_trans	*tp,	/* transaction pointer */
	xfs_fsblock_t		fsbno,	/* file system block number */
	uint			lock,	/* lock flags for read_buf */
	struct xfs_buf		**bpp,	/* buffer for fsbno */
380
	int			refval,	/* ref count value for buffer */
381
	const struct xfs_buf_ops *ops);
L
Linus Torvalds 已提交
382 383 384 385 386 387 388 389 390

/*
 * Read-ahead the block, don't wait for it, don't return a buffer.
 * Long-form addressing.
 */
void					/* error */
xfs_btree_reada_bufl(
	struct xfs_mount	*mp,	/* file system mount point */
	xfs_fsblock_t		fsbno,	/* file system block number */
391
	xfs_extlen_t		count,	/* count of filesystem blocks */
392
	const struct xfs_buf_ops *ops);
L
Linus Torvalds 已提交
393 394 395 396 397 398 399 400 401 402

/*
 * Read-ahead the block, don't wait for it, don't return a buffer.
 * Short-form addressing.
 */
void					/* error */
xfs_btree_reada_bufs(
	struct xfs_mount	*mp,	/* file system mount point */
	xfs_agnumber_t		agno,	/* allocation group number */
	xfs_agblock_t		agbno,	/* allocation group block number */
403
	xfs_extlen_t		count,	/* count of filesystem blocks */
404
	const struct xfs_buf_ops *ops);
L
Linus Torvalds 已提交
405

406 407 408 409 410 411 412 413 414 415
/*
 * Initialise a new btree block header
 */
void
xfs_btree_init_block(
	struct xfs_mount *mp,
	struct xfs_buf	*bp,
	__u32		magic,
	__u16		level,
	__u16		numrecs,
416
	__u64		owner,
417
	unsigned int	flags);
418

419 420 421 422 423 424 425 426 427 428 429
void
xfs_btree_init_block_int(
	struct xfs_mount	*mp,
	struct xfs_btree_block	*buf,
	xfs_daddr_t		blkno,
	__u32			magic,
	__u16			level,
	__u16			numrecs,
	__u64			owner,
	unsigned int		flags);

430 431 432 433
/*
 * Common btree core entry points.
 */
int xfs_btree_increment(struct xfs_btree_cur *, int, int *);
434
int xfs_btree_decrement(struct xfs_btree_cur *, int, int *);
435
int xfs_btree_lookup(struct xfs_btree_cur *, xfs_lookup_t, int *);
436
int xfs_btree_update(struct xfs_btree_cur *, union xfs_btree_rec *);
437
int xfs_btree_new_iroot(struct xfs_btree_cur *, int *, int *);
438
int xfs_btree_insert(struct xfs_btree_cur *, int *);
439
int xfs_btree_delete(struct xfs_btree_cur *, int *);
440
int xfs_btree_get_rec(struct xfs_btree_cur *, union xfs_btree_rec **, int *);
441 442
int xfs_btree_change_owner(struct xfs_btree_cur *cur, __uint64_t new_owner,
			   struct list_head *buffer_list);
443

444 445 446 447 448 449 450 451
/*
 * btree block CRC helpers
 */
void xfs_btree_lblock_calc_crc(struct xfs_buf *);
bool xfs_btree_lblock_verify_crc(struct xfs_buf *);
void xfs_btree_sblock_calc_crc(struct xfs_buf *);
bool xfs_btree_sblock_verify_crc(struct xfs_buf *);

452 453 454 455 456 457
/*
 * Internal btree helpers also used by xfs_bmap.c.
 */
void xfs_btree_log_block(struct xfs_btree_cur *, struct xfs_buf *, int);
void xfs_btree_log_recs(struct xfs_btree_cur *, struct xfs_buf *, int, int);

458 459 460
/*
 * Helpers.
 */
461 462 463 464 465
static inline int xfs_btree_get_numrecs(struct xfs_btree_block *block)
{
	return be16_to_cpu(block->bb_numrecs);
}

466 467 468 469 470 471
static inline void xfs_btree_set_numrecs(struct xfs_btree_block *block,
		__uint16_t numrecs)
{
	block->bb_numrecs = cpu_to_be16(numrecs);
}

472 473 474 475 476
static inline int xfs_btree_get_level(struct xfs_btree_block *block)
{
	return be16_to_cpu(block->bb_level);
}

L
Linus Torvalds 已提交
477 478 479 480

/*
 * Min and max functions for extlen, agblock, fileoff, and filblks types.
 */
481 482 483 484 485 486 487 488
#define	XFS_EXTLEN_MIN(a,b)	min_t(xfs_extlen_t, (a), (b))
#define	XFS_EXTLEN_MAX(a,b)	max_t(xfs_extlen_t, (a), (b))
#define	XFS_AGBLOCK_MIN(a,b)	min_t(xfs_agblock_t, (a), (b))
#define	XFS_AGBLOCK_MAX(a,b)	max_t(xfs_agblock_t, (a), (b))
#define	XFS_FILEOFF_MIN(a,b)	min_t(xfs_fileoff_t, (a), (b))
#define	XFS_FILEOFF_MAX(a,b)	max_t(xfs_fileoff_t, (a), (b))
#define	XFS_FILBLKS_MIN(a,b)	min_t(xfs_filblks_t, (a), (b))
#define	XFS_FILBLKS_MAX(a,b)	max_t(xfs_filblks_t, (a), (b))
489

L
Linus Torvalds 已提交
490 491
#define	XFS_FSB_SANITY_CHECK(mp,fsb)	\
	(XFS_FSB_TO_AGNO(mp, fsb) < mp->m_sb.sb_agcount && \
492
		XFS_FSB_TO_AGBNO(mp, fsb) < mp->m_sb.sb_agblocks)
L
Linus Torvalds 已提交
493

494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512
/*
 * Trace hooks.  Currently not implemented as they need to be ported
 * over to the generic tracing functionality, which is some effort.
 *
 * i,j = integer (32 bit)
 * b = btree block buffer (xfs_buf_t)
 * p = btree ptr
 * r = btree record
 * k = btree key
 */
#define	XFS_BTREE_TRACE_ARGBI(c, b, i)
#define	XFS_BTREE_TRACE_ARGBII(c, b, i, j)
#define	XFS_BTREE_TRACE_ARGI(c, i)
#define	XFS_BTREE_TRACE_ARGIPK(c, i, p, s)
#define	XFS_BTREE_TRACE_ARGIPR(c, i, p, r)
#define	XFS_BTREE_TRACE_ARGIK(c, i, k)
#define XFS_BTREE_TRACE_ARGR(c, r)
#define	XFS_BTREE_TRACE_CURSOR(c, t)

513 514
bool xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp);
bool xfs_btree_sblock_verify(struct xfs_buf *bp, unsigned int max_recs);
515 516
uint xfs_btree_compute_maxlevels(struct xfs_mount *mp, uint *limits,
				 unsigned long len);
517

518 519 520 521 522
void xfs_btree_get_leaf_keys(struct xfs_btree_cur *cur,
		struct xfs_btree_block *block, union xfs_btree_key *key);
void xfs_btree_get_node_keys(struct xfs_btree_cur *cur,
		struct xfs_btree_block *block, union xfs_btree_key *key);
int xfs_btree_update_keys(struct xfs_btree_cur *cur, int level);
523 524 525 526 527
void xfs_btree_get_leaf_keys_overlapped(struct xfs_btree_cur *cur,
		struct xfs_btree_block *block, union xfs_btree_key *key);
void xfs_btree_get_node_keys_overlapped(struct xfs_btree_cur *cur,
		struct xfs_btree_block *block, union xfs_btree_key *key);
int xfs_btree_update_keys_overlapped(struct xfs_btree_cur *cur, int level);
528

529 530 531 532 533 534 535 536 537 538
/* return codes */
#define XFS_BTREE_QUERY_RANGE_CONTINUE	0	/* keep iterating */
#define XFS_BTREE_QUERY_RANGE_ABORT	1	/* stop iterating */
typedef int (*xfs_btree_query_range_fn)(struct xfs_btree_cur *cur,
		union xfs_btree_rec *rec, void *priv);

int xfs_btree_query_range(struct xfs_btree_cur *cur,
		union xfs_btree_irec *low_rec, union xfs_btree_irec *high_rec,
		xfs_btree_query_range_fn fn, void *priv);

539 540 541 542 543
typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
		void *data);
int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
		xfs_btree_visit_blocks_fn fn, void *data);

L
Linus Torvalds 已提交
544
#endif	/* __XFS_BTREE_H__ */