Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
0004  * All Rights Reserved.
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  * Freespace allocation types.  Argument to xfs_alloc_[v]extent.
0021  */
0022 #define XFS_ALLOCTYPE_FIRST_AG  0x02    /* ... start at ag 0 */
0023 #define XFS_ALLOCTYPE_THIS_AG   0x08    /* anywhere in this a.g. */
0024 #define XFS_ALLOCTYPE_START_BNO 0x10    /* near this block else anywhere */
0025 #define XFS_ALLOCTYPE_NEAR_BNO  0x20    /* in this a.g. and near this block */
0026 #define XFS_ALLOCTYPE_THIS_BNO  0x40    /* at exactly this block */
0027 
0028 /* this should become an enum again when the tracing code is fixed */
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  * Flags for xfs_alloc_fix_freelist.
0040  */
0041 #define XFS_ALLOC_FLAG_TRYLOCK  0x00000001  /* use trylock for buffer locking */
0042 #define XFS_ALLOC_FLAG_FREEING  0x00000002  /* indicate caller is freeing extents*/
0043 #define XFS_ALLOC_FLAG_NORMAP   0x00000004  /* don't modify the rmapbt */
0044 #define XFS_ALLOC_FLAG_NOSHRINK 0x00000008  /* don't shrink the freelist */
0045 #define XFS_ALLOC_FLAG_CHECK    0x00000010  /* test only, don't modify args */
0046 
0047 /*
0048  * Argument structure for xfs_alloc routines.
0049  * This is turned into a structure to avoid having 20 arguments passed
0050  * down several levels of the stack.
0051  */
0052 typedef struct xfs_alloc_arg {
0053     struct xfs_trans *tp;       /* transaction pointer */
0054     struct xfs_mount *mp;       /* file system mount point */
0055     struct xfs_buf  *agbp;      /* buffer for a.g. freelist header */
0056     struct xfs_perag *pag;      /* per-ag struct for this agno */
0057     xfs_fsblock_t   fsbno;      /* file system block number */
0058     xfs_agnumber_t  agno;       /* allocation group number */
0059     xfs_agblock_t   agbno;      /* allocation group-relative block # */
0060     xfs_extlen_t    minlen;     /* minimum size of extent */
0061     xfs_extlen_t    maxlen;     /* maximum size of extent */
0062     xfs_extlen_t    mod;        /* mod value for extent size */
0063     xfs_extlen_t    prod;       /* prod value for extent size */
0064     xfs_extlen_t    minleft;    /* min blocks must be left after us */
0065     xfs_extlen_t    total;      /* total blocks needed in xaction */
0066     xfs_extlen_t    alignment;  /* align answer to multiple of this */
0067     xfs_extlen_t    minalignslop;   /* slop for minlen+alignment calcs */
0068     xfs_agblock_t   min_agbno;  /* set an agbno range for NEAR allocs */
0069     xfs_agblock_t   max_agbno;  /* ... */
0070     xfs_extlen_t    len;        /* output: actual size of extent */
0071     xfs_alloctype_t type;       /* allocation type XFS_ALLOCTYPE_... */
0072     xfs_alloctype_t otype;      /* original allocation type */
0073     int     datatype;   /* mask defining data type treatment */
0074     char        wasdel;     /* set if allocation was prev delayed */
0075     char        wasfromfl;  /* set if allocation is from freelist */
0076     struct xfs_owner_info   oinfo;  /* owner of blocks being allocated */
0077     enum xfs_ag_resv_type   resv;   /* block reservation to use */
0078 #ifdef DEBUG
0079     bool        alloc_minlen_only; /* allocate exact minlen extent */
0080 #endif
0081 } xfs_alloc_arg_t;
0082 
0083 /*
0084  * Defines for datatype
0085  */
0086 #define XFS_ALLOC_USERDATA      (1 << 0)/* allocation is for user data*/
0087 #define XFS_ALLOC_INITIAL_USER_DATA (1 << 1)/* special case start of file */
0088 #define XFS_ALLOC_NOBUSY        (1 << 2)/* Busy extents not allowed */
0089 
0090 /* freespace limit calculations */
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  * Compute and fill in value of m_alloc_maxlevels.
0106  */
0107 void
0108 xfs_alloc_compute_maxlevels(
0109     struct xfs_mount    *mp);   /* file system mount structure */
0110 
0111 /*
0112  * Log the given fields from the agf structure.
0113  */
0114 void
0115 xfs_alloc_log_agf(
0116     struct xfs_trans *tp,   /* transaction pointer */
0117     struct xfs_buf  *bp,    /* buffer for a.g. freelist header */
0118     uint32_t    fields);/* mask of fields to be logged (XFS_AGF_...) */
0119 
0120 /*
0121  * Allocate an extent (variable-size).
0122  */
0123 int             /* error */
0124 xfs_alloc_vextent(
0125     xfs_alloc_arg_t *args); /* allocation argument structure */
0126 
0127 /*
0128  * Free an extent.
0129  */
0130 int             /* error */
0131 __xfs_free_extent(
0132     struct xfs_trans    *tp,    /* transaction pointer */
0133     xfs_fsblock_t       bno,    /* starting block number of extent */
0134     xfs_extlen_t        len,    /* length of extent */
0135     const struct xfs_owner_info *oinfo, /* extent owner */
0136     enum xfs_ag_resv_type   type,   /* block reservation 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             /* error */
0151 xfs_alloc_lookup_le(
0152     struct xfs_btree_cur    *cur,   /* btree cursor */
0153     xfs_agblock_t       bno,    /* starting block of extent */
0154     xfs_extlen_t        len,    /* length of extent */
0155     int         *stat); /* success/failure */
0156 
0157 int             /* error */
0158 xfs_alloc_lookup_ge(
0159     struct xfs_btree_cur    *cur,   /* btree cursor */
0160     xfs_agblock_t       bno,    /* starting block of extent */
0161     xfs_extlen_t        len,    /* length of extent */
0162     int         *stat); /* success/failure */
0163 
0164 int                 /* error */
0165 xfs_alloc_get_rec(
0166     struct xfs_btree_cur    *cur,   /* btree cursor */
0167     xfs_agblock_t       *bno,   /* output: starting block of extent */
0168     xfs_extlen_t        *len,   /* output: length of extent */
0169     int         *stat); /* output: success/failure */
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  * List of extents to be free "later".
0220  * The list is kept sorted on xbf_startblock.
0221  */
0222 struct xfs_extent_free_item {
0223     struct list_head    xefi_list;
0224     uint64_t        xefi_owner;
0225     xfs_fsblock_t       xefi_startblock;/* starting fs block number */
0226     xfs_extlen_t        xefi_blockcount;/* number of blocks in extent */
0227     unsigned int        xefi_flags;
0228 };
0229 
0230 #define XFS_EFI_SKIP_DISCARD    (1U << 0) /* don't issue discard */
0231 #define XFS_EFI_ATTR_FORK   (1U << 1) /* freeing attr fork block */
0232 #define XFS_EFI_BMBT_BLOCK  (1U << 2) /* freeing bmap btree block */
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  /* __XFS_ALLOC_H__ */