^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^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) * alloc.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Function prototypes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (C) 2002, 2004 Oracle. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #ifndef OCFS2_ALLOC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define OCFS2_ALLOC_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * For xattr tree leaf, we limit the leaf byte size to be 64K.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * the b-tree operations in ocfs2. Now all the b-tree operations are not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * limited to ocfs2_dinode only. Any data which need to allocate clusters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * to store can use b-tree. And it only needs to implement its ocfs2_extent_tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * and operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ocfs2_extent_tree becomes the first-class object for extent tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * manipulation. Callers of the alloc.c code need to fill it via one of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * the ocfs2_init_*_extent_tree() operations below.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * ocfs2_extent_tree contains info for the root of the b-tree, it must have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * root ocfs2_extent_list and a root_bh so that they can be used in the b-tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * functions. It needs the ocfs2_caching_info structure associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * I/O on the tree. With metadata ecc, we now call different journal_access
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * functions for each type of metadata, so it must have the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * root_journal_access function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * ocfs2_extent_tree_operations abstract the normal operations we do for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * the root of extent b-tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct ocfs2_extent_tree_operations;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct ocfs2_extent_tree {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) const struct ocfs2_extent_tree_operations *et_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct buffer_head *et_root_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ocfs2_extent_list *et_root_el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct ocfs2_caching_info *et_ci;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) ocfs2_journal_access_func et_root_journal_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void *et_object;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int et_max_leaf_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct ocfs2_cached_dealloc_ctxt *et_dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * ocfs2_init_*_extent_tree() will fill an ocfs2_extent_tree from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * specified object buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) void ocfs2_init_dinode_extent_tree(struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct buffer_head *bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void ocfs2_init_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) struct buffer_head *bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct ocfs2_xattr_value_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct ocfs2_xattr_value_buf *vb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) void ocfs2_init_dx_root_extent_tree(struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct buffer_head *bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) void ocfs2_init_refcount_extent_tree(struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct buffer_head *bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * Read an extent block into *bh. If *bh is NULL, a bh will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * allocated. This is a cached read. The extent block will be validated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * with ocfs2_validate_extent_block().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) int ocfs2_read_extent_block(struct ocfs2_caching_info *ci, u64 eb_blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) struct buffer_head **bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct ocfs2_alloc_context;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) int ocfs2_insert_extent(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) u32 cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) u64 start_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) u32 new_clusters,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u8 flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct ocfs2_alloc_context *meta_ac);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) enum ocfs2_alloc_restarted {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) RESTART_NONE = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) RESTART_TRANS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) RESTART_META
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int ocfs2_add_clusters_in_btree(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u32 *logical_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) u32 clusters_to_add,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int mark_unwritten,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct ocfs2_alloc_context *data_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) enum ocfs2_alloc_restarted *reason_ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct ocfs2_cached_dealloc_ctxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct ocfs2_path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int ocfs2_split_extent(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct ocfs2_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) int split_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct ocfs2_extent_rec *split_rec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct ocfs2_cached_dealloc_ctxt *dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int ocfs2_mark_extent_written(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) handle_t *handle, u32 cpos, u32 len, u32 phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) struct ocfs2_cached_dealloc_ctxt *dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) int ocfs2_change_extent_flag(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u32 cpos, u32 len, u32 phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) struct ocfs2_cached_dealloc_ctxt *dealloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int new_flags, int clear_flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int ocfs2_remove_extent(handle_t *handle, struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u32 cpos, u32 len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct ocfs2_alloc_context *meta_ac,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct ocfs2_cached_dealloc_ctxt *dealloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) int ocfs2_remove_btree_range(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) u32 cpos, u32 phys_cpos, u32 len, int flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct ocfs2_cached_dealloc_ctxt *dealloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) u64 refcount_loc, bool refcount_tree_locked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int ocfs2_num_free_extents(struct ocfs2_extent_tree *et);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * how many new metadata chunks would an allocation need at maximum?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * Please note that the caller must make sure that root_el is the root
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * the result may be wrong.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) static inline int ocfs2_extend_meta_needed(struct ocfs2_extent_list *root_el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * Rather than do all the work of determining how much we need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * (involves a ton of reads and locks), just ask for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * maximal limit. That's a tree depth shift. So, one block for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * level of the tree (current l_tree_depth), one block for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * new tree_depth==0 extent_block, and one block at the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * top-of-the tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) return le16_to_cpu(root_el->l_tree_depth) + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) void ocfs2_dinode_new_extent_list(struct inode *inode, struct ocfs2_dinode *di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) void ocfs2_set_inode_data_inline(struct inode *inode, struct ocfs2_dinode *di);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) int ocfs2_convert_inline_data_to_extents(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) struct buffer_head *di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int ocfs2_truncate_log_init(struct ocfs2_super *osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) void ocfs2_truncate_log_shutdown(struct ocfs2_super *osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void ocfs2_schedule_truncate_log_flush(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) int cancel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int ocfs2_flush_truncate_log(struct ocfs2_super *osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int ocfs2_begin_truncate_log_recovery(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int slot_num,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct ocfs2_dinode **tl_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int ocfs2_complete_truncate_log_recovery(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct ocfs2_dinode *tl_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int ocfs2_truncate_log_needs_flush(struct ocfs2_super *osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int ocfs2_truncate_log_append(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) u64 start_blk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) unsigned int num_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) int __ocfs2_flush_truncate_log(struct ocfs2_super *osb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) int ocfs2_try_to_free_truncate_log(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) unsigned int needed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * Process local structure which describes the block unlinks done
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * during an operation. This is populated via
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * ocfs2_cache_block_dealloc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * ocfs2_run_deallocs() should be called after the potentially
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) * de-allocating routines. No journal handles should be open, and most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) * locks should have been dropped.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) struct ocfs2_cached_dealloc_ctxt {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct ocfs2_per_slot_free_list *c_first_suballocator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct ocfs2_cached_block_free *c_global_allocator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static inline void ocfs2_init_dealloc_ctxt(struct ocfs2_cached_dealloc_ctxt *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) c->c_first_suballocator = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) c->c_global_allocator = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) int ocfs2_cache_cluster_dealloc(struct ocfs2_cached_dealloc_ctxt *ctxt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) u64 blkno, unsigned int bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) int ocfs2_cache_block_dealloc(struct ocfs2_cached_dealloc_ctxt *ctxt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int type, int slot, u64 suballoc, u64 blkno,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) unsigned int bit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static inline int ocfs2_dealloc_has_cluster(struct ocfs2_cached_dealloc_ctxt *c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return c->c_global_allocator != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) int ocfs2_run_deallocs(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct ocfs2_cached_dealloc_ctxt *ctxt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) struct ocfs2_truncate_context {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) struct ocfs2_cached_dealloc_ctxt tc_dealloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) int tc_ext_alloc_locked; /* is it cluster locked? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* these get destroyed once it's passed to ocfs2_commit_truncate. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct buffer_head *tc_last_eb_bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int ocfs2_zero_range_for_truncate(struct inode *inode, handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) u64 range_start, u64 range_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) int ocfs2_commit_truncate(struct ocfs2_super *osb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct buffer_head *di_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int ocfs2_truncate_inline(struct inode *inode, struct buffer_head *di_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned int start, unsigned int end, int trunc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) int ocfs2_find_leaf(struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct ocfs2_extent_list *root_el, u32 cpos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct buffer_head **leaf_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int ocfs2_search_extent_list(struct ocfs2_extent_list *el, u32 v_cluster);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) int ocfs2_trim_fs(struct super_block *sb, struct fstrim_range *range);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * Helper function to look at the # of clusters in an extent record.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) static inline unsigned int ocfs2_rec_clusters(struct ocfs2_extent_list *el,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct ocfs2_extent_rec *rec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) * Cluster count in extent records is slightly different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) * between interior nodes and leaf nodes. This is to support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) * unwritten extents which need a flags field in leaf node
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) * records, thus shrinking the available space for a clusters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) * field.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) if (el->l_tree_depth)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return le32_to_cpu(rec->e_int_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return le16_to_cpu(rec->e_leaf_clusters);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) * This is only valid for leaf nodes, which are the only ones that can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * have empty extents anyway.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static inline int ocfs2_is_empty_extent(struct ocfs2_extent_rec *rec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) return !rec->e_leaf_clusters;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) int ocfs2_grab_pages(struct inode *inode, loff_t start, loff_t end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) struct page **pages, int *num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) void ocfs2_map_and_dirty_page(struct inode *inode, handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) unsigned int from, unsigned int to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) struct page *page, int zero, u64 *phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) * Structures which describe a path through a btree, and functions to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) * manipulate them.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) * The idea here is to be as generic as possible with the tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * manipulation code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct ocfs2_path_item {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct ocfs2_extent_list *el;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #define OCFS2_MAX_PATH_DEPTH 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct ocfs2_path {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int p_tree_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) ocfs2_journal_access_func p_root_access;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct ocfs2_path_item p_node[OCFS2_MAX_PATH_DEPTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) #define path_root_bh(_path) ((_path)->p_node[0].bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #define path_root_el(_path) ((_path)->p_node[0].el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) #define path_root_access(_path)((_path)->p_root_access)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #define path_leaf_bh(_path) ((_path)->p_node[(_path)->p_tree_depth].bh)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) #define path_leaf_el(_path) ((_path)->p_node[(_path)->p_tree_depth].el)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #define path_num_items(_path) ((_path)->p_tree_depth + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) void ocfs2_reinit_path(struct ocfs2_path *path, int keep_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) void ocfs2_free_path(struct ocfs2_path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) int ocfs2_find_path(struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) struct ocfs2_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) u32 cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct ocfs2_path *ocfs2_new_path_from_path(struct ocfs2_path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct ocfs2_path *ocfs2_new_path_from_et(struct ocfs2_extent_tree *et);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) int ocfs2_path_bh_journal_access(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct ocfs2_path *path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) int ocfs2_journal_access_path(struct ocfs2_caching_info *ci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct ocfs2_path *path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) int ocfs2_find_cpos_for_right_leaf(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) struct ocfs2_path *path, u32 *cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) int ocfs2_find_cpos_for_left_leaf(struct super_block *sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct ocfs2_path *path, u32 *cpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) int ocfs2_find_subtree_root(struct ocfs2_extent_tree *et,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) struct ocfs2_path *left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) struct ocfs2_path *right);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) #endif /* OCFS2_ALLOC_H */