Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
40 xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb) in xfs_fsb_to_db() argument
42 if (XFS_IS_REALTIME_INODE(ip)) in xfs_fsb_to_db()
43 return XFS_FSB_TO_BB(ip->i_mount, fsb); in xfs_fsb_to_db()
44 return XFS_FSB_TO_DADDR(ip->i_mount, fsb); in xfs_fsb_to_db()
56 struct xfs_inode *ip, in xfs_zero_extent() argument
60 struct xfs_mount *mp = ip->i_mount; in xfs_zero_extent()
61 struct xfs_buftarg *target = xfs_inode_buftarg(ip); in xfs_zero_extent()
62 xfs_daddr_t sector = xfs_fsb_to_db(ip, start_fsb); in xfs_zero_extent()
65 return blkdev_issue_zeroout(target->bt_bdev, in xfs_zero_extent()
66 block << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
67 count_fsb << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
76 struct xfs_mount *mp = ap->ip->i_mount; in xfs_bmap_rtalloc()
77 xfs_fileoff_t orig_offset = ap->offset; in xfs_bmap_rtalloc()
83 xfs_extlen_t orig_length = ap->length; in xfs_bmap_rtalloc()
84 xfs_extlen_t minlen = mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
90 align = xfs_get_extsz_hint(ap->ip); in xfs_bmap_rtalloc()
92 prod = align / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
93 error = xfs_bmap_extsize_align(mp, &ap->got, &ap->prev, in xfs_bmap_rtalloc()
94 align, 1, ap->eof, 0, in xfs_bmap_rtalloc()
95 ap->conv, &ap->offset, &ap->length); in xfs_bmap_rtalloc()
98 ASSERT(ap->length); in xfs_bmap_rtalloc()
99 ASSERT(ap->length % mp->m_sb.sb_rextsize == 0); in xfs_bmap_rtalloc()
105 * blocks that the caller asked for. in xfs_bmap_rtalloc()
107 if (ap->offset != orig_offset) in xfs_bmap_rtalloc()
108 minlen += orig_offset - ap->offset; in xfs_bmap_rtalloc()
114 div_u64_rem(ap->offset, align, &mod); in xfs_bmap_rtalloc()
115 if (mod || ap->length % align) in xfs_bmap_rtalloc()
120 ralen = ap->length / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
128 if (ralen * mp->m_sb.sb_rextsize >= XFS_MAX_BMBT_EXTLEN) in xfs_bmap_rtalloc()
129 ralen = XFS_MAX_BMBT_EXTLEN / mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
135 xfs_ilock(mp->m_rbmip, XFS_ILOCK_EXCL|XFS_ILOCK_RTBITMAP); in xfs_bmap_rtalloc()
136 xfs_trans_ijoin(ap->tp, mp->m_rbmip, XFS_ILOCK_EXCL); in xfs_bmap_rtalloc()
137 xfs_ilock(mp->m_rsumip, XFS_ILOCK_EXCL|XFS_ILOCK_RTSUM); in xfs_bmap_rtalloc()
138 xfs_trans_ijoin(ap->tp, mp->m_rsumip, XFS_ILOCK_EXCL); in xfs_bmap_rtalloc()
146 if (ap->eof && ap->offset == 0) { in xfs_bmap_rtalloc()
149 error = xfs_rtpick_extent(mp, ap->tp, ralen, &rtx); in xfs_bmap_rtalloc()
152 ap->blkno = rtx * mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
154 ap->blkno = 0; in xfs_bmap_rtalloc()
163 ap->blkno = 0; in xfs_bmap_rtalloc()
165 do_div(ap->blkno, mp->m_sb.sb_rextsize); in xfs_bmap_rtalloc()
166 rtb = ap->blkno; in xfs_bmap_rtalloc()
167 ap->length = ralen; in xfs_bmap_rtalloc()
168 raminlen = max_t(xfs_extlen_t, 1, minlen / mp->m_sb.sb_rextsize); in xfs_bmap_rtalloc()
169 error = xfs_rtallocate_extent(ap->tp, ap->blkno, raminlen, ap->length, in xfs_bmap_rtalloc()
170 &ralen, ap->wasdel, prod, &rtb); in xfs_bmap_rtalloc()
175 ap->blkno = rtb * mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
176 ap->length = ralen * mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
177 ap->ip->i_nblocks += ap->length; in xfs_bmap_rtalloc()
178 xfs_trans_log_inode(ap->tp, ap->ip, XFS_ILOG_CORE); in xfs_bmap_rtalloc()
179 if (ap->wasdel) in xfs_bmap_rtalloc()
180 ap->ip->i_delayed_blks -= ap->length; in xfs_bmap_rtalloc()
185 xfs_trans_mod_dquot_byino(ap->tp, ap->ip, in xfs_bmap_rtalloc()
186 ap->wasdel ? XFS_TRANS_DQ_DELRTBCOUNT : in xfs_bmap_rtalloc()
187 XFS_TRANS_DQ_RTBCOUNT, ap->length); in xfs_bmap_rtalloc()
191 if (align > mp->m_sb.sb_rextsize) { in xfs_bmap_rtalloc()
198 ap->offset = orig_offset; in xfs_bmap_rtalloc()
199 ap->length = orig_length; in xfs_bmap_rtalloc()
200 minlen = align = mp->m_sb.sb_rextsize; in xfs_bmap_rtalloc()
204 if (!ignore_locality && ap->blkno != 0) { in xfs_bmap_rtalloc()
213 ap->blkno = NULLFSBLOCK; in xfs_bmap_rtalloc()
214 ap->length = 0; in xfs_bmap_rtalloc()
224 * Count leaf blocks given a range of extent records. Delayed allocation
253 struct xfs_inode *ip, in xfs_bmap_count_blocks() argument
258 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_count_blocks()
259 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_count_blocks()
270 switch (ifp->if_format) { in xfs_bmap_count_blocks()
272 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_count_blocks()
276 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_count_blocks()
285 * only interested in allocated disk blocks. in xfs_bmap_count_blocks()
287 *count += btblocks - 1; in xfs_bmap_count_blocks()
300 struct xfs_inode *ip, in xfs_getbmap_report_one() argument
306 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_one()
310 error = xfs_reflink_trim_around_shared(ip, got, &shared); in xfs_getbmap_report_one()
314 if (isnullstartblock(got->br_startblock) || in xfs_getbmap_report_one()
315 got->br_startblock == DELAYSTARTBLOCK) { in xfs_getbmap_report_one()
317 * Take the flush completion as being a point-in-time snapshot in xfs_getbmap_report_one()
322 if (!(bmv->bmv_iflags & BMV_IF_DELALLOC)) in xfs_getbmap_report_one()
325 p->bmv_oflags |= BMV_OF_DELALLOC; in xfs_getbmap_report_one()
326 p->bmv_block = -2; in xfs_getbmap_report_one()
328 p->bmv_block = xfs_fsb_to_db(ip, got->br_startblock); in xfs_getbmap_report_one()
331 if (got->br_state == XFS_EXT_UNWRITTEN && in xfs_getbmap_report_one()
332 (bmv->bmv_iflags & BMV_IF_PREALLOC)) in xfs_getbmap_report_one()
333 p->bmv_oflags |= BMV_OF_PREALLOC; in xfs_getbmap_report_one()
336 p->bmv_oflags |= BMV_OF_SHARED; in xfs_getbmap_report_one()
338 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, got->br_startoff); in xfs_getbmap_report_one()
339 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, got->br_blockcount); in xfs_getbmap_report_one()
341 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_one()
342 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_one()
343 bmv->bmv_entries++; in xfs_getbmap_report_one()
349 struct xfs_inode *ip, in xfs_getbmap_report_hole() argument
356 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_hole()
358 if (bmv->bmv_iflags & BMV_IF_NO_HOLES) in xfs_getbmap_report_hole()
361 p->bmv_block = -1; in xfs_getbmap_report_hole()
362 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, bno); in xfs_getbmap_report_hole()
363 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, end - bno); in xfs_getbmap_report_hole()
365 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_hole()
366 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_hole()
367 bmv->bmv_entries++; in xfs_getbmap_report_hole()
374 return bmv->bmv_length == 0 || bmv->bmv_entries >= bmv->bmv_count - 1; in xfs_getbmap_full()
382 xfs_fileoff_t end = rec->br_startoff + rec->br_blockcount; in xfs_getbmap_next_rec()
387 rec->br_startoff += rec->br_blockcount; in xfs_getbmap_next_rec()
388 if (!isnullstartblock(rec->br_startblock) && in xfs_getbmap_next_rec()
389 rec->br_startblock != DELAYSTARTBLOCK) in xfs_getbmap_next_rec()
390 rec->br_startblock += rec->br_blockcount; in xfs_getbmap_next_rec()
391 rec->br_blockcount = total_end - end; in xfs_getbmap_next_rec()
398 * are mapped, until the passed-in bmv->bmv_count slots have
399 * been filled, or until the formatter short-circuits the loop,
400 * if it is tracking filled-in extents on its own.
404 struct xfs_inode *ip, in xfs_getbmap() argument
408 struct xfs_mount *mp = ip->i_mount; in xfs_getbmap()
409 int iflags = bmv->bmv_iflags; in xfs_getbmap()
418 if (bmv->bmv_iflags & ~BMV_IF_VALID) in xfs_getbmap()
419 return -EINVAL; in xfs_getbmap()
423 return -EINVAL; in xfs_getbmap()
426 return -EINVAL; in xfs_getbmap()
428 if (bmv->bmv_length < -1) in xfs_getbmap()
429 return -EINVAL; in xfs_getbmap()
430 bmv->bmv_entries = 0; in xfs_getbmap()
431 if (bmv->bmv_length == 0) in xfs_getbmap()
441 xfs_ilock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
444 lock = xfs_ilock_attr_map_shared(ip); in xfs_getbmap()
445 if (!xfs_inode_has_attr_fork(ip)) in xfs_getbmap()
452 xfs_ilock(ip, lock); in xfs_getbmap()
455 if (!xfs_ifork_ptr(ip, whichfork)) in xfs_getbmap()
458 if (xfs_get_cowextsz_hint(ip)) in xfs_getbmap()
459 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
461 max_len = XFS_ISIZE(ip); in xfs_getbmap()
465 (ip->i_delayed_blks || XFS_ISIZE(ip) > ip->i_disk_size)) { in xfs_getbmap()
466 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_getbmap()
472 * delalloc blocks on the inode beyond EOF due to in xfs_getbmap()
476 * ip->i_delayed_blks == 0. in xfs_getbmap()
480 if (xfs_get_extsz_hint(ip) || in xfs_getbmap()
481 (ip->i_diflags & in xfs_getbmap()
483 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
485 max_len = XFS_ISIZE(ip); in xfs_getbmap()
487 lock = xfs_ilock_data_map_shared(ip); in xfs_getbmap()
491 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_getbmap()
493 switch (ifp->if_format) { in xfs_getbmap()
501 error = -EINVAL; in xfs_getbmap()
505 if (bmv->bmv_length == -1) { in xfs_getbmap()
507 bmv->bmv_length = max(0LL, max_len - bmv->bmv_offset); in xfs_getbmap()
510 bmv_end = bmv->bmv_offset + bmv->bmv_length; in xfs_getbmap()
512 first_bno = bno = XFS_BB_TO_FSBT(mp, bmv->bmv_offset); in xfs_getbmap()
513 len = XFS_BB_TO_FSB(mp, bmv->bmv_length); in xfs_getbmap()
515 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_getbmap()
519 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_getbmap()
521 * Report a whole-file hole if the delalloc flag is set to in xfs_getbmap()
525 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
526 XFS_B_TO_FSB(mp, XFS_ISIZE(ip))); in xfs_getbmap()
538 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
552 error = xfs_getbmap_report_one(ip, bmv, out, bmv_end, in xfs_getbmap()
559 xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); in xfs_getbmap()
561 if (bmv->bmv_entries > 0) in xfs_getbmap()
562 out[bmv->bmv_entries - 1].bmv_oflags |= in xfs_getbmap()
567 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, in xfs_getbmap()
578 xfs_iunlock(ip, lock); in xfs_getbmap()
580 xfs_iunlock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
585 * Dead simple method of punching delalyed allocation blocks from a range in
586 * the inode. This will always punch out both the start and end blocks, even
588 * ensure that partial blocks are not passed in.
592 struct xfs_inode *ip, in xfs_bmap_punch_delalloc_range() argument
596 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_punch_delalloc_range()
597 struct xfs_ifork *ifp = &ip->i_df; in xfs_bmap_punch_delalloc_range()
606 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
607 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_bmap_punch_delalloc_range()
612 xfs_trim_extent(&del, start_fsb, end_fsb - start_fsb); in xfs_bmap_punch_delalloc_range()
616 * previous extent on non-delalloc or extents outside the in xfs_bmap_punch_delalloc_range()
626 error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, in xfs_bmap_punch_delalloc_range()
633 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
639 * blocks. The 'force' parameter determines whether we should also consider
640 * regular files that are marked preallocated or append-only.
644 struct xfs_inode *ip, in xfs_can_free_eofblocks() argument
648 struct xfs_mount *mp = ip->i_mount; in xfs_can_free_eofblocks()
658 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL) || in xfs_can_free_eofblocks()
659 (VFS_I(ip)->i_state & I_FREEING)); in xfs_can_free_eofblocks()
662 if (!S_ISREG(VFS_I(ip)->i_mode)) in xfs_can_free_eofblocks()
666 * Zero sized files with no cached pages and delalloc blocks will not in xfs_can_free_eofblocks()
667 * have speculative prealloc/delalloc blocks to remove. in xfs_can_free_eofblocks()
669 if (VFS_I(ip)->i_size == 0 && in xfs_can_free_eofblocks()
670 VFS_I(ip)->i_mapping->nrpages == 0 && in xfs_can_free_eofblocks()
671 ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
675 if (xfs_need_iread_extents(&ip->i_df)) in xfs_can_free_eofblocks()
679 * Do not free real preallocated or append-only files unless the file in xfs_can_free_eofblocks()
680 * has delalloc blocks and we are forced to remove them. in xfs_can_free_eofblocks()
682 if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) in xfs_can_free_eofblocks()
683 if (!force || ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
687 * Do not try to free post-EOF blocks if EOF is beyond the end of the in xfs_can_free_eofblocks()
691 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); in xfs_can_free_eofblocks()
692 if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) in xfs_can_free_eofblocks()
693 end_fsb = roundup_64(end_fsb, mp->m_sb.sb_rextsize); in xfs_can_free_eofblocks()
694 last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); in xfs_can_free_eofblocks()
702 xfs_ilock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
703 error = xfs_bmapi_read(ip, end_fsb, last_fsb - end_fsb, &imap, &nimaps, in xfs_can_free_eofblocks()
705 xfs_iunlock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
711 * reservations, then we have post-EOF blocks to try to free. in xfs_can_free_eofblocks()
713 return imap.br_startblock != HOLESTARTBLOCK || ip->i_delayed_blks; in xfs_can_free_eofblocks()
717 * This is called to free any blocks beyond eof. The caller must hold
723 struct xfs_inode *ip) in xfs_free_eofblocks() argument
726 struct xfs_mount *mp = ip->i_mount; in xfs_free_eofblocks()
730 error = xfs_qm_dqattach(ip); in xfs_free_eofblocks()
735 inode_dio_wait(VFS_I(ip)); in xfs_free_eofblocks()
737 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); in xfs_free_eofblocks()
743 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
744 xfs_trans_ijoin(tp, ip, 0); in xfs_free_eofblocks()
747 * Do not update the on-disk file size. If we update the on-disk file in xfs_free_eofblocks()
752 error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, in xfs_free_eofblocks()
753 XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); in xfs_free_eofblocks()
761 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
771 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
777 struct xfs_inode *ip, in xfs_alloc_file_space() argument
781 xfs_mount_t *mp = ip->i_mount; in xfs_alloc_file_space()
792 trace_xfs_alloc_file_space(ip); in xfs_alloc_file_space()
795 return -EIO; in xfs_alloc_file_space()
797 error = xfs_qm_dqattach(ip); in xfs_alloc_file_space()
802 return -EINVAL; in xfs_alloc_file_space()
804 rt = XFS_IS_REALTIME_INODE(ip); in xfs_alloc_file_space()
805 extsz = xfs_get_extsz_hint(ip); in xfs_alloc_file_space()
811 allocatesize_fsb = endoffset_fsb - startoffset_fsb; in xfs_alloc_file_space()
834 e += extsz - temp; in xfs_alloc_file_space()
841 * The transaction reservation is limited to a 32-bit block in xfs_alloc_file_space()
842 * count, hence we need to limit the number of blocks we are in xfs_alloc_file_space()
848 resblks = min_t(xfs_fileoff_t, (e - s), in xfs_alloc_file_space()
858 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_alloc_file_space()
863 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_alloc_file_space()
865 if (error == -EFBIG) in xfs_alloc_file_space()
866 error = xfs_iext_count_upgrade(tp, ip, in xfs_alloc_file_space()
871 error = xfs_bmapi_write(tp, ip, startoffset_fsb, in xfs_alloc_file_space()
877 ip->i_diflags |= XFS_DIFLAG_PREALLOC; in xfs_alloc_file_space()
878 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_alloc_file_space()
881 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
895 startoffset_fsb += imapp->br_blockcount; in xfs_alloc_file_space()
896 allocatesize_fsb -= imapp->br_blockcount; in xfs_alloc_file_space()
904 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
910 struct xfs_inode *ip, in xfs_unmap_extent() argument
915 struct xfs_mount *mp = ip->i_mount; in xfs_unmap_extent()
920 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0, in xfs_unmap_extent()
925 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_unmap_extent()
927 if (error == -EFBIG) in xfs_unmap_extent()
928 error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT); in xfs_unmap_extent()
932 error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); in xfs_unmap_extent()
938 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
949 struct xfs_inode *ip, in xfs_flush_unmap_range() argument
953 struct xfs_mount *mp = ip->i_mount; in xfs_flush_unmap_range()
954 struct inode *inode = VFS_I(ip); in xfs_flush_unmap_range()
958 rounding = max_t(xfs_off_t, mp->m_sb.sb_blocksize, PAGE_SIZE); in xfs_flush_unmap_range()
960 end = round_up(offset + len, rounding) - 1; in xfs_flush_unmap_range()
962 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in xfs_flush_unmap_range()
971 struct xfs_inode *ip, in xfs_free_file_space() argument
975 struct xfs_mount *mp = ip->i_mount; in xfs_free_file_space()
980 trace_xfs_free_file_space(ip); in xfs_free_file_space()
982 error = xfs_qm_dqattach(ip); in xfs_free_file_space()
993 if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) { in xfs_free_file_space()
995 mp->m_sb.sb_rextsize); in xfs_free_file_space()
997 mp->m_sb.sb_rextsize); in xfs_free_file_space()
1005 error = xfs_unmap_extent(ip, startoffset_fsb, in xfs_free_file_space()
1006 endoffset_fsb - startoffset_fsb, &done); in xfs_free_file_space()
1013 * Now that we've unmap all full blocks we'll have to zero out any in xfs_free_file_space()
1018 if (offset >= XFS_ISIZE(ip)) in xfs_free_file_space()
1020 if (offset + len > XFS_ISIZE(ip)) in xfs_free_file_space()
1021 len = XFS_ISIZE(ip) - offset; in xfs_free_file_space()
1022 error = xfs_zero_range(ip, offset, len, NULL); in xfs_free_file_space()
1028 * must make sure that the post-EOF area is also zeroed because the in xfs_free_file_space()
1032 if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { in xfs_free_file_space()
1033 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, in xfs_free_file_space()
1042 struct xfs_inode *ip, in xfs_prepare_shift() argument
1045 struct xfs_mount *mp = ip->i_mount; in xfs_prepare_shift()
1049 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation in xfs_prepare_shift()
1052 if (xfs_can_free_eofblocks(ip, true)) { in xfs_prepare_shift()
1053 error = xfs_free_eofblocks(ip); in xfs_prepare_shift()
1065 offset = round_down(offset, mp->m_sb.sb_blocksize); in xfs_prepare_shift()
1067 offset -= mp->m_sb.sb_blocksize; in xfs_prepare_shift()
1073 error = xfs_flush_unmap_range(ip, offset, XFS_ISIZE(ip)); in xfs_prepare_shift()
1082 if (xfs_inode_has_cow_data(ip)) { in xfs_prepare_shift()
1083 error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF, in xfs_prepare_shift()
1095 * The first thing we do is to free data blocks in the specified range
1106 struct xfs_inode *ip, in xfs_collapse_file_space() argument
1110 struct xfs_mount *mp = ip->i_mount; in xfs_collapse_file_space()
1117 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_collapse_file_space()
1118 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_collapse_file_space()
1120 trace_xfs_collapse_file_space(ip); in xfs_collapse_file_space()
1122 error = xfs_free_file_space(ip, offset, len); in xfs_collapse_file_space()
1126 error = xfs_prepare_shift(ip, offset); in xfs_collapse_file_space()
1130 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_collapse_file_space()
1134 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1135 xfs_trans_ijoin(tp, ip, 0); in xfs_collapse_file_space()
1138 error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb, in xfs_collapse_file_space()
1152 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1157 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1175 struct xfs_inode *ip, in xfs_insert_file_space() argument
1179 struct xfs_mount *mp = ip->i_mount; in xfs_insert_file_space()
1187 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_insert_file_space()
1188 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_insert_file_space()
1190 trace_xfs_insert_file_space(ip); in xfs_insert_file_space()
1192 error = xfs_bmap_can_insert_extents(ip, stop_fsb, shift_fsb); in xfs_insert_file_space()
1196 error = xfs_prepare_shift(ip, offset); in xfs_insert_file_space()
1200 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, in xfs_insert_file_space()
1205 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1206 xfs_trans_ijoin(tp, ip, 0); in xfs_insert_file_space()
1208 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_insert_file_space()
1210 if (error == -EFBIG) in xfs_insert_file_space()
1211 error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT); in xfs_insert_file_space()
1220 error = xfs_bmap_split_extent(tp, ip, stop_fsb); in xfs_insert_file_space()
1229 error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb, in xfs_insert_file_space()
1236 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1241 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1267 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents_check_format() argument
1270 struct xfs_ifork *ifp = &ip->i_df; in xfs_swap_extents_check_format()
1271 struct xfs_ifork *tifp = &tip->i_df; in xfs_swap_extents_check_format()
1274 if (XFS_IS_QUOTA_ON(ip->i_mount) && in xfs_swap_extents_check_format()
1275 (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) || in xfs_swap_extents_check_format()
1276 !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) || in xfs_swap_extents_check_format()
1277 ip->i_projid != tip->i_projid)) in xfs_swap_extents_check_format()
1278 return -EINVAL; in xfs_swap_extents_check_format()
1281 if (ifp->if_format == XFS_DINODE_FMT_LOCAL || in xfs_swap_extents_check_format()
1282 tifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_swap_extents_check_format()
1283 return -EINVAL; in xfs_swap_extents_check_format()
1289 if (ifp->if_nextents < tifp->if_nextents) in xfs_swap_extents_check_format()
1290 return -EINVAL; in xfs_swap_extents_check_format()
1296 if (xfs_has_rmapbt(ip->i_mount)) in xfs_swap_extents_check_format()
1304 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1305 tifp->if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extents_check_format()
1306 return -EINVAL; in xfs_swap_extents_check_format()
1309 if (tifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1310 tifp->if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1311 return -EINVAL; in xfs_swap_extents_check_format()
1314 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1315 ifp->if_nextents > XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1316 return -EINVAL; in xfs_swap_extents_check_format()
1323 * Note that we have to be careful to allow btree->extent conversions in xfs_swap_extents_check_format()
1327 if (tifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1328 if (xfs_inode_has_attr_fork(ip) && in xfs_swap_extents_check_format()
1329 XFS_BMAP_BMDR_SPACE(tifp->if_broot) > xfs_inode_fork_boff(ip)) in xfs_swap_extents_check_format()
1330 return -EINVAL; in xfs_swap_extents_check_format()
1331 if (tifp->if_nextents <= XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1332 return -EINVAL; in xfs_swap_extents_check_format()
1335 /* Reciprocal target->temp btree format checks */ in xfs_swap_extents_check_format()
1336 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1338 XFS_BMAP_BMDR_SPACE(ip->i_df.if_broot) > xfs_inode_fork_boff(tip)) in xfs_swap_extents_check_format()
1339 return -EINVAL; in xfs_swap_extents_check_format()
1340 if (ifp->if_nextents <= XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1341 return -EINVAL; in xfs_swap_extents_check_format()
1349 struct xfs_inode *ip) in xfs_swap_extent_flush() argument
1353 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_swap_extent_flush()
1356 truncate_pagecache_range(VFS_I(ip), 0, -1); in xfs_swap_extent_flush()
1359 if (VFS_I(ip)->i_mapping->nrpages) in xfs_swap_extent_flush()
1360 return -EINVAL; in xfs_swap_extent_flush()
1370 struct xfs_inode *ip, in xfs_swap_extent_rmap() argument
1387 * If the source file has shared blocks, we must flag the donor in xfs_swap_extent_rmap()
1388 * file as having shared blocks so that we get the shared-block in xfs_swap_extent_rmap()
1392 tip_flags2 = tip->i_diflags2; in xfs_swap_extent_rmap()
1393 if (ip->i_diflags2 & XFS_DIFLAG2_REFLINK) in xfs_swap_extent_rmap()
1394 tip->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_swap_extent_rmap()
1397 end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); in xfs_swap_extent_rmap()
1398 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); in xfs_swap_extent_rmap()
1413 /* Unmap the old blocks in the source file. */ in xfs_swap_extent_rmap()
1415 ASSERT(tp->t_highest_agno == NULLAGNUMBER); in xfs_swap_extent_rmap()
1420 error = xfs_bmapi_read(ip, tirec.br_startoff, in xfs_swap_extent_rmap()
1427 trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); in xfs_swap_extent_rmap()
1437 error = xfs_iext_count_may_overflow(ip, in xfs_swap_extent_rmap()
1440 if (error == -EFBIG) in xfs_swap_extent_rmap()
1441 error = xfs_iext_count_upgrade(tp, ip, in xfs_swap_extent_rmap()
1451 if (error == -EFBIG) in xfs_swap_extent_rmap()
1452 error = xfs_iext_count_upgrade(tp, ip, in xfs_swap_extent_rmap()
1462 xfs_bmap_unmap_extent(tp, ip, &irec); in xfs_swap_extent_rmap()
1464 /* Map the donor file's blocks into the source file. */ in xfs_swap_extent_rmap()
1465 xfs_bmap_map_extent(tp, ip, &uirec); in xfs_swap_extent_rmap()
1467 /* Map the source file's blocks into the donor file. */ in xfs_swap_extent_rmap()
1479 tirec.br_blockcount -= rlen; in xfs_swap_extent_rmap()
1483 count_fsb -= ilen; in xfs_swap_extent_rmap()
1487 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1491 trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); in xfs_swap_extent_rmap()
1492 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1500 struct xfs_inode *ip, in xfs_swap_extent_forks() argument
1512 * Count the number of extended attribute blocks in xfs_swap_extent_forks()
1514 if (xfs_inode_has_attr_fork(ip) && ip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1515 ip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1516 error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk, in xfs_swap_extent_forks()
1521 if (xfs_inode_has_attr_fork(tip) && tip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1522 tip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1531 * block headers. We can't start changing the bmbt blocks until the in xfs_swap_extent_forks()
1536 if (xfs_has_v3inodes(ip->i_mount)) { in xfs_swap_extent_forks()
1537 if (ip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1539 if (tip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1546 swap(ip->i_df, tip->i_df); in xfs_swap_extent_forks()
1549 * Fix the on-disk inode values in xfs_swap_extent_forks()
1551 tmp = (uint64_t)ip->i_nblocks; in xfs_swap_extent_forks()
1552 ip->i_nblocks = tip->i_nblocks - taforkblks + aforkblks; in xfs_swap_extent_forks()
1553 tip->i_nblocks = tmp + taforkblks - aforkblks; in xfs_swap_extent_forks()
1559 * number of delalloc blocks the data fork in the source inode is in xfs_swap_extent_forks()
1564 ASSERT(tip->i_delayed_blks == 0); in xfs_swap_extent_forks()
1565 tip->i_delayed_blks = ip->i_delayed_blks; in xfs_swap_extent_forks()
1566 ip->i_delayed_blks = 0; in xfs_swap_extent_forks()
1568 switch (ip->i_df.if_format) { in xfs_swap_extent_forks()
1573 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1579 switch (tip->i_df.if_format) { in xfs_swap_extent_forks()
1585 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1594 * Fix up the owners of the bmbt blocks to refer to the current inode. The
1597 * physically logged as a fallback and the scan returns -EAGAIN. We must roll
1604 struct xfs_inode *ip, in xfs_swap_change_owner() argument
1611 error = xfs_bmbt_change_owner(tp, ip, XFS_DATA_FORK, ip->i_ino, in xfs_swap_change_owner()
1614 if (error != -EAGAIN) in xfs_swap_change_owner()
1626 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_change_owner()
1628 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_swap_change_owner()
1637 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents() argument
1641 struct xfs_mount *mp = ip->i_mount; in xfs_swap_extents()
1643 struct xfs_bstat *sbp = &sxp->sx_stat; in xfs_swap_extents()
1657 lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()
1658 filemap_invalidate_lock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1659 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1662 if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { in xfs_swap_extents()
1663 error = -EINVAL; in xfs_swap_extents()
1667 /* Verify both files are either real-time or non-realtime */ in xfs_swap_extents()
1668 if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { in xfs_swap_extents()
1669 error = -EINVAL; in xfs_swap_extents()
1673 error = xfs_qm_dqattach(ip); in xfs_swap_extents()
1681 error = xfs_swap_extent_flush(ip); in xfs_swap_extents()
1701 uint32_t ipnext = ip->i_df.if_nextents; in xfs_swap_extents()
1702 uint32_t tipnext = tip->i_df.if_nextents; in xfs_swap_extents()
1716 * prematurely and cause shutdown. Return freed blocks to the in xfs_swap_extents()
1721 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, flags, in xfs_swap_extents()
1730 xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1731 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_extents()
1736 if (sxp->sx_offset != 0 || in xfs_swap_extents()
1737 sxp->sx_length != ip->i_disk_size || in xfs_swap_extents()
1738 sxp->sx_length != tip->i_disk_size) { in xfs_swap_extents()
1739 error = -EFAULT; in xfs_swap_extents()
1743 trace_xfs_swap_extent_before(ip, 0); in xfs_swap_extents()
1747 error = xfs_swap_extents_check_format(ip, tip); in xfs_swap_extents()
1751 __func__, ip->i_ino); in xfs_swap_extents()
1762 ctime = inode_get_ctime(VFS_I(ip)); in xfs_swap_extents()
1763 if ((sbp->bs_ctime.tv_sec != ctime.tv_sec) || in xfs_swap_extents()
1764 (sbp->bs_ctime.tv_nsec != ctime.tv_nsec) || in xfs_swap_extents()
1765 (sbp->bs_mtime.tv_sec != VFS_I(ip)->i_mtime.tv_sec) || in xfs_swap_extents()
1766 (sbp->bs_mtime.tv_nsec != VFS_I(ip)->i_mtime.tv_nsec)) { in xfs_swap_extents()
1767 error = -EBUSY; in xfs_swap_extents()
1772 * Note the trickiness in setting the log flags - we set the owner log in xfs_swap_extents()
1776 * not the pre-swapped inodes. in xfs_swap_extents()
1782 error = xfs_swap_extent_rmap(&tp, ip, tip); in xfs_swap_extents()
1784 error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, in xfs_swap_extents()
1790 if ((ip->i_diflags2 & XFS_DIFLAG2_REFLINK) ^ in xfs_swap_extents()
1791 (tip->i_diflags2 & XFS_DIFLAG2_REFLINK)) { in xfs_swap_extents()
1792 f = ip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1793 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1794 ip->i_diflags2 |= tip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1795 tip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1796 tip->i_diflags2 |= f & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1801 ASSERT(!ip->i_cowfp || in xfs_swap_extents()
1802 ip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1803 ASSERT(!tip->i_cowfp || in xfs_swap_extents()
1804 tip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1806 swap(ip->i_cowfp, tip->i_cowfp); in xfs_swap_extents()
1808 if (ip->i_cowfp && ip->i_cowfp->if_bytes) in xfs_swap_extents()
1809 xfs_inode_set_cowblocks_tag(ip); in xfs_swap_extents()
1811 xfs_inode_clear_cowblocks_tag(ip); in xfs_swap_extents()
1812 if (tip->i_cowfp && tip->i_cowfp->if_bytes) in xfs_swap_extents()
1818 xfs_trans_log_inode(tp, ip, src_log_flags); in xfs_swap_extents()
1823 * have inode number owner values in the bmbt blocks that still refer to in xfs_swap_extents()
1828 error = xfs_swap_change_owner(&tp, ip, tip); in xfs_swap_extents()
1833 error = xfs_swap_change_owner(&tp, tip, ip); in xfs_swap_extents()
1847 trace_xfs_swap_extent_after(ip, 0); in xfs_swap_extents()
1851 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1854 filemap_invalidate_unlock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1855 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1856 unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()