hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/fs/xfs/libxfs/xfs_btree.h
....@@ -1,4 +1,4 @@
1
-// SPDX-License-Identifier: GPL-2.0
1
+/* SPDX-License-Identifier: GPL-2.0 */
22 /*
33 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
44 * All Rights Reserved.
....@@ -10,6 +10,7 @@
1010 struct xfs_inode;
1111 struct xfs_mount;
1212 struct xfs_trans;
13
+struct xfs_ifork;
1314
1415 extern kmem_zone_t *xfs_btree_cur_zone;
1516
....@@ -177,12 +178,37 @@
177178 struct xfs_refcount_irec rc;
178179 };
179180
180
-/* Per-AG btree private information. */
181
-union xfs_btree_cur_private {
182
- struct {
183
- unsigned long nr_ops; /* # record updates */
184
- int shape_changes; /* # of extent splits */
185
- } refc;
181
+/* Per-AG btree information. */
182
+struct xfs_btree_cur_ag {
183
+ union {
184
+ struct xfs_buf *agbp;
185
+ struct xbtree_afakeroot *afake; /* for staging cursor */
186
+ };
187
+ xfs_agnumber_t agno;
188
+ union {
189
+ struct {
190
+ unsigned long nr_ops; /* # record updates */
191
+ int shape_changes; /* # of extent splits */
192
+ } refc;
193
+ struct {
194
+ bool active; /* allocation cursor state */
195
+ } abt;
196
+ };
197
+};
198
+
199
+/* Btree-in-inode cursor information */
200
+struct xfs_btree_cur_ino {
201
+ struct xfs_inode *ip;
202
+ struct xbtree_ifakeroot *ifake; /* for staging cursor */
203
+ int allocated;
204
+ short forksize;
205
+ char whichfork;
206
+ char flags;
207
+/* We are converting a delalloc reservation */
208
+#define XFS_BTCUR_BMBT_WASDEL (1 << 0)
209
+
210
+/* For extent swap, ignore owner check in verifier */
211
+#define XFS_BTCUR_BMBT_INVALID_OWNER (1 << 1)
186212 };
187213
188214 /*
....@@ -206,21 +232,9 @@
206232 xfs_btnum_t bc_btnum; /* identifies which btree type */
207233 int bc_statoff; /* offset of btre stats array */
208234 union {
209
- struct { /* needed for BNO, CNT, INO */
210
- struct xfs_buf *agbp; /* agf/agi buffer pointer */
211
- xfs_agnumber_t agno; /* ag number */
212
- union xfs_btree_cur_private priv;
213
- } a;
214
- struct { /* needed for BMAP */
215
- struct xfs_inode *ip; /* pointer to our inode */
216
- int allocated; /* count of alloced */
217
- short forksize; /* fork's inode space */
218
- char whichfork; /* data or attr fork */
219
- char flags; /* flags */
220
-#define XFS_BTCUR_BPRV_WASDEL (1<<0) /* was delayed */
221
-#define XFS_BTCUR_BPRV_INVALID_OWNER (1<<1) /* for ext swap */
222
- } b;
223
- } bc_private; /* per-btree type data */
235
+ struct xfs_btree_cur_ag bc_ag;
236
+ struct xfs_btree_cur_ino bc_ino;
237
+ };
224238 } xfs_btree_cur_t;
225239
226240 /* cursor flags */
....@@ -229,6 +243,12 @@
229243 #define XFS_BTREE_LASTREC_UPDATE (1<<2) /* track last rec externally */
230244 #define XFS_BTREE_CRC_BLOCKS (1<<3) /* uses extended btree blocks */
231245 #define XFS_BTREE_OVERLAPPING (1<<4) /* overlapping intervals */
246
+/*
247
+ * The root of this btree is a fakeroot structure so that we can stage a btree
248
+ * rebuild without leaving it accessible via primary metadata. The ops struct
249
+ * is dynamically allocated and must be freed when the cursor is deleted.
250
+ */
251
+#define XFS_BTREE_STAGING (1<<5)
232252
233253
234254 #define XFS_BTREE_NOERROR 0
....@@ -294,37 +314,6 @@
294314 xfs_btree_cur_t **ncur);/* output cursor */
295315
296316 /*
297
- * Get a buffer for the block, return it with no data read.
298
- * Long-form addressing.
299
- */
300
-struct xfs_buf * /* buffer for fsbno */
301
-xfs_btree_get_bufl(
302
- struct xfs_mount *mp, /* file system mount point */
303
- struct xfs_trans *tp, /* transaction pointer */
304
- xfs_fsblock_t fsbno, /* file system block number */
305
- uint lock); /* lock flags for get_buf */
306
-
307
-/*
308
- * Get a buffer for the block, return it with no data read.
309
- * Short-form addressing.
310
- */
311
-struct xfs_buf * /* buffer for agno/agbno */
312
-xfs_btree_get_bufs(
313
- struct xfs_mount *mp, /* file system mount point */
314
- struct xfs_trans *tp, /* transaction pointer */
315
- xfs_agnumber_t agno, /* allocation group number */
316
- xfs_agblock_t agbno, /* allocation group block number */
317
- uint lock); /* lock flags for get_buf */
318
-
319
-/*
320
- * Check for the cursor referring to the last block at the given level.
321
- */
322
-int /* 1=is last block, 0=not last block */
323
-xfs_btree_islastblock(
324
- xfs_btree_cur_t *cur, /* btree cursor */
325
- int level); /* level to check */
326
-
327
-/*
328317 * Compute first and last byte offsets for the fields given.
329318 * Interprets the offsets table, which contains struct field offsets.
330319 */
....@@ -345,7 +334,6 @@
345334 struct xfs_mount *mp, /* file system mount point */
346335 struct xfs_trans *tp, /* transaction pointer */
347336 xfs_fsblock_t fsbno, /* file system block number */
348
- uint lock, /* lock flags for read_buf */
349337 struct xfs_buf **bpp, /* buffer for fsbno */
350338 int refval, /* ref count value for buffer */
351339 const struct xfs_buf_ops *ops);
....@@ -383,8 +371,7 @@
383371 xfs_btnum_t btnum,
384372 __u16 level,
385373 __u16 numrecs,
386
- __u64 owner,
387
- unsigned int flags);
374
+ __u64 owner);
388375
389376 void
390377 xfs_btree_init_block_int(
....@@ -468,9 +455,13 @@
468455 uint xfs_btree_compute_maxlevels(uint *limits, unsigned long len);
469456 unsigned long long xfs_btree_calc_size(uint *limits, unsigned long long len);
470457
471
-/* return codes */
472
-#define XFS_BTREE_QUERY_RANGE_CONTINUE 0 /* keep iterating */
473
-#define XFS_BTREE_QUERY_RANGE_ABORT 1 /* stop iterating */
458
+/*
459
+ * Return codes for the query range iterator function are 0 to continue
460
+ * iterating, and non-zero to stop iterating. Any non-zero value will be
461
+ * passed up to the _query_range caller. The special value -ECANCELED can be
462
+ * used to stop iteration, because _query_range never generates that error
463
+ * code on its own.
464
+ */
474465 typedef int (*xfs_btree_query_range_fn)(struct xfs_btree_cur *cur,
475466 union xfs_btree_rec *rec, void *priv);
476467
....@@ -482,8 +473,15 @@
482473
483474 typedef int (*xfs_btree_visit_blocks_fn)(struct xfs_btree_cur *cur, int level,
484475 void *data);
476
+/* Visit record blocks. */
477
+#define XFS_BTREE_VISIT_RECORDS (1 << 0)
478
+/* Visit leaf blocks. */
479
+#define XFS_BTREE_VISIT_LEAVES (1 << 1)
480
+/* Visit all blocks. */
481
+#define XFS_BTREE_VISIT_ALL (XFS_BTREE_VISIT_RECORDS | \
482
+ XFS_BTREE_VISIT_LEAVES)
485483 int xfs_btree_visit_blocks(struct xfs_btree_cur *cur,
486
- xfs_btree_visit_blocks_fn fn, void *data);
484
+ xfs_btree_visit_blocks_fn fn, unsigned int flags, void *data);
487485
488486 int xfs_btree_count_blocks(struct xfs_btree_cur *cur, xfs_extlen_t *blocks);
489487
....@@ -513,5 +511,39 @@
513511 int xfs_btree_has_record(struct xfs_btree_cur *cur, union xfs_btree_irec *low,
514512 union xfs_btree_irec *high, bool *exists);
515513 bool xfs_btree_has_more_records(struct xfs_btree_cur *cur);
514
+struct xfs_ifork *xfs_btree_ifork_ptr(struct xfs_btree_cur *cur);
515
+
516
+/* Does this cursor point to the last block in the given level? */
517
+static inline bool
518
+xfs_btree_islastblock(
519
+ xfs_btree_cur_t *cur,
520
+ int level)
521
+{
522
+ struct xfs_btree_block *block;
523
+ struct xfs_buf *bp;
524
+
525
+ block = xfs_btree_get_block(cur, level, &bp);
526
+ ASSERT(block && xfs_btree_check_block(cur, block, level, bp) == 0);
527
+
528
+ if (cur->bc_flags & XFS_BTREE_LONG_PTRS)
529
+ return block->bb_u.l.bb_rightsib == cpu_to_be64(NULLFSBLOCK);
530
+ return block->bb_u.s.bb_rightsib == cpu_to_be32(NULLAGBLOCK);
531
+}
532
+
533
+void xfs_btree_set_ptr_null(struct xfs_btree_cur *cur,
534
+ union xfs_btree_ptr *ptr);
535
+int xfs_btree_get_buf_block(struct xfs_btree_cur *cur, union xfs_btree_ptr *ptr,
536
+ struct xfs_btree_block **block, struct xfs_buf **bpp);
537
+void xfs_btree_set_sibling(struct xfs_btree_cur *cur,
538
+ struct xfs_btree_block *block, union xfs_btree_ptr *ptr,
539
+ int lr);
540
+void xfs_btree_init_block_cur(struct xfs_btree_cur *cur,
541
+ struct xfs_buf *bp, int level, int numrecs);
542
+void xfs_btree_copy_ptrs(struct xfs_btree_cur *cur,
543
+ union xfs_btree_ptr *dst_ptr,
544
+ const union xfs_btree_ptr *src_ptr, int numptrs);
545
+void xfs_btree_copy_keys(struct xfs_btree_cur *cur,
546
+ union xfs_btree_key *dst_key, union xfs_btree_key *src_key,
547
+ int numkeys);
516548
517549 #endif /* __XFS_BTREE_H__ */