Lines Matching +full:ip +full:- +full:blocks

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
55 uint64_t maxblocks; /* max blocks at this level */ in xfs_bmap_compute_maxlevels()
65 * leaf entries, is controlled by the size of the on-disk extent count. in xfs_bmap_compute_maxlevels()
69 * (xfs_default_attroffset(ip) >> 3) because we could have mounted with 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()
129 static inline bool xfs_bmap_needs_btree(struct xfs_inode *ip, int whichfork) in xfs_bmap_needs_btree() argument
131 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_needs_btree()
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()
141 static inline bool xfs_bmap_wants_extents(struct xfs_inode *ip, int whichfork) in xfs_bmap_wants_extents() argument
143 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_wants_extents()
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
167 * for ip's delayed extent of length "len".
171 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_worst_indlen() argument
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()
201 struct xfs_inode *ip) in xfs_default_attroffset() argument
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
215 xfs_inode_t *ip, in xfs_bmap_forkoff_reset() argument
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()
221 uint dfl_forkoff = xfs_default_attroffset(ip) >> 3; 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()
309 * Check that the extents for the inode ip are in the right order in all
318 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_check_leaf_extents() argument
321 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_check_leaf_extents()
322 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); 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()
379 * no duplicate blocks). 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()
508 mval[i - 1].br_startoff + mval[i - 1].br_blockcount == in xfs_bmap_validate_ret()
518 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0) argument
530 * Since the extents are already in-core, all we have to do is give up the space
536 struct xfs_inode *ip, /* incore inode pointer */ in xfs_bmap_btree_to_extents() argument
541 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_btree_to_extents()
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()
552 if (!xfs_bmap_wants_extents(ip, whichfork)) 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()
575 xfs_rmap_ino_bmbt_owner(&oinfo, ip->i_ino, whichfork); in xfs_bmap_btree_to_extents()
576 xfs_free_extent_later(cur->bc_tp, cbno, 1, &oinfo); in xfs_bmap_btree_to_extents()
577 ip->i_nblocks--; in xfs_bmap_btree_to_extents()
578 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); in xfs_bmap_btree_to_extents()
580 if (cur->bc_levels[0].bp == cbp) in xfs_bmap_btree_to_extents()
581 cur->bc_levels[0].bp = NULL; in xfs_bmap_btree_to_extents()
582 xfs_iroot_realloc(ip, -1, whichfork); in xfs_bmap_btree_to_extents()
583 ASSERT(ifp->if_broot == NULL); in xfs_bmap_btree_to_extents()
584 ifp->if_format = XFS_DINODE_FMT_EXTENTS; in xfs_bmap_btree_to_extents()
590 * Convert an extents-format file into a btree-format file.
596 struct xfs_inode *ip, /* incore inode pointer */ in xfs_bmap_extents_to_btree() argument
617 mp = ip->i_mount; in xfs_bmap_extents_to_btree()
619 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_extents_to_btree()
620 ASSERT(ifp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_bmap_extents_to_btree()
626 xfs_iroot_realloc(ip, 1, whichfork); in xfs_bmap_extents_to_btree()
631 block = ifp->if_broot; in xfs_bmap_extents_to_btree()
633 XFS_BTNUM_BMAP, 1, 1, ip->i_ino, in xfs_bmap_extents_to_btree()
638 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_extents_to_btree()
639 cur->bc_ino.flags = wasdel ? XFS_BTCUR_BMBT_WASDEL : 0; in xfs_bmap_extents_to_btree()
643 ifp->if_format = XFS_DINODE_FMT_BTREE; in xfs_bmap_extents_to_btree()
647 xfs_rmap_ino_bmbt_owner(&args.oinfo, ip->i_ino, whichfork); in xfs_bmap_extents_to_btree()
648 if (tp->t_firstblock == NULLFSBLOCK) { in xfs_bmap_extents_to_btree()
650 args.fsbno = XFS_INO_TO_FSB(mp, ip->i_ino); in xfs_bmap_extents_to_btree()
651 } else if (tp->t_flags & XFS_TRANS_LOWMODE) { in xfs_bmap_extents_to_btree()
653 args.fsbno = tp->t_firstblock; in xfs_bmap_extents_to_btree()
656 args.fsbno = tp->t_firstblock; in xfs_bmap_extents_to_btree()
666 error = -ENOSPC; in xfs_bmap_extents_to_btree()
673 ASSERT(tp->t_firstblock == NULLFSBLOCK || in xfs_bmap_extents_to_btree()
674 args.agno >= XFS_FSB_TO_AGNO(mp, tp->t_firstblock)); in xfs_bmap_extents_to_btree()
675 tp->t_firstblock = args.fsbno; in xfs_bmap_extents_to_btree()
676 cur->bc_ino.allocated++; in xfs_bmap_extents_to_btree()
677 ip->i_nblocks++; in xfs_bmap_extents_to_btree()
678 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, 1L); in xfs_bmap_extents_to_btree()
679 error = xfs_trans_get_buf(tp, mp->m_ddev_targp, in xfs_bmap_extents_to_btree()
681 mp->m_bsize, 0, &abp); in xfs_bmap_extents_to_btree()
688 abp->b_ops = &xfs_bmbt_buf_ops; in xfs_bmap_extents_to_btree()
691 XFS_BTNUM_BMAP, 0, 0, ip->i_ino, in xfs_bmap_extents_to_btree()
701 ASSERT(cnt == ifp->if_nextents); in xfs_bmap_extents_to_btree()
709 kp->br_startoff = cpu_to_be64(xfs_bmbt_disk_get_startoff(arp)); in xfs_bmap_extents_to_btree()
711 be16_to_cpu(block->bb_level))); in xfs_bmap_extents_to_btree()
719 xfs_btree_log_recs(cur, abp, 1, be16_to_cpu(ablock->bb_numrecs)); in xfs_bmap_extents_to_btree()
726 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, -1L); in xfs_bmap_extents_to_btree()
728 xfs_iroot_realloc(ip, -1, whichfork); in xfs_bmap_extents_to_btree()
729 ifp->if_format = XFS_DINODE_FMT_EXTENTS; in xfs_bmap_extents_to_btree()
730 ASSERT(ifp->if_broot == NULL); in xfs_bmap_extents_to_btree()
740 * (The bmap-level manipulations are ok, though).
745 struct xfs_inode *ip, in xfs_bmap_local_to_extents_empty() argument
748 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_local_to_extents_empty()
751 ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); in xfs_bmap_local_to_extents_empty()
752 ASSERT(ifp->if_bytes == 0); in xfs_bmap_local_to_extents_empty()
753 ASSERT(ifp->if_nextents == 0); in xfs_bmap_local_to_extents_empty()
755 xfs_bmap_forkoff_reset(ip, whichfork); in xfs_bmap_local_to_extents_empty()
756 ifp->if_u1.if_root = NULL; in xfs_bmap_local_to_extents_empty()
757 ifp->if_height = 0; in xfs_bmap_local_to_extents_empty()
758 ifp->if_format = XFS_DINODE_FMT_EXTENTS; in xfs_bmap_local_to_extents_empty()
759 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_bmap_local_to_extents_empty()
766 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_local_to_extents() argument
767 xfs_extlen_t total, /* total blocks needed by transaction */ in xfs_bmap_local_to_extents()
772 struct xfs_inode *ip, in xfs_bmap_local_to_extents() argument
787 ASSERT(!(S_ISREG(VFS_I(ip)->i_mode) && whichfork == XFS_DATA_FORK)); in xfs_bmap_local_to_extents()
788 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_local_to_extents()
789 ASSERT(ifp->if_format == XFS_DINODE_FMT_LOCAL); in xfs_bmap_local_to_extents()
791 if (!ifp->if_bytes) { in xfs_bmap_local_to_extents()
792 xfs_bmap_local_to_extents_empty(tp, ip, whichfork); in xfs_bmap_local_to_extents()
801 args.mp = ip->i_mount; in xfs_bmap_local_to_extents()
802 xfs_rmap_ino_owner(&args.oinfo, ip->i_ino, whichfork, 0); in xfs_bmap_local_to_extents()
807 if (tp->t_firstblock == NULLFSBLOCK) { in xfs_bmap_local_to_extents()
808 args.fsbno = XFS_INO_TO_FSB(args.mp, ip->i_ino); in xfs_bmap_local_to_extents()
811 args.fsbno = tp->t_firstblock; in xfs_bmap_local_to_extents()
823 tp->t_firstblock = args.fsbno; in xfs_bmap_local_to_extents()
824 error = xfs_trans_get_buf(tp, args.mp->m_ddev_targp, in xfs_bmap_local_to_extents()
826 args.mp->m_bsize, 0, &bp); in xfs_bmap_local_to_extents()
838 init_fn(tp, bp, ip, ifp); in xfs_bmap_local_to_extents()
841 xfs_idata_realloc(ip, -ifp->if_bytes, whichfork); in xfs_bmap_local_to_extents()
842 xfs_bmap_local_to_extents_empty(tp, ip, whichfork); in xfs_bmap_local_to_extents()
845 ifp->if_u1.if_root = NULL; in xfs_bmap_local_to_extents()
846 ifp->if_height = 0; in xfs_bmap_local_to_extents()
853 xfs_iext_insert(ip, &icur, &rec, 0); in xfs_bmap_local_to_extents()
855 ifp->if_nextents = 1; in xfs_bmap_local_to_extents()
856 ip->i_nblocks = 1; in xfs_bmap_local_to_extents()
857 xfs_trans_mod_dquot_byino(tp, ip, in xfs_bmap_local_to_extents()
872 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_add_attrfork_btree() argument
875 struct xfs_btree_block *block = ip->i_df.if_broot; in xfs_bmap_add_attrfork_btree()
881 mp = ip->i_mount; in xfs_bmap_add_attrfork_btree()
883 if (XFS_BMAP_BMDR_SPACE(block) <= xfs_inode_data_fork_size(ip)) in xfs_bmap_add_attrfork_btree()
886 cur = xfs_bmbt_init_cursor(mp, tp, ip, XFS_DATA_FORK); in xfs_bmap_add_attrfork_btree()
892 error = -EFSCORRUPTED; in xfs_bmap_add_attrfork_btree()
899 return -ENOSPC; in xfs_bmap_add_attrfork_btree()
901 cur->bc_ino.allocated = 0; in xfs_bmap_add_attrfork_btree()
916 struct xfs_inode *ip, /* incore inode pointer */ in xfs_bmap_add_attrfork_extents() argument
922 if (ip->i_df.if_nextents * sizeof(struct xfs_bmbt_rec) <= in xfs_bmap_add_attrfork_extents()
923 xfs_inode_data_fork_size(ip)) in xfs_bmap_add_attrfork_extents()
926 error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, flags, in xfs_bmap_add_attrfork_extents()
929 cur->bc_ino.allocated = 0; in xfs_bmap_add_attrfork_extents()
943 * formatting callout. It should be possible - it's just a very complex
949 struct xfs_inode *ip, /* incore inode pointer */ in xfs_bmap_add_attrfork_local() argument
954 if (ip->i_df.if_bytes <= xfs_inode_data_fork_size(ip)) in xfs_bmap_add_attrfork_local()
957 if (S_ISDIR(VFS_I(ip)->i_mode)) { in xfs_bmap_add_attrfork_local()
959 dargs.geo = ip->i_mount->m_dir_geo; in xfs_bmap_add_attrfork_local()
960 dargs.dp = ip; in xfs_bmap_add_attrfork_local()
961 dargs.total = dargs.geo->fsbcount; in xfs_bmap_add_attrfork_local()
967 if (S_ISLNK(VFS_I(ip)->i_mode)) in xfs_bmap_add_attrfork_local()
968 return xfs_bmap_local_to_extents(tp, ip, 1, flags, in xfs_bmap_add_attrfork_local()
974 return -EFSCORRUPTED; in xfs_bmap_add_attrfork_local()
982 struct xfs_inode *ip, in xfs_bmap_set_attrforkoff() argument
986 int default_size = xfs_default_attroffset(ip) >> 3; in xfs_bmap_set_attrforkoff()
988 switch (ip->i_df.if_format) { in xfs_bmap_set_attrforkoff()
990 ip->i_forkoff = default_size; in xfs_bmap_set_attrforkoff()
995 ip->i_forkoff = xfs_attr_shortform_bytesfit(ip, size); in xfs_bmap_set_attrforkoff()
996 if (!ip->i_forkoff) in xfs_bmap_set_attrforkoff()
997 ip->i_forkoff = default_size; in xfs_bmap_set_attrforkoff()
998 else if (xfs_has_attr2(ip->i_mount) && version) in xfs_bmap_set_attrforkoff()
1003 return -EINVAL; in xfs_bmap_set_attrforkoff()
1010 * Convert inode from non-attributed to attributed.
1011 * Must not be in a transaction, ip must not be locked.
1015 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_add_attrfork() argument
1026 ASSERT(xfs_inode_has_attr_fork(ip) == 0); in xfs_bmap_add_attrfork()
1028 mp = ip->i_mount; in xfs_bmap_add_attrfork()
1029 ASSERT(!XFS_NOT_DQATTACHED(mp, ip)); in xfs_bmap_add_attrfork()
1033 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_addafork, blks, 0, in xfs_bmap_add_attrfork()
1037 if (xfs_inode_has_attr_fork(ip)) in xfs_bmap_add_attrfork()
1040 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_bmap_add_attrfork()
1041 error = xfs_bmap_set_attrforkoff(ip, size, &version); in xfs_bmap_add_attrfork()
1045 xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); in xfs_bmap_add_attrfork()
1047 switch (ip->i_df.if_format) { in xfs_bmap_add_attrfork()
1049 error = xfs_bmap_add_attrfork_local(tp, ip, &logflags); in xfs_bmap_add_attrfork()
1052 error = xfs_bmap_add_attrfork_extents(tp, ip, &logflags); in xfs_bmap_add_attrfork()
1055 error = xfs_bmap_add_attrfork_btree(tp, ip, &logflags); in xfs_bmap_add_attrfork()
1062 xfs_trans_log_inode(tp, ip, logflags); in xfs_bmap_add_attrfork()
1069 spin_lock(&mp->m_sb_lock); in xfs_bmap_add_attrfork()
1078 spin_unlock(&mp->m_sb_lock); in xfs_bmap_add_attrfork()
1084 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_add_attrfork()
1089 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_add_attrfork()
1110 struct xfs_mount *mp = cur->bc_mp; in xfs_iread_bmbt_block()
1111 struct xfs_inode *ip = cur->bc_ino.ip; in xfs_iread_bmbt_block() local
1117 int whichfork = cur->bc_ino.whichfork; in xfs_iread_bmbt_block()
1118 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_iread_bmbt_block()
1124 if (unlikely(ir->loaded + num_recs > ifp->if_nextents)) { in xfs_iread_bmbt_block()
1125 xfs_warn(ip->i_mount, "corrupt dinode %llu, (btree extents).", in xfs_iread_bmbt_block()
1126 (unsigned long long)ip->i_ino); in xfs_iread_bmbt_block()
1127 xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, block, in xfs_iread_bmbt_block()
1129 return -EFSCORRUPTED; in xfs_iread_bmbt_block()
1134 for (j = 0; j < num_recs; j++, frp++, ir->loaded++) { in xfs_iread_bmbt_block()
1139 fa = xfs_bmap_validate_extent(ip, whichfork, &new); in xfs_iread_bmbt_block()
1141 xfs_inode_verifier_error(ip, -EFSCORRUPTED, in xfs_iread_bmbt_block()
1144 return -EFSCORRUPTED; in xfs_iread_bmbt_block()
1146 xfs_iext_insert(ip, &ir->icur, &new, in xfs_iread_bmbt_block()
1148 trace_xfs_read_extent(ip, &ir->icur, in xfs_iread_bmbt_block()
1150 xfs_iext_next(ifp, &ir->icur); in xfs_iread_bmbt_block()
1157 * Read in extents from a btree-format inode.
1162 struct xfs_inode *ip, in xfs_iread_extents() argument
1166 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_iread_extents()
1167 struct xfs_mount *mp = ip->i_mount; in xfs_iread_extents()
1174 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in xfs_iread_extents()
1178 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_iread_extents()
1185 if (XFS_IS_CORRUPT(mp, ir.loaded != ifp->if_nextents)) { in xfs_iread_extents()
1186 error = -EFSCORRUPTED; in xfs_iread_extents()
1198 * fork with at least "len" logically contiguous blocks free. This is the
1199 * lowest-address hole if the fork has holes, else the first block past the end
1200 * of fork. Return 0 if the fork is currently local (in-inode).
1205 struct xfs_inode *ip, /* incore inode */ in xfs_bmap_first_unused() argument
1210 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_first_unused()
1217 if (ifp->if_format == XFS_DINODE_FMT_LOCAL) { in xfs_bmap_first_unused()
1224 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_first_unused()
1234 got.br_startoff - max >= len) in xfs_bmap_first_unused()
1245 * Returns the file-relative block number of the last block - 1 before
1253 struct xfs_inode *ip, /* incore inode */ in xfs_bmap_last_before() argument
1257 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_last_before()
1262 switch (ifp->if_format) { in xfs_bmap_last_before()
1271 return -EFSCORRUPTED; in xfs_bmap_last_before()
1274 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_last_before()
1278 if (!xfs_iext_lookup_extent_before(ip, ifp, last_block, &icur, &got)) in xfs_bmap_last_before()
1286 struct xfs_inode *ip, in xfs_bmap_last_extent() argument
1291 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_last_extent()
1295 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_last_extent()
1309 * in blocks being allocated at the end of the file. When we allocate new data
1310 * blocks at the end of the file which do not start at the previous data block,
1311 * we will try to align the new blocks at stripe unit boundaries.
1313 * Returns 1 in bma->aeof if the file (fork) is empty as any new write will be
1325 bma->aeof = false; in xfs_bmap_isaeof()
1326 error = xfs_bmap_last_extent(NULL, bma->ip, whichfork, &rec, in xfs_bmap_isaeof()
1332 bma->aeof = true; in xfs_bmap_isaeof()
1340 bma->aeof = bma->offset >= rec.br_startoff + rec.br_blockcount || in xfs_bmap_isaeof()
1341 (bma->offset >= rec.br_startoff && in xfs_bmap_isaeof()
1347 * Returns the file-relative block number of the first block past eof in
1353 struct xfs_inode *ip, in xfs_bmap_last_offset() argument
1357 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_last_offset()
1364 if (ifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_bmap_last_offset()
1367 if (XFS_IS_CORRUPT(ip->i_mount, !xfs_ifork_has_extents(ifp))) in xfs_bmap_last_offset()
1368 return -EFSCORRUPTED; in xfs_bmap_last_offset()
1370 error = xfs_bmap_last_extent(NULL, ip, whichfork, &rec, &is_empty); in xfs_bmap_last_offset()
1390 struct xfs_mount *mp = bma->ip->i_mount; in xfs_bmap_add_extent_delay_real()
1391 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmap_add_extent_delay_real()
1392 struct xfs_bmbt_irec *new = &bma->got; in xfs_bmap_add_extent_delay_real()
1400 xfs_filblks_t da_new; /* new count del alloc blocks used */ in xfs_bmap_add_extent_delay_real()
1401 xfs_filblks_t da_old; /* old count del alloc blocks used */ in xfs_bmap_add_extent_delay_real()
1407 ASSERT(!isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_delay_real()
1408 ASSERT(!bma->cur || in xfs_bmap_add_extent_delay_real()
1409 (bma->cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL)); in xfs_bmap_add_extent_delay_real()
1420 xfs_iext_get_extent(ifp, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1421 new_endoff = new->br_startoff + new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1423 ASSERT(PREV.br_startoff <= new->br_startoff); in xfs_bmap_add_extent_delay_real()
1433 if (PREV.br_startoff == new->br_startoff) in xfs_bmap_add_extent_delay_real()
1442 if (xfs_iext_peek_prev_extent(ifp, &bma->icur, &LEFT)) { in xfs_bmap_add_extent_delay_real()
1449 LEFT.br_startoff + LEFT.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_delay_real()
1450 LEFT.br_startblock + LEFT.br_blockcount == new->br_startblock && in xfs_bmap_add_extent_delay_real()
1451 LEFT.br_state == new->br_state && in xfs_bmap_add_extent_delay_real()
1452 LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_delay_real()
1458 * Also check for all-three-contiguous being too large. in xfs_bmap_add_extent_delay_real()
1460 if (xfs_iext_peek_next_extent(ifp, &bma->icur, &RIGHT)) { in xfs_bmap_add_extent_delay_real()
1468 new->br_startblock + new->br_blockcount == RIGHT.br_startblock && in xfs_bmap_add_extent_delay_real()
1469 new->br_state == RIGHT.br_state && in xfs_bmap_add_extent_delay_real()
1470 new->br_blockcount + RIGHT.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_delay_real()
1475 LEFT.br_blockcount + new->br_blockcount + RIGHT.br_blockcount in xfs_bmap_add_extent_delay_real()
1493 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1494 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1495 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1496 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT); in xfs_bmap_add_extent_delay_real()
1497 ifp->if_nextents--; in xfs_bmap_add_extent_delay_real()
1499 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1503 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i); in xfs_bmap_add_extent_delay_real()
1507 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1510 error = xfs_btree_delete(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1514 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1517 error = xfs_btree_decrement(bma->cur, 0, &i); in xfs_bmap_add_extent_delay_real()
1521 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1524 error = xfs_bmbt_update(bma->cur, &LEFT); in xfs_bmap_add_extent_delay_real()
1538 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1539 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1540 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT); in xfs_bmap_add_extent_delay_real()
1542 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1546 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i); in xfs_bmap_add_extent_delay_real()
1550 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1553 error = xfs_bmbt_update(bma->cur, &LEFT); in xfs_bmap_add_extent_delay_real()
1563 * with delay -> unwritten extent allocation here because the in xfs_bmap_add_extent_delay_real()
1566 PREV.br_startblock = new->br_startblock; in xfs_bmap_add_extent_delay_real()
1568 PREV.br_state = new->br_state; in xfs_bmap_add_extent_delay_real()
1570 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1571 xfs_iext_remove(bma->ip, &bma->icur, state); in xfs_bmap_add_extent_delay_real()
1572 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1573 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1575 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1579 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i); in xfs_bmap_add_extent_delay_real()
1583 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1586 error = xfs_bmbt_update(bma->cur, &PREV); in xfs_bmap_add_extent_delay_real()
1598 PREV.br_startblock = new->br_startblock; in xfs_bmap_add_extent_delay_real()
1599 PREV.br_state = new->br_state; in xfs_bmap_add_extent_delay_real()
1600 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1601 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1603 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1607 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1611 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1614 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1618 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1630 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1631 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1634 LEFT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1637 PREV.br_startoff += new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1640 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1641 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1642 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT); in xfs_bmap_add_extent_delay_real()
1644 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1648 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i); in xfs_bmap_add_extent_delay_real()
1652 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1655 error = xfs_bmbt_update(bma->cur, &LEFT); in xfs_bmap_add_extent_delay_real()
1666 xfs_iext_update_extent(bma->ip, state, &bma->icur, new); in xfs_bmap_add_extent_delay_real()
1667 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1669 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1673 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1677 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1680 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1684 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1689 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1690 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1691 &bma->cur, 1, &tmp_rval, whichfork); in xfs_bmap_add_extent_delay_real()
1697 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1698 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1699 startblockval(PREV.br_startblock) - in xfs_bmap_add_extent_delay_real()
1700 (bma->cur ? bma->cur->bc_ino.allocated : 0)); in xfs_bmap_add_extent_delay_real()
1705 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1706 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state); in xfs_bmap_add_extent_delay_real()
1707 xfs_iext_prev(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1716 RIGHT.br_startoff = new->br_startoff; in xfs_bmap_add_extent_delay_real()
1717 RIGHT.br_startblock = new->br_startblock; in xfs_bmap_add_extent_delay_real()
1718 RIGHT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1720 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1724 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i); in xfs_bmap_add_extent_delay_real()
1728 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1731 error = xfs_bmbt_update(bma->cur, &RIGHT); in xfs_bmap_add_extent_delay_real()
1736 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1737 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1743 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1744 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1745 xfs_iext_update_extent(bma->ip, state, &bma->icur, &RIGHT); in xfs_bmap_add_extent_delay_real()
1753 xfs_iext_update_extent(bma->ip, state, &bma->icur, new); in xfs_bmap_add_extent_delay_real()
1754 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1756 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1760 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1764 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1767 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1771 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1776 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1777 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1778 &bma->cur, 1, &tmp_rval, whichfork); in xfs_bmap_add_extent_delay_real()
1784 temp = PREV.br_blockcount - new->br_blockcount; in xfs_bmap_add_extent_delay_real()
1785 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp), in xfs_bmap_add_extent_delay_real()
1786 startblockval(PREV.br_startblock) - in xfs_bmap_add_extent_delay_real()
1787 (bma->cur ? bma->cur->bc_ino.allocated : 0)); in xfs_bmap_add_extent_delay_real()
1791 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state); in xfs_bmap_add_extent_delay_real()
1792 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1825 PREV.br_startoff + PREV.br_blockcount - new_endoff; in xfs_bmap_add_extent_delay_real()
1827 nullstartblock(xfs_bmap_worst_indlen(bma->ip, in xfs_bmap_add_extent_delay_real()
1831 PREV.br_blockcount = new->br_startoff - PREV.br_startoff; in xfs_bmap_add_extent_delay_real()
1833 nullstartblock(xfs_bmap_worst_indlen(bma->ip, in xfs_bmap_add_extent_delay_real()
1835 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV); in xfs_bmap_add_extent_delay_real()
1837 xfs_iext_next(ifp, &bma->icur); in xfs_bmap_add_extent_delay_real()
1838 xfs_iext_insert(bma->ip, &bma->icur, &RIGHT, state); in xfs_bmap_add_extent_delay_real()
1839 xfs_iext_insert(bma->ip, &bma->icur, &LEFT, state); in xfs_bmap_add_extent_delay_real()
1840 ifp->if_nextents++; in xfs_bmap_add_extent_delay_real()
1842 if (bma->cur == NULL) in xfs_bmap_add_extent_delay_real()
1846 error = xfs_bmbt_lookup_eq(bma->cur, new, &i); in xfs_bmap_add_extent_delay_real()
1850 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1853 error = xfs_btree_insert(bma->cur, &i); in xfs_bmap_add_extent_delay_real()
1857 error = -EFSCORRUPTED; in xfs_bmap_add_extent_delay_real()
1862 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1863 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1864 &bma->cur, 1, &tmp_rval, whichfork); in xfs_bmap_add_extent_delay_real()
1888 if (!(bma->flags & XFS_BMAPI_NORMAP)) in xfs_bmap_add_extent_delay_real()
1889 xfs_rmap_map_extent(bma->tp, bma->ip, whichfork, new); in xfs_bmap_add_extent_delay_real()
1892 if (xfs_bmap_needs_btree(bma->ip, whichfork)) { in xfs_bmap_add_extent_delay_real()
1895 ASSERT(bma->cur == NULL); in xfs_bmap_add_extent_delay_real()
1896 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip, in xfs_bmap_add_extent_delay_real()
1897 &bma->cur, da_old > 0, &tmp_logflags, in xfs_bmap_add_extent_delay_real()
1899 bma->logflags |= tmp_logflags; in xfs_bmap_add_extent_delay_real()
1905 xfs_mod_delalloc(mp, (int64_t)da_new - da_old); in xfs_bmap_add_extent_delay_real()
1907 if (bma->cur) { in xfs_bmap_add_extent_delay_real()
1908 da_new += bma->cur->bc_ino.allocated; in xfs_bmap_add_extent_delay_real()
1909 bma->cur->bc_ino.allocated = 0; in xfs_bmap_add_extent_delay_real()
1912 /* adjust for changes in reserved delayed indirect blocks */ in xfs_bmap_add_extent_delay_real()
1915 error = xfs_mod_fdblocks(mp, (int64_t)(da_old - da_new), in xfs_bmap_add_extent_delay_real()
1919 xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork); in xfs_bmap_add_extent_delay_real()
1922 bma->logflags |= rval; in xfs_bmap_add_extent_delay_real()
1935 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_add_extent_unwritten_real() argument
1951 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_add_extent_unwritten_real()
1957 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_add_extent_unwritten_real()
1959 ASSERT(!isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_unwritten_real()
1972 ASSERT(new->br_state != PREV.br_state); in xfs_bmap_add_extent_unwritten_real()
1973 new_endoff = new->br_startoff + new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
1974 ASSERT(PREV.br_startoff <= new->br_startoff); in xfs_bmap_add_extent_unwritten_real()
1981 if (PREV.br_startoff == new->br_startoff) in xfs_bmap_add_extent_unwritten_real()
1997 LEFT.br_startoff + LEFT.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_unwritten_real()
1998 LEFT.br_startblock + LEFT.br_blockcount == new->br_startblock && in xfs_bmap_add_extent_unwritten_real()
1999 LEFT.br_state == new->br_state && in xfs_bmap_add_extent_unwritten_real()
2000 LEFT.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_unwritten_real()
2006 * Also check for all-three-contiguous being too large. in xfs_bmap_add_extent_unwritten_real()
2016 new->br_startblock + new->br_blockcount == RIGHT.br_startblock && in xfs_bmap_add_extent_unwritten_real()
2017 new->br_state == RIGHT.br_state && in xfs_bmap_add_extent_unwritten_real()
2018 new->br_blockcount + RIGHT.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_unwritten_real()
2023 LEFT.br_blockcount + new->br_blockcount + RIGHT.br_blockcount in xfs_bmap_add_extent_unwritten_real()
2040 xfs_iext_remove(ip, icur, state); in xfs_bmap_add_extent_unwritten_real()
2041 xfs_iext_remove(ip, icur, state); in xfs_bmap_add_extent_unwritten_real()
2043 xfs_iext_update_extent(ip, state, icur, &LEFT); in xfs_bmap_add_extent_unwritten_real()
2044 ifp->if_nextents -= 2; in xfs_bmap_add_extent_unwritten_real()
2053 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2059 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2065 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2071 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2077 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2093 xfs_iext_remove(ip, icur, state); in xfs_bmap_add_extent_unwritten_real()
2095 xfs_iext_update_extent(ip, state, icur, &LEFT); in xfs_bmap_add_extent_unwritten_real()
2096 ifp->if_nextents--; in xfs_bmap_add_extent_unwritten_real()
2105 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2111 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2117 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2132 PREV.br_state = new->br_state; in xfs_bmap_add_extent_unwritten_real()
2135 xfs_iext_remove(ip, icur, state); in xfs_bmap_add_extent_unwritten_real()
2137 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2138 ifp->if_nextents--; in xfs_bmap_add_extent_unwritten_real()
2148 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2154 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2160 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2175 PREV.br_state = new->br_state; in xfs_bmap_add_extent_unwritten_real()
2176 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2186 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2200 LEFT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2203 PREV.br_startoff += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2204 PREV.br_startblock += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2205 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2207 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2209 xfs_iext_update_extent(ip, state, icur, &LEFT); in xfs_bmap_add_extent_unwritten_real()
2219 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2240 PREV.br_startoff += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2241 PREV.br_startblock += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2242 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2244 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2245 xfs_iext_insert(ip, icur, new, state); in xfs_bmap_add_extent_unwritten_real()
2246 ifp->if_nextents++; in xfs_bmap_add_extent_unwritten_real()
2256 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2262 cur->bc_rec.b = *new; in xfs_bmap_add_extent_unwritten_real()
2266 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2278 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2280 RIGHT.br_startoff = new->br_startoff; in xfs_bmap_add_extent_unwritten_real()
2281 RIGHT.br_startblock = new->br_startblock; in xfs_bmap_add_extent_unwritten_real()
2282 RIGHT.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2284 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2286 xfs_iext_update_extent(ip, state, icur, &RIGHT); in xfs_bmap_add_extent_unwritten_real()
2296 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2317 PREV.br_blockcount -= new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2319 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2321 xfs_iext_insert(ip, icur, new, state); in xfs_bmap_add_extent_unwritten_real()
2322 ifp->if_nextents++; in xfs_bmap_add_extent_unwritten_real()
2332 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2342 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2348 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2361 PREV.br_blockcount = new->br_startoff - PREV.br_startoff; in xfs_bmap_add_extent_unwritten_real()
2366 old.br_startoff + old.br_blockcount - new_endoff; in xfs_bmap_add_extent_unwritten_real()
2367 r[1].br_startblock = new->br_startblock + new->br_blockcount; in xfs_bmap_add_extent_unwritten_real()
2370 xfs_iext_update_extent(ip, state, icur, &PREV); in xfs_bmap_add_extent_unwritten_real()
2372 xfs_iext_insert(ip, icur, &r[1], state); in xfs_bmap_add_extent_unwritten_real()
2373 xfs_iext_insert(ip, icur, &r[0], state); in xfs_bmap_add_extent_unwritten_real()
2374 ifp->if_nextents += 2; in xfs_bmap_add_extent_unwritten_real()
2384 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2387 /* new right extent - oldext */ in xfs_bmap_add_extent_unwritten_real()
2391 /* new left extent - oldext */ in xfs_bmap_add_extent_unwritten_real()
2392 cur->bc_rec.b = PREV; in xfs_bmap_add_extent_unwritten_real()
2396 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2408 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2411 /* new middle extent - newext */ in xfs_bmap_add_extent_unwritten_real()
2415 error = -EFSCORRUPTED; in xfs_bmap_add_extent_unwritten_real()
2435 xfs_rmap_convert_extent(mp, tp, ip, whichfork, new); in xfs_bmap_add_extent_unwritten_real()
2438 if (xfs_bmap_needs_btree(ip, whichfork)) { in xfs_bmap_add_extent_unwritten_real()
2442 error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, in xfs_bmap_add_extent_unwritten_real()
2451 cur->bc_ino.allocated = 0; in xfs_bmap_add_extent_unwritten_real()
2455 xfs_bmap_check_leaf_extents(*curp, ip, whichfork); in xfs_bmap_add_extent_unwritten_real()
2469 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_add_extent_hole_delay() argument
2482 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_add_extent_hole_delay()
2483 ASSERT(isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_hole_delay()
2496 * If it doesn't exist, we're converting the hole at end-of-file. in xfs_bmap_add_extent_hole_delay()
2509 left.br_startoff + left.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_hole_delay()
2510 left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_hole_delay()
2514 new->br_startoff + new->br_blockcount == right.br_startoff && in xfs_bmap_add_extent_hole_delay()
2515 new->br_blockcount + right.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_hole_delay()
2517 (left.br_blockcount + new->br_blockcount + in xfs_bmap_add_extent_hole_delay()
2531 temp = left.br_blockcount + new->br_blockcount + in xfs_bmap_add_extent_hole_delay()
2535 startblockval(new->br_startblock) + in xfs_bmap_add_extent_hole_delay()
2537 newlen = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), in xfs_bmap_add_extent_hole_delay()
2542 xfs_iext_remove(ip, icur, state); in xfs_bmap_add_extent_hole_delay()
2544 xfs_iext_update_extent(ip, state, icur, &left); in xfs_bmap_add_extent_hole_delay()
2553 temp = left.br_blockcount + new->br_blockcount; in xfs_bmap_add_extent_hole_delay()
2556 startblockval(new->br_startblock); in xfs_bmap_add_extent_hole_delay()
2557 newlen = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), in xfs_bmap_add_extent_hole_delay()
2563 xfs_iext_update_extent(ip, state, icur, &left); in xfs_bmap_add_extent_hole_delay()
2572 temp = new->br_blockcount + right.br_blockcount; in xfs_bmap_add_extent_hole_delay()
2573 oldlen = startblockval(new->br_startblock) + in xfs_bmap_add_extent_hole_delay()
2575 newlen = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, temp), in xfs_bmap_add_extent_hole_delay()
2577 right.br_startoff = new->br_startoff; in xfs_bmap_add_extent_hole_delay()
2580 xfs_iext_update_extent(ip, state, icur, &right); in xfs_bmap_add_extent_hole_delay()
2590 xfs_iext_insert(ip, icur, new, state); in xfs_bmap_add_extent_hole_delay()
2595 xfs_mod_fdblocks(ip->i_mount, (int64_t)(oldlen - newlen), in xfs_bmap_add_extent_hole_delay()
2600 xfs_mod_delalloc(ip->i_mount, (int64_t)newlen - oldlen); in xfs_bmap_add_extent_hole_delay()
2610 struct xfs_inode *ip, in xfs_bmap_add_extent_hole_real() argument
2618 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_add_extent_hole_real()
2619 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_add_extent_hole_real()
2629 ASSERT(!isnullstartblock(new->br_startblock)); in xfs_bmap_add_extent_hole_real()
2630 ASSERT(!cur || !(cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL)); in xfs_bmap_add_extent_hole_real()
2658 left.br_startoff + left.br_blockcount == new->br_startoff && in xfs_bmap_add_extent_hole_real()
2659 left.br_startblock + left.br_blockcount == new->br_startblock && in xfs_bmap_add_extent_hole_real()
2660 left.br_state == new->br_state && in xfs_bmap_add_extent_hole_real()
2661 left.br_blockcount + new->br_blockcount <= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_add_extent_hole_real()
2665 new->br_startoff + new->br_blockcount == right.br_startoff && in xfs_bmap_add_extent_hole_real()
2666 new->br_startblock + new->br_blockcount == right.br_startblock && in xfs_bmap_add_extent_hole_real()
2667 new->br_state == right.br_state && in xfs_bmap_add_extent_hole_real()
2668 new->br_blockcount + right.br_blockcount <= XFS_MAX_BMBT_EXTLEN && in xfs_bmap_add_extent_hole_real()
2670 left.br_blockcount + new->br_blockcount + in xfs_bmap_add_extent_hole_real()
2685 left.br_blockcount += new->br_blockcount + right.br_blockcount; in xfs_bmap_add_extent_hole_real()
2687 xfs_iext_remove(ip, icur, state); in xfs_bmap_add_extent_hole_real()
2689 xfs_iext_update_extent(ip, state, icur, &left); in xfs_bmap_add_extent_hole_real()
2690 ifp->if_nextents--; in xfs_bmap_add_extent_hole_real()
2700 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2707 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2714 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2730 left.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_hole_real()
2733 xfs_iext_update_extent(ip, state, icur, &left); in xfs_bmap_add_extent_hole_real()
2743 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2760 right.br_startoff = new->br_startoff; in xfs_bmap_add_extent_hole_real()
2761 right.br_startblock = new->br_startblock; in xfs_bmap_add_extent_hole_real()
2762 right.br_blockcount += new->br_blockcount; in xfs_bmap_add_extent_hole_real()
2763 xfs_iext_update_extent(ip, state, icur, &right); in xfs_bmap_add_extent_hole_real()
2773 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2788 xfs_iext_insert(ip, icur, new, state); in xfs_bmap_add_extent_hole_real()
2789 ifp->if_nextents++; in xfs_bmap_add_extent_hole_real()
2799 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2806 error = -EFSCORRUPTED; in xfs_bmap_add_extent_hole_real()
2815 xfs_rmap_map_extent(tp, ip, whichfork, new); in xfs_bmap_add_extent_hole_real()
2818 if (xfs_bmap_needs_btree(ip, whichfork)) { in xfs_bmap_add_extent_hole_real()
2822 error = xfs_bmap_extents_to_btree(tp, ip, curp, 0, in xfs_bmap_add_extent_hole_real()
2832 cur->bc_ino.allocated = 0; in xfs_bmap_add_extent_hole_real()
2834 xfs_bmap_check_leaf_extents(cur, ip, whichfork); in xfs_bmap_add_extent_hole_real()
2854 int eof, /* is extent at end-of-file? */ in xfs_bmap_extsize_align()
2881 (orig_off >= gotp->br_startoff) && in xfs_bmap_extsize_align()
2882 (orig_end <= gotp->br_startoff + gotp->br_blockcount)) { in xfs_bmap_extsize_align()
2896 align_off -= temp; in xfs_bmap_extsize_align()
2902 align_alen += extsz - temp; in xfs_bmap_extsize_align()
2913 align_alen -= extsz; in xfs_bmap_extsize_align()
2920 if (prevp->br_startoff != NULLFILEOFF) { in xfs_bmap_extsize_align()
2921 if (prevp->br_startblock == HOLESTARTBLOCK) in xfs_bmap_extsize_align()
2922 prevo = prevp->br_startoff; in xfs_bmap_extsize_align()
2924 prevo = prevp->br_startoff + prevp->br_blockcount; in xfs_bmap_extsize_align()
2937 if (!eof && gotp->br_startoff != NULLFILEOFF) { in xfs_bmap_extsize_align()
2938 if ((delay && gotp->br_startblock == HOLESTARTBLOCK) || in xfs_bmap_extsize_align()
2939 (!delay && gotp->br_startblock == DELAYSTARTBLOCK)) in xfs_bmap_extsize_align()
2940 nexto = gotp->br_startoff + gotp->br_blockcount; in xfs_bmap_extsize_align()
2942 nexto = gotp->br_startoff; in xfs_bmap_extsize_align()
2948 align_off = nexto > align_alen ? nexto - align_alen : 0; in xfs_bmap_extsize_align()
2961 align_alen = nexto - align_off; in xfs_bmap_extsize_align()
2966 * extent size we need to remove blocks until it is. in xfs_bmap_extsize_align()
2968 if (rt && (temp = (align_alen % mp->m_sb.sb_rextsize))) { in xfs_bmap_extsize_align()
2975 align_alen - temp < orig_alen) in xfs_bmap_extsize_align()
2976 return -EINVAL; in xfs_bmap_extsize_align()
2981 align_alen -= temp; in xfs_bmap_extsize_align()
2987 else if (align_off + align_alen - temp >= orig_end) in xfs_bmap_extsize_align()
2988 align_alen -= temp; in xfs_bmap_extsize_align()
2993 align_alen -= orig_off - align_off; in xfs_bmap_extsize_align()
2995 align_alen -= align_alen % mp->m_sb.sb_rextsize; in xfs_bmap_extsize_align()
3001 return -EINVAL; in xfs_bmap_extsize_align()
3010 if (!eof && gotp->br_startoff != NULLFILEOFF) in xfs_bmap_extsize_align()
3011 ASSERT(align_off + align_alen <= gotp->br_startoff); in xfs_bmap_extsize_align()
3012 if (prevp->br_startoff != NULLFILEOFF) in xfs_bmap_extsize_align()
3013 ASSERT(align_off >= prevp->br_startoff + prevp->br_blockcount); in xfs_bmap_extsize_align()
3028 xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ in xfs_bmap_adjacent()
3030 int nullfb; /* true if ap->firstblock isn't set */ in xfs_bmap_adjacent()
3035 (x) < mp->m_sb.sb_rblocks : \ in xfs_bmap_adjacent()
3037 XFS_FSB_TO_AGNO(mp, x) < mp->m_sb.sb_agcount && \ in xfs_bmap_adjacent()
3038 XFS_FSB_TO_AGBNO(mp, x) < mp->m_sb.sb_agblocks) in xfs_bmap_adjacent()
3040 mp = ap->ip->i_mount; in xfs_bmap_adjacent()
3041 nullfb = ap->tp->t_firstblock == NULLFSBLOCK; in xfs_bmap_adjacent()
3042 rt = XFS_IS_REALTIME_INODE(ap->ip) && in xfs_bmap_adjacent()
3043 (ap->datatype & XFS_ALLOC_USERDATA); in xfs_bmap_adjacent()
3045 ap->tp->t_firstblock); in xfs_bmap_adjacent()
3050 if (ap->eof && ap->prev.br_startoff != NULLFILEOFF && in xfs_bmap_adjacent()
3051 !isnullstartblock(ap->prev.br_startblock) && in xfs_bmap_adjacent()
3052 ISVALID(ap->prev.br_startblock + ap->prev.br_blockcount, in xfs_bmap_adjacent()
3053 ap->prev.br_startblock)) { in xfs_bmap_adjacent()
3054 ap->blkno = ap->prev.br_startblock + ap->prev.br_blockcount; in xfs_bmap_adjacent()
3058 adjust = ap->offset - in xfs_bmap_adjacent()
3059 (ap->prev.br_startoff + ap->prev.br_blockcount); in xfs_bmap_adjacent()
3061 ISVALID(ap->blkno + adjust, ap->prev.br_startblock)) in xfs_bmap_adjacent()
3062 ap->blkno += adjust; in xfs_bmap_adjacent()
3065 * If not at eof, then compare the two neighbor blocks. in xfs_bmap_adjacent()
3069 else if (!ap->eof) { in xfs_bmap_adjacent()
3079 if (ap->prev.br_startoff != NULLFILEOFF && in xfs_bmap_adjacent()
3080 !isnullstartblock(ap->prev.br_startblock) && in xfs_bmap_adjacent()
3081 (prevbno = ap->prev.br_startblock + in xfs_bmap_adjacent()
3082 ap->prev.br_blockcount) && in xfs_bmap_adjacent()
3083 ISVALID(prevbno, ap->prev.br_startblock)) { in xfs_bmap_adjacent()
3087 adjust = prevdiff = ap->offset - in xfs_bmap_adjacent()
3088 (ap->prev.br_startoff + in xfs_bmap_adjacent()
3089 ap->prev.br_blockcount); in xfs_bmap_adjacent()
3098 if (prevdiff <= XFS_ALLOC_GAP_UNITS * ap->length && in xfs_bmap_adjacent()
3100 ap->prev.br_startblock)) in xfs_bmap_adjacent()
3121 if (!isnullstartblock(ap->got.br_startblock)) { in xfs_bmap_adjacent()
3125 adjust = gotdiff = ap->got.br_startoff - ap->offset; in xfs_bmap_adjacent()
3130 gotbno = ap->got.br_startblock; in xfs_bmap_adjacent()
3138 if (gotdiff <= XFS_ALLOC_GAP_UNITS * ap->length && in xfs_bmap_adjacent()
3139 ISVALID(gotbno - gotdiff, gotbno)) in xfs_bmap_adjacent()
3140 gotbno -= adjust; in xfs_bmap_adjacent()
3141 else if (ISVALID(gotbno - ap->length, gotbno)) { in xfs_bmap_adjacent()
3142 gotbno -= ap->length; in xfs_bmap_adjacent()
3143 gotdiff += adjust - ap->length; in xfs_bmap_adjacent()
3161 * one, else ap->blkno is already set (to 0 or the inode block). in xfs_bmap_adjacent()
3164 ap->blkno = prevdiff <= gotdiff ? prevbno : gotbno; in xfs_bmap_adjacent()
3166 ap->blkno = prevbno; in xfs_bmap_adjacent()
3168 ap->blkno = gotbno; in xfs_bmap_adjacent()
3180 struct xfs_mount *mp = tp->t_mountp; in xfs_bmap_longest_free_extent()
3186 if (!pag->pagf_init) { in xfs_bmap_longest_free_extent()
3191 if (error == -EAGAIN) { in xfs_bmap_longest_free_extent()
3217 if (notinit || *blen < ap->minlen) { in xfs_bmap_select_minlen()
3222 args->minlen = ap->minlen; in xfs_bmap_select_minlen()
3223 } else if (*blen < args->maxlen) { in xfs_bmap_select_minlen()
3228 args->minlen = *blen; in xfs_bmap_select_minlen()
3234 args->minlen = args->maxlen; in xfs_bmap_select_minlen()
3244 struct xfs_mount *mp = ap->ip->i_mount; in xfs_bmap_btalloc_nullfb()
3249 args->type = XFS_ALLOCTYPE_START_BNO; in xfs_bmap_btalloc_nullfb()
3250 args->total = ap->total; in xfs_bmap_btalloc_nullfb()
3252 startag = ag = XFS_FSB_TO_AGNO(mp, args->fsbno); in xfs_bmap_btalloc_nullfb()
3256 while (*blen < args->maxlen) { in xfs_bmap_btalloc_nullfb()
3257 error = xfs_bmap_longest_free_extent(args->tp, ag, blen, in xfs_bmap_btalloc_nullfb()
3262 if (++ag == mp->m_sb.sb_agcount) in xfs_bmap_btalloc_nullfb()
3278 struct xfs_mount *mp = ap->ip->i_mount; in xfs_bmap_btalloc_filestreams()
3283 args->type = XFS_ALLOCTYPE_NEAR_BNO; in xfs_bmap_btalloc_filestreams()
3284 args->total = ap->total; in xfs_bmap_btalloc_filestreams()
3286 ag = XFS_FSB_TO_AGNO(mp, args->fsbno); in xfs_bmap_btalloc_filestreams()
3290 error = xfs_bmap_longest_free_extent(args->tp, ag, blen, &notinit); in xfs_bmap_btalloc_filestreams()
3294 if (*blen < args->maxlen) { in xfs_bmap_btalloc_filestreams()
3299 error = xfs_bmap_longest_free_extent(args->tp, ag, blen, in xfs_bmap_btalloc_filestreams()
3312 ap->blkno = args->fsbno = XFS_AGB_TO_FSB(mp, ag, 0); in xfs_bmap_btalloc_filestreams()
3322 if (ap->flags & XFS_BMAPI_COWFORK) { in xfs_bmap_btalloc_accounting()
3324 * COW fork blocks are in-core only and thus are treated as in xfs_bmap_btalloc_accounting()
3325 * in-core quota reservation (like delalloc blocks) even when in xfs_bmap_btalloc_accounting()
3326 * converted to real blocks. The quota reservation is not in xfs_bmap_btalloc_accounting()
3327 * accounted to disk until blocks are remapped to the data in xfs_bmap_btalloc_accounting()
3328 * fork. So if these blocks were previously delalloc, we in xfs_bmap_btalloc_accounting()
3332 if (ap->wasdel) { in xfs_bmap_btalloc_accounting()
3333 xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len); in xfs_bmap_btalloc_accounting()
3338 * Otherwise, we've allocated blocks in a hole. The transaction in xfs_bmap_btalloc_accounting()
3339 * has acquired in-core quota reservation for this extent. in xfs_bmap_btalloc_accounting()
3340 * Rather than account these as real blocks, however, we reduce in xfs_bmap_btalloc_accounting()
3345 ap->ip->i_delayed_blks += args->len; in xfs_bmap_btalloc_accounting()
3346 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, XFS_TRANS_DQ_RES_BLKS, in xfs_bmap_btalloc_accounting()
3347 -(long)args->len); in xfs_bmap_btalloc_accounting()
3352 ap->ip->i_nblocks += args->len; in xfs_bmap_btalloc_accounting()
3353 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); in xfs_bmap_btalloc_accounting()
3354 if (ap->wasdel) { in xfs_bmap_btalloc_accounting()
3355 ap->ip->i_delayed_blks -= args->len; in xfs_bmap_btalloc_accounting()
3356 xfs_mod_delalloc(ap->ip->i_mount, -(int64_t)args->len); in xfs_bmap_btalloc_accounting()
3358 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, in xfs_bmap_btalloc_accounting()
3359 ap->wasdel ? XFS_TRANS_DQ_DELBCOUNT : XFS_TRANS_DQ_BCOUNT, in xfs_bmap_btalloc_accounting()
3360 args->len); in xfs_bmap_btalloc_accounting()
3368 struct xfs_mount *mp = args->mp; in xfs_bmap_compute_alignments()
3373 if (mp->m_swidth && xfs_has_swalloc(mp)) in xfs_bmap_compute_alignments()
3374 stripe_align = mp->m_swidth; in xfs_bmap_compute_alignments()
3375 else if (mp->m_dalign) in xfs_bmap_compute_alignments()
3376 stripe_align = mp->m_dalign; in xfs_bmap_compute_alignments()
3378 if (ap->flags & XFS_BMAPI_COWFORK) in xfs_bmap_compute_alignments()
3379 align = xfs_get_cowextsz_hint(ap->ip); in xfs_bmap_compute_alignments()
3380 else if (ap->datatype & XFS_ALLOC_USERDATA) in xfs_bmap_compute_alignments()
3381 align = xfs_get_extsz_hint(ap->ip); in xfs_bmap_compute_alignments()
3383 if (xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, align, 0, in xfs_bmap_compute_alignments()
3384 ap->eof, 0, ap->conv, &ap->offset, in xfs_bmap_compute_alignments()
3385 &ap->length)) in xfs_bmap_compute_alignments()
3387 ASSERT(ap->length); in xfs_bmap_compute_alignments()
3392 args->prod = align; in xfs_bmap_compute_alignments()
3393 div_u64_rem(ap->offset, args->prod, &args->mod); in xfs_bmap_compute_alignments()
3394 if (args->mod) in xfs_bmap_compute_alignments()
3395 args->mod = args->prod - args->mod; in xfs_bmap_compute_alignments()
3396 } else if (mp->m_sb.sb_blocksize >= PAGE_SIZE) { in xfs_bmap_compute_alignments()
3397 args->prod = 1; in xfs_bmap_compute_alignments()
3398 args->mod = 0; in xfs_bmap_compute_alignments()
3400 args->prod = PAGE_SIZE >> mp->m_sb.sb_blocklog; in xfs_bmap_compute_alignments()
3401 div_u64_rem(ap->offset, args->prod, &args->mod); in xfs_bmap_compute_alignments()
3402 if (args->mod) in xfs_bmap_compute_alignments()
3403 args->mod = args->prod - args->mod; in xfs_bmap_compute_alignments()
3418 nullfb = ap->tp->t_firstblock == NULLFSBLOCK; in xfs_bmap_process_allocated_extent()
3425 XFS_FSB_TO_AGNO(args->mp, ap->tp->t_firstblock) <= in xfs_bmap_process_allocated_extent()
3426 XFS_FSB_TO_AGNO(args->mp, args->fsbno)); in xfs_bmap_process_allocated_extent()
3428 ap->blkno = args->fsbno; in xfs_bmap_process_allocated_extent()
3430 ap->tp->t_firstblock = args->fsbno; in xfs_bmap_process_allocated_extent()
3431 ap->length = args->len; in xfs_bmap_process_allocated_extent()
3444 if (ap->length <= orig_length) in xfs_bmap_process_allocated_extent()
3445 ap->offset = orig_offset; in xfs_bmap_process_allocated_extent()
3446 else if (ap->offset + ap->length < orig_offset + orig_length) in xfs_bmap_process_allocated_extent()
3447 ap->offset = orig_offset + orig_length - ap->length; in xfs_bmap_process_allocated_extent()
3456 struct xfs_mount *mp = ap->ip->i_mount; in xfs_bmap_exact_minlen_extent_alloc()
3457 struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; in xfs_bmap_exact_minlen_extent_alloc()
3462 ASSERT(ap->length); in xfs_bmap_exact_minlen_extent_alloc()
3464 if (ap->minlen != 1) { in xfs_bmap_exact_minlen_extent_alloc()
3465 ap->blkno = NULLFSBLOCK; in xfs_bmap_exact_minlen_extent_alloc()
3466 ap->length = 0; in xfs_bmap_exact_minlen_extent_alloc()
3470 orig_offset = ap->offset; in xfs_bmap_exact_minlen_extent_alloc()
3471 orig_length = ap->length; in xfs_bmap_exact_minlen_extent_alloc()
3477 if (ap->tp->t_firstblock == NULLFSBLOCK) { in xfs_bmap_exact_minlen_extent_alloc()
3486 ap->blkno = XFS_AGB_TO_FSB(mp, 0, 0); in xfs_bmap_exact_minlen_extent_alloc()
3488 ap->blkno = ap->tp->t_firstblock; in xfs_bmap_exact_minlen_extent_alloc()
3491 args.fsbno = ap->blkno; in xfs_bmap_exact_minlen_extent_alloc()
3494 args.minlen = args.maxlen = ap->minlen; in xfs_bmap_exact_minlen_extent_alloc()
3495 args.total = ap->total; in xfs_bmap_exact_minlen_extent_alloc()
3500 args.minleft = ap->minleft; in xfs_bmap_exact_minlen_extent_alloc()
3501 args.wasdel = ap->wasdel; in xfs_bmap_exact_minlen_extent_alloc()
3503 args.datatype = ap->datatype; in xfs_bmap_exact_minlen_extent_alloc()
3513 ap->blkno = NULLFSBLOCK; in xfs_bmap_exact_minlen_extent_alloc()
3514 ap->length = 0; in xfs_bmap_exact_minlen_extent_alloc()
3521 #define xfs_bmap_exact_minlen_extent_alloc(bma) (-EFSCORRUPTED)
3529 struct xfs_mount *mp = ap->ip->i_mount; in xfs_bmap_btalloc()
3530 struct xfs_alloc_arg args = { .tp = ap->tp, .mp = mp }; in xfs_bmap_btalloc()
3532 xfs_agnumber_t fb_agno; /* ag number of ap->firstblock */ in xfs_bmap_btalloc()
3538 int nullfb; /* true if ap->firstblock isn't set */ in xfs_bmap_btalloc()
3544 ASSERT(ap->length); in xfs_bmap_btalloc()
3545 orig_offset = ap->offset; in xfs_bmap_btalloc()
3546 orig_length = ap->length; in xfs_bmap_btalloc()
3550 nullfb = ap->tp->t_firstblock == NULLFSBLOCK; in xfs_bmap_btalloc()
3552 ap->tp->t_firstblock); in xfs_bmap_btalloc()
3554 if ((ap->datatype & XFS_ALLOC_USERDATA) && in xfs_bmap_btalloc()
3555 xfs_inode_is_filestream(ap->ip)) { in xfs_bmap_btalloc()
3556 ag = xfs_filestream_lookup_ag(ap->ip); in xfs_bmap_btalloc()
3558 ap->blkno = XFS_AGB_TO_FSB(mp, ag, 0); in xfs_bmap_btalloc()
3560 ap->blkno = XFS_INO_TO_FSB(mp, ap->ip->i_ino); in xfs_bmap_btalloc()
3563 ap->blkno = ap->tp->t_firstblock; in xfs_bmap_btalloc()
3568 * If allowed, use ap->blkno; otherwise must use firstblock since in xfs_bmap_btalloc()
3571 if (nullfb || XFS_FSB_TO_AGNO(mp, ap->blkno) == fb_agno) in xfs_bmap_btalloc()
3574 ap->blkno = ap->tp->t_firstblock; in xfs_bmap_btalloc()
3579 args.fsbno = ap->blkno; in xfs_bmap_btalloc()
3583 args.maxlen = min(ap->length, mp->m_ag_max_usable); in xfs_bmap_btalloc()
3591 if ((ap->datatype & XFS_ALLOC_USERDATA) && in xfs_bmap_btalloc()
3592 xfs_inode_is_filestream(ap->ip)) in xfs_bmap_btalloc()
3598 } else if (ap->tp->t_flags & XFS_TRANS_LOWMODE) { in xfs_bmap_btalloc()
3599 if (xfs_inode_is_filestream(ap->ip)) in xfs_bmap_btalloc()
3603 args.total = args.minlen = ap->minlen; in xfs_bmap_btalloc()
3606 args.total = ap->total; in xfs_bmap_btalloc()
3607 args.minlen = ap->minlen; in xfs_bmap_btalloc()
3611 * If we are not low on available data blocks, and the underlying in xfs_bmap_btalloc()
3613 * try to allocate data blocks on stripe unit boundary. NOTE: ap->aeof in xfs_bmap_btalloc()
3617 if (!(ap->tp->t_flags & XFS_TRANS_LOWMODE) && ap->aeof) { in xfs_bmap_btalloc()
3618 if (!ap->offset) { in xfs_bmap_btalloc()
3628 args.minlen = blen - args.alignment; in xfs_bmap_btalloc()
3647 nextminlen = blen - stripe_align; in xfs_bmap_btalloc()
3652 nextminlen + stripe_align - in xfs_bmap_btalloc()
3653 args.minlen - 1; in xfs_bmap_btalloc()
3661 args.minleft = ap->minleft; in xfs_bmap_btalloc()
3662 args.wasdel = ap->wasdel; in xfs_bmap_btalloc()
3664 args.datatype = ap->datatype; in xfs_bmap_btalloc()
3676 args.fsbno = ap->blkno; in xfs_bmap_btalloc()
3690 args.fsbno = ap->blkno; in xfs_bmap_btalloc()
3696 args.minlen > ap->minlen) { in xfs_bmap_btalloc()
3697 args.minlen = ap->minlen; in xfs_bmap_btalloc()
3699 args.fsbno = ap->blkno; in xfs_bmap_btalloc()
3706 args.total = ap->minlen; in xfs_bmap_btalloc()
3709 ap->tp->t_flags |= XFS_TRANS_LOWMODE; in xfs_bmap_btalloc()
3716 ap->blkno = NULLFSBLOCK; in xfs_bmap_btalloc()
3717 ap->length = 0; in xfs_bmap_btalloc()
3732 if (irec->br_startoff + irec->br_blockcount <= bno || in xfs_trim_extent()
3733 irec->br_startoff >= end) { in xfs_trim_extent()
3734 irec->br_blockcount = 0; in xfs_trim_extent()
3738 if (irec->br_startoff < bno) { in xfs_trim_extent()
3739 distance = bno - irec->br_startoff; in xfs_trim_extent()
3740 if (isnullstartblock(irec->br_startblock)) in xfs_trim_extent()
3741 irec->br_startblock = DELAYSTARTBLOCK; in xfs_trim_extent()
3742 if (irec->br_startblock != DELAYSTARTBLOCK && in xfs_trim_extent()
3743 irec->br_startblock != HOLESTARTBLOCK) in xfs_trim_extent()
3744 irec->br_startblock += distance; in xfs_trim_extent()
3745 irec->br_startoff += distance; in xfs_trim_extent()
3746 irec->br_blockcount -= distance; in xfs_trim_extent()
3749 if (end < irec->br_startoff + irec->br_blockcount) { in xfs_trim_extent()
3750 distance = irec->br_startoff + irec->br_blockcount - end; in xfs_trim_extent()
3751 irec->br_blockcount -= distance; in xfs_trim_extent()
3770 got->br_startoff + got->br_blockcount <= obno) { in xfs_bmapi_trim_map()
3772 if (isnullstartblock(got->br_startblock)) in xfs_bmapi_trim_map()
3773 mval->br_startblock = DELAYSTARTBLOCK; in xfs_bmapi_trim_map()
3781 mval->br_startoff = *bno; in xfs_bmapi_trim_map()
3782 if (isnullstartblock(got->br_startblock)) in xfs_bmapi_trim_map()
3783 mval->br_startblock = DELAYSTARTBLOCK; in xfs_bmapi_trim_map()
3785 mval->br_startblock = got->br_startblock + in xfs_bmapi_trim_map()
3786 (*bno - got->br_startoff); in xfs_bmapi_trim_map()
3794 mval->br_blockcount = XFS_FILBLKS_MIN(end - *bno, in xfs_bmapi_trim_map()
3795 got->br_blockcount - (*bno - got->br_startoff)); in xfs_bmapi_trim_map()
3796 mval->br_state = got->br_state; in xfs_bmapi_trim_map()
3797 ASSERT(mval->br_blockcount <= len); in xfs_bmapi_trim_map()
3817 ((mval->br_startoff + mval->br_blockcount) <= end)); in xfs_bmapi_update_map()
3818 ASSERT((flags & XFS_BMAPI_ENTIRE) || (mval->br_blockcount <= *len) || in xfs_bmapi_update_map()
3819 (mval->br_startoff < obno)); in xfs_bmapi_update_map()
3821 *bno = mval->br_startoff + mval->br_blockcount; in xfs_bmapi_update_map()
3822 *len = end - *bno; in xfs_bmapi_update_map()
3823 if (*n > 0 && mval->br_startoff == mval[-1].br_startoff) { in xfs_bmapi_update_map()
3825 ASSERT(mval->br_startblock == mval[-1].br_startblock); in xfs_bmapi_update_map()
3826 ASSERT(mval->br_blockcount > mval[-1].br_blockcount); in xfs_bmapi_update_map()
3827 ASSERT(mval->br_state == mval[-1].br_state); in xfs_bmapi_update_map()
3828 mval[-1].br_blockcount = mval->br_blockcount; in xfs_bmapi_update_map()
3829 mval[-1].br_state = mval->br_state; in xfs_bmapi_update_map()
3830 } else if (*n > 0 && mval->br_startblock != DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3831 mval[-1].br_startblock != DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3832 mval[-1].br_startblock != HOLESTARTBLOCK && in xfs_bmapi_update_map()
3833 mval->br_startblock == mval[-1].br_startblock + in xfs_bmapi_update_map()
3834 mval[-1].br_blockcount && in xfs_bmapi_update_map()
3835 mval[-1].br_state == mval->br_state) { in xfs_bmapi_update_map()
3836 ASSERT(mval->br_startoff == in xfs_bmapi_update_map()
3837 mval[-1].br_startoff + mval[-1].br_blockcount); in xfs_bmapi_update_map()
3838 mval[-1].br_blockcount += mval->br_blockcount; in xfs_bmapi_update_map()
3840 mval->br_startblock == DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3841 mval[-1].br_startblock == DELAYSTARTBLOCK && in xfs_bmapi_update_map()
3842 mval->br_startoff == in xfs_bmapi_update_map()
3843 mval[-1].br_startoff + mval[-1].br_blockcount) { in xfs_bmapi_update_map()
3844 mval[-1].br_blockcount += mval->br_blockcount; in xfs_bmapi_update_map()
3845 mval[-1].br_state = mval->br_state; in xfs_bmapi_update_map()
3847 ((mval->br_startoff + mval->br_blockcount) <= in xfs_bmapi_update_map()
3856 * Map file blocks to filesystem blocks without allocation.
3860 struct xfs_inode *ip, in xfs_bmapi_read() argument
3867 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_read()
3869 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmapi_read()
3880 ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED|XFS_ILOCK_EXCL)); in xfs_bmapi_read()
3883 return -EFSCORRUPTED; in xfs_bmapi_read()
3887 return -EFSCORRUPTED; in xfs_bmapi_read()
3890 return -EIO; in xfs_bmapi_read()
3894 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_bmapi_read()
3898 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) in xfs_bmapi_read()
3909 mval->br_startoff = bno; in xfs_bmapi_read()
3910 mval->br_startblock = HOLESTARTBLOCK; in xfs_bmapi_read()
3911 mval->br_blockcount = in xfs_bmapi_read()
3912 XFS_FILBLKS_MIN(len, got.br_startoff - bno); in xfs_bmapi_read()
3913 mval->br_state = XFS_EXT_NORM; in xfs_bmapi_read()
3914 bno += mval->br_blockcount; in xfs_bmapi_read()
3915 len -= mval->br_blockcount; in xfs_bmapi_read()
3938 * Add a delayed allocation extent to an inode. Blocks are reserved from the
3939 * global pool and the extent inserted into the inode in-core extent tree.
3952 struct xfs_inode *ip, in xfs_bmapi_reserve_delalloc() argument
3961 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_reserve_delalloc()
3962 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmapi_reserve_delalloc()
3974 alen = XFS_FILBLKS_MIN(alen, got->br_startoff - aoff); in xfs_bmapi_reserve_delalloc()
3976 prealloc = alen - len; in xfs_bmapi_reserve_delalloc()
3981 xfs_extlen_t extsz = xfs_get_cowextsz_hint(ip); in xfs_bmapi_reserve_delalloc()
3992 * Make a transaction-less quota reservation for delayed allocation in xfs_bmapi_reserve_delalloc()
3993 * blocks. This number gets adjusted later. We return if we haven't in xfs_bmapi_reserve_delalloc()
3994 * allocated blocks already inside this loop. in xfs_bmapi_reserve_delalloc()
3996 error = xfs_quota_reserve_blkres(ip, alen); in xfs_bmapi_reserve_delalloc()
4004 indlen = (xfs_extlen_t)xfs_bmap_worst_indlen(ip, alen); in xfs_bmapi_reserve_delalloc()
4007 error = xfs_mod_fdblocks(mp, -((int64_t)alen), false); in xfs_bmapi_reserve_delalloc()
4011 error = xfs_mod_fdblocks(mp, -((int64_t)indlen), false); in xfs_bmapi_reserve_delalloc()
4016 ip->i_delayed_blks += alen; in xfs_bmapi_reserve_delalloc()
4017 xfs_mod_delalloc(ip->i_mount, alen + indlen); in xfs_bmapi_reserve_delalloc()
4019 got->br_startoff = aoff; in xfs_bmapi_reserve_delalloc()
4020 got->br_startblock = nullstartblock(indlen); in xfs_bmapi_reserve_delalloc()
4021 got->br_blockcount = alen; in xfs_bmapi_reserve_delalloc()
4022 got->br_state = XFS_EXT_NORM; in xfs_bmapi_reserve_delalloc()
4024 xfs_bmap_add_extent_hole_delay(ip, whichfork, icur, got); in xfs_bmapi_reserve_delalloc()
4027 * Tag the inode if blocks were preallocated. Note that COW fork in xfs_bmapi_reserve_delalloc()
4032 xfs_inode_set_eofblocks_tag(ip); in xfs_bmapi_reserve_delalloc()
4034 xfs_inode_set_cowblocks_tag(ip); in xfs_bmapi_reserve_delalloc()
4042 xfs_quota_unreserve_blkres(ip, alen); in xfs_bmapi_reserve_delalloc()
4050 struct xfs_mount *mp = bma->ip->i_mount; in xfs_bmap_alloc_userdata()
4051 int whichfork = xfs_bmapi_whichfork(bma->flags); in xfs_bmap_alloc_userdata()
4060 bma->datatype = XFS_ALLOC_NOBUSY; in xfs_bmap_alloc_userdata()
4062 bma->datatype |= XFS_ALLOC_USERDATA; in xfs_bmap_alloc_userdata()
4063 if (bma->offset == 0) in xfs_bmap_alloc_userdata()
4064 bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA; in xfs_bmap_alloc_userdata()
4066 if (mp->m_dalign && bma->length >= mp->m_dalign) { in xfs_bmap_alloc_userdata()
4072 if (XFS_IS_REALTIME_INODE(bma->ip)) in xfs_bmap_alloc_userdata()
4087 struct xfs_mount *mp = bma->ip->i_mount; in xfs_bmapi_allocate()
4088 int whichfork = xfs_bmapi_whichfork(bma->flags); in xfs_bmapi_allocate()
4089 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmapi_allocate()
4093 ASSERT(bma->length > 0); in xfs_bmapi_allocate()
4099 if (bma->wasdel) { in xfs_bmapi_allocate()
4100 bma->length = (xfs_extlen_t)bma->got.br_blockcount; in xfs_bmapi_allocate()
4101 bma->offset = bma->got.br_startoff; in xfs_bmapi_allocate()
4102 if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev)) in xfs_bmapi_allocate()
4103 bma->prev.br_startoff = NULLFILEOFF; in xfs_bmapi_allocate()
4105 bma->length = XFS_FILBLKS_MIN(bma->length, XFS_MAX_BMBT_EXTLEN); in xfs_bmapi_allocate()
4106 if (!bma->eof) in xfs_bmapi_allocate()
4107 bma->length = XFS_FILBLKS_MIN(bma->length, in xfs_bmapi_allocate()
4108 bma->got.br_startoff - bma->offset); in xfs_bmapi_allocate()
4111 if (bma->flags & XFS_BMAPI_CONTIG) in xfs_bmapi_allocate()
4112 bma->minlen = bma->length; in xfs_bmapi_allocate()
4114 bma->minlen = 1; in xfs_bmapi_allocate()
4116 if (bma->flags & XFS_BMAPI_METADATA) { in xfs_bmapi_allocate()
4125 if (error || bma->blkno == NULLFSBLOCK) in xfs_bmapi_allocate()
4128 if (bma->flags & XFS_BMAPI_ZERO) { in xfs_bmapi_allocate()
4129 error = xfs_zero_extent(bma->ip, bma->blkno, bma->length); in xfs_bmapi_allocate()
4134 if (ifp->if_format == XFS_DINODE_FMT_BTREE && !bma->cur) in xfs_bmapi_allocate()
4135 bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork); in xfs_bmapi_allocate()
4140 bma->nallocs++; in xfs_bmapi_allocate()
4142 if (bma->cur) in xfs_bmapi_allocate()
4143 bma->cur->bc_ino.flags = in xfs_bmapi_allocate()
4144 bma->wasdel ? XFS_BTCUR_BMBT_WASDEL : 0; in xfs_bmapi_allocate()
4146 bma->got.br_startoff = bma->offset; in xfs_bmapi_allocate()
4147 bma->got.br_startblock = bma->blkno; in xfs_bmapi_allocate()
4148 bma->got.br_blockcount = bma->length; in xfs_bmapi_allocate()
4149 bma->got.br_state = XFS_EXT_NORM; in xfs_bmapi_allocate()
4151 if (bma->flags & XFS_BMAPI_PREALLOC) in xfs_bmapi_allocate()
4152 bma->got.br_state = XFS_EXT_UNWRITTEN; in xfs_bmapi_allocate()
4154 if (bma->wasdel) in xfs_bmapi_allocate()
4157 error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip, in xfs_bmapi_allocate()
4158 whichfork, &bma->icur, &bma->cur, &bma->got, in xfs_bmapi_allocate()
4159 &bma->logflags, bma->flags); in xfs_bmapi_allocate()
4161 bma->logflags |= tmp_logflags; in xfs_bmapi_allocate()
4170 xfs_iext_get_extent(ifp, &bma->icur, &bma->got); in xfs_bmapi_allocate()
4172 ASSERT(bma->got.br_startoff <= bma->offset); in xfs_bmapi_allocate()
4173 ASSERT(bma->got.br_startoff + bma->got.br_blockcount >= in xfs_bmapi_allocate()
4174 bma->offset + bma->length); in xfs_bmapi_allocate()
4175 ASSERT(bma->got.br_state == XFS_EXT_NORM || in xfs_bmapi_allocate()
4176 bma->got.br_state == XFS_EXT_UNWRITTEN); in xfs_bmapi_allocate()
4188 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmapi_convert_unwritten()
4192 /* check if we need to do unwritten->real conversion */ in xfs_bmapi_convert_unwritten()
4193 if (mval->br_state == XFS_EXT_UNWRITTEN && in xfs_bmapi_convert_unwritten()
4197 /* check if we need to do real->unwritten conversion */ in xfs_bmapi_convert_unwritten()
4198 if (mval->br_state == XFS_EXT_NORM && in xfs_bmapi_convert_unwritten()
4206 ASSERT(mval->br_blockcount <= len); in xfs_bmapi_convert_unwritten()
4207 if (ifp->if_format == XFS_DINODE_FMT_BTREE && !bma->cur) { in xfs_bmapi_convert_unwritten()
4208 bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp, in xfs_bmapi_convert_unwritten()
4209 bma->ip, whichfork); in xfs_bmapi_convert_unwritten()
4211 mval->br_state = (mval->br_state == XFS_EXT_UNWRITTEN) in xfs_bmapi_convert_unwritten()
4219 error = xfs_zero_extent(bma->ip, mval->br_startblock, in xfs_bmapi_convert_unwritten()
4220 mval->br_blockcount); in xfs_bmapi_convert_unwritten()
4225 error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, whichfork, in xfs_bmapi_convert_unwritten()
4226 &bma->icur, &bma->cur, mval, &tmp_logflags); in xfs_bmapi_convert_unwritten()
4236 * any on-disk updates to make, so we don't need to log anything. in xfs_bmapi_convert_unwritten()
4239 bma->logflags |= tmp_logflags | XFS_ILOG_CORE; in xfs_bmapi_convert_unwritten()
4248 xfs_iext_get_extent(ifp, &bma->icur, &bma->got); in xfs_bmapi_convert_unwritten()
4254 if (mval->br_blockcount < len) in xfs_bmapi_convert_unwritten()
4255 return -EAGAIN; in xfs_bmapi_convert_unwritten()
4262 struct xfs_inode *ip, in xfs_bmapi_minleft() argument
4265 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, fork); in xfs_bmapi_minleft()
4267 if (tp && tp->t_firstblock != NULLFSBLOCK) in xfs_bmapi_minleft()
4269 if (ifp->if_format != XFS_DINODE_FMT_BTREE) in xfs_bmapi_minleft()
4271 return be16_to_cpu(ifp->if_broot->bb_level) + 1; in xfs_bmapi_minleft()
4286 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork); in xfs_bmapi_finish()
4288 if ((bma->logflags & xfs_ilog_fext(whichfork)) && in xfs_bmapi_finish()
4289 ifp->if_format != XFS_DINODE_FMT_EXTENTS) in xfs_bmapi_finish()
4290 bma->logflags &= ~xfs_ilog_fext(whichfork); in xfs_bmapi_finish()
4291 else if ((bma->logflags & xfs_ilog_fbroot(whichfork)) && in xfs_bmapi_finish()
4292 ifp->if_format != XFS_DINODE_FMT_BTREE) in xfs_bmapi_finish()
4293 bma->logflags &= ~xfs_ilog_fbroot(whichfork); in xfs_bmapi_finish()
4295 if (bma->logflags) in xfs_bmapi_finish()
4296 xfs_trans_log_inode(bma->tp, bma->ip, bma->logflags); in xfs_bmapi_finish()
4297 if (bma->cur) in xfs_bmapi_finish()
4298 xfs_btree_del_cursor(bma->cur, error); in xfs_bmapi_finish()
4302 * Map file blocks to filesystem blocks, and allocate blocks or convert the
4304 * parameter. Only allocates blocks from a single allocation group, to avoid
4310 struct xfs_inode *ip, /* incore inode */ in xfs_bmapi_write() argument
4314 xfs_extlen_t total, /* total blocks needed */ in xfs_bmapi_write()
4320 .ip = ip, in xfs_bmapi_write()
4323 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_write()
4325 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmapi_write()
4350 ASSERT(ifp->if_format != XFS_DINODE_FMT_LOCAL); in xfs_bmapi_write()
4351 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in xfs_bmapi_write()
4358 * we can allocate unwritten extents or pre-zero allocated blocks, in xfs_bmapi_write()
4368 return -EFSCORRUPTED; in xfs_bmapi_write()
4372 return -EIO; in xfs_bmapi_write()
4376 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmapi_write()
4380 if (!xfs_iext_lookup_extent(ip, ifp, bno, &bma.icur, &bma.got)) in xfs_bmapi_write()
4384 bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork); in xfs_bmapi_write()
4423 * check for 32-bit overflows and handle them here. in xfs_bmapi_write()
4453 if (error == -EAGAIN) in xfs_bmapi_write()
4476 error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags, in xfs_bmapi_write()
4481 ASSERT(ifp->if_format != XFS_DINODE_FMT_BTREE || in xfs_bmapi_write()
4482 ifp->if_nextents > XFS_IFORK_MAXEXT(ip, whichfork)); in xfs_bmapi_write()
4493 * Convert an existing delalloc extent to real blocks based on file offset. This
4500 struct xfs_inode *ip, in xfs_bmapi_convert_delalloc() argument
4506 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmapi_convert_delalloc()
4507 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_convert_delalloc()
4518 * Space for the extent and indirect blocks was reserved when the in xfs_bmapi_convert_delalloc()
4521 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, in xfs_bmapi_convert_delalloc()
4526 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmapi_convert_delalloc()
4527 xfs_trans_ijoin(tp, ip, 0); in xfs_bmapi_convert_delalloc()
4529 error = xfs_iext_count_may_overflow(ip, whichfork, in xfs_bmapi_convert_delalloc()
4531 if (error == -EFBIG) in xfs_bmapi_convert_delalloc()
4532 error = xfs_iext_count_upgrade(tp, ip, in xfs_bmapi_convert_delalloc()
4537 if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) || in xfs_bmapi_convert_delalloc()
4545 error = -EAGAIN; in xfs_bmapi_convert_delalloc()
4554 xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags); in xfs_bmapi_convert_delalloc()
4555 *seq = READ_ONCE(ifp->if_seq); in xfs_bmapi_convert_delalloc()
4560 bma.ip = ip; in xfs_bmapi_convert_delalloc()
4565 bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork); in xfs_bmapi_convert_delalloc()
4591 error = -ENOSPC; in xfs_bmapi_convert_delalloc()
4594 error = -EFSCORRUPTED; in xfs_bmapi_convert_delalloc()
4595 if (WARN_ON_ONCE(!xfs_valid_startblock(ip, bma.got.br_startblock))) in xfs_bmapi_convert_delalloc()
4602 xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags); in xfs_bmapi_convert_delalloc()
4603 *seq = READ_ONCE(ifp->if_seq); in xfs_bmapi_convert_delalloc()
4608 error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags, in xfs_bmapi_convert_delalloc()
4615 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmapi_convert_delalloc()
4622 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmapi_convert_delalloc()
4629 struct xfs_inode *ip, in xfs_bmapi_remap() argument
4635 struct xfs_mount *mp = ip->i_mount; in xfs_bmapi_remap()
4643 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmapi_remap()
4646 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in xfs_bmapi_remap()
4654 return -EFSCORRUPTED; in xfs_bmapi_remap()
4658 return -EIO; in xfs_bmapi_remap()
4660 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmapi_remap()
4664 if (xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_bmapi_remap()
4667 ASSERT(got.br_startoff - bno >= len); in xfs_bmapi_remap()
4670 ip->i_nblocks += len; in xfs_bmapi_remap()
4671 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_bmapi_remap()
4673 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmapi_remap()
4674 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmapi_remap()
4675 cur->bc_ino.flags = 0; in xfs_bmapi_remap()
4686 error = xfs_bmap_add_extent_hole_real(tp, ip, whichfork, &icur, in xfs_bmapi_remap()
4691 error = xfs_bmap_btree_to_extents(tp, ip, cur, &logflags, whichfork); in xfs_bmapi_remap()
4694 if (ip->i_df.if_format != XFS_DINODE_FMT_EXTENTS) in xfs_bmapi_remap()
4696 else if (ip->i_df.if_format != XFS_DINODE_FMT_BTREE) in xfs_bmapi_remap()
4700 xfs_trans_log_inode(tp, ip, logflags); in xfs_bmapi_remap()
4714 * blocks from a deleted extent to make up a reservation deficiency (e.g., if
4715 * ores == 1). The number of stolen blocks is returned. The availability and
4716 * subsequent accounting of stolen blocks is the responsibility of the caller.
4723 xfs_filblks_t avail) /* stealable blocks */ in xfs_bmap_split_indlen()
4732 * Steal as many blocks as we can to try and satisfy the worst case in xfs_bmap_split_indlen()
4736 stolen = XFS_FILBLKS_MIN(nres - ores, avail); in xfs_bmap_split_indlen()
4766 ores -= (len1 + len2); in xfs_bmap_split_indlen()
4767 ASSERT((*indlen1 - len1) + (*indlen2 - len2) >= ores); in xfs_bmap_split_indlen()
4770 ores--; in xfs_bmap_split_indlen()
4775 ores--; in xfs_bmap_split_indlen()
4781 ores--; in xfs_bmap_split_indlen()
4793 struct xfs_inode *ip, in xfs_bmap_del_extent_delay() argument
4799 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_del_extent_delay()
4800 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_del_extent_delay()
4811 isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip); in xfs_bmap_del_extent_delay()
4812 del_endoff = del->br_startoff + del->br_blockcount; in xfs_bmap_del_extent_delay()
4813 got_endoff = got->br_startoff + got->br_blockcount; in xfs_bmap_del_extent_delay()
4814 da_old = startblockval(got->br_startblock); in xfs_bmap_del_extent_delay()
4817 ASSERT(del->br_blockcount > 0); in xfs_bmap_del_extent_delay()
4818 ASSERT(got->br_startoff <= del->br_startoff); in xfs_bmap_del_extent_delay()
4822 uint64_t rtexts = XFS_FSB_TO_B(mp, del->br_blockcount); in xfs_bmap_del_extent_delay()
4824 do_div(rtexts, mp->m_sb.sb_rextsize); in xfs_bmap_del_extent_delay()
4830 * sb counters as we might have to borrow some blocks for the in xfs_bmap_del_extent_delay()
4834 error = xfs_quota_unreserve_blkres(ip, del->br_blockcount); in xfs_bmap_del_extent_delay()
4837 ip->i_delayed_blks -= del->br_blockcount; in xfs_bmap_del_extent_delay()
4839 if (got->br_startoff == del->br_startoff) in xfs_bmap_del_extent_delay()
4849 xfs_iext_remove(ip, icur, state); in xfs_bmap_del_extent_delay()
4856 got->br_startoff = del_endoff; in xfs_bmap_del_extent_delay()
4857 got->br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_delay()
4858 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, in xfs_bmap_del_extent_delay()
4859 got->br_blockcount), da_old); in xfs_bmap_del_extent_delay()
4860 got->br_startblock = nullstartblock((int)da_new); in xfs_bmap_del_extent_delay()
4861 xfs_iext_update_extent(ip, state, icur, got); in xfs_bmap_del_extent_delay()
4867 got->br_blockcount = got->br_blockcount - del->br_blockcount; in xfs_bmap_del_extent_delay()
4868 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(ip, in xfs_bmap_del_extent_delay()
4869 got->br_blockcount), da_old); in xfs_bmap_del_extent_delay()
4870 got->br_startblock = nullstartblock((int)da_new); in xfs_bmap_del_extent_delay()
4871 xfs_iext_update_extent(ip, state, icur, got); in xfs_bmap_del_extent_delay()
4878 * extents. Steal blocks from the deleted extent if necessary. in xfs_bmap_del_extent_delay()
4879 * Stealing blocks simply fudges the fdblocks accounting below. in xfs_bmap_del_extent_delay()
4883 got->br_blockcount = del->br_startoff - got->br_startoff; in xfs_bmap_del_extent_delay()
4884 got_indlen = xfs_bmap_worst_indlen(ip, got->br_blockcount); in xfs_bmap_del_extent_delay()
4886 new.br_blockcount = got_endoff - del_endoff; in xfs_bmap_del_extent_delay()
4887 new_indlen = xfs_bmap_worst_indlen(ip, new.br_blockcount); in xfs_bmap_del_extent_delay()
4891 del->br_blockcount); in xfs_bmap_del_extent_delay()
4893 got->br_startblock = nullstartblock((int)got_indlen); in xfs_bmap_del_extent_delay()
4896 new.br_state = got->br_state; in xfs_bmap_del_extent_delay()
4899 xfs_iext_update_extent(ip, state, icur, got); in xfs_bmap_del_extent_delay()
4901 xfs_iext_insert(ip, icur, &new, state); in xfs_bmap_del_extent_delay()
4903 da_new = got_indlen + new_indlen - stolen; in xfs_bmap_del_extent_delay()
4904 del->br_blockcount -= stolen; in xfs_bmap_del_extent_delay()
4909 da_diff = da_old - da_new; in xfs_bmap_del_extent_delay()
4911 da_diff += del->br_blockcount; in xfs_bmap_del_extent_delay()
4914 xfs_mod_delalloc(mp, -da_diff); in xfs_bmap_del_extent_delay()
4921 struct xfs_inode *ip, in xfs_bmap_del_extent_cow() argument
4926 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_del_extent_cow()
4927 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); in xfs_bmap_del_extent_cow()
4934 del_endoff = del->br_startoff + del->br_blockcount; in xfs_bmap_del_extent_cow()
4935 got_endoff = got->br_startoff + got->br_blockcount; in xfs_bmap_del_extent_cow()
4937 ASSERT(del->br_blockcount > 0); in xfs_bmap_del_extent_cow()
4938 ASSERT(got->br_startoff <= del->br_startoff); in xfs_bmap_del_extent_cow()
4940 ASSERT(!isnullstartblock(got->br_startblock)); in xfs_bmap_del_extent_cow()
4942 if (got->br_startoff == del->br_startoff) in xfs_bmap_del_extent_cow()
4952 xfs_iext_remove(ip, icur, state); in xfs_bmap_del_extent_cow()
4959 got->br_startoff = del_endoff; in xfs_bmap_del_extent_cow()
4960 got->br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_cow()
4961 got->br_startblock = del->br_startblock + del->br_blockcount; in xfs_bmap_del_extent_cow()
4962 xfs_iext_update_extent(ip, state, icur, got); in xfs_bmap_del_extent_cow()
4968 got->br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_cow()
4969 xfs_iext_update_extent(ip, state, icur, got); in xfs_bmap_del_extent_cow()
4975 got->br_blockcount = del->br_startoff - got->br_startoff; in xfs_bmap_del_extent_cow()
4978 new.br_blockcount = got_endoff - del_endoff; in xfs_bmap_del_extent_cow()
4979 new.br_state = got->br_state; in xfs_bmap_del_extent_cow()
4980 new.br_startblock = del->br_startblock + del->br_blockcount; in xfs_bmap_del_extent_cow()
4982 xfs_iext_update_extent(ip, state, icur, got); in xfs_bmap_del_extent_cow()
4984 xfs_iext_insert(ip, icur, &new, state); in xfs_bmap_del_extent_cow()
4987 ip->i_delayed_blks -= del->br_blockcount; in xfs_bmap_del_extent_cow()
4996 xfs_inode_t *ip, /* incore inode pointer */ in xfs_bmap_del_extent_real() argument
5022 mp = ip->i_mount; in xfs_bmap_del_extent_real()
5025 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_del_extent_real()
5026 ASSERT(del->br_blockcount > 0); in xfs_bmap_del_extent_real()
5028 ASSERT(got.br_startoff <= del->br_startoff); in xfs_bmap_del_extent_real()
5029 del_endoff = del->br_startoff + del->br_blockcount; in xfs_bmap_del_extent_real()
5040 * btree format, then reject it. The calling code will then swap blocks in xfs_bmap_del_extent_real()
5044 if (tp->t_blk_res == 0 && in xfs_bmap_del_extent_real()
5045 ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_bmap_del_extent_real()
5046 ifp->if_nextents >= XFS_IFORK_MAXEXT(ip, whichfork) && in xfs_bmap_del_extent_real()
5047 del->br_startoff > got.br_startoff && del_endoff < got_endoff) in xfs_bmap_del_extent_real()
5048 return -ENOSPC; in xfs_bmap_del_extent_real()
5051 if (whichfork == XFS_DATA_FORK && XFS_IS_REALTIME_INODE(ip)) { in xfs_bmap_del_extent_real()
5055 len = div_u64_rem(del->br_blockcount, mp->m_sb.sb_rextsize, in xfs_bmap_del_extent_real()
5062 bno = div_u64_rem(del->br_startblock, in xfs_bmap_del_extent_real()
5063 mp->m_sb.sb_rextsize, &mod); in xfs_bmap_del_extent_real()
5072 nblks = len * mp->m_sb.sb_rextsize; in xfs_bmap_del_extent_real()
5076 nblks = del->br_blockcount; in xfs_bmap_del_extent_real()
5080 del_endblock = del->br_startblock + del->br_blockcount; in xfs_bmap_del_extent_real()
5086 error = -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5091 if (got.br_startoff == del->br_startoff) in xfs_bmap_del_extent_real()
5101 xfs_iext_remove(ip, icur, state); in xfs_bmap_del_extent_real()
5103 ifp->if_nextents--; in xfs_bmap_del_extent_real()
5113 error = -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5123 got.br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_real()
5124 xfs_iext_update_extent(ip, state, icur, &got); in xfs_bmap_del_extent_real()
5137 got.br_blockcount -= del->br_blockcount; in xfs_bmap_del_extent_real()
5138 xfs_iext_update_extent(ip, state, icur, &got); in xfs_bmap_del_extent_real()
5154 got.br_blockcount = del->br_startoff - got.br_startoff; in xfs_bmap_del_extent_real()
5155 xfs_iext_update_extent(ip, state, icur, &got); in xfs_bmap_del_extent_real()
5158 new.br_blockcount = got_endoff - del_endoff; in xfs_bmap_del_extent_real()
5170 cur->bc_rec.b = new; in xfs_bmap_del_extent_real()
5172 if (error && error != -ENOSPC) in xfs_bmap_del_extent_real()
5175 * If get no-space back from btree insert, it tried a in xfs_bmap_del_extent_real()
5179 if (error == -ENOSPC) { in xfs_bmap_del_extent_real()
5188 error = -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5202 xfs_iext_update_extent(ip, state, icur, &old); in xfs_bmap_del_extent_real()
5204 error = -ENOSPC; in xfs_bmap_del_extent_real()
5208 error = -EFSCORRUPTED; in xfs_bmap_del_extent_real()
5214 ifp->if_nextents++; in xfs_bmap_del_extent_real()
5216 xfs_iext_insert(ip, icur, &new, state); in xfs_bmap_del_extent_real()
5221 xfs_rmap_unmap_extent(tp, ip, whichfork, del); in xfs_bmap_del_extent_real()
5227 if (xfs_is_reflink_inode(ip) && whichfork == XFS_DATA_FORK) { in xfs_bmap_del_extent_real()
5230 __xfs_free_extent_later(tp, del->br_startblock, in xfs_bmap_del_extent_real()
5231 del->br_blockcount, NULL, in xfs_bmap_del_extent_real()
5233 del->br_state == XFS_EXT_UNWRITTEN); in xfs_bmap_del_extent_real()
5238 * Adjust inode # blocks in the file. in xfs_bmap_del_extent_real()
5241 ip->i_nblocks -= nblks; in xfs_bmap_del_extent_real()
5246 xfs_trans_mod_dquot_byino(tp, ip, qfield, (long)-nblks); in xfs_bmap_del_extent_real()
5254 * Unmap (remove) blocks from a file.
5262 struct xfs_inode *ip, /* incore inode */ in __xfs_bunmapi() argument
5277 struct xfs_mount *mp = ip->i_mount; in __xfs_bunmapi()
5287 trace_xfs_bunmap(ip, start, len, flags, _RET_IP_); in __xfs_bunmapi()
5291 ifp = xfs_ifork_ptr(ip, whichfork); in __xfs_bunmapi()
5293 return -EFSCORRUPTED; in __xfs_bunmapi()
5295 return -EIO; in __xfs_bunmapi()
5297 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in __xfs_bunmapi()
5301 error = xfs_iread_extents(tp, ip, whichfork); in __xfs_bunmapi()
5310 isrt = (whichfork == XFS_DATA_FORK) && XFS_IS_REALTIME_INODE(ip); in __xfs_bunmapi()
5313 if (!xfs_iext_lookup_extent_before(ip, ifp, &end, &icur, &got)) { in __xfs_bunmapi()
5317 end--; in __xfs_bunmapi()
5320 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in __xfs_bunmapi()
5321 ASSERT(ifp->if_format == XFS_DINODE_FMT_BTREE); in __xfs_bunmapi()
5322 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in __xfs_bunmapi()
5323 cur->bc_ino.flags = 0; in __xfs_bunmapi()
5331 xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); in __xfs_bunmapi()
5332 xfs_trans_ijoin(tp, mp->m_rbmip, XFS_ILOCK_EXCL); in __xfs_bunmapi()
5333 xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); in __xfs_bunmapi()
5334 xfs_trans_ijoin(tp, mp->m_rsumip, XFS_ILOCK_EXCL); in __xfs_bunmapi()
5338 while (end != (xfs_fileoff_t)-1 && end >= start && in __xfs_bunmapi()
5354 got.br_startoff + got.br_blockcount - 1); in __xfs_bunmapi()
5366 del.br_blockcount -= start - got.br_startoff; in __xfs_bunmapi()
5368 del.br_startblock += start - got.br_startoff; in __xfs_bunmapi()
5371 del.br_blockcount = end + 1 - del.br_startoff; in __xfs_bunmapi()
5377 div_u64_rem(sum, mp->m_sb.sb_rextsize, &mod); in __xfs_bunmapi()
5392 end -= mod > del.br_blockcount ? in __xfs_bunmapi()
5406 ASSERT(tp->t_blk_res > 0); in __xfs_bunmapi()
5412 del.br_startoff += del.br_blockcount - mod; in __xfs_bunmapi()
5413 del.br_startblock += del.br_blockcount - mod; in __xfs_bunmapi()
5417 error = xfs_bmap_add_extent_unwritten_real(tp, ip, in __xfs_bunmapi()
5424 div_u64_rem(del.br_startblock, mp->m_sb.sb_rextsize, &mod); in __xfs_bunmapi()
5426 xfs_extlen_t off = mp->m_sb.sb_rextsize - mod; in __xfs_bunmapi()
5434 del.br_blockcount -= off; in __xfs_bunmapi()
5439 tp->t_blk_res == 0)) { in __xfs_bunmapi()
5445 end -= del.br_blockcount; in __xfs_bunmapi()
5469 del.br_startoff - mod, in __xfs_bunmapi()
5471 mod = unwrite_start - prev.br_startoff; in __xfs_bunmapi()
5474 prev.br_blockcount -= mod; in __xfs_bunmapi()
5477 ip, whichfork, &icur, &cur, in __xfs_bunmapi()
5486 ip, whichfork, &icur, &cur, in __xfs_bunmapi()
5496 error = xfs_bmap_del_extent_delay(ip, whichfork, &icur, in __xfs_bunmapi()
5499 error = xfs_bmap_del_extent_real(ip, tp, &icur, cur, in __xfs_bunmapi()
5508 end = del.br_startoff - 1; in __xfs_bunmapi()
5513 if (end != (xfs_fileoff_t)-1 && end >= start) { in __xfs_bunmapi()
5523 if (done || end == (xfs_fileoff_t)-1 || end < start) in __xfs_bunmapi()
5526 *rlen = end - start + 1; in __xfs_bunmapi()
5531 if (xfs_bmap_needs_btree(ip, whichfork)) { in __xfs_bunmapi()
5533 error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, in __xfs_bunmapi()
5537 error = xfs_bmap_btree_to_extents(tp, ip, cur, &logflags, in __xfs_bunmapi()
5547 ifp->if_format != XFS_DINODE_FMT_EXTENTS) in __xfs_bunmapi()
5550 ifp->if_format != XFS_DINODE_FMT_BTREE) in __xfs_bunmapi()
5557 xfs_trans_log_inode(tp, ip, logflags); in __xfs_bunmapi()
5560 cur->bc_ino.allocated = 0; in __xfs_bunmapi()
5570 struct xfs_inode *ip, in xfs_bunmapi() argument
5579 error = __xfs_bunmapi(tp, ip, bno, &len, flags, nexts); in xfs_bunmapi()
5596 startoff = got->br_startoff - shift; in xfs_bmse_can_merge()
5599 * The extent, once shifted, must be adjacent in-file and on-disk with in xfs_bmse_can_merge()
5602 if ((left->br_startoff + left->br_blockcount != startoff) || in xfs_bmse_can_merge()
5603 (left->br_startblock + left->br_blockcount != got->br_startblock) || in xfs_bmse_can_merge()
5604 (left->br_state != got->br_state) || in xfs_bmse_can_merge()
5605 (left->br_blockcount + got->br_blockcount > XFS_MAX_BMBT_EXTLEN)) in xfs_bmse_can_merge()
5617 * This function assumes the caller has verified a shift-by-merge is possible
5623 struct xfs_inode *ip, in xfs_bmse_merge() argument
5632 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmse_merge()
5636 struct xfs_mount *mp = ip->i_mount; in xfs_bmse_merge()
5638 blockcount = left->br_blockcount + got->br_blockcount; in xfs_bmse_merge()
5640 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_bmse_merge()
5641 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in xfs_bmse_merge()
5648 * Update the on-disk extent count, the btree if necessary and log the in xfs_bmse_merge()
5651 ifp->if_nextents--; in xfs_bmse_merge()
5663 return -EFSCORRUPTED; in xfs_bmse_merge()
5669 return -EFSCORRUPTED; in xfs_bmse_merge()
5676 return -EFSCORRUPTED; in xfs_bmse_merge()
5683 error = xfs_bmap_btree_to_extents(tp, ip, cur, logflags, whichfork); in xfs_bmse_merge()
5688 xfs_iext_remove(ip, icur, 0); in xfs_bmse_merge()
5690 xfs_iext_update_extent(ip, xfs_bmap_fork_to_state(whichfork), icur, in xfs_bmse_merge()
5694 xfs_rmap_unmap_extent(tp, ip, whichfork, got); in xfs_bmse_merge()
5696 new.br_startoff = left->br_startoff + left->br_blockcount; in xfs_bmse_merge()
5697 xfs_rmap_map_extent(tp, ip, whichfork, &new); in xfs_bmse_merge()
5704 struct xfs_inode *ip, in xfs_bmap_shift_update_extent() argument
5712 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_shift_update_extent()
5718 got->br_startoff = startoff; in xfs_bmap_shift_update_extent()
5725 return -EFSCORRUPTED; in xfs_bmap_shift_update_extent()
5734 xfs_iext_update_extent(ip, xfs_bmap_fork_to_state(whichfork), icur, in xfs_bmap_shift_update_extent()
5738 xfs_rmap_unmap_extent(tp, ip, whichfork, &prev); in xfs_bmap_shift_update_extent()
5739 xfs_rmap_map_extent(tp, ip, whichfork, got); in xfs_bmap_shift_update_extent()
5746 struct xfs_inode *ip, in xfs_bmap_collapse_extents() argument
5752 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_collapse_extents()
5753 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_collapse_extents()
5763 return -EFSCORRUPTED; in xfs_bmap_collapse_extents()
5767 return -EIO; in xfs_bmap_collapse_extents()
5769 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL)); in xfs_bmap_collapse_extents()
5771 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_collapse_extents()
5775 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmap_collapse_extents()
5776 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_collapse_extents()
5777 cur->bc_ino.flags = 0; in xfs_bmap_collapse_extents()
5780 if (!xfs_iext_lookup_extent(ip, ifp, *next_fsb, &icur, &got)) { in xfs_bmap_collapse_extents()
5785 error = -EFSCORRUPTED; in xfs_bmap_collapse_extents()
5789 new_startoff = got.br_startoff - offset_shift_fsb; in xfs_bmap_collapse_extents()
5792 error = -EINVAL; in xfs_bmap_collapse_extents()
5797 error = xfs_bmse_merge(tp, ip, whichfork, in xfs_bmap_collapse_extents()
5806 error = -EINVAL; in xfs_bmap_collapse_extents()
5811 error = xfs_bmap_shift_update_extent(tp, ip, whichfork, &icur, &got, in xfs_bmap_collapse_extents()
5827 xfs_trans_log_inode(tp, ip, logflags); in xfs_bmap_collapse_extents()
5831 /* Make sure we won't be right-shifting an extent past the maximum bound. */
5834 struct xfs_inode *ip, in xfs_bmap_can_insert_extents() argument
5842 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_bmap_can_insert_extents()
5844 if (xfs_is_shutdown(ip->i_mount)) in xfs_bmap_can_insert_extents()
5845 return -EIO; in xfs_bmap_can_insert_extents()
5847 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_can_insert_extents()
5848 error = xfs_bmap_last_extent(NULL, ip, XFS_DATA_FORK, &got, &is_empty); in xfs_bmap_can_insert_extents()
5851 error = -EINVAL; in xfs_bmap_can_insert_extents()
5852 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_can_insert_extents()
5860 struct xfs_inode *ip, in xfs_bmap_insert_extents() argument
5867 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_insert_extents()
5868 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_insert_extents()
5878 return -EFSCORRUPTED; in xfs_bmap_insert_extents()
5882 return -EIO; in xfs_bmap_insert_extents()
5884 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL)); in xfs_bmap_insert_extents()
5886 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_insert_extents()
5890 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmap_insert_extents()
5891 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_insert_extents()
5892 cur->bc_ino.flags = 0; in xfs_bmap_insert_extents()
5903 if (!xfs_iext_lookup_extent(ip, ifp, *next_fsb, &icur, &got)) { in xfs_bmap_insert_extents()
5909 error = -EFSCORRUPTED; in xfs_bmap_insert_extents()
5914 error = -EFSCORRUPTED; in xfs_bmap_insert_extents()
5921 error = -EINVAL; in xfs_bmap_insert_extents()
5935 error = xfs_bmap_shift_update_extent(tp, ip, whichfork, &icur, &got, in xfs_bmap_insert_extents()
5951 xfs_trans_log_inode(tp, ip, logflags); in xfs_bmap_insert_extents()
5964 struct xfs_inode *ip, in xfs_bmap_split_extent() argument
5968 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_split_extent()
5972 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_split_extent()
5981 return -EFSCORRUPTED; in xfs_bmap_split_extent()
5985 return -EIO; in xfs_bmap_split_extent()
5988 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_split_extent()
5995 if (!xfs_iext_lookup_extent(ip, ifp, split_fsb, &icur, &got) || in xfs_bmap_split_extent()
5999 gotblkcnt = split_fsb - got.br_startoff; in xfs_bmap_split_extent()
6002 new.br_blockcount = got.br_blockcount - gotblkcnt; in xfs_bmap_split_extent()
6005 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_bmap_split_extent()
6006 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_split_extent()
6007 cur->bc_ino.flags = 0; in xfs_bmap_split_extent()
6012 error = -EFSCORRUPTED; in xfs_bmap_split_extent()
6018 xfs_iext_update_extent(ip, xfs_bmap_fork_to_state(whichfork), &icur, in xfs_bmap_split_extent()
6031 xfs_iext_insert(ip, &icur, &new, 0); in xfs_bmap_split_extent()
6032 ifp->if_nextents++; in xfs_bmap_split_extent()
6039 error = -EFSCORRUPTED; in xfs_bmap_split_extent()
6046 error = -EFSCORRUPTED; in xfs_bmap_split_extent()
6054 if (xfs_bmap_needs_btree(ip, whichfork)) { in xfs_bmap_split_extent()
6058 error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, in xfs_bmap_split_extent()
6065 cur->bc_ino.allocated = 0; in xfs_bmap_split_extent()
6070 xfs_trans_log_inode(tp, ip, logflags); in xfs_bmap_split_extent()
6079 return bmap->br_startblock != HOLESTARTBLOCK && in xfs_bmap_is_update_needed()
6080 bmap->br_startblock != DELAYSTARTBLOCK; in xfs_bmap_is_update_needed()
6088 struct xfs_inode *ip, in __xfs_bmap_add() argument
6094 trace_xfs_bmap_defer(tp->t_mountp, in __xfs_bmap_add()
6095 XFS_FSB_TO_AGNO(tp->t_mountp, bmap->br_startblock), in __xfs_bmap_add()
6097 XFS_FSB_TO_AGBNO(tp->t_mountp, bmap->br_startblock), in __xfs_bmap_add()
6098 ip->i_ino, whichfork, in __xfs_bmap_add()
6099 bmap->br_startoff, in __xfs_bmap_add()
6100 bmap->br_blockcount, in __xfs_bmap_add()
6101 bmap->br_state); in __xfs_bmap_add()
6104 INIT_LIST_HEAD(&bi->bi_list); in __xfs_bmap_add()
6105 bi->bi_type = type; in __xfs_bmap_add()
6106 bi->bi_owner = ip; in __xfs_bmap_add()
6107 bi->bi_whichfork = whichfork; in __xfs_bmap_add()
6108 bi->bi_bmap = *bmap; in __xfs_bmap_add()
6110 xfs_defer_add(tp, XFS_DEFER_OPS_TYPE_BMAP, &bi->bi_list); in __xfs_bmap_add()
6118 struct xfs_inode *ip, in xfs_bmap_map_extent() argument
6124 __xfs_bmap_add(tp, XFS_BMAP_MAP, ip, XFS_DATA_FORK, PREV); in xfs_bmap_map_extent()
6131 struct xfs_inode *ip, in xfs_bmap_unmap_extent() argument
6137 __xfs_bmap_add(tp, XFS_BMAP_UNMAP, ip, XFS_DATA_FORK, PREV); in xfs_bmap_unmap_extent()
6147 struct xfs_inode *ip, in xfs_bmap_finish_one() argument
6157 ASSERT(tp->t_firstblock == NULLFSBLOCK); in xfs_bmap_finish_one()
6159 trace_xfs_bmap_deferred(tp->t_mountp, in xfs_bmap_finish_one()
6160 XFS_FSB_TO_AGNO(tp->t_mountp, startblock), type, in xfs_bmap_finish_one()
6161 XFS_FSB_TO_AGBNO(tp->t_mountp, startblock), in xfs_bmap_finish_one()
6162 ip->i_ino, whichfork, startoff, *blockcount, state); in xfs_bmap_finish_one()
6165 return -EFSCORRUPTED; in xfs_bmap_finish_one()
6167 if (XFS_TEST_ERROR(false, tp->t_mountp, in xfs_bmap_finish_one()
6169 return -EIO; in xfs_bmap_finish_one()
6173 error = xfs_bmapi_remap(tp, ip, startoff, *blockcount, in xfs_bmap_finish_one()
6178 error = __xfs_bunmapi(tp, ip, startoff, blockcount, in xfs_bmap_finish_one()
6183 error = -EFSCORRUPTED; in xfs_bmap_finish_one()
6192 struct xfs_inode *ip, in xfs_bmap_validate_extent() argument
6196 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_validate_extent()
6198 if (!xfs_verify_fileext(mp, irec->br_startoff, irec->br_blockcount)) in xfs_bmap_validate_extent()
6201 if (XFS_IS_REALTIME_INODE(ip) && whichfork == XFS_DATA_FORK) { in xfs_bmap_validate_extent()
6202 if (!xfs_verify_rtext(mp, irec->br_startblock, in xfs_bmap_validate_extent()
6203 irec->br_blockcount)) in xfs_bmap_validate_extent()
6206 if (!xfs_verify_fsbext(mp, irec->br_startblock, in xfs_bmap_validate_extent()
6207 irec->br_blockcount)) in xfs_bmap_validate_extent()
6210 if (irec->br_state != XFS_EXT_NORM && whichfork != XFS_DATA_FORK) in xfs_bmap_validate_extent()
6222 return xfs_bmap_intent_cache != NULL ? 0 : -ENOMEM; in xfs_bmap_intent_init_cache()