• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0+
39 * through the use of a copy-on-write mechanism. At a high level, that
40 * means that when we want to write to a shared block, we allocate a new
41 * block, write the data to the new block, and if that succeeds we map the
42 * new block into the file.
45 * of disk blocks to dirty-but-not-yet-mapped file blocks as long as
49 * The delalloc mechanism begins when the kernel wants to make a block
51 * create a delalloc mapping, which is a regular in-core extent, but without
53 * a flag that this is a delalloc mapping, and a worst-case estimate of how
63 * D: --RRRRRRSSSRRRRRRRR--- (data fork)
64 * C: ------DDDDDDD--------- (CoW fork)
72 * D: --RRRRRRSSSRRRRRRRR---
73 * C: ------UUUUUUU---------
75 * We want to adapt the delalloc mechanism for copy-on-write, since the
85 * Block-aligned directio writes will use the same mechanism as buffered
93 * D: --RRRRRRSSSRRRRRRRR---
94 * C: ------UUrrUUU---------
96 * CoW remapping must be done after the data block write completes,
98 * the new block has been written. Since the new mappings are kept in a
104 * only to remap the blocks that we've actually written out -- we must
109 * D: --RRRRRRrrSRRRRRRRR---
110 * C: ------UU--UUU---------
122 * Given an AG extent, find the lowest-numbered run of shared blocks
146 cur = xfs_refcountbt_init_cursor(pag->pag_mount, tp, agbp, pag); in xfs_reflink_find_shared()
158 * Trim the mapping to the next block where there's a change in the
160 * find the lowest-numbered extent of shared blocks that coincides with
161 * the given block mapping. If the shared extent overlaps the start of
169 struct xfs_inode *ip, in xfs_reflink_trim_around_shared() argument
173 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_trim_around_shared()
182 if (!xfs_is_cow_inode(ip) || !xfs_bmap_is_written_extent(irec)) { in xfs_reflink_trim_around_shared()
187 trace_xfs_reflink_trim_around_shared(ip, irec); in xfs_reflink_trim_around_shared()
189 pag = xfs_perag_get(mp, XFS_FSB_TO_AGNO(mp, irec->br_startblock)); in xfs_reflink_trim_around_shared()
190 agbno = XFS_FSB_TO_AGBNO(mp, irec->br_startblock); in xfs_reflink_trim_around_shared()
191 aglen = irec->br_blockcount; in xfs_reflink_trim_around_shared()
212 irec->br_blockcount = flen; in xfs_reflink_trim_around_shared()
223 irec->br_blockcount = fbno - agbno; in xfs_reflink_trim_around_shared()
229 struct xfs_inode *ip, in xfs_bmap_trim_cow() argument
234 if (xfs_is_always_cow_inode(ip) && in xfs_bmap_trim_cow()
235 !isnullstartblock(imap->br_startblock)) { in xfs_bmap_trim_cow()
241 return xfs_reflink_trim_around_shared(ip, imap, shared); in xfs_bmap_trim_cow()
246 struct xfs_inode *ip, in xfs_reflink_convert_cow_locked() argument
256 if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, &got)) in xfs_reflink_convert_cow_locked()
265 return -EIO; in xfs_reflink_convert_cow_locked()
272 error = xfs_bmap_add_extent_unwritten_real(NULL, ip, in xfs_reflink_convert_cow_locked()
277 } while (xfs_iext_next_extent(ip->i_cowfp, &icur, &got)); in xfs_reflink_convert_cow_locked()
285 struct xfs_inode *ip, in xfs_reflink_convert_cow() argument
289 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_convert_cow()
292 xfs_filblks_t count_fsb = end_fsb - offset_fsb; in xfs_reflink_convert_cow()
297 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_convert_cow()
298 error = xfs_reflink_convert_cow_locked(ip, offset_fsb, count_fsb); in xfs_reflink_convert_cow()
299 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_convert_cow()
310 struct xfs_inode *ip, in xfs_find_trim_cow_extent() argument
316 xfs_fileoff_t offset_fsb = imap->br_startoff; in xfs_find_trim_cow_extent()
317 xfs_filblks_t count_fsb = imap->br_blockcount; in xfs_find_trim_cow_extent()
326 if (!xfs_iext_lookup_extent(ip, ip->i_cowfp, offset_fsb, &icur, cmap)) in xfs_find_trim_cow_extent()
327 cmap->br_startoff = offset_fsb + count_fsb; in xfs_find_trim_cow_extent()
328 if (cmap->br_startoff > offset_fsb) { in xfs_find_trim_cow_extent()
329 xfs_trim_extent(imap, imap->br_startoff, in xfs_find_trim_cow_extent()
330 cmap->br_startoff - imap->br_startoff); in xfs_find_trim_cow_extent()
331 return xfs_bmap_trim_cow(ip, imap, shared); in xfs_find_trim_cow_extent()
335 if (isnullstartblock(cmap->br_startblock)) { in xfs_find_trim_cow_extent()
336 xfs_trim_extent(imap, cmap->br_startoff, cmap->br_blockcount); in xfs_find_trim_cow_extent()
340 /* real extent found - no need to allocate */ in xfs_find_trim_cow_extent()
348 struct xfs_inode *ip, in xfs_reflink_convert_unwritten() argument
353 xfs_fileoff_t offset_fsb = imap->br_startoff; in xfs_reflink_convert_unwritten()
354 xfs_filblks_t count_fsb = imap->br_blockcount; in xfs_reflink_convert_unwritten()
367 if (!convert_now || cmap->br_state == XFS_EXT_NORM) in xfs_reflink_convert_unwritten()
370 trace_xfs_reflink_convert_cow(ip, cmap); in xfs_reflink_convert_unwritten()
372 error = xfs_reflink_convert_cow_locked(ip, offset_fsb, count_fsb); in xfs_reflink_convert_unwritten()
374 cmap->br_state = XFS_EXT_NORM; in xfs_reflink_convert_unwritten()
381 struct xfs_inode *ip, in xfs_reflink_fill_cow_hole() argument
388 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_fill_cow_hole()
396 resaligned = xfs_aligned_fsb_count(imap->br_startoff, in xfs_reflink_fill_cow_hole()
397 imap->br_blockcount, xfs_get_cowextsz_hint(ip)); in xfs_reflink_fill_cow_hole()
400 xfs_iunlock(ip, *lockmode); in xfs_reflink_fill_cow_hole()
403 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, resblks, 0, in xfs_reflink_fill_cow_hole()
410 error = xfs_find_trim_cow_extent(ip, imap, cmap, shared, &found); in xfs_reflink_fill_cow_hole()
421 error = xfs_bmapi_write(tp, ip, imap->br_startoff, imap->br_blockcount, in xfs_reflink_fill_cow_hole()
427 xfs_inode_set_cowblocks_tag(ip); in xfs_reflink_fill_cow_hole()
433 return xfs_reflink_convert_unwritten(ip, imap, cmap, convert_now); in xfs_reflink_fill_cow_hole()
442 struct xfs_inode *ip, in xfs_reflink_fill_delalloc() argument
449 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_fill_delalloc()
456 xfs_iunlock(ip, *lockmode); in xfs_reflink_fill_delalloc()
459 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, 0, 0, in xfs_reflink_fill_delalloc()
466 error = xfs_find_trim_cow_extent(ip, imap, cmap, shared, in xfs_reflink_fill_delalloc()
476 ASSERT(isnullstartblock(cmap->br_startblock) || in xfs_reflink_fill_delalloc()
477 cmap->br_startblock == DELAYSTARTBLOCK); in xfs_reflink_fill_delalloc()
483 error = xfs_bmapi_write(tp, ip, cmap->br_startoff, in xfs_reflink_fill_delalloc()
484 cmap->br_blockcount, in xfs_reflink_fill_delalloc()
490 xfs_inode_set_cowblocks_tag(ip); in xfs_reflink_fill_delalloc()
494 } while (cmap->br_startoff + cmap->br_blockcount <= imap->br_startoff); in xfs_reflink_fill_delalloc()
496 return xfs_reflink_convert_unwritten(ip, imap, cmap, convert_now); in xfs_reflink_fill_delalloc()
506 struct xfs_inode *ip, in xfs_reflink_allocate_cow() argument
516 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in xfs_reflink_allocate_cow()
517 if (!ip->i_cowfp) { in xfs_reflink_allocate_cow()
518 ASSERT(!xfs_is_reflink_inode(ip)); in xfs_reflink_allocate_cow()
519 xfs_ifork_init_cow(ip); in xfs_reflink_allocate_cow()
522 error = xfs_find_trim_cow_extent(ip, imap, cmap, shared, &found); in xfs_reflink_allocate_cow()
528 return xfs_reflink_convert_unwritten(ip, imap, cmap, in xfs_reflink_allocate_cow()
535 if (cmap->br_startoff > imap->br_startoff) in xfs_reflink_allocate_cow()
536 return xfs_reflink_fill_cow_hole(ip, imap, cmap, shared, in xfs_reflink_allocate_cow()
543 if (isnullstartblock(cmap->br_startblock) || in xfs_reflink_allocate_cow()
544 cmap->br_startblock == DELAYSTARTBLOCK) in xfs_reflink_allocate_cow()
545 return xfs_reflink_fill_delalloc(ip, imap, cmap, shared, in xfs_reflink_allocate_cow()
550 return -EFSCORRUPTED; in xfs_reflink_allocate_cow()
554 * Cancel CoW reservations for some block range of an inode.
564 struct xfs_inode *ip, in xfs_reflink_cancel_cow_blocks() argument
570 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); in xfs_reflink_cancel_cow_blocks()
575 if (!xfs_inode_has_cow_data(ip)) in xfs_reflink_cancel_cow_blocks()
577 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_reflink_cancel_cow_blocks()
583 xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb); in xfs_reflink_cancel_cow_blocks()
591 trace_xfs_reflink_cancel_cow(ip, &del); in xfs_reflink_cancel_cow_blocks()
594 error = xfs_bmap_del_extent_delay(ip, XFS_COW_FORK, in xfs_reflink_cancel_cow_blocks()
599 ASSERT((*tpp)->t_highest_agno == NULLAGNUMBER); in xfs_reflink_cancel_cow_blocks()
617 xfs_bmap_del_extent_cow(ip, &icur, &got, &del); in xfs_reflink_cancel_cow_blocks()
620 error = xfs_quota_unreserve_blkres(ip, in xfs_reflink_cancel_cow_blocks()
634 if (!ifp->if_bytes) in xfs_reflink_cancel_cow_blocks()
635 xfs_inode_clear_cowblocks_tag(ip); in xfs_reflink_cancel_cow_blocks()
647 struct xfs_inode *ip, in xfs_reflink_cancel_cow_range() argument
657 trace_xfs_reflink_cancel_cow_range(ip, offset, count); in xfs_reflink_cancel_cow_range()
658 ASSERT(ip->i_cowfp); in xfs_reflink_cancel_cow_range()
660 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); in xfs_reflink_cancel_cow_range()
664 end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); in xfs_reflink_cancel_cow_range()
667 error = xfs_trans_alloc(ip->i_mount, &M_RES(ip->i_mount)->tr_write, in xfs_reflink_cancel_cow_range()
672 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_cancel_cow_range()
673 xfs_trans_ijoin(tp, ip, 0); in xfs_reflink_cancel_cow_range()
676 error = xfs_reflink_cancel_cow_blocks(ip, &tp, offset_fsb, end_fsb, in xfs_reflink_cancel_cow_range()
683 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_cancel_cow_range()
688 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_cancel_cow_range()
690 trace_xfs_reflink_cancel_cow_range_error(ip, error, _RET_IP_); in xfs_reflink_cancel_cow_range()
701 * every remap operation and we'd like to keep the block reservation
706 struct xfs_inode *ip, in xfs_reflink_end_cow_extent() argument
712 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_end_cow_extent()
714 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); in xfs_reflink_end_cow_extent()
720 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, in xfs_reflink_end_cow_extent()
730 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_end_cow_extent()
731 xfs_trans_ijoin(tp, ip, 0); in xfs_reflink_end_cow_extent()
733 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_reflink_end_cow_extent()
735 if (error == -EFBIG) in xfs_reflink_end_cow_extent()
736 error = xfs_iext_count_upgrade(tp, ip, in xfs_reflink_end_cow_extent()
746 if (!xfs_iext_lookup_extent(ip, ifp, *offset_fsb, &icur, &got) || in xfs_reflink_end_cow_extent()
767 xfs_trim_extent(&del, *offset_fsb, end_fsb - *offset_fsb); in xfs_reflink_end_cow_extent()
771 error = xfs_bmapi_read(ip, del.br_startoff, del.br_blockcount, &data, in xfs_reflink_end_cow_extent()
780 trace_xfs_reflink_cow_remap_from(ip, &del); in xfs_reflink_end_cow_extent()
781 trace_xfs_reflink_cow_remap_to(ip, &data); in xfs_reflink_end_cow_extent()
788 xfs_bmap_unmap_extent(tp, ip, &data); in xfs_reflink_end_cow_extent()
790 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, in xfs_reflink_end_cow_extent()
791 -data.br_blockcount); in xfs_reflink_end_cow_extent()
801 error = xfs_bunmapi(NULL, ip, data.br_startoff, in xfs_reflink_end_cow_extent()
812 xfs_bmap_map_extent(tp, ip, &del); in xfs_reflink_end_cow_extent()
814 /* Charge this new data fork mapping to the on-disk quota. */ in xfs_reflink_end_cow_extent()
815 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_DELBCOUNT, in xfs_reflink_end_cow_extent()
819 xfs_bmap_del_extent_cow(ip, &icur, &got, &del); in xfs_reflink_end_cow_extent()
822 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_end_cow_extent()
832 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_end_cow_extent()
841 struct xfs_inode *ip, in xfs_reflink_end_cow() argument
849 trace_xfs_reflink_end_cow(ip, offset, count); in xfs_reflink_end_cow()
851 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); in xfs_reflink_end_cow()
852 end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); in xfs_reflink_end_cow()
867 * region. There are also have post-eof checks in the writeback in xfs_reflink_end_cow()
887 error = xfs_reflink_end_cow_extent(ip, &offset_fsb, end_fsb); in xfs_reflink_end_cow()
890 trace_xfs_reflink_end_cow_error(ip, error, _RET_IP_); in xfs_reflink_end_cow()
923 * Reflinking (Block) Ranges of Two Files Together
933 * - Read src's bmbt at the start of srange ("imap")
934 * - If imap doesn't exist, make imap appear to start at the end of srange
936 * - If imap starts before srange, advance imap to start at srange.
937 * - If imap goes beyond srange, truncate imap to end at the end of srange.
938 * - Punch (imap start - srange start + imap len) blocks from dest at
940 * - If imap points to a real range of pblks,
943 * (drange start + imap start - srange start)
944 * - Advance drange and srange by (imap start - srange start + imap len)
946 * Finally, if the reflink made dest longer, update both the in-core and
947 * on-disk file sizes.
953 * ----SSSSSSS-SSSSS----SSSSSS (src file)
954 * <-------------------->
958 * --DDDDDDDDDDDDDDDDDDD--DDD (dest file)
959 * <-------------------->
960 * '-' means a hole, and 'S' and 'D' are written blocks in the src and dest.
967 * ----SSSSSSS-SSSSS----SSSSSS
968 * <------->
969 * --DDDDD---------DDDDD--DDD
970 * <------->
974 * ----SSSSSSS-SSSSS----SSSSSS
975 * <------->
976 * --DDDDD--SSSSSSSDDDDD--DDD
977 * <------->
982 * ----SSSSSSS-SSSSS----SSSSSS
983 * <---->
984 * --DDDDD--SSSSSSS-SSSSS-DDD
985 * <---->
990 * ----SSSSSSS-SSSSS----SSSSSS
991 * <----->
992 * --DDDDD--SSSSSSS-SSSSS----SSS
993 * <----->
1006 struct xfs_mount *mp = src->i_mount; in xfs_reflink_set_inode_flag()
1013 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); in xfs_reflink_set_inode_flag()
1018 if (src->i_ino == dest->i_ino) in xfs_reflink_set_inode_flag()
1026 src->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_reflink_set_inode_flag()
1032 if (src->i_ino == dest->i_ino) in xfs_reflink_set_inode_flag()
1038 dest->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_reflink_set_inode_flag()
1065 struct xfs_mount *mp = dest->i_mount; in xfs_reflink_update_dest()
1072 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); in xfs_reflink_update_dest()
1082 dest->i_disk_size = newlen; in xfs_reflink_update_dest()
1086 dest->i_cowextsize = cowextsize; in xfs_reflink_update_dest()
1087 dest->i_diflags2 |= XFS_DIFLAG2_COWEXTSIZE; in xfs_reflink_update_dest()
1122 error = -ENOSPC; in xfs_reflink_ag_has_free_space()
1133 struct xfs_inode *ip, in xfs_reflink_remap_extent() argument
1138 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_remap_extent()
1172 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_reflink_remap_extent()
1173 resblks + dmap->br_blockcount, 0, false, &tp); in xfs_reflink_remap_extent()
1174 if (error == -EDQUOT || error == -ENOSPC) { in xfs_reflink_remap_extent()
1176 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_reflink_remap_extent()
1188 error = xfs_bmapi_read(ip, dmap->br_startoff, dmap->br_blockcount, in xfs_reflink_remap_extent()
1192 ASSERT(nimaps == 1 && smap.br_startoff == dmap->br_startoff); in xfs_reflink_remap_extent()
1199 dmap->br_blockcount = min(dmap->br_blockcount, smap.br_blockcount); in xfs_reflink_remap_extent()
1200 ASSERT(dmap->br_blockcount == smap.br_blockcount); in xfs_reflink_remap_extent()
1202 trace_xfs_reflink_remap_extent_dest(ip, &smap); in xfs_reflink_remap_extent()
1205 * Two extents mapped to the same physical block must not have in xfs_reflink_remap_extent()
1209 if (dmap->br_startblock == smap.br_startblock) { in xfs_reflink_remap_extent()
1210 if (dmap->br_state != smap.br_state) in xfs_reflink_remap_extent()
1211 error = -EFSCORRUPTED; in xfs_reflink_remap_extent()
1216 if (dmap->br_state == XFS_EXT_UNWRITTEN && in xfs_reflink_remap_extent()
1223 XFS_FSB_TO_AGNO(mp, dmap->br_startblock)); in xfs_reflink_remap_extent()
1229 * Increase quota reservation if we think the quota block counter for in xfs_reflink_remap_extent()
1233 * enough quota block count reservation to handle the blocks in that in xfs_reflink_remap_extent()
1234 * extent. We log only the delta to the quota block counts, so if the in xfs_reflink_remap_extent()
1240 * the delalloc reservation gives the block count back to the quota in xfs_reflink_remap_extent()
1251 error = xfs_trans_reserve_quota_nblks(tp, ip, in xfs_reflink_remap_extent()
1252 dmap->br_blockcount, 0, false); in xfs_reflink_remap_extent()
1263 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, iext_delta); in xfs_reflink_remap_extent()
1264 if (error == -EFBIG) in xfs_reflink_remap_extent()
1265 error = xfs_iext_count_upgrade(tp, ip, iext_delta); in xfs_reflink_remap_extent()
1274 xfs_bmap_unmap_extent(tp, ip, &smap); in xfs_reflink_remap_extent()
1276 qdelta -= smap.br_blockcount; in xfs_reflink_remap_extent()
1286 error = xfs_bunmapi(NULL, ip, smap.br_startoff, in xfs_reflink_remap_extent()
1299 xfs_bmap_map_extent(tp, ip, dmap); in xfs_reflink_remap_extent()
1300 qdelta += dmap->br_blockcount; in xfs_reflink_remap_extent()
1303 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, qdelta); in xfs_reflink_remap_extent()
1306 newlen = XFS_FSB_TO_B(mp, dmap->br_startoff + dmap->br_blockcount); in xfs_reflink_remap_extent()
1308 if (newlen > i_size_read(VFS_I(ip))) { in xfs_reflink_remap_extent()
1309 trace_xfs_reflink_update_inode_size(ip, newlen); in xfs_reflink_remap_extent()
1310 i_size_write(VFS_I(ip), newlen); in xfs_reflink_remap_extent()
1311 ip->i_disk_size = newlen; in xfs_reflink_remap_extent()
1312 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_reflink_remap_extent()
1322 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_remap_extent()
1325 trace_xfs_reflink_remap_extent_error(ip, error, _RET_IP_); in xfs_reflink_remap_extent()
1340 struct xfs_mount *mp = src->i_mount; in xfs_reflink_remap_blocks()
1374 error = -EFSCORRUPTED; in xfs_reflink_remap_blocks()
1387 error = -EINTR; in xfs_reflink_remap_blocks()
1394 len -= imap.br_blockcount; in xfs_reflink_remap_blocks()
1401 XFS_FSB_TO_B(src->i_mount, remapped_len)); in xfs_reflink_remap_blocks()
1407 * zero any speculative post-EOF preallocations that sit between the old EOF
1412 struct xfs_inode *ip, in xfs_reflink_zero_posteof() argument
1415 loff_t isize = i_size_read(VFS_I(ip)); in xfs_reflink_zero_posteof()
1420 trace_xfs_zero_eof(ip, isize, pos - isize); in xfs_reflink_zero_posteof()
1421 return xfs_zero_range(ip, isize, pos - isize, NULL); in xfs_reflink_zero_posteof()
1432 * EOF block in the source dedupe range because it's not a complete block match,
1433 * hence can introduce a corruption into the file that has it's block replaced.
1436 * "block aligned" for the purposes of cloning entire files. However, if the
1437 * source file range includes the EOF block and it lands within the existing EOF
1441 * XFS doesn't support partial block sharing, so in both cases we have check
1443 * down to the previous whole block and ignore the partial EOF block. While this
1444 * means we can't dedupe the last block of a file, this is an acceptible
1447 * For cloning, we want to share the partial EOF block if it is also the new EOF
1448 * block of the destination file. If the partial EOF block lies inside the
1451 * -EINVAL in this case.
1473 /* Check file eligibility and prepare for block sharing. */ in xfs_reflink_remap_prep()
1474 ret = -EINVAL; in xfs_reflink_remap_prep()
1479 /* Don't share DAX file data with non-DAX file. */ in xfs_reflink_remap_prep()
1492 /* Attach dquots to dest inode before changing block map */ in xfs_reflink_remap_prep()
1498 * Zero existing post-eof speculative preallocations in the destination in xfs_reflink_remap_prep()
1516 loff_t flen = *len + (pos_out - XFS_ISIZE(dest)); in xfs_reflink_remap_prep()
1538 struct xfs_inode *ip, in xfs_reflink_inode_has_shared_extents() argument
1542 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_inode_has_shared_extents()
1548 ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); in xfs_reflink_inode_has_shared_extents()
1549 error = xfs_iread_extents(tp, ip, XFS_DATA_FORK); in xfs_reflink_inode_has_shared_extents()
1554 found = xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got); in xfs_reflink_inode_has_shared_extents()
1575 /* Is there still a shared block here? */ in xfs_reflink_inode_has_shared_extents()
1595 struct xfs_inode *ip, in xfs_reflink_clear_inode_flag() argument
1601 ASSERT(xfs_is_reflink_inode(ip)); in xfs_reflink_clear_inode_flag()
1603 if (!xfs_can_free_cowblocks(ip)) in xfs_reflink_clear_inode_flag()
1606 error = xfs_reflink_inode_has_shared_extents(*tpp, ip, &needs_flag); in xfs_reflink_clear_inode_flag()
1614 error = xfs_reflink_cancel_cow_blocks(ip, tpp, 0, XFS_MAX_FILEOFF, in xfs_reflink_clear_inode_flag()
1620 trace_xfs_reflink_unset_inode_flag(ip); in xfs_reflink_clear_inode_flag()
1621 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_reflink_clear_inode_flag()
1622 xfs_inode_clear_cowblocks_tag(ip); in xfs_reflink_clear_inode_flag()
1623 xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE); in xfs_reflink_clear_inode_flag()
1634 struct xfs_inode *ip) in xfs_reflink_try_clear_inode_flag() argument
1636 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_try_clear_inode_flag()
1641 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_reflink_try_clear_inode_flag()
1645 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_try_clear_inode_flag()
1646 xfs_trans_ijoin(tp, ip, 0); in xfs_reflink_try_clear_inode_flag()
1648 error = xfs_reflink_clear_inode_flag(ip, &tp); in xfs_reflink_try_clear_inode_flag()
1656 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_try_clear_inode_flag()
1661 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_try_clear_inode_flag()
1666 * Pre-COW all shared blocks within a given byte range of a file and turn off
1671 struct xfs_inode *ip, in xfs_reflink_unshare() argument
1675 struct inode *inode = VFS_I(ip); in xfs_reflink_unshare()
1678 if (!xfs_is_reflink_inode(ip)) in xfs_reflink_unshare()
1681 trace_xfs_reflink_unshare(ip, offset, len); in xfs_reflink_unshare()
1694 error = filemap_write_and_wait_range(inode->i_mapping, offset, in xfs_reflink_unshare()
1695 offset + len - 1); in xfs_reflink_unshare()
1700 error = xfs_reflink_try_clear_inode_flag(ip); in xfs_reflink_unshare()
1706 trace_xfs_reflink_unshare_error(ip, error, _RET_IP_); in xfs_reflink_unshare()