1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Copyright (C) 2016 Oracle. All Rights Reserved.
4 * Author: Darrick J. Wong <darrick.wong@oracle.com>
5 */
6 #ifndef __XFS_REFLINK_H
7 #define __XFS_REFLINK_H 1
8
9 /*
10 * Check whether it is safe to free COW fork blocks from an inode. It is unsafe
11 * to do so when an inode has dirty cache or I/O in-flight, even if no shared
12 * extents exist in the data fork, because outstanding I/O may target blocks
13 * that were speculatively allocated to the COW fork.
14 */
15 static inline bool
xfs_can_free_cowblocks(struct xfs_inode * ip)16 xfs_can_free_cowblocks(struct xfs_inode *ip)
17 {
18 struct inode *inode = VFS_I(ip);
19
20 if ((inode->i_state & I_DIRTY_PAGES) ||
21 mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ||
22 mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
23 atomic_read(&inode->i_dio_count))
24 return false;
25 return true;
26 }
27
28 int xfs_reflink_trim_around_shared(struct xfs_inode *ip,
29 struct xfs_bmbt_irec *irec, bool *shared);
30 int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
31 bool *shared);
32
33 int xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
34 struct xfs_bmbt_irec *cmap, bool *shared, uint *lockmode,
35 bool convert_now);
36 extern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset,
37 xfs_off_t count);
38 int xfs_reflink_convert_cow_locked(struct xfs_inode *ip,
39 xfs_fileoff_t offset_fsb, xfs_filblks_t count_fsb);
40
41 extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip,
42 struct xfs_trans **tpp, xfs_fileoff_t offset_fsb,
43 xfs_fileoff_t end_fsb, bool cancel_real);
44 extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
45 xfs_off_t count, bool cancel_real);
46 extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
47 xfs_off_t count);
48 int xfs_reflink_end_atomic_cow(struct xfs_inode *ip, xfs_off_t offset,
49 xfs_off_t count);
50 extern int xfs_reflink_recover_cow(struct xfs_mount *mp);
51 extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
52 struct file *file_out, loff_t pos_out, loff_t len,
53 unsigned int remap_flags);
54 extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp,
55 struct xfs_inode *ip, bool *has_shared);
56 extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
57 struct xfs_trans **tpp);
58 extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
59 xfs_off_t len);
60 extern int xfs_reflink_remap_prep(struct file *file_in, loff_t pos_in,
61 struct file *file_out, loff_t pos_out, loff_t *len,
62 unsigned int remap_flags);
63 extern int xfs_reflink_remap_blocks(struct xfs_inode *src, loff_t pos_in,
64 struct xfs_inode *dest, loff_t pos_out, loff_t remap_len,
65 loff_t *remapped);
66 extern int xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen,
67 xfs_extlen_t cowextsize, unsigned int remap_flags);
68
69 bool xfs_reflink_supports_rextsize(struct xfs_mount *mp, unsigned int rextsize);
70
71 xfs_extlen_t xfs_reflink_max_atomic_cow(struct xfs_mount *mp);
72
73 #endif /* __XFS_REFLINK_H */
74