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