xref: /openbmc/linux/fs/ocfs2/refcounttree.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
11802d0beSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2*fa60ce2cSMasahiro Yamada /*
38dec98edSTao Ma  * refcounttree.h
48dec98edSTao Ma  *
58dec98edSTao Ma  * Copyright (C) 2009 Oracle.  All rights reserved.
68dec98edSTao Ma  */
78dec98edSTao Ma #ifndef OCFS2_REFCOUNTTREE_H
88dec98edSTao Ma #define OCFS2_REFCOUNTTREE_H
98dec98edSTao Ma 
108dec98edSTao Ma struct ocfs2_refcount_tree {
118dec98edSTao Ma 	struct rb_node rf_node;
128dec98edSTao Ma 	u64 rf_blkno;
138dec98edSTao Ma 	u32 rf_generation;
1483fd9c7fSGoldwyn Rodrigues 	struct kref rf_getcnt;
158dec98edSTao Ma 	struct rw_semaphore rf_sem;
168dec98edSTao Ma 	struct ocfs2_lock_res rf_lockres;
178dec98edSTao Ma 	int rf_removed;
188dec98edSTao Ma 
198dec98edSTao Ma 	/* the following 4 fields are used by caching_info. */
208dec98edSTao Ma 	spinlock_t rf_lock;
2183fd9c7fSGoldwyn Rodrigues 	struct ocfs2_caching_info rf_ci;
228dec98edSTao Ma 	struct mutex rf_io_mutex;
238dec98edSTao Ma 	struct super_block *rf_sb;
248dec98edSTao Ma };
258dec98edSTao Ma 
26374a263eSTao Ma void ocfs2_purge_refcount_trees(struct ocfs2_super *osb);
27374a263eSTao Ma int ocfs2_lock_refcount_tree(struct ocfs2_super *osb, u64 ref_blkno, int rw,
28374a263eSTao Ma 			     struct ocfs2_refcount_tree **tree,
29374a263eSTao Ma 			     struct buffer_head **ref_bh);
30374a263eSTao Ma void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb,
31374a263eSTao Ma 				struct ocfs2_refcount_tree *tree,
32374a263eSTao Ma 				int rw);
331823cb0bSTao Ma 
341823cb0bSTao Ma int ocfs2_decrease_refcount(struct inode *inode,
351823cb0bSTao Ma 			    handle_t *handle, u32 cpos, u32 len,
361823cb0bSTao Ma 			    struct ocfs2_alloc_context *meta_ac,
376ae23c55STao Ma 			    struct ocfs2_cached_dealloc_ctxt *dealloc,
386ae23c55STao Ma 			    int delete);
39bcbbb24aSTao Ma int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
4078f94673STristan Ye 					  u64 refcount_loc,
41bcbbb24aSTao Ma 					  u64 phys_blkno,
42bcbbb24aSTao Ma 					  u32 clusters,
43bcbbb24aSTao Ma 					  int *credits,
4478f94673STristan Ye 					  int *ref_blocks);
4515502712STao Ma int ocfs2_refcount_cow(struct inode *inode,
46c7dd3392STiger Yang 		       struct buffer_head *di_bh,
4737f8a2bfSTao Ma 		       u32 cpos, u32 write_len, u32 max_cpos);
48492a8a33STao Ma 
49492a8a33STao Ma typedef int (ocfs2_post_refcount_func)(struct inode *inode,
50492a8a33STao Ma 				       handle_t *handle,
51492a8a33STao Ma 				       void *para);
52492a8a33STao Ma /*
53492a8a33STao Ma  * Some refcount caller need to do more work after we modify the data b-tree
54492a8a33STao Ma  * during refcount operation(including CoW and add refcount flag), and make the
55492a8a33STao Ma  * transaction complete. So it must give us this structure so that we can do it
56492a8a33STao Ma  * within our transaction.
57492a8a33STao Ma  *
58492a8a33STao Ma  */
59492a8a33STao Ma struct ocfs2_post_refcount {
60492a8a33STao Ma 	int credits;			/* credits it need for journal. */
61492a8a33STao Ma 	ocfs2_post_refcount_func *func;	/* real function. */
62492a8a33STao Ma 	void *para;
63492a8a33STao Ma };
64492a8a33STao Ma 
65492a8a33STao Ma int ocfs2_refcounted_xattr_delete_need(struct inode *inode,
66492a8a33STao Ma 				       struct ocfs2_caching_info *ref_ci,
67492a8a33STao Ma 				       struct buffer_head *ref_root_bh,
68492a8a33STao Ma 				       struct ocfs2_xattr_value_root *xv,
69492a8a33STao Ma 				       int *meta_add, int *credits);
70492a8a33STao Ma int ocfs2_refcount_cow_xattr(struct inode *inode,
71492a8a33STao Ma 			     struct ocfs2_dinode *di,
72492a8a33STao Ma 			     struct ocfs2_xattr_value_buf *vb,
73492a8a33STao Ma 			     struct ocfs2_refcount_tree *ref_tree,
74492a8a33STao Ma 			     struct buffer_head *ref_root_bh,
75492a8a33STao Ma 			     u32 cpos, u32 write_len,
76492a8a33STao Ma 			     struct ocfs2_post_refcount *post);
773e19a25eSTristan Ye int ocfs2_duplicate_clusters_by_page(handle_t *handle,
78c7dd3392STiger Yang 				     struct inode *inode,
793e19a25eSTristan Ye 				     u32 cpos, u32 old_cluster,
803e19a25eSTristan Ye 				     u32 new_cluster, u32 new_len);
813e19a25eSTristan Ye int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
82c7dd3392STiger Yang 				    struct inode *inode,
833e19a25eSTristan Ye 				    u32 cpos, u32 old_cluster,
843e19a25eSTristan Ye 				    u32 new_cluster, u32 new_len);
853e19a25eSTristan Ye int ocfs2_cow_sync_writeback(struct super_block *sb,
863e19a25eSTristan Ye 			     struct inode *inode,
873e19a25eSTristan Ye 			     u32 cpos, u32 num_clusters);
880129241eSTao Ma int ocfs2_add_refcount_flag(struct inode *inode,
890129241eSTao Ma 			    struct ocfs2_extent_tree *data_et,
900129241eSTao Ma 			    struct ocfs2_caching_info *ref_ci,
910129241eSTao Ma 			    struct buffer_head *ref_root_bh,
920129241eSTao Ma 			    u32 cpos, u32 p_cluster, u32 num_clusters,
930129241eSTao Ma 			    struct ocfs2_cached_dealloc_ctxt *dealloc,
940129241eSTao Ma 			    struct ocfs2_post_refcount *post);
958b2c0dbaSTao Ma int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh);
968b2c0dbaSTao Ma int ocfs2_try_remove_refcount_tree(struct inode *inode,
978b2c0dbaSTao Ma 				   struct buffer_head *di_bh);
982999d12fSTao Ma int ocfs2_increase_refcount(handle_t *handle,
992999d12fSTao Ma 			    struct ocfs2_caching_info *ci,
1002999d12fSTao Ma 			    struct buffer_head *ref_root_bh,
1012999d12fSTao Ma 			    u64 cpos, u32 len,
1022999d12fSTao Ma 			    struct ocfs2_alloc_context *meta_ac,
1032999d12fSTao Ma 			    struct ocfs2_cached_dealloc_ctxt *dealloc);
104bd50873dSTao Ma int ocfs2_reflink_ioctl(struct inode *inode,
105bd50873dSTao Ma 			const char __user *oldname,
106bd50873dSTao Ma 			const char __user *newname,
107bd50873dSTao Ma 			bool preserve);
10865f098e9SDarrick J. Wong loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode,
10965f098e9SDarrick J. Wong 				  struct buffer_head *s_bh,
11029ac8e85SDarrick J. Wong 				  loff_t pos_in,
11165f098e9SDarrick J. Wong 				  struct inode *t_inode,
11265f098e9SDarrick J. Wong 				  struct buffer_head *t_bh,
11329ac8e85SDarrick J. Wong 				  loff_t pos_out,
11465f098e9SDarrick J. Wong 				  loff_t len);
11565f098e9SDarrick J. Wong int ocfs2_reflink_inodes_lock(struct inode *s_inode,
11665f098e9SDarrick J. Wong 			      struct buffer_head **bh1,
11765f098e9SDarrick J. Wong 			      struct inode *t_inode,
11865f098e9SDarrick J. Wong 			      struct buffer_head **bh2);
11965f098e9SDarrick J. Wong void ocfs2_reflink_inodes_unlock(struct inode *s_inode,
12065f098e9SDarrick J. Wong 				 struct buffer_head *s_bh,
12165f098e9SDarrick J. Wong 				 struct inode *t_inode,
12265f098e9SDarrick J. Wong 				 struct buffer_head *t_bh);
12365f098e9SDarrick J. Wong int ocfs2_reflink_update_dest(struct inode *dest,
12465f098e9SDarrick J. Wong 			      struct buffer_head *d_bh,
12565f098e9SDarrick J. Wong 			      loff_t newlen);
12629ac8e85SDarrick J. Wong 
1278dec98edSTao Ma #endif /* OCFS2_REFCOUNTTREE_H */
128