Lines Matching refs:bma
1337 * Returns 1 in bma->aeof if the file (fork) is empty as any new write will be
1342 struct xfs_bmalloca *bma,
1349 bma->aeof = false;
1350 error = xfs_bmap_last_extent(NULL, bma->ip, whichfork, &rec,
1356 bma->aeof = true;
1364 bma->aeof = bma->offset >= rec.br_startoff + rec.br_blockcount ||
1365 (bma->offset >= rec.br_startoff &&
1411 struct xfs_bmalloca *bma,
1414 struct xfs_mount *mp = bma->ip->i_mount;
1415 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork);
1416 struct xfs_bmbt_irec *new = &bma->got;
1432 ASSERT(!bma->cur ||
1433 (bma->cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL));
1444 xfs_iext_get_extent(ifp, &bma->icur, &PREV);
1466 if (xfs_iext_peek_prev_extent(ifp, &bma->icur, &LEFT)) {
1484 if (xfs_iext_peek_next_extent(ifp, &bma->icur, &RIGHT)) {
1517 xfs_iext_remove(bma->ip, &bma->icur, state);
1518 xfs_iext_remove(bma->ip, &bma->icur, state);
1519 xfs_iext_prev(ifp, &bma->icur);
1520 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
1523 if (bma->cur == NULL)
1527 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i);
1534 error = xfs_btree_delete(bma->cur, &i);
1541 error = xfs_btree_decrement(bma->cur, 0, &i);
1548 error = xfs_bmbt_update(bma->cur, &LEFT);
1562 xfs_iext_remove(bma->ip, &bma->icur, state);
1563 xfs_iext_prev(ifp, &bma->icur);
1564 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
1566 if (bma->cur == NULL)
1570 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i);
1577 error = xfs_bmbt_update(bma->cur, &LEFT);
1594 xfs_iext_next(ifp, &bma->icur);
1595 xfs_iext_remove(bma->ip, &bma->icur, state);
1596 xfs_iext_prev(ifp, &bma->icur);
1597 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1599 if (bma->cur == NULL)
1603 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i);
1610 error = xfs_bmbt_update(bma->cur, &PREV);
1624 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1627 if (bma->cur == NULL)
1631 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1638 error = xfs_btree_insert(bma->cur, &i);
1655 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1664 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1665 xfs_iext_prev(ifp, &bma->icur);
1666 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
1668 if (bma->cur == NULL)
1672 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i);
1679 error = xfs_bmbt_update(bma->cur, &LEFT);
1690 xfs_iext_update_extent(bma->ip, state, &bma->icur, new);
1693 if (bma->cur == NULL)
1697 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1704 error = xfs_btree_insert(bma->cur, &i);
1713 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1714 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1715 &bma->cur, 1, &tmp_rval, whichfork);
1722 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1724 (bma->cur ? bma->cur->bc_ino.allocated : 0));
1729 xfs_iext_next(ifp, &bma->icur);
1730 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state);
1731 xfs_iext_prev(ifp, &bma->icur);
1744 if (bma->cur == NULL)
1748 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i);
1755 error = xfs_bmbt_update(bma->cur, &RIGHT);
1761 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1767 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1768 xfs_iext_next(ifp, &bma->icur);
1769 xfs_iext_update_extent(bma->ip, state, &bma->icur, &RIGHT);
1777 xfs_iext_update_extent(bma->ip, state, &bma->icur, new);
1780 if (bma->cur == NULL)
1784 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1791 error = xfs_btree_insert(bma->cur, &i);
1800 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1801 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1802 &bma->cur, 1, &tmp_rval, whichfork);
1809 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1811 (bma->cur ? bma->cur->bc_ino.allocated : 0));
1815 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state);
1816 xfs_iext_next(ifp, &bma->icur);
1851 nullstartblock(xfs_bmap_worst_indlen(bma->ip,
1857 nullstartblock(xfs_bmap_worst_indlen(bma->ip,
1859 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1861 xfs_iext_next(ifp, &bma->icur);
1862 xfs_iext_insert(bma->ip, &bma->icur, &RIGHT, state);
1863 xfs_iext_insert(bma->ip, &bma->icur, &LEFT, state);
1866 if (bma->cur == NULL)
1870 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1877 error = xfs_btree_insert(bma->cur, &i);
1886 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1887 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1888 &bma->cur, 1, &tmp_rval, whichfork);
1912 if (!(bma->flags & XFS_BMAPI_NORMAP))
1913 xfs_rmap_map_extent(bma->tp, bma->ip, whichfork, new);
1916 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1919 ASSERT(bma->cur == NULL);
1920 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1921 &bma->cur, da_old > 0, &tmp_logflags,
1923 bma->logflags |= tmp_logflags;
1931 if (bma->cur) {
1932 da_new += bma->cur->bc_ino.allocated;
1933 bma->cur->bc_ino.allocated = 0;
1943 xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork);
1946 bma->logflags |= rval;
3450 #define xfs_bmap_exact_minlen_extent_alloc(bma) (-EFSCORRUPTED)
4054 struct xfs_bmalloca *bma)
4056 struct xfs_mount *mp = bma->ip->i_mount;
4057 int whichfork = xfs_bmapi_whichfork(bma->flags);
4066 bma->datatype = XFS_ALLOC_NOBUSY;
4068 bma->datatype |= XFS_ALLOC_USERDATA;
4069 if (bma->offset == 0)
4070 bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA;
4072 if (mp->m_dalign && bma->length >= mp->m_dalign) {
4073 error = xfs_bmap_isaeof(bma, whichfork);
4078 if (XFS_IS_REALTIME_INODE(bma->ip))
4079 return xfs_bmap_rtalloc(bma);
4084 return xfs_bmap_exact_minlen_extent_alloc(bma);
4086 return xfs_bmap_btalloc(bma);
4091 struct xfs_bmalloca *bma)
4093 struct xfs_mount *mp = bma->ip->i_mount;
4094 int whichfork = xfs_bmapi_whichfork(bma->flags);
4095 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork);
4099 ASSERT(bma->length > 0);
4105 if (bma->wasdel) {
4106 bma->length = (xfs_extlen_t)bma->got.br_blockcount;
4107 bma->offset = bma->got.br_startoff;
4108 if (!xfs_iext_peek_prev_extent(ifp, &bma->icur, &bma->prev))
4109 bma->prev.br_startoff = NULLFILEOFF;
4111 bma->length = XFS_FILBLKS_MIN(bma->length, XFS_MAX_BMBT_EXTLEN);
4112 if (!bma->eof)
4113 bma->length = XFS_FILBLKS_MIN(bma->length,
4114 bma->got.br_startoff - bma->offset);
4117 if (bma->flags & XFS_BMAPI_CONTIG)
4118 bma->minlen = bma->length;
4120 bma->minlen = 1;
4122 if (bma->flags & XFS_BMAPI_METADATA) {
4125 error = xfs_bmap_exact_minlen_extent_alloc(bma);
4127 error = xfs_bmap_btalloc(bma);
4129 error = xfs_bmap_alloc_userdata(bma);
4131 if (error || bma->blkno == NULLFSBLOCK)
4134 if (bma->flags & XFS_BMAPI_ZERO) {
4135 error = xfs_zero_extent(bma->ip, bma->blkno, bma->length);
4140 if (ifp->if_format == XFS_DINODE_FMT_BTREE && !bma->cur)
4141 bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork);
4146 bma->nallocs++;
4148 if (bma->cur)
4149 bma->cur->bc_ino.flags =
4150 bma->wasdel ? XFS_BTCUR_BMBT_WASDEL : 0;
4152 bma->got.br_startoff = bma->offset;
4153 bma->got.br_startblock = bma->blkno;
4154 bma->got.br_blockcount = bma->length;
4155 bma->got.br_state = XFS_EXT_NORM;
4157 if (bma->flags & XFS_BMAPI_PREALLOC)
4158 bma->got.br_state = XFS_EXT_UNWRITTEN;
4160 if (bma->wasdel)
4161 error = xfs_bmap_add_extent_delay_real(bma, whichfork);
4163 error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip,
4164 whichfork, &bma->icur, &bma->cur, &bma->got,
4165 &bma->logflags, bma->flags);
4167 bma->logflags |= tmp_logflags;
4176 xfs_iext_get_extent(ifp, &bma->icur, &bma->got);
4178 ASSERT(bma->got.br_startoff <= bma->offset);
4179 ASSERT(bma->got.br_startoff + bma->got.br_blockcount >=
4180 bma->offset + bma->length);
4181 ASSERT(bma->got.br_state == XFS_EXT_NORM ||
4182 bma->got.br_state == XFS_EXT_UNWRITTEN);
4188 struct xfs_bmalloca *bma,
4194 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork);
4213 if (ifp->if_format == XFS_DINODE_FMT_BTREE && !bma->cur) {
4214 bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp,
4215 bma->ip, whichfork);
4225 error = xfs_zero_extent(bma->ip, mval->br_startblock,
4231 error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, whichfork,
4232 &bma->icur, &bma->cur, mval, &tmp_logflags);
4245 bma->logflags |= tmp_logflags | XFS_ILOG_CORE;
4254 xfs_iext_get_extent(ifp, &bma->icur, &bma->got);
4288 struct xfs_bmalloca *bma,
4292 struct xfs_ifork *ifp = xfs_ifork_ptr(bma->ip, whichfork);
4294 if ((bma->logflags & xfs_ilog_fext(whichfork)) &&
4296 bma->logflags &= ~xfs_ilog_fext(whichfork);
4297 else if ((bma->logflags & xfs_ilog_fbroot(whichfork)) &&
4299 bma->logflags &= ~xfs_ilog_fbroot(whichfork);
4301 if (bma->logflags)
4302 xfs_trans_log_inode(bma->tp, bma->ip, bma->logflags);
4303 if (bma->cur)
4304 xfs_btree_del_cursor(bma->cur, error);
4324 struct xfs_bmalloca bma = {
4386 if (!xfs_iext_lookup_extent(ip, ifp, bno, &bma.icur, &bma.got))
4388 if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
4389 bma.prev.br_startoff = NULLFILEOFF;
4390 bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
4399 if (eof || bma.got.br_startoff > bno) {
4409 } else if (isnullstartblock(bma.got.br_startblock)) {
4418 bma.eof = eof;
4419 bma.conv = !!(flags & XFS_BMAPI_CONVERT);
4420 bma.wasdel = wasdelay;
4421 bma.offset = bno;
4422 bma.flags = flags;
4427 * length) and the bma length request, which is
4432 bma.length = XFS_MAX_BMBT_EXTLEN;
4434 bma.length = len;
4437 ASSERT(bma.length > 0);
4438 error = xfs_bmapi_allocate(&bma);
4441 if (bma.blkno == NULLFSBLOCK)
4449 xfs_refcount_alloc_cow_extent(tp, bma.blkno,
4450 bma.length);
4454 xfs_bmapi_trim_map(mval, &bma.got, &bno, len, obno,
4458 error = xfs_bmapi_convert_unwritten(&bma, mval, len, flags);
4472 if (bno >= end || n >= *nmap || bma.nallocs >= *nmap)
4476 bma.prev = bma.got;
4477 if (!xfs_iext_next_extent(ifp, &bma.icur, &bma.got))
4482 error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags,
4489 xfs_bmapi_finish(&bma, whichfork, 0);
4494 xfs_bmapi_finish(&bma, whichfork, error);
4515 struct xfs_bmalloca bma = { NULL };
4543 if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) ||
4544 bma.got.br_startoff > offset_fsb) {
4559 if (!isnullstartblock(bma.got.br_startblock)) {
4560 xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
4566 bma.tp = tp;
4567 bma.ip = ip;
4568 bma.wasdel = true;
4569 bma.offset = bma.got.br_startoff;
4570 bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount,
4572 bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
4587 bma.flags = XFS_BMAPI_PREALLOC;
4589 bma.flags |= XFS_BMAPI_COWFORK;
4591 if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
4592 bma.prev.br_startoff = NULLFILEOFF;
4594 error = xfs_bmapi_allocate(&bma);
4599 if (WARN_ON_ONCE(bma.blkno == NULLFSBLOCK))
4602 if (WARN_ON_ONCE(!xfs_valid_startblock(ip, bma.got.br_startblock)))
4605 XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
4608 ASSERT(!isnullstartblock(bma.got.br_startblock));
4609 xfs_bmbt_to_iomap(ip, iomap, &bma.got, 0, flags,
4614 xfs_refcount_alloc_cow_extent(tp, bma.blkno, bma.length);
4616 error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags,
4621 xfs_bmapi_finish(&bma, whichfork, 0);
4627 xfs_bmapi_finish(&bma, whichfork, error);