Lines Matching +full:ip +full:- +full:blocks
1 // SPDX-License-Identifier: GPL-2.0+
34 * Copy on Write of Shared Blocks
37 * the same physical blocks. This means that a write to one file must not
38 * alter the blocks in a different file; the way that we'll do that is
39 * through the use of a copy-on-write mechanism. At a high level, that
45 * of disk blocks to dirty-but-not-yet-mapped file blocks as long as
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
54 * many blocks might be required to put the mapping into the BMBT.) delalloc
63 * D: --RRRRRRSSSRRRRRRRR--- (data fork)
64 * C: ------DDDDDDD--------- (CoW fork)
68 * allocating blocks and replacing the delalloc mapping with real ones.
72 * D: --RRRRRRSSSRRRRRRRR---
73 * C: ------UUUUUUU---------
75 * We want to adapt the delalloc mechanism for copy-on-write, since the
77 * and allocating the blocks) are exactly the same as delalloc except that
85 * Block-aligned directio writes will use the same mechanism as buffered
93 * D: --RRRRRRSSSRRRRRRRR---
94 * C: ------UUrrUUU---------
100 * that cover the file blocks that we just CoW'd. For each extent, simply
104 * only to remap the blocks that we've actually written out -- we must
105 * never remap delalloc reservations nor CoW staging blocks that have
109 * D: --RRRRRRrrSRRRRRRRR---
110 * C: ------UU--UUU---------
116 * remember the presence of unwritten blocks and CoW blocks with a single
122 * Given an AG extent, find the lowest-numbered run of shared blocks
125 * shared blocks. If there are no shared extents, fbno and flen will
146 cur = xfs_refcountbt_init_cursor(pag->pag_mount, tp, agbp, pag); in xfs_reflink_find_shared()
160 * find the lowest-numbered extent of shared blocks that coincides with
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()
201 /* No shared blocks at all. */ 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()
419 ASSERT(cmap->br_startoff > imap->br_startoff); in xfs_reflink_fill_cow_hole()
421 /* Allocate the entire reservation as unwritten blocks. */ in xfs_reflink_fill_cow_hole()
423 error = xfs_bmapi_write(tp, ip, imap->br_startoff, imap->br_blockcount, in xfs_reflink_fill_cow_hole()
429 xfs_inode_set_cowblocks_tag(ip); in xfs_reflink_fill_cow_hole()
439 return -ENOSPC; in xfs_reflink_fill_cow_hole()
442 return xfs_reflink_convert_unwritten(ip, imap, cmap, convert_now); in xfs_reflink_fill_cow_hole()
451 struct xfs_inode *ip, in xfs_reflink_fill_delalloc() argument
458 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_fill_delalloc()
465 xfs_iunlock(ip, *lockmode); in xfs_reflink_fill_delalloc()
468 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, 0, 0, in xfs_reflink_fill_delalloc()
475 error = xfs_find_trim_cow_extent(ip, imap, cmap, shared, in xfs_reflink_fill_delalloc()
485 ASSERT(isnullstartblock(cmap->br_startblock) || in xfs_reflink_fill_delalloc()
486 cmap->br_startblock == DELAYSTARTBLOCK); in xfs_reflink_fill_delalloc()
492 error = xfs_bmapi_write(tp, ip, cmap->br_startoff, in xfs_reflink_fill_delalloc()
493 cmap->br_blockcount, in xfs_reflink_fill_delalloc()
499 xfs_inode_set_cowblocks_tag(ip); in xfs_reflink_fill_delalloc()
509 return -ENOSPC; in xfs_reflink_fill_delalloc()
510 } while (cmap->br_startoff + cmap->br_blockcount <= imap->br_startoff); in xfs_reflink_fill_delalloc()
512 return xfs_reflink_convert_unwritten(ip, imap, cmap, convert_now); in xfs_reflink_fill_delalloc()
519 /* Allocate all CoW reservations covering a range of blocks in a file. */
522 struct xfs_inode *ip, in xfs_reflink_allocate_cow() argument
532 ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL)); in xfs_reflink_allocate_cow()
533 if (!ip->i_cowfp) { in xfs_reflink_allocate_cow()
534 ASSERT(!xfs_is_reflink_inode(ip)); in xfs_reflink_allocate_cow()
535 xfs_ifork_init_cow(ip); in xfs_reflink_allocate_cow()
538 error = xfs_find_trim_cow_extent(ip, imap, cmap, shared, &found); in xfs_reflink_allocate_cow()
544 return xfs_reflink_convert_unwritten(ip, imap, cmap, in xfs_reflink_allocate_cow()
551 if (cmap->br_startoff > imap->br_startoff) in xfs_reflink_allocate_cow()
552 return xfs_reflink_fill_cow_hole(ip, imap, cmap, shared, in xfs_reflink_allocate_cow()
559 if (isnullstartblock(cmap->br_startblock) || in xfs_reflink_allocate_cow()
560 cmap->br_startblock == DELAYSTARTBLOCK) in xfs_reflink_allocate_cow()
561 return xfs_reflink_fill_delalloc(ip, imap, cmap, shared, in xfs_reflink_allocate_cow()
566 return -EFSCORRUPTED; in xfs_reflink_allocate_cow()
580 struct xfs_inode *ip, in xfs_reflink_cancel_cow_blocks() argument
586 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); in xfs_reflink_cancel_cow_blocks()
591 if (!xfs_inode_has_cow_data(ip)) in xfs_reflink_cancel_cow_blocks()
593 if (!xfs_iext_lookup_extent_before(ip, ifp, &end_fsb, &icur, &got)) in xfs_reflink_cancel_cow_blocks()
599 xfs_trim_extent(&del, offset_fsb, end_fsb - offset_fsb); in xfs_reflink_cancel_cow_blocks()
607 trace_xfs_reflink_cancel_cow(ip, &del); in xfs_reflink_cancel_cow_blocks()
610 error = xfs_bmap_del_extent_delay(ip, XFS_COW_FORK, in xfs_reflink_cancel_cow_blocks()
615 ASSERT((*tpp)->t_firstblock == NULLFSBLOCK); in xfs_reflink_cancel_cow_blocks()
630 xfs_bmap_del_extent_cow(ip, &icur, &got, &del); in xfs_reflink_cancel_cow_blocks()
633 error = xfs_quota_unreserve_blkres(ip, in xfs_reflink_cancel_cow_blocks()
647 if (!ifp->if_bytes) in xfs_reflink_cancel_cow_blocks()
648 xfs_inode_clear_cowblocks_tag(ip); in xfs_reflink_cancel_cow_blocks()
660 struct xfs_inode *ip, in xfs_reflink_cancel_cow_range() argument
670 trace_xfs_reflink_cancel_cow_range(ip, offset, count); in xfs_reflink_cancel_cow_range()
671 ASSERT(ip->i_cowfp); in xfs_reflink_cancel_cow_range()
673 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); in xfs_reflink_cancel_cow_range()
677 end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); in xfs_reflink_cancel_cow_range()
680 error = xfs_trans_alloc(ip->i_mount, &M_RES(ip->i_mount)->tr_write, in xfs_reflink_cancel_cow_range()
685 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_cancel_cow_range()
686 xfs_trans_ijoin(tp, ip, 0); in xfs_reflink_cancel_cow_range()
689 error = xfs_reflink_cancel_cow_blocks(ip, &tp, offset_fsb, end_fsb, in xfs_reflink_cancel_cow_range()
696 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_cancel_cow_range()
701 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_cancel_cow_range()
703 trace_xfs_reflink_cancel_cow_range_error(ip, error, _RET_IP_); in xfs_reflink_cancel_cow_range()
713 * transaction because we can end up merging and splitting bmbt blocks for
719 struct xfs_inode *ip, in xfs_reflink_end_cow_extent() argument
725 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_end_cow_extent()
727 struct xfs_ifork *ifp = xfs_ifork_ptr(ip, XFS_COW_FORK); in xfs_reflink_end_cow_extent()
733 if (ifp->if_bytes == 0) { in xfs_reflink_end_cow_extent()
739 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, resblks, 0, in xfs_reflink_end_cow_extent()
749 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_end_cow_extent()
750 xfs_trans_ijoin(tp, ip, 0); in xfs_reflink_end_cow_extent()
752 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, in xfs_reflink_end_cow_extent()
754 if (error == -EFBIG) in xfs_reflink_end_cow_extent()
755 error = xfs_iext_count_upgrade(tp, ip, in xfs_reflink_end_cow_extent()
765 if (!xfs_iext_lookup_extent(ip, ifp, *offset_fsb, &icur, &got) || in xfs_reflink_end_cow_extent()
789 error = xfs_bmapi_read(ip, del.br_startoff, del.br_blockcount, &data, in xfs_reflink_end_cow_extent()
798 trace_xfs_reflink_cow_remap_from(ip, &del); in xfs_reflink_end_cow_extent()
799 trace_xfs_reflink_cow_remap_to(ip, &data); in xfs_reflink_end_cow_extent()
806 xfs_bmap_unmap_extent(tp, ip, &data); in xfs_reflink_end_cow_extent()
808 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, in xfs_reflink_end_cow_extent()
809 -data.br_blockcount); in xfs_reflink_end_cow_extent()
819 error = xfs_bunmapi(NULL, ip, data.br_startoff, in xfs_reflink_end_cow_extent()
829 /* Map the new blocks into the data fork. */ in xfs_reflink_end_cow_extent()
830 xfs_bmap_map_extent(tp, ip, &del); in xfs_reflink_end_cow_extent()
832 /* Charge this new data fork mapping to the on-disk quota. */ in xfs_reflink_end_cow_extent()
833 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_DELBCOUNT, in xfs_reflink_end_cow_extent()
837 xfs_bmap_del_extent_cow(ip, &icur, &got, &del); in xfs_reflink_end_cow_extent()
840 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_end_cow_extent()
850 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_end_cow_extent()
859 struct xfs_inode *ip, in xfs_reflink_end_cow() argument
867 trace_xfs_reflink_end_cow(ip, offset, count); in xfs_reflink_end_cow()
869 offset_fsb = XFS_B_TO_FSBT(ip->i_mount, offset); in xfs_reflink_end_cow()
870 end_fsb = XFS_B_TO_FSB(ip->i_mount, offset + count); in xfs_reflink_end_cow()
885 * region. There are also have post-eof checks in the writeback in xfs_reflink_end_cow()
902 * blocks will be remapped. in xfs_reflink_end_cow()
905 error = xfs_reflink_end_cow_extent(ip, &offset_fsb, end_fsb); in xfs_reflink_end_cow()
908 trace_xfs_reflink_end_cow_error(ip, error, _RET_IP_); in xfs_reflink_end_cow()
913 * Free all CoW staging blocks that are still referenced by the ondisk refcount
948 * logical blocks in dest and src touched by the reflink operation.
951 * - Read src's bmbt at the start of srange ("imap")
952 * - If imap doesn't exist, make imap appear to start at the end of srange
954 * - If imap starts before srange, advance imap to start at srange.
955 * - If imap goes beyond srange, truncate imap to end at the end of srange.
956 * - Punch (imap start - srange start + imap len) blocks from dest at
958 * - If imap points to a real range of pblks,
961 * (drange start + imap start - srange start)
962 * - Advance drange and srange by (imap start - srange start + imap len)
964 * Finally, if the reflink made dest longer, update both the in-core and
965 * on-disk file sizes.
971 * ----SSSSSSS-SSSSS----SSSSSS (src file)
972 * <-------------------->
976 * --DDDDDDDDDDDDDDDDDDD--DDD (dest file)
977 * <-------------------->
978 * '-' means a hole, and 'S' and 'D' are written blocks in the src and dest.
983 * unmap more blocks from the destination file than we remap.
985 * ----SSSSSSS-SSSSS----SSSSSS
986 * <------->
987 * --DDDDD---------DDDDD--DDD
988 * <------->
992 * ----SSSSSSS-SSSSS----SSSSSS
993 * <------->
994 * --DDDDD--SSSSSSSDDDDD--DDD
995 * <------->
1000 * ----SSSSSSS-SSSSS----SSSSSS
1001 * <---->
1002 * --DDDDD--SSSSSSS-SSSSS-DDD
1003 * <---->
1008 * ----SSSSSSS-SSSSS----SSSSSS
1009 * <----->
1010 * --DDDDD--SSSSSSS-SSSSS----SSS
1011 * <----->
1024 struct xfs_mount *mp = src->i_mount; in xfs_reflink_set_inode_flag()
1031 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); in xfs_reflink_set_inode_flag()
1036 if (src->i_ino == dest->i_ino) in xfs_reflink_set_inode_flag()
1044 src->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_reflink_set_inode_flag()
1050 if (src->i_ino == dest->i_ino) in xfs_reflink_set_inode_flag()
1056 dest->i_diflags2 |= XFS_DIFLAG2_REFLINK; in xfs_reflink_set_inode_flag()
1083 struct xfs_mount *mp = dest->i_mount; in xfs_reflink_update_dest()
1090 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_ichange, 0, 0, 0, &tp); in xfs_reflink_update_dest()
1100 dest->i_disk_size = newlen; in xfs_reflink_update_dest()
1104 dest->i_cowextsize = cowextsize; in xfs_reflink_update_dest()
1105 dest->i_diflags2 |= XFS_DIFLAG2_COWEXTSIZE; in xfs_reflink_update_dest()
1140 error = -ENOSPC; in xfs_reflink_ag_has_free_space()
1147 * the number of blocks that were actually remapped.
1151 struct xfs_inode *ip, in xfs_reflink_remap_extent() argument
1156 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_remap_extent()
1190 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_reflink_remap_extent()
1191 resblks + dmap->br_blockcount, 0, false, &tp); in xfs_reflink_remap_extent()
1192 if (error == -EDQUOT || error == -ENOSPC) { in xfs_reflink_remap_extent()
1194 error = xfs_trans_alloc_inode(ip, &M_RES(mp)->tr_write, in xfs_reflink_remap_extent()
1206 error = xfs_bmapi_read(ip, dmap->br_startoff, dmap->br_blockcount, in xfs_reflink_remap_extent()
1210 ASSERT(nimaps == 1 && smap.br_startoff == dmap->br_startoff); in xfs_reflink_remap_extent()
1214 * We can only remap as many blocks as the smaller of the two extent in xfs_reflink_remap_extent()
1217 dmap->br_blockcount = min(dmap->br_blockcount, smap.br_blockcount); in xfs_reflink_remap_extent()
1218 ASSERT(dmap->br_blockcount == smap.br_blockcount); in xfs_reflink_remap_extent()
1220 trace_xfs_reflink_remap_extent_dest(ip, &smap); in xfs_reflink_remap_extent()
1227 if (dmap->br_startblock == smap.br_startblock) { in xfs_reflink_remap_extent()
1228 if (dmap->br_state != smap.br_state) in xfs_reflink_remap_extent()
1229 error = -EFSCORRUPTED; in xfs_reflink_remap_extent()
1234 if (dmap->br_state == XFS_EXT_UNWRITTEN && in xfs_reflink_remap_extent()
1241 XFS_FSB_TO_AGNO(mp, dmap->br_startblock)); in xfs_reflink_remap_extent()
1251 * enough quota block count reservation to handle the blocks in that in xfs_reflink_remap_extent()
1253 * extent we're unmapping also has blocks allocated to it, we don't in xfs_reflink_remap_extent()
1269 error = xfs_trans_reserve_quota_nblks(tp, ip, in xfs_reflink_remap_extent()
1270 dmap->br_blockcount, 0, false); in xfs_reflink_remap_extent()
1281 error = xfs_iext_count_may_overflow(ip, XFS_DATA_FORK, iext_delta); in xfs_reflink_remap_extent()
1282 if (error == -EFBIG) in xfs_reflink_remap_extent()
1283 error = xfs_iext_count_upgrade(tp, ip, iext_delta); in xfs_reflink_remap_extent()
1292 xfs_bmap_unmap_extent(tp, ip, &smap); in xfs_reflink_remap_extent()
1294 qdelta -= smap.br_blockcount; in xfs_reflink_remap_extent()
1304 error = xfs_bunmapi(NULL, ip, smap.br_startoff, in xfs_reflink_remap_extent()
1317 xfs_bmap_map_extent(tp, ip, dmap); in xfs_reflink_remap_extent()
1318 qdelta += dmap->br_blockcount; in xfs_reflink_remap_extent()
1321 xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_BCOUNT, qdelta); in xfs_reflink_remap_extent()
1324 newlen = XFS_FSB_TO_B(mp, dmap->br_startoff + dmap->br_blockcount); in xfs_reflink_remap_extent()
1326 if (newlen > i_size_read(VFS_I(ip))) { in xfs_reflink_remap_extent()
1327 trace_xfs_reflink_update_inode_size(ip, newlen); in xfs_reflink_remap_extent()
1328 i_size_write(VFS_I(ip), newlen); in xfs_reflink_remap_extent()
1329 ip->i_disk_size = newlen; in xfs_reflink_remap_extent()
1330 xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); in xfs_reflink_remap_extent()
1340 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_remap_extent()
1343 trace_xfs_reflink_remap_extent_error(ip, error, _RET_IP_); in xfs_reflink_remap_extent()
1358 struct xfs_mount *mp = src->i_mount; in xfs_reflink_remap_blocks()
1392 error = -EFSCORRUPTED; in xfs_reflink_remap_blocks()
1405 error = -EINTR; in xfs_reflink_remap_blocks()
1412 len -= imap.br_blockcount; in xfs_reflink_remap_blocks()
1419 XFS_FSB_TO_B(src->i_mount, remapped_len)); in xfs_reflink_remap_blocks()
1425 * zero any speculative post-EOF preallocations that sit between the old EOF
1430 struct xfs_inode *ip, in xfs_reflink_zero_posteof() argument
1433 loff_t isize = i_size_read(VFS_I(ip)); in xfs_reflink_zero_posteof()
1438 trace_xfs_zero_eof(ip, isize, pos - isize); in xfs_reflink_zero_posteof()
1439 return xfs_zero_range(ip, isize, pos - isize, NULL); in xfs_reflink_zero_posteof()
1448 * The VFS allows partial EOF blocks to "match" for dedupe even though it hasn't
1453 * In similar fashion, the VFS file cloning also allows partial EOF blocks to be
1469 * -EINVAL in this case.
1492 ret = -EINVAL; in xfs_reflink_remap_prep()
1497 /* Don't share DAX file data with non-DAX file. */ in xfs_reflink_remap_prep()
1516 * Zero existing post-eof speculative preallocations in the destination in xfs_reflink_remap_prep()
1523 /* Set flags and remap blocks. */ in xfs_reflink_remap_prep()
1529 * If pos_out > EOF, we may have dirtied blocks between EOF and in xfs_reflink_remap_prep()
1534 loff_t flen = *len + (pos_out - XFS_ISIZE(dest)); in xfs_reflink_remap_prep()
1552 struct xfs_inode *ip, in xfs_reflink_inode_has_shared_extents() argument
1556 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_inode_has_shared_extents()
1562 ifp = xfs_ifork_ptr(ip, XFS_DATA_FORK); in xfs_reflink_inode_has_shared_extents()
1563 error = xfs_iread_extents(tp, ip, XFS_DATA_FORK); in xfs_reflink_inode_has_shared_extents()
1568 found = xfs_iext_lookup_extent(ip, ifp, 0, &icur, &got); in xfs_reflink_inode_has_shared_extents()
1609 struct xfs_inode *ip, in xfs_reflink_clear_inode_flag() argument
1615 ASSERT(xfs_is_reflink_inode(ip)); in xfs_reflink_clear_inode_flag()
1617 error = xfs_reflink_inode_has_shared_extents(*tpp, ip, &needs_flag); in xfs_reflink_clear_inode_flag()
1622 * We didn't find any shared blocks so turn off the reflink flag. in xfs_reflink_clear_inode_flag()
1625 error = xfs_reflink_cancel_cow_blocks(ip, tpp, 0, XFS_MAX_FILEOFF, in xfs_reflink_clear_inode_flag()
1631 trace_xfs_reflink_unset_inode_flag(ip); in xfs_reflink_clear_inode_flag()
1632 ip->i_diflags2 &= ~XFS_DIFLAG2_REFLINK; in xfs_reflink_clear_inode_flag()
1633 xfs_inode_clear_cowblocks_tag(ip); in xfs_reflink_clear_inode_flag()
1634 xfs_trans_log_inode(*tpp, ip, XFS_ILOG_CORE); in xfs_reflink_clear_inode_flag()
1645 struct xfs_inode *ip) in xfs_reflink_try_clear_inode_flag() argument
1647 struct xfs_mount *mp = ip->i_mount; in xfs_reflink_try_clear_inode_flag()
1652 error = xfs_trans_alloc(mp, &M_RES(mp)->tr_write, 0, 0, 0, &tp); in xfs_reflink_try_clear_inode_flag()
1656 xfs_ilock(ip, XFS_ILOCK_EXCL); in xfs_reflink_try_clear_inode_flag()
1657 xfs_trans_ijoin(tp, ip, 0); in xfs_reflink_try_clear_inode_flag()
1659 error = xfs_reflink_clear_inode_flag(ip, &tp); in xfs_reflink_try_clear_inode_flag()
1667 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_try_clear_inode_flag()
1672 xfs_iunlock(ip, XFS_ILOCK_EXCL); in xfs_reflink_try_clear_inode_flag()
1677 * Pre-COW all shared blocks within a given byte range of a file and turn off
1678 * the reflink flag if we unshare all of the file's blocks.
1682 struct xfs_inode *ip, in xfs_reflink_unshare() argument
1686 struct inode *inode = VFS_I(ip); in xfs_reflink_unshare()
1689 if (!xfs_is_reflink_inode(ip)) in xfs_reflink_unshare()
1692 trace_xfs_reflink_unshare(ip, offset, len); in xfs_reflink_unshare()
1701 error = filemap_write_and_wait_range(inode->i_mapping, offset, in xfs_reflink_unshare()
1702 offset + len - 1); in xfs_reflink_unshare()
1707 error = xfs_reflink_try_clear_inode_flag(ip); in xfs_reflink_unshare()
1713 trace_xfs_reflink_unshare_error(ip, error, _RET_IP_); in xfs_reflink_unshare()