xref: /openbmc/linux/fs/xfs/xfs_reflink.h (revision d37cf9b63113f13d742713881ce691fc615d8b3b)
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 
xfs_is_always_cow_inode(struct xfs_inode * ip)9 static inline bool xfs_is_always_cow_inode(struct xfs_inode *ip)
10 {
11 	return ip->i_mount->m_always_cow && xfs_has_reflink(ip->i_mount);
12 }
13 
xfs_is_cow_inode(struct xfs_inode * ip)14 static inline bool xfs_is_cow_inode(struct xfs_inode *ip)
15 {
16 	return xfs_is_reflink_inode(ip) || xfs_is_always_cow_inode(ip);
17 }
18 
19 /*
20  * Check whether it is safe to free COW fork blocks from an inode. It is unsafe
21  * to do so when an inode has dirty cache or I/O in-flight, even if no shared
22  * extents exist in the data fork, because outstanding I/O may target blocks
23  * that were speculatively allocated to the COW fork.
24  */
25 static inline bool
xfs_can_free_cowblocks(struct xfs_inode * ip)26 xfs_can_free_cowblocks(struct xfs_inode *ip)
27 {
28 	struct inode *inode = VFS_I(ip);
29 
30 	if ((inode->i_state & I_DIRTY_PAGES) ||
31 	    mapping_tagged(inode->i_mapping, PAGECACHE_TAG_DIRTY) ||
32 	    mapping_tagged(inode->i_mapping, PAGECACHE_TAG_WRITEBACK) ||
33 	    atomic_read(&inode->i_dio_count))
34 		return false;
35 	return true;
36 }
37 
38 extern int xfs_reflink_trim_around_shared(struct xfs_inode *ip,
39 		struct xfs_bmbt_irec *irec, bool *shared);
40 int xfs_bmap_trim_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
41 		bool *shared);
42 
43 int xfs_reflink_allocate_cow(struct xfs_inode *ip, struct xfs_bmbt_irec *imap,
44 		struct xfs_bmbt_irec *cmap, bool *shared, uint *lockmode,
45 		bool convert_now);
46 extern int xfs_reflink_convert_cow(struct xfs_inode *ip, xfs_off_t offset,
47 		xfs_off_t count);
48 
49 extern int xfs_reflink_cancel_cow_blocks(struct xfs_inode *ip,
50 		struct xfs_trans **tpp, xfs_fileoff_t offset_fsb,
51 		xfs_fileoff_t end_fsb, bool cancel_real);
52 extern int xfs_reflink_cancel_cow_range(struct xfs_inode *ip, xfs_off_t offset,
53 		xfs_off_t count, bool cancel_real);
54 extern int xfs_reflink_end_cow(struct xfs_inode *ip, xfs_off_t offset,
55 		xfs_off_t count);
56 extern int xfs_reflink_recover_cow(struct xfs_mount *mp);
57 extern loff_t xfs_reflink_remap_range(struct file *file_in, loff_t pos_in,
58 		struct file *file_out, loff_t pos_out, loff_t len,
59 		unsigned int remap_flags);
60 extern int xfs_reflink_inode_has_shared_extents(struct xfs_trans *tp,
61 		struct xfs_inode *ip, bool *has_shared);
62 extern int xfs_reflink_clear_inode_flag(struct xfs_inode *ip,
63 		struct xfs_trans **tpp);
64 extern int xfs_reflink_unshare(struct xfs_inode *ip, xfs_off_t offset,
65 		xfs_off_t len);
66 extern int xfs_reflink_remap_prep(struct file *file_in, loff_t pos_in,
67 		struct file *file_out, loff_t pos_out, loff_t *len,
68 		unsigned int remap_flags);
69 extern int xfs_reflink_remap_blocks(struct xfs_inode *src, loff_t pos_in,
70 		struct xfs_inode *dest, loff_t pos_out, loff_t remap_len,
71 		loff_t *remapped);
72 extern int xfs_reflink_update_dest(struct xfs_inode *dest, xfs_off_t newlen,
73 		xfs_extlen_t cowextsize, unsigned int remap_flags);
74 
75 #endif /* __XFS_REFLINK_H */
76