Lines Matching +full:ip +full:- +full:block

1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2006 Silicon Graphics, Inc.
36 * Convert the given file system block to a disk block. We have to treat it
41 xfs_fsb_to_db(struct xfs_inode *ip, xfs_fsblock_t fsb) in xfs_fsb_to_db() argument
43 if (XFS_IS_REALTIME_INODE(ip)) in xfs_fsb_to_db()
44 return XFS_FSB_TO_BB(ip->i_mount, fsb); in xfs_fsb_to_db()
45 return XFS_FSB_TO_DADDR(ip->i_mount, fsb); in xfs_fsb_to_db()
51 * The VFS functions take a linearised filesystem block offset, so we have to
57 struct xfs_inode *ip, in xfs_zero_extent() argument
61 struct xfs_mount *mp = ip->i_mount; in xfs_zero_extent()
62 struct xfs_buftarg *target = xfs_inode_buftarg(ip); in xfs_zero_extent()
63 xfs_daddr_t sector = xfs_fsb_to_db(ip, start_fsb); in xfs_zero_extent()
64 sector_t block = XFS_BB_TO_FSBT(mp, sector); in xfs_zero_extent() local
66 return blkdev_issue_zeroout(target->bt_bdev, in xfs_zero_extent()
67 block << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
68 count_fsb << (mp->m_super->s_blocksize_bits - 9), in xfs_zero_extent()
73 * Extent tree block counting routines.
106 struct xfs_inode *ip, in xfs_bmap_count_blocks() argument
111 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_count_blocks()
112 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_count_blocks()
123 switch (ifp->if_format) { in xfs_bmap_count_blocks()
125 error = xfs_iread_extents(tp, ip, whichfork); in xfs_bmap_count_blocks()
129 cur = xfs_bmbt_init_cursor(mp, tp, ip, whichfork); in xfs_bmap_count_blocks()
136 * xfs_btree_count_blocks includes the root block contained in in xfs_bmap_count_blocks()
140 *count += btblocks - 1; in xfs_bmap_count_blocks()
153 struct xfs_inode *ip, in xfs_getbmap_report_one() argument
159 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_one()
163 error = xfs_reflink_trim_around_shared(ip, got, &shared); in xfs_getbmap_report_one()
167 if (isnullstartblock(got->br_startblock) || in xfs_getbmap_report_one()
168 got->br_startblock == DELAYSTARTBLOCK) { in xfs_getbmap_report_one()
170 * Take the flush completion as being a point-in-time snapshot in xfs_getbmap_report_one()
175 if (!(bmv->bmv_iflags & BMV_IF_DELALLOC)) in xfs_getbmap_report_one()
178 p->bmv_oflags |= BMV_OF_DELALLOC; in xfs_getbmap_report_one()
179 p->bmv_block = -2; in xfs_getbmap_report_one()
181 p->bmv_block = xfs_fsb_to_db(ip, got->br_startblock); in xfs_getbmap_report_one()
184 if (got->br_state == XFS_EXT_UNWRITTEN && in xfs_getbmap_report_one()
185 (bmv->bmv_iflags & BMV_IF_PREALLOC)) in xfs_getbmap_report_one()
186 p->bmv_oflags |= BMV_OF_PREALLOC; in xfs_getbmap_report_one()
189 p->bmv_oflags |= BMV_OF_SHARED; in xfs_getbmap_report_one()
191 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, got->br_startoff); in xfs_getbmap_report_one()
192 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, got->br_blockcount); in xfs_getbmap_report_one()
194 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_one()
195 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_one()
196 bmv->bmv_entries++; in xfs_getbmap_report_one()
202 struct xfs_inode *ip, in xfs_getbmap_report_hole() argument
209 struct kgetbmap *p = out + bmv->bmv_entries; in xfs_getbmap_report_hole()
211 if (bmv->bmv_iflags & BMV_IF_NO_HOLES) in xfs_getbmap_report_hole()
214 p->bmv_block = -1; in xfs_getbmap_report_hole()
215 p->bmv_offset = XFS_FSB_TO_BB(ip->i_mount, bno); in xfs_getbmap_report_hole()
216 p->bmv_length = XFS_FSB_TO_BB(ip->i_mount, end - bno); in xfs_getbmap_report_hole()
218 bmv->bmv_offset = p->bmv_offset + p->bmv_length; in xfs_getbmap_report_hole()
219 bmv->bmv_length = max(0LL, bmv_end - bmv->bmv_offset); in xfs_getbmap_report_hole()
220 bmv->bmv_entries++; in xfs_getbmap_report_hole()
227 return bmv->bmv_length == 0 || bmv->bmv_entries >= bmv->bmv_count - 1; in xfs_getbmap_full()
235 xfs_fileoff_t end = rec->br_startoff + rec->br_blockcount; in xfs_getbmap_next_rec()
240 rec->br_startoff += rec->br_blockcount; in xfs_getbmap_next_rec()
241 if (!isnullstartblock(rec->br_startblock) && in xfs_getbmap_next_rec()
242 rec->br_startblock != DELAYSTARTBLOCK) in xfs_getbmap_next_rec()
243 rec->br_startblock += rec->br_blockcount; in xfs_getbmap_next_rec()
244 rec->br_blockcount = total_end - end; in xfs_getbmap_next_rec()
251 * are mapped, until the passed-in bmv->bmv_count slots have
252 * been filled, or until the formatter short-circuits the loop,
253 * if it is tracking filled-in extents on its own.
257 struct xfs_inode *ip, in xfs_getbmap() argument
261 struct xfs_mount *mp = ip->i_mount; in xfs_getbmap()
262 int iflags = bmv->bmv_iflags; in xfs_getbmap()
271 if (bmv->bmv_iflags & ~BMV_IF_VALID) in xfs_getbmap()
272 return -EINVAL; in xfs_getbmap()
276 return -EINVAL; in xfs_getbmap()
279 return -EINVAL; in xfs_getbmap()
281 if (bmv->bmv_length < -1) in xfs_getbmap()
282 return -EINVAL; in xfs_getbmap()
283 bmv->bmv_entries = 0; in xfs_getbmap()
284 if (bmv->bmv_length == 0) in xfs_getbmap()
294 xfs_ilock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
297 lock = xfs_ilock_attr_map_shared(ip); in xfs_getbmap()
298 if (!xfs_inode_has_attr_fork(ip)) in xfs_getbmap()
305 xfs_ilock(ip, lock); in xfs_getbmap()
308 if (!xfs_ifork_ptr(ip, whichfork)) in xfs_getbmap()
311 if (xfs_get_cowextsz_hint(ip)) in xfs_getbmap()
312 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
314 max_len = XFS_ISIZE(ip); in xfs_getbmap()
318 (ip->i_delayed_blks || XFS_ISIZE(ip) > ip->i_disk_size)) { in xfs_getbmap()
319 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_getbmap()
329 * ip->i_delayed_blks == 0. in xfs_getbmap()
333 if (xfs_get_extsz_hint(ip) || in xfs_getbmap()
334 (ip->i_diflags & XFS_DIFLAG_PREALLOC)) in xfs_getbmap()
335 max_len = mp->m_super->s_maxbytes; in xfs_getbmap()
337 max_len = XFS_ISIZE(ip); in xfs_getbmap()
339 lock = xfs_ilock_data_map_shared(ip); in xfs_getbmap()
343 ifp = xfs_ifork_ptr(ip, whichfork); in xfs_getbmap()
345 switch (ifp->if_format) { in xfs_getbmap()
353 error = -EINVAL; in xfs_getbmap()
357 if (bmv->bmv_length == -1) { in xfs_getbmap()
359 bmv->bmv_length = max(0LL, max_len - bmv->bmv_offset); in xfs_getbmap()
362 bmv_end = bmv->bmv_offset + bmv->bmv_length; in xfs_getbmap()
364 first_bno = bno = XFS_BB_TO_FSBT(mp, bmv->bmv_offset); in xfs_getbmap()
365 len = XFS_BB_TO_FSB(mp, bmv->bmv_length); in xfs_getbmap()
367 error = xfs_iread_extents(NULL, ip, whichfork); in xfs_getbmap()
371 if (!xfs_iext_lookup_extent(ip, ifp, bno, &icur, &got)) { in xfs_getbmap()
373 * Report a whole-file hole if the delalloc flag is set to in xfs_getbmap()
377 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
378 XFS_B_TO_FSB(mp, XFS_ISIZE(ip))); in xfs_getbmap()
390 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, bno, in xfs_getbmap()
404 error = xfs_getbmap_report_one(ip, bmv, out, bmv_end, in xfs_getbmap()
411 xfs_fileoff_t end = XFS_B_TO_FSB(mp, XFS_ISIZE(ip)); in xfs_getbmap()
413 if (bmv->bmv_entries > 0) in xfs_getbmap()
414 out[bmv->bmv_entries - 1].bmv_oflags |= in xfs_getbmap()
419 xfs_getbmap_report_hole(ip, bmv, out, bmv_end, in xfs_getbmap()
430 xfs_iunlock(ip, lock); in xfs_getbmap()
432 xfs_iunlock(ip, XFS_IOLOCK_SHARED); in xfs_getbmap()
444 struct xfs_inode *ip, in xfs_bmap_punch_delalloc_range() argument
449 struct xfs_mount *mp = ip->i_mount; in xfs_bmap_punch_delalloc_range()
450 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, whichfork); in xfs_bmap_punch_delalloc_range()
458 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
459 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_bmap_punch_delalloc_range()
464 xfs_trim_extent(&del, start_fsb, end_fsb - start_fsb); in xfs_bmap_punch_delalloc_range()
468 * previous extent on non-delalloc or extents outside the in xfs_bmap_punch_delalloc_range()
478 xfs_bmap_del_extent_delay(ip, whichfork, &icur, &got, &del); in xfs_bmap_punch_delalloc_range()
483 if (whichfork == XFS_COW_FORK && !ifp->if_bytes) in xfs_bmap_punch_delalloc_range()
484 xfs_inode_clear_cowblocks_tag(ip); in xfs_bmap_punch_delalloc_range()
487 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_bmap_punch_delalloc_range()
496 struct xfs_inode *ip) in xfs_can_free_eofblocks() argument
498 struct xfs_mount *mp = ip->i_mount; in xfs_can_free_eofblocks()
509 if (!(VFS_I(ip)->i_state & I_FREEING)) in xfs_can_free_eofblocks()
510 xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL); in xfs_can_free_eofblocks()
513 if (!S_ISREG(VFS_I(ip)->i_mode)) in xfs_can_free_eofblocks()
520 if (VFS_I(ip)->i_size == 0 && in xfs_can_free_eofblocks()
521 VFS_I(ip)->i_mapping->nrpages == 0 && in xfs_can_free_eofblocks()
522 ip->i_delayed_blks == 0) in xfs_can_free_eofblocks()
526 if (xfs_need_iread_extents(&ip->i_df)) in xfs_can_free_eofblocks()
533 if ((ip->i_diflags & XFS_DIFLAG_PREALLOC) && !ip->i_delayed_blks) in xfs_can_free_eofblocks()
537 * Do not try to free post-EOF blocks if EOF is beyond the end of the in xfs_can_free_eofblocks()
541 end_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_ISIZE(ip)); in xfs_can_free_eofblocks()
542 if (xfs_inode_has_bigrtalloc(ip)) in xfs_can_free_eofblocks()
544 last_fsb = XFS_B_TO_FSB(mp, mp->m_super->s_maxbytes); in xfs_can_free_eofblocks()
549 * Check if there is an post-EOF extent to free. in xfs_can_free_eofblocks()
551 xfs_ilock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
552 if (xfs_iext_lookup_extent(ip, &ip->i_df, end_fsb, &icur, &imap)) in xfs_can_free_eofblocks()
554 xfs_iunlock(ip, XFS_ILOCK_SHARED); in xfs_can_free_eofblocks()
565 struct xfs_inode *ip) in xfs_free_eofblocks() argument
568 struct xfs_mount *mp = ip->i_mount; in xfs_free_eofblocks()
572 error = xfs_qm_dqattach(ip); in xfs_free_eofblocks()
577 inode_dio_wait(VFS_I(ip)); in xfs_free_eofblocks()
585 if (ip->i_diflags & (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) { in xfs_free_eofblocks()
586 if (ip->i_delayed_blks) { in xfs_free_eofblocks()
587 xfs_bmap_punch_delalloc_range(ip, XFS_DATA_FORK, in xfs_free_eofblocks()
588 round_up(XFS_ISIZE(ip), mp->m_sb.sb_blocksize), in xfs_free_eofblocks()
591 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
595 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_itruncate, 0, 0, 0, &tp); in xfs_free_eofblocks()
601 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
602 xfs_trans_ijoin(tp, ip, 0); in xfs_free_eofblocks()
605 * Do not update the on-disk file size. If we update the on-disk file in xfs_free_eofblocks()
610 error = xfs_itruncate_extents_flags(&tp, ip, XFS_DATA_FORK, in xfs_free_eofblocks()
611 XFS_ISIZE(ip), XFS_BMAPI_NODISCARD); in xfs_free_eofblocks()
619 xfs_inode_clear_eofblocks_tag(ip); in xfs_free_eofblocks()
629 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_free_eofblocks()
635 struct xfs_inode *ip, in xfs_alloc_file_space() argument
639 xfs_mount_t *mp = ip->i_mount; in xfs_alloc_file_space()
650 if (xfs_is_always_cow_inode(ip)) in xfs_alloc_file_space()
653 trace_xfs_alloc_file_space(ip); in xfs_alloc_file_space()
656 return -EIO; in xfs_alloc_file_space()
658 error = xfs_qm_dqattach(ip); in xfs_alloc_file_space()
663 return -EINVAL; in xfs_alloc_file_space()
665 rt = XFS_IS_REALTIME_INODE(ip); in xfs_alloc_file_space()
666 extsz = xfs_get_extsz_hint(ip); in xfs_alloc_file_space()
672 allocatesize_fsb = endoffset_fsb - startoffset_fsb; in xfs_alloc_file_space()
695 e += extsz - temp; in xfs_alloc_file_space()
702 * The transaction reservation is limited to a 32-bit block in xfs_alloc_file_space()
709 resblks = min_t(xfs_fileoff_t, (e - s), in xfs_alloc_file_space()
719 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_alloc_file_space()
724 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_alloc_file_space()
731 * enough to cover the start block of the requested range, in xfs_alloc_file_space()
732 * xfs_bmapi_write will return -ENOSR. in xfs_alloc_file_space()
738 error = xfs_bmapi_write(tp, ip, startoffset_fsb, in xfs_alloc_file_space()
742 if (error != -ENOSR) in xfs_alloc_file_space()
746 startoffset_fsb += imapp->br_blockcount; in xfs_alloc_file_space()
747 allocatesize_fsb -= imapp->br_blockcount; in xfs_alloc_file_space()
750 ip->i_diflags |= XFS_DIFLAG_PREALLOC; in xfs_alloc_file_space()
751 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_alloc_file_space()
754 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
761 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_alloc_file_space()
767 struct xfs_inode *ip, in xfs_unmap_extent() argument
772 struct xfs_mount *mp = ip->i_mount; in xfs_unmap_extent()
777 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0, in xfs_unmap_extent()
782 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_unmap_extent()
787 error = xfs_bunmapi(tp, ip, startoffset_fsb, len_fsb, 0, 2, done); in xfs_unmap_extent()
793 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_unmap_extent()
804 struct xfs_inode *ip, in xfs_flush_unmap_range() argument
808 struct inode *inode = VFS_I(ip); in xfs_flush_unmap_range()
817 rounding = max_t(xfs_off_t, xfs_inode_alloc_unitsize(ip), PAGE_SIZE); in xfs_flush_unmap_range()
819 end = roundup_64(offset + len, rounding) - 1; in xfs_flush_unmap_range()
821 error = filemap_write_and_wait_range(inode->i_mapping, start, end); in xfs_flush_unmap_range()
830 struct xfs_inode *ip, in xfs_free_file_space() argument
834 struct xfs_mount *mp = ip->i_mount; in xfs_free_file_space()
839 trace_xfs_free_file_space(ip); in xfs_free_file_space()
841 error = xfs_qm_dqattach(ip); in xfs_free_file_space()
852 error = xfs_flush_unmap_range(ip, offset, len); in xfs_free_file_space()
860 if (xfs_inode_has_bigrtalloc(ip)) { in xfs_free_file_space()
870 error = xfs_unmap_extent(ip, startoffset_fsb, in xfs_free_file_space()
871 endoffset_fsb - startoffset_fsb, &done); in xfs_free_file_space()
879 * partial block at the beginning and/or end. xfs_zero_range is smart in xfs_free_file_space()
883 if (offset >= XFS_ISIZE(ip)) in xfs_free_file_space()
885 if (offset + len > XFS_ISIZE(ip)) in xfs_free_file_space()
886 len = XFS_ISIZE(ip) - offset; in xfs_free_file_space()
887 error = xfs_zero_range(ip, offset, len, NULL); in xfs_free_file_space()
893 * must make sure that the post-EOF area is also zeroed because the in xfs_free_file_space()
897 if (offset + len >= XFS_ISIZE(ip) && offset_in_page(offset + len) > 0) { in xfs_free_file_space()
898 error = filemap_write_and_wait_range(VFS_I(ip)->i_mapping, in xfs_free_file_space()
907 struct xfs_inode *ip, in xfs_prepare_shift() argument
914 * Trim eofblocks to avoid shifting uninitialized post-eof preallocation in xfs_prepare_shift()
917 if (xfs_can_free_eofblocks(ip)) { in xfs_prepare_shift()
918 error = xfs_free_eofblocks(ip); in xfs_prepare_shift()
924 * Shift operations must stabilize the start block offset boundary along in xfs_prepare_shift()
931 rounding = xfs_inode_alloc_unitsize(ip); in xfs_prepare_shift()
934 offset -= rounding; in xfs_prepare_shift()
940 error = xfs_flush_unmap_range(ip, offset, XFS_ISIZE(ip)); in xfs_prepare_shift()
949 if (xfs_inode_has_cow_data(ip)) { in xfs_prepare_shift()
950 error = xfs_reflink_cancel_cow_range(ip, offset, NULLFILEOFF, in xfs_prepare_shift()
973 struct xfs_inode *ip, in xfs_collapse_file_space() argument
977 struct xfs_mount *mp = ip->i_mount; in xfs_collapse_file_space()
984 xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); in xfs_collapse_file_space()
986 trace_xfs_collapse_file_space(ip); in xfs_collapse_file_space()
988 error = xfs_free_file_space(ip, offset, len); in xfs_collapse_file_space()
992 error = xfs_prepare_shift(ip, offset); in xfs_collapse_file_space()
996 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_collapse_file_space()
1000 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1001 xfs_trans_ijoin(tp, ip, 0); in xfs_collapse_file_space()
1004 error = xfs_bmap_collapse_extents(tp, ip, &next_fsb, shift_fsb, in xfs_collapse_file_space()
1018 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1023 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_collapse_file_space()
1041 struct xfs_inode *ip, in xfs_insert_file_space() argument
1045 struct xfs_mount *mp = ip->i_mount; in xfs_insert_file_space()
1053 xfs_assert_ilocked(ip, XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL); in xfs_insert_file_space()
1055 trace_xfs_insert_file_space(ip); in xfs_insert_file_space()
1057 error = xfs_bmap_can_insert_extents(ip, stop_fsb, shift_fsb); in xfs_insert_file_space()
1061 error = xfs_prepare_shift(ip, offset); in xfs_insert_file_space()
1065 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, in xfs_insert_file_space()
1070 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1071 xfs_trans_ijoin(tp, ip, 0); in xfs_insert_file_space()
1073 error = xfs_iext_count_extend(tp, ip, XFS_DATA_FORK, in xfs_insert_file_space()
1080 * is not the starting block of extent, we need to split the extent at in xfs_insert_file_space()
1083 error = xfs_bmap_split_extent(tp, ip, stop_fsb); in xfs_insert_file_space()
1092 error = xfs_bmap_insert_extents(tp, ip, &next_fsb, shift_fsb, in xfs_insert_file_space()
1099 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1104 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_insert_file_space()
1130 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents_check_format() argument
1133 struct xfs_ifork *ifp = &ip->i_df; in xfs_swap_extents_check_format()
1134 struct xfs_ifork *tifp = &tip->i_df; in xfs_swap_extents_check_format()
1137 if (XFS_IS_QUOTA_ON(ip->i_mount) && in xfs_swap_extents_check_format()
1138 (!uid_eq(VFS_I(ip)->i_uid, VFS_I(tip)->i_uid) || in xfs_swap_extents_check_format()
1139 !gid_eq(VFS_I(ip)->i_gid, VFS_I(tip)->i_gid) || in xfs_swap_extents_check_format()
1140 ip->i_projid != tip->i_projid)) in xfs_swap_extents_check_format()
1141 return -EINVAL; in xfs_swap_extents_check_format()
1144 if (ifp->if_format == XFS_DINODE_FMT_LOCAL || in xfs_swap_extents_check_format()
1145 tifp->if_format == XFS_DINODE_FMT_LOCAL) in xfs_swap_extents_check_format()
1146 return -EINVAL; in xfs_swap_extents_check_format()
1152 if (ifp->if_nextents < tifp->if_nextents) in xfs_swap_extents_check_format()
1153 return -EINVAL; in xfs_swap_extents_check_format()
1159 if (xfs_has_rmapbt(ip->i_mount)) in xfs_swap_extents_check_format()
1167 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1168 tifp->if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extents_check_format()
1169 return -EINVAL; in xfs_swap_extents_check_format()
1172 if (tifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1173 tifp->if_nextents > XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1174 return -EINVAL; in xfs_swap_extents_check_format()
1177 if (ifp->if_format == XFS_DINODE_FMT_EXTENTS && in xfs_swap_extents_check_format()
1178 ifp->if_nextents > XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1179 return -EINVAL; in xfs_swap_extents_check_format()
1182 * If we are in a btree format, check that the temp root block will fit in xfs_swap_extents_check_format()
1186 * Note that we have to be careful to allow btree->extent conversions in xfs_swap_extents_check_format()
1190 if (tifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1191 if (xfs_inode_has_attr_fork(ip) && in xfs_swap_extents_check_format()
1192 xfs_bmap_bmdr_space(tifp->if_broot) > xfs_inode_fork_boff(ip)) in xfs_swap_extents_check_format()
1193 return -EINVAL; in xfs_swap_extents_check_format()
1194 if (tifp->if_nextents <= XFS_IFORK_MAXEXT(ip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1195 return -EINVAL; in xfs_swap_extents_check_format()
1198 /* Reciprocal target->temp btree format checks */ in xfs_swap_extents_check_format()
1199 if (ifp->if_format == XFS_DINODE_FMT_BTREE) { in xfs_swap_extents_check_format()
1201 xfs_bmap_bmdr_space(ip->i_df.if_broot) > xfs_inode_fork_boff(tip)) in xfs_swap_extents_check_format()
1202 return -EINVAL; in xfs_swap_extents_check_format()
1203 if (ifp->if_nextents <= XFS_IFORK_MAXEXT(tip, XFS_DATA_FORK)) in xfs_swap_extents_check_format()
1204 return -EINVAL; in xfs_swap_extents_check_format()
1212 struct xfs_inode *ip) in xfs_swap_extent_flush() argument
1216 error = filemap_write_and_wait(VFS_I(ip)->i_mapping); in xfs_swap_extent_flush()
1219 truncate_pagecache_range(VFS_I(ip), 0, -1); in xfs_swap_extent_flush()
1222 if (VFS_I(ip)->i_mapping->nrpages) in xfs_swap_extent_flush()
1223 return -EINVAL; in xfs_swap_extent_flush()
1233 struct xfs_inode *ip, in xfs_swap_extent_rmap() argument
1251 * file as having shared blocks so that we get the shared-block in xfs_swap_extent_rmap()
1255 tip_flags2 = tip->i_diflags2; in xfs_swap_extent_rmap()
1256 if (ip->i_diflags2 & XFS_DIFLAG2_REFLINK) in xfs_swap_extent_rmap()
1257 tip->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_swap_extent_rmap()
1260 end_fsb = XFS_B_TO_FSB(ip->i_mount, i_size_read(VFS_I(ip))); in xfs_swap_extent_rmap()
1261 count_fsb = (xfs_filblks_t)(end_fsb - offset_fsb); in xfs_swap_extent_rmap()
1278 ASSERT(tp->t_highest_agno == NULLAGNUMBER); in xfs_swap_extent_rmap()
1283 error = xfs_bmapi_read(ip, tirec.br_startoff, in xfs_swap_extent_rmap()
1290 trace_xfs_swap_extent_rmap_remap_piece(ip, &irec); in xfs_swap_extent_rmap()
1300 error = xfs_iext_count_extend(tp, ip, in xfs_swap_extent_rmap()
1319 xfs_bmap_unmap_extent(tp, ip, XFS_DATA_FORK, &irec); in xfs_swap_extent_rmap()
1322 xfs_bmap_map_extent(tp, ip, XFS_DATA_FORK, &uirec); in xfs_swap_extent_rmap()
1336 tirec.br_blockcount -= rlen; in xfs_swap_extent_rmap()
1340 count_fsb -= ilen; in xfs_swap_extent_rmap()
1344 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1348 trace_xfs_swap_extent_rmap_error(ip, error, _RET_IP_); in xfs_swap_extent_rmap()
1349 tip->i_diflags2 = tip_flags2; in xfs_swap_extent_rmap()
1357 struct xfs_inode *ip, in xfs_swap_extent_forks() argument
1371 if (xfs_inode_has_attr_fork(ip) && ip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1372 ip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1373 error = xfs_bmap_count_blocks(tp, ip, XFS_ATTR_FORK, &junk, in xfs_swap_extent_forks()
1378 if (xfs_inode_has_attr_fork(tip) && tip->i_af.if_nextents > 0 && in xfs_swap_extent_forks()
1379 tip->i_af.if_format != XFS_DINODE_FMT_LOCAL) { in xfs_swap_extent_forks()
1388 * block headers. We can't start changing the bmbt blocks until the in xfs_swap_extent_forks()
1393 if (xfs_has_v3inodes(ip->i_mount)) { in xfs_swap_extent_forks()
1394 if (ip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1396 if (tip->i_df.if_format == XFS_DINODE_FMT_BTREE) in xfs_swap_extent_forks()
1403 swap(ip->i_df, tip->i_df); in xfs_swap_extent_forks()
1406 * Fix the on-disk inode values in xfs_swap_extent_forks()
1408 tmp = (uint64_t)ip->i_nblocks; in xfs_swap_extent_forks()
1409 ip->i_nblocks = tip->i_nblocks - taforkblks + aforkblks; in xfs_swap_extent_forks()
1410 tip->i_nblocks = tmp + taforkblks - aforkblks; in xfs_swap_extent_forks()
1421 ASSERT(tip->i_delayed_blks == 0); in xfs_swap_extent_forks()
1422 tip->i_delayed_blks = ip->i_delayed_blks; in xfs_swap_extent_forks()
1423 ip->i_delayed_blks = 0; in xfs_swap_extent_forks()
1425 switch (ip->i_df.if_format) { in xfs_swap_extent_forks()
1430 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1436 switch (tip->i_df.if_format) { in xfs_swap_extent_forks()
1442 ASSERT(!xfs_has_v3inodes(ip->i_mount) || in xfs_swap_extent_forks()
1454 * physically logged as a fallback and the scan returns -EAGAIN. We must roll
1461 struct xfs_inode *ip, in xfs_swap_change_owner() argument
1468 error = xfs_bmbt_change_owner(tp, ip, XFS_DATA_FORK, ip->i_ino, in xfs_swap_change_owner()
1471 if (error != -EAGAIN) in xfs_swap_change_owner()
1483 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_change_owner()
1485 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_swap_change_owner()
1494 struct xfs_inode *ip, /* target inode */ in xfs_swap_extents() argument
1498 struct xfs_mount *mp = ip->i_mount; in xfs_swap_extents()
1500 struct xfs_bstat *sbp = &sxp->sx_stat; in xfs_swap_extents()
1514 lock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()
1515 filemap_invalidate_lock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1516 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1519 if ((VFS_I(ip)->i_mode & S_IFMT) != (VFS_I(tip)->i_mode & S_IFMT)) { in xfs_swap_extents()
1520 error = -EINVAL; in xfs_swap_extents()
1524 /* Verify both files are either real-time or non-realtime */ in xfs_swap_extents()
1525 if (XFS_IS_REALTIME_INODE(ip) != XFS_IS_REALTIME_INODE(tip)) { in xfs_swap_extents()
1526 error = -EINVAL; in xfs_swap_extents()
1530 error = xfs_qm_dqattach(ip); in xfs_swap_extents()
1538 error = xfs_swap_extent_flush(ip); in xfs_swap_extents()
1553 * a block reservation because it's really just a remap operation in xfs_swap_extents()
1558 uint32_t ipnext = ip->i_df.if_nextents; in xfs_swap_extents()
1559 uint32_t tipnext = tip->i_df.if_nextents; in xfs_swap_extents()
1570 * If either inode straddles a bmapbt block allocation boundary, in xfs_swap_extents()
1572 * extents are remapped. This can exhaust the block reservation in xfs_swap_extents()
1578 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, flags, in xfs_swap_extents()
1587 xfs_lock_two_inodes(ip, XFS_ILOCK_EXCL, tip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1588 xfs_trans_ijoin(tp, ip, 0); in xfs_swap_extents()
1593 if (sxp->sx_offset != 0 || in xfs_swap_extents()
1594 sxp->sx_length != ip->i_disk_size || in xfs_swap_extents()
1595 sxp->sx_length != tip->i_disk_size) { in xfs_swap_extents()
1596 error = -EFAULT; in xfs_swap_extents()
1600 trace_xfs_swap_extent_before(ip, 0); in xfs_swap_extents()
1604 error = xfs_swap_extents_check_format(ip, tip); in xfs_swap_extents()
1608 __func__, ip->i_ino); in xfs_swap_extents()
1619 ctime = inode_get_ctime(VFS_I(ip)); in xfs_swap_extents()
1620 mtime = inode_get_mtime(VFS_I(ip)); in xfs_swap_extents()
1621 if ((sbp->bs_ctime.tv_sec != ctime.tv_sec) || in xfs_swap_extents()
1622 (sbp->bs_ctime.tv_nsec != ctime.tv_nsec) || in xfs_swap_extents()
1623 (sbp->bs_mtime.tv_sec != mtime.tv_sec) || in xfs_swap_extents()
1624 (sbp->bs_mtime.tv_nsec != mtime.tv_nsec)) { in xfs_swap_extents()
1625 error = -EBUSY; in xfs_swap_extents()
1630 * Note the trickiness in setting the log flags - we set the owner log in xfs_swap_extents()
1634 * not the pre-swapped inodes. in xfs_swap_extents()
1640 error = xfs_swap_extent_rmap(&tp, ip, tip); in xfs_swap_extents()
1642 error = xfs_swap_extent_forks(tp, ip, tip, &src_log_flags, in xfs_swap_extents()
1648 if ((ip->i_diflags2 & XFS_DIFLAG2_REFLINK) ^ in xfs_swap_extents()
1649 (tip->i_diflags2 & XFS_DIFLAG2_REFLINK)) { in xfs_swap_extents()
1650 f = ip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1651 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1652 ip->i_diflags2 |= tip->i_diflags2 & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1653 tip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1654 tip->i_diflags2 |= f & XFS_DIFLAG2_REFLINK; in xfs_swap_extents()
1659 ASSERT(!ip->i_cowfp || in xfs_swap_extents()
1660 ip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1661 ASSERT(!tip->i_cowfp || in xfs_swap_extents()
1662 tip->i_cowfp->if_format == XFS_DINODE_FMT_EXTENTS); in xfs_swap_extents()
1664 swap(ip->i_cowfp, tip->i_cowfp); in xfs_swap_extents()
1666 if (ip->i_cowfp && ip->i_cowfp->if_bytes) in xfs_swap_extents()
1667 xfs_inode_set_cowblocks_tag(ip); in xfs_swap_extents()
1669 xfs_inode_clear_cowblocks_tag(ip); in xfs_swap_extents()
1670 if (tip->i_cowfp && tip->i_cowfp->if_bytes) in xfs_swap_extents()
1676 xfs_trans_log_inode(tp, ip, src_log_flags); in xfs_swap_extents()
1686 error = xfs_swap_change_owner(&tp, ip, tip); in xfs_swap_extents()
1691 error = xfs_swap_change_owner(&tp, tip, ip); in xfs_swap_extents()
1705 trace_xfs_swap_extent_after(ip, 0); in xfs_swap_extents()
1709 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_swap_extents()
1712 filemap_invalidate_unlock_two(VFS_I(ip)->i_mapping, in xfs_swap_extents()
1713 VFS_I(tip)->i_mapping); in xfs_swap_extents()
1714 unlock_two_nondirectories(VFS_I(ip), VFS_I(tip)); in xfs_swap_extents()