0001
0002
0003
0004
0005
0006 #ifndef __XFS_ALLOC_H__
0007 #define __XFS_ALLOC_H__
0008
0009 struct xfs_buf;
0010 struct xfs_btree_cur;
0011 struct xfs_mount;
0012 struct xfs_perag;
0013 struct xfs_trans;
0014
0015 extern struct workqueue_struct *xfs_alloc_wq;
0016
0017 unsigned int xfs_agfl_size(struct xfs_mount *mp);
0018
0019
0020
0021
0022 #define XFS_ALLOCTYPE_FIRST_AG 0x02
0023 #define XFS_ALLOCTYPE_THIS_AG 0x08
0024 #define XFS_ALLOCTYPE_START_BNO 0x10
0025 #define XFS_ALLOCTYPE_NEAR_BNO 0x20
0026 #define XFS_ALLOCTYPE_THIS_BNO 0x40
0027
0028
0029 typedef unsigned int xfs_alloctype_t;
0030
0031 #define XFS_ALLOC_TYPES \
0032 { XFS_ALLOCTYPE_FIRST_AG, "FIRST_AG" }, \
0033 { XFS_ALLOCTYPE_THIS_AG, "THIS_AG" }, \
0034 { XFS_ALLOCTYPE_START_BNO, "START_BNO" }, \
0035 { XFS_ALLOCTYPE_NEAR_BNO, "NEAR_BNO" }, \
0036 { XFS_ALLOCTYPE_THIS_BNO, "THIS_BNO" }
0037
0038
0039
0040
0041 #define XFS_ALLOC_FLAG_TRYLOCK 0x00000001
0042 #define XFS_ALLOC_FLAG_FREEING 0x00000002
0043 #define XFS_ALLOC_FLAG_NORMAP 0x00000004
0044 #define XFS_ALLOC_FLAG_NOSHRINK 0x00000008
0045 #define XFS_ALLOC_FLAG_CHECK 0x00000010
0046
0047
0048
0049
0050
0051
0052 typedef struct xfs_alloc_arg {
0053 struct xfs_trans *tp;
0054 struct xfs_mount *mp;
0055 struct xfs_buf *agbp;
0056 struct xfs_perag *pag;
0057 xfs_fsblock_t fsbno;
0058 xfs_agnumber_t agno;
0059 xfs_agblock_t agbno;
0060 xfs_extlen_t minlen;
0061 xfs_extlen_t maxlen;
0062 xfs_extlen_t mod;
0063 xfs_extlen_t prod;
0064 xfs_extlen_t minleft;
0065 xfs_extlen_t total;
0066 xfs_extlen_t alignment;
0067 xfs_extlen_t minalignslop;
0068 xfs_agblock_t min_agbno;
0069 xfs_agblock_t max_agbno;
0070 xfs_extlen_t len;
0071 xfs_alloctype_t type;
0072 xfs_alloctype_t otype;
0073 int datatype;
0074 char wasdel;
0075 char wasfromfl;
0076 struct xfs_owner_info oinfo;
0077 enum xfs_ag_resv_type resv;
0078 #ifdef DEBUG
0079 bool alloc_minlen_only;
0080 #endif
0081 } xfs_alloc_arg_t;
0082
0083
0084
0085
0086 #define XFS_ALLOC_USERDATA (1 << 0)
0087 #define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)
0088 #define XFS_ALLOC_NOBUSY (1 << 2)
0089
0090
0091 unsigned int xfs_alloc_set_aside(struct xfs_mount *mp);
0092 unsigned int xfs_alloc_ag_max_usable(struct xfs_mount *mp);
0093
0094 xfs_extlen_t xfs_alloc_longest_free_extent(struct xfs_perag *pag,
0095 xfs_extlen_t need, xfs_extlen_t reserved);
0096 unsigned int xfs_alloc_min_freelist(struct xfs_mount *mp,
0097 struct xfs_perag *pag);
0098 int xfs_alloc_get_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
0099 struct xfs_buf *agfbp, xfs_agblock_t *bnop, int btreeblk);
0100 int xfs_alloc_put_freelist(struct xfs_perag *pag, struct xfs_trans *tp,
0101 struct xfs_buf *agfbp, struct xfs_buf *agflbp,
0102 xfs_agblock_t bno, int btreeblk);
0103
0104
0105
0106
0107 void
0108 xfs_alloc_compute_maxlevels(
0109 struct xfs_mount *mp);
0110
0111
0112
0113
0114 void
0115 xfs_alloc_log_agf(
0116 struct xfs_trans *tp,
0117 struct xfs_buf *bp,
0118 uint32_t fields);
0119
0120
0121
0122
0123 int
0124 xfs_alloc_vextent(
0125 xfs_alloc_arg_t *args);
0126
0127
0128
0129
0130 int
0131 __xfs_free_extent(
0132 struct xfs_trans *tp,
0133 xfs_fsblock_t bno,
0134 xfs_extlen_t len,
0135 const struct xfs_owner_info *oinfo,
0136 enum xfs_ag_resv_type type,
0137 bool skip_discard);
0138
0139 static inline int
0140 xfs_free_extent(
0141 struct xfs_trans *tp,
0142 xfs_fsblock_t bno,
0143 xfs_extlen_t len,
0144 const struct xfs_owner_info *oinfo,
0145 enum xfs_ag_resv_type type)
0146 {
0147 return __xfs_free_extent(tp, bno, len, oinfo, type, false);
0148 }
0149
0150 int
0151 xfs_alloc_lookup_le(
0152 struct xfs_btree_cur *cur,
0153 xfs_agblock_t bno,
0154 xfs_extlen_t len,
0155 int *stat);
0156
0157 int
0158 xfs_alloc_lookup_ge(
0159 struct xfs_btree_cur *cur,
0160 xfs_agblock_t bno,
0161 xfs_extlen_t len,
0162 int *stat);
0163
0164 int
0165 xfs_alloc_get_rec(
0166 struct xfs_btree_cur *cur,
0167 xfs_agblock_t *bno,
0168 xfs_extlen_t *len,
0169 int *stat);
0170
0171 int xfs_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags,
0172 struct xfs_buf **agfbpp);
0173 int xfs_alloc_read_agf(struct xfs_perag *pag, struct xfs_trans *tp, int flags,
0174 struct xfs_buf **agfbpp);
0175 int xfs_alloc_read_agfl(struct xfs_perag *pag, struct xfs_trans *tp,
0176 struct xfs_buf **bpp);
0177 int xfs_free_agfl_block(struct xfs_trans *, xfs_agnumber_t, xfs_agblock_t,
0178 struct xfs_buf *, struct xfs_owner_info *);
0179 int xfs_alloc_fix_freelist(struct xfs_alloc_arg *args, int flags);
0180 int xfs_free_extent_fix_freelist(struct xfs_trans *tp, struct xfs_perag *pag,
0181 struct xfs_buf **agbp);
0182
0183 xfs_extlen_t xfs_prealloc_blocks(struct xfs_mount *mp);
0184
0185 typedef int (*xfs_alloc_query_range_fn)(
0186 struct xfs_btree_cur *cur,
0187 const struct xfs_alloc_rec_incore *rec,
0188 void *priv);
0189
0190 int xfs_alloc_query_range(struct xfs_btree_cur *cur,
0191 const struct xfs_alloc_rec_incore *low_rec,
0192 const struct xfs_alloc_rec_incore *high_rec,
0193 xfs_alloc_query_range_fn fn, void *priv);
0194 int xfs_alloc_query_all(struct xfs_btree_cur *cur, xfs_alloc_query_range_fn fn,
0195 void *priv);
0196
0197 int xfs_alloc_has_record(struct xfs_btree_cur *cur, xfs_agblock_t bno,
0198 xfs_extlen_t len, bool *exist);
0199
0200 typedef int (*xfs_agfl_walk_fn)(struct xfs_mount *mp, xfs_agblock_t bno,
0201 void *priv);
0202 int xfs_agfl_walk(struct xfs_mount *mp, struct xfs_agf *agf,
0203 struct xfs_buf *agflbp, xfs_agfl_walk_fn walk_fn, void *priv);
0204
0205 static inline __be32 *
0206 xfs_buf_to_agfl_bno(
0207 struct xfs_buf *bp)
0208 {
0209 if (xfs_has_crc(bp->b_mount))
0210 return bp->b_addr + sizeof(struct xfs_agfl);
0211 return bp->b_addr;
0212 }
0213
0214 void __xfs_free_extent_later(struct xfs_trans *tp, xfs_fsblock_t bno,
0215 xfs_filblks_t len, const struct xfs_owner_info *oinfo,
0216 bool skip_discard);
0217
0218
0219
0220
0221
0222 struct xfs_extent_free_item {
0223 struct list_head xefi_list;
0224 uint64_t xefi_owner;
0225 xfs_fsblock_t xefi_startblock;
0226 xfs_extlen_t xefi_blockcount;
0227 unsigned int xefi_flags;
0228 };
0229
0230 #define XFS_EFI_SKIP_DISCARD (1U << 0)
0231 #define XFS_EFI_ATTR_FORK (1U << 1)
0232 #define XFS_EFI_BMBT_BLOCK (1U << 2)
0233
0234 static inline void
0235 xfs_free_extent_later(
0236 struct xfs_trans *tp,
0237 xfs_fsblock_t bno,
0238 xfs_filblks_t len,
0239 const struct xfs_owner_info *oinfo)
0240 {
0241 __xfs_free_extent_later(tp, bno, len, oinfo, false);
0242 }
0243
0244
0245 extern struct kmem_cache *xfs_extfree_item_cache;
0246
0247 int __init xfs_extfree_intent_init_cache(void);
0248 void xfs_extfree_intent_destroy_cache(void);
0249
0250 #endif