Lines Matching refs:bma

1385  * Returns 1 in bma->aeof if the file (fork) is empty as any new write will be
1390 struct xfs_bmalloca *bma,
1397 bma->aeof = false;
1398 error = xfs_bmap_last_extent(NULL, bma->ip, whichfork, &rec,
1404 bma->aeof = true;
1412 bma->aeof = bma->offset >= rec.br_startoff + rec.br_blockcount ||
1413 (bma->offset >= rec.br_startoff &&
1491 struct xfs_bmalloca *bma,
1494 struct xfs_mount *mp = bma->ip->i_mount;
1495 struct xfs_ifork *ifp = XFS_IFORK_PTR(bma->ip, whichfork);
1496 struct xfs_bmbt_irec *new = &bma->got;
1512 ASSERT(!bma->cur ||
1513 (bma->cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL));
1524 xfs_iext_get_extent(ifp, &bma->icur, &PREV);
1546 if (xfs_iext_peek_prev_extent(ifp, &bma->icur, &LEFT)) {
1564 if (xfs_iext_peek_next_extent(ifp, &bma->icur, &RIGHT)) {
1597 xfs_iext_remove(bma->ip, &bma->icur, state);
1598 xfs_iext_remove(bma->ip, &bma->icur, state);
1599 xfs_iext_prev(ifp, &bma->icur);
1600 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
1603 if (bma->cur == NULL)
1607 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i);
1614 error = xfs_btree_delete(bma->cur, &i);
1621 error = xfs_btree_decrement(bma->cur, 0, &i);
1628 error = xfs_bmbt_update(bma->cur, &LEFT);
1642 xfs_iext_remove(bma->ip, &bma->icur, state);
1643 xfs_iext_prev(ifp, &bma->icur);
1644 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
1646 if (bma->cur == NULL)
1650 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i);
1657 error = xfs_bmbt_update(bma->cur, &LEFT);
1674 xfs_iext_next(ifp, &bma->icur);
1675 xfs_iext_remove(bma->ip, &bma->icur, state);
1676 xfs_iext_prev(ifp, &bma->icur);
1677 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1679 if (bma->cur == NULL)
1683 error = xfs_bmbt_lookup_eq(bma->cur, &RIGHT, &i);
1690 error = xfs_bmbt_update(bma->cur, &PREV);
1704 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1707 if (bma->cur == NULL)
1711 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1718 error = xfs_btree_insert(bma->cur, &i);
1735 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1744 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1745 xfs_iext_prev(ifp, &bma->icur);
1746 xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
1748 if (bma->cur == NULL)
1752 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i);
1759 error = xfs_bmbt_update(bma->cur, &LEFT);
1770 xfs_iext_update_extent(bma->ip, state, &bma->icur, new);
1773 if (bma->cur == NULL)
1777 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1784 error = xfs_btree_insert(bma->cur, &i);
1793 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1794 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1795 &bma->cur, 1, &tmp_rval, whichfork);
1802 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1804 (bma->cur ? bma->cur->bc_ino.allocated : 0));
1809 xfs_iext_next(ifp, &bma->icur);
1810 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state);
1811 xfs_iext_prev(ifp, &bma->icur);
1824 if (bma->cur == NULL)
1828 error = xfs_bmbt_lookup_eq(bma->cur, &old, &i);
1835 error = xfs_bmbt_update(bma->cur, &RIGHT);
1841 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1847 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1848 xfs_iext_next(ifp, &bma->icur);
1849 xfs_iext_update_extent(bma->ip, state, &bma->icur, &RIGHT);
1857 xfs_iext_update_extent(bma->ip, state, &bma->icur, new);
1860 if (bma->cur == NULL)
1864 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1871 error = xfs_btree_insert(bma->cur, &i);
1880 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1881 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1882 &bma->cur, 1, &tmp_rval, whichfork);
1889 da_new = XFS_FILBLKS_MIN(xfs_bmap_worst_indlen(bma->ip, temp),
1891 (bma->cur ? bma->cur->bc_ino.allocated : 0));
1895 xfs_iext_insert(bma->ip, &bma->icur, &PREV, state);
1896 xfs_iext_next(ifp, &bma->icur);
1931 nullstartblock(xfs_bmap_worst_indlen(bma->ip,
1937 nullstartblock(xfs_bmap_worst_indlen(bma->ip,
1939 xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
1941 xfs_iext_next(ifp, &bma->icur);
1942 xfs_iext_insert(bma->ip, &bma->icur, &RIGHT, state);
1943 xfs_iext_insert(bma->ip, &bma->icur, &LEFT, state);
1946 if (bma->cur == NULL)
1950 error = xfs_bmbt_lookup_eq(bma->cur, new, &i);
1957 error = xfs_btree_insert(bma->cur, &i);
1966 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1967 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
1968 &bma->cur, 1, &tmp_rval, whichfork);
1992 if (!(bma->flags & XFS_BMAPI_NORMAP))
1993 xfs_rmap_map_extent(bma->tp, bma->ip, whichfork, new);
1996 if (xfs_bmap_needs_btree(bma->ip, whichfork)) {
1999 ASSERT(bma->cur == NULL);
2000 error = xfs_bmap_extents_to_btree(bma->tp, bma->ip,
2001 &bma->cur, da_old > 0, &tmp_logflags,
2003 bma->logflags |= tmp_logflags;
2011 if (bma->cur) {
2012 da_new += bma->cur->bc_ino.allocated;
2013 bma->cur->bc_ino.allocated = 0;
2023 xfs_bmap_check_leaf_extents(bma->cur, bma->ip, whichfork);
2026 bma->logflags |= rval;
4058 struct xfs_bmalloca *bma)
4060 struct xfs_mount *mp = bma->ip->i_mount;
4061 int whichfork = xfs_bmapi_whichfork(bma->flags);
4070 bma->datatype = XFS_ALLOC_NOBUSY;
4072 bma->datatype |= XFS_ALLOC_USERDATA;
4073 if (bma->offset == 0)
4074 bma->datatype |= XFS_ALLOC_INITIAL_USER_DATA;
4076 if (mp->m_dalign && bma->length >= mp->m_dalign) {
4077 error = xfs_bmap_isaeof(bma, whichfork);
4082 if (XFS_IS_REALTIME_INODE(bma->ip))
4083 return xfs_bmap_rtalloc(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, MAXEXTLEN);
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)
4123 error = xfs_bmap_btalloc(bma);
4125 error = xfs_bmap_alloc_userdata(bma);
4126 if (error || bma->blkno == NULLFSBLOCK)
4129 if (bma->flags & XFS_BMAPI_ZERO) {
4130 error = xfs_zero_extent(bma->ip, bma->blkno, bma->length);
4135 if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur)
4136 bma->cur = xfs_bmbt_init_cursor(mp, bma->tp, bma->ip, whichfork);
4141 bma->nallocs++;
4143 if (bma->cur)
4144 bma->cur->bc_ino.flags =
4145 bma->wasdel ? XFS_BTCUR_BMBT_WASDEL : 0;
4147 bma->got.br_startoff = bma->offset;
4148 bma->got.br_startblock = bma->blkno;
4149 bma->got.br_blockcount = bma->length;
4150 bma->got.br_state = XFS_EXT_NORM;
4152 if (bma->flags & XFS_BMAPI_PREALLOC)
4153 bma->got.br_state = XFS_EXT_UNWRITTEN;
4155 if (bma->wasdel)
4156 error = xfs_bmap_add_extent_delay_real(bma, whichfork);
4158 error = xfs_bmap_add_extent_hole_real(bma->tp, bma->ip,
4159 whichfork, &bma->icur, &bma->cur, &bma->got,
4160 &bma->logflags, bma->flags);
4162 bma->logflags |= tmp_logflags;
4171 xfs_iext_get_extent(ifp, &bma->icur, &bma->got);
4173 ASSERT(bma->got.br_startoff <= bma->offset);
4174 ASSERT(bma->got.br_startoff + bma->got.br_blockcount >=
4175 bma->offset + bma->length);
4176 ASSERT(bma->got.br_state == XFS_EXT_NORM ||
4177 bma->got.br_state == XFS_EXT_UNWRITTEN);
4183 struct xfs_bmalloca *bma,
4189 struct xfs_ifork *ifp = XFS_IFORK_PTR(bma->ip, whichfork);
4208 if ((ifp->if_flags & XFS_IFBROOT) && !bma->cur) {
4209 bma->cur = xfs_bmbt_init_cursor(bma->ip->i_mount, bma->tp,
4210 bma->ip, whichfork);
4220 error = xfs_zero_extent(bma->ip, mval->br_startblock,
4226 error = xfs_bmap_add_extent_unwritten_real(bma->tp, bma->ip, whichfork,
4227 &bma->icur, &bma->cur, mval, &tmp_logflags);
4240 bma->logflags |= tmp_logflags | XFS_ILOG_CORE;
4249 xfs_iext_get_extent(ifp, &bma->icur, &bma->got);
4283 struct xfs_bmalloca *bma,
4287 struct xfs_ifork *ifp = XFS_IFORK_PTR(bma->ip, whichfork);
4289 if ((bma->logflags & xfs_ilog_fext(whichfork)) &&
4291 bma->logflags &= ~xfs_ilog_fext(whichfork);
4292 else if ((bma->logflags & xfs_ilog_fbroot(whichfork)) &&
4294 bma->logflags &= ~xfs_ilog_fbroot(whichfork);
4296 if (bma->logflags)
4297 xfs_trans_log_inode(bma->tp, bma->ip, bma->logflags);
4298 if (bma->cur)
4299 xfs_btree_del_cursor(bma->cur, error);
4319 struct xfs_bmalloca bma = {
4383 if (!xfs_iext_lookup_extent(ip, ifp, bno, &bma.icur, &bma.got))
4385 if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
4386 bma.prev.br_startoff = NULLFILEOFF;
4387 bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
4396 if (eof || bma.got.br_startoff > bno) {
4406 } else if (isnullstartblock(bma.got.br_startblock)) {
4415 bma.eof = eof;
4416 bma.conv = !!(flags & XFS_BMAPI_CONVERT);
4417 bma.wasdel = wasdelay;
4418 bma.offset = bno;
4419 bma.flags = flags;
4424 * length) and the bma length request, which is
4429 bma.length = MAXEXTLEN;
4431 bma.length = len;
4434 ASSERT(bma.length > 0);
4435 error = xfs_bmapi_allocate(&bma);
4438 if (bma.blkno == NULLFSBLOCK)
4446 xfs_refcount_alloc_cow_extent(tp, bma.blkno,
4447 bma.length);
4451 xfs_bmapi_trim_map(mval, &bma.got, &bno, len, obno,
4455 error = xfs_bmapi_convert_unwritten(&bma, mval, len, flags);
4469 if (bno >= end || n >= *nmap || bma.nallocs >= *nmap)
4473 bma.prev = bma.got;
4474 if (!xfs_iext_next_extent(ifp, &bma.icur, &bma.got))
4479 error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags,
4486 xfs_bmapi_finish(&bma, whichfork, 0);
4491 xfs_bmapi_finish(&bma, whichfork, error);
4512 struct xfs_bmalloca bma = { NULL };
4532 if (!xfs_iext_lookup_extent(ip, ifp, offset_fsb, &bma.icur, &bma.got) ||
4533 bma.got.br_startoff > offset_fsb) {
4548 if (!isnullstartblock(bma.got.br_startblock)) {
4549 xfs_bmbt_to_iomap(ip, iomap, &bma.got, flags);
4554 bma.tp = tp;
4555 bma.ip = ip;
4556 bma.wasdel = true;
4557 bma.offset = bma.got.br_startoff;
4558 bma.length = max_t(xfs_filblks_t, bma.got.br_blockcount, MAXEXTLEN);
4559 bma.minleft = xfs_bmapi_minleft(tp, ip, whichfork);
4574 bma.flags = XFS_BMAPI_PREALLOC;
4576 bma.flags |= XFS_BMAPI_COWFORK;
4578 if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
4579 bma.prev.br_startoff = NULLFILEOFF;
4581 error = xfs_bmapi_allocate(&bma);
4586 if (WARN_ON_ONCE(bma.blkno == NULLFSBLOCK))
4589 if (WARN_ON_ONCE(!xfs_valid_startblock(ip, bma.got.br_startblock)))
4592 XFS_STATS_ADD(mp, xs_xstrat_bytes, XFS_FSB_TO_B(mp, bma.length));
4595 ASSERT(!isnullstartblock(bma.got.br_startblock));
4596 xfs_bmbt_to_iomap(ip, iomap, &bma.got, flags);
4600 xfs_refcount_alloc_cow_extent(tp, bma.blkno, bma.length);
4602 error = xfs_bmap_btree_to_extents(tp, ip, bma.cur, &bma.logflags,
4607 xfs_bmapi_finish(&bma, whichfork, 0);
4613 xfs_bmapi_finish(&bma, whichfork, error);