Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
45 xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb) in xfs_fsb_to_db() argument
47 return (XFS_IS_REALTIME_INODE(ip) ? \ in xfs_fsb_to_db()
48 (xfs_daddr_t)XFS_FSB_TO_BB((ip)->i_mount, (fsb)) : \ in xfs_fsb_to_db()
49 XFS_FSB_TO_DADDR((ip)->i_mount, (fsb))); in xfs_fsb_to_db()
61 struct xfs_inode *ip, in xfs_zero_extent() argument
65 struct xfs_mount *mp = ip->i_mount; in xfs_zero_extent()
66 xfs_daddr_t sector = xfs_fsb_to_db(ip, start_fsb); in xfs_zero_extent()
69 return blkdev_issue_zeroout(xfs_find_bdev_for_inode(VFS_I(ip)), in xfs_zero_extent()
70 block << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
71 count_fsb << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
88 mp = ap->ip->i_mount; in xfs_bmap_rtalloc()
89 align = xfs_get_extsz_hint(ap->ip); in xfs_bmap_rtalloc()
90 prod = align / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
91 error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, in xfs_bmap_rtalloc()
92 align, 1, ap->eof, 0, in xfs_bmap_rtalloc()
93 ap->conv, &ap->offset, &ap->length); in xfs_bmap_rtalloc()
96 ASSERT(ap->length); in xfs_bmap_rtalloc()
97 ASSERT(ap->length % mp->m_sb.sb_rextsize == 0); in xfs_bmap_rtalloc()
103 div_u64_rem(ap->offset, align, &mod); in xfs_bmap_rtalloc()
104 if (mod || ap->length % align) in xfs_bmap_rtalloc()
109 ralen = ap->length / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
117 if (ralen * mp->m_sb.sb_rextsize >= MAXEXTLEN) in xfs_bmap_rtalloc()
118 ralen = MAXEXTLEN / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
123 xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); in xfs_bmap_rtalloc()
124 xfs_trans_ijoin(ap->tp, mp->m_rbmip, XFS_ILOCK_EXCL); in xfs_bmap_rtalloc()
125 xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); in xfs_bmap_rtalloc()
126 xfs_trans_ijoin(ap->tp, mp->m_rsumip, XFS_ILOCK_EXCL); in xfs_bmap_rtalloc()
132 if (ap->eof && ap->offset == 0) { in xfs_bmap_rtalloc()
135 error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx); in xfs_bmap_rtalloc()
138 ap->blkno = rtx * mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
140 ap->blkno = 0; in xfs_bmap_rtalloc()
148 do_div(ap->blkno, mp->m_sb.sb_rextsize); in xfs_bmap_rtalloc()
149 rtb = ap->blkno; in xfs_bmap_rtalloc()
150 ap->length = ralen; in xfs_bmap_rtalloc()
151 error = xfs_rtallocate_extent(ap->tp, ap->blkno, 1, ap->length, in xfs_bmap_rtalloc()
152 &ralen, ap->wasdel, prod, &rtb); in xfs_bmap_rtalloc()
156 ap->blkno = rtb; in xfs_bmap_rtalloc()
157 if (ap->blkno != NULLFSBLOCK) { in xfs_bmap_rtalloc()
158 ap->blkno *= mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
159 ralen *= mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
160 ap->length = ralen; in xfs_bmap_rtalloc()
161 ap->ip->i_d.di_nblocks += ralen; in xfs_bmap_rtalloc()
162 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); in xfs_bmap_rtalloc()
163 if (ap->wasdel) in xfs_bmap_rtalloc()
164 ap->ip->i_delayed_blks -= ralen; in xfs_bmap_rtalloc()
169 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, in xfs_bmap_rtalloc()
170 ap->wasdel ? XFS_TRANS_DQ_DELRTBCOUNT : in xfs_bmap_rtalloc()
174 if (ap->datatype & XFS_ALLOC_USERDATA_ZERO) { in xfs_bmap_rtalloc()
175 error = xfs_zero_extent(ap->ip, ap->blkno, ap->length); in xfs_bmap_rtalloc()
180 ap->length = 0; in xfs_bmap_rtalloc()
193 struct xfs_inode *ip, in xfs_bmap_eof() argument
201 error = xfs_bmap_last_extent(NULL, ip, whichfork, &rec, eof); in xfs_bmap_eof()
214 * Count leaf blocks given a range of extent records. Delayed allocation
237 * Count leaf blocks given a range of extent records originally
286 if (--level) { in xfs_bmap_count_tree()
288 nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); in xfs_bmap_count_tree()
297 nextbno = be64_to_cpu(nextblock->bb_u.l.bb_rightsib); in xfs_bmap_count_tree()
302 pp = XFS_BMBT_PTR_ADDR(mp, block, 1, mp->m_bmap_dmxr[1]); in xfs_bmap_count_tree()
310 return -EFSCORRUPTED; in xfs_bmap_count_tree()
316 nextbno = be64_to_cpu(block->bb_u.l.bb_rightsib); in xfs_bmap_count_tree()
317 numrecs = be16_to_cpu(block->bb_numrecs); in xfs_bmap_count_tree()
343 struct xfs_inode *ip, in xfs_bmap_count_blocks() argument
357 mp = ip->i_mount; in xfs_bmap_count_blocks()
360 ifp = XFS_IFORK_PTR(ip, whichfork); in xfs_bmap_count_blocks()
364 switch (XFS_IFORK_FORMAT(ip, whichfork)) { in xfs_bmap_count_blocks()
369 if (!(ifp->if_flags & XFS_IFEXTENTS)) { in xfs_bmap_count_blocks()
370 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_count_blocks()
378 block = ifp->if_broot; in xfs_bmap_count_blocks()
379 level = be16_to_cpu(block->bb_level); in xfs_bmap_count_blocks()
381 pp = XFS_BMAP_BROOT_PTR_ADDR(mp, block, 1, ifp->if_broot_bytes); in xfs_bmap_count_blocks()
384 ASSERT(XFS_FSB_TO_AGNO(mp, bno) < mp->m_sb.sb_agcount); in xfs_bmap_count_blocks()
385 ASSERT(XFS_FSB_TO_AGBNO(mp, bno) < mp->m_sb.sb_agblocks); in xfs_bmap_count_blocks()
392 return -EFSCORRUPTED; in xfs_bmap_count_blocks()
402 struct xfs_inode *ip, in xfs_getbmap_report_one() argument
408 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_one()
412 error = xfs_reflink_trim_around_shared(ip, got, &shared, &trimmed); in xfs_getbmap_report_one()
416 if (isnullstartblock(got->br_startblock) || in xfs_getbmap_report_one()
417 got->br_startblock == DELAYSTARTBLOCK) { in xfs_getbmap_report_one()
426 if (got->br_startoff < XFS_B_TO_FSB(ip->i_mount, XFS_ISIZE(ip))) in xfs_getbmap_report_one()
427 ASSERT((bmv->bmv_iflags & BMV_IF_DELALLOC) != 0); in xfs_getbmap_report_one()
429 p->bmv_oflags |= BMV_OF_DELALLOC; in xfs_getbmap_report_one()
430 p->bmv_block = -2; in xfs_getbmap_report_one()
432 p->bmv_block = xfs_fsb_to_db(ip, got->br_startblock); in xfs_getbmap_report_one()
435 if (got->br_state == XFS_EXT_UNWRITTEN && in xfs_getbmap_report_one()
436 (bmv->bmv_iflags & BMV_IF_PREALLOC)) in xfs_getbmap_report_one()
437 p->bmv_oflags |= BMV_OF_PREALLOC; in xfs_getbmap_report_one()
440 p->bmv_oflags |= BMV_OF_SHARED; in xfs_getbmap_report_one()
442 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, got->br_startoff); in xfs_getbmap_report_one()
443 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, got->br_blockcount); in xfs_getbmap_report_one()
445 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_one()
446 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_one()
447 bmv->bmv_entries++; in xfs_getbmap_report_one()
453 struct xfs_inode *ip, in xfs_getbmap_report_hole() argument
460 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_hole()
462 if (bmv->bmv_iflags & BMV_IF_NO_HOLES) in xfs_getbmap_report_hole()
465 p->bmv_block = -1; in xfs_getbmap_report_hole()
466 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, bno); in xfs_getbmap_report_hole()
467 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, end - bno); in xfs_getbmap_report_hole()
469 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_hole()
470 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_hole()
471 bmv->bmv_entries++; in xfs_getbmap_report_hole()
478 return bmv->bmv_length == 0 || bmv->bmv_entries >= bmv->bmv_count - 1; in xfs_getbmap_full()
486 xfs_fileoff_t end = rec->br_startoff + rec->br_blockcount; in xfs_getbmap_next_rec()
491 rec->br_startoff += rec->br_blockcount; in xfs_getbmap_next_rec()
492 if (!isnullstartblock(rec->br_startblock) && in xfs_getbmap_next_rec()
493 rec->br_startblock != DELAYSTARTBLOCK) in xfs_getbmap_next_rec()
494 rec->br_startblock += rec->br_blockcount; in xfs_getbmap_next_rec()
495 rec->br_blockcount = total_end - end; in xfs_getbmap_next_rec()
502 * are mapped, until the passed-in bmv->bmv_count slots have
503 * been filled, or until the formatter short-circuits the loop,
504 * if it is tracking filled-in extents on its own.
508 struct xfs_inode *ip, in xfs_getbmap() argument
512 struct xfs_mount *mp = ip->i_mount; in xfs_getbmap()
513 int iflags = bmv->bmv_iflags; in xfs_getbmap()
522 if (bmv->bmv_iflags & ~BMV_IF_VALID) in xfs_getbmap()
523 return -EINVAL; in xfs_getbmap()
527 return -EINVAL; in xfs_getbmap()
530 return -EINVAL; in xfs_getbmap()
532 if (bmv->bmv_length < -1) in xfs_getbmap()
533 return -EINVAL; in xfs_getbmap()
534 bmv->bmv_entries = 0; in xfs_getbmap()
535 if (bmv->bmv_length == 0) in xfs_getbmap()
544 ifp = XFS_IFORK_PTR(ip, whichfork); in xfs_getbmap()
546 xfs_ilock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
549 if (!XFS_IFORK_Q(ip)) in xfs_getbmap()
553 lock = xfs_ilock_attr_map_shared(ip); in xfs_getbmap()
560 if (xfs_get_cowextsz_hint(ip)) in xfs_getbmap()
561 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
563 max_len = XFS_ISIZE(ip); in xfs_getbmap()
566 xfs_ilock(ip, lock); in xfs_getbmap()
570 (ip->i_delayed_blks || XFS_ISIZE(ip) > ip->i_d.di_size)) { in xfs_getbmap()
571 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_getbmap()
577 * delalloc blocks on the inode beyond EOF due to in xfs_getbmap()
581 * ip->i_delayed_blks == 0. in xfs_getbmap()
585 if (xfs_get_extsz_hint(ip) || in xfs_getbmap()
586 (ip->i_d.di_flags & in xfs_getbmap()
588 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
590 max_len = XFS_ISIZE(ip); in xfs_getbmap()
592 lock = xfs_ilock_data_map_shared(ip); in xfs_getbmap()
596 switch (XFS_IFORK_FORMAT(ip, whichfork)) { in xfs_getbmap()
604 error = -EINVAL; in xfs_getbmap()
608 if (bmv->bmv_length == -1) { in xfs_getbmap()
610 bmv->bmv_length = max(0LL, max_len - bmv->bmv_offset); in xfs_getbmap()
613 bmv_end = bmv->bmv_offset + bmv->bmv_length; in xfs_getbmap()
615 first_bno = bno = XFS_BB_TO_FSBT(mp, bmv->bmv_offset); in xfs_getbmap()
616 len = XFS_BB_TO_FSB(mp, bmv->bmv_length); in xfs_getbmap()
618 if (!(ifp->if_flags & XFS_IFEXTENTS)) { in xfs_getbmap()
619 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_getbmap()
624 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_getbmap()
626 * Report a whole-file hole if the delalloc flag is set to in xfs_getbmap()
630 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
631 XFS_B_TO_FSB(mp, XFS_ISIZE(ip))); in xfs_getbmap()
643 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
657 error = xfs_getbmap_report_one(ip, bmv, out, bmv_end, in xfs_getbmap()
664 xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); in xfs_getbmap()
666 out[bmv->bmv_entries - 1].bmv_oflags |= BMV_OF_LAST; in xfs_getbmap()
670 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, in xfs_getbmap()
681 xfs_iunlock(ip, lock); in xfs_getbmap()
683 xfs_iunlock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
688 * Dead simple method of punching delalyed allocation blocks from a range in
689 * the inode. This will always punch out both the start and end blocks, even
691 * ensure that partial blocks are not passed in.
695 struct xfs_inode *ip, in xfs_bmap_punch_delalloc_range() argument
699 struct xfs_ifork *ifp = &ip->i_df; in xfs_bmap_punch_delalloc_range()
705 ASSERT(ifp->if_flags & XFS_IFEXTENTS); in xfs_bmap_punch_delalloc_range()
707 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
708 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_bmap_punch_delalloc_range()
717 * previous extent on non-delalloc or extents outside the in xfs_bmap_punch_delalloc_range()
727 error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, in xfs_bmap_punch_delalloc_range()
734 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
740 * blocks. The 'force' parameter determines whether we should also consider
741 * regular files that are marked preallocated or append-only.
744 xfs_can_free_eofblocks(struct xfs_inode *ip, bool force) in xfs_can_free_eofblocks() argument
747 if (!S_ISREG(VFS_I(ip)->i_mode)) in xfs_can_free_eofblocks()
751 * Zero sized files with no cached pages and delalloc blocks will not in xfs_can_free_eofblocks()
752 * have speculative prealloc/delalloc blocks to remove. in xfs_can_free_eofblocks()
754 if (VFS_I(ip)->i_size == 0 && in xfs_can_free_eofblocks()
755 VFS_I(ip)->i_mapping->nrpages == 0 && in xfs_can_free_eofblocks()
756 ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
760 if (!(ip->i_df.if_flags & XFS_IFEXTENTS)) in xfs_can_free_eofblocks()
764 * Do not free real preallocated or append-only files unless the file in xfs_can_free_eofblocks()
765 * has delalloc blocks and we are forced to remove them. in xfs_can_free_eofblocks()
767 if (ip->i_d.di_flags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) in xfs_can_free_eofblocks()
768 if (!force || ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
775 * This is called to free any blocks beyond eof. The caller must hold
781 struct xfs_inode *ip) in xfs_free_eofblocks() argument
790 struct xfs_mount *mp = ip->i_mount; in xfs_free_eofblocks()
793 * Figure out if there are any blocks beyond the end in xfs_free_eofblocks()
796 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); in xfs_free_eofblocks()
797 last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); in xfs_free_eofblocks()
800 map_len = last_fsb - end_fsb; in xfs_free_eofblocks()
803 xfs_ilock(ip, XFS_ILOCK_SHARED); in xfs_free_eofblocks()
804 error = xfs_bmapi_read(ip, end_fsb, map_len, &imap, &nimaps, 0); in xfs_free_eofblocks()
805 xfs_iunlock(ip, XFS_ILOCK_SHARED); in xfs_free_eofblocks()
808 * If there are blocks after the end of file, truncate the file to its in xfs_free_eofblocks()
813 ip->i_delayed_blks)) { in xfs_free_eofblocks()
817 error = xfs_qm_dqattach(ip); in xfs_free_eofblocks()
822 inode_dio_wait(VFS_I(ip)); in xfs_free_eofblocks()
824 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, in xfs_free_eofblocks()
831 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
832 xfs_trans_ijoin(tp, ip, 0); in xfs_free_eofblocks()
835 * Do not update the on-disk file size. If we update the in xfs_free_eofblocks()
836 * on-disk file size and then the system crashes before the in xfs_free_eofblocks()
840 error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, in xfs_free_eofblocks()
841 XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); in xfs_free_eofblocks()
851 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
854 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
861 struct xfs_inode *ip, in xfs_alloc_file_space() argument
866 xfs_mount_t *mp = ip->i_mount; in xfs_alloc_file_space()
880 trace_xfs_alloc_file_space(ip); in xfs_alloc_file_space()
883 return -EIO; in xfs_alloc_file_space()
885 error = xfs_qm_dqattach(ip); in xfs_alloc_file_space()
890 return -EINVAL; in xfs_alloc_file_space()
892 rt = XFS_IS_REALTIME_INODE(ip); in xfs_alloc_file_space()
893 extsz = xfs_get_extsz_hint(ip); in xfs_alloc_file_space()
920 e += extsz - temp; in xfs_alloc_file_space()
927 * The transaction reservation is limited to a 32-bit block in xfs_alloc_file_space()
928 * count, hence we need to limit the number of blocks we are in xfs_alloc_file_space()
933 resblks = min_t(xfs_fileoff_t, (e - s), (MAXEXTLEN * nimaps)); in xfs_alloc_file_space()
936 resrtextents /= mp->m_sb.sb_rextsize; in xfs_alloc_file_space()
948 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, in xfs_alloc_file_space()
958 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp)); in xfs_alloc_file_space()
961 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
962 error = xfs_trans_reserve_quota_nblks(tp, ip, qblocks, in xfs_alloc_file_space()
967 xfs_trans_ijoin(tp, ip, 0); in xfs_alloc_file_space()
969 error = xfs_bmapi_write(tp, ip, startoffset_fsb, in xfs_alloc_file_space()
979 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
983 allocated_fsb = imapp->br_blockcount; in xfs_alloc_file_space()
986 error = -ENOSPC; in xfs_alloc_file_space()
991 allocatesize_fsb -= allocated_fsb; in xfs_alloc_file_space()
996 error0: /* unlock inode, unreserve quota blocks, cancel trans */ in xfs_alloc_file_space()
997 xfs_trans_unreserve_quota_nblks(tp, ip, (long)qblocks, 0, quota_flag); in xfs_alloc_file_space()
1001 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
1007 struct xfs_inode *ip, in xfs_unmap_extent() argument
1012 struct xfs_mount *mp = ip->i_mount; in xfs_unmap_extent()
1017 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0, &tp); in xfs_unmap_extent()
1019 ASSERT(error == -ENOSPC || XFS_FORCED_SHUTDOWN(mp)); in xfs_unmap_extent()
1023 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
1024 error = xfs_trans_reserve_quota(tp, mp, ip->i_udquot, ip->i_gdquot, in xfs_unmap_extent()
1025 ip->i_pdquot, resblks, 0, XFS_QMOPT_RES_REGBLKS); in xfs_unmap_extent()
1029 xfs_trans_ijoin(tp, ip, 0); in xfs_unmap_extent()
1031 error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); in xfs_unmap_extent()
1037 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
1047 struct xfs_inode *ip, in xfs_adjust_extent_unmap_boundaries() argument
1051 struct xfs_mount *mp = ip->i_mount; in xfs_adjust_extent_unmap_boundaries()
1057 error = xfs_bmapi_read(ip, *startoffset_fsb, 1, &imap, &nimap, 0); in xfs_adjust_extent_unmap_boundaries()
1063 div_u64_rem(imap.br_startblock, mp->m_sb.sb_rextsize, &mod); in xfs_adjust_extent_unmap_boundaries()
1065 *startoffset_fsb += mp->m_sb.sb_rextsize - mod; in xfs_adjust_extent_unmap_boundaries()
1069 error = xfs_bmapi_read(ip, *endoffset_fsb - 1, 1, &imap, &nimap, 0); in xfs_adjust_extent_unmap_boundaries()
1076 if (mod && mod != mp->m_sb.sb_rextsize) in xfs_adjust_extent_unmap_boundaries()
1077 *endoffset_fsb -= mod; in xfs_adjust_extent_unmap_boundaries()
1085 struct xfs_inode *ip, in xfs_flush_unmap_range() argument
1089 struct xfs_mount *mp = ip->i_mount; in xfs_flush_unmap_range()
1090 struct inode *inode = VFS_I(ip); in xfs_flush_unmap_range()
1097 rounding = max_t(xfs_off_t, 1 << mp->m_sb.sb_blocklog, PAGE_SIZE); in xfs_flush_unmap_range()
1099 end = round_up(offset + len, rounding) - 1; in xfs_flush_unmap_range()
1101 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in xfs_flush_unmap_range()
1110 struct xfs_inode *ip, in xfs_free_file_space() argument
1114 struct xfs_mount *mp = ip->i_mount; in xfs_free_file_space()
1119 trace_xfs_free_file_space(ip); in xfs_free_file_space()
1121 error = xfs_qm_dqattach(ip); in xfs_free_file_space()
1128 error = xfs_flush_unmap_range(ip, offset, len); in xfs_free_file_space()
1141 if (XFS_IS_REALTIME_INODE(ip) && in xfs_free_file_space()
1142 !xfs_sb_version_hasextflgbit(&mp->m_sb)) { in xfs_free_file_space()
1143 error = xfs_adjust_extent_unmap_boundaries(ip, &startoffset_fsb, in xfs_free_file_space()
1151 error = xfs_unmap_extent(ip, startoffset_fsb, in xfs_free_file_space()
1152 endoffset_fsb - startoffset_fsb, &done); in xfs_free_file_space()
1159 * Now that we've unmap all full blocks we'll have to zero out any in xfs_free_file_space()
1164 if (offset >= XFS_ISIZE(ip)) in xfs_free_file_space()
1166 if (offset + len > XFS_ISIZE(ip)) in xfs_free_file_space()
1167 len = XFS_ISIZE(ip) - offset; in xfs_free_file_space()
1168 error = iomap_zero_range(VFS_I(ip), offset, len, NULL, &xfs_iomap_ops); in xfs_free_file_space()
1174 * must make sure that the post-EOF area is also zeroed because the in xfs_free_file_space()
1178 if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { in xfs_free_file_space()
1179 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, in xfs_free_file_space()
1192 struct xfs_inode *ip, in xfs_zero_file_space() argument
1196 struct xfs_mount *mp = ip->i_mount; in xfs_zero_file_space()
1200 trace_xfs_zero_file_space(ip); in xfs_zero_file_space()
1202 blksize = 1 << mp->m_sb.sb_blocklog; in xfs_zero_file_space()
1210 * 2.) If prealloc returns ENOSPC, the file range is still zero-valued in xfs_zero_file_space()
1213 error = xfs_free_file_space(ip, offset, len); in xfs_zero_file_space()
1217 error = xfs_alloc_file_space(ip, round_down(offset, blksize), in xfs_zero_file_space()
1218 round_up(offset + len, blksize) - in xfs_zero_file_space()
1228 struct xfs_inode *ip, in xfs_prepare_shift() argument
1234 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation in xfs_prepare_shift()
1237 if (xfs_can_free_eofblocks(ip, true)) { in xfs_prepare_shift()
1238 error = xfs_free_eofblocks(ip); in xfs_prepare_shift()
1247 error = xfs_flush_unmap_range(ip, offset, XFS_ISIZE(ip)); in xfs_prepare_shift()
1256 if (xfs_inode_has_cow_data(ip)) { in xfs_prepare_shift()
1257 error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF, in xfs_prepare_shift()
1269 * The first thing we do is to free data blocks in the specified range
1280 struct xfs_inode *ip, in xfs_collapse_file_space() argument
1284 struct xfs_mount *mp = ip->i_mount; in xfs_collapse_file_space()
1292 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_collapse_file_space()
1293 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_collapse_file_space()
1295 trace_xfs_collapse_file_space(ip); in xfs_collapse_file_space()
1297 error = xfs_free_file_space(ip, offset, len); in xfs_collapse_file_space()
1301 error = xfs_prepare_shift(ip, offset); in xfs_collapse_file_space()
1306 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0, in xfs_collapse_file_space()
1311 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1312 error = xfs_trans_reserve_quota(tp, mp, ip->i_udquot, in xfs_collapse_file_space()
1313 ip->i_gdquot, ip->i_pdquot, resblks, 0, in xfs_collapse_file_space()
1317 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1319 error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb, in xfs_collapse_file_space()
1348 struct xfs_inode *ip, in xfs_insert_file_space() argument
1352 struct xfs_mount *mp = ip->i_mount; in xfs_insert_file_space()
1360 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_insert_file_space()
1361 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_insert_file_space()
1363 trace_xfs_insert_file_space(ip); in xfs_insert_file_space()
1365 error = xfs_bmap_can_insert_extents(ip, stop_fsb, shift_fsb); in xfs_insert_file_space()
1369 error = xfs_prepare_shift(ip, offset); in xfs_insert_file_space()
1378 error = xfs_bmap_split_extent(ip, stop_fsb); in xfs_insert_file_space()
1383 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, in xfs_insert_file_space()
1388 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1389 xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1390 error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb, in xfs_insert_file_space()
1427 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents_check_format() argument
1432 if (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL || in xfs_swap_extents_check_format()
1433 tip->i_d.di_format == XFS_DINODE_FMT_LOCAL) in xfs_swap_extents_check_format()
1434 return -EINVAL; in xfs_swap_extents_check_format()
1440 if (ip->i_d.di_nextents < tip->i_d.di_nextents) in xfs_swap_extents_check_format()
1441 return -EINVAL; in xfs_swap_extents_check_format()
1447 if (xfs_sb_version_hasrmapbt(&ip->i_mount->m_sb)) in xfs_swap_extents_check_format()
1455 if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1456 tip->i_d.di_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extents_check_format()
1457 return -EINVAL; in xfs_swap_extents_check_format()
1460 if (tip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1462 XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1463 return -EINVAL; in xfs_swap_extents_check_format()
1466 if (ip->i_d.di_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1467 XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) > in xfs_swap_extents_check_format()
1469 return -EINVAL; in xfs_swap_extents_check_format()
1476 * Note that we have to be careful to allow btree->extent conversions in xfs_swap_extents_check_format()
1480 if (tip->i_d.di_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1481 if (XFS_IFORK_Q(ip) && in xfs_swap_extents_check_format()
1482 XFS_BMAP_BMDR_SPACE(tip->i_df.if_broot) > XFS_IFORK_BOFF(ip)) in xfs_swap_extents_check_format()
1483 return -EINVAL; in xfs_swap_extents_check_format()
1485 XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1486 return -EINVAL; in xfs_swap_extents_check_format()
1489 /* Reciprocal target->temp btree format checks */ in xfs_swap_extents_check_format()
1490 if (ip->i_d.di_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1492 XFS_BMAP_BMDR_SPACE(ip->i_df.if_broot) > XFS_IFORK_BOFF(tip)) in xfs_swap_extents_check_format()
1493 return -EINVAL; in xfs_swap_extents_check_format()
1494 if (XFS_IFORK_NEXTENTS(ip, XFS_DATA_FORK) <= in xfs_swap_extents_check_format()
1496 return -EINVAL; in xfs_swap_extents_check_format()
1504 struct xfs_inode *ip) in xfs_swap_extent_flush() argument
1508 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_swap_extent_flush()
1511 truncate_pagecache_range(VFS_I(ip), 0, -1); in xfs_swap_extent_flush()
1514 if (VFS_I(ip)->i_mapping->nrpages) in xfs_swap_extent_flush()
1515 return -EINVAL; in xfs_swap_extent_flush()
1525 struct xfs_inode *ip, in xfs_swap_extent_rmap() argument
1542 * If the source file has shared blocks, we must flag the donor in xfs_swap_extent_rmap()
1543 * file as having shared blocks so that we get the shared-block in xfs_swap_extent_rmap()
1547 tip_flags2 = tip->i_d.di_flags2; in xfs_swap_extent_rmap()
1548 if (ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) in xfs_swap_extent_rmap()
1549 tip->i_d.di_flags2 |= XFS_DIFLAG2_REFLINK; in xfs_swap_extent_rmap()
1552 end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); in xfs_swap_extent_rmap()
1553 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); in xfs_swap_extent_rmap()
1568 /* Unmap the old blocks in the source file. */ in xfs_swap_extent_rmap()
1570 ASSERT(tp->t_firstblock == NULLFSBLOCK); in xfs_swap_extent_rmap()
1575 error = xfs_bmapi_read(ip, tirec.br_startoff, in xfs_swap_extent_rmap()
1582 trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); in xfs_swap_extent_rmap()
1597 error = xfs_bmap_unmap_extent(tp, ip, &irec); in xfs_swap_extent_rmap()
1601 /* Map the donor file's blocks into the source file. */ in xfs_swap_extent_rmap()
1602 error = xfs_bmap_map_extent(tp, ip, &uirec); in xfs_swap_extent_rmap()
1606 /* Map the source file's blocks into the donor file. */ in xfs_swap_extent_rmap()
1620 tirec.br_blockcount -= rlen; in xfs_swap_extent_rmap()
1624 count_fsb -= ilen; in xfs_swap_extent_rmap()
1628 tip->i_d.di_flags2 = tip_flags2; in xfs_swap_extent_rmap()
1632 trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); in xfs_swap_extent_rmap()
1633 tip->i_d.di_flags2 = tip_flags2; in xfs_swap_extent_rmap()
1641 struct xfs_inode *ip, in xfs_swap_extent_forks() argument
1653 * Count the number of extended attribute blocks in xfs_swap_extent_forks()
1655 if ( ((XFS_IFORK_Q(ip) != 0) && (ip->i_d.di_anextents > 0)) && in xfs_swap_extent_forks()
1656 (ip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { in xfs_swap_extent_forks()
1657 error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk, in xfs_swap_extent_forks()
1662 if ( ((XFS_IFORK_Q(tip) != 0) && (tip->i_d.di_anextents > 0)) && in xfs_swap_extent_forks()
1663 (tip->i_d.di_aformat != XFS_DINODE_FMT_LOCAL)) { in xfs_swap_extent_forks()
1672 * block headers. We can't start changing the bmbt blocks until the in xfs_swap_extent_forks()
1677 if (ip->i_d.di_version == 3 && in xfs_swap_extent_forks()
1678 ip->i_d.di_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1680 if (tip->i_d.di_version == 3 && in xfs_swap_extent_forks()
1681 tip->i_d.di_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1687 swap(ip->i_df, tip->i_df); in xfs_swap_extent_forks()
1690 * Fix the on-disk inode values in xfs_swap_extent_forks()
1692 tmp = (uint64_t)ip->i_d.di_nblocks; in xfs_swap_extent_forks()
1693 ip->i_d.di_nblocks = tip->i_d.di_nblocks - taforkblks + aforkblks; in xfs_swap_extent_forks()
1694 tip->i_d.di_nblocks = tmp + taforkblks - aforkblks; in xfs_swap_extent_forks()
1696 swap(ip->i_d.di_nextents, tip->i_d.di_nextents); in xfs_swap_extent_forks()
1697 swap(ip->i_d.di_format, tip->i_d.di_format); in xfs_swap_extent_forks()
1703 * number of delalloc blocks the data fork in the source inode is in xfs_swap_extent_forks()
1708 ASSERT(tip->i_delayed_blks == 0); in xfs_swap_extent_forks()
1709 tip->i_delayed_blks = ip->i_delayed_blks; in xfs_swap_extent_forks()
1710 ip->i_delayed_blks = 0; in xfs_swap_extent_forks()
1712 switch (ip->i_d.di_format) { in xfs_swap_extent_forks()
1717 ASSERT(ip->i_d.di_version < 3 || in xfs_swap_extent_forks()
1723 switch (tip->i_d.di_format) { in xfs_swap_extent_forks()
1729 ASSERT(tip->i_d.di_version < 3 || in xfs_swap_extent_forks()
1738 * Fix up the owners of the bmbt blocks to refer to the current inode. The
1741 * physically logged as a fallback and the scan returns -EAGAIN. We must roll
1748 struct xfs_inode *ip, in xfs_swap_change_owner() argument
1755 error = xfs_bmbt_change_owner(tp, ip, XFS_DATA_FORK, ip->i_ino, in xfs_swap_change_owner()
1758 if (error != -EAGAIN) in xfs_swap_change_owner()
1770 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_change_owner()
1772 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_swap_change_owner()
1781 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents() argument
1785 struct xfs_mount *mp = ip->i_mount; in xfs_swap_extents()
1787 struct xfs_bstat *sbp = &sxp->sx_stat; in xfs_swap_extents()
1800 lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()
1802 xfs_lock_two_inodes(ip, XFS_MMAPLOCK_EXCL, tip, XFS_MMAPLOCK_EXCL); in xfs_swap_extents()
1805 if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { in xfs_swap_extents()
1806 error = -EINVAL; in xfs_swap_extents()
1810 /* Verify both files are either real-time or non-realtime */ in xfs_swap_extents()
1811 if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { in xfs_swap_extents()
1812 error = -EINVAL; in xfs_swap_extents()
1816 error = xfs_swap_extent_flush(ip); in xfs_swap_extents()
1834 if (xfs_sb_version_hasrmapbt(&mp->m_sb)) { in xfs_swap_extents()
1836 uint32_t ipnext = XFS_IFORK_NEXTENTS(ip, w); in xfs_swap_extents()
1850 * btree <-> extent format on unmap -> remap cycles, freeing and in xfs_swap_extents()
1853 if (ipnext == (XFS_IFORK_MAXEXT(ip, w) + 1)) in xfs_swap_extents()
1854 resblks += XFS_IFORK_MAXEXT(ip, w); in xfs_swap_extents()
1858 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, 0, &tp); in xfs_swap_extents()
1866 xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1868 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_extents()
1873 if (sxp->sx_offset != 0 || in xfs_swap_extents()
1874 sxp->sx_length != ip->i_d.di_size || in xfs_swap_extents()
1875 sxp->sx_length != tip->i_d.di_size) { in xfs_swap_extents()
1876 error = -EFAULT; in xfs_swap_extents()
1880 trace_xfs_swap_extent_before(ip, 0); in xfs_swap_extents()
1884 error = xfs_swap_extents_check_format(ip, tip); in xfs_swap_extents()
1888 __func__, ip->i_ino); in xfs_swap_extents()
1899 if ((sbp->bs_ctime.tv_sec != VFS_I(ip)->i_ctime.tv_sec) || in xfs_swap_extents()
1900 (sbp->bs_ctime.tv_nsec != VFS_I(ip)->i_ctime.tv_nsec) || in xfs_swap_extents()
1901 (sbp->bs_mtime.tv_sec != VFS_I(ip)->i_mtime.tv_sec) || in xfs_swap_extents()
1902 (sbp->bs_mtime.tv_nsec != VFS_I(ip)->i_mtime.tv_nsec)) { in xfs_swap_extents()
1903 error = -EBUSY; in xfs_swap_extents()
1908 * Note the trickiness in setting the log flags - we set the owner log in xfs_swap_extents()
1912 * not the pre-swapped inodes. in xfs_swap_extents()
1917 if (xfs_sb_version_hasrmapbt(&mp->m_sb)) in xfs_swap_extents()
1918 error = xfs_swap_extent_rmap(&tp, ip, tip); in xfs_swap_extents()
1920 error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, in xfs_swap_extents()
1926 if ((ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK) ^ in xfs_swap_extents()
1927 (tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK)) { in xfs_swap_extents()
1928 f = ip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1929 ip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1930 ip->i_d.di_flags2 |= tip->i_d.di_flags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1931 tip->i_d.di_flags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1932 tip->i_d.di_flags2 |= f & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1936 if (xfs_sb_version_hasreflink(&mp->m_sb)) { in xfs_swap_extents()
1937 ASSERT(ip->i_cformat == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1938 ASSERT(tip->i_cformat == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1940 swap(ip->i_cnextents, tip->i_cnextents); in xfs_swap_extents()
1941 swap(ip->i_cowfp, tip->i_cowfp); in xfs_swap_extents()
1943 if (ip->i_cowfp && ip->i_cowfp->if_bytes) in xfs_swap_extents()
1944 xfs_inode_set_cowblocks_tag(ip); in xfs_swap_extents()
1946 xfs_inode_clear_cowblocks_tag(ip); in xfs_swap_extents()
1947 if (tip->i_cowfp && tip->i_cowfp->if_bytes) in xfs_swap_extents()
1953 xfs_trans_log_inode(tp, ip, src_log_flags); in xfs_swap_extents()
1958 * have inode number owner values in the bmbt blocks that still refer to in xfs_swap_extents()
1963 error = xfs_swap_change_owner(&tp, ip, tip); in xfs_swap_extents()
1968 error = xfs_swap_change_owner(&tp, tip, ip); in xfs_swap_extents()
1977 if (mp->m_flags & XFS_MOUNT_WSYNC) in xfs_swap_extents()
1982 trace_xfs_swap_extent_after(ip, 0); in xfs_swap_extents()
1986 xfs_iunlock(ip, lock_flags); in xfs_swap_extents()
1988 unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()