aboutsummaryrefslogtreecommitdiffstats
path: root/fs/xfs/xfs_dir2_node.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/xfs/xfs_dir2_node.c')
-rw-r--r--fs/xfs/xfs_dir2_node.c377
1 files changed, 170 insertions, 207 deletions
diff --git a/fs/xfs/xfs_dir2_node.c b/fs/xfs/xfs_dir2_node.c
index 4c3dba7ffb74..48c7d18f68c3 100644
--- a/fs/xfs/xfs_dir2_node.c
+++ b/fs/xfs/xfs_dir2_node.c
@@ -18,22 +18,21 @@
18 */ 18 */
19#include "xfs.h" 19#include "xfs.h"
20#include "xfs_fs.h" 20#include "xfs_fs.h"
21#include "xfs_types.h" 21#include "xfs_format.h"
22#include "xfs_log.h" 22#include "xfs_log_format.h"
23#include "xfs_trans.h" 23#include "xfs_trans_resv.h"
24#include "xfs_sb.h" 24#include "xfs_sb.h"
25#include "xfs_ag.h" 25#include "xfs_ag.h"
26#include "xfs_mount.h" 26#include "xfs_mount.h"
27#include "xfs_da_format.h"
27#include "xfs_da_btree.h" 28#include "xfs_da_btree.h"
28#include "xfs_bmap_btree.h"
29#include "xfs_dinode.h"
30#include "xfs_inode.h" 29#include "xfs_inode.h"
31#include "xfs_bmap.h" 30#include "xfs_bmap.h"
32#include "xfs_dir2_format.h"
33#include "xfs_dir2.h" 31#include "xfs_dir2.h"
34#include "xfs_dir2_priv.h" 32#include "xfs_dir2_priv.h"
35#include "xfs_error.h" 33#include "xfs_error.h"
36#include "xfs_trace.h" 34#include "xfs_trace.h"
35#include "xfs_trans.h"
37#include "xfs_buf_item.h" 36#include "xfs_buf_item.h"
38#include "xfs_cksum.h" 37#include "xfs_cksum.h"
39 38
@@ -55,21 +54,21 @@ static int xfs_dir2_node_addname_int(xfs_da_args_t *args,
55 * Check internal consistency of a leafn block. 54 * Check internal consistency of a leafn block.
56 */ 55 */
57#ifdef DEBUG 56#ifdef DEBUG
58#define xfs_dir3_leaf_check(mp, bp) \ 57#define xfs_dir3_leaf_check(dp, bp) \
59do { \ 58do { \
60 if (!xfs_dir3_leafn_check((mp), (bp))) \ 59 if (!xfs_dir3_leafn_check((dp), (bp))) \
61 ASSERT(0); \ 60 ASSERT(0); \
62} while (0); 61} while (0);
63 62
64static bool 63static bool
65xfs_dir3_leafn_check( 64xfs_dir3_leafn_check(
66 struct xfs_mount *mp, 65 struct xfs_inode *dp,
67 struct xfs_buf *bp) 66 struct xfs_buf *bp)
68{ 67{
69 struct xfs_dir2_leaf *leaf = bp->b_addr; 68 struct xfs_dir2_leaf *leaf = bp->b_addr;
70 struct xfs_dir3_icleaf_hdr leafhdr; 69 struct xfs_dir3_icleaf_hdr leafhdr;
71 70
72 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 71 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
73 72
74 if (leafhdr.magic == XFS_DIR3_LEAFN_MAGIC) { 73 if (leafhdr.magic == XFS_DIR3_LEAFN_MAGIC) {
75 struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr; 74 struct xfs_dir3_leaf_hdr *leaf3 = bp->b_addr;
@@ -78,10 +77,10 @@ xfs_dir3_leafn_check(
78 } else if (leafhdr.magic != XFS_DIR2_LEAFN_MAGIC) 77 } else if (leafhdr.magic != XFS_DIR2_LEAFN_MAGIC)
79 return false; 78 return false;
80 79
81 return xfs_dir3_leaf_check_int(mp, &leafhdr, leaf); 80 return xfs_dir3_leaf_check_int(dp->i_mount, dp, &leafhdr, leaf);
82} 81}
83#else 82#else
84#define xfs_dir3_leaf_check(mp, bp) 83#define xfs_dir3_leaf_check(dp, bp)
85#endif 84#endif
86 85
87static bool 86static bool
@@ -193,53 +192,6 @@ xfs_dir2_free_try_read(
193 return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp); 192 return __xfs_dir3_free_read(tp, dp, fbno, -2, bpp);
194} 193}
195 194
196
197void
198xfs_dir3_free_hdr_from_disk(
199 struct xfs_dir3_icfree_hdr *to,
200 struct xfs_dir2_free *from)
201{
202 if (from->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC)) {
203 to->magic = be32_to_cpu(from->hdr.magic);
204 to->firstdb = be32_to_cpu(from->hdr.firstdb);
205 to->nvalid = be32_to_cpu(from->hdr.nvalid);
206 to->nused = be32_to_cpu(from->hdr.nused);
207 } else {
208 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)from;
209
210 to->magic = be32_to_cpu(hdr3->hdr.magic);
211 to->firstdb = be32_to_cpu(hdr3->firstdb);
212 to->nvalid = be32_to_cpu(hdr3->nvalid);
213 to->nused = be32_to_cpu(hdr3->nused);
214 }
215
216 ASSERT(to->magic == XFS_DIR2_FREE_MAGIC ||
217 to->magic == XFS_DIR3_FREE_MAGIC);
218}
219
220static void
221xfs_dir3_free_hdr_to_disk(
222 struct xfs_dir2_free *to,
223 struct xfs_dir3_icfree_hdr *from)
224{
225 ASSERT(from->magic == XFS_DIR2_FREE_MAGIC ||
226 from->magic == XFS_DIR3_FREE_MAGIC);
227
228 if (from->magic == XFS_DIR2_FREE_MAGIC) {
229 to->hdr.magic = cpu_to_be32(from->magic);
230 to->hdr.firstdb = cpu_to_be32(from->firstdb);
231 to->hdr.nvalid = cpu_to_be32(from->nvalid);
232 to->hdr.nused = cpu_to_be32(from->nused);
233 } else {
234 struct xfs_dir3_free_hdr *hdr3 = (struct xfs_dir3_free_hdr *)to;
235
236 hdr3->hdr.magic = cpu_to_be32(from->magic);
237 hdr3->firstdb = cpu_to_be32(from->firstdb);
238 hdr3->nvalid = cpu_to_be32(from->nvalid);
239 hdr3->nused = cpu_to_be32(from->nused);
240 }
241}
242
243static int 195static int
244xfs_dir3_free_get_buf( 196xfs_dir3_free_get_buf(
245 struct xfs_trans *tp, 197 struct xfs_trans *tp,
@@ -277,7 +229,7 @@ xfs_dir3_free_get_buf(
277 uuid_copy(&hdr3->hdr.uuid, &mp->m_sb.sb_uuid); 229 uuid_copy(&hdr3->hdr.uuid, &mp->m_sb.sb_uuid);
278 } else 230 } else
279 hdr.magic = XFS_DIR2_FREE_MAGIC; 231 hdr.magic = XFS_DIR2_FREE_MAGIC;
280 xfs_dir3_free_hdr_to_disk(bp->b_addr, &hdr); 232 dp->d_ops->free_hdr_to_disk(bp->b_addr, &hdr);
281 *bpp = bp; 233 *bpp = bp;
282 return 0; 234 return 0;
283} 235}
@@ -288,6 +240,7 @@ xfs_dir3_free_get_buf(
288STATIC void 240STATIC void
289xfs_dir2_free_log_bests( 241xfs_dir2_free_log_bests(
290 struct xfs_trans *tp, 242 struct xfs_trans *tp,
243 struct xfs_inode *dp,
291 struct xfs_buf *bp, 244 struct xfs_buf *bp,
292 int first, /* first entry to log */ 245 int first, /* first entry to log */
293 int last) /* last entry to log */ 246 int last) /* last entry to log */
@@ -296,7 +249,7 @@ xfs_dir2_free_log_bests(
296 __be16 *bests; 249 __be16 *bests;
297 250
298 free = bp->b_addr; 251 free = bp->b_addr;
299 bests = xfs_dir3_free_bests_p(tp->t_mountp, free); 252 bests = dp->d_ops->free_bests_p(free);
300 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) || 253 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
301 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC)); 254 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
302 xfs_trans_log_buf(tp, bp, 255 xfs_trans_log_buf(tp, bp,
@@ -311,6 +264,7 @@ xfs_dir2_free_log_bests(
311static void 264static void
312xfs_dir2_free_log_header( 265xfs_dir2_free_log_header(
313 struct xfs_trans *tp, 266 struct xfs_trans *tp,
267 struct xfs_inode *dp,
314 struct xfs_buf *bp) 268 struct xfs_buf *bp)
315{ 269{
316#ifdef DEBUG 270#ifdef DEBUG
@@ -320,7 +274,7 @@ xfs_dir2_free_log_header(
320 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) || 274 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
321 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC)); 275 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
322#endif 276#endif
323 xfs_trans_log_buf(tp, bp, 0, xfs_dir3_free_hdr_size(tp->t_mountp) - 1); 277 xfs_trans_log_buf(tp, bp, 0, dp->d_ops->free_hdr_size - 1);
324} 278}
325 279
326/* 280/*
@@ -369,7 +323,7 @@ xfs_dir2_leaf_to_node(
369 return error; 323 return error;
370 324
371 free = fbp->b_addr; 325 free = fbp->b_addr;
372 xfs_dir3_free_hdr_from_disk(&freehdr, free); 326 dp->d_ops->free_hdr_from_disk(&freehdr, free);
373 leaf = lbp->b_addr; 327 leaf = lbp->b_addr;
374 ltp = xfs_dir2_leaf_tail_p(mp, leaf); 328 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
375 ASSERT(be32_to_cpu(ltp->bestcount) <= 329 ASSERT(be32_to_cpu(ltp->bestcount) <=
@@ -380,7 +334,7 @@ xfs_dir2_leaf_to_node(
380 * Count active entries. 334 * Count active entries.
381 */ 335 */
382 from = xfs_dir2_leaf_bests_p(ltp); 336 from = xfs_dir2_leaf_bests_p(ltp);
383 to = xfs_dir3_free_bests_p(mp, free); 337 to = dp->d_ops->free_bests_p(free);
384 for (i = n = 0; i < be32_to_cpu(ltp->bestcount); i++, from++, to++) { 338 for (i = n = 0; i < be32_to_cpu(ltp->bestcount); i++, from++, to++) {
385 if ((off = be16_to_cpu(*from)) != NULLDATAOFF) 339 if ((off = be16_to_cpu(*from)) != NULLDATAOFF)
386 n++; 340 n++;
@@ -393,9 +347,9 @@ xfs_dir2_leaf_to_node(
393 freehdr.nused = n; 347 freehdr.nused = n;
394 freehdr.nvalid = be32_to_cpu(ltp->bestcount); 348 freehdr.nvalid = be32_to_cpu(ltp->bestcount);
395 349
396 xfs_dir3_free_hdr_to_disk(fbp->b_addr, &freehdr); 350 dp->d_ops->free_hdr_to_disk(fbp->b_addr, &freehdr);
397 xfs_dir2_free_log_bests(tp, fbp, 0, freehdr.nvalid - 1); 351 xfs_dir2_free_log_bests(tp, dp, fbp, 0, freehdr.nvalid - 1);
398 xfs_dir2_free_log_header(tp, fbp); 352 xfs_dir2_free_log_header(tp, dp, fbp);
399 353
400 /* 354 /*
401 * Converting the leaf to a leafnode is just a matter of changing the 355 * Converting the leaf to a leafnode is just a matter of changing the
@@ -409,8 +363,8 @@ xfs_dir2_leaf_to_node(
409 leaf->hdr.info.magic = cpu_to_be16(XFS_DIR3_LEAFN_MAGIC); 363 leaf->hdr.info.magic = cpu_to_be16(XFS_DIR3_LEAFN_MAGIC);
410 lbp->b_ops = &xfs_dir3_leafn_buf_ops; 364 lbp->b_ops = &xfs_dir3_leafn_buf_ops;
411 xfs_trans_buf_set_type(tp, lbp, XFS_BLFT_DIR_LEAFN_BUF); 365 xfs_trans_buf_set_type(tp, lbp, XFS_BLFT_DIR_LEAFN_BUF);
412 xfs_dir3_leaf_log_header(tp, lbp); 366 xfs_dir3_leaf_log_header(tp, dp, lbp);
413 xfs_dir3_leaf_check(mp, lbp); 367 xfs_dir3_leaf_check(dp, lbp);
414 return 0; 368 return 0;
415} 369}
416 370
@@ -443,8 +397,8 @@ xfs_dir2_leafn_add(
443 mp = dp->i_mount; 397 mp = dp->i_mount;
444 tp = args->trans; 398 tp = args->trans;
445 leaf = bp->b_addr; 399 leaf = bp->b_addr;
446 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 400 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
447 ents = xfs_dir3_leaf_ents_p(leaf); 401 ents = dp->d_ops->leaf_ents_p(leaf);
448 402
449 /* 403 /*
450 * Quick check just to make sure we are not going to index 404 * Quick check just to make sure we are not going to index
@@ -460,7 +414,7 @@ xfs_dir2_leafn_add(
460 * a compact. 414 * a compact.
461 */ 415 */
462 416
463 if (leafhdr.count == xfs_dir3_max_leaf_ents(mp, leaf)) { 417 if (leafhdr.count == dp->d_ops->leaf_max_ents(mp)) {
464 if (!leafhdr.stale) 418 if (!leafhdr.stale)
465 return XFS_ERROR(ENOSPC); 419 return XFS_ERROR(ENOSPC);
466 compact = leafhdr.stale > 1; 420 compact = leafhdr.stale > 1;
@@ -498,30 +452,30 @@ xfs_dir2_leafn_add(
498 lep->address = cpu_to_be32(xfs_dir2_db_off_to_dataptr(mp, 452 lep->address = cpu_to_be32(xfs_dir2_db_off_to_dataptr(mp,
499 args->blkno, args->index)); 453 args->blkno, args->index));
500 454
501 xfs_dir3_leaf_hdr_to_disk(leaf, &leafhdr); 455 dp->d_ops->leaf_hdr_to_disk(leaf, &leafhdr);
502 xfs_dir3_leaf_log_header(tp, bp); 456 xfs_dir3_leaf_log_header(tp, dp, bp);
503 xfs_dir3_leaf_log_ents(tp, bp, lfloglow, lfloghigh); 457 xfs_dir3_leaf_log_ents(tp, dp, bp, lfloglow, lfloghigh);
504 xfs_dir3_leaf_check(mp, bp); 458 xfs_dir3_leaf_check(dp, bp);
505 return 0; 459 return 0;
506} 460}
507 461
508#ifdef DEBUG 462#ifdef DEBUG
509static void 463static void
510xfs_dir2_free_hdr_check( 464xfs_dir2_free_hdr_check(
511 struct xfs_mount *mp, 465 struct xfs_inode *dp,
512 struct xfs_buf *bp, 466 struct xfs_buf *bp,
513 xfs_dir2_db_t db) 467 xfs_dir2_db_t db)
514{ 468{
515 struct xfs_dir3_icfree_hdr hdr; 469 struct xfs_dir3_icfree_hdr hdr;
516 470
517 xfs_dir3_free_hdr_from_disk(&hdr, bp->b_addr); 471 dp->d_ops->free_hdr_from_disk(&hdr, bp->b_addr);
518 472
519 ASSERT((hdr.firstdb % xfs_dir3_free_max_bests(mp)) == 0); 473 ASSERT((hdr.firstdb % dp->d_ops->free_max_bests(dp->i_mount)) == 0);
520 ASSERT(hdr.firstdb <= db); 474 ASSERT(hdr.firstdb <= db);
521 ASSERT(db < hdr.firstdb + hdr.nvalid); 475 ASSERT(db < hdr.firstdb + hdr.nvalid);
522} 476}
523#else 477#else
524#define xfs_dir2_free_hdr_check(mp, dp, db) 478#define xfs_dir2_free_hdr_check(dp, bp, db)
525#endif /* DEBUG */ 479#endif /* DEBUG */
526 480
527/* 481/*
@@ -530,6 +484,7 @@ xfs_dir2_free_hdr_check(
530 */ 484 */
531xfs_dahash_t /* hash value */ 485xfs_dahash_t /* hash value */
532xfs_dir2_leafn_lasthash( 486xfs_dir2_leafn_lasthash(
487 struct xfs_inode *dp,
533 struct xfs_buf *bp, /* leaf buffer */ 488 struct xfs_buf *bp, /* leaf buffer */
534 int *count) /* count of entries in leaf */ 489 int *count) /* count of entries in leaf */
535{ 490{
@@ -537,7 +492,7 @@ xfs_dir2_leafn_lasthash(
537 struct xfs_dir2_leaf_entry *ents; 492 struct xfs_dir2_leaf_entry *ents;
538 struct xfs_dir3_icleaf_hdr leafhdr; 493 struct xfs_dir3_icleaf_hdr leafhdr;
539 494
540 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 495 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
541 496
542 ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC || 497 ASSERT(leafhdr.magic == XFS_DIR2_LEAFN_MAGIC ||
543 leafhdr.magic == XFS_DIR3_LEAFN_MAGIC); 498 leafhdr.magic == XFS_DIR3_LEAFN_MAGIC);
@@ -547,7 +502,7 @@ xfs_dir2_leafn_lasthash(
547 if (!leafhdr.count) 502 if (!leafhdr.count)
548 return 0; 503 return 0;
549 504
550 ents = xfs_dir3_leaf_ents_p(leaf); 505 ents = dp->d_ops->leaf_ents_p(leaf);
551 return be32_to_cpu(ents[leafhdr.count - 1].hashval); 506 return be32_to_cpu(ents[leafhdr.count - 1].hashval);
552} 507}
553 508
@@ -584,10 +539,10 @@ xfs_dir2_leafn_lookup_for_addname(
584 tp = args->trans; 539 tp = args->trans;
585 mp = dp->i_mount; 540 mp = dp->i_mount;
586 leaf = bp->b_addr; 541 leaf = bp->b_addr;
587 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 542 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
588 ents = xfs_dir3_leaf_ents_p(leaf); 543 ents = dp->d_ops->leaf_ents_p(leaf);
589 544
590 xfs_dir3_leaf_check(mp, bp); 545 xfs_dir3_leaf_check(dp, bp);
591 ASSERT(leafhdr.count > 0); 546 ASSERT(leafhdr.count > 0);
592 547
593 /* 548 /*
@@ -605,7 +560,7 @@ xfs_dir2_leafn_lookup_for_addname(
605 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) || 560 ASSERT(free->hdr.magic == cpu_to_be32(XFS_DIR2_FREE_MAGIC) ||
606 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC)); 561 free->hdr.magic == cpu_to_be32(XFS_DIR3_FREE_MAGIC));
607 } 562 }
608 length = xfs_dir3_data_entsize(mp, args->namelen); 563 length = dp->d_ops->data_entsize(args->namelen);
609 /* 564 /*
610 * Loop over leaf entries with the right hash value. 565 * Loop over leaf entries with the right hash value.
611 */ 566 */
@@ -637,7 +592,7 @@ xfs_dir2_leafn_lookup_for_addname(
637 * Convert the data block to the free block 592 * Convert the data block to the free block
638 * holding its freespace information. 593 * holding its freespace information.
639 */ 594 */
640 newfdb = xfs_dir2_db_to_fdb(mp, newdb); 595 newfdb = dp->d_ops->db_to_fdb(mp, newdb);
641 /* 596 /*
642 * If it's not the one we have in hand, read it in. 597 * If it's not the one we have in hand, read it in.
643 */ 598 */
@@ -655,16 +610,16 @@ xfs_dir2_leafn_lookup_for_addname(
655 return error; 610 return error;
656 free = curbp->b_addr; 611 free = curbp->b_addr;
657 612
658 xfs_dir2_free_hdr_check(mp, curbp, curdb); 613 xfs_dir2_free_hdr_check(dp, curbp, curdb);
659 } 614 }
660 /* 615 /*
661 * Get the index for our entry. 616 * Get the index for our entry.
662 */ 617 */
663 fi = xfs_dir2_db_to_fdindex(mp, curdb); 618 fi = dp->d_ops->db_to_fdindex(mp, curdb);
664 /* 619 /*
665 * If it has room, return it. 620 * If it has room, return it.
666 */ 621 */
667 bests = xfs_dir3_free_bests_p(mp, free); 622 bests = dp->d_ops->free_bests_p(free);
668 if (unlikely(bests[fi] == cpu_to_be16(NULLDATAOFF))) { 623 if (unlikely(bests[fi] == cpu_to_be16(NULLDATAOFF))) {
669 XFS_ERROR_REPORT("xfs_dir2_leafn_lookup_int", 624 XFS_ERROR_REPORT("xfs_dir2_leafn_lookup_int",
670 XFS_ERRLEVEL_LOW, mp); 625 XFS_ERRLEVEL_LOW, mp);
@@ -734,10 +689,10 @@ xfs_dir2_leafn_lookup_for_entry(
734 tp = args->trans; 689 tp = args->trans;
735 mp = dp->i_mount; 690 mp = dp->i_mount;
736 leaf = bp->b_addr; 691 leaf = bp->b_addr;
737 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 692 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
738 ents = xfs_dir3_leaf_ents_p(leaf); 693 ents = dp->d_ops->leaf_ents_p(leaf);
739 694
740 xfs_dir3_leaf_check(mp, bp); 695 xfs_dir3_leaf_check(dp, bp);
741 ASSERT(leafhdr.count > 0); 696 ASSERT(leafhdr.count > 0);
742 697
743 /* 698 /*
@@ -816,7 +771,7 @@ xfs_dir2_leafn_lookup_for_entry(
816 xfs_trans_brelse(tp, state->extrablk.bp); 771 xfs_trans_brelse(tp, state->extrablk.bp);
817 args->cmpresult = cmp; 772 args->cmpresult = cmp;
818 args->inumber = be64_to_cpu(dep->inumber); 773 args->inumber = be64_to_cpu(dep->inumber);
819 args->filetype = xfs_dir3_dirent_get_ftype(mp, dep); 774 args->filetype = dp->d_ops->data_get_ftype(dep);
820 *indexp = index; 775 *indexp = index;
821 state->extravalid = 1; 776 state->extravalid = 1;
822 state->extrablk.bp = curbp; 777 state->extrablk.bp = curbp;
@@ -907,7 +862,7 @@ xfs_dir3_leafn_moveents(
907 if (start_d < dhdr->count) { 862 if (start_d < dhdr->count) {
908 memmove(&dents[start_d + count], &dents[start_d], 863 memmove(&dents[start_d + count], &dents[start_d],
909 (dhdr->count - start_d) * sizeof(xfs_dir2_leaf_entry_t)); 864 (dhdr->count - start_d) * sizeof(xfs_dir2_leaf_entry_t));
910 xfs_dir3_leaf_log_ents(tp, bp_d, start_d + count, 865 xfs_dir3_leaf_log_ents(tp, args->dp, bp_d, start_d + count,
911 count + dhdr->count - 1); 866 count + dhdr->count - 1);
912 } 867 }
913 /* 868 /*
@@ -929,7 +884,8 @@ xfs_dir3_leafn_moveents(
929 */ 884 */
930 memcpy(&dents[start_d], &sents[start_s], 885 memcpy(&dents[start_d], &sents[start_s],
931 count * sizeof(xfs_dir2_leaf_entry_t)); 886 count * sizeof(xfs_dir2_leaf_entry_t));
932 xfs_dir3_leaf_log_ents(tp, bp_d, start_d, start_d + count - 1); 887 xfs_dir3_leaf_log_ents(tp, args->dp, bp_d,
888 start_d, start_d + count - 1);
933 889
934 /* 890 /*
935 * If there are source entries after the ones we copied, 891 * If there are source entries after the ones we copied,
@@ -938,7 +894,8 @@ xfs_dir3_leafn_moveents(
938 if (start_s + count < shdr->count) { 894 if (start_s + count < shdr->count) {
939 memmove(&sents[start_s], &sents[start_s + count], 895 memmove(&sents[start_s], &sents[start_s + count],
940 count * sizeof(xfs_dir2_leaf_entry_t)); 896 count * sizeof(xfs_dir2_leaf_entry_t));
941 xfs_dir3_leaf_log_ents(tp, bp_s, start_s, start_s + count - 1); 897 xfs_dir3_leaf_log_ents(tp, args->dp, bp_s,
898 start_s, start_s + count - 1);
942 } 899 }
943 900
944 /* 901 /*
@@ -956,6 +913,7 @@ xfs_dir3_leafn_moveents(
956 */ 913 */
957int /* sort order */ 914int /* sort order */
958xfs_dir2_leafn_order( 915xfs_dir2_leafn_order(
916 struct xfs_inode *dp,
959 struct xfs_buf *leaf1_bp, /* leaf1 buffer */ 917 struct xfs_buf *leaf1_bp, /* leaf1 buffer */
960 struct xfs_buf *leaf2_bp) /* leaf2 buffer */ 918 struct xfs_buf *leaf2_bp) /* leaf2 buffer */
961{ 919{
@@ -966,10 +924,10 @@ xfs_dir2_leafn_order(
966 struct xfs_dir3_icleaf_hdr hdr1; 924 struct xfs_dir3_icleaf_hdr hdr1;
967 struct xfs_dir3_icleaf_hdr hdr2; 925 struct xfs_dir3_icleaf_hdr hdr2;
968 926
969 xfs_dir3_leaf_hdr_from_disk(&hdr1, leaf1); 927 dp->d_ops->leaf_hdr_from_disk(&hdr1, leaf1);
970 xfs_dir3_leaf_hdr_from_disk(&hdr2, leaf2); 928 dp->d_ops->leaf_hdr_from_disk(&hdr2, leaf2);
971 ents1 = xfs_dir3_leaf_ents_p(leaf1); 929 ents1 = dp->d_ops->leaf_ents_p(leaf1);
972 ents2 = xfs_dir3_leaf_ents_p(leaf2); 930 ents2 = dp->d_ops->leaf_ents_p(leaf2);
973 931
974 if (hdr1.count > 0 && hdr2.count > 0 && 932 if (hdr1.count > 0 && hdr2.count > 0 &&
975 (be32_to_cpu(ents2[0].hashval) < be32_to_cpu(ents1[0].hashval) || 933 (be32_to_cpu(ents2[0].hashval) < be32_to_cpu(ents1[0].hashval) ||
@@ -1007,12 +965,13 @@ xfs_dir2_leafn_rebalance(
1007 struct xfs_dir2_leaf_entry *ents2; 965 struct xfs_dir2_leaf_entry *ents2;
1008 struct xfs_dir3_icleaf_hdr hdr1; 966 struct xfs_dir3_icleaf_hdr hdr1;
1009 struct xfs_dir3_icleaf_hdr hdr2; 967 struct xfs_dir3_icleaf_hdr hdr2;
968 struct xfs_inode *dp = state->args->dp;
1010 969
1011 args = state->args; 970 args = state->args;
1012 /* 971 /*
1013 * If the block order is wrong, swap the arguments. 972 * If the block order is wrong, swap the arguments.
1014 */ 973 */
1015 if ((swap = xfs_dir2_leafn_order(blk1->bp, blk2->bp))) { 974 if ((swap = xfs_dir2_leafn_order(dp, blk1->bp, blk2->bp))) {
1016 xfs_da_state_blk_t *tmp; /* temp for block swap */ 975 xfs_da_state_blk_t *tmp; /* temp for block swap */
1017 976
1018 tmp = blk1; 977 tmp = blk1;
@@ -1021,10 +980,10 @@ xfs_dir2_leafn_rebalance(
1021 } 980 }
1022 leaf1 = blk1->bp->b_addr; 981 leaf1 = blk1->bp->b_addr;
1023 leaf2 = blk2->bp->b_addr; 982 leaf2 = blk2->bp->b_addr;
1024 xfs_dir3_leaf_hdr_from_disk(&hdr1, leaf1); 983 dp->d_ops->leaf_hdr_from_disk(&hdr1, leaf1);
1025 xfs_dir3_leaf_hdr_from_disk(&hdr2, leaf2); 984 dp->d_ops->leaf_hdr_from_disk(&hdr2, leaf2);
1026 ents1 = xfs_dir3_leaf_ents_p(leaf1); 985 ents1 = dp->d_ops->leaf_ents_p(leaf1);
1027 ents2 = xfs_dir3_leaf_ents_p(leaf2); 986 ents2 = dp->d_ops->leaf_ents_p(leaf2);
1028 987
1029 oldsum = hdr1.count + hdr2.count; 988 oldsum = hdr1.count + hdr2.count;
1030#if defined(DEBUG) || defined(XFS_WARN) 989#if defined(DEBUG) || defined(XFS_WARN)
@@ -1070,13 +1029,13 @@ xfs_dir2_leafn_rebalance(
1070 ASSERT(hdr1.stale + hdr2.stale == oldstale); 1029 ASSERT(hdr1.stale + hdr2.stale == oldstale);
1071 1030
1072 /* log the changes made when moving the entries */ 1031 /* log the changes made when moving the entries */
1073 xfs_dir3_leaf_hdr_to_disk(leaf1, &hdr1); 1032 dp->d_ops->leaf_hdr_to_disk(leaf1, &hdr1);
1074 xfs_dir3_leaf_hdr_to_disk(leaf2, &hdr2); 1033 dp->d_ops->leaf_hdr_to_disk(leaf2, &hdr2);
1075 xfs_dir3_leaf_log_header(args->trans, blk1->bp); 1034 xfs_dir3_leaf_log_header(args->trans, dp, blk1->bp);
1076 xfs_dir3_leaf_log_header(args->trans, blk2->bp); 1035 xfs_dir3_leaf_log_header(args->trans, dp, blk2->bp);
1077 1036
1078 xfs_dir3_leaf_check(args->dp->i_mount, blk1->bp); 1037 xfs_dir3_leaf_check(dp, blk1->bp);
1079 xfs_dir3_leaf_check(args->dp->i_mount, blk2->bp); 1038 xfs_dir3_leaf_check(dp, blk2->bp);
1080 1039
1081 /* 1040 /*
1082 * Mark whether we're inserting into the old or new leaf. 1041 * Mark whether we're inserting into the old or new leaf.
@@ -1097,11 +1056,11 @@ xfs_dir2_leafn_rebalance(
1097 * Finally sanity check just to make sure we are not returning a 1056 * Finally sanity check just to make sure we are not returning a
1098 * negative index 1057 * negative index
1099 */ 1058 */
1100 if(blk2->index < 0) { 1059 if (blk2->index < 0) {
1101 state->inleaf = 1; 1060 state->inleaf = 1;
1102 blk2->index = 0; 1061 blk2->index = 0;
1103 xfs_alert(args->dp->i_mount, 1062 xfs_alert(dp->i_mount,
1104 "%s: picked the wrong leaf? reverting original leaf: blk1->index %d\n", 1063 "%s: picked the wrong leaf? reverting original leaf: blk1->index %d",
1105 __func__, blk1->index); 1064 __func__, blk1->index);
1106 } 1065 }
1107} 1066}
@@ -1120,17 +1079,17 @@ xfs_dir3_data_block_free(
1120 int logfree = 0; 1079 int logfree = 0;
1121 __be16 *bests; 1080 __be16 *bests;
1122 struct xfs_dir3_icfree_hdr freehdr; 1081 struct xfs_dir3_icfree_hdr freehdr;
1082 struct xfs_inode *dp = args->dp;
1123 1083
1124 xfs_dir3_free_hdr_from_disk(&freehdr, free); 1084 dp->d_ops->free_hdr_from_disk(&freehdr, free);
1125 1085 bests = dp->d_ops->free_bests_p(free);
1126 bests = xfs_dir3_free_bests_p(tp->t_mountp, free);
1127 if (hdr) { 1086 if (hdr) {
1128 /* 1087 /*
1129 * Data block is not empty, just set the free entry to the new 1088 * Data block is not empty, just set the free entry to the new
1130 * value. 1089 * value.
1131 */ 1090 */
1132 bests[findex] = cpu_to_be16(longest); 1091 bests[findex] = cpu_to_be16(longest);
1133 xfs_dir2_free_log_bests(tp, fbp, findex, findex); 1092 xfs_dir2_free_log_bests(tp, dp, fbp, findex, findex);
1134 return 0; 1093 return 0;
1135 } 1094 }
1136 1095
@@ -1157,8 +1116,8 @@ xfs_dir3_data_block_free(
1157 logfree = 1; 1116 logfree = 1;
1158 } 1117 }
1159 1118
1160 xfs_dir3_free_hdr_to_disk(free, &freehdr); 1119 dp->d_ops->free_hdr_to_disk(free, &freehdr);
1161 xfs_dir2_free_log_header(tp, fbp); 1120 xfs_dir2_free_log_header(tp, dp, fbp);
1162 1121
1163 /* 1122 /*
1164 * If there are no useful entries left in the block, get rid of the 1123 * If there are no useful entries left in the block, get rid of the
@@ -1182,7 +1141,7 @@ xfs_dir3_data_block_free(
1182 1141
1183 /* Log the free entry that changed, unless we got rid of it. */ 1142 /* Log the free entry that changed, unless we got rid of it. */
1184 if (logfree) 1143 if (logfree)
1185 xfs_dir2_free_log_bests(tp, fbp, findex, findex); 1144 xfs_dir2_free_log_bests(tp, dp, fbp, findex, findex);
1186 return 0; 1145 return 0;
1187} 1146}
1188 1147
@@ -1222,8 +1181,8 @@ xfs_dir2_leafn_remove(
1222 tp = args->trans; 1181 tp = args->trans;
1223 mp = dp->i_mount; 1182 mp = dp->i_mount;
1224 leaf = bp->b_addr; 1183 leaf = bp->b_addr;
1225 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 1184 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
1226 ents = xfs_dir3_leaf_ents_p(leaf); 1185 ents = dp->d_ops->leaf_ents_p(leaf);
1227 1186
1228 /* 1187 /*
1229 * Point to the entry we're removing. 1188 * Point to the entry we're removing.
@@ -1243,11 +1202,11 @@ xfs_dir2_leafn_remove(
1243 * Log the leaf block changes. 1202 * Log the leaf block changes.
1244 */ 1203 */
1245 leafhdr.stale++; 1204 leafhdr.stale++;
1246 xfs_dir3_leaf_hdr_to_disk(leaf, &leafhdr); 1205 dp->d_ops->leaf_hdr_to_disk(leaf, &leafhdr);
1247 xfs_dir3_leaf_log_header(tp, bp); 1206 xfs_dir3_leaf_log_header(tp, dp, bp);
1248 1207
1249 lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR); 1208 lep->address = cpu_to_be32(XFS_DIR2_NULL_DATAPTR);
1250 xfs_dir3_leaf_log_ents(tp, bp, index, index); 1209 xfs_dir3_leaf_log_ents(tp, dp, bp, index, index);
1251 1210
1252 /* 1211 /*
1253 * Make the data entry free. Keep track of the longest freespace 1212 * Make the data entry free. Keep track of the longest freespace
@@ -1256,19 +1215,19 @@ xfs_dir2_leafn_remove(
1256 dbp = dblk->bp; 1215 dbp = dblk->bp;
1257 hdr = dbp->b_addr; 1216 hdr = dbp->b_addr;
1258 dep = (xfs_dir2_data_entry_t *)((char *)hdr + off); 1217 dep = (xfs_dir2_data_entry_t *)((char *)hdr + off);
1259 bf = xfs_dir3_data_bestfree_p(hdr); 1218 bf = dp->d_ops->data_bestfree_p(hdr);
1260 longest = be16_to_cpu(bf[0].length); 1219 longest = be16_to_cpu(bf[0].length);
1261 needlog = needscan = 0; 1220 needlog = needscan = 0;
1262 xfs_dir2_data_make_free(tp, dbp, off, 1221 xfs_dir2_data_make_free(tp, dp, dbp, off,
1263 xfs_dir3_data_entsize(mp, dep->namelen), &needlog, &needscan); 1222 dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
1264 /* 1223 /*
1265 * Rescan the data block freespaces for bestfree. 1224 * Rescan the data block freespaces for bestfree.
1266 * Log the data block header if needed. 1225 * Log the data block header if needed.
1267 */ 1226 */
1268 if (needscan) 1227 if (needscan)
1269 xfs_dir2_data_freescan(mp, hdr, &needlog); 1228 xfs_dir2_data_freescan(dp, hdr, &needlog);
1270 if (needlog) 1229 if (needlog)
1271 xfs_dir2_data_log_header(tp, dbp); 1230 xfs_dir2_data_log_header(tp, dp, dbp);
1272 xfs_dir3_data_check(dp, dbp); 1231 xfs_dir3_data_check(dp, dbp);
1273 /* 1232 /*
1274 * If the longest data block freespace changes, need to update 1233 * If the longest data block freespace changes, need to update
@@ -1285,7 +1244,7 @@ xfs_dir2_leafn_remove(
1285 * Convert the data block number to a free block, 1244 * Convert the data block number to a free block,
1286 * read in the free block. 1245 * read in the free block.
1287 */ 1246 */
1288 fdb = xfs_dir2_db_to_fdb(mp, db); 1247 fdb = dp->d_ops->db_to_fdb(mp, db);
1289 error = xfs_dir2_free_read(tp, dp, xfs_dir2_db_to_da(mp, fdb), 1248 error = xfs_dir2_free_read(tp, dp, xfs_dir2_db_to_da(mp, fdb),
1290 &fbp); 1249 &fbp);
1291 if (error) 1250 if (error)
@@ -1294,22 +1253,22 @@ xfs_dir2_leafn_remove(
1294#ifdef DEBUG 1253#ifdef DEBUG
1295 { 1254 {
1296 struct xfs_dir3_icfree_hdr freehdr; 1255 struct xfs_dir3_icfree_hdr freehdr;
1297 xfs_dir3_free_hdr_from_disk(&freehdr, free); 1256 dp->d_ops->free_hdr_from_disk(&freehdr, free);
1298 ASSERT(freehdr.firstdb == xfs_dir3_free_max_bests(mp) * 1257 ASSERT(freehdr.firstdb == dp->d_ops->free_max_bests(mp) *
1299 (fdb - XFS_DIR2_FREE_FIRSTDB(mp))); 1258 (fdb - XFS_DIR2_FREE_FIRSTDB(mp)));
1300 } 1259 }
1301#endif 1260#endif
1302 /* 1261 /*
1303 * Calculate which entry we need to fix. 1262 * Calculate which entry we need to fix.
1304 */ 1263 */
1305 findex = xfs_dir2_db_to_fdindex(mp, db); 1264 findex = dp->d_ops->db_to_fdindex(mp, db);
1306 longest = be16_to_cpu(bf[0].length); 1265 longest = be16_to_cpu(bf[0].length);
1307 /* 1266 /*
1308 * If the data block is now empty we can get rid of it 1267 * If the data block is now empty we can get rid of it
1309 * (usually). 1268 * (usually).
1310 */ 1269 */
1311 if (longest == mp->m_dirblksize - 1270 if (longest == mp->m_dirblksize -
1312 xfs_dir3_data_entry_offset(hdr)) { 1271 dp->d_ops->data_entry_offset) {
1313 /* 1272 /*
1314 * Try to punch out the data block. 1273 * Try to punch out the data block.
1315 */ 1274 */
@@ -1336,12 +1295,12 @@ xfs_dir2_leafn_remove(
1336 return error; 1295 return error;
1337 } 1296 }
1338 1297
1339 xfs_dir3_leaf_check(mp, bp); 1298 xfs_dir3_leaf_check(dp, bp);
1340 /* 1299 /*
1341 * Return indication of whether this leaf block is empty enough 1300 * Return indication of whether this leaf block is empty enough
1342 * to justify trying to join it with a neighbor. 1301 * to justify trying to join it with a neighbor.
1343 */ 1302 */
1344 *rval = (xfs_dir3_leaf_hdr_size(leaf) + 1303 *rval = (dp->d_ops->leaf_hdr_size +
1345 (uint)sizeof(ents[0]) * (leafhdr.count - leafhdr.stale)) < 1304 (uint)sizeof(ents[0]) * (leafhdr.count - leafhdr.stale)) <
1346 mp->m_dir_magicpct; 1305 mp->m_dir_magicpct;
1347 return 0; 1306 return 0;
@@ -1360,13 +1319,14 @@ xfs_dir2_leafn_split(
1360 xfs_dablk_t blkno; /* new leaf block number */ 1319 xfs_dablk_t blkno; /* new leaf block number */
1361 int error; /* error return value */ 1320 int error; /* error return value */
1362 xfs_mount_t *mp; /* filesystem mount point */ 1321 xfs_mount_t *mp; /* filesystem mount point */
1322 struct xfs_inode *dp;
1363 1323
1364 /* 1324 /*
1365 * Allocate space for a new leaf node. 1325 * Allocate space for a new leaf node.
1366 */ 1326 */
1367 args = state->args; 1327 args = state->args;
1368 mp = args->dp->i_mount; 1328 dp = args->dp;
1369 ASSERT(args != NULL); 1329 mp = dp->i_mount;
1370 ASSERT(oldblk->magic == XFS_DIR2_LEAFN_MAGIC); 1330 ASSERT(oldblk->magic == XFS_DIR2_LEAFN_MAGIC);
1371 error = xfs_da_grow_inode(args, &blkno); 1331 error = xfs_da_grow_inode(args, &blkno);
1372 if (error) { 1332 if (error) {
@@ -1401,10 +1361,10 @@ xfs_dir2_leafn_split(
1401 /* 1361 /*
1402 * Update last hashval in each block since we added the name. 1362 * Update last hashval in each block since we added the name.
1403 */ 1363 */
1404 oldblk->hashval = xfs_dir2_leafn_lasthash(oldblk->bp, NULL); 1364 oldblk->hashval = xfs_dir2_leafn_lasthash(dp, oldblk->bp, NULL);
1405 newblk->hashval = xfs_dir2_leafn_lasthash(newblk->bp, NULL); 1365 newblk->hashval = xfs_dir2_leafn_lasthash(dp, newblk->bp, NULL);
1406 xfs_dir3_leaf_check(mp, oldblk->bp); 1366 xfs_dir3_leaf_check(dp, oldblk->bp);
1407 xfs_dir3_leaf_check(mp, newblk->bp); 1367 xfs_dir3_leaf_check(dp, newblk->bp);
1408 return error; 1368 return error;
1409} 1369}
1410 1370
@@ -1434,6 +1394,7 @@ xfs_dir2_leafn_toosmall(
1434 int rval; /* result from path_shift */ 1394 int rval; /* result from path_shift */
1435 struct xfs_dir3_icleaf_hdr leafhdr; 1395 struct xfs_dir3_icleaf_hdr leafhdr;
1436 struct xfs_dir2_leaf_entry *ents; 1396 struct xfs_dir2_leaf_entry *ents;
1397 struct xfs_inode *dp = state->args->dp;
1437 1398
1438 /* 1399 /*
1439 * Check for the degenerate case of the block being over 50% full. 1400 * Check for the degenerate case of the block being over 50% full.
@@ -1442,12 +1403,12 @@ xfs_dir2_leafn_toosmall(
1442 */ 1403 */
1443 blk = &state->path.blk[state->path.active - 1]; 1404 blk = &state->path.blk[state->path.active - 1];
1444 leaf = blk->bp->b_addr; 1405 leaf = blk->bp->b_addr;
1445 xfs_dir3_leaf_hdr_from_disk(&leafhdr, leaf); 1406 dp->d_ops->leaf_hdr_from_disk(&leafhdr, leaf);
1446 ents = xfs_dir3_leaf_ents_p(leaf); 1407 ents = dp->d_ops->leaf_ents_p(leaf);
1447 xfs_dir3_leaf_check(state->args->dp->i_mount, blk->bp); 1408 xfs_dir3_leaf_check(dp, blk->bp);
1448 1409
1449 count = leafhdr.count - leafhdr.stale; 1410 count = leafhdr.count - leafhdr.stale;
1450 bytes = xfs_dir3_leaf_hdr_size(leaf) + count * sizeof(ents[0]); 1411 bytes = dp->d_ops->leaf_hdr_size + count * sizeof(ents[0]);
1451 if (bytes > (state->blocksize >> 1)) { 1412 if (bytes > (state->blocksize >> 1)) {
1452 /* 1413 /*
1453 * Blk over 50%, don't try to join. 1414 * Blk over 50%, don't try to join.
@@ -1492,7 +1453,7 @@ xfs_dir2_leafn_toosmall(
1492 /* 1453 /*
1493 * Read the sibling leaf block. 1454 * Read the sibling leaf block.
1494 */ 1455 */
1495 error = xfs_dir3_leafn_read(state->args->trans, state->args->dp, 1456 error = xfs_dir3_leafn_read(state->args->trans, dp,
1496 blkno, -1, &bp); 1457 blkno, -1, &bp);
1497 if (error) 1458 if (error)
1498 return error; 1459 return error;
@@ -1504,8 +1465,8 @@ xfs_dir2_leafn_toosmall(
1504 bytes = state->blocksize - (state->blocksize >> 2); 1465 bytes = state->blocksize - (state->blocksize >> 2);
1505 1466
1506 leaf = bp->b_addr; 1467 leaf = bp->b_addr;
1507 xfs_dir3_leaf_hdr_from_disk(&hdr2, leaf); 1468 dp->d_ops->leaf_hdr_from_disk(&hdr2, leaf);
1508 ents = xfs_dir3_leaf_ents_p(leaf); 1469 ents = dp->d_ops->leaf_ents_p(leaf);
1509 count += hdr2.count - hdr2.stale; 1470 count += hdr2.count - hdr2.stale;
1510 bytes -= count * sizeof(ents[0]); 1471 bytes -= count * sizeof(ents[0]);
1511 1472
@@ -1559,6 +1520,7 @@ xfs_dir2_leafn_unbalance(
1559 struct xfs_dir3_icleaf_hdr drophdr; 1520 struct xfs_dir3_icleaf_hdr drophdr;
1560 struct xfs_dir2_leaf_entry *sents; 1521 struct xfs_dir2_leaf_entry *sents;
1561 struct xfs_dir2_leaf_entry *dents; 1522 struct xfs_dir2_leaf_entry *dents;
1523 struct xfs_inode *dp = state->args->dp;
1562 1524
1563 args = state->args; 1525 args = state->args;
1564 ASSERT(drop_blk->magic == XFS_DIR2_LEAFN_MAGIC); 1526 ASSERT(drop_blk->magic == XFS_DIR2_LEAFN_MAGIC);
@@ -1566,10 +1528,10 @@ xfs_dir2_leafn_unbalance(
1566 drop_leaf = drop_blk->bp->b_addr; 1528 drop_leaf = drop_blk->bp->b_addr;
1567 save_leaf = save_blk->bp->b_addr; 1529 save_leaf = save_blk->bp->b_addr;
1568 1530
1569 xfs_dir3_leaf_hdr_from_disk(&savehdr, save_leaf); 1531 dp->d_ops->leaf_hdr_from_disk(&savehdr, save_leaf);
1570 xfs_dir3_leaf_hdr_from_disk(&drophdr, drop_leaf); 1532 dp->d_ops->leaf_hdr_from_disk(&drophdr, drop_leaf);
1571 sents = xfs_dir3_leaf_ents_p(save_leaf); 1533 sents = dp->d_ops->leaf_ents_p(save_leaf);
1572 dents = xfs_dir3_leaf_ents_p(drop_leaf); 1534 dents = dp->d_ops->leaf_ents_p(drop_leaf);
1573 1535
1574 /* 1536 /*
1575 * If there are any stale leaf entries, take this opportunity 1537 * If there are any stale leaf entries, take this opportunity
@@ -1584,7 +1546,7 @@ xfs_dir2_leafn_unbalance(
1584 * Move the entries from drop to the appropriate end of save. 1546 * Move the entries from drop to the appropriate end of save.
1585 */ 1547 */
1586 drop_blk->hashval = be32_to_cpu(dents[drophdr.count - 1].hashval); 1548 drop_blk->hashval = be32_to_cpu(dents[drophdr.count - 1].hashval);
1587 if (xfs_dir2_leafn_order(save_blk->bp, drop_blk->bp)) 1549 if (xfs_dir2_leafn_order(dp, save_blk->bp, drop_blk->bp))
1588 xfs_dir3_leafn_moveents(args, drop_blk->bp, &drophdr, dents, 0, 1550 xfs_dir3_leafn_moveents(args, drop_blk->bp, &drophdr, dents, 0,
1589 save_blk->bp, &savehdr, sents, 0, 1551 save_blk->bp, &savehdr, sents, 0,
1590 drophdr.count); 1552 drophdr.count);
@@ -1595,13 +1557,13 @@ xfs_dir2_leafn_unbalance(
1595 save_blk->hashval = be32_to_cpu(sents[savehdr.count - 1].hashval); 1557 save_blk->hashval = be32_to_cpu(sents[savehdr.count - 1].hashval);
1596 1558
1597 /* log the changes made when moving the entries */ 1559 /* log the changes made when moving the entries */
1598 xfs_dir3_leaf_hdr_to_disk(save_leaf, &savehdr); 1560 dp->d_ops->leaf_hdr_to_disk(save_leaf, &savehdr);
1599 xfs_dir3_leaf_hdr_to_disk(drop_leaf, &drophdr); 1561 dp->d_ops->leaf_hdr_to_disk(drop_leaf, &drophdr);
1600 xfs_dir3_leaf_log_header(args->trans, save_blk->bp); 1562 xfs_dir3_leaf_log_header(args->trans, dp, save_blk->bp);
1601 xfs_dir3_leaf_log_header(args->trans, drop_blk->bp); 1563 xfs_dir3_leaf_log_header(args->trans, dp, drop_blk->bp);
1602 1564
1603 xfs_dir3_leaf_check(args->dp->i_mount, save_blk->bp); 1565 xfs_dir3_leaf_check(dp, save_blk->bp);
1604 xfs_dir3_leaf_check(args->dp->i_mount, drop_blk->bp); 1566 xfs_dir3_leaf_check(dp, drop_blk->bp);
1605} 1567}
1606 1568
1607/* 1569/*
@@ -1712,7 +1674,7 @@ xfs_dir2_node_addname_int(
1712 dp = args->dp; 1674 dp = args->dp;
1713 mp = dp->i_mount; 1675 mp = dp->i_mount;
1714 tp = args->trans; 1676 tp = args->trans;
1715 length = xfs_dir3_data_entsize(mp, args->namelen); 1677 length = dp->d_ops->data_entsize(args->namelen);
1716 /* 1678 /*
1717 * If we came in with a freespace block that means that lookup 1679 * If we came in with a freespace block that means that lookup
1718 * found an entry with our hash value. This is the freespace 1680 * found an entry with our hash value. This is the freespace
@@ -1726,8 +1688,8 @@ xfs_dir2_node_addname_int(
1726 ifbno = fblk->blkno; 1688 ifbno = fblk->blkno;
1727 free = fbp->b_addr; 1689 free = fbp->b_addr;
1728 findex = fblk->index; 1690 findex = fblk->index;
1729 bests = xfs_dir3_free_bests_p(mp, free); 1691 bests = dp->d_ops->free_bests_p(free);
1730 xfs_dir3_free_hdr_from_disk(&freehdr, free); 1692 dp->d_ops->free_hdr_from_disk(&freehdr, free);
1731 1693
1732 /* 1694 /*
1733 * This means the free entry showed that the data block had 1695 * This means the free entry showed that the data block had
@@ -1819,8 +1781,8 @@ xfs_dir2_node_addname_int(
1819 * and the freehdr are actually initialised if they are placed 1781 * and the freehdr are actually initialised if they are placed
1820 * there, so we have to do it here to avoid warnings. Blech. 1782 * there, so we have to do it here to avoid warnings. Blech.
1821 */ 1783 */
1822 bests = xfs_dir3_free_bests_p(mp, free); 1784 bests = dp->d_ops->free_bests_p(free);
1823 xfs_dir3_free_hdr_from_disk(&freehdr, free); 1785 dp->d_ops->free_hdr_from_disk(&freehdr, free);
1824 if (be16_to_cpu(bests[findex]) != NULLDATAOFF && 1786 if (be16_to_cpu(bests[findex]) != NULLDATAOFF &&
1825 be16_to_cpu(bests[findex]) >= length) 1787 be16_to_cpu(bests[findex]) >= length)
1826 dbno = freehdr.firstdb + findex; 1788 dbno = freehdr.firstdb + findex;
@@ -1871,7 +1833,7 @@ xfs_dir2_node_addname_int(
1871 * Get the freespace block corresponding to the data block 1833 * Get the freespace block corresponding to the data block
1872 * that was just allocated. 1834 * that was just allocated.
1873 */ 1835 */
1874 fbno = xfs_dir2_db_to_fdb(mp, dbno); 1836 fbno = dp->d_ops->db_to_fdb(mp, dbno);
1875 error = xfs_dir2_free_try_read(tp, dp, 1837 error = xfs_dir2_free_try_read(tp, dp,
1876 xfs_dir2_db_to_da(mp, fbno), 1838 xfs_dir2_db_to_da(mp, fbno),
1877 &fbp); 1839 &fbp);
@@ -1888,12 +1850,12 @@ xfs_dir2_node_addname_int(
1888 if (error) 1850 if (error)
1889 return error; 1851 return error;
1890 1852
1891 if (unlikely(xfs_dir2_db_to_fdb(mp, dbno) != fbno)) { 1853 if (unlikely(dp->d_ops->db_to_fdb(mp, dbno) != fbno)) {
1892 xfs_alert(mp, 1854 xfs_alert(mp,
1893 "%s: dir ino %llu needed freesp block %lld for\n" 1855 "%s: dir ino %llu needed freesp block %lld for\n"
1894 " data block %lld, got %lld ifbno %llu lastfbno %d", 1856 " data block %lld, got %lld ifbno %llu lastfbno %d",
1895 __func__, (unsigned long long)dp->i_ino, 1857 __func__, (unsigned long long)dp->i_ino,
1896 (long long)xfs_dir2_db_to_fdb(mp, dbno), 1858 (long long)dp->d_ops->db_to_fdb(mp, dbno),
1897 (long long)dbno, (long long)fbno, 1859 (long long)dbno, (long long)fbno,
1898 (unsigned long long)ifbno, lastfbno); 1860 (unsigned long long)ifbno, lastfbno);
1899 if (fblk) { 1861 if (fblk) {
@@ -1918,30 +1880,30 @@ xfs_dir2_node_addname_int(
1918 if (error) 1880 if (error)
1919 return error; 1881 return error;
1920 free = fbp->b_addr; 1882 free = fbp->b_addr;
1921 bests = xfs_dir3_free_bests_p(mp, free); 1883 bests = dp->d_ops->free_bests_p(free);
1922 xfs_dir3_free_hdr_from_disk(&freehdr, free); 1884 dp->d_ops->free_hdr_from_disk(&freehdr, free);
1923 1885
1924 /* 1886 /*
1925 * Remember the first slot as our empty slot. 1887 * Remember the first slot as our empty slot.
1926 */ 1888 */
1927 freehdr.firstdb = (fbno - XFS_DIR2_FREE_FIRSTDB(mp)) * 1889 freehdr.firstdb = (fbno - XFS_DIR2_FREE_FIRSTDB(mp)) *
1928 xfs_dir3_free_max_bests(mp); 1890 dp->d_ops->free_max_bests(mp);
1929 } else { 1891 } else {
1930 free = fbp->b_addr; 1892 free = fbp->b_addr;
1931 bests = xfs_dir3_free_bests_p(mp, free); 1893 bests = dp->d_ops->free_bests_p(free);
1932 xfs_dir3_free_hdr_from_disk(&freehdr, free); 1894 dp->d_ops->free_hdr_from_disk(&freehdr, free);
1933 } 1895 }
1934 1896
1935 /* 1897 /*
1936 * Set the freespace block index from the data block number. 1898 * Set the freespace block index from the data block number.
1937 */ 1899 */
1938 findex = xfs_dir2_db_to_fdindex(mp, dbno); 1900 findex = dp->d_ops->db_to_fdindex(mp, dbno);
1939 /* 1901 /*
1940 * If it's after the end of the current entries in the 1902 * If it's after the end of the current entries in the
1941 * freespace block, extend that table. 1903 * freespace block, extend that table.
1942 */ 1904 */
1943 if (findex >= freehdr.nvalid) { 1905 if (findex >= freehdr.nvalid) {
1944 ASSERT(findex < xfs_dir3_free_max_bests(mp)); 1906 ASSERT(findex < dp->d_ops->free_max_bests(mp));
1945 freehdr.nvalid = findex + 1; 1907 freehdr.nvalid = findex + 1;
1946 /* 1908 /*
1947 * Tag new entry so nused will go up. 1909 * Tag new entry so nused will go up.
@@ -1954,8 +1916,8 @@ xfs_dir2_node_addname_int(
1954 */ 1916 */
1955 if (bests[findex] == cpu_to_be16(NULLDATAOFF)) { 1917 if (bests[findex] == cpu_to_be16(NULLDATAOFF)) {
1956 freehdr.nused++; 1918 freehdr.nused++;
1957 xfs_dir3_free_hdr_to_disk(fbp->b_addr, &freehdr); 1919 dp->d_ops->free_hdr_to_disk(fbp->b_addr, &freehdr);
1958 xfs_dir2_free_log_header(tp, fbp); 1920 xfs_dir2_free_log_header(tp, dp, fbp);
1959 } 1921 }
1960 /* 1922 /*
1961 * Update the real value in the table. 1923 * Update the real value in the table.
@@ -1963,7 +1925,7 @@ xfs_dir2_node_addname_int(
1963 * change again. 1925 * change again.
1964 */ 1926 */
1965 hdr = dbp->b_addr; 1927 hdr = dbp->b_addr;
1966 bf = xfs_dir3_data_bestfree_p(hdr); 1928 bf = dp->d_ops->data_bestfree_p(hdr);
1967 bests[findex] = bf[0].length; 1929 bests[findex] = bf[0].length;
1968 logfree = 1; 1930 logfree = 1;
1969 } 1931 }
@@ -1985,7 +1947,7 @@ xfs_dir2_node_addname_int(
1985 if (error) 1947 if (error)
1986 return error; 1948 return error;
1987 hdr = dbp->b_addr; 1949 hdr = dbp->b_addr;
1988 bf = xfs_dir3_data_bestfree_p(hdr); 1950 bf = dp->d_ops->data_bestfree_p(hdr);
1989 logfree = 0; 1951 logfree = 0;
1990 } 1952 }
1991 ASSERT(be16_to_cpu(bf[0].length) >= length); 1953 ASSERT(be16_to_cpu(bf[0].length) >= length);
@@ -1998,7 +1960,7 @@ xfs_dir2_node_addname_int(
1998 /* 1960 /*
1999 * Mark the first part of the unused space, inuse for us. 1961 * Mark the first part of the unused space, inuse for us.
2000 */ 1962 */
2001 xfs_dir2_data_use_free(tp, dbp, dup, 1963 xfs_dir2_data_use_free(tp, dp, dbp, dup,
2002 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length, 1964 (xfs_dir2_data_aoff_t)((char *)dup - (char *)hdr), length,
2003 &needlog, &needscan); 1965 &needlog, &needscan);
2004 /* 1966 /*
@@ -2008,24 +1970,24 @@ xfs_dir2_node_addname_int(
2008 dep->inumber = cpu_to_be64(args->inumber); 1970 dep->inumber = cpu_to_be64(args->inumber);
2009 dep->namelen = args->namelen; 1971 dep->namelen = args->namelen;
2010 memcpy(dep->name, args->name, dep->namelen); 1972 memcpy(dep->name, args->name, dep->namelen);
2011 xfs_dir3_dirent_put_ftype(mp, dep, args->filetype); 1973 dp->d_ops->data_put_ftype(dep, args->filetype);
2012 tagp = xfs_dir3_data_entry_tag_p(mp, dep); 1974 tagp = dp->d_ops->data_entry_tag_p(dep);
2013 *tagp = cpu_to_be16((char *)dep - (char *)hdr); 1975 *tagp = cpu_to_be16((char *)dep - (char *)hdr);
2014 xfs_dir2_data_log_entry(tp, dbp, dep); 1976 xfs_dir2_data_log_entry(tp, dp, dbp, dep);
2015 /* 1977 /*
2016 * Rescan the block for bestfree if needed. 1978 * Rescan the block for bestfree if needed.
2017 */ 1979 */
2018 if (needscan) 1980 if (needscan)
2019 xfs_dir2_data_freescan(mp, hdr, &needlog); 1981 xfs_dir2_data_freescan(dp, hdr, &needlog);
2020 /* 1982 /*
2021 * Log the data block header if needed. 1983 * Log the data block header if needed.
2022 */ 1984 */
2023 if (needlog) 1985 if (needlog)
2024 xfs_dir2_data_log_header(tp, dbp); 1986 xfs_dir2_data_log_header(tp, dp, dbp);
2025 /* 1987 /*
2026 * If the freespace entry is now wrong, update it. 1988 * If the freespace entry is now wrong, update it.
2027 */ 1989 */
2028 bests = xfs_dir3_free_bests_p(mp, free); /* gcc is so stupid */ 1990 bests = dp->d_ops->free_bests_p(free); /* gcc is so stupid */
2029 if (be16_to_cpu(bests[findex]) != be16_to_cpu(bf[0].length)) { 1991 if (be16_to_cpu(bests[findex]) != be16_to_cpu(bf[0].length)) {
2030 bests[findex] = bf[0].length; 1992 bests[findex] = bf[0].length;
2031 logfree = 1; 1993 logfree = 1;
@@ -2034,7 +1996,7 @@ xfs_dir2_node_addname_int(
2034 * Log the freespace entry if needed. 1996 * Log the freespace entry if needed.
2035 */ 1997 */
2036 if (logfree) 1998 if (logfree)
2037 xfs_dir2_free_log_bests(tp, fbp, findex, findex); 1999 xfs_dir2_free_log_bests(tp, dp, fbp, findex, findex);
2038 /* 2000 /*
2039 * Return the data block and offset in args, then drop the data block. 2001 * Return the data block and offset in args, then drop the data block.
2040 */ 2002 */
@@ -2105,12 +2067,12 @@ xfs_dir2_node_lookup(
2105 */ 2067 */
2106int /* error */ 2068int /* error */
2107xfs_dir2_node_removename( 2069xfs_dir2_node_removename(
2108 xfs_da_args_t *args) /* operation arguments */ 2070 struct xfs_da_args *args) /* operation arguments */
2109{ 2071{
2110 xfs_da_state_blk_t *blk; /* leaf block */ 2072 struct xfs_da_state_blk *blk; /* leaf block */
2111 int error; /* error return value */ 2073 int error; /* error return value */
2112 int rval; /* operation return value */ 2074 int rval; /* operation return value */
2113 xfs_da_state_t *state; /* btree cursor */ 2075 struct xfs_da_state *state; /* btree cursor */
2114 2076
2115 trace_xfs_dir2_node_removename(args); 2077 trace_xfs_dir2_node_removename(args);
2116 2078
@@ -2122,19 +2084,18 @@ xfs_dir2_node_removename(
2122 state->mp = args->dp->i_mount; 2084 state->mp = args->dp->i_mount;
2123 state->blocksize = state->mp->m_dirblksize; 2085 state->blocksize = state->mp->m_dirblksize;
2124 state->node_ents = state->mp->m_dir_node_ents; 2086 state->node_ents = state->mp->m_dir_node_ents;
2125 /* 2087
2126 * Look up the entry we're deleting, set up the cursor. 2088 /* Look up the entry we're deleting, set up the cursor. */
2127 */
2128 error = xfs_da3_node_lookup_int(state, &rval); 2089 error = xfs_da3_node_lookup_int(state, &rval);
2129 if (error) 2090 if (error)
2130 rval = error; 2091 goto out_free;
2131 /* 2092
2132 * Didn't find it, upper layer screwed up. 2093 /* Didn't find it, upper layer screwed up. */
2133 */
2134 if (rval != EEXIST) { 2094 if (rval != EEXIST) {
2135 xfs_da_state_free(state); 2095 error = rval;
2136 return rval; 2096 goto out_free;
2137 } 2097 }
2098
2138 blk = &state->path.blk[state->path.active - 1]; 2099 blk = &state->path.blk[state->path.active - 1];
2139 ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC); 2100 ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
2140 ASSERT(state->extravalid); 2101 ASSERT(state->extravalid);
@@ -2145,7 +2106,7 @@ xfs_dir2_node_removename(
2145 error = xfs_dir2_leafn_remove(args, blk->bp, blk->index, 2106 error = xfs_dir2_leafn_remove(args, blk->bp, blk->index,
2146 &state->extrablk, &rval); 2107 &state->extrablk, &rval);
2147 if (error) 2108 if (error)
2148 return error; 2109 goto out_free;
2149 /* 2110 /*
2150 * Fix the hash values up the btree. 2111 * Fix the hash values up the btree.
2151 */ 2112 */
@@ -2160,6 +2121,7 @@ xfs_dir2_node_removename(
2160 */ 2121 */
2161 if (!error) 2122 if (!error)
2162 error = xfs_dir2_node_to_leaf(state); 2123 error = xfs_dir2_node_to_leaf(state);
2124out_free:
2163 xfs_da_state_free(state); 2125 xfs_da_state_free(state);
2164 return error; 2126 return error;
2165} 2127}
@@ -2212,7 +2174,7 @@ xfs_dir2_node_replace(
2212 blk = &state->path.blk[state->path.active - 1]; 2174 blk = &state->path.blk[state->path.active - 1];
2213 ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC); 2175 ASSERT(blk->magic == XFS_DIR2_LEAFN_MAGIC);
2214 leaf = blk->bp->b_addr; 2176 leaf = blk->bp->b_addr;
2215 ents = xfs_dir3_leaf_ents_p(leaf); 2177 ents = args->dp->d_ops->leaf_ents_p(leaf);
2216 lep = &ents[blk->index]; 2178 lep = &ents[blk->index];
2217 ASSERT(state->extravalid); 2179 ASSERT(state->extravalid);
2218 /* 2180 /*
@@ -2229,8 +2191,9 @@ xfs_dir2_node_replace(
2229 * Fill in the new inode number and log the entry. 2191 * Fill in the new inode number and log the entry.
2230 */ 2192 */
2231 dep->inumber = cpu_to_be64(inum); 2193 dep->inumber = cpu_to_be64(inum);
2232 xfs_dir3_dirent_put_ftype(state->mp, dep, args->filetype); 2194 args->dp->d_ops->data_put_ftype(dep, args->filetype);
2233 xfs_dir2_data_log_entry(args->trans, state->extrablk.bp, dep); 2195 xfs_dir2_data_log_entry(args->trans, args->dp,
2196 state->extrablk.bp, dep);
2234 rval = 0; 2197 rval = 0;
2235 } 2198 }
2236 /* 2199 /*
@@ -2285,7 +2248,7 @@ xfs_dir2_node_trim_free(
2285 if (!bp) 2248 if (!bp)
2286 return 0; 2249 return 0;
2287 free = bp->b_addr; 2250 free = bp->b_addr;
2288 xfs_dir3_free_hdr_from_disk(&freehdr, free); 2251 dp->d_ops->free_hdr_from_disk(&freehdr, free);
2289 2252
2290 /* 2253 /*
2291 * If there are used entries, there's nothing to do. 2254 * If there are used entries, there's nothing to do.