blob: 0b9014495726a2697977d246f998668203d5e54d [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Tao Ma8dec98e2009-08-18 11:19:58 +08002/* -*- mode: c; c-basic-offset: 8; -*-
3 * vim: noexpandtab sw=8 ts=8 sts=0:
4 *
5 * refcounttree.h
6 *
7 * Copyright (C) 2009 Oracle. All rights reserved.
Tao Ma8dec98e2009-08-18 11:19:58 +08008 */
9#ifndef OCFS2_REFCOUNTTREE_H
10#define OCFS2_REFCOUNTTREE_H
11
12struct ocfs2_refcount_tree {
13 struct rb_node rf_node;
14 u64 rf_blkno;
15 u32 rf_generation;
Goldwyn Rodrigues83fd9c72010-06-10 17:21:36 -050016 struct kref rf_getcnt;
Tao Ma8dec98e2009-08-18 11:19:58 +080017 struct rw_semaphore rf_sem;
18 struct ocfs2_lock_res rf_lockres;
Tao Ma8dec98e2009-08-18 11:19:58 +080019 int rf_removed;
20
21 /* the following 4 fields are used by caching_info. */
Tao Ma8dec98e2009-08-18 11:19:58 +080022 spinlock_t rf_lock;
Goldwyn Rodrigues83fd9c72010-06-10 17:21:36 -050023 struct ocfs2_caching_info rf_ci;
Tao Ma8dec98e2009-08-18 11:19:58 +080024 struct mutex rf_io_mutex;
25 struct super_block *rf_sb;
26};
27
Tao Ma374a2632009-08-24 11:13:37 +080028void ocfs2_purge_refcount_trees(struct ocfs2_super *osb);
29int ocfs2_lock_refcount_tree(struct ocfs2_super *osb, u64 ref_blkno, int rw,
30 struct ocfs2_refcount_tree **tree,
31 struct buffer_head **ref_bh);
32void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb,
33 struct ocfs2_refcount_tree *tree,
34 int rw);
Tao Ma1823cb02009-08-18 11:24:49 +080035
36int ocfs2_decrease_refcount(struct inode *inode,
37 handle_t *handle, u32 cpos, u32 len,
38 struct ocfs2_alloc_context *meta_ac,
Tao Ma6ae23c52009-08-18 11:30:55 +080039 struct ocfs2_cached_dealloc_ctxt *dealloc,
40 int delete);
Tao Mabcbbb242009-08-18 11:29:12 +080041int ocfs2_prepare_refcount_change_for_del(struct inode *inode,
Tristan Ye78f94672010-05-11 17:54:42 +080042 u64 refcount_loc,
Tao Mabcbbb242009-08-18 11:29:12 +080043 u64 phys_blkno,
44 u32 clusters,
45 int *credits,
Tristan Ye78f94672010-05-11 17:54:42 +080046 int *ref_blocks);
Tao Ma15502712010-08-12 10:36:38 +080047int ocfs2_refcount_cow(struct inode *inode,
Tiger Yangc7dd3392013-08-13 16:00:58 -070048 struct buffer_head *di_bh,
Tao Ma37f8a2b2009-08-26 09:47:28 +080049 u32 cpos, u32 write_len, u32 max_cpos);
Tao Ma492a8a32009-08-18 11:43:17 +080050
51typedef int (ocfs2_post_refcount_func)(struct inode *inode,
52 handle_t *handle,
53 void *para);
54/*
55 * Some refcount caller need to do more work after we modify the data b-tree
56 * during refcount operation(including CoW and add refcount flag), and make the
57 * transaction complete. So it must give us this structure so that we can do it
58 * within our transaction.
59 *
60 */
61struct ocfs2_post_refcount {
62 int credits; /* credits it need for journal. */
63 ocfs2_post_refcount_func *func; /* real function. */
64 void *para;
65};
66
67int ocfs2_refcounted_xattr_delete_need(struct inode *inode,
68 struct ocfs2_caching_info *ref_ci,
69 struct buffer_head *ref_root_bh,
70 struct ocfs2_xattr_value_root *xv,
71 int *meta_add, int *credits);
72int ocfs2_refcount_cow_xattr(struct inode *inode,
73 struct ocfs2_dinode *di,
74 struct ocfs2_xattr_value_buf *vb,
75 struct ocfs2_refcount_tree *ref_tree,
76 struct buffer_head *ref_root_bh,
77 u32 cpos, u32 write_len,
78 struct ocfs2_post_refcount *post);
Tristan Ye3e19a252011-05-24 16:21:20 +080079int ocfs2_duplicate_clusters_by_page(handle_t *handle,
Tiger Yangc7dd3392013-08-13 16:00:58 -070080 struct inode *inode,
Tristan Ye3e19a252011-05-24 16:21:20 +080081 u32 cpos, u32 old_cluster,
82 u32 new_cluster, u32 new_len);
83int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
Tiger Yangc7dd3392013-08-13 16:00:58 -070084 struct inode *inode,
Tristan Ye3e19a252011-05-24 16:21:20 +080085 u32 cpos, u32 old_cluster,
86 u32 new_cluster, u32 new_len);
87int ocfs2_cow_sync_writeback(struct super_block *sb,
88 struct inode *inode,
89 u32 cpos, u32 num_clusters);
Tao Ma01292412009-09-21 13:04:19 +080090int ocfs2_add_refcount_flag(struct inode *inode,
91 struct ocfs2_extent_tree *data_et,
92 struct ocfs2_caching_info *ref_ci,
93 struct buffer_head *ref_root_bh,
94 u32 cpos, u32 p_cluster, u32 num_clusters,
95 struct ocfs2_cached_dealloc_ctxt *dealloc,
96 struct ocfs2_post_refcount *post);
Tao Ma8b2c0db2009-08-18 11:43:49 +080097int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh);
98int ocfs2_try_remove_refcount_tree(struct inode *inode,
99 struct buffer_head *di_bh);
Tao Ma2999d122009-08-18 11:43:55 +0800100int ocfs2_increase_refcount(handle_t *handle,
101 struct ocfs2_caching_info *ci,
102 struct buffer_head *ref_root_bh,
103 u64 cpos, u32 len,
104 struct ocfs2_alloc_context *meta_ac,
105 struct ocfs2_cached_dealloc_ctxt *dealloc);
Tao Mabd508732009-09-21 11:25:14 +0800106int ocfs2_reflink_ioctl(struct inode *inode,
107 const char __user *oldname,
108 const char __user *newname,
109 bool preserve);
Darrick J. Wong65f098e2018-10-30 10:45:48 +1100110loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode,
111 struct buffer_head *s_bh,
112 loff_t pos_in,
113 struct inode *t_inode,
114 struct buffer_head *t_bh,
115 loff_t pos_out,
116 loff_t len);
117int ocfs2_reflink_inodes_lock(struct inode *s_inode,
118 struct buffer_head **bh1,
119 struct inode *t_inode,
120 struct buffer_head **bh2);
121void ocfs2_reflink_inodes_unlock(struct inode *s_inode,
122 struct buffer_head *s_bh,
123 struct inode *t_inode,
124 struct buffer_head *t_bh);
125int ocfs2_reflink_update_dest(struct inode *dest,
126 struct buffer_head *d_bh,
127 loff_t newlen);
Darrick J. Wong29ac8e82016-11-09 14:13:11 -0800128
Tao Ma8dec98e2009-08-18 11:19:58 +0800129#endif /* OCFS2_REFCOUNTTREE_H */