2 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "xfs_trans.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_ialloc.h"
39 #include "xfs_btree.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
46 #include "xfs_buf_item.h"
47 #include "xfs_trans_space.h"
48 #include "xfs_utils.h"
49 #include "xfs_iomap.h"
50 #include "xfs_trace.h"
53 #define XFS_WRITEIO_ALIGN(mp,off) (((off) >> mp->m_writeio_log) \
55 #define XFS_STRAT_WRITE_IMAPS 2
56 #define XFS_WRITE_IMAPS XFS_BMAP_MAX_NMAP
62 xfs_bmbt_irec_t *imap,
64 int imaps, /* Number of imap entries */
67 xfs_mount_t *mp = ip->i_mount;
68 xfs_fsblock_t start_block;
70 iomapp->iomap_offset = XFS_FSB_TO_B(mp, imap->br_startoff);
71 iomapp->iomap_delta = offset - iomapp->iomap_offset;
72 iomapp->iomap_bsize = XFS_FSB_TO_B(mp, imap->br_blockcount);
73 iomapp->iomap_flags = flags;
75 if (XFS_IS_REALTIME_INODE(ip)) {
76 iomapp->iomap_flags |= IOMAP_REALTIME;
77 iomapp->iomap_target = mp->m_rtdev_targp;
79 iomapp->iomap_target = mp->m_ddev_targp;
81 start_block = imap->br_startblock;
82 if (start_block == HOLESTARTBLOCK) {
83 iomapp->iomap_bn = IOMAP_DADDR_NULL;
84 iomapp->iomap_flags |= IOMAP_HOLE;
85 } else if (start_block == DELAYSTARTBLOCK) {
86 iomapp->iomap_bn = IOMAP_DADDR_NULL;
87 iomapp->iomap_flags |= IOMAP_DELAY;
89 iomapp->iomap_bn = xfs_fsb_to_db(ip, start_block);
90 if (ISUNWRITTEN(imap))
91 iomapp->iomap_flags |= IOMAP_UNWRITTEN;
104 xfs_mount_t *mp = ip->i_mount;
105 xfs_fileoff_t offset_fsb, end_fsb;
108 xfs_bmbt_irec_t imap;
113 ASSERT((ip->i_d.di_mode & S_IFMT) == S_IFREG);
114 ASSERT(niomaps && *niomaps == 1);
116 if (XFS_FORCED_SHUTDOWN(mp))
117 return XFS_ERROR(EIO);
119 trace_xfs_iomap_enter(ip, offset, count, flags, NULL);
121 switch (flags & (BMAPI_READ | BMAPI_WRITE | BMAPI_ALLOCATE)) {
123 lockmode = xfs_ilock_map_shared(ip);
124 bmapi_flags = XFS_BMAPI_ENTIRE;
127 lockmode = XFS_ILOCK_EXCL;
128 if (flags & BMAPI_IGNSTATE)
129 bmapi_flags |= XFS_BMAPI_IGSTATE|XFS_BMAPI_ENTIRE;
130 xfs_ilock(ip, lockmode);
133 lockmode = XFS_ILOCK_SHARED;
134 bmapi_flags = XFS_BMAPI_ENTIRE;
136 /* Attempt non-blocking lock */
137 if (flags & BMAPI_TRYLOCK) {
138 if (!xfs_ilock_nowait(ip, lockmode))
139 return XFS_ERROR(EAGAIN);
141 xfs_ilock(ip, lockmode);
148 ASSERT(offset <= mp->m_maxioffset);
149 if ((xfs_fsize_t)offset + count > mp->m_maxioffset)
150 count = mp->m_maxioffset - offset;
151 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
152 offset_fsb = XFS_B_TO_FSBT(mp, offset);
154 error = xfs_bmapi(NULL, ip, offset_fsb,
155 (xfs_filblks_t)(end_fsb - offset_fsb),
156 bmapi_flags, NULL, 0, &imap,
157 &nimaps, NULL, NULL);
162 switch (flags & (BMAPI_WRITE|BMAPI_ALLOCATE)) {
164 /* If we found an extent, return it */
166 (imap.br_startblock != HOLESTARTBLOCK) &&
167 (imap.br_startblock != DELAYSTARTBLOCK)) {
168 trace_xfs_iomap_found(ip, offset, count, flags, &imap);
172 if (flags & (BMAPI_DIRECT|BMAPI_MMAP)) {
173 error = xfs_iomap_write_direct(ip, offset, count, flags,
174 &imap, &nimaps, nimaps);
176 error = xfs_iomap_write_delay(ip, offset, count, flags,
180 trace_xfs_iomap_alloc(ip, offset, count, flags, &imap);
182 iomap_flags = IOMAP_NEW;
185 /* If we found an extent, return it */
186 xfs_iunlock(ip, lockmode);
189 if (nimaps && !isnullstartblock(imap.br_startblock)) {
190 trace_xfs_iomap_found(ip, offset, count, flags, &imap);
194 error = xfs_iomap_write_allocate(ip, offset, count,
202 xfs_imap_to_bmap(ip, offset, &imap, iomapp, nimaps, iomap_flags);
207 xfs_iunlock(ip, lockmode);
208 return XFS_ERROR(error);
213 xfs_iomap_eof_align_last_fsb(
216 xfs_extlen_t extsize,
217 xfs_fileoff_t *last_fsb)
219 xfs_fileoff_t new_last_fsb = 0;
223 if (XFS_IS_REALTIME_INODE(ip))
226 * If mounted with the "-o swalloc" option, roundup the allocation
227 * request to a stripe width boundary if the file size is >=
228 * stripe width and we are allocating past the allocation eof.
230 else if (mp->m_swidth && (mp->m_flags & XFS_MOUNT_SWALLOC) &&
231 (ip->i_size >= XFS_FSB_TO_B(mp, mp->m_swidth)))
232 new_last_fsb = roundup_64(*last_fsb, mp->m_swidth);
234 * Roundup the allocation request to a stripe unit (m_dalign) boundary
235 * if the file size is >= stripe unit size, and we are allocating past
236 * the allocation eof.
238 else if (mp->m_dalign && (ip->i_size >= XFS_FSB_TO_B(mp, mp->m_dalign)))
239 new_last_fsb = roundup_64(*last_fsb, mp->m_dalign);
242 * Always round up the allocation request to an extent boundary
243 * (when file on a real-time subvolume or has di_extsize hint).
247 align = roundup_64(new_last_fsb, extsize);
250 new_last_fsb = roundup_64(*last_fsb, align);
254 error = xfs_bmap_eof(ip, new_last_fsb, XFS_DATA_FORK, &eof);
258 *last_fsb = new_last_fsb;
264 xfs_cmn_err_fsblock_zero(
266 xfs_bmbt_irec_t *imap)
268 xfs_cmn_err(XFS_PTAG_FSBLOCK_ZERO, CE_ALERT, ip->i_mount,
269 "Access to block zero in inode %llu "
270 "start_block: %llx start_off: %llx "
271 "blkcnt: %llx extent-state: %x\n",
272 (unsigned long long)ip->i_ino,
273 (unsigned long long)imap->br_startblock,
274 (unsigned long long)imap->br_startoff,
275 (unsigned long long)imap->br_blockcount,
281 xfs_iomap_write_direct(
286 xfs_bmbt_irec_t *ret_imap,
290 xfs_mount_t *mp = ip->i_mount;
291 xfs_fileoff_t offset_fsb;
292 xfs_fileoff_t last_fsb;
293 xfs_filblks_t count_fsb, resaligned;
294 xfs_fsblock_t firstfsb;
295 xfs_extlen_t extsz, temp;
301 xfs_bmbt_irec_t imap;
302 xfs_bmap_free_t free_list;
303 uint qblocks, resblks, resrtextents;
308 * Make sure that the dquots are there. This doesn't hold
309 * the ilock across a disk read.
311 error = xfs_qm_dqattach_locked(ip, 0);
313 return XFS_ERROR(error);
315 rt = XFS_IS_REALTIME_INODE(ip);
316 extsz = xfs_get_extsz_hint(ip);
318 offset_fsb = XFS_B_TO_FSBT(mp, offset);
319 last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
320 if ((offset + count) > ip->i_size) {
321 error = xfs_iomap_eof_align_last_fsb(mp, ip, extsz, &last_fsb);
325 if (found && (ret_imap->br_startblock == HOLESTARTBLOCK))
326 last_fsb = MIN(last_fsb, (xfs_fileoff_t)
327 ret_imap->br_blockcount +
328 ret_imap->br_startoff);
330 count_fsb = last_fsb - offset_fsb;
331 ASSERT(count_fsb > 0);
333 resaligned = count_fsb;
334 if (unlikely(extsz)) {
335 if ((temp = do_mod(offset_fsb, extsz)))
337 if ((temp = do_mod(resaligned, extsz)))
338 resaligned += extsz - temp;
342 resrtextents = qblocks = resaligned;
343 resrtextents /= mp->m_sb.sb_rextsize;
344 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0);
345 quota_flag = XFS_QMOPT_RES_RTBLKS;
348 resblks = qblocks = XFS_DIOSTRAT_SPACE_RES(mp, resaligned);
349 quota_flag = XFS_QMOPT_RES_REGBLKS;
353 * Allocate and setup the transaction
355 xfs_iunlock(ip, XFS_ILOCK_EXCL);
356 tp = xfs_trans_alloc(mp, XFS_TRANS_DIOSTRAT);
357 error = xfs_trans_reserve(tp, resblks,
358 XFS_WRITE_LOG_RES(mp), resrtextents,
359 XFS_TRANS_PERM_LOG_RES,
360 XFS_WRITE_LOG_COUNT);
362 * Check for running out of space, note: need lock to return
365 xfs_trans_cancel(tp, 0);
366 xfs_ilock(ip, XFS_ILOCK_EXCL);
370 error = xfs_trans_reserve_quota_nblks(tp, ip, qblocks, 0, quota_flag);
374 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
375 xfs_trans_ihold(tp, ip);
377 bmapi_flag = XFS_BMAPI_WRITE;
378 if ((flags & BMAPI_DIRECT) && (offset < ip->i_size || extsz))
379 bmapi_flag |= XFS_BMAPI_PREALLOC;
382 * Issue the xfs_bmapi() call to allocate the blocks
384 xfs_bmap_init(&free_list, &firstfsb);
386 error = xfs_bmapi(tp, ip, offset_fsb, count_fsb, bmapi_flag,
387 &firstfsb, 0, &imap, &nimaps, &free_list, NULL);
392 * Complete the transaction
394 error = xfs_bmap_finish(&tp, &free_list, &committed);
397 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
402 * Copy any maps to caller's array and return any error.
409 if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip))) {
410 error = xfs_cmn_err_fsblock_zero(ip, &imap);
418 error0: /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
419 xfs_bmap_cancel(&free_list);
420 xfs_trans_unreserve_quota_nblks(tp, ip, qblocks, 0, quota_flag);
422 error1: /* Just cancel transaction */
423 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
424 *nmaps = 0; /* nothing set-up here */
427 return XFS_ERROR(error);
431 * If the caller is doing a write at the end of the file, then extend the
432 * allocation out to the file system's write iosize. We clean up any extra
433 * space left over when the file is closed in xfs_inactive().
436 xfs_iomap_eof_want_preallocate(
442 xfs_bmbt_irec_t *imap,
446 xfs_fileoff_t start_fsb;
447 xfs_filblks_t count_fsb;
448 xfs_fsblock_t firstblock;
452 if ((offset + count) <= ip->i_size)
456 * If there are any real blocks past eof, then don't
457 * do any speculative allocation.
459 start_fsb = XFS_B_TO_FSBT(mp, ((xfs_ufsize_t)(offset + count - 1)));
460 count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
461 while (count_fsb > 0) {
463 firstblock = NULLFSBLOCK;
464 error = xfs_bmapi(NULL, ip, start_fsb, count_fsb, 0,
465 &firstblock, 0, imap, &imaps, NULL, NULL);
468 for (n = 0; n < imaps; n++) {
469 if ((imap[n].br_startblock != HOLESTARTBLOCK) &&
470 (imap[n].br_startblock != DELAYSTARTBLOCK))
472 start_fsb += imap[n].br_blockcount;
473 count_fsb -= imap[n].br_blockcount;
481 xfs_iomap_write_delay(
486 xfs_bmbt_irec_t *ret_imap,
489 xfs_mount_t *mp = ip->i_mount;
490 xfs_fileoff_t offset_fsb;
491 xfs_fileoff_t last_fsb;
492 xfs_off_t aligned_offset;
493 xfs_fileoff_t ioalign;
494 xfs_fsblock_t firstblock;
497 xfs_bmbt_irec_t imap[XFS_WRITE_IMAPS];
498 int prealloc, flushed = 0;
501 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
504 * Make sure that the dquots are there. This doesn't hold
505 * the ilock across a disk read.
507 error = xfs_qm_dqattach_locked(ip, 0);
509 return XFS_ERROR(error);
511 extsz = xfs_get_extsz_hint(ip);
512 offset_fsb = XFS_B_TO_FSBT(mp, offset);
514 error = xfs_iomap_eof_want_preallocate(mp, ip, offset, count,
515 ioflag, imap, XFS_WRITE_IMAPS, &prealloc);
521 aligned_offset = XFS_WRITEIO_ALIGN(mp, (offset + count - 1));
522 ioalign = XFS_B_TO_FSBT(mp, aligned_offset);
523 last_fsb = ioalign + mp->m_writeio_blocks;
525 last_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)(offset + count)));
528 if (prealloc || extsz) {
529 error = xfs_iomap_eof_align_last_fsb(mp, ip, extsz, &last_fsb);
534 nimaps = XFS_WRITE_IMAPS;
535 firstblock = NULLFSBLOCK;
536 error = xfs_bmapi(NULL, ip, offset_fsb,
537 (xfs_filblks_t)(last_fsb - offset_fsb),
538 XFS_BMAPI_DELAY | XFS_BMAPI_WRITE |
539 XFS_BMAPI_ENTIRE, &firstblock, 1, imap,
540 &nimaps, NULL, NULL);
541 if (error && (error != ENOSPC))
542 return XFS_ERROR(error);
545 * If bmapi returned us nothing, and if we didn't get back EDQUOT,
546 * then we must have run out of space - flush all other inodes with
547 * delalloc blocks and retry without EOF preallocation.
550 trace_xfs_delalloc_enospc(ip, offset, count);
552 return XFS_ERROR(ENOSPC);
554 xfs_iunlock(ip, XFS_ILOCK_EXCL);
555 xfs_flush_inodes(ip);
556 xfs_ilock(ip, XFS_ILOCK_EXCL);
564 if (!(imap[0].br_startblock || XFS_IS_REALTIME_INODE(ip)))
565 return xfs_cmn_err_fsblock_zero(ip, &imap[0]);
574 * Pass in a delayed allocate extent, convert it to real extents;
575 * return to the caller the extent we create which maps on top of
576 * the originating callers request.
578 * Called without a lock on the inode.
580 * We no longer bother to look at the incoming map - all we have to
581 * guarantee is that whatever we allocate fills the required range.
584 xfs_iomap_write_allocate(
588 xfs_bmbt_irec_t *map,
591 xfs_mount_t *mp = ip->i_mount;
592 xfs_fileoff_t offset_fsb, last_block;
593 xfs_fileoff_t end_fsb, map_start_fsb;
594 xfs_fsblock_t first_block;
595 xfs_bmap_free_t free_list;
596 xfs_filblks_t count_fsb;
597 xfs_bmbt_irec_t imap;
599 int nimaps, committed;
606 * Make sure that the dquots are there.
608 error = xfs_qm_dqattach(ip, 0);
610 return XFS_ERROR(error);
612 offset_fsb = XFS_B_TO_FSBT(mp, offset);
613 count_fsb = map->br_blockcount;
614 map_start_fsb = map->br_startoff;
616 XFS_STATS_ADD(xs_xstrat_bytes, XFS_FSB_TO_B(mp, count_fsb));
618 while (count_fsb != 0) {
620 * Set up a transaction with which to allocate the
621 * backing store for the file. Do allocations in a
622 * loop until we get some space in the range we are
623 * interested in. The other space that might be allocated
624 * is in the delayed allocation extent on which we sit
625 * but before our buffer starts.
629 while (nimaps == 0) {
630 tp = xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE);
631 tp->t_flags |= XFS_TRANS_RESERVE;
632 nres = XFS_EXTENTADD_SPACE_RES(mp, XFS_DATA_FORK);
633 error = xfs_trans_reserve(tp, nres,
634 XFS_WRITE_LOG_RES(mp),
635 0, XFS_TRANS_PERM_LOG_RES,
636 XFS_WRITE_LOG_COUNT);
638 xfs_trans_cancel(tp, 0);
639 return XFS_ERROR(error);
641 xfs_ilock(ip, XFS_ILOCK_EXCL);
642 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
643 xfs_trans_ihold(tp, ip);
645 xfs_bmap_init(&free_list, &first_block);
648 * it is possible that the extents have changed since
649 * we did the read call as we dropped the ilock for a
650 * while. We have to be careful about truncates or hole
651 * punchs here - we are not allowed to allocate
652 * non-delalloc blocks here.
654 * The only protection against truncation is the pages
655 * for the range we are being asked to convert are
656 * locked and hence a truncate will block on them
659 * As a result, if we go beyond the range we really
660 * need and hit an delalloc extent boundary followed by
661 * a hole while we have excess blocks in the map, we
662 * will fill the hole incorrectly and overrun the
663 * transaction reservation.
665 * Using a single map prevents this as we are forced to
666 * check each map we look for overlap with the desired
667 * range and abort as soon as we find it. Also, given
668 * that we only return a single map, having one beyond
669 * what we can return is probably a bit silly.
671 * We also need to check that we don't go beyond EOF;
672 * this is a truncate optimisation as a truncate sets
673 * the new file size before block on the pages we
674 * currently have locked under writeback. Because they
675 * are about to be tossed, we don't need to write them
679 end_fsb = XFS_B_TO_FSB(mp, ip->i_size);
680 error = xfs_bmap_last_offset(NULL, ip, &last_block,
685 last_block = XFS_FILEOFF_MAX(last_block, end_fsb);
686 if ((map_start_fsb + count_fsb) > last_block) {
687 count_fsb = last_block - map_start_fsb;
688 if (count_fsb == 0) {
694 /* Go get the actual blocks */
695 error = xfs_bmapi(tp, ip, map_start_fsb, count_fsb,
696 XFS_BMAPI_WRITE, &first_block, 1,
697 &imap, &nimaps, &free_list, NULL);
701 error = xfs_bmap_finish(&tp, &free_list, &committed);
705 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
709 xfs_iunlock(ip, XFS_ILOCK_EXCL);
713 * See if we were able to allocate an extent that
714 * covers at least part of the callers request
716 if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
717 return xfs_cmn_err_fsblock_zero(ip, &imap);
719 if ((offset_fsb >= imap.br_startoff) &&
720 (offset_fsb < (imap.br_startoff +
721 imap.br_blockcount))) {
724 XFS_STATS_INC(xs_xstrat_quick);
729 * So far we have not mapped the requested part of the
730 * file, just surrounding data, try again.
732 count_fsb -= imap.br_blockcount;
733 map_start_fsb = imap.br_startoff + imap.br_blockcount;
737 xfs_bmap_cancel(&free_list);
738 xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
740 xfs_iunlock(ip, XFS_ILOCK_EXCL);
741 return XFS_ERROR(error);
745 xfs_iomap_write_unwritten(
750 xfs_mount_t *mp = ip->i_mount;
751 xfs_fileoff_t offset_fsb;
752 xfs_filblks_t count_fsb;
753 xfs_filblks_t numblks_fsb;
754 xfs_fsblock_t firstfsb;
757 xfs_bmbt_irec_t imap;
758 xfs_bmap_free_t free_list;
763 trace_xfs_unwritten_convert(ip, offset, count);
765 offset_fsb = XFS_B_TO_FSBT(mp, offset);
766 count_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)offset + count);
767 count_fsb = (xfs_filblks_t)(count_fsb - offset_fsb);
770 * Reserve enough blocks in this transaction for two complete extent
771 * btree splits. We may be converting the middle part of an unwritten
772 * extent and in this case we will insert two new extents in the btree
773 * each of which could cause a full split.
775 * This reservation amount will be used in the first call to
776 * xfs_bmbt_split() to select an AG with enough space to satisfy the
777 * rest of the operation.
779 resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
783 * set up a transaction to convert the range of extents
784 * from unwritten to real. Do allocations in a loop until
785 * we have covered the range passed in.
787 * Note that we open code the transaction allocation here
788 * to pass KM_NOFS--we can't risk to recursing back into
789 * the filesystem here as we might be asked to write out
790 * the same inode that we complete here and might deadlock
793 xfs_wait_for_freeze(mp, SB_FREEZE_TRANS);
794 tp = _xfs_trans_alloc(mp, XFS_TRANS_STRAT_WRITE, KM_NOFS);
795 tp->t_flags |= XFS_TRANS_RESERVE;
796 error = xfs_trans_reserve(tp, resblks,
797 XFS_WRITE_LOG_RES(mp), 0,
798 XFS_TRANS_PERM_LOG_RES,
799 XFS_WRITE_LOG_COUNT);
801 xfs_trans_cancel(tp, 0);
802 return XFS_ERROR(error);
805 xfs_ilock(ip, XFS_ILOCK_EXCL);
806 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
807 xfs_trans_ihold(tp, ip);
810 * Modify the unwritten extent state of the buffer.
812 xfs_bmap_init(&free_list, &firstfsb);
814 error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
815 XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb,
816 1, &imap, &nimaps, &free_list, NULL);
818 goto error_on_bmapi_transaction;
820 error = xfs_bmap_finish(&(tp), &(free_list), &committed);
822 goto error_on_bmapi_transaction;
824 error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
825 xfs_iunlock(ip, XFS_ILOCK_EXCL);
827 return XFS_ERROR(error);
829 if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
830 return xfs_cmn_err_fsblock_zero(ip, &imap);
832 if ((numblks_fsb = imap.br_blockcount) == 0) {
834 * The numblks_fsb value should always get
835 * smaller, otherwise the loop is stuck.
837 ASSERT(imap.br_blockcount);
840 offset_fsb += numblks_fsb;
841 count_fsb -= numblks_fsb;
842 } while (count_fsb > 0);
846 error_on_bmapi_transaction:
847 xfs_bmap_cancel(&free_list);
848 xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT));
849 xfs_iunlock(ip, XFS_ILOCK_EXCL);
850 return XFS_ERROR(error);