1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (c) 2022-2024 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <djwong@kernel.org>
*/
#ifndef __LIBXFS_RTGROUP_H
#define __LIBXFS_RTGROUP_H 1
#include "xfs_group.h"
struct xfs_mount;
struct xfs_trans;
enum xfs_rtg_inodes {
XFS_RTGI_BITMAP, /* allocation bitmap */
XFS_RTGI_SUMMARY, /* allocation summary */
XFS_RTGI_RMAP, /* rmap btree inode */
XFS_RTGI_REFCOUNT, /* refcount btree inode */
XFS_RTGI_MAX,
};
#ifdef MAX_LOCKDEP_SUBCLASSES
static_assert(XFS_RTGI_MAX <= MAX_LOCKDEP_SUBCLASSES);
#endif
/*
* Realtime group incore structure, similar to the per-AG structure.
*/
struct xfs_rtgroup {
struct xfs_group rtg_group;
/* per-rtgroup metadata inodes */
struct xfs_inode *rtg_inodes[XFS_RTGI_MAX];
/* Number of blocks in this group */
xfs_rtxnum_t rtg_extents;
/*
* For bitmap based RT devices this points to a cache of rt summary
* level per bitmap block with the invariant that rtg_rsum_cache[bbno]
* > the maximum i for which rsum[i][bbno] != 0, or 0 if
* rsum[i][bbno] == 0 for all i.
* Reads and writes are serialized by the rsumip inode lock.
*
* For zoned RT devices this points to the open zone structure for
* a group that is open for writers, or is NULL.
*/
union {
uint8_t *rtg_rsum_cache;
struct xfs_open_zone *rtg_open_zone;
};
};
/*
* For zoned RT devices this is set on groups that have no written blocks
* and can be picked by the allocator for opening.
*/
#define XFS_RTG_FREE XA_MARK_0
/*
* For zoned RT devices this is set on groups that are fully written and that
* have unused blocks. Used by the garbage collection to pick targets.
*/
#define XFS_RTG_RECLAIMABLE XA_MARK_1
static inline struct xfs_rtgroup *to_rtg(struct xfs_group *xg)
{
return container_of(xg, struct xfs_rtgroup, rtg_group);
}
static inline struct xfs_group *rtg_group(struct xfs_rtgroup *rtg)
{
return &rtg->rtg_group;
}
static inline struct xfs_mount *rtg_mount(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_group.xg_mount;
}
static inline xfs_rgnumber_t rtg_rgno(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_group.xg_gno;
}
static inline xfs_rgblock_t rtg_blocks(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_group.xg_block_count;
}
static inline struct xfs_inode *rtg_bitmap(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_inodes[XFS_RTGI_BITMAP];
}
static inline struct xfs_inode *rtg_summary(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_inodes[XFS_RTGI_SUMMARY];
}
static inline struct xfs_inode *rtg_rmap(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_inodes[XFS_RTGI_RMAP];
}
static inline struct xfs_inode *rtg_refcount(const struct xfs_rtgroup *rtg)
{
return rtg->rtg_inodes[XFS_RTGI_REFCOUNT];
}
/* Passive rtgroup references */
static inline struct xfs_rtgroup *
xfs_rtgroup_get(
struct xfs_mount *mp,
xfs_rgnumber_t rgno)
{
return to_rtg(xfs_group_get(mp, rgno, XG_TYPE_RTG));
}
static inline struct xfs_rtgroup *
xfs_rtgroup_hold(
struct xfs_rtgroup *rtg)
{
return to_rtg(xfs_group_hold(rtg_group(rtg)));
}
static inline void
xfs_rtgroup_put(
struct xfs_rtgroup *rtg)
{
xfs_group_put(rtg_group(rtg));
}
/* Active rtgroup references */
static inline struct xfs_rtgroup *
xfs_rtgroup_grab(
struct xfs_mount *mp,
xfs_rgnumber_t rgno)
{
return to_rtg(xfs_group_grab(mp, rgno, XG_TYPE_RTG));
}
static inline void
xfs_rtgroup_rele(
struct xfs_rtgroup *rtg)
{
xfs_group_rele(rtg_group(rtg));
}
static inline struct xfs_rtgroup *
xfs_rtgroup_next_range(
struct xfs_mount *mp,
struct xfs_rtgroup *rtg,
xfs_rgnumber_t start_rgno,
xfs_rgnumber_t end_rgno)
{
return to_rtg(xfs_group_next_range(mp, rtg ? rtg_group(rtg) : NULL,
start_rgno, end_rgno, XG_TYPE_RTG));
}
static inline struct xfs_rtgroup *
xfs_rtgroup_next(
struct xfs_mount *mp,
struct xfs_rtgroup *rtg)
{
return xfs_rtgroup_next_range(mp, rtg, 0, mp->m_sb.sb_rgcount - 1);
}
static inline bool
xfs_verify_rgbno(
struct xfs_rtgroup *rtg,
xfs_rgblock_t rgbno)
{
ASSERT(xfs_has_rtgroups(rtg_mount(rtg)));
return xfs_verify_gbno(rtg_group(rtg), rgbno);
}
/*
* Check that [@rgbno,@len] is a valid extent range in @rtg.
*
* Must only be used for RTG-enabled file systems.
*/
static inline bool
xfs_verify_rgbext(
struct xfs_rtgroup *rtg,
xfs_rgblock_t rgbno,
xfs_extlen_t len)
{
ASSERT(xfs_has_rtgroups(rtg_mount(rtg)));
return xfs_verify_gbext(rtg_group(rtg), rgbno, len);
}
static inline xfs_rtblock_t
xfs_rgbno_to_rtb(
struct xfs_rtgroup *rtg,
xfs_rgblock_t rgbno)
{
return xfs_gbno_to_fsb(rtg_group(rtg), rgbno);
}
static inline xfs_rgnumber_t
xfs_rtb_to_rgno(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
return xfs_fsb_to_gno(mp, rtbno, XG_TYPE_RTG);
}
static inline xfs_rgblock_t
xfs_rtb_to_rgbno(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
return xfs_fsb_to_gbno(mp, rtbno, XG_TYPE_RTG);
}
/* Is rtbno the start of a RT group? */
static inline bool
xfs_rtbno_is_group_start(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
return (rtbno & mp->m_groups[XG_TYPE_RTG].blkmask) == 0;
}
/* Convert an rtgroups rt extent number into an rgbno. */
static inline xfs_rgblock_t
xfs_rtx_to_rgbno(
struct xfs_rtgroup *rtg,
xfs_rtxnum_t rtx)
{
struct xfs_mount *mp = rtg_mount(rtg);
if (likely(mp->m_rtxblklog >= 0))
return rtx << mp->m_rtxblklog;
return rtx * mp->m_sb.sb_rextsize;
}
static inline xfs_daddr_t
xfs_rtb_to_daddr(
struct xfs_mount *mp,
xfs_rtblock_t rtbno)
{
struct xfs_groups *g = &mp->m_groups[XG_TYPE_RTG];
if (xfs_has_rtgroups(mp) && !g->has_daddr_gaps) {
xfs_rgnumber_t rgno = xfs_rtb_to_rgno(mp, rtbno);
rtbno = (xfs_rtblock_t)rgno * g->blocks + (rtbno & g->blkmask);
}
return XFS_FSB_TO_BB(mp, g->start_fsb + rtbno);
}
static inline xfs_rtblock_t
xfs_daddr_to_rtb(
struct xfs_mount *mp,
xfs_daddr_t daddr)
{
struct xfs_groups *g = &mp->m_groups[XG_TYPE_RTG];
xfs_rfsblock_t bno;
bno = XFS_BB_TO_FSBT(mp, daddr) - g->start_fsb;
if (xfs_has_rtgroups(mp) && !g->has_daddr_gaps) {
xfs_rgnumber_t rgno;
uint32_t rgbno;
rgno = div_u64_rem(bno, g->blocks, &rgbno);
return ((xfs_rtblock_t)rgno << g->blklog) + rgbno;
}
return bno;
}
#ifdef CONFIG_XFS_RT
int xfs_rtgroup_alloc(struct xfs_mount *mp, xfs_rgnumber_t rgno,
xfs_rgnumber_t rgcount, xfs_rtbxlen_t rextents);
void xfs_rtgroup_free(struct xfs_mount *mp, xfs_rgnumber_t rgno);
void xfs_free_rtgroups(struct xfs_mount *mp, xfs_rgnumber_t first_rgno,
xfs_rgnumber_t end_rgno);
int xfs_initialize_rtgroups(struct xfs_mount *mp, xfs_rgnumber_t first_rgno,
xfs_rgnumber_t end_rgno, xfs_rtbxlen_t rextents);
xfs_rtxnum_t __xfs_rtgroup_extents(struct xfs_mount *mp, xfs_rgnumber_t rgno,
xfs_rgnumber_t rgcount, xfs_rtbxlen_t rextents);
xfs_rtxnum_t xfs_rtgroup_extents(struct xfs_mount *mp, xfs_rgnumber_t rgno);
void xfs_rtgroup_calc_geometry(struct xfs_mount *mp, struct xfs_rtgroup *rtg,
xfs_rgnumber_t rgno, xfs_rgnumber_t rgcount,
xfs_rtbxlen_t rextents);
int xfs_update_last_rtgroup_size(struct xfs_mount *mp,
xfs_rgnumber_t prev_rgcount);
/* Lock the rt bitmap inode in exclusive mode */
#define XFS_RTGLOCK_BITMAP (1U << 0)
/* Lock the rt bitmap inode in shared mode */
#define XFS_RTGLOCK_BITMAP_SHARED (1U << 1)
/* Lock the rt rmap inode in exclusive mode */
#define XFS_RTGLOCK_RMAP (1U << 2)
/* Lock the rt refcount inode in exclusive mode */
#define XFS_RTGLOCK_REFCOUNT (1U << 3)
#define XFS_RTGLOCK_ALL_FLAGS (XFS_RTGLOCK_BITMAP | \
XFS_RTGLOCK_BITMAP_SHARED | \
XFS_RTGLOCK_RMAP | \
XFS_RTGLOCK_REFCOUNT)
void xfs_rtgroup_lock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
void xfs_rtgroup_unlock(struct xfs_rtgroup *rtg, unsigned int rtglock_flags);
void xfs_rtgroup_trans_join(struct xfs_trans *tp, struct xfs_rtgroup *rtg,
unsigned int rtglock_flags);
int xfs_rtgroup_get_geometry(struct xfs_rtgroup *rtg,
struct xfs_rtgroup_geometry *rgeo);
int xfs_rtginode_mkdir_parent(struct xfs_mount *mp);
int xfs_rtginode_load_parent(struct xfs_trans *tp);
const char *xfs_rtginode_name(enum xfs_rtg_inodes type);
enum xfs_metafile_type xfs_rtginode_metafile_type(enum xfs_rtg_inodes type);
bool xfs_rtginode_enabled(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type);
void xfs_rtginode_mark_sick(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type);
int xfs_rtginode_load(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type,
struct xfs_trans *tp);
int xfs_rtginode_create(struct xfs_rtgroup *rtg, enum xfs_rtg_inodes type,
bool init);
void xfs_rtginode_irele(struct xfs_inode **ipp);
void xfs_rtginode_irele(struct xfs_inode **ipp);
static inline const char *xfs_rtginode_path(xfs_rgnumber_t rgno,
enum xfs_rtg_inodes type)
{
return kasprintf(GFP_KERNEL, "%u.%s", rgno, xfs_rtginode_name(type));
}
void xfs_update_rtsb(struct xfs_buf *rtsb_bp,
const struct xfs_buf *sb_bp);
struct xfs_buf *xfs_log_rtsb(struct xfs_trans *tp,
const struct xfs_buf *sb_bp);
#else
static inline void xfs_free_rtgroups(struct xfs_mount *mp,
xfs_rgnumber_t first_rgno, xfs_rgnumber_t end_rgno)
{
}
static inline int xfs_initialize_rtgroups(struct xfs_mount *mp,
xfs_rgnumber_t first_rgno, xfs_rgnumber_t end_rgno,
xfs_rtbxlen_t rextents)
{
return 0;
}
# define xfs_rtgroup_extents(mp, rgno) (0)
# define xfs_update_last_rtgroup_size(mp, rgno) (0)
# define xfs_rtgroup_lock(rtg, gf) ((void)0)
# define xfs_rtgroup_unlock(rtg, gf) ((void)0)
# define xfs_rtgroup_trans_join(tp, rtg, gf) ((void)0)
# define xfs_update_rtsb(bp, sb_bp) ((void)0)
# define xfs_log_rtsb(tp, sb_bp) (NULL)
# define xfs_rtgroup_get_geometry(rtg, rgeo) (-EOPNOTSUPP)
#endif /* CONFIG_XFS_RT */
#endif /* __LIBXFS_RTGROUP_H */
|