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()
324 if (got->br_startoff < XFS_B_TO_FSB(ip->i_mount, XFS_ISIZE(ip))) in xfs_getbmap_report_one()
325 ASSERT((bmv->bmv_iflags & BMV_IF_DELALLOC) != 0); in xfs_getbmap_report_one()
327 p->bmv_oflags |= BMV_OF_DELALLOC; in xfs_getbmap_report_one()
328 p->bmv_block = -2; in xfs_getbmap_report_one()
330 p->bmv_block = xfs_fsb_to_db(ip, got->br_startblock); in xfs_getbmap_report_one()
333 if (got->br_state == XFS_EXT_UNWRITTEN && in xfs_getbmap_report_one()
334 (bmv->bmv_iflags & BMV_IF_PREALLOC)) in xfs_getbmap_report_one()
335 p->bmv_oflags |= BMV_OF_PREALLOC; in xfs_getbmap_report_one()
338 p->bmv_oflags |= BMV_OF_SHARED; in xfs_getbmap_report_one()
340 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, got->br_startoff); in xfs_getbmap_report_one()
341 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, got->br_blockcount); in xfs_getbmap_report_one()
343 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_one()
344 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_one()
345 bmv->bmv_entries++; in xfs_getbmap_report_one()
351 struct xfs_inode *ip, in xfs_getbmap_report_hole() argument
358 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_hole()
360 if (bmv->bmv_iflags & BMV_IF_NO_HOLES) in xfs_getbmap_report_hole()
363 p->bmv_block = -1; in xfs_getbmap_report_hole()
364 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, bno); in xfs_getbmap_report_hole()
365 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, end - bno); in xfs_getbmap_report_hole()
367 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_hole()
368 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_hole()
369 bmv->bmv_entries++; in xfs_getbmap_report_hole()
376 return bmv->bmv_length == 0 || bmv->bmv_entries >= bmv->bmv_count - 1; in xfs_getbmap_full()
384 xfs_fileoff_t end = rec->br_startoff + rec->br_blockcount; in xfs_getbmap_next_rec()
389 rec->br_startoff += rec->br_blockcount; in xfs_getbmap_next_rec()
390 if (!isnullstartblock(rec->br_startblock) && in xfs_getbmap_next_rec()
391 rec->br_startblock != DELAYSTARTBLOCK) in xfs_getbmap_next_rec()
392 rec->br_startblock += rec->br_blockcount; in xfs_getbmap_next_rec()
393 rec->br_blockcount = total_end - end; in xfs_getbmap_next_rec()
400 * are mapped, until the passed-in bmv->bmv_count slots have
401 * been filled, or until the formatter short-circuits the loop,
402 * if it is tracking filled-in extents on its own.
406 struct xfs_inode *ip, in xfs_getbmap() argument
410 struct xfs_mount *mp = ip->i_mount; in xfs_getbmap()
411 int iflags = bmv->bmv_iflags; in xfs_getbmap()
420 if (bmv->bmv_iflags & ~BMV_IF_VALID) in xfs_getbmap()
421 return -EINVAL; in xfs_getbmap()
425 return -EINVAL; in xfs_getbmap()
428 return -EINVAL; in xfs_getbmap()
430 if (bmv->bmv_length < -1) in xfs_getbmap()
431 return -EINVAL; in xfs_getbmap()
432 bmv->bmv_entries = 0; in xfs_getbmap()
433 if (bmv->bmv_length == 0) in xfs_getbmap()
443 xfs_ilock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
446 lock = xfs_ilock_attr_map_shared(ip); in xfs_getbmap()
447 if (!xfs_inode_has_attr_fork(ip)) in xfs_getbmap()
454 xfs_ilock(ip, lock); in xfs_getbmap()
457 if (!xfs_ifork_ptr(ip, whichfork)) in xfs_getbmap()
460 if (xfs_get_cowextsz_hint(ip)) in xfs_getbmap()
461 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
463 max_len = XFS_ISIZE(ip); in xfs_getbmap()
467 (ip->i_delayed_blks || XFS_ISIZE(ip) > ip->i_disk_size)) { in xfs_getbmap()
468 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_getbmap()
474 * delalloc blocks on the inode beyond EOF due to in xfs_getbmap()
478 * ip->i_delayed_blks == 0. in xfs_getbmap()
482 if (xfs_get_extsz_hint(ip) || in xfs_getbmap()
483 (ip->i_diflags & in xfs_getbmap()
485 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
487 max_len = XFS_ISIZE(ip); in xfs_getbmap()
489 lock = xfs_ilock_data_map_shared(ip); in xfs_getbmap()
493 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_getbmap()
495 switch (ifp->if_format) { in xfs_getbmap()
503 error = -EINVAL; in xfs_getbmap()
507 if (bmv->bmv_length == -1) { in xfs_getbmap()
509 bmv->bmv_length = max(0LL, max_len - bmv->bmv_offset); in xfs_getbmap()
512 bmv_end = bmv->bmv_offset + bmv->bmv_length; in xfs_getbmap()
514 first_bno = bno = XFS_BB_TO_FSBT(mp, bmv->bmv_offset); in xfs_getbmap()
515 len = XFS_BB_TO_FSB(mp, bmv->bmv_length); in xfs_getbmap()
517 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_getbmap()
521 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_getbmap()
523 * Report a whole-file hole if the delalloc flag is set to in xfs_getbmap()
527 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
528 XFS_B_TO_FSB(mp, XFS_ISIZE(ip))); in xfs_getbmap()
540 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
554 error = xfs_getbmap_report_one(ip, bmv, out, bmv_end, in xfs_getbmap()
561 xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); in xfs_getbmap()
563 out[bmv->bmv_entries - 1].bmv_oflags |= BMV_OF_LAST; 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_ifork *ifp = &ip->i_df; in xfs_bmap_punch_delalloc_range()
604 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
605 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_bmap_punch_delalloc_range()
614 * previous extent on non-delalloc or extents outside the in xfs_bmap_punch_delalloc_range()
624 error = xfs_bmap_del_extent_delay(ip, XFS_DATA_FORK, &icur, in xfs_bmap_punch_delalloc_range()
631 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
637 * blocks. The 'force' parameter determines whether we should also consider
638 * regular files that are marked preallocated or append-only.
642 struct xfs_inode *ip, in xfs_can_free_eofblocks() argument
646 struct xfs_mount *mp = ip->i_mount; in xfs_can_free_eofblocks()
656 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL) || in xfs_can_free_eofblocks()
657 (VFS_I(ip)->i_state & I_FREEING)); in xfs_can_free_eofblocks()
660 if (!S_ISREG(VFS_I(ip)->i_mode)) in xfs_can_free_eofblocks()
664 * Zero sized files with no cached pages and delalloc blocks will not in xfs_can_free_eofblocks()
665 * have speculative prealloc/delalloc blocks to remove. in xfs_can_free_eofblocks()
667 if (VFS_I(ip)->i_size == 0 && in xfs_can_free_eofblocks()
668 VFS_I(ip)->i_mapping->nrpages == 0 && in xfs_can_free_eofblocks()
669 ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
673 if (xfs_need_iread_extents(&ip->i_df)) in xfs_can_free_eofblocks()
677 * Do not free real preallocated or append-only files unless the file in xfs_can_free_eofblocks()
678 * has delalloc blocks and we are forced to remove them. in xfs_can_free_eofblocks()
680 if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) in xfs_can_free_eofblocks()
681 if (!force || ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
685 * Do not try to free post-EOF blocks if EOF is beyond the end of the in xfs_can_free_eofblocks()
689 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); in xfs_can_free_eofblocks()
690 if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) in xfs_can_free_eofblocks()
691 end_fsb = roundup_64(end_fsb, mp->m_sb.sb_rextsize); in xfs_can_free_eofblocks()
692 last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); in xfs_can_free_eofblocks()
700 xfs_ilock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
701 error = xfs_bmapi_read(ip, end_fsb, last_fsb - end_fsb, &imap, &nimaps, in xfs_can_free_eofblocks()
703 xfs_iunlock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
709 * reservations, then we have post-EOF blocks to try to free. in xfs_can_free_eofblocks()
711 return imap.br_startblock != HOLESTARTBLOCK || ip->i_delayed_blks; in xfs_can_free_eofblocks()
715 * This is called to free any blocks beyond eof. The caller must hold
721 struct xfs_inode *ip) in xfs_free_eofblocks() argument
724 struct xfs_mount *mp = ip->i_mount; in xfs_free_eofblocks()
728 error = xfs_qm_dqattach(ip); in xfs_free_eofblocks()
733 inode_dio_wait(VFS_I(ip)); in xfs_free_eofblocks()
735 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); in xfs_free_eofblocks()
741 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
742 xfs_trans_ijoin(tp, ip, 0); in xfs_free_eofblocks()
745 * Do not update the on-disk file size. If we update the on-disk file in xfs_free_eofblocks()
750 error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, in xfs_free_eofblocks()
751 XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); in xfs_free_eofblocks()
759 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
769 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
775 struct xfs_inode *ip, in xfs_alloc_file_space() argument
779 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()
812 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()
885 allocated_fsb = imapp->br_blockcount; in xfs_alloc_file_space()
888 error = -ENOSPC; in xfs_alloc_file_space()
893 allocatesize_fsb -= allocated_fsb; in xfs_alloc_file_space()
900 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
906 struct xfs_inode *ip, in xfs_unmap_extent() argument
911 struct xfs_mount *mp = ip->i_mount; in xfs_unmap_extent()
916 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0, in xfs_unmap_extent()
921 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_unmap_extent()
923 if (error == -EFBIG) in xfs_unmap_extent()
924 error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT); in xfs_unmap_extent()
928 error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); in xfs_unmap_extent()
934 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
945 struct xfs_inode *ip, in xfs_flush_unmap_range() argument
949 struct xfs_mount *mp = ip->i_mount; in xfs_flush_unmap_range()
950 struct inode *inode = VFS_I(ip); in xfs_flush_unmap_range()
954 rounding = max_t(xfs_off_t, mp->m_sb.sb_blocksize, PAGE_SIZE); in xfs_flush_unmap_range()
956 end = round_up(offset + len, rounding) - 1; in xfs_flush_unmap_range()
958 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in xfs_flush_unmap_range()
967 struct xfs_inode *ip, in xfs_free_file_space() argument
971 struct xfs_mount *mp = ip->i_mount; in xfs_free_file_space()
976 trace_xfs_free_file_space(ip); in xfs_free_file_space()
978 error = xfs_qm_dqattach(ip); in xfs_free_file_space()
989 if (XFS_IS_REALTIME_INODE(ip) && mp->m_sb.sb_rextsize > 1) { in xfs_free_file_space()
991 mp->m_sb.sb_rextsize); in xfs_free_file_space()
993 mp->m_sb.sb_rextsize); in xfs_free_file_space()
1001 error = xfs_unmap_extent(ip, startoffset_fsb, in xfs_free_file_space()
1002 endoffset_fsb - startoffset_fsb, &done); in xfs_free_file_space()
1009 * Now that we've unmap all full blocks we'll have to zero out any in xfs_free_file_space()
1014 if (offset >= XFS_ISIZE(ip)) in xfs_free_file_space()
1016 if (offset + len > XFS_ISIZE(ip)) in xfs_free_file_space()
1017 len = XFS_ISIZE(ip) - offset; in xfs_free_file_space()
1018 error = xfs_zero_range(ip, offset, len, NULL); in xfs_free_file_space()
1024 * must make sure that the post-EOF area is also zeroed because the in xfs_free_file_space()
1028 if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { in xfs_free_file_space()
1029 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, in xfs_free_file_space()
1038 struct xfs_inode *ip, in xfs_prepare_shift() argument
1041 struct xfs_mount *mp = ip->i_mount; in xfs_prepare_shift()
1045 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation in xfs_prepare_shift()
1048 if (xfs_can_free_eofblocks(ip, true)) { in xfs_prepare_shift()
1049 error = xfs_free_eofblocks(ip); in xfs_prepare_shift()
1061 offset = round_down(offset, mp->m_sb.sb_blocksize); in xfs_prepare_shift()
1063 offset -= mp->m_sb.sb_blocksize; in xfs_prepare_shift()
1069 error = xfs_flush_unmap_range(ip, offset, XFS_ISIZE(ip)); in xfs_prepare_shift()
1078 if (xfs_inode_has_cow_data(ip)) { in xfs_prepare_shift()
1079 error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF, in xfs_prepare_shift()
1091 * The first thing we do is to free data blocks in the specified range
1102 struct xfs_inode *ip, in xfs_collapse_file_space() argument
1106 struct xfs_mount *mp = ip->i_mount; in xfs_collapse_file_space()
1113 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_collapse_file_space()
1114 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_collapse_file_space()
1116 trace_xfs_collapse_file_space(ip); in xfs_collapse_file_space()
1118 error = xfs_free_file_space(ip, offset, len); in xfs_collapse_file_space()
1122 error = xfs_prepare_shift(ip, offset); in xfs_collapse_file_space()
1126 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_collapse_file_space()
1130 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1131 xfs_trans_ijoin(tp, ip, 0); in xfs_collapse_file_space()
1134 error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb, in xfs_collapse_file_space()
1148 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1153 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1171 struct xfs_inode *ip, in xfs_insert_file_space() argument
1175 struct xfs_mount *mp = ip->i_mount; in xfs_insert_file_space()
1183 ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); in xfs_insert_file_space()
1184 ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); in xfs_insert_file_space()
1186 trace_xfs_insert_file_space(ip); in xfs_insert_file_space()
1188 error = xfs_bmap_can_insert_extents(ip, stop_fsb, shift_fsb); in xfs_insert_file_space()
1192 error = xfs_prepare_shift(ip, offset); in xfs_insert_file_space()
1196 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, in xfs_insert_file_space()
1201 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1202 xfs_trans_ijoin(tp, ip, 0); in xfs_insert_file_space()
1204 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_insert_file_space()
1206 if (error == -EFBIG) in xfs_insert_file_space()
1207 error = xfs_iext_count_upgrade(tp, ip, XFS_IEXT_PUNCH_HOLE_CNT); in xfs_insert_file_space()
1216 error = xfs_bmap_split_extent(tp, ip, stop_fsb); in xfs_insert_file_space()
1225 error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb, in xfs_insert_file_space()
1232 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1237 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1263 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents_check_format() argument
1266 struct xfs_ifork *ifp = &ip->i_df; in xfs_swap_extents_check_format()
1267 struct xfs_ifork *tifp = &tip->i_df; in xfs_swap_extents_check_format()
1270 if (XFS_IS_QUOTA_ON(ip->i_mount) && in xfs_swap_extents_check_format()
1271 (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) || in xfs_swap_extents_check_format()
1272 !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) || in xfs_swap_extents_check_format()
1273 ip->i_projid != tip->i_projid)) in xfs_swap_extents_check_format()
1274 return -EINVAL; in xfs_swap_extents_check_format()
1277 if (ifp->if_format == XFS_DINODE_FMT_LOCAL || in xfs_swap_extents_check_format()
1278 tifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_swap_extents_check_format()
1279 return -EINVAL; in xfs_swap_extents_check_format()
1285 if (ifp->if_nextents < tifp->if_nextents) in xfs_swap_extents_check_format()
1286 return -EINVAL; in xfs_swap_extents_check_format()
1292 if (xfs_has_rmapbt(ip->i_mount)) in xfs_swap_extents_check_format()
1300 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1301 tifp->if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extents_check_format()
1302 return -EINVAL; in xfs_swap_extents_check_format()
1305 if (tifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1306 tifp->if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1307 return -EINVAL; in xfs_swap_extents_check_format()
1310 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1311 ifp->if_nextents > XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1312 return -EINVAL; in xfs_swap_extents_check_format()
1319 * Note that we have to be careful to allow btree->extent conversions in xfs_swap_extents_check_format()
1323 if (tifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1324 if (xfs_inode_has_attr_fork(ip) && in xfs_swap_extents_check_format()
1325 XFS_BMAP_BMDR_SPACE(tifp->if_broot) > xfs_inode_fork_boff(ip)) in xfs_swap_extents_check_format()
1326 return -EINVAL; in xfs_swap_extents_check_format()
1327 if (tifp->if_nextents <= XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1328 return -EINVAL; in xfs_swap_extents_check_format()
1331 /* Reciprocal target->temp btree format checks */ in xfs_swap_extents_check_format()
1332 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1334 XFS_BMAP_BMDR_SPACE(ip->i_df.if_broot) > xfs_inode_fork_boff(tip)) in xfs_swap_extents_check_format()
1335 return -EINVAL; in xfs_swap_extents_check_format()
1336 if (ifp->if_nextents <= XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1337 return -EINVAL; in xfs_swap_extents_check_format()
1345 struct xfs_inode *ip) in xfs_swap_extent_flush() argument
1349 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_swap_extent_flush()
1352 truncate_pagecache_range(VFS_I(ip), 0, -1); in xfs_swap_extent_flush()
1355 if (VFS_I(ip)->i_mapping->nrpages) in xfs_swap_extent_flush()
1356 return -EINVAL; in xfs_swap_extent_flush()
1366 struct xfs_inode *ip, in xfs_swap_extent_rmap() argument
1383 * If the source file has shared blocks, we must flag the donor in xfs_swap_extent_rmap()
1384 * file as having shared blocks so that we get the shared-block in xfs_swap_extent_rmap()
1388 tip_flags2 = tip->i_diflags2; in xfs_swap_extent_rmap()
1389 if (ip->i_diflags2 & XFS_DIFLAG2_REFLINK) in xfs_swap_extent_rmap()
1390 tip->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_swap_extent_rmap()
1393 end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); in xfs_swap_extent_rmap()
1394 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); in xfs_swap_extent_rmap()
1409 /* Unmap the old blocks in the source file. */ in xfs_swap_extent_rmap()
1411 ASSERT(tp->t_firstblock == NULLFSBLOCK); in xfs_swap_extent_rmap()
1416 error = xfs_bmapi_read(ip, tirec.br_startoff, in xfs_swap_extent_rmap()
1423 trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); in xfs_swap_extent_rmap()
1433 error = xfs_iext_count_may_overflow(ip, in xfs_swap_extent_rmap()
1436 if (error == -EFBIG) in xfs_swap_extent_rmap()
1437 error = xfs_iext_count_upgrade(tp, ip, in xfs_swap_extent_rmap()
1447 if (error == -EFBIG) in xfs_swap_extent_rmap()
1448 error = xfs_iext_count_upgrade(tp, ip, in xfs_swap_extent_rmap()
1458 xfs_bmap_unmap_extent(tp, ip, &irec); in xfs_swap_extent_rmap()
1460 /* Map the donor file's blocks into the source file. */ in xfs_swap_extent_rmap()
1461 xfs_bmap_map_extent(tp, ip, &uirec); in xfs_swap_extent_rmap()
1463 /* Map the source file's blocks into the donor file. */ in xfs_swap_extent_rmap()
1475 tirec.br_blockcount -= rlen; in xfs_swap_extent_rmap()
1479 count_fsb -= ilen; in xfs_swap_extent_rmap()
1483 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1487 trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); in xfs_swap_extent_rmap()
1488 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1496 struct xfs_inode *ip, in xfs_swap_extent_forks() argument
1508 * Count the number of extended attribute blocks in xfs_swap_extent_forks()
1510 if (xfs_inode_has_attr_fork(ip) && ip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1511 ip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1512 error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk, in xfs_swap_extent_forks()
1517 if (xfs_inode_has_attr_fork(tip) && tip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1518 tip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1527 * block headers. We can't start changing the bmbt blocks until the in xfs_swap_extent_forks()
1532 if (xfs_has_v3inodes(ip->i_mount)) { in xfs_swap_extent_forks()
1533 if (ip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1535 if (tip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1542 swap(ip->i_df, tip->i_df); in xfs_swap_extent_forks()
1545 * Fix the on-disk inode values in xfs_swap_extent_forks()
1547 tmp = (uint64_t)ip->i_nblocks; in xfs_swap_extent_forks()
1548 ip->i_nblocks = tip->i_nblocks - taforkblks + aforkblks; in xfs_swap_extent_forks()
1549 tip->i_nblocks = tmp + taforkblks - aforkblks; in xfs_swap_extent_forks()
1555 * number of delalloc blocks the data fork in the source inode is in xfs_swap_extent_forks()
1560 ASSERT(tip->i_delayed_blks == 0); in xfs_swap_extent_forks()
1561 tip->i_delayed_blks = ip->i_delayed_blks; in xfs_swap_extent_forks()
1562 ip->i_delayed_blks = 0; in xfs_swap_extent_forks()
1564 switch (ip->i_df.if_format) { in xfs_swap_extent_forks()
1569 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1575 switch (tip->i_df.if_format) { in xfs_swap_extent_forks()
1581 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1590 * Fix up the owners of the bmbt blocks to refer to the current inode. The
1593 * physically logged as a fallback and the scan returns -EAGAIN. We must roll
1600 struct xfs_inode *ip, in xfs_swap_change_owner() argument
1607 error = xfs_bmbt_change_owner(tp, ip, XFS_DATA_FORK, ip->i_ino, in xfs_swap_change_owner()
1610 if (error != -EAGAIN) in xfs_swap_change_owner()
1622 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_change_owner()
1624 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_swap_change_owner()
1633 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents() argument
1637 struct xfs_mount *mp = ip->i_mount; in xfs_swap_extents()
1639 struct xfs_bstat *sbp = &sxp->sx_stat; in xfs_swap_extents()
1652 lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()
1653 filemap_invalidate_lock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1654 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1657 if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { in xfs_swap_extents()
1658 error = -EINVAL; in xfs_swap_extents()
1662 /* Verify both files are either real-time or non-realtime */ in xfs_swap_extents()
1663 if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { in xfs_swap_extents()
1664 error = -EINVAL; in xfs_swap_extents()
1668 error = xfs_qm_dqattach(ip); in xfs_swap_extents()
1676 error = xfs_swap_extent_flush(ip); in xfs_swap_extents()
1696 uint32_t ipnext = ip->i_df.if_nextents; in xfs_swap_extents()
1697 uint32_t tipnext = tip->i_df.if_nextents; in xfs_swap_extents()
1711 * prematurely and cause shutdown. Return freed blocks to the in xfs_swap_extents()
1716 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, flags, in xfs_swap_extents()
1725 xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1726 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_extents()
1731 if (sxp->sx_offset != 0 || in xfs_swap_extents()
1732 sxp->sx_length != ip->i_disk_size || in xfs_swap_extents()
1733 sxp->sx_length != tip->i_disk_size) { in xfs_swap_extents()
1734 error = -EFAULT; in xfs_swap_extents()
1738 trace_xfs_swap_extent_before(ip, 0); in xfs_swap_extents()
1742 error = xfs_swap_extents_check_format(ip, tip); in xfs_swap_extents()
1746 __func__, ip->i_ino); in xfs_swap_extents()
1757 if ((sbp->bs_ctime.tv_sec != VFS_I(ip)->i_ctime.tv_sec) || in xfs_swap_extents()
1758 (sbp->bs_ctime.tv_nsec != VFS_I(ip)->i_ctime.tv_nsec) || in xfs_swap_extents()
1759 (sbp->bs_mtime.tv_sec != VFS_I(ip)->i_mtime.tv_sec) || in xfs_swap_extents()
1760 (sbp->bs_mtime.tv_nsec != VFS_I(ip)->i_mtime.tv_nsec)) { in xfs_swap_extents()
1761 error = -EBUSY; in xfs_swap_extents()
1766 * Note the trickiness in setting the log flags - we set the owner log in xfs_swap_extents()
1770 * not the pre-swapped inodes. in xfs_swap_extents()
1776 error = xfs_swap_extent_rmap(&tp, ip, tip); in xfs_swap_extents()
1778 error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, in xfs_swap_extents()
1784 if ((ip->i_diflags2 & XFS_DIFLAG2_REFLINK) ^ in xfs_swap_extents()
1785 (tip->i_diflags2 & XFS_DIFLAG2_REFLINK)) { in xfs_swap_extents()
1786 f = ip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1787 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1788 ip->i_diflags2 |= tip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1789 tip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1790 tip->i_diflags2 |= f & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1795 ASSERT(!ip->i_cowfp || in xfs_swap_extents()
1796 ip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1797 ASSERT(!tip->i_cowfp || in xfs_swap_extents()
1798 tip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1800 swap(ip->i_cowfp, tip->i_cowfp); in xfs_swap_extents()
1802 if (ip->i_cowfp && ip->i_cowfp->if_bytes) in xfs_swap_extents()
1803 xfs_inode_set_cowblocks_tag(ip); in xfs_swap_extents()
1805 xfs_inode_clear_cowblocks_tag(ip); in xfs_swap_extents()
1806 if (tip->i_cowfp && tip->i_cowfp->if_bytes) in xfs_swap_extents()
1812 xfs_trans_log_inode(tp, ip, src_log_flags); in xfs_swap_extents()
1817 * have inode number owner values in the bmbt blocks that still refer to in xfs_swap_extents()
1822 error = xfs_swap_change_owner(&tp, ip, tip); in xfs_swap_extents()
1827 error = xfs_swap_change_owner(&tp, tip, ip); in xfs_swap_extents()
1841 trace_xfs_swap_extent_after(ip, 0); in xfs_swap_extents()
1845 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1848 filemap_invalidate_unlock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1849 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1850 unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()