xref: /OK3568_Linux_fs/kernel/fs/ocfs2/refcounttree.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /* -*- mode: c; c-basic-offset: 8; -*-
3*4882a593Smuzhiyun  * vim: noexpandtab sw=8 ts=8 sts=0:
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * refcounttree.h
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (C) 2009 Oracle.  All rights reserved.
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #ifndef OCFS2_REFCOUNTTREE_H
10*4882a593Smuzhiyun #define OCFS2_REFCOUNTTREE_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun struct ocfs2_refcount_tree {
13*4882a593Smuzhiyun 	struct rb_node rf_node;
14*4882a593Smuzhiyun 	u64 rf_blkno;
15*4882a593Smuzhiyun 	u32 rf_generation;
16*4882a593Smuzhiyun 	struct kref rf_getcnt;
17*4882a593Smuzhiyun 	struct rw_semaphore rf_sem;
18*4882a593Smuzhiyun 	struct ocfs2_lock_res rf_lockres;
19*4882a593Smuzhiyun 	int rf_removed;
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun 	/* the following 4 fields are used by caching_info. */
22*4882a593Smuzhiyun 	spinlock_t rf_lock;
23*4882a593Smuzhiyun 	struct ocfs2_caching_info rf_ci;
24*4882a593Smuzhiyun 	struct mutex rf_io_mutex;
25*4882a593Smuzhiyun 	struct super_block *rf_sb;
26*4882a593Smuzhiyun };
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun void ocfs2_purge_refcount_trees(struct ocfs2_super *osb);
29*4882a593Smuzhiyun int ocfs2_lock_refcount_tree(struct ocfs2_super *osb, u64 ref_blkno, int rw,
30*4882a593Smuzhiyun 			     struct ocfs2_refcount_tree **tree,
31*4882a593Smuzhiyun 			     struct buffer_head **ref_bh);
32*4882a593Smuzhiyun void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb,
33*4882a593Smuzhiyun 				struct ocfs2_refcount_tree *tree,
34*4882a593Smuzhiyun 				int rw);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun int ocfs2_decrease_refcount(struct inode *inode,
37*4882a593Smuzhiyun 			    handle_t *handle, u32 cpos, u32 len,
38*4882a593Smuzhiyun 			    struct ocfs2_alloc_context *meta_ac,
39*4882a593Smuzhiyun 			    struct ocfs2_cached_dealloc_ctxt *dealloc,
40*4882a593Smuzhiyun 			    int delete);
41*4882a593Smuzhiyun int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
42*4882a593Smuzhiyun 					  u64 refcount_loc,
43*4882a593Smuzhiyun 					  u64 phys_blkno,
44*4882a593Smuzhiyun 					  u32 clusters,
45*4882a593Smuzhiyun 					  int *credits,
46*4882a593Smuzhiyun 					  int *ref_blocks);
47*4882a593Smuzhiyun int ocfs2_refcount_cow(struct inode *inode,
48*4882a593Smuzhiyun 		       struct buffer_head *di_bh,
49*4882a593Smuzhiyun 		       u32 cpos, u32 write_len, u32 max_cpos);
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun typedef int (ocfs2_post_refcount_func)(struct inode *inode,
52*4882a593Smuzhiyun 				       handle_t *handle,
53*4882a593Smuzhiyun 				       void *para);
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun  * Some refcount caller need to do more work after we modify the data b-tree
56*4882a593Smuzhiyun  * during refcount operation(including CoW and add refcount flag), and make the
57*4882a593Smuzhiyun  * transaction complete. So it must give us this structure so that we can do it
58*4882a593Smuzhiyun  * within our transaction.
59*4882a593Smuzhiyun  *
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun struct ocfs2_post_refcount {
62*4882a593Smuzhiyun 	int credits;			/* credits it need for journal. */
63*4882a593Smuzhiyun 	ocfs2_post_refcount_func *func;	/* real function. */
64*4882a593Smuzhiyun 	void *para;
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun int ocfs2_refcounted_xattr_delete_need(struct inode *inode,
68*4882a593Smuzhiyun 				       struct ocfs2_caching_info *ref_ci,
69*4882a593Smuzhiyun 				       struct buffer_head *ref_root_bh,
70*4882a593Smuzhiyun 				       struct ocfs2_xattr_value_root *xv,
71*4882a593Smuzhiyun 				       int *meta_add, int *credits);
72*4882a593Smuzhiyun int ocfs2_refcount_cow_xattr(struct inode *inode,
73*4882a593Smuzhiyun 			     struct ocfs2_dinode *di,
74*4882a593Smuzhiyun 			     struct ocfs2_xattr_value_buf *vb,
75*4882a593Smuzhiyun 			     struct ocfs2_refcount_tree *ref_tree,
76*4882a593Smuzhiyun 			     struct buffer_head *ref_root_bh,
77*4882a593Smuzhiyun 			     u32 cpos, u32 write_len,
78*4882a593Smuzhiyun 			     struct ocfs2_post_refcount *post);
79*4882a593Smuzhiyun int ocfs2_duplicate_clusters_by_page(handle_t *handle,
80*4882a593Smuzhiyun 				     struct inode *inode,
81*4882a593Smuzhiyun 				     u32 cpos, u32 old_cluster,
82*4882a593Smuzhiyun 				     u32 new_cluster, u32 new_len);
83*4882a593Smuzhiyun int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
84*4882a593Smuzhiyun 				    struct inode *inode,
85*4882a593Smuzhiyun 				    u32 cpos, u32 old_cluster,
86*4882a593Smuzhiyun 				    u32 new_cluster, u32 new_len);
87*4882a593Smuzhiyun int ocfs2_cow_sync_writeback(struct super_block *sb,
88*4882a593Smuzhiyun 			     struct inode *inode,
89*4882a593Smuzhiyun 			     u32 cpos, u32 num_clusters);
90*4882a593Smuzhiyun int ocfs2_add_refcount_flag(struct inode *inode,
91*4882a593Smuzhiyun 			    struct ocfs2_extent_tree *data_et,
92*4882a593Smuzhiyun 			    struct ocfs2_caching_info *ref_ci,
93*4882a593Smuzhiyun 			    struct buffer_head *ref_root_bh,
94*4882a593Smuzhiyun 			    u32 cpos, u32 p_cluster, u32 num_clusters,
95*4882a593Smuzhiyun 			    struct ocfs2_cached_dealloc_ctxt *dealloc,
96*4882a593Smuzhiyun 			    struct ocfs2_post_refcount *post);
97*4882a593Smuzhiyun int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh);
98*4882a593Smuzhiyun int ocfs2_try_remove_refcount_tree(struct inode *inode,
99*4882a593Smuzhiyun 				   struct buffer_head *di_bh);
100*4882a593Smuzhiyun int ocfs2_increase_refcount(handle_t *handle,
101*4882a593Smuzhiyun 			    struct ocfs2_caching_info *ci,
102*4882a593Smuzhiyun 			    struct buffer_head *ref_root_bh,
103*4882a593Smuzhiyun 			    u64 cpos, u32 len,
104*4882a593Smuzhiyun 			    struct ocfs2_alloc_context *meta_ac,
105*4882a593Smuzhiyun 			    struct ocfs2_cached_dealloc_ctxt *dealloc);
106*4882a593Smuzhiyun int ocfs2_reflink_ioctl(struct inode *inode,
107*4882a593Smuzhiyun 			const char __user *oldname,
108*4882a593Smuzhiyun 			const char __user *newname,
109*4882a593Smuzhiyun 			bool preserve);
110*4882a593Smuzhiyun loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode,
111*4882a593Smuzhiyun 				  struct buffer_head *s_bh,
112*4882a593Smuzhiyun 				  loff_t pos_in,
113*4882a593Smuzhiyun 				  struct inode *t_inode,
114*4882a593Smuzhiyun 				  struct buffer_head *t_bh,
115*4882a593Smuzhiyun 				  loff_t pos_out,
116*4882a593Smuzhiyun 				  loff_t len);
117*4882a593Smuzhiyun int ocfs2_reflink_inodes_lock(struct inode *s_inode,
118*4882a593Smuzhiyun 			      struct buffer_head **bh1,
119*4882a593Smuzhiyun 			      struct inode *t_inode,
120*4882a593Smuzhiyun 			      struct buffer_head **bh2);
121*4882a593Smuzhiyun void ocfs2_reflink_inodes_unlock(struct inode *s_inode,
122*4882a593Smuzhiyun 				 struct buffer_head *s_bh,
123*4882a593Smuzhiyun 				 struct inode *t_inode,
124*4882a593Smuzhiyun 				 struct buffer_head *t_bh);
125*4882a593Smuzhiyun int ocfs2_reflink_update_dest(struct inode *dest,
126*4882a593Smuzhiyun 			      struct buffer_head *d_bh,
127*4882a593Smuzhiyun 			      loff_t newlen);
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #endif /* OCFS2_REFCOUNTTREE_H */
130