Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * suballoc.h
0004  *
0005  * Defines sub allocator api
0006  *
0007  * Copyright (C) 2003, 2004 Oracle.  All rights reserved.
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,           /* bits_wanted */
0017                  u32,           /* min_bits */
0018                  u64,           /* max_block */
0019                  struct ocfs2_suballoc_result *);
0020                             /* found bits */
0021 
0022 struct ocfs2_alloc_context {
0023     struct inode *ac_inode;    /* which bitmap are we allocating from? */
0024     struct buffer_head *ac_bh; /* file entry bh */
0025     u32    ac_alloc_slot;   /* which slot are we allocating from? */
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     /* these are used by the chain search */
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;  /* Highest block number to allocate. 0 is
0041                  the same as ~0 - unlimited */
0042 
0043     int    ac_find_loc_only;  /* hack for reflink operation ordering */
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  * Please note that the caller must make sure that root_el is the root
0058  * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
0059  * the result may be wrong.
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  * Use this variant of ocfs2_claim_clusters to specify a maxiumum
0110  * number of clusters smaller than the allocation reserved.
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     /* This should work for all block group descriptors as only
0151      * the 1st group descriptor of the cluster bitmap is
0152      * different. */
0153 
0154     if (bg_blkno == osb->first_cluster_group_blkno)
0155         return 0;
0156 
0157     /* the rest of the block groups are located at the beginning
0158      * of their 1st cluster, so a direct translation just
0159      * works. */
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 /* This is for local alloc ONLY. Others should use the task-specific
0170  * apis above. */
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 /* given a cluster offset, calculate which block group it belongs to
0176  * and return that block offset. */
0177 u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster);
0178 
0179 /*
0180  * By default, ocfs2_read_group_descriptor() calls ocfs2_error() when it
0181  * finds a problem.  A caller that wants to check a group descriptor
0182  * without going readonly should read the block with ocfs2_read_block[s]()
0183  * and then checking it with this function.  This is only resize, really.
0184  * Everyone else should be using ocfs2_read_group_descriptor().
0185  */
0186 int ocfs2_check_group_descriptor(struct super_block *sb,
0187                  struct ocfs2_dinode *di,
0188                  struct buffer_head *bh);
0189 /*
0190  * Read a group descriptor block into *bh.  If *bh is NULL, a bh will be
0191  * allocated.  This is a cached read.  The descriptor will be validated with
0192  * ocfs2_validate_group_descriptor().
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  * The following two interfaces are for ocfs2_create_inode_in_orphan().
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 /* _CHAINALLOC_H_ */