0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _CHAINALLOC_H_
0011 #define _CHAINALLOC_H_
0012
0013 struct ocfs2_suballoc_result;
0014 typedef int (group_search_t)(struct inode *,
0015 struct buffer_head *,
0016 u32,
0017 u32,
0018 u64,
0019 struct ocfs2_suballoc_result *);
0020
0021
0022 struct ocfs2_alloc_context {
0023 struct inode *ac_inode;
0024 struct buffer_head *ac_bh;
0025 u32 ac_alloc_slot;
0026 u32 ac_bits_wanted;
0027 u32 ac_bits_given;
0028 #define OCFS2_AC_USE_LOCAL 1
0029 #define OCFS2_AC_USE_MAIN 2
0030 #define OCFS2_AC_USE_INODE 3
0031 #define OCFS2_AC_USE_META 4
0032 u32 ac_which;
0033
0034
0035 u16 ac_chain;
0036 int ac_disable_chain_relink;
0037 group_search_t *ac_group_search;
0038
0039 u64 ac_last_group;
0040 u64 ac_max_block;
0041
0042
0043 int ac_find_loc_only;
0044 struct ocfs2_suballoc_result *ac_find_loc_priv;
0045
0046 struct ocfs2_alloc_reservation *ac_resv;
0047 };
0048
0049 void ocfs2_init_steal_slots(struct ocfs2_super *osb);
0050 void ocfs2_free_alloc_context(struct ocfs2_alloc_context *ac);
0051 static inline int ocfs2_alloc_context_bits_left(struct ocfs2_alloc_context *ac)
0052 {
0053 return ac->ac_bits_wanted - ac->ac_bits_given;
0054 }
0055
0056
0057
0058
0059
0060
0061 int ocfs2_reserve_new_metadata(struct ocfs2_super *osb,
0062 struct ocfs2_extent_list *root_el,
0063 struct ocfs2_alloc_context **ac);
0064 int ocfs2_reserve_new_metadata_blocks(struct ocfs2_super *osb,
0065 int blocks,
0066 struct ocfs2_alloc_context **ac);
0067 int ocfs2_reserve_new_inode(struct ocfs2_super *osb,
0068 struct ocfs2_alloc_context **ac);
0069 int ocfs2_reserve_clusters(struct ocfs2_super *osb,
0070 u32 bits_wanted,
0071 struct ocfs2_alloc_context **ac);
0072
0073 int ocfs2_alloc_dinode_update_counts(struct inode *inode,
0074 handle_t *handle,
0075 struct buffer_head *di_bh,
0076 u32 num_bits,
0077 u16 chain);
0078 void ocfs2_rollback_alloc_dinode_counts(struct inode *inode,
0079 struct buffer_head *di_bh,
0080 u32 num_bits,
0081 u16 chain);
0082 int ocfs2_block_group_set_bits(handle_t *handle,
0083 struct inode *alloc_inode,
0084 struct ocfs2_group_desc *bg,
0085 struct buffer_head *group_bh,
0086 unsigned int bit_off,
0087 unsigned int num_bits);
0088
0089 int ocfs2_claim_metadata(handle_t *handle,
0090 struct ocfs2_alloc_context *ac,
0091 u32 bits_wanted,
0092 u64 *suballoc_loc,
0093 u16 *suballoc_bit_start,
0094 u32 *num_bits,
0095 u64 *blkno_start);
0096 int ocfs2_claim_new_inode(handle_t *handle,
0097 struct inode *dir,
0098 struct buffer_head *parent_fe_bh,
0099 struct ocfs2_alloc_context *ac,
0100 u64 *suballoc_loc,
0101 u16 *suballoc_bit,
0102 u64 *fe_blkno);
0103 int ocfs2_claim_clusters(handle_t *handle,
0104 struct ocfs2_alloc_context *ac,
0105 u32 min_clusters,
0106 u32 *cluster_start,
0107 u32 *num_clusters);
0108
0109
0110
0111
0112 int __ocfs2_claim_clusters(handle_t *handle,
0113 struct ocfs2_alloc_context *ac,
0114 u32 min_clusters,
0115 u32 max_clusters,
0116 u32 *cluster_start,
0117 u32 *num_clusters);
0118
0119 int ocfs2_free_suballoc_bits(handle_t *handle,
0120 struct inode *alloc_inode,
0121 struct buffer_head *alloc_bh,
0122 unsigned int start_bit,
0123 u64 bg_blkno,
0124 unsigned int count);
0125 int ocfs2_free_dinode(handle_t *handle,
0126 struct inode *inode_alloc_inode,
0127 struct buffer_head *inode_alloc_bh,
0128 struct ocfs2_dinode *di);
0129 int ocfs2_free_clusters(handle_t *handle,
0130 struct inode *bitmap_inode,
0131 struct buffer_head *bitmap_bh,
0132 u64 start_blk,
0133 unsigned int num_clusters);
0134 int ocfs2_release_clusters(handle_t *handle,
0135 struct inode *bitmap_inode,
0136 struct buffer_head *bitmap_bh,
0137 u64 start_blk,
0138 unsigned int num_clusters);
0139
0140 static inline u64 ocfs2_which_suballoc_group(u64 block, unsigned int bit)
0141 {
0142 u64 group = block - (u64) bit;
0143
0144 return group;
0145 }
0146
0147 static inline u32 ocfs2_cluster_from_desc(struct ocfs2_super *osb,
0148 u64 bg_blkno)
0149 {
0150
0151
0152
0153
0154 if (bg_blkno == osb->first_cluster_group_blkno)
0155 return 0;
0156
0157
0158
0159
0160 return ocfs2_blocks_to_clusters(osb->sb, bg_blkno);
0161 }
0162
0163 static inline int ocfs2_is_cluster_bitmap(struct inode *inode)
0164 {
0165 struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
0166 return osb->bitmap_blkno == OCFS2_I(inode)->ip_blkno;
0167 }
0168
0169
0170
0171 int ocfs2_reserve_cluster_bitmap_bits(struct ocfs2_super *osb,
0172 struct ocfs2_alloc_context *ac);
0173 void ocfs2_free_ac_resource(struct ocfs2_alloc_context *ac);
0174
0175
0176
0177 u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster);
0178
0179
0180
0181
0182
0183
0184
0185
0186 int ocfs2_check_group_descriptor(struct super_block *sb,
0187 struct ocfs2_dinode *di,
0188 struct buffer_head *bh);
0189
0190
0191
0192
0193
0194 int ocfs2_read_group_descriptor(struct inode *inode, struct ocfs2_dinode *di,
0195 u64 gd_blkno, struct buffer_head **bh);
0196
0197 int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et,
0198 u32 clusters_to_add, u32 extents_to_split,
0199 struct ocfs2_alloc_context **data_ac,
0200 struct ocfs2_alloc_context **meta_ac);
0201
0202 int ocfs2_test_inode_bit(struct ocfs2_super *osb, u64 blkno, int *res);
0203
0204
0205
0206
0207
0208
0209 int ocfs2_find_new_inode_loc(struct inode *dir,
0210 struct buffer_head *parent_fe_bh,
0211 struct ocfs2_alloc_context *ac,
0212 u64 *fe_blkno);
0213
0214 int ocfs2_claim_new_inode_at_loc(handle_t *handle,
0215 struct inode *dir,
0216 struct ocfs2_alloc_context *ac,
0217 u64 *suballoc_loc,
0218 u16 *suballoc_bit,
0219 u64 di_blkno);
0220
0221 #endif