Lines Matching +full:bat +full:- +full:temp +full:- +full:ok

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
65 * leaf entries, is controlled by the size of the on-disk extent count. in xfs_bmap_compute_maxlevels()
83 minleafrecs = mp->m_bmap_dmnr[0]; in xfs_bmap_compute_maxlevels()
84 minnoderecs = mp->m_bmap_dmnr[1]; in xfs_bmap_compute_maxlevels()
92 mp->m_bm_maxlevels[whichfork] = level; in xfs_bmap_compute_maxlevels()
93 ASSERT(mp->m_bm_maxlevels[whichfork] <= xfs_bmbt_maxlevels_ondisk()); in xfs_bmap_compute_maxlevels()
100 if (mp->m_sb.sb_inodesize == 256) in xfs_bmap_compute_attr_offset()
101 return XFS_LITINO(mp) - XFS_BMDR_SPACE_CALC(MINABTPTRS); in xfs_bmap_compute_attr_offset()
111 cur->bc_rec.b = *irec; in xfs_bmbt_lookup_eq()
120 cur->bc_rec.b.br_startoff = 0; in xfs_bmbt_lookup_first()
121 cur->bc_rec.b.br_startblock = 0; in xfs_bmbt_lookup_first()
122 cur->bc_rec.b.br_blockcount = 0; in xfs_bmbt_lookup_first()
134 ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_bmap_needs_btree()
135 ifp->if_nextents > XFS_IFORK_MAXEXT(ip, whichfork); in xfs_bmap_needs_btree()
146 ifp->if_format == XFS_DINODE_FMT_BTREE && in xfs_bmap_wants_extents()
147 ifp->if_nextents <= XFS_IFORK_MAXEXT(ip, whichfork); in xfs_bmap_wants_extents()
166 * Compute the worst-case number of indirect blocks that will be used
179 mp = ip->i_mount; in xfs_bmap_worst_indlen()
180 maxrecs = mp->m_bmap_dmxr[0]; in xfs_bmap_worst_indlen()
184 len += maxrecs - 1; in xfs_bmap_worst_indlen()
188 return rval + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) - in xfs_bmap_worst_indlen()
189 level - 1; in xfs_bmap_worst_indlen()
191 maxrecs = mp->m_bmap_dmxr[1]; in xfs_bmap_worst_indlen()
203 if (ip->i_df.if_format == XFS_DINODE_FMT_DEV) in xfs_default_attroffset()
205 return M_IGEO(ip->i_mount)->attr_fork_offset; in xfs_default_attroffset()
210 * from local to extent format - we reset it where possible to make space
219 ip->i_df.if_format != XFS_DINODE_FMT_DEV && in xfs_bmap_forkoff_reset()
220 ip->i_df.if_format != XFS_DINODE_FMT_BTREE) { in xfs_bmap_forkoff_reset()
223 if (dfl_forkoff > ip->i_forkoff) in xfs_bmap_forkoff_reset()
224 ip->i_forkoff = dfl_forkoff; in xfs_bmap_forkoff_reset()
240 for (i = 0; i < cur->bc_maxlevels; i++) { in xfs_bmap_get_bp()
241 if (!cur->bc_levels[i].bp) in xfs_bmap_get_bp()
243 if (xfs_buf_daddr(cur->bc_levels[i].bp) == bno) in xfs_bmap_get_bp()
244 return cur->bc_levels[i].bp; in xfs_bmap_get_bp()
248 list_for_each_entry(lip, &cur->bc_tp->t_items, li_trans) { in xfs_bmap_get_bp()
251 if (bip->bli_item.li_type == XFS_LI_BUF && in xfs_bmap_get_bp()
252 xfs_buf_daddr(bip->bli_buf) == bno) in xfs_bmap_get_bp()
253 return bip->bli_buf; in xfs_bmap_get_bp()
270 ASSERT(be16_to_cpu(block->bb_level) > 0); in xfs_check_block()
274 dmxr = mp->m_bmap_dmxr[0]; in xfs_check_block()
278 ASSERT(be64_to_cpu(prevp->br_startoff) < in xfs_check_block()
279 be64_to_cpu(keyp->br_startoff)); in xfs_check_block()
291 for (j = i+1; j <= be16_to_cpu(block->bb_numrecs); j++) { in xfs_check_block()
321 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_check_leaf_extents()
335 if (ifp->if_format != XFS_DINODE_FMT_BTREE) in xfs_bmap_check_leaf_extents()
339 if (ip->i_df.if_nextents > 10000) in xfs_bmap_check_leaf_extents()
343 block = ifp->if_broot; in xfs_bmap_check_leaf_extents()
347 level = be16_to_cpu(block->bb_level); in xfs_bmap_check_leaf_extents()
349 xfs_check_block(block, mp, 1, ifp->if_broot_bytes); in xfs_bmap_check_leaf_extents()
350 pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes); in xfs_bmap_check_leaf_extents()
354 ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount); in xfs_bmap_check_leaf_extents()
355 ASSERT(XFS_FSB_TO_AGBNO(mp, bno) < mp->m_sb.sb_agblocks); in xfs_bmap_check_leaf_extents()
361 while (level-- > 0) { in xfs_bmap_check_leaf_extents()
383 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); in xfs_bmap_check_leaf_extents()
386 error = -EFSCORRUPTED; in xfs_bmap_check_leaf_extents()
411 * Read-ahead the next leaf block, if any. in xfs_bmap_check_leaf_extents()
414 nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); in xfs_bmap_check_leaf_extents()
417 * Check all the extents to make sure they are OK. in xfs_bmap_check_leaf_extents()
508 mval[i - 1].br_startoff + mval[i - 1].br_blockcount == in xfs_bmap_validate_ret()
530 * Since the extents are already in-core, all we have to do is give up the space
542 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_btree_to_extents()
543 struct xfs_btree_block *rblock = ifp->if_broot; in xfs_bmap_btree_to_extents()
557 ASSERT(ifp->if_format == XFS_DINODE_FMT_BTREE); in xfs_bmap_btree_to_extents()
558 ASSERT(be16_to_cpu(rblock->bb_level) == 1); in xfs_bmap_btree_to_extents()
559 ASSERT(be16_to_cpu(rblock->bb_numrecs) == 1); in xfs_bmap_btree_to_extents()
560 ASSERT(xfs_bmbt_maxrecs(mp, ifp->if_broot_bytes, 0) == 1); in xfs_bmap_btree_to_extents()
562 pp = XFS_BMAP_BROOT_PTR_ADDR(mp, rblock, 1, ifp->if_broot_bytes); in xfs_bmap_btree_to_extents()
565 if (XFS_IS_CORRUPT(cur->bc_mp, !xfs_btree_check_lptr(cur, cbno, 1))) in xfs_bmap_btree_to_extents()
566 return -EFSCORRUPTED; in xfs_bmap_btree_to_extents()
576 xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, whichfork); in xfs_bmap_btree_to_extents()
577 error = xfs_free_extent_later(cur->bc_tp, cbno, 1, &oinfo, in xfs_bmap_btree_to_extents()
582 ip->i_nblocks--; in xfs_bmap_btree_to_extents()
583 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); in xfs_bmap_btree_to_extents()
585 if (cur->bc_levels[0].bp == cbp) in xfs_bmap_btree_to_extents()
586 cur->bc_levels[0].bp = NULL; in xfs_bmap_btree_to_extents()
587 xfs_iroot_realloc(ip, -1, whichfork); in xfs_bmap_btree_to_extents()
588 ASSERT(ifp->if_broot == NULL); in xfs_bmap_btree_to_extents()
589 ifp->if_format = XFS_DINODE_FMT_EXTENTS; in xfs_bmap_btree_to_extents()
595 * Convert an extents-format file into a btree-format file.
622 mp = ip->i_mount; in xfs_bmap_extents_to_btree()
625 ASSERT(ifp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_bmap_extents_to_btree()
636 block = ifp->if_broot; in xfs_bmap_extents_to_btree()
638 XFS_BTNUM_BMAP, 1, 1, ip->i_ino, in xfs_bmap_extents_to_btree()
644 cur->bc_ino.flags = wasdel ? XFS_BTCUR_BMBT_WASDEL : 0; in xfs_bmap_extents_to_btree()
648 ifp->if_format = XFS_DINODE_FMT_BTREE; in xfs_bmap_extents_to_btree()
652 xfs_rmap_ino_bmbt_owner(&args.oinfo, ip->i_ino, whichfork); in xfs_bmap_extents_to_btree()
658 XFS_INO_TO_FSB(mp, ip->i_ino)); in xfs_bmap_extents_to_btree()
666 error = -ENOSPC; in xfs_bmap_extents_to_btree()
670 cur->bc_ino.allocated++; in xfs_bmap_extents_to_btree()
671 ip->i_nblocks++; in xfs_bmap_extents_to_btree()
673 error = xfs_trans_get_buf(tp, mp->m_ddev_targp, in xfs_bmap_extents_to_btree()
675 mp->m_bsize, 0, &abp); in xfs_bmap_extents_to_btree()
682 abp->b_ops = &xfs_bmbt_buf_ops; in xfs_bmap_extents_to_btree()
685 XFS_BTNUM_BMAP, 0, 0, ip->i_ino, in xfs_bmap_extents_to_btree()
695 ASSERT(cnt == ifp->if_nextents); in xfs_bmap_extents_to_btree()
703 kp->br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(arp)); in xfs_bmap_extents_to_btree()
705 be16_to_cpu(block->bb_level))); in xfs_bmap_extents_to_btree()
713 xfs_btree_log_recs(cur, abp, 1, be16_to_cpu(ablock->bb_numrecs)); in xfs_bmap_extents_to_btree()
720 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); in xfs_bmap_extents_to_btree()
722 xfs_iroot_realloc(ip, -1, whichfork); in xfs_bmap_extents_to_btree()
723 ifp->if_format = XFS_DINODE_FMT_EXTENTS; in xfs_bmap_extents_to_btree()
724 ASSERT(ifp->if_broot == NULL); in xfs_bmap_extents_to_btree()
734 * (The bmap-level manipulations are ok, though).
745 ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); in xfs_bmap_local_to_extents_empty()
746 ASSERT(ifp->if_bytes == 0); in xfs_bmap_local_to_extents_empty()
747 ASSERT(ifp->if_nextents == 0); in xfs_bmap_local_to_extents_empty()
750 ifp->if_u1.if_root = NULL; in xfs_bmap_local_to_extents_empty()
751 ifp->if_height = 0; in xfs_bmap_local_to_extents_empty()
752 ifp->if_format = XFS_DINODE_FMT_EXTENTS; in xfs_bmap_local_to_extents_empty()
781 ASSERT(!(S_ISREG(VFS_I(ip)->i_mode) && whichfork == XFS_DATA_FORK)); in xfs_bmap_local_to_extents()
783 ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); in xfs_bmap_local_to_extents()
785 if (!ifp->if_bytes) { in xfs_bmap_local_to_extents()
795 args.mp = ip->i_mount; in xfs_bmap_local_to_extents()
798 xfs_rmap_ino_owner(&args.oinfo, ip->i_ino, whichfork, 0); in xfs_bmap_local_to_extents()
807 XFS_INO_TO_FSB(args.mp, ip->i_ino)); in xfs_bmap_local_to_extents()
814 error = xfs_trans_get_buf(tp, args.mp->m_ddev_targp, in xfs_bmap_local_to_extents()
816 args.mp->m_bsize, 0, &bp); in xfs_bmap_local_to_extents()
831 xfs_idata_realloc(ip, -ifp->if_bytes, whichfork); in xfs_bmap_local_to_extents()
835 ifp->if_u1.if_root = NULL; in xfs_bmap_local_to_extents()
836 ifp->if_height = 0; in xfs_bmap_local_to_extents()
845 ifp->if_nextents = 1; in xfs_bmap_local_to_extents()
846 ip->i_nblocks = 1; in xfs_bmap_local_to_extents()
864 struct xfs_btree_block *block = ip->i_df.if_broot; in xfs_bmap_add_attrfork_btree()
870 mp = ip->i_mount; in xfs_bmap_add_attrfork_btree()
881 error = -EFSCORRUPTED; in xfs_bmap_add_attrfork_btree()
888 return -ENOSPC; in xfs_bmap_add_attrfork_btree()
890 cur->bc_ino.allocated = 0; in xfs_bmap_add_attrfork_btree()
911 if (ip->i_df.if_nextents * sizeof(struct xfs_bmbt_rec) <= in xfs_bmap_add_attrfork_extents()
918 cur->bc_ino.allocated = 0; in xfs_bmap_add_attrfork_extents()
932 * formatting callout. It should be possible - it's just a very complex
943 if (ip->i_df.if_bytes <= xfs_inode_data_fork_size(ip)) in xfs_bmap_add_attrfork_local()
946 if (S_ISDIR(VFS_I(ip)->i_mode)) { in xfs_bmap_add_attrfork_local()
948 dargs.geo = ip->i_mount->m_dir_geo; in xfs_bmap_add_attrfork_local()
950 dargs.total = dargs.geo->fsbcount; in xfs_bmap_add_attrfork_local()
956 if (S_ISLNK(VFS_I(ip)->i_mode)) in xfs_bmap_add_attrfork_local()
963 return -EFSCORRUPTED; in xfs_bmap_add_attrfork_local()
977 switch (ip->i_df.if_format) { in xfs_bmap_set_attrforkoff()
979 ip->i_forkoff = default_size; in xfs_bmap_set_attrforkoff()
984 ip->i_forkoff = xfs_attr_shortform_bytesfit(ip, size); in xfs_bmap_set_attrforkoff()
985 if (!ip->i_forkoff) in xfs_bmap_set_attrforkoff()
986 ip->i_forkoff = default_size; in xfs_bmap_set_attrforkoff()
987 else if (xfs_has_attr2(ip->i_mount) && version) in xfs_bmap_set_attrforkoff()
992 return -EINVAL; in xfs_bmap_set_attrforkoff()
999 * Convert inode from non-attributed to attributed.
1017 mp = ip->i_mount; in xfs_bmap_add_attrfork()
1022 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0, in xfs_bmap_add_attrfork()
1036 switch (ip->i_df.if_format) { in xfs_bmap_add_attrfork()
1058 spin_lock(&mp->m_sb_lock); in xfs_bmap_add_attrfork()
1067 spin_unlock(&mp->m_sb_lock); in xfs_bmap_add_attrfork()
1098 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_complain_bad_rec()
1110 ip->i_ino, forkname, fa); in xfs_bmap_complain_bad_rec()
1113 irec->br_startoff, irec->br_startblock, irec->br_blockcount, in xfs_bmap_complain_bad_rec()
1114 irec->br_state); in xfs_bmap_complain_bad_rec()
1116 return -EFSCORRUPTED; in xfs_bmap_complain_bad_rec()
1127 struct xfs_mount *mp = cur->bc_mp; in xfs_iread_bmbt_block()
1128 struct xfs_inode *ip = cur->bc_ino.ip; in xfs_iread_bmbt_block()
1134 int whichfork = cur->bc_ino.whichfork; in xfs_iread_bmbt_block()
1141 if (unlikely(ir->loaded + num_recs > ifp->if_nextents)) { in xfs_iread_bmbt_block()
1142 xfs_warn(ip->i_mount, "corrupt dinode %llu, (btree extents).", in xfs_iread_bmbt_block()
1143 (unsigned long long)ip->i_ino); in xfs_iread_bmbt_block()
1144 xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, block, in xfs_iread_bmbt_block()
1146 return -EFSCORRUPTED; in xfs_iread_bmbt_block()
1151 for (j = 0; j < num_recs; j++, frp++, ir->loaded++) { in xfs_iread_bmbt_block()
1158 xfs_inode_verifier_error(ip, -EFSCORRUPTED, in xfs_iread_bmbt_block()
1164 xfs_iext_insert(ip, &ir->icur, &new, in xfs_iread_bmbt_block()
1166 trace_xfs_read_extent(ip, &ir->icur, in xfs_iread_bmbt_block()
1168 xfs_iext_next(ifp, &ir->icur); in xfs_iread_bmbt_block()
1175 * Read in extents from a btree-format inode.
1185 struct xfs_mount *mp = ip->i_mount; in xfs_iread_extents()
1203 if (XFS_IS_CORRUPT(mp, ir.loaded != ifp->if_nextents)) { in xfs_iread_extents()
1204 error = -EFSCORRUPTED; in xfs_iread_extents()
1213 smp_store_release(&ifp->if_needextents, 0); in xfs_iread_extents()
1223 * lowest-address hole if the fork has holes, else the first block past the end
1224 * of fork. Return 0 if the fork is currently local (in-inode).
1241 if (ifp->if_format == XFS_DINODE_FMT_LOCAL) { in xfs_bmap_first_unused()
1258 got.br_startoff - max >= len) in xfs_bmap_first_unused()
1269 * Returns the file-relative block number of the last block - 1 before
1286 switch (ifp->if_format) { in xfs_bmap_last_before()
1295 return -EFSCORRUPTED; in xfs_bmap_last_before()
1337 * Returns 1 in bma->aeof if the file (fork) is empty as any new write will be
1349 bma->aeof = false; in xfs_bmap_isaeof()
1350 error = xfs_bmap_last_extent(NULL, bma->ip, whichfork, &rec, in xfs_bmap_isaeof()
1356 bma->aeof = true; in xfs_bmap_isaeof()
1364 bma->aeof = bma->offset >= rec.br_startoff + rec.br_blockcount || in xfs_bmap_isaeof()
1365 (bma->offset >= rec.br_startoff && in xfs_bmap_isaeof()
1371 * Returns the file-relative block number of the first block past eof in
1388 if (ifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_bmap_last_offset()
1391 if (XFS_IS_CORRUPT(ip->i_mount, !xfs_ifork_has_extents(ifp))) in xfs_bmap_last_offset()
1392 return -EFSCORRUPTED; in xfs_bmap_last_offset()
1414 struct xfs_mount *mp = bma->ip->i_mount; in xfs_bmap_add_extent_delay_real()
1415 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmap_add_extent_delay_real()
1416 struct xfs_bmbt_irec *new = &bma->got; in xfs_bmap_add_extent_delay_real()
1418 int i; /* temp state */ in xfs_bmap_add_extent_delay_real()
1426 xfs_filblks_t temp=0; /* value for da_new calculations */ in xfs_bmap_add_extent_delay_real() local
1431 ASSERT(!isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_delay_real()
1432 ASSERT(!bma->cur || in xfs_bmap_add_extent_delay_real()
1433 (bma->cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL)); in xfs_bmap_add_extent_delay_real()
1444 xfs_iext_get_extent(ifp, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1445 new_endoff = new->br_startoff + new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1447 ASSERT(PREV.br_startoff <= new->br_startoff); in xfs_bmap_add_extent_delay_real()
1457 if (PREV.br_startoff == new->br_startoff) in xfs_bmap_add_extent_delay_real()
1466 if (xfs_iext_peek_prev_extent(ifp, &bma->icur, &LEFT)) { in xfs_bmap_add_extent_delay_real()
1473 LEFT.br_startoff + LEFT.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_delay_real()
1474 LEFT.br_startblock + LEFT.br_blockcount == new->br_startblock && in xfs_bmap_add_extent_delay_real()
1475 LEFT.br_state == new->br_state && in xfs_bmap_add_extent_delay_real()
1476 LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_delay_real()
1482 * Also check for all-three-contiguous being too large. in xfs_bmap_add_extent_delay_real()
1484 if (xfs_iext_peek_next_extent(ifp, &bma->icur, &RIGHT)) { in xfs_bmap_add_extent_delay_real()
1492 new->br_startblock + new->br_blockcount == RIGHT.br_startblock && in xfs_bmap_add_extent_delay_real()
1493 new->br_state == RIGHT.br_state && in xfs_bmap_add_extent_delay_real()
1494 new->br_blockcount + RIGHT.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_delay_real()
1499 LEFT.br_blockcount + new->br_blockcount + RIGHT.br_blockcount in xfs_bmap_add_extent_delay_real()
1517 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1518 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1519 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1520 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT); in xfs_bmap_add_extent_delay_real()
1521 ifp->if_nextents--; in xfs_bmap_add_extent_delay_real()
1523 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1527 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i); in xfs_bmap_add_extent_delay_real()
1531 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1534 error = xfs_btree_delete(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1538 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1541 error = xfs_btree_decrement(bma->cur, 0, &i); in xfs_bmap_add_extent_delay_real()
1545 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1548 error = xfs_bmbt_update(bma->cur, &LEFT); in xfs_bmap_add_extent_delay_real()
1563 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1564 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1565 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT); in xfs_bmap_add_extent_delay_real()
1567 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1571 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i); in xfs_bmap_add_extent_delay_real()
1575 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1578 error = xfs_bmbt_update(bma->cur, &LEFT); in xfs_bmap_add_extent_delay_real()
1589 * with delay -> unwritten extent allocation here because the in xfs_bmap_add_extent_delay_real()
1592 PREV.br_startblock = new->br_startblock; in xfs_bmap_add_extent_delay_real()
1594 PREV.br_state = new->br_state; in xfs_bmap_add_extent_delay_real()
1596 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1597 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1598 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1599 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1601 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1605 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i); in xfs_bmap_add_extent_delay_real()
1609 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1612 error = xfs_bmbt_update(bma->cur, &PREV); in xfs_bmap_add_extent_delay_real()
1625 PREV.br_startblock = new->br_startblock; in xfs_bmap_add_extent_delay_real()
1626 PREV.br_state = new->br_state; in xfs_bmap_add_extent_delay_real()
1627 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1628 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1630 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1634 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1638 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1641 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1645 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1658 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1659 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1662 LEFT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1664 PREV.br_blockcount = temp; in xfs_bmap_add_extent_delay_real()
1665 PREV.br_startoff += new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1668 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1669 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1670 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT); in xfs_bmap_add_extent_delay_real()
1672 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1676 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i); in xfs_bmap_add_extent_delay_real()
1680 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1683 error = xfs_bmbt_update(bma->cur, &LEFT); in xfs_bmap_add_extent_delay_real()
1695 xfs_iext_update_extent(bma->ip, state, &bma->icur, new); in xfs_bmap_add_extent_delay_real()
1696 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1698 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1702 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1706 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1709 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1713 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1718 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1719 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1720 &bma->cur, 1, &tmp_rval, whichfork); in xfs_bmap_add_extent_delay_real()
1726 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1727 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1728 startblockval(PREV.br_startblock) - in xfs_bmap_add_extent_delay_real()
1729 (bma->cur ? bma->cur->bc_ino.allocated : 0)); in xfs_bmap_add_extent_delay_real()
1732 PREV.br_blockcount = temp; in xfs_bmap_add_extent_delay_real()
1734 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1735 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state); in xfs_bmap_add_extent_delay_real()
1736 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1745 RIGHT.br_startoff = new->br_startoff; in xfs_bmap_add_extent_delay_real()
1746 RIGHT.br_startblock = new->br_startblock; in xfs_bmap_add_extent_delay_real()
1747 RIGHT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1749 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1753 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i); in xfs_bmap_add_extent_delay_real()
1757 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1760 error = xfs_bmbt_update(bma->cur, &RIGHT); in xfs_bmap_add_extent_delay_real()
1765 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1766 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1769 PREV.br_blockcount = temp; in xfs_bmap_add_extent_delay_real()
1772 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1773 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1774 xfs_iext_update_extent(bma->ip, state, &bma->icur, &RIGHT); in xfs_bmap_add_extent_delay_real()
1783 xfs_iext_update_extent(bma->ip, state, &bma->icur, new); in xfs_bmap_add_extent_delay_real()
1784 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1786 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1790 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1794 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1797 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1801 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1806 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1807 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1808 &bma->cur, 1, &tmp_rval, whichfork); in xfs_bmap_add_extent_delay_real()
1814 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1815 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1816 startblockval(PREV.br_startblock) - in xfs_bmap_add_extent_delay_real()
1817 (bma->cur ? bma->cur->bc_ino.allocated : 0)); in xfs_bmap_add_extent_delay_real()
1820 PREV.br_blockcount = temp; in xfs_bmap_add_extent_delay_real()
1821 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state); in xfs_bmap_add_extent_delay_real()
1822 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1856 PREV.br_startoff + PREV.br_blockcount - new_endoff; in xfs_bmap_add_extent_delay_real()
1858 nullstartblock(xfs_bmap_worst_indlen(bma->ip, in xfs_bmap_add_extent_delay_real()
1862 PREV.br_blockcount = new->br_startoff - PREV.br_startoff; in xfs_bmap_add_extent_delay_real()
1864 nullstartblock(xfs_bmap_worst_indlen(bma->ip, in xfs_bmap_add_extent_delay_real()
1866 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1868 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1869 xfs_iext_insert(bma->ip, &bma->icur, &RIGHT, state); in xfs_bmap_add_extent_delay_real()
1870 xfs_iext_insert(bma->ip, &bma->icur, &LEFT, state); in xfs_bmap_add_extent_delay_real()
1871 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1873 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1877 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1881 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1884 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1888 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1893 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1894 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1895 &bma->cur, 1, &tmp_rval, whichfork); in xfs_bmap_add_extent_delay_real()
1919 if (!(bma->flags & XFS_BMAPI_NORMAP)) in xfs_bmap_add_extent_delay_real()
1920 xfs_rmap_map_extent(bma->tp, bma->ip, whichfork, new); in xfs_bmap_add_extent_delay_real()
1923 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1926 ASSERT(bma->cur == NULL); in xfs_bmap_add_extent_delay_real()
1927 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1928 &bma->cur, da_old > 0, &tmp_logflags, in xfs_bmap_add_extent_delay_real()
1930 bma->logflags |= tmp_logflags; in xfs_bmap_add_extent_delay_real()
1936 xfs_mod_delalloc(mp, (int64_t)da_new - da_old); in xfs_bmap_add_extent_delay_real()
1938 if (bma->cur) { in xfs_bmap_add_extent_delay_real()
1939 da_new += bma->cur->bc_ino.allocated; in xfs_bmap_add_extent_delay_real()
1940 bma->cur->bc_ino.allocated = 0; in xfs_bmap_add_extent_delay_real()
1945 error = xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new), in xfs_bmap_add_extent_delay_real()
1948 xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); in xfs_bmap_add_extent_delay_real()
1951 bma->logflags |= rval; in xfs_bmap_add_extent_delay_real()
1973 int i; /* temp state */ in xfs_bmap_add_extent_unwritten_real()
1980 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_add_extent_unwritten_real()
1988 ASSERT(!isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_unwritten_real()
2001 ASSERT(new->br_state != PREV.br_state); in xfs_bmap_add_extent_unwritten_real()
2002 new_endoff = new->br_startoff + new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2003 ASSERT(PREV.br_startoff <= new->br_startoff); in xfs_bmap_add_extent_unwritten_real()
2010 if (PREV.br_startoff == new->br_startoff) in xfs_bmap_add_extent_unwritten_real()
2026 LEFT.br_startoff + LEFT.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_unwritten_real()
2027 LEFT.br_startblock + LEFT.br_blockcount == new->br_startblock && in xfs_bmap_add_extent_unwritten_real()
2028 LEFT.br_state == new->br_state && in xfs_bmap_add_extent_unwritten_real()
2029 LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_unwritten_real()
2035 * Also check for all-three-contiguous being too large. in xfs_bmap_add_extent_unwritten_real()
2045 new->br_startblock + new->br_blockcount == RIGHT.br_startblock && in xfs_bmap_add_extent_unwritten_real()
2046 new->br_state == RIGHT.br_state && in xfs_bmap_add_extent_unwritten_real()
2047 new->br_blockcount + RIGHT.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_unwritten_real()
2052 LEFT.br_blockcount + new->br_blockcount + RIGHT.br_blockcount in xfs_bmap_add_extent_unwritten_real()
2073 ifp->if_nextents -= 2; in xfs_bmap_add_extent_unwritten_real()
2082 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2088 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2094 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2100 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2106 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2125 ifp->if_nextents--; in xfs_bmap_add_extent_unwritten_real()
2134 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2140 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2146 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2161 PREV.br_state = new->br_state; in xfs_bmap_add_extent_unwritten_real()
2167 ifp->if_nextents--; in xfs_bmap_add_extent_unwritten_real()
2177 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2183 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2189 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2204 PREV.br_state = new->br_state; in xfs_bmap_add_extent_unwritten_real()
2215 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2229 LEFT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2232 PREV.br_startoff += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2233 PREV.br_startblock += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2234 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2248 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2269 PREV.br_startoff += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2270 PREV.br_startblock += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2271 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2275 ifp->if_nextents++; in xfs_bmap_add_extent_unwritten_real()
2285 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2291 cur->bc_rec.b = *new; in xfs_bmap_add_extent_unwritten_real()
2295 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2307 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2309 RIGHT.br_startoff = new->br_startoff; in xfs_bmap_add_extent_unwritten_real()
2310 RIGHT.br_startblock = new->br_startblock; in xfs_bmap_add_extent_unwritten_real()
2311 RIGHT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2325 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2346 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2351 ifp->if_nextents++; in xfs_bmap_add_extent_unwritten_real()
2361 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2371 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2377 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2390 PREV.br_blockcount = new->br_startoff - PREV.br_startoff; in xfs_bmap_add_extent_unwritten_real()
2395 old.br_startoff + old.br_blockcount - new_endoff; in xfs_bmap_add_extent_unwritten_real()
2396 r[1].br_startblock = new->br_startblock + new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2403 ifp->if_nextents += 2; in xfs_bmap_add_extent_unwritten_real()
2413 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2416 /* new right extent - oldext */ in xfs_bmap_add_extent_unwritten_real()
2420 /* new left extent - oldext */ in xfs_bmap_add_extent_unwritten_real()
2421 cur->bc_rec.b = PREV; in xfs_bmap_add_extent_unwritten_real()
2425 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2437 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2440 /* new middle extent - newext */ in xfs_bmap_add_extent_unwritten_real()
2444 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2480 cur->bc_ino.allocated = 0; in xfs_bmap_add_extent_unwritten_real()
2509 xfs_filblks_t temp; /* temp for indirect calculations */ in xfs_bmap_add_extent_hole_delay() local
2512 ASSERT(isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_hole_delay()
2525 * If it doesn't exist, we're converting the hole at end-of-file. in xfs_bmap_add_extent_hole_delay()
2538 left.br_startoff + left.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_hole_delay()
2539 left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_hole_delay()
2543 new->br_startoff + new->br_blockcount == right.br_startoff && in xfs_bmap_add_extent_hole_delay()
2544 new->br_blockcount + right.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_hole_delay()
2546 (left.br_blockcount + new->br_blockcount + in xfs_bmap_add_extent_hole_delay()
2560 temp = left.br_blockcount + new->br_blockcount + in xfs_bmap_add_extent_hole_delay()
2564 startblockval(new->br_startblock) + in xfs_bmap_add_extent_hole_delay()
2566 newlen = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), in xfs_bmap_add_extent_hole_delay()
2569 left.br_blockcount = temp; in xfs_bmap_add_extent_hole_delay()
2582 temp = left.br_blockcount + new->br_blockcount; in xfs_bmap_add_extent_hole_delay()
2585 startblockval(new->br_startblock); in xfs_bmap_add_extent_hole_delay()
2586 newlen = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), in xfs_bmap_add_extent_hole_delay()
2588 left.br_blockcount = temp; in xfs_bmap_add_extent_hole_delay()
2601 temp = new->br_blockcount + right.br_blockcount; in xfs_bmap_add_extent_hole_delay()
2602 oldlen = startblockval(new->br_startblock) + in xfs_bmap_add_extent_hole_delay()
2604 newlen = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), in xfs_bmap_add_extent_hole_delay()
2606 right.br_startoff = new->br_startoff; in xfs_bmap_add_extent_hole_delay()
2608 right.br_blockcount = temp; in xfs_bmap_add_extent_hole_delay()
2624 xfs_mod_fdblocks(ip->i_mount, (int64_t)(oldlen - newlen), in xfs_bmap_add_extent_hole_delay()
2629 xfs_mod_delalloc(ip->i_mount, (int64_t)newlen - oldlen); in xfs_bmap_add_extent_hole_delay()
2648 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_add_extent_hole_real()
2651 int i; /* temp state */ in xfs_bmap_add_extent_hole_real()
2658 ASSERT(!isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_hole_real()
2659 ASSERT(!cur || !(cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL)); in xfs_bmap_add_extent_hole_real()
2687 left.br_startoff + left.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_hole_real()
2688 left.br_startblock + left.br_blockcount == new->br_startblock && in xfs_bmap_add_extent_hole_real()
2689 left.br_state == new->br_state && in xfs_bmap_add_extent_hole_real()
2690 left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_hole_real()
2694 new->br_startoff + new->br_blockcount == right.br_startoff && in xfs_bmap_add_extent_hole_real()
2695 new->br_startblock + new->br_blockcount == right.br_startblock && in xfs_bmap_add_extent_hole_real()
2696 new->br_state == right.br_state && in xfs_bmap_add_extent_hole_real()
2697 new->br_blockcount + right.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_hole_real()
2699 left.br_blockcount + new->br_blockcount + in xfs_bmap_add_extent_hole_real()
2714 left.br_blockcount += new->br_blockcount + right.br_blockcount; in xfs_bmap_add_extent_hole_real()
2719 ifp->if_nextents--; in xfs_bmap_add_extent_hole_real()
2729 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2736 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2743 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2759 left.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_hole_real()
2772 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2789 right.br_startoff = new->br_startoff; in xfs_bmap_add_extent_hole_real()
2790 right.br_startblock = new->br_startblock; in xfs_bmap_add_extent_hole_real()
2791 right.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_hole_real()
2802 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2818 ifp->if_nextents++; in xfs_bmap_add_extent_hole_real()
2828 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2835 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2861 cur->bc_ino.allocated = 0; in xfs_bmap_add_extent_hole_real()
2883 int eof, /* is extent at end-of-file? */ in xfs_bmap_extsize_align()
2894 xfs_fileoff_t align_off; /* temp for offset */ in xfs_bmap_extsize_align()
2895 xfs_extlen_t align_alen; /* temp for length */ in xfs_bmap_extsize_align()
2896 xfs_extlen_t temp; /* temp for calculations */ in xfs_bmap_extsize_align() local
2910 (orig_off >= gotp->br_startoff) && in xfs_bmap_extsize_align()
2911 (orig_end <= gotp->br_startoff + gotp->br_blockcount)) { in xfs_bmap_extsize_align()
2922 div_u64_rem(orig_off, extsz, &temp); in xfs_bmap_extsize_align()
2923 if (temp) { in xfs_bmap_extsize_align()
2924 align_alen += temp; in xfs_bmap_extsize_align()
2925 align_off -= temp; in xfs_bmap_extsize_align()
2929 temp = (align_alen % extsz); in xfs_bmap_extsize_align()
2930 if (temp) in xfs_bmap_extsize_align()
2931 align_alen += extsz - temp; in xfs_bmap_extsize_align()
2942 align_alen -= extsz; in xfs_bmap_extsize_align()
2949 if (prevp->br_startoff != NULLFILEOFF) { in xfs_bmap_extsize_align()
2950 if (prevp->br_startblock == HOLESTARTBLOCK) in xfs_bmap_extsize_align()
2951 prevo = prevp->br_startoff; in xfs_bmap_extsize_align()
2953 prevo = prevp->br_startoff + prevp->br_blockcount; in xfs_bmap_extsize_align()
2966 if (!eof && gotp->br_startoff != NULLFILEOFF) { in xfs_bmap_extsize_align()
2967 if ((delay && gotp->br_startblock == HOLESTARTBLOCK) || in xfs_bmap_extsize_align()
2968 (!delay && gotp->br_startblock == DELAYSTARTBLOCK)) in xfs_bmap_extsize_align()
2969 nexto = gotp->br_startoff + gotp->br_blockcount; in xfs_bmap_extsize_align()
2971 nexto = gotp->br_startoff; in xfs_bmap_extsize_align()
2977 align_off = nexto > align_alen ? nexto - align_alen : 0; in xfs_bmap_extsize_align()
2990 align_alen = nexto - align_off; in xfs_bmap_extsize_align()
2997 if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) { in xfs_bmap_extsize_align()
3004 align_alen - temp < orig_alen) in xfs_bmap_extsize_align()
3005 return -EINVAL; in xfs_bmap_extsize_align()
3009 if (align_off + temp <= orig_off) { in xfs_bmap_extsize_align()
3010 align_alen -= temp; in xfs_bmap_extsize_align()
3011 align_off += temp; in xfs_bmap_extsize_align()
3016 else if (align_off + align_alen - temp >= orig_end) in xfs_bmap_extsize_align()
3017 align_alen -= temp; in xfs_bmap_extsize_align()
3022 align_alen -= orig_off - align_off; in xfs_bmap_extsize_align()
3024 align_alen -= align_alen % mp->m_sb.sb_rextsize; in xfs_bmap_extsize_align()
3030 return -EINVAL; in xfs_bmap_extsize_align()
3039 if (!eof && gotp->br_startoff != NULLFILEOFF) in xfs_bmap_extsize_align()
3040 ASSERT(align_off + align_alen <= gotp->br_startoff); in xfs_bmap_extsize_align()
3041 if (prevp->br_startoff != NULLFILEOFF) in xfs_bmap_extsize_align()
3042 ASSERT(align_off >= prevp->br_startoff + prevp->br_blockcount); in xfs_bmap_extsize_align()
3062 (x) < mp->m_sb.sb_rblocks : \ in xfs_bmap_adjacent()
3064 XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount && \ in xfs_bmap_adjacent()
3065 XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks) in xfs_bmap_adjacent()
3067 mp = ap->ip->i_mount; in xfs_bmap_adjacent()
3068 rt = XFS_IS_REALTIME_INODE(ap->ip) && in xfs_bmap_adjacent()
3069 (ap->datatype & XFS_ALLOC_USERDATA); in xfs_bmap_adjacent()
3074 if (ap->eof && ap->prev.br_startoff != NULLFILEOFF && in xfs_bmap_adjacent()
3075 !isnullstartblock(ap->prev.br_startblock) && in xfs_bmap_adjacent()
3076 ISVALID(ap->prev.br_startblock + ap->prev.br_blockcount, in xfs_bmap_adjacent()
3077 ap->prev.br_startblock)) { in xfs_bmap_adjacent()
3078 ap->blkno = ap->prev.br_startblock + ap->prev.br_blockcount; in xfs_bmap_adjacent()
3082 adjust = ap->offset - in xfs_bmap_adjacent()
3083 (ap->prev.br_startoff + ap->prev.br_blockcount); in xfs_bmap_adjacent()
3085 ISVALID(ap->blkno + adjust, ap->prev.br_startblock)) in xfs_bmap_adjacent()
3086 ap->blkno += adjust; in xfs_bmap_adjacent()
3093 else if (!ap->eof) { in xfs_bmap_adjacent()
3103 if (ap->prev.br_startoff != NULLFILEOFF && in xfs_bmap_adjacent()
3104 !isnullstartblock(ap->prev.br_startblock) && in xfs_bmap_adjacent()
3105 (prevbno = ap->prev.br_startblock + in xfs_bmap_adjacent()
3106 ap->prev.br_blockcount) && in xfs_bmap_adjacent()
3107 ISVALID(prevbno, ap->prev.br_startblock)) { in xfs_bmap_adjacent()
3111 adjust = prevdiff = ap->offset - in xfs_bmap_adjacent()
3112 (ap->prev.br_startoff + in xfs_bmap_adjacent()
3113 ap->prev.br_blockcount); in xfs_bmap_adjacent()
3122 if (prevdiff <= XFS_ALLOC_GAP_UNITS * ap->length && in xfs_bmap_adjacent()
3124 ap->prev.br_startblock)) in xfs_bmap_adjacent()
3138 if (!isnullstartblock(ap->got.br_startblock)) { in xfs_bmap_adjacent()
3142 adjust = gotdiff = ap->got.br_startoff - ap->offset; in xfs_bmap_adjacent()
3147 gotbno = ap->got.br_startblock; in xfs_bmap_adjacent()
3155 if (gotdiff <= XFS_ALLOC_GAP_UNITS * ap->length && in xfs_bmap_adjacent()
3156 ISVALID(gotbno - gotdiff, gotbno)) in xfs_bmap_adjacent()
3157 gotbno -= adjust; in xfs_bmap_adjacent()
3158 else if (ISVALID(gotbno - ap->length, gotbno)) { in xfs_bmap_adjacent()
3159 gotbno -= ap->length; in xfs_bmap_adjacent()
3160 gotdiff += adjust - ap->length; in xfs_bmap_adjacent()
3171 * one, else ap->blkno is already set (to 0 or the inode block). in xfs_bmap_adjacent()
3174 ap->blkno = prevdiff <= gotdiff ? prevbno : gotbno; in xfs_bmap_adjacent()
3176 ap->blkno = prevbno; in xfs_bmap_adjacent()
3178 ap->blkno = gotbno; in xfs_bmap_adjacent()
3200 xfs_alloc_min_freelist(pag->pag_mount, pag), in xfs_bmap_longest_free_extent()
3219 if (blen < ap->minlen) in xfs_bmap_select_minlen()
3220 return ap->minlen; in xfs_bmap_select_minlen()
3227 if (blen < args->maxlen) in xfs_bmap_select_minlen()
3229 return args->maxlen; in xfs_bmap_select_minlen()
3238 struct xfs_mount *mp = args->mp; in xfs_bmap_btalloc_select_lengths()
3243 if (ap->tp->t_flags & XFS_TRANS_LOWMODE) { in xfs_bmap_btalloc_select_lengths()
3244 args->total = ap->minlen; in xfs_bmap_btalloc_select_lengths()
3245 args->minlen = ap->minlen; in xfs_bmap_btalloc_select_lengths()
3249 args->total = ap->total; in xfs_bmap_btalloc_select_lengths()
3250 startag = XFS_FSB_TO_AGNO(mp, ap->blkno); in xfs_bmap_btalloc_select_lengths()
3256 error = xfs_bmap_longest_free_extent(pag, args->tp, blen); in xfs_bmap_btalloc_select_lengths()
3257 if (error && error != -EAGAIN) in xfs_bmap_btalloc_select_lengths()
3260 if (*blen >= args->maxlen) in xfs_bmap_btalloc_select_lengths()
3266 args->minlen = xfs_bmap_select_minlen(ap, args, *blen); in xfs_bmap_btalloc_select_lengths()
3276 if (ap->flags & XFS_BMAPI_COWFORK) { in xfs_bmap_btalloc_accounting()
3278 * COW fork blocks are in-core only and thus are treated as in xfs_bmap_btalloc_accounting()
3279 * in-core quota reservation (like delalloc blocks) even when in xfs_bmap_btalloc_accounting()
3286 if (ap->wasdel) { in xfs_bmap_btalloc_accounting()
3287 xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len); in xfs_bmap_btalloc_accounting()
3293 * has acquired in-core quota reservation for this extent. in xfs_bmap_btalloc_accounting()
3299 ap->ip->i_delayed_blks += args->len; in xfs_bmap_btalloc_accounting()
3300 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, XFS_TRANS_DQ_RES_BLKS, in xfs_bmap_btalloc_accounting()
3301 -(long)args->len); in xfs_bmap_btalloc_accounting()
3306 ap->ip->i_nblocks += args->len; in xfs_bmap_btalloc_accounting()
3307 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); in xfs_bmap_btalloc_accounting()
3308 if (ap->wasdel) { in xfs_bmap_btalloc_accounting()
3309 ap->ip->i_delayed_blks -= args->len; in xfs_bmap_btalloc_accounting()
3310 xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len); in xfs_bmap_btalloc_accounting()
3312 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, in xfs_bmap_btalloc_accounting()
3313 ap->wasdel ? XFS_TRANS_DQ_DELBCOUNT : XFS_TRANS_DQ_BCOUNT, in xfs_bmap_btalloc_accounting()
3314 args->len); in xfs_bmap_btalloc_accounting()
3322 struct xfs_mount *mp = args->mp; in xfs_bmap_compute_alignments()
3327 if (mp->m_swidth && xfs_has_swalloc(mp)) in xfs_bmap_compute_alignments()
3328 stripe_align = mp->m_swidth; in xfs_bmap_compute_alignments()
3329 else if (mp->m_dalign) in xfs_bmap_compute_alignments()
3330 stripe_align = mp->m_dalign; in xfs_bmap_compute_alignments()
3332 if (ap->flags & XFS_BMAPI_COWFORK) in xfs_bmap_compute_alignments()
3333 align = xfs_get_cowextsz_hint(ap->ip); in xfs_bmap_compute_alignments()
3334 else if (ap->datatype & XFS_ALLOC_USERDATA) in xfs_bmap_compute_alignments()
3335 align = xfs_get_extsz_hint(ap->ip); in xfs_bmap_compute_alignments()
3337 if (xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, align, 0, in xfs_bmap_compute_alignments()
3338 ap->eof, 0, ap->conv, &ap->offset, in xfs_bmap_compute_alignments()
3339 &ap->length)) in xfs_bmap_compute_alignments()
3341 ASSERT(ap->length); in xfs_bmap_compute_alignments()
3346 args->prod = align; in xfs_bmap_compute_alignments()
3347 div_u64_rem(ap->offset, args->prod, &args->mod); in xfs_bmap_compute_alignments()
3348 if (args->mod) in xfs_bmap_compute_alignments()
3349 args->mod = args->prod - args->mod; in xfs_bmap_compute_alignments()
3350 } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { in xfs_bmap_compute_alignments()
3351 args->prod = 1; in xfs_bmap_compute_alignments()
3352 args->mod = 0; in xfs_bmap_compute_alignments()
3354 args->prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; in xfs_bmap_compute_alignments()
3355 div_u64_rem(ap->offset, args->prod, &args->mod); in xfs_bmap_compute_alignments()
3356 if (args->mod) in xfs_bmap_compute_alignments()
3357 args->mod = args->prod - args->mod; in xfs_bmap_compute_alignments()
3370 ap->blkno = args->fsbno; in xfs_bmap_process_allocated_extent()
3371 ap->length = args->len; in xfs_bmap_process_allocated_extent()
3384 if (ap->length <= orig_length) in xfs_bmap_process_allocated_extent()
3385 ap->offset = orig_offset; in xfs_bmap_process_allocated_extent()
3386 else if (ap->offset + ap->length < orig_offset + orig_length) in xfs_bmap_process_allocated_extent()
3387 ap->offset = orig_offset + orig_length - ap->length; in xfs_bmap_process_allocated_extent()
3396 if (ap->minlen != 1) { in xfs_bmap_exact_minlen_extent_alloc()
3397 args->fsbno = NULLFSBLOCK; in xfs_bmap_exact_minlen_extent_alloc()
3401 args->alloc_minlen_only = 1; in xfs_bmap_exact_minlen_extent_alloc()
3402 args->minlen = args->maxlen = ap->minlen; in xfs_bmap_exact_minlen_extent_alloc()
3403 args->total = ap->total; in xfs_bmap_exact_minlen_extent_alloc()
3413 ap->blkno = XFS_AGB_TO_FSB(ap->ip->i_mount, 0, 0); in xfs_bmap_exact_minlen_extent_alloc()
3417 * iteration and then drops args->total to args->minlen, which might be in xfs_bmap_exact_minlen_extent_alloc()
3429 * NOTE: ap->aeof is only set if the allocation length is >= the
3440 struct xfs_mount *mp = args->mp; in xfs_bmap_btalloc_at_eof()
3441 struct xfs_perag *caller_pag = args->pag; in xfs_bmap_btalloc_at_eof()
3450 if (ap->offset) { in xfs_bmap_btalloc_at_eof()
3458 args->alignment = 1; in xfs_bmap_btalloc_at_eof()
3459 if (blen > stripe_align && blen <= args->maxlen) in xfs_bmap_btalloc_at_eof()
3460 nextminlen = blen - stripe_align; in xfs_bmap_btalloc_at_eof()
3462 nextminlen = args->minlen; in xfs_bmap_btalloc_at_eof()
3463 if (nextminlen + stripe_align > args->minlen + 1) in xfs_bmap_btalloc_at_eof()
3464 args->minalignslop = nextminlen + stripe_align - in xfs_bmap_btalloc_at_eof()
3465 args->minlen - 1; in xfs_bmap_btalloc_at_eof()
3467 args->minalignslop = 0; in xfs_bmap_btalloc_at_eof()
3470 args->pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, ap->blkno)); in xfs_bmap_btalloc_at_eof()
3471 error = xfs_alloc_vextent_exact_bno(args, ap->blkno); in xfs_bmap_btalloc_at_eof()
3473 xfs_perag_put(args->pag); in xfs_bmap_btalloc_at_eof()
3474 args->pag = NULL; in xfs_bmap_btalloc_at_eof()
3479 if (args->fsbno != NULLFSBLOCK) in xfs_bmap_btalloc_at_eof()
3485 args->alignment = stripe_align; in xfs_bmap_btalloc_at_eof()
3486 args->minlen = nextminlen; in xfs_bmap_btalloc_at_eof()
3487 args->minalignslop = 0; in xfs_bmap_btalloc_at_eof()
3493 args->alignment = stripe_align; in xfs_bmap_btalloc_at_eof()
3494 if (blen > args->alignment && in xfs_bmap_btalloc_at_eof()
3495 blen <= args->maxlen + args->alignment) in xfs_bmap_btalloc_at_eof()
3496 args->minlen = blen - args->alignment; in xfs_bmap_btalloc_at_eof()
3497 args->minalignslop = 0; in xfs_bmap_btalloc_at_eof()
3501 error = xfs_alloc_vextent_near_bno(args, ap->blkno); in xfs_bmap_btalloc_at_eof()
3503 args->pag = NULL; in xfs_bmap_btalloc_at_eof()
3504 error = xfs_alloc_vextent_start_ag(args, ap->blkno); in xfs_bmap_btalloc_at_eof()
3505 ASSERT(args->pag == NULL); in xfs_bmap_btalloc_at_eof()
3506 args->pag = caller_pag; in xfs_bmap_btalloc_at_eof()
3511 if (args->fsbno != NULLFSBLOCK) in xfs_bmap_btalloc_at_eof()
3516 * original non-aligned state so the caller can proceed on allocation in xfs_bmap_btalloc_at_eof()
3519 args->alignment = 1; in xfs_bmap_btalloc_at_eof()
3542 if (args->minlen > ap->minlen) { in xfs_bmap_btalloc_low_space()
3543 args->minlen = ap->minlen; in xfs_bmap_btalloc_low_space()
3544 error = xfs_alloc_vextent_start_ag(args, ap->blkno); in xfs_bmap_btalloc_low_space()
3545 if (error || args->fsbno != NULLFSBLOCK) in xfs_bmap_btalloc_low_space()
3550 args->total = ap->minlen; in xfs_bmap_btalloc_low_space()
3554 ap->tp->t_flags |= XFS_TRANS_LOWMODE; in xfs_bmap_btalloc_low_space()
3571 ASSERT(args->pag); in xfs_bmap_btalloc_filestreams()
3578 if (ap->tp->t_flags & XFS_TRANS_LOWMODE) { in xfs_bmap_btalloc_filestreams()
3579 args->minlen = ap->minlen; in xfs_bmap_btalloc_filestreams()
3580 ASSERT(args->fsbno == NULLFSBLOCK); in xfs_bmap_btalloc_filestreams()
3584 args->minlen = xfs_bmap_select_minlen(ap, args, blen); in xfs_bmap_btalloc_filestreams()
3585 if (ap->aeof) in xfs_bmap_btalloc_filestreams()
3589 if (!error && args->fsbno == NULLFSBLOCK) in xfs_bmap_btalloc_filestreams()
3590 error = xfs_alloc_vextent_near_bno(args, ap->blkno); in xfs_bmap_btalloc_filestreams()
3600 xfs_perag_rele(args->pag); in xfs_bmap_btalloc_filestreams()
3601 args->pag = NULL; in xfs_bmap_btalloc_filestreams()
3602 if (error || args->fsbno != NULLFSBLOCK) in xfs_bmap_btalloc_filestreams()
3617 ap->blkno = XFS_INO_TO_FSB(args->mp, ap->ip->i_ino); in xfs_bmap_btalloc_best_length()
3635 if (ap->aeof && !(ap->tp->t_flags & XFS_TRANS_LOWMODE)) { in xfs_bmap_btalloc_best_length()
3638 if (error || args->fsbno != NULLFSBLOCK) in xfs_bmap_btalloc_best_length()
3642 error = xfs_alloc_vextent_start_ag(args, ap->blkno); in xfs_bmap_btalloc_best_length()
3643 if (error || args->fsbno != NULLFSBLOCK) in xfs_bmap_btalloc_best_length()
3653 struct xfs_mount *mp = ap->ip->i_mount; in xfs_bmap_btalloc()
3655 .tp = ap->tp, in xfs_bmap_btalloc()
3659 .minleft = ap->minleft, in xfs_bmap_btalloc()
3660 .wasdel = ap->wasdel, in xfs_bmap_btalloc()
3662 .datatype = ap->datatype, in xfs_bmap_btalloc()
3671 ASSERT(ap->length); in xfs_bmap_btalloc()
3672 orig_offset = ap->offset; in xfs_bmap_btalloc()
3673 orig_length = ap->length; in xfs_bmap_btalloc()
3678 args.maxlen = min(ap->length, mp->m_ag_max_usable); in xfs_bmap_btalloc()
3683 else if ((ap->datatype & XFS_ALLOC_USERDATA) && in xfs_bmap_btalloc()
3684 xfs_inode_is_filestream(ap->ip)) in xfs_bmap_btalloc()
3695 ap->blkno = NULLFSBLOCK; in xfs_bmap_btalloc()
3696 ap->length = 0; in xfs_bmap_btalloc()
3711 if (irec->br_startoff + irec->br_blockcount <= bno || in xfs_trim_extent()
3712 irec->br_startoff >= end) { in xfs_trim_extent()
3713 irec->br_blockcount = 0; in xfs_trim_extent()
3717 if (irec->br_startoff < bno) { in xfs_trim_extent()
3718 distance = bno - irec->br_startoff; in xfs_trim_extent()
3719 if (isnullstartblock(irec->br_startblock)) in xfs_trim_extent()
3720 irec->br_startblock = DELAYSTARTBLOCK; in xfs_trim_extent()
3721 if (irec->br_startblock != DELAYSTARTBLOCK && in xfs_trim_extent()
3722 irec->br_startblock != HOLESTARTBLOCK) in xfs_trim_extent()
3723 irec->br_startblock += distance; in xfs_trim_extent()
3724 irec->br_startoff += distance; in xfs_trim_extent()
3725 irec->br_blockcount -= distance; in xfs_trim_extent()
3728 if (end < irec->br_startoff + irec->br_blockcount) { in xfs_trim_extent()
3729 distance = irec->br_startoff + irec->br_blockcount - end; in xfs_trim_extent()
3730 irec->br_blockcount -= distance; in xfs_trim_extent()
3749 got->br_startoff + got->br_blockcount <= obno) { in xfs_bmapi_trim_map()
3751 if (isnullstartblock(got->br_startblock)) in xfs_bmapi_trim_map()
3752 mval->br_startblock = DELAYSTARTBLOCK; in xfs_bmapi_trim_map()
3760 mval->br_startoff = *bno; in xfs_bmapi_trim_map()
3761 if (isnullstartblock(got->br_startblock)) in xfs_bmapi_trim_map()
3762 mval->br_startblock = DELAYSTARTBLOCK; in xfs_bmapi_trim_map()
3764 mval->br_startblock = got->br_startblock + in xfs_bmapi_trim_map()
3765 (*bno - got->br_startoff); in xfs_bmapi_trim_map()
3773 mval->br_blockcount = XFS_FILBLKS_MIN(end - *bno, in xfs_bmapi_trim_map()
3774 got->br_blockcount - (*bno - got->br_startoff)); in xfs_bmapi_trim_map()
3775 mval->br_state = got->br_state; in xfs_bmapi_trim_map()
3776 ASSERT(mval->br_blockcount <= len); in xfs_bmapi_trim_map()
3796 ((mval->br_startoff + mval->br_blockcount) <= end)); in xfs_bmapi_update_map()
3797 ASSERT((flags & XFS_BMAPI_ENTIRE) || (mval->br_blockcount <= *len) || in xfs_bmapi_update_map()
3798 (mval->br_startoff < obno)); in xfs_bmapi_update_map()
3800 *bno = mval->br_startoff + mval->br_blockcount; in xfs_bmapi_update_map()
3801 *len = end - *bno; in xfs_bmapi_update_map()
3802 if (*n > 0 && mval->br_startoff == mval[-1].br_startoff) { in xfs_bmapi_update_map()
3804 ASSERT(mval->br_startblock == mval[-1].br_startblock); in xfs_bmapi_update_map()
3805 ASSERT(mval->br_blockcount > mval[-1].br_blockcount); in xfs_bmapi_update_map()
3806 ASSERT(mval->br_state == mval[-1].br_state); in xfs_bmapi_update_map()
3807 mval[-1].br_blockcount = mval->br_blockcount; in xfs_bmapi_update_map()
3808 mval[-1].br_state = mval->br_state; in xfs_bmapi_update_map()
3809 } else if (*n > 0 && mval->br_startblock != DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3810 mval[-1].br_startblock != DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3811 mval[-1].br_startblock != HOLESTARTBLOCK && in xfs_bmapi_update_map()
3812 mval->br_startblock == mval[-1].br_startblock + in xfs_bmapi_update_map()
3813 mval[-1].br_blockcount && in xfs_bmapi_update_map()
3814 mval[-1].br_state == mval->br_state) { in xfs_bmapi_update_map()
3815 ASSERT(mval->br_startoff == in xfs_bmapi_update_map()
3816 mval[-1].br_startoff + mval[-1].br_blockcount); in xfs_bmapi_update_map()
3817 mval[-1].br_blockcount += mval->br_blockcount; in xfs_bmapi_update_map()
3819 mval->br_startblock == DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3820 mval[-1].br_startblock == DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3821 mval->br_startoff == in xfs_bmapi_update_map()
3822 mval[-1].br_startoff + mval[-1].br_blockcount) { in xfs_bmapi_update_map()
3823 mval[-1].br_blockcount += mval->br_blockcount; in xfs_bmapi_update_map()
3824 mval[-1].br_state = mval->br_state; in xfs_bmapi_update_map()
3826 ((mval->br_startoff + mval->br_blockcount) <= in xfs_bmapi_update_map()
3846 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_read()
3862 return -EFSCORRUPTED; in xfs_bmapi_read()
3866 return -EFSCORRUPTED; in xfs_bmapi_read()
3869 return -EIO; in xfs_bmapi_read()
3888 mval->br_startoff = bno; in xfs_bmapi_read()
3889 mval->br_startblock = HOLESTARTBLOCK; in xfs_bmapi_read()
3890 mval->br_blockcount = in xfs_bmapi_read()
3891 XFS_FILBLKS_MIN(len, got.br_startoff - bno); in xfs_bmapi_read()
3892 mval->br_state = XFS_EXT_NORM; in xfs_bmapi_read()
3893 bno += mval->br_blockcount; in xfs_bmapi_read()
3894 len -= mval->br_blockcount; in xfs_bmapi_read()
3918 * global pool and the extent inserted into the inode in-core extent tree.
3940 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_reserve_delalloc()
3957 alen = XFS_FILBLKS_MIN(alen, got->br_startoff - aoff); in xfs_bmapi_reserve_delalloc()
3959 prealloc = alen - len; in xfs_bmapi_reserve_delalloc()
3983 * Make a transaction-less quota reservation for delayed allocation in xfs_bmapi_reserve_delalloc()
3998 error = xfs_mod_fdblocks(mp, -((int64_t)alen), false); in xfs_bmapi_reserve_delalloc()
4002 error = xfs_mod_fdblocks(mp, -((int64_t)indlen), false); in xfs_bmapi_reserve_delalloc()
4007 ip->i_delayed_blks += alen; in xfs_bmapi_reserve_delalloc()
4008 xfs_mod_delalloc(ip->i_mount, alen + indlen); in xfs_bmapi_reserve_delalloc()
4010 got->br_startoff = aoff; in xfs_bmapi_reserve_delalloc()
4011 got->br_startblock = nullstartblock(indlen); in xfs_bmapi_reserve_delalloc()
4012 got->br_blockcount = alen; in xfs_bmapi_reserve_delalloc()
4013 got->br_state = XFS_EXT_NORM; in xfs_bmapi_reserve_delalloc()
4035 if (error == -ENOSPC || error == -EDQUOT) { in xfs_bmapi_reserve_delalloc()
4052 struct xfs_mount *mp = bma->ip->i_mount; in xfs_bmapi_allocate()
4053 int whichfork = xfs_bmapi_whichfork(bma->flags); in xfs_bmapi_allocate()
4054 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmapi_allocate()
4058 ASSERT(bma->length > 0); in xfs_bmapi_allocate()
4064 if (bma->wasdel) { in xfs_bmapi_allocate()
4065 bma->length = (xfs_extlen_t)bma->got.br_blockcount; in xfs_bmapi_allocate()
4066 bma->offset = bma->got.br_startoff; in xfs_bmapi_allocate()
4067 if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev)) in xfs_bmapi_allocate()
4068 bma->prev.br_startoff = NULLFILEOFF; in xfs_bmapi_allocate()
4070 bma->length = XFS_FILBLKS_MIN(bma->length, XFS_MAX_BMBT_EXTLEN); in xfs_bmapi_allocate()
4071 if (!bma->eof) in xfs_bmapi_allocate()
4072 bma->length = XFS_FILBLKS_MIN(bma->length, in xfs_bmapi_allocate()
4073 bma->got.br_startoff - bma->offset); in xfs_bmapi_allocate()
4076 if (bma->flags & XFS_BMAPI_CONTIG) in xfs_bmapi_allocate()
4077 bma->minlen = bma->length; in xfs_bmapi_allocate()
4079 bma->minlen = 1; in xfs_bmapi_allocate()
4081 if (!(bma->flags & XFS_BMAPI_METADATA)) { in xfs_bmapi_allocate()
4088 bma->datatype = XFS_ALLOC_NOBUSY; in xfs_bmapi_allocate()
4090 bma->datatype |= XFS_ALLOC_USERDATA; in xfs_bmapi_allocate()
4091 if (bma->offset == 0) in xfs_bmapi_allocate()
4092 bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA; in xfs_bmapi_allocate()
4094 if (mp->m_dalign && bma->length >= mp->m_dalign) { in xfs_bmapi_allocate()
4102 if ((bma->datatype & XFS_ALLOC_USERDATA) && in xfs_bmapi_allocate()
4103 XFS_IS_REALTIME_INODE(bma->ip)) in xfs_bmapi_allocate()
4109 if (bma->blkno == NULLFSBLOCK) in xfs_bmapi_allocate()
4110 return -ENOSPC; in xfs_bmapi_allocate()
4112 if (bma->flags & XFS_BMAPI_ZERO) { in xfs_bmapi_allocate()
4113 error = xfs_zero_extent(bma->ip, bma->blkno, bma->length); in xfs_bmapi_allocate()
4118 if (ifp->if_format == XFS_DINODE_FMT_BTREE && !bma->cur) in xfs_bmapi_allocate()
4119 bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork); in xfs_bmapi_allocate()
4124 bma->nallocs++; in xfs_bmapi_allocate()
4126 if (bma->cur) in xfs_bmapi_allocate()
4127 bma->cur->bc_ino.flags = in xfs_bmapi_allocate()
4128 bma->wasdel ? XFS_BTCUR_BMBT_WASDEL : 0; in xfs_bmapi_allocate()
4130 bma->got.br_startoff = bma->offset; in xfs_bmapi_allocate()
4131 bma->got.br_startblock = bma->blkno; in xfs_bmapi_allocate()
4132 bma->got.br_blockcount = bma->length; in xfs_bmapi_allocate()
4133 bma->got.br_state = XFS_EXT_NORM; in xfs_bmapi_allocate()
4135 if (bma->flags & XFS_BMAPI_PREALLOC) in xfs_bmapi_allocate()
4136 bma->got.br_state = XFS_EXT_UNWRITTEN; in xfs_bmapi_allocate()
4138 if (bma->wasdel) in xfs_bmapi_allocate()
4141 error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, in xfs_bmapi_allocate()
4142 whichfork, &bma->icur, &bma->cur, &bma->got, in xfs_bmapi_allocate()
4143 &bma->logflags, bma->flags); in xfs_bmapi_allocate()
4145 bma->logflags |= tmp_logflags; in xfs_bmapi_allocate()
4154 xfs_iext_get_extent(ifp, &bma->icur, &bma->got); in xfs_bmapi_allocate()
4156 ASSERT(bma->got.br_startoff <= bma->offset); in xfs_bmapi_allocate()
4157 ASSERT(bma->got.br_startoff + bma->got.br_blockcount >= in xfs_bmapi_allocate()
4158 bma->offset + bma->length); in xfs_bmapi_allocate()
4159 ASSERT(bma->got.br_state == XFS_EXT_NORM || in xfs_bmapi_allocate()
4160 bma->got.br_state == XFS_EXT_UNWRITTEN); in xfs_bmapi_allocate()
4172 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmapi_convert_unwritten()
4176 /* check if we need to do unwritten->real conversion */ in xfs_bmapi_convert_unwritten()
4177 if (mval->br_state == XFS_EXT_UNWRITTEN && in xfs_bmapi_convert_unwritten()
4181 /* check if we need to do real->unwritten conversion */ in xfs_bmapi_convert_unwritten()
4182 if (mval->br_state == XFS_EXT_NORM && in xfs_bmapi_convert_unwritten()
4190 ASSERT(mval->br_blockcount <= len); in xfs_bmapi_convert_unwritten()
4191 if (ifp->if_format == XFS_DINODE_FMT_BTREE && !bma->cur) { in xfs_bmapi_convert_unwritten()
4192 bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp, in xfs_bmapi_convert_unwritten()
4193 bma->ip, whichfork); in xfs_bmapi_convert_unwritten()
4195 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) in xfs_bmapi_convert_unwritten()
4203 error = xfs_zero_extent(bma->ip, mval->br_startblock, in xfs_bmapi_convert_unwritten()
4204 mval->br_blockcount); in xfs_bmapi_convert_unwritten()
4209 error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, whichfork, in xfs_bmapi_convert_unwritten()
4210 &bma->icur, &bma->cur, mval, &tmp_logflags); in xfs_bmapi_convert_unwritten()
4220 * any on-disk updates to make, so we don't need to log anything. in xfs_bmapi_convert_unwritten()
4223 bma->logflags |= tmp_logflags | XFS_ILOG_CORE; in xfs_bmapi_convert_unwritten()
4232 xfs_iext_get_extent(ifp, &bma->icur, &bma->got); in xfs_bmapi_convert_unwritten()
4238 if (mval->br_blockcount < len) in xfs_bmapi_convert_unwritten()
4239 return -EAGAIN; in xfs_bmapi_convert_unwritten()
4251 if (tp && tp->t_highest_agno != NULLAGNUMBER) in xfs_bmapi_minleft()
4253 if (ifp->if_format != XFS_DINODE_FMT_BTREE) in xfs_bmapi_minleft()
4255 return be16_to_cpu(ifp->if_broot->bb_level) + 1; in xfs_bmapi_minleft()
4270 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmapi_finish()
4272 if ((bma->logflags & xfs_ilog_fext(whichfork)) && in xfs_bmapi_finish()
4273 ifp->if_format != XFS_DINODE_FMT_EXTENTS) in xfs_bmapi_finish()
4274 bma->logflags &= ~xfs_ilog_fext(whichfork); in xfs_bmapi_finish()
4275 else if ((bma->logflags & xfs_ilog_fbroot(whichfork)) && in xfs_bmapi_finish()
4276 ifp->if_format != XFS_DINODE_FMT_BTREE) in xfs_bmapi_finish()
4277 bma->logflags &= ~xfs_ilog_fbroot(whichfork); in xfs_bmapi_finish()
4279 if (bma->logflags) in xfs_bmapi_finish()
4280 xfs_trans_log_inode(bma->tp, bma->ip, bma->logflags); in xfs_bmapi_finish()
4281 if (bma->cur) in xfs_bmapi_finish()
4282 xfs_btree_del_cursor(bma->cur, error); in xfs_bmapi_finish()
4296 * Returns a negative error code on failure, including -ENOSPC when it could not
4297 * allocate any blocks and -ENOSR when it did allocate blocks to convert a
4316 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_write()
4343 ASSERT(ifp->if_format != XFS_DINODE_FMT_LOCAL); in xfs_bmapi_write()
4351 * we can allocate unwritten extents or pre-zero allocated blocks, in xfs_bmapi_write()
4361 return -EFSCORRUPTED; in xfs_bmapi_write()
4365 return -EIO; in xfs_bmapi_write()
4416 * check for 32-bit overflows and handle them here. in xfs_bmapi_write()
4432 if (error == -ENOSPC && bma.nallocs) in xfs_bmapi_write()
4452 if (error == -EAGAIN) in xfs_bmapi_write()
4479 ASSERT(ifp->if_format != XFS_DINODE_FMT_BTREE || in xfs_bmapi_write()
4480 ifp->if_nextents > XFS_IFORK_MAXEXT(ip, whichfork)); in xfs_bmapi_write()
4491 * -ENOSR error code for this particular case so that the caller can in xfs_bmapi_write()
4496 return -ENOSR; in xfs_bmapi_write()
4520 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_convert_one_delalloc()
4534 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, in xfs_bmapi_convert_one_delalloc()
4544 if (error == -EFBIG) in xfs_bmapi_convert_one_delalloc()
4558 error = -EAGAIN; in xfs_bmapi_convert_one_delalloc()
4570 *seq = READ_ONCE(ifp->if_seq); in xfs_bmapi_convert_one_delalloc()
4606 error = -EFSCORRUPTED; in xfs_bmapi_convert_one_delalloc()
4617 *seq = READ_ONCE(ifp->if_seq); in xfs_bmapi_convert_one_delalloc()
4665 } while (iomap->offset + iomap->length <= offset); in xfs_bmapi_convert_delalloc()
4679 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_remap()
4698 return -EFSCORRUPTED; in xfs_bmapi_remap()
4702 return -EIO; in xfs_bmapi_remap()
4711 ASSERT(got.br_startoff - bno >= len); in xfs_bmapi_remap()
4714 ip->i_nblocks += len; in xfs_bmapi_remap()
4717 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmapi_remap()
4719 cur->bc_ino.flags = 0; in xfs_bmapi_remap()
4738 if (ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS) in xfs_bmapi_remap()
4740 else if (ip->i_df.if_format != XFS_DINODE_FMT_BTREE) in xfs_bmapi_remap()
4780 stolen = XFS_FILBLKS_MIN(nres - ores, avail); in xfs_bmap_split_indlen()
4807 * below starts with len1, so hand len2 a block right off the bat if it in xfs_bmap_split_indlen()
4810 ores -= (len1 + len2); in xfs_bmap_split_indlen()
4811 ASSERT((*indlen1 - len1) + (*indlen2 - len2) >= ores); in xfs_bmap_split_indlen()
4814 ores--; in xfs_bmap_split_indlen()
4819 ores--; in xfs_bmap_split_indlen()
4825 ores--; in xfs_bmap_split_indlen()
4843 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_del_extent_delay()
4856 del_endoff = del->br_startoff + del->br_blockcount; in xfs_bmap_del_extent_delay()
4857 got_endoff = got->br_startoff + got->br_blockcount; in xfs_bmap_del_extent_delay()
4858 da_old = startblockval(got->br_startblock); in xfs_bmap_del_extent_delay()
4861 ASSERT(del->br_blockcount > 0); in xfs_bmap_del_extent_delay()
4862 ASSERT(got->br_startoff <= del->br_startoff); in xfs_bmap_del_extent_delay()
4866 uint64_t rtexts = del->br_blockcount; in xfs_bmap_del_extent_delay()
4868 do_div(rtexts, mp->m_sb.sb_rextsize); in xfs_bmap_del_extent_delay()
4878 error = xfs_quota_unreserve_blkres(ip, del->br_blockcount); in xfs_bmap_del_extent_delay()
4881 ip->i_delayed_blks -= del->br_blockcount; in xfs_bmap_del_extent_delay()
4883 if (got->br_startoff == del->br_startoff) in xfs_bmap_del_extent_delay()
4900 got->br_startoff = del_endoff; in xfs_bmap_del_extent_delay()
4901 got->br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_delay()
4903 got->br_blockcount), da_old); in xfs_bmap_del_extent_delay()
4904 got->br_startblock = nullstartblock((int)da_new); in xfs_bmap_del_extent_delay()
4911 got->br_blockcount = got->br_blockcount - del->br_blockcount; in xfs_bmap_del_extent_delay()
4913 got->br_blockcount), da_old); in xfs_bmap_del_extent_delay()
4914 got->br_startblock = nullstartblock((int)da_new); in xfs_bmap_del_extent_delay()
4927 got->br_blockcount = del->br_startoff - got->br_startoff; in xfs_bmap_del_extent_delay()
4928 got_indlen = xfs_bmap_worst_indlen(ip, got->br_blockcount); in xfs_bmap_del_extent_delay()
4930 new.br_blockcount = got_endoff - del_endoff; in xfs_bmap_del_extent_delay()
4935 del->br_blockcount); in xfs_bmap_del_extent_delay()
4937 got->br_startblock = nullstartblock((int)got_indlen); in xfs_bmap_del_extent_delay()
4940 new.br_state = got->br_state; in xfs_bmap_del_extent_delay()
4947 da_new = got_indlen + new_indlen - stolen; in xfs_bmap_del_extent_delay()
4948 del->br_blockcount -= stolen; in xfs_bmap_del_extent_delay()
4953 da_diff = da_old - da_new; in xfs_bmap_del_extent_delay()
4955 da_diff += del->br_blockcount; in xfs_bmap_del_extent_delay()
4958 xfs_mod_delalloc(mp, -da_diff); in xfs_bmap_del_extent_delay()
4970 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_del_extent_cow()
4978 del_endoff = del->br_startoff + del->br_blockcount; in xfs_bmap_del_extent_cow()
4979 got_endoff = got->br_startoff + got->br_blockcount; in xfs_bmap_del_extent_cow()
4981 ASSERT(del->br_blockcount > 0); in xfs_bmap_del_extent_cow()
4982 ASSERT(got->br_startoff <= del->br_startoff); in xfs_bmap_del_extent_cow()
4984 ASSERT(!isnullstartblock(got->br_startblock)); in xfs_bmap_del_extent_cow()
4986 if (got->br_startoff == del->br_startoff) in xfs_bmap_del_extent_cow()
5003 got->br_startoff = del_endoff; in xfs_bmap_del_extent_cow()
5004 got->br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_cow()
5005 got->br_startblock = del->br_startblock + del->br_blockcount; in xfs_bmap_del_extent_cow()
5012 got->br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_cow()
5019 got->br_blockcount = del->br_startoff - got->br_startoff; in xfs_bmap_del_extent_cow()
5022 new.br_blockcount = got_endoff - del_endoff; in xfs_bmap_del_extent_cow()
5023 new.br_state = got->br_state; in xfs_bmap_del_extent_cow()
5024 new.br_startblock = del->br_startblock + del->br_blockcount; in xfs_bmap_del_extent_cow()
5031 ip->i_delayed_blks -= del->br_blockcount; in xfs_bmap_del_extent_cow()
5055 int i; /* temp state */ in xfs_bmap_del_extent_real()
5067 mp = ip->i_mount; in xfs_bmap_del_extent_real()
5071 ASSERT(del->br_blockcount > 0); in xfs_bmap_del_extent_real()
5073 ASSERT(got.br_startoff <= del->br_startoff); in xfs_bmap_del_extent_real()
5074 del_endoff = del->br_startoff + del->br_blockcount; in xfs_bmap_del_extent_real()
5088 if (tp->t_blk_res == 0 && in xfs_bmap_del_extent_real()
5089 ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_bmap_del_extent_real()
5090 ifp->if_nextents >= XFS_IFORK_MAXEXT(ip, whichfork) && in xfs_bmap_del_extent_real()
5091 del->br_startoff > got.br_startoff && del_endoff < got_endoff) in xfs_bmap_del_extent_real()
5092 return -ENOSPC; in xfs_bmap_del_extent_real()
5097 error = xfs_rtfree_blocks(tp, del->br_startblock, in xfs_bmap_del_extent_real()
5098 del->br_blockcount); in xfs_bmap_del_extent_real()
5109 nblks = del->br_blockcount; in xfs_bmap_del_extent_real()
5111 del_endblock = del->br_startblock + del->br_blockcount; in xfs_bmap_del_extent_real()
5117 return -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5120 if (got.br_startoff == del->br_startoff) in xfs_bmap_del_extent_real()
5132 ifp->if_nextents--; in xfs_bmap_del_extent_real()
5142 return -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5150 got.br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_real()
5164 got.br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_real()
5181 got.br_blockcount = del->br_startoff - got.br_startoff; in xfs_bmap_del_extent_real()
5185 new.br_blockcount = got_endoff - del_endoff; in xfs_bmap_del_extent_real()
5197 cur->bc_rec.b = new; in xfs_bmap_del_extent_real()
5199 if (error && error != -ENOSPC) in xfs_bmap_del_extent_real()
5202 * If get no-space back from btree insert, it tried a in xfs_bmap_del_extent_real()
5206 if (error == -ENOSPC) { in xfs_bmap_del_extent_real()
5215 return -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5229 return -ENOSPC; in xfs_bmap_del_extent_real()
5232 return -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5236 ifp->if_nextents++; in xfs_bmap_del_extent_real()
5252 error = __xfs_free_extent_later(tp, del->br_startblock, in xfs_bmap_del_extent_real()
5253 del->br_blockcount, NULL, in xfs_bmap_del_extent_real()
5256 del->br_state == XFS_EXT_UNWRITTEN)); in xfs_bmap_del_extent_real()
5266 ip->i_nblocks -= nblks; in xfs_bmap_del_extent_real()
5271 xfs_trans_mod_dquot_byino(tp, ip, qfield, (long)-nblks); in xfs_bmap_del_extent_real()
5300 struct xfs_mount *mp = ip->i_mount; in __xfs_bunmapi()
5316 return -EFSCORRUPTED; in __xfs_bunmapi()
5318 return -EIO; in __xfs_bunmapi()
5340 end--; in __xfs_bunmapi()
5343 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in __xfs_bunmapi()
5344 ASSERT(ifp->if_format == XFS_DINODE_FMT_BTREE); in __xfs_bunmapi()
5346 cur->bc_ino.flags = 0; in __xfs_bunmapi()
5354 xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); in __xfs_bunmapi()
5355 xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL); in __xfs_bunmapi()
5356 xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); in __xfs_bunmapi()
5357 xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL); in __xfs_bunmapi()
5361 while (end != (xfs_fileoff_t)-1 && end >= start && in __xfs_bunmapi()
5377 got.br_startoff + got.br_blockcount - 1); in __xfs_bunmapi()
5389 del.br_blockcount -= start - got.br_startoff; in __xfs_bunmapi()
5391 del.br_startblock += start - got.br_startoff; in __xfs_bunmapi()
5394 del.br_blockcount = end + 1 - del.br_startoff; in __xfs_bunmapi()
5400 div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod); in __xfs_bunmapi()
5415 end -= mod > del.br_blockcount ? in __xfs_bunmapi()
5429 ASSERT(tp->t_blk_res > 0); in __xfs_bunmapi()
5435 del.br_startoff += del.br_blockcount - mod; in __xfs_bunmapi()
5436 del.br_startblock += del.br_blockcount - mod; in __xfs_bunmapi()
5447 div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod); in __xfs_bunmapi()
5449 xfs_extlen_t off = mp->m_sb.sb_rextsize - mod; in __xfs_bunmapi()
5457 del.br_blockcount -= off; in __xfs_bunmapi()
5462 tp->t_blk_res == 0)) { in __xfs_bunmapi()
5468 end -= del.br_blockcount; in __xfs_bunmapi()
5492 del.br_startoff - mod, in __xfs_bunmapi()
5494 mod = unwrite_start - prev.br_startoff; in __xfs_bunmapi()
5497 prev.br_blockcount -= mod; in __xfs_bunmapi()
5531 end = del.br_startoff - 1; in __xfs_bunmapi()
5536 if (end != (xfs_fileoff_t)-1 && end >= start) { in __xfs_bunmapi()
5546 if (done || end == (xfs_fileoff_t)-1 || end < start) in __xfs_bunmapi()
5549 *rlen = end - start + 1; in __xfs_bunmapi()
5570 ifp->if_format != XFS_DINODE_FMT_EXTENTS) in __xfs_bunmapi()
5573 ifp->if_format != XFS_DINODE_FMT_BTREE) in __xfs_bunmapi()
5583 cur->bc_ino.allocated = 0; in __xfs_bunmapi()
5619 startoff = got->br_startoff - shift; in xfs_bmse_can_merge()
5622 * The extent, once shifted, must be adjacent in-file and on-disk with in xfs_bmse_can_merge()
5625 if ((left->br_startoff + left->br_blockcount != startoff) || in xfs_bmse_can_merge()
5626 (left->br_startblock + left->br_blockcount != got->br_startblock) || in xfs_bmse_can_merge()
5627 (left->br_state != got->br_state) || in xfs_bmse_can_merge()
5628 (left->br_blockcount + got->br_blockcount > XFS_MAX_BMBT_EXTLEN)) in xfs_bmse_can_merge()
5640 * This function assumes the caller has verified a shift-by-merge is possible
5659 struct xfs_mount *mp = ip->i_mount; in xfs_bmse_merge()
5661 blockcount = left->br_blockcount + got->br_blockcount; in xfs_bmse_merge()
5671 * Update the on-disk extent count, the btree if necessary and log the in xfs_bmse_merge()
5674 ifp->if_nextents--; in xfs_bmse_merge()
5686 return -EFSCORRUPTED; in xfs_bmse_merge()
5692 return -EFSCORRUPTED; in xfs_bmse_merge()
5699 return -EFSCORRUPTED; in xfs_bmse_merge()
5719 new.br_startoff = left->br_startoff + left->br_blockcount; in xfs_bmse_merge()
5735 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_shift_update_extent()
5741 got->br_startoff = startoff; in xfs_bmap_shift_update_extent()
5748 return -EFSCORRUPTED; in xfs_bmap_shift_update_extent()
5775 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_collapse_extents()
5786 return -EFSCORRUPTED; in xfs_bmap_collapse_extents()
5790 return -EIO; in xfs_bmap_collapse_extents()
5798 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmap_collapse_extents()
5800 cur->bc_ino.flags = 0; in xfs_bmap_collapse_extents()
5808 error = -EFSCORRUPTED; in xfs_bmap_collapse_extents()
5812 new_startoff = got.br_startoff - offset_shift_fsb; in xfs_bmap_collapse_extents()
5815 error = -EINVAL; in xfs_bmap_collapse_extents()
5829 error = -EINVAL; in xfs_bmap_collapse_extents()
5854 /* Make sure we won't be right-shifting an extent past the maximum bound. */
5867 if (xfs_is_shutdown(ip->i_mount)) in xfs_bmap_can_insert_extents()
5868 return -EIO; in xfs_bmap_can_insert_extents()
5874 error = -EINVAL; in xfs_bmap_can_insert_extents()
5890 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_insert_extents()
5901 return -EFSCORRUPTED; in xfs_bmap_insert_extents()
5905 return -EIO; in xfs_bmap_insert_extents()
5913 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmap_insert_extents()
5915 cur->bc_ino.flags = 0; in xfs_bmap_insert_extents()
5932 error = -EFSCORRUPTED; in xfs_bmap_insert_extents()
5937 error = -EFSCORRUPTED; in xfs_bmap_insert_extents()
5944 error = -EINVAL; in xfs_bmap_insert_extents()
5995 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_split_extent()
6004 return -EFSCORRUPTED; in xfs_bmap_split_extent()
6008 return -EIO; in xfs_bmap_split_extent()
6022 gotblkcnt = split_fsb - got.br_startoff; in xfs_bmap_split_extent()
6025 new.br_blockcount = got.br_blockcount - gotblkcnt; in xfs_bmap_split_extent()
6028 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmap_split_extent()
6030 cur->bc_ino.flags = 0; in xfs_bmap_split_extent()
6035 error = -EFSCORRUPTED; in xfs_bmap_split_extent()
6055 ifp->if_nextents++; in xfs_bmap_split_extent()
6062 error = -EFSCORRUPTED; in xfs_bmap_split_extent()
6069 error = -EFSCORRUPTED; in xfs_bmap_split_extent()
6088 cur->bc_ino.allocated = 0; in xfs_bmap_split_extent()
6102 return bmap->br_startblock != HOLESTARTBLOCK && in xfs_bmap_is_update_needed()
6103 bmap->br_startblock != DELAYSTARTBLOCK; in xfs_bmap_is_update_needed()
6117 trace_xfs_bmap_defer(tp->t_mountp, in __xfs_bmap_add()
6118 XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock), in __xfs_bmap_add()
6120 XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock), in __xfs_bmap_add()
6121 ip->i_ino, whichfork, in __xfs_bmap_add()
6122 bmap->br_startoff, in __xfs_bmap_add()
6123 bmap->br_blockcount, in __xfs_bmap_add()
6124 bmap->br_state); in __xfs_bmap_add()
6127 INIT_LIST_HEAD(&bi->bi_list); in __xfs_bmap_add()
6128 bi->bi_type = type; in __xfs_bmap_add()
6129 bi->bi_owner = ip; in __xfs_bmap_add()
6130 bi->bi_whichfork = whichfork; in __xfs_bmap_add()
6131 bi->bi_bmap = *bmap; in __xfs_bmap_add()
6133 xfs_bmap_update_get_group(tp->t_mountp, bi); in __xfs_bmap_add()
6134 xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_BMAP, &bi->bi_list); in __xfs_bmap_add()
6173 struct xfs_bmbt_irec *bmap = &bi->bi_bmap; in xfs_bmap_finish_one()
6176 ASSERT(tp->t_highest_agno == NULLAGNUMBER); in xfs_bmap_finish_one()
6178 trace_xfs_bmap_deferred(tp->t_mountp, in xfs_bmap_finish_one()
6179 XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock), in xfs_bmap_finish_one()
6180 bi->bi_type, in xfs_bmap_finish_one()
6181 XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock), in xfs_bmap_finish_one()
6182 bi->bi_owner->i_ino, bi->bi_whichfork, in xfs_bmap_finish_one()
6183 bmap->br_startoff, bmap->br_blockcount, in xfs_bmap_finish_one()
6184 bmap->br_state); in xfs_bmap_finish_one()
6186 if (WARN_ON_ONCE(bi->bi_whichfork != XFS_DATA_FORK)) in xfs_bmap_finish_one()
6187 return -EFSCORRUPTED; in xfs_bmap_finish_one()
6189 if (XFS_TEST_ERROR(false, tp->t_mountp, in xfs_bmap_finish_one()
6191 return -EIO; in xfs_bmap_finish_one()
6193 switch (bi->bi_type) { in xfs_bmap_finish_one()
6195 error = xfs_bmapi_remap(tp, bi->bi_owner, bmap->br_startoff, in xfs_bmap_finish_one()
6196 bmap->br_blockcount, bmap->br_startblock, 0); in xfs_bmap_finish_one()
6197 bmap->br_blockcount = 0; in xfs_bmap_finish_one()
6200 error = __xfs_bunmapi(tp, bi->bi_owner, bmap->br_startoff, in xfs_bmap_finish_one()
6201 &bmap->br_blockcount, XFS_BMAPI_REMAP, 1); in xfs_bmap_finish_one()
6205 error = -EFSCORRUPTED; in xfs_bmap_finish_one()
6218 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_validate_extent()
6220 if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount)) in xfs_bmap_validate_extent()
6224 if (!xfs_verify_rtext(mp, irec->br_startblock, in xfs_bmap_validate_extent()
6225 irec->br_blockcount)) in xfs_bmap_validate_extent()
6228 if (!xfs_verify_fsbext(mp, irec->br_startblock, in xfs_bmap_validate_extent()
6229 irec->br_blockcount)) in xfs_bmap_validate_extent()
6232 if (irec->br_state != XFS_EXT_NORM && whichfork != XFS_DATA_FORK) in xfs_bmap_validate_extent()
6244 return xfs_bmap_intent_cache != NULL ? 0 : -ENOMEM; in xfs_bmap_intent_init_cache()