Lines Matching +full:ip +full:- +full:blocks

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
42 xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb) in xfs_fsb_to_db() argument
44 if (XFS_IS_REALTIME_INODE(ip)) in xfs_fsb_to_db()
45 return xfs_rtb_to_daddr(ip->i_mount, fsb); in xfs_fsb_to_db()
46 return XFS_FSB_TO_DADDR(ip->i_mount, fsb); in xfs_fsb_to_db()
54 struct xfs_inode *ip, in xfs_zero_extent() argument
58 return blkdev_issue_zeroout(xfs_inode_buftarg(ip)->bt_bdev, in xfs_zero_extent()
59 xfs_fsb_to_db(ip, start_fsb), in xfs_zero_extent()
60 XFS_FSB_TO_BB(ip->i_mount, count_fsb), in xfs_zero_extent()
69 * Count leaf blocks given a range of extent records. Delayed allocation
98 struct xfs_inode *ip, in xfs_bmap_count_blocks() argument
103 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_count_blocks()
104 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_count_blocks()
115 switch (ifp->if_format) { in xfs_bmap_count_blocks()
117 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_count_blocks()
121 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_count_blocks()
130 * only interested in allocated disk blocks. in xfs_bmap_count_blocks()
132 *count += btblocks - 1; in xfs_bmap_count_blocks()
145 struct xfs_inode *ip, in xfs_getbmap_report_one() argument
151 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_one()
155 error = xfs_reflink_trim_around_shared(ip, got, &shared); in xfs_getbmap_report_one()
159 if (isnullstartblock(got->br_startblock) || in xfs_getbmap_report_one()
160 got->br_startblock == DELAYSTARTBLOCK) { in xfs_getbmap_report_one()
162 * Take the flush completion as being a point-in-time snapshot in xfs_getbmap_report_one()
167 if (!(bmv->bmv_iflags & BMV_IF_DELALLOC)) in xfs_getbmap_report_one()
170 p->bmv_oflags |= BMV_OF_DELALLOC; in xfs_getbmap_report_one()
171 p->bmv_block = -2; in xfs_getbmap_report_one()
173 p->bmv_block = xfs_fsb_to_db(ip, got->br_startblock); in xfs_getbmap_report_one()
176 if (got->br_state == XFS_EXT_UNWRITTEN && in xfs_getbmap_report_one()
177 (bmv->bmv_iflags & BMV_IF_PREALLOC)) in xfs_getbmap_report_one()
178 p->bmv_oflags |= BMV_OF_PREALLOC; in xfs_getbmap_report_one()
181 p->bmv_oflags |= BMV_OF_SHARED; in xfs_getbmap_report_one()
183 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, got->br_startoff); in xfs_getbmap_report_one()
184 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, got->br_blockcount); in xfs_getbmap_report_one()
186 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_one()
187 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_one()
188 bmv->bmv_entries++; in xfs_getbmap_report_one()
194 struct xfs_inode *ip, in xfs_getbmap_report_hole() argument
201 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_hole()
203 if (bmv->bmv_iflags & BMV_IF_NO_HOLES) in xfs_getbmap_report_hole()
206 p->bmv_block = -1; in xfs_getbmap_report_hole()
207 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, bno); in xfs_getbmap_report_hole()
208 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, end - bno); in xfs_getbmap_report_hole()
210 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_hole()
211 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_hole()
212 bmv->bmv_entries++; in xfs_getbmap_report_hole()
219 return bmv->bmv_length == 0 || bmv->bmv_entries >= bmv->bmv_count - 1; in xfs_getbmap_full()
227 xfs_fileoff_t end = rec->br_startoff + rec->br_blockcount; in xfs_getbmap_next_rec()
232 rec->br_startoff += rec->br_blockcount; in xfs_getbmap_next_rec()
233 if (!isnullstartblock(rec->br_startblock) && in xfs_getbmap_next_rec()
234 rec->br_startblock != DELAYSTARTBLOCK) in xfs_getbmap_next_rec()
235 rec->br_startblock += rec->br_blockcount; in xfs_getbmap_next_rec()
236 rec->br_blockcount = total_end - end; in xfs_getbmap_next_rec()
243 * are mapped, until the passed-in bmv->bmv_count slots have
244 * been filled, or until the formatter short-circuits the loop,
245 * if it is tracking filled-in extents on its own.
249 struct xfs_inode *ip, in xfs_getbmap() argument
253 struct xfs_mount *mp = ip->i_mount; in xfs_getbmap()
254 int iflags = bmv->bmv_iflags; in xfs_getbmap()
263 if (bmv->bmv_iflags & ~BMV_IF_VALID) in xfs_getbmap()
264 return -EINVAL; in xfs_getbmap()
268 return -EINVAL; in xfs_getbmap()
271 return -EINVAL; in xfs_getbmap()
273 if (bmv->bmv_length < -1) in xfs_getbmap()
274 return -EINVAL; in xfs_getbmap()
275 bmv->bmv_entries = 0; in xfs_getbmap()
276 if (bmv->bmv_length == 0) in xfs_getbmap()
286 xfs_ilock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
289 lock = xfs_ilock_attr_map_shared(ip); in xfs_getbmap()
290 if (!xfs_inode_has_attr_fork(ip)) in xfs_getbmap()
297 xfs_ilock(ip, lock); in xfs_getbmap()
300 if (!xfs_ifork_ptr(ip, whichfork)) in xfs_getbmap()
303 if (xfs_get_cowextsz_hint(ip)) in xfs_getbmap()
304 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
306 max_len = XFS_ISIZE(ip); in xfs_getbmap()
310 (ip->i_delayed_blks || XFS_ISIZE(ip) > ip->i_disk_size)) { in xfs_getbmap()
311 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_getbmap()
317 * delalloc blocks on the inode beyond EOF due to in xfs_getbmap()
321 * ip->i_delayed_blks == 0. in xfs_getbmap()
325 if (xfs_get_extsz_hint(ip) || in xfs_getbmap()
326 (ip->i_diflags & XFS_DIFLAG_PREALLOC)) in xfs_getbmap()
327 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
329 max_len = XFS_ISIZE(ip); in xfs_getbmap()
331 lock = xfs_ilock_data_map_shared(ip); in xfs_getbmap()
335 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_getbmap()
337 switch (ifp->if_format) { in xfs_getbmap()
345 error = -EINVAL; in xfs_getbmap()
349 if (bmv->bmv_length == -1) { in xfs_getbmap()
351 bmv->bmv_length = max(0LL, max_len - bmv->bmv_offset); in xfs_getbmap()
354 bmv_end = bmv->bmv_offset + bmv->bmv_length; in xfs_getbmap()
356 first_bno = bno = XFS_BB_TO_FSBT(mp, bmv->bmv_offset); in xfs_getbmap()
357 len = XFS_BB_TO_FSB(mp, bmv->bmv_length); in xfs_getbmap()
359 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_getbmap()
363 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_getbmap()
365 * Report a whole-file hole if the delalloc flag is set to in xfs_getbmap()
369 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
370 XFS_B_TO_FSB(mp, XFS_ISIZE(ip))); in xfs_getbmap()
382 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
396 error = xfs_getbmap_report_one(ip, bmv, out, bmv_end, in xfs_getbmap()
403 xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); in xfs_getbmap()
405 if (bmv->bmv_entries > 0) in xfs_getbmap()
406 out[bmv->bmv_entries - 1].bmv_oflags |= in xfs_getbmap()
411 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, in xfs_getbmap()
422 xfs_iunlock(ip, lock); in xfs_getbmap()
424 xfs_iunlock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
429 * Dead simple method of punching delalyed allocation blocks from a range in
430 * the inode. This will always punch out both the start and end blocks, even
432 * ensure that partial blocks are not passed in.
436 struct xfs_inode *ip, in xfs_bmap_punch_delalloc_range() argument
441 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_punch_delalloc_range()
442 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_punch_delalloc_range()
450 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
451 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_bmap_punch_delalloc_range()
456 xfs_trim_extent(&del, start_fsb, end_fsb - start_fsb); in xfs_bmap_punch_delalloc_range()
460 * previous extent on non-delalloc or extents outside the in xfs_bmap_punch_delalloc_range()
470 xfs_bmap_del_extent_delay(ip, whichfork, &icur, &got, &del); in xfs_bmap_punch_delalloc_range()
475 if (whichfork == XFS_COW_FORK && !ifp->if_bytes) in xfs_bmap_punch_delalloc_range()
476 xfs_inode_clear_cowblocks_tag(ip); in xfs_bmap_punch_delalloc_range()
479 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
484 * blocks.
488 struct xfs_inode *ip) in xfs_can_free_eofblocks() argument
490 struct xfs_mount *mp = ip->i_mount; in xfs_can_free_eofblocks()
501 if (!(VFS_I(ip)->i_state & I_FREEING)) in xfs_can_free_eofblocks()
502 xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL); in xfs_can_free_eofblocks()
505 if (!S_ISREG(VFS_I(ip)->i_mode)) in xfs_can_free_eofblocks()
509 * Zero sized files with no cached pages and delalloc blocks will not in xfs_can_free_eofblocks()
510 * have speculative prealloc/delalloc blocks to remove. in xfs_can_free_eofblocks()
512 if (VFS_I(ip)->i_size == 0 && in xfs_can_free_eofblocks()
513 VFS_I(ip)->i_mapping->nrpages == 0 && in xfs_can_free_eofblocks()
514 ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
518 if (xfs_need_iread_extents(&ip->i_df)) in xfs_can_free_eofblocks()
523 * delalloc blocks and we are forced to remove them. in xfs_can_free_eofblocks()
525 if ((ip->i_diflags & XFS_DIFLAG_PREALLOC) && !ip->i_delayed_blks) in xfs_can_free_eofblocks()
529 * Do not try to free post-EOF blocks if EOF is beyond the end of the in xfs_can_free_eofblocks()
533 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); in xfs_can_free_eofblocks()
534 if (xfs_inode_has_bigrtalloc(ip)) in xfs_can_free_eofblocks()
536 last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); in xfs_can_free_eofblocks()
541 * Check if there is an post-EOF extent to free. If there are any in xfs_can_free_eofblocks()
542 * delalloc blocks attached to the inode (data fork delalloc in xfs_can_free_eofblocks()
546 xfs_ilock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
547 if (ip->i_delayed_blks || in xfs_can_free_eofblocks()
548 xfs_iext_lookup_extent(ip, &ip->i_df, end_fsb, &icur, &imap)) in xfs_can_free_eofblocks()
550 xfs_iunlock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
555 * This is called to free any blocks beyond eof. The caller must hold
561 struct xfs_inode *ip) in xfs_free_eofblocks() argument
564 struct xfs_mount *mp = ip->i_mount; in xfs_free_eofblocks()
568 error = xfs_qm_dqattach(ip); in xfs_free_eofblocks()
573 inode_dio_wait(VFS_I(ip)); in xfs_free_eofblocks()
581 if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { in xfs_free_eofblocks()
582 if (ip->i_delayed_blks) { in xfs_free_eofblocks()
583 xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, in xfs_free_eofblocks()
584 round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), in xfs_free_eofblocks()
587 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
591 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); in xfs_free_eofblocks()
597 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
598 xfs_trans_ijoin(tp, ip, 0); in xfs_free_eofblocks()
601 * Do not update the on-disk file size. If we update the on-disk file in xfs_free_eofblocks()
606 error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, in xfs_free_eofblocks()
607 XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); in xfs_free_eofblocks()
615 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
625 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
631 struct xfs_inode *ip, in xfs_alloc_file_space() argument
635 xfs_mount_t *mp = ip->i_mount; in xfs_alloc_file_space()
646 if (xfs_is_always_cow_inode(ip)) in xfs_alloc_file_space()
649 trace_xfs_alloc_file_space(ip); in xfs_alloc_file_space()
652 return -EIO; in xfs_alloc_file_space()
654 error = xfs_qm_dqattach(ip); in xfs_alloc_file_space()
659 return -EINVAL; in xfs_alloc_file_space()
661 rt = XFS_IS_REALTIME_INODE(ip); in xfs_alloc_file_space()
662 extsz = xfs_get_extsz_hint(ip); in xfs_alloc_file_space()
668 allocatesize_fsb = endoffset_fsb - startoffset_fsb; in xfs_alloc_file_space()
691 e += extsz - temp; in xfs_alloc_file_space()
698 * The transaction reservation is limited to a 32-bit block in xfs_alloc_file_space()
699 * count, hence we need to limit the number of blocks we are in xfs_alloc_file_space()
705 resblks = min_t(xfs_fileoff_t, (e - s), in xfs_alloc_file_space()
715 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_alloc_file_space()
720 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_alloc_file_space()
728 * xfs_bmapi_write will return -ENOSR. in xfs_alloc_file_space()
734 error = xfs_bmapi_write(tp, ip, startoffset_fsb, in xfs_alloc_file_space()
738 if (error != -ENOSR) in xfs_alloc_file_space()
742 startoffset_fsb += imapp->br_blockcount; in xfs_alloc_file_space()
743 allocatesize_fsb -= imapp->br_blockcount; in xfs_alloc_file_space()
746 ip->i_diflags |= XFS_DIFLAG_PREALLOC; in xfs_alloc_file_space()
747 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_alloc_file_space()
750 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
757 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
763 struct xfs_inode *ip, in xfs_unmap_extent() argument
768 struct xfs_mount *mp = ip->i_mount; in xfs_unmap_extent()
773 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0, in xfs_unmap_extent()
778 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_unmap_extent()
783 error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); in xfs_unmap_extent()
789 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
800 struct xfs_inode *ip, in xfs_flush_unmap_range() argument
804 struct inode *inode = VFS_I(ip); in xfs_flush_unmap_range()
813 rounding = max_t(xfs_off_t, xfs_inode_alloc_unitsize(ip), PAGE_SIZE); in xfs_flush_unmap_range()
815 end = roundup_64(offset + len, rounding) - 1; in xfs_flush_unmap_range()
817 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in xfs_flush_unmap_range()
826 struct xfs_inode *ip, in xfs_free_file_space() argument
830 struct xfs_mount *mp = ip->i_mount; in xfs_free_file_space()
835 trace_xfs_free_file_space(ip); in xfs_free_file_space()
837 error = xfs_qm_dqattach(ip); in xfs_free_file_space()
848 error = xfs_flush_unmap_range(ip, offset, len); in xfs_free_file_space()
856 if (xfs_inode_has_bigrtalloc(ip)) { in xfs_free_file_space()
866 error = xfs_unmap_extent(ip, startoffset_fsb, in xfs_free_file_space()
867 endoffset_fsb - startoffset_fsb, &done); in xfs_free_file_space()
874 * Now that we've unmap all full blocks we'll have to zero out any in xfs_free_file_space()
879 if (offset >= XFS_ISIZE(ip)) in xfs_free_file_space()
881 if (offset + len > XFS_ISIZE(ip)) in xfs_free_file_space()
882 len = XFS_ISIZE(ip) - offset; in xfs_free_file_space()
883 error = xfs_zero_range(ip, offset, len, NULL); in xfs_free_file_space()
889 * must make sure that the post-EOF area is also zeroed because the in xfs_free_file_space()
893 if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { in xfs_free_file_space()
894 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, in xfs_free_file_space()
903 struct xfs_inode *ip, in xfs_prepare_shift() argument
910 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation in xfs_prepare_shift()
913 if (xfs_can_free_eofblocks(ip)) { in xfs_prepare_shift()
914 error = xfs_free_eofblocks(ip); in xfs_prepare_shift()
927 rounding = xfs_inode_alloc_unitsize(ip); in xfs_prepare_shift()
930 offset -= rounding; in xfs_prepare_shift()
936 error = xfs_flush_unmap_range(ip, offset, XFS_ISIZE(ip)); in xfs_prepare_shift()
945 if (xfs_inode_has_cow_data(ip)) { in xfs_prepare_shift()
946 error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF, in xfs_prepare_shift()
958 * The first thing we do is to free data blocks in the specified range
969 struct xfs_inode *ip, in xfs_collapse_file_space() argument
973 struct xfs_mount *mp = ip->i_mount; in xfs_collapse_file_space()
980 xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); in xfs_collapse_file_space()
982 trace_xfs_collapse_file_space(ip); in xfs_collapse_file_space()
984 error = xfs_free_file_space(ip, offset, len); in xfs_collapse_file_space()
988 error = xfs_prepare_shift(ip, offset); in xfs_collapse_file_space()
992 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_collapse_file_space()
996 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
997 xfs_trans_ijoin(tp, ip, 0); in xfs_collapse_file_space()
1000 error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb, in xfs_collapse_file_space()
1014 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1019 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1037 struct xfs_inode *ip, in xfs_insert_file_space() argument
1041 struct xfs_mount *mp = ip->i_mount; in xfs_insert_file_space()
1049 xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); in xfs_insert_file_space()
1051 trace_xfs_insert_file_space(ip); in xfs_insert_file_space()
1053 error = xfs_bmap_can_insert_extents(ip, stop_fsb, shift_fsb); in xfs_insert_file_space()
1057 error = xfs_prepare_shift(ip, offset); in xfs_insert_file_space()
1061 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, in xfs_insert_file_space()
1066 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1067 xfs_trans_ijoin(tp, ip, 0); in xfs_insert_file_space()
1069 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_insert_file_space()
1079 error = xfs_bmap_split_extent(tp, ip, stop_fsb); in xfs_insert_file_space()
1088 error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb, in xfs_insert_file_space()
1095 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1100 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1126 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents_check_format() argument
1129 struct xfs_ifork *ifp = &ip->i_df; in xfs_swap_extents_check_format()
1130 struct xfs_ifork *tifp = &tip->i_df; in xfs_swap_extents_check_format()
1133 if (XFS_IS_QUOTA_ON(ip->i_mount) && in xfs_swap_extents_check_format()
1134 (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) || in xfs_swap_extents_check_format()
1135 !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) || in xfs_swap_extents_check_format()
1136 ip->i_projid != tip->i_projid)) in xfs_swap_extents_check_format()
1137 return -EINVAL; in xfs_swap_extents_check_format()
1140 if (ifp->if_format == XFS_DINODE_FMT_LOCAL || in xfs_swap_extents_check_format()
1141 tifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_swap_extents_check_format()
1142 return -EINVAL; in xfs_swap_extents_check_format()
1148 if (ifp->if_nextents < tifp->if_nextents) in xfs_swap_extents_check_format()
1149 return -EINVAL; in xfs_swap_extents_check_format()
1155 if (xfs_has_rmapbt(ip->i_mount)) in xfs_swap_extents_check_format()
1163 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1164 tifp->if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extents_check_format()
1165 return -EINVAL; in xfs_swap_extents_check_format()
1168 if (tifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1169 tifp->if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1170 return -EINVAL; in xfs_swap_extents_check_format()
1173 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1174 ifp->if_nextents > XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1175 return -EINVAL; in xfs_swap_extents_check_format()
1182 * Note that we have to be careful to allow btree->extent conversions in xfs_swap_extents_check_format()
1186 if (tifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1187 if (xfs_inode_has_attr_fork(ip) && in xfs_swap_extents_check_format()
1188 xfs_bmap_bmdr_space(tifp->if_broot) > xfs_inode_fork_boff(ip)) in xfs_swap_extents_check_format()
1189 return -EINVAL; in xfs_swap_extents_check_format()
1190 if (tifp->if_nextents <= XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1191 return -EINVAL; in xfs_swap_extents_check_format()
1194 /* Reciprocal target->temp btree format checks */ in xfs_swap_extents_check_format()
1195 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1197 xfs_bmap_bmdr_space(ip->i_df.if_broot) > xfs_inode_fork_boff(tip)) in xfs_swap_extents_check_format()
1198 return -EINVAL; in xfs_swap_extents_check_format()
1199 if (ifp->if_nextents <= XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1200 return -EINVAL; in xfs_swap_extents_check_format()
1208 struct xfs_inode *ip) in xfs_swap_extent_flush() argument
1212 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_swap_extent_flush()
1215 truncate_pagecache_range(VFS_I(ip), 0, -1); in xfs_swap_extent_flush()
1218 if (VFS_I(ip)->i_mapping->nrpages) in xfs_swap_extent_flush()
1219 return -EINVAL; in xfs_swap_extent_flush()
1229 struct xfs_inode *ip, in xfs_swap_extent_rmap() argument
1246 * If the source file has shared blocks, we must flag the donor in xfs_swap_extent_rmap()
1247 * file as having shared blocks so that we get the shared-block in xfs_swap_extent_rmap()
1251 tip_flags2 = tip->i_diflags2; in xfs_swap_extent_rmap()
1252 if (ip->i_diflags2 & XFS_DIFLAG2_REFLINK) in xfs_swap_extent_rmap()
1253 tip->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_swap_extent_rmap()
1256 end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); in xfs_swap_extent_rmap()
1257 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); in xfs_swap_extent_rmap()
1272 /* Unmap the old blocks in the source file. */ in xfs_swap_extent_rmap()
1274 ASSERT(tp->t_highest_agno == NULLAGNUMBER); in xfs_swap_extent_rmap()
1279 error = xfs_bmapi_read(ip, tirec.br_startoff, in xfs_swap_extent_rmap()
1286 trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); in xfs_swap_extent_rmap()
1296 error = xfs_iext_count_extend(tp, ip, in xfs_swap_extent_rmap()
1315 xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &irec); in xfs_swap_extent_rmap()
1317 /* Map the donor file's blocks into the source file. */ in xfs_swap_extent_rmap()
1318 xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &uirec); in xfs_swap_extent_rmap()
1320 /* Map the source file's blocks into the donor file. */ in xfs_swap_extent_rmap()
1332 tirec.br_blockcount -= rlen; in xfs_swap_extent_rmap()
1336 count_fsb -= ilen; in xfs_swap_extent_rmap()
1340 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1344 trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); in xfs_swap_extent_rmap()
1345 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1353 struct xfs_inode *ip, in xfs_swap_extent_forks() argument
1365 * Count the number of extended attribute blocks in xfs_swap_extent_forks()
1367 if (xfs_inode_has_attr_fork(ip) && ip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1368 ip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1369 error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk, in xfs_swap_extent_forks()
1374 if (xfs_inode_has_attr_fork(tip) && tip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1375 tip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1384 * block headers. We can't start changing the bmbt blocks until the in xfs_swap_extent_forks()
1389 if (xfs_has_v3inodes(ip->i_mount)) { in xfs_swap_extent_forks()
1390 if (ip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1392 if (tip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1399 swap(ip->i_df, tip->i_df); in xfs_swap_extent_forks()
1402 * Fix the on-disk inode values in xfs_swap_extent_forks()
1404 tmp = (uint64_t)ip->i_nblocks; in xfs_swap_extent_forks()
1405 ip->i_nblocks = tip->i_nblocks - taforkblks + aforkblks; in xfs_swap_extent_forks()
1406 tip->i_nblocks = tmp + taforkblks - aforkblks; in xfs_swap_extent_forks()
1412 * number of delalloc blocks the data fork in the source inode is in xfs_swap_extent_forks()
1417 ASSERT(tip->i_delayed_blks == 0); in xfs_swap_extent_forks()
1418 tip->i_delayed_blks = ip->i_delayed_blks; in xfs_swap_extent_forks()
1419 ip->i_delayed_blks = 0; in xfs_swap_extent_forks()
1421 switch (ip->i_df.if_format) { in xfs_swap_extent_forks()
1426 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1432 switch (tip->i_df.if_format) { in xfs_swap_extent_forks()
1438 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1447 * Fix up the owners of the bmbt blocks to refer to the current inode. The
1450 * physically logged as a fallback and the scan returns -EAGAIN. We must roll
1457 struct xfs_inode *ip, in xfs_swap_change_owner() argument
1464 error = xfs_bmbt_change_owner(tp, ip, XFS_DATA_FORK, ip->i_ino, in xfs_swap_change_owner()
1467 if (error != -EAGAIN) in xfs_swap_change_owner()
1479 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_change_owner()
1481 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_swap_change_owner()
1490 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents() argument
1494 struct xfs_mount *mp = ip->i_mount; in xfs_swap_extents()
1496 struct xfs_bstat *sbp = &sxp->sx_stat; in xfs_swap_extents()
1510 lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()
1511 filemap_invalidate_lock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1512 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1515 if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { in xfs_swap_extents()
1516 error = -EINVAL; in xfs_swap_extents()
1520 /* Verify both files are either real-time or non-realtime */ in xfs_swap_extents()
1521 if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { in xfs_swap_extents()
1522 error = -EINVAL; in xfs_swap_extents()
1533 if (XFS_IS_REALTIME_INODE(ip) && xfs_has_rtgroups(ip->i_mount)) { in xfs_swap_extents()
1534 error = -EOPNOTSUPP; in xfs_swap_extents()
1538 error = xfs_qm_dqattach(ip); in xfs_swap_extents()
1546 error = xfs_swap_extent_flush(ip); in xfs_swap_extents()
1566 uint32_t ipnext = ip->i_df.if_nextents; in xfs_swap_extents()
1567 uint32_t tipnext = tip->i_df.if_nextents; in xfs_swap_extents()
1581 * prematurely and cause shutdown. Return freed blocks to the in xfs_swap_extents()
1586 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, flags, in xfs_swap_extents()
1595 xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1596 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_extents()
1601 if (sxp->sx_offset != 0 || in xfs_swap_extents()
1602 sxp->sx_length != ip->i_disk_size || in xfs_swap_extents()
1603 sxp->sx_length != tip->i_disk_size) { in xfs_swap_extents()
1604 error = -EFAULT; in xfs_swap_extents()
1608 trace_xfs_swap_extent_before(ip, 0); in xfs_swap_extents()
1612 error = xfs_swap_extents_check_format(ip, tip); in xfs_swap_extents()
1616 __func__, ip->i_ino); in xfs_swap_extents()
1627 ctime = inode_get_ctime(VFS_I(ip)); in xfs_swap_extents()
1628 mtime = inode_get_mtime(VFS_I(ip)); in xfs_swap_extents()
1629 if ((sbp->bs_ctime.tv_sec != ctime.tv_sec) || in xfs_swap_extents()
1630 (sbp->bs_ctime.tv_nsec != ctime.tv_nsec) || in xfs_swap_extents()
1631 (sbp->bs_mtime.tv_sec != mtime.tv_sec) || in xfs_swap_extents()
1632 (sbp->bs_mtime.tv_nsec != mtime.tv_nsec)) { in xfs_swap_extents()
1633 error = -EBUSY; in xfs_swap_extents()
1638 * Note the trickiness in setting the log flags - we set the owner log in xfs_swap_extents()
1642 * not the pre-swapped inodes. in xfs_swap_extents()
1648 error = xfs_swap_extent_rmap(&tp, ip, tip); in xfs_swap_extents()
1650 error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, in xfs_swap_extents()
1656 if ((ip->i_diflags2 & XFS_DIFLAG2_REFLINK) ^ in xfs_swap_extents()
1657 (tip->i_diflags2 & XFS_DIFLAG2_REFLINK)) { in xfs_swap_extents()
1658 f = ip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1659 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1660 ip->i_diflags2 |= tip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1661 tip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1662 tip->i_diflags2 |= f & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1667 ASSERT(!ip->i_cowfp || in xfs_swap_extents()
1668 ip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1669 ASSERT(!tip->i_cowfp || in xfs_swap_extents()
1670 tip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1672 swap(ip->i_cowfp, tip->i_cowfp); in xfs_swap_extents()
1674 if (ip->i_cowfp && ip->i_cowfp->if_bytes) in xfs_swap_extents()
1675 xfs_inode_set_cowblocks_tag(ip); in xfs_swap_extents()
1677 xfs_inode_clear_cowblocks_tag(ip); in xfs_swap_extents()
1678 if (tip->i_cowfp && tip->i_cowfp->if_bytes) in xfs_swap_extents()
1684 xfs_trans_log_inode(tp, ip, src_log_flags); in xfs_swap_extents()
1689 * have inode number owner values in the bmbt blocks that still refer to in xfs_swap_extents()
1694 error = xfs_swap_change_owner(&tp, ip, tip); in xfs_swap_extents()
1699 error = xfs_swap_change_owner(&tp, tip, ip); in xfs_swap_extents()
1713 trace_xfs_swap_extent_after(ip, 0); in xfs_swap_extents()
1717 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1720 filemap_invalidate_unlock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1721 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1722 unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()