0001
0002
0003
0004
0005
0006
0007 #ifndef __LIBXFS_AG_H
0008 #define __LIBXFS_AG_H 1
0009
0010 struct xfs_mount;
0011 struct xfs_trans;
0012 struct xfs_perag;
0013
0014
0015
0016
0017
0018
0019 struct xfs_ag_resv {
0020
0021 xfs_extlen_t ar_orig_reserved;
0022
0023 xfs_extlen_t ar_reserved;
0024
0025 xfs_extlen_t ar_asked;
0026 };
0027
0028
0029
0030
0031
0032 struct xfs_perag {
0033 struct xfs_mount *pag_mount;
0034 xfs_agnumber_t pag_agno;
0035 atomic_t pag_ref;
0036 char pagf_init;
0037 char pagi_init;
0038 char pagf_metadata;
0039 char pagi_inodeok;
0040 uint8_t pagf_levels[XFS_BTNUM_AGF];
0041
0042 bool pagf_agflreset;
0043 uint32_t pagf_flcount;
0044 xfs_extlen_t pagf_freeblks;
0045 xfs_extlen_t pagf_longest;
0046 uint32_t pagf_btreeblks;
0047 xfs_agino_t pagi_freecount;
0048 xfs_agino_t pagi_count;
0049
0050
0051
0052
0053
0054
0055 xfs_agino_t pagl_pagino;
0056 xfs_agino_t pagl_leftrec;
0057 xfs_agino_t pagl_rightrec;
0058
0059 int pagb_count;
0060 uint8_t pagf_refcount_level;
0061
0062
0063 struct xfs_ag_resv pag_meta_resv;
0064
0065 struct xfs_ag_resv pag_rmapbt_resv;
0066
0067
0068 struct rcu_head rcu_head;
0069
0070
0071 xfs_agblock_t block_count;
0072 xfs_agblock_t min_block;
0073 xfs_agino_t agino_min;
0074 xfs_agino_t agino_max;
0075
0076 #ifdef __KERNEL__
0077
0078
0079
0080
0081
0082
0083 uint16_t pag_checked;
0084 uint16_t pag_sick;
0085 spinlock_t pag_state_lock;
0086
0087 spinlock_t pagb_lock;
0088 struct rb_root pagb_tree;
0089 unsigned int pagb_gen;
0090 wait_queue_head_t pagb_wait;
0091
0092 atomic_t pagf_fstrms;
0093
0094 spinlock_t pag_ici_lock;
0095 struct radix_tree_root pag_ici_root;
0096 int pag_ici_reclaimable;
0097 unsigned long pag_ici_reclaim_cursor;
0098
0099
0100 spinlock_t pag_buf_lock;
0101 struct rhashtable pag_buf_hash;
0102
0103
0104 struct delayed_work pag_blockgc_work;
0105
0106 #endif
0107 };
0108
0109 int xfs_initialize_perag(struct xfs_mount *mp, xfs_agnumber_t agcount,
0110 xfs_rfsblock_t dcount, xfs_agnumber_t *maxagi);
0111 int xfs_initialize_perag_data(struct xfs_mount *mp, xfs_agnumber_t agno);
0112 void xfs_free_perag(struct xfs_mount *mp);
0113
0114 struct xfs_perag *xfs_perag_get(struct xfs_mount *mp, xfs_agnumber_t agno);
0115 struct xfs_perag *xfs_perag_get_tag(struct xfs_mount *mp, xfs_agnumber_t agno,
0116 unsigned int tag);
0117 void xfs_perag_put(struct xfs_perag *pag);
0118
0119
0120
0121
0122 xfs_agblock_t xfs_ag_block_count(struct xfs_mount *mp, xfs_agnumber_t agno);
0123 void xfs_agino_range(struct xfs_mount *mp, xfs_agnumber_t agno,
0124 xfs_agino_t *first, xfs_agino_t *last);
0125
0126 static inline bool
0127 xfs_verify_agbno(struct xfs_perag *pag, xfs_agblock_t agbno)
0128 {
0129 if (agbno >= pag->block_count)
0130 return false;
0131 if (agbno <= pag->min_block)
0132 return false;
0133 return true;
0134 }
0135
0136
0137
0138
0139
0140 static inline bool
0141 xfs_verify_agino(struct xfs_perag *pag, xfs_agino_t agino)
0142 {
0143 if (agino < pag->agino_min)
0144 return false;
0145 if (agino > pag->agino_max)
0146 return false;
0147 return true;
0148 }
0149
0150
0151
0152
0153
0154 static inline bool
0155 xfs_verify_agino_or_null(struct xfs_perag *pag, xfs_agino_t agino)
0156 {
0157 if (agino == NULLAGINO)
0158 return true;
0159 return xfs_verify_agino(pag, agino);
0160 }
0161
0162 static inline bool
0163 xfs_ag_contains_log(struct xfs_mount *mp, xfs_agnumber_t agno)
0164 {
0165 return mp->m_sb.sb_logstart > 0 &&
0166 agno == XFS_FSB_TO_AGNO(mp, mp->m_sb.sb_logstart);
0167 }
0168
0169
0170
0171
0172 static inline struct xfs_perag *
0173 xfs_perag_next(
0174 struct xfs_perag *pag,
0175 xfs_agnumber_t *agno,
0176 xfs_agnumber_t end_agno)
0177 {
0178 struct xfs_mount *mp = pag->pag_mount;
0179
0180 *agno = pag->pag_agno + 1;
0181 xfs_perag_put(pag);
0182 if (*agno > end_agno)
0183 return NULL;
0184 return xfs_perag_get(mp, *agno);
0185 }
0186
0187 #define for_each_perag_range(mp, agno, end_agno, pag) \
0188 for ((pag) = xfs_perag_get((mp), (agno)); \
0189 (pag) != NULL; \
0190 (pag) = xfs_perag_next((pag), &(agno), (end_agno)))
0191
0192 #define for_each_perag_from(mp, agno, pag) \
0193 for_each_perag_range((mp), (agno), (mp)->m_sb.sb_agcount - 1, (pag))
0194
0195
0196 #define for_each_perag(mp, agno, pag) \
0197 (agno) = 0; \
0198 for_each_perag_from((mp), (agno), (pag))
0199
0200 #define for_each_perag_tag(mp, agno, pag, tag) \
0201 for ((agno) = 0, (pag) = xfs_perag_get_tag((mp), 0, (tag)); \
0202 (pag) != NULL; \
0203 (agno) = (pag)->pag_agno + 1, \
0204 xfs_perag_put(pag), \
0205 (pag) = xfs_perag_get_tag((mp), (agno), (tag)))
0206
0207 struct aghdr_init_data {
0208
0209 xfs_agblock_t agno;
0210 xfs_extlen_t agsize;
0211 struct list_head buffer_list;
0212 xfs_rfsblock_t nfree;
0213
0214
0215 xfs_daddr_t daddr;
0216 size_t numblks;
0217 xfs_btnum_t type;
0218 };
0219
0220 int xfs_ag_init_headers(struct xfs_mount *mp, struct aghdr_init_data *id);
0221 int xfs_ag_shrink_space(struct xfs_perag *pag, struct xfs_trans **tpp,
0222 xfs_extlen_t delta);
0223 int xfs_ag_extend_space(struct xfs_perag *pag, struct xfs_trans *tp,
0224 xfs_extlen_t len);
0225 int xfs_ag_get_geometry(struct xfs_perag *pag, struct xfs_ag_geometry *ageo);
0226
0227 #endif