Thomas Gleixner | 1802d0b | 2019-05-27 08:55:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Masahiro Yamada | fa60ce2 | 2021-05-06 18:06:44 -0700 | [diff] [blame] | 2 | /* |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 3 | * refcounttree.h |
| 4 | * |
| 5 | * Copyright (C) 2009 Oracle. All rights reserved. |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 6 | */ |
| 7 | #ifndef OCFS2_REFCOUNTTREE_H |
| 8 | #define OCFS2_REFCOUNTTREE_H |
| 9 | |
| 10 | struct ocfs2_refcount_tree { |
| 11 | struct rb_node rf_node; |
| 12 | u64 rf_blkno; |
| 13 | u32 rf_generation; |
Goldwyn Rodrigues | 83fd9c7 | 2010-06-10 17:21:36 -0500 | [diff] [blame] | 14 | struct kref rf_getcnt; |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 15 | struct rw_semaphore rf_sem; |
| 16 | struct ocfs2_lock_res rf_lockres; |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 17 | int rf_removed; |
| 18 | |
| 19 | /* the following 4 fields are used by caching_info. */ |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 20 | spinlock_t rf_lock; |
Goldwyn Rodrigues | 83fd9c7 | 2010-06-10 17:21:36 -0500 | [diff] [blame] | 21 | struct ocfs2_caching_info rf_ci; |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 22 | struct mutex rf_io_mutex; |
| 23 | struct super_block *rf_sb; |
| 24 | }; |
| 25 | |
Tao Ma | 374a263 | 2009-08-24 11:13:37 +0800 | [diff] [blame] | 26 | void ocfs2_purge_refcount_trees(struct ocfs2_super *osb); |
| 27 | int ocfs2_lock_refcount_tree(struct ocfs2_super *osb, u64 ref_blkno, int rw, |
| 28 | struct ocfs2_refcount_tree **tree, |
| 29 | struct buffer_head **ref_bh); |
| 30 | void ocfs2_unlock_refcount_tree(struct ocfs2_super *osb, |
| 31 | struct ocfs2_refcount_tree *tree, |
| 32 | int rw); |
Tao Ma | 1823cb0 | 2009-08-18 11:24:49 +0800 | [diff] [blame] | 33 | |
| 34 | int ocfs2_decrease_refcount(struct inode *inode, |
| 35 | handle_t *handle, u32 cpos, u32 len, |
| 36 | struct ocfs2_alloc_context *meta_ac, |
Tao Ma | 6ae23c5 | 2009-08-18 11:30:55 +0800 | [diff] [blame] | 37 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
| 38 | int delete); |
Tao Ma | bcbbb24 | 2009-08-18 11:29:12 +0800 | [diff] [blame] | 39 | int ocfs2_prepare_refcount_change_for_del(struct inode *inode, |
Tristan Ye | 78f9467 | 2010-05-11 17:54:42 +0800 | [diff] [blame] | 40 | u64 refcount_loc, |
Tao Ma | bcbbb24 | 2009-08-18 11:29:12 +0800 | [diff] [blame] | 41 | u64 phys_blkno, |
| 42 | u32 clusters, |
| 43 | int *credits, |
Tristan Ye | 78f9467 | 2010-05-11 17:54:42 +0800 | [diff] [blame] | 44 | int *ref_blocks); |
Tao Ma | 1550271 | 2010-08-12 10:36:38 +0800 | [diff] [blame] | 45 | int ocfs2_refcount_cow(struct inode *inode, |
Tiger Yang | c7dd339 | 2013-08-13 16:00:58 -0700 | [diff] [blame] | 46 | struct buffer_head *di_bh, |
Tao Ma | 37f8a2b | 2009-08-26 09:47:28 +0800 | [diff] [blame] | 47 | u32 cpos, u32 write_len, u32 max_cpos); |
Tao Ma | 492a8a3 | 2009-08-18 11:43:17 +0800 | [diff] [blame] | 48 | |
| 49 | typedef int (ocfs2_post_refcount_func)(struct inode *inode, |
| 50 | handle_t *handle, |
| 51 | void *para); |
| 52 | /* |
| 53 | * Some refcount caller need to do more work after we modify the data b-tree |
| 54 | * during refcount operation(including CoW and add refcount flag), and make the |
| 55 | * transaction complete. So it must give us this structure so that we can do it |
| 56 | * within our transaction. |
| 57 | * |
| 58 | */ |
| 59 | struct ocfs2_post_refcount { |
| 60 | int credits; /* credits it need for journal. */ |
| 61 | ocfs2_post_refcount_func *func; /* real function. */ |
| 62 | void *para; |
| 63 | }; |
| 64 | |
| 65 | int ocfs2_refcounted_xattr_delete_need(struct inode *inode, |
| 66 | struct ocfs2_caching_info *ref_ci, |
| 67 | struct buffer_head *ref_root_bh, |
| 68 | struct ocfs2_xattr_value_root *xv, |
| 69 | int *meta_add, int *credits); |
| 70 | int ocfs2_refcount_cow_xattr(struct inode *inode, |
| 71 | struct ocfs2_dinode *di, |
| 72 | struct ocfs2_xattr_value_buf *vb, |
| 73 | struct ocfs2_refcount_tree *ref_tree, |
| 74 | struct buffer_head *ref_root_bh, |
| 75 | u32 cpos, u32 write_len, |
| 76 | struct ocfs2_post_refcount *post); |
Tristan Ye | 3e19a25 | 2011-05-24 16:21:20 +0800 | [diff] [blame] | 77 | int ocfs2_duplicate_clusters_by_page(handle_t *handle, |
Tiger Yang | c7dd339 | 2013-08-13 16:00:58 -0700 | [diff] [blame] | 78 | struct inode *inode, |
Tristan Ye | 3e19a25 | 2011-05-24 16:21:20 +0800 | [diff] [blame] | 79 | u32 cpos, u32 old_cluster, |
| 80 | u32 new_cluster, u32 new_len); |
| 81 | int ocfs2_duplicate_clusters_by_jbd(handle_t *handle, |
Tiger Yang | c7dd339 | 2013-08-13 16:00:58 -0700 | [diff] [blame] | 82 | struct inode *inode, |
Tristan Ye | 3e19a25 | 2011-05-24 16:21:20 +0800 | [diff] [blame] | 83 | u32 cpos, u32 old_cluster, |
| 84 | u32 new_cluster, u32 new_len); |
| 85 | int ocfs2_cow_sync_writeback(struct super_block *sb, |
| 86 | struct inode *inode, |
| 87 | u32 cpos, u32 num_clusters); |
Tao Ma | 0129241 | 2009-09-21 13:04:19 +0800 | [diff] [blame] | 88 | int ocfs2_add_refcount_flag(struct inode *inode, |
| 89 | struct ocfs2_extent_tree *data_et, |
| 90 | struct ocfs2_caching_info *ref_ci, |
| 91 | struct buffer_head *ref_root_bh, |
| 92 | u32 cpos, u32 p_cluster, u32 num_clusters, |
| 93 | struct ocfs2_cached_dealloc_ctxt *dealloc, |
| 94 | struct ocfs2_post_refcount *post); |
Tao Ma | 8b2c0db | 2009-08-18 11:43:49 +0800 | [diff] [blame] | 95 | int ocfs2_remove_refcount_tree(struct inode *inode, struct buffer_head *di_bh); |
| 96 | int ocfs2_try_remove_refcount_tree(struct inode *inode, |
| 97 | struct buffer_head *di_bh); |
Tao Ma | 2999d12 | 2009-08-18 11:43:55 +0800 | [diff] [blame] | 98 | int ocfs2_increase_refcount(handle_t *handle, |
| 99 | struct ocfs2_caching_info *ci, |
| 100 | struct buffer_head *ref_root_bh, |
| 101 | u64 cpos, u32 len, |
| 102 | struct ocfs2_alloc_context *meta_ac, |
| 103 | struct ocfs2_cached_dealloc_ctxt *dealloc); |
Tao Ma | bd50873 | 2009-09-21 11:25:14 +0800 | [diff] [blame] | 104 | int ocfs2_reflink_ioctl(struct inode *inode, |
| 105 | const char __user *oldname, |
| 106 | const char __user *newname, |
| 107 | bool preserve); |
Darrick J. Wong | 65f098e | 2018-10-30 10:45:48 +1100 | [diff] [blame] | 108 | loff_t ocfs2_reflink_remap_blocks(struct inode *s_inode, |
| 109 | struct buffer_head *s_bh, |
| 110 | loff_t pos_in, |
| 111 | struct inode *t_inode, |
| 112 | struct buffer_head *t_bh, |
| 113 | loff_t pos_out, |
| 114 | loff_t len); |
| 115 | int ocfs2_reflink_inodes_lock(struct inode *s_inode, |
| 116 | struct buffer_head **bh1, |
| 117 | struct inode *t_inode, |
| 118 | struct buffer_head **bh2); |
| 119 | void ocfs2_reflink_inodes_unlock(struct inode *s_inode, |
| 120 | struct buffer_head *s_bh, |
| 121 | struct inode *t_inode, |
| 122 | struct buffer_head *t_bh); |
| 123 | int ocfs2_reflink_update_dest(struct inode *dest, |
| 124 | struct buffer_head *d_bh, |
| 125 | loff_t newlen); |
Darrick J. Wong | 29ac8e8 | 2016-11-09 14:13:11 -0800 | [diff] [blame] | 126 | |
Tao Ma | 8dec98e | 2009-08-18 11:19:58 +0800 | [diff] [blame] | 127 | #endif /* OCFS2_REFCOUNTTREE_H */ |