Skip to content

Commit 5c8483c

Browse files
Christoph HellwigDarrick J. Wong
authored andcommitted
xfs: move metadata health tracking to the generic group structure
Prepare for also tracking the health status of the upcoming realtime groups by moving the health tracking code to the generic xfs_group structure. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 86437e6 commit 5c8483c

File tree

8 files changed

+95
-92
lines changed

8 files changed

+95
-92
lines changed

fs/xfs/libxfs/xfs_ag.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ xfs_perag_alloc(
232232
/* Place kernel structure only init below this point. */
233233
spin_lock_init(&pag->pag_ici_lock);
234234
spin_lock_init(&pag->pagb_lock);
235-
spin_lock_init(&pag->pag_state_lock);
236235
INIT_DELAYED_WORK(&pag->pag_blockgc_work, xfs_blockgc_worker);
237236
INIT_RADIX_TREE(&pag->pag_ici_root, GFP_ATOMIC);
238237
xfs_defer_drain_init(&pag->pag_intents_drain);

fs/xfs/libxfs/xfs_ag.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,6 @@ struct xfs_perag {
6969
#ifdef __KERNEL__
7070
/* -- kernel only structures below this line -- */
7171

72-
/*
73-
* Bitsets of per-ag metadata that have been checked and/or are sick.
74-
* Callers should hold pag_state_lock before accessing this field.
75-
*/
76-
uint16_t pag_checked;
77-
uint16_t pag_sick;
78-
7972
#ifdef CONFIG_XFS_ONLINE_REPAIR
8073
/*
8174
* Alternate btree heights so that online repair won't trip the write
@@ -87,8 +80,6 @@ struct xfs_perag {
8780
uint8_t pagf_repair_rmap_level;
8881
#endif
8982

90-
spinlock_t pag_state_lock;
91-
9283
spinlock_t pagb_lock; /* lock for pagb_tree */
9384
struct rb_root pagb_tree; /* ordered tree of busy extents */
9485
unsigned int pagb_gen; /* generation count for pagb_tree */

fs/xfs/libxfs/xfs_group.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ xfs_group_insert(
182182
xg->xg_gno = index;
183183
xg->xg_type = type;
184184

185+
#ifdef __KERNEL__
186+
spin_lock_init(&xg->xg_state_lock);
187+
#endif
188+
185189
/* Active ref owned by mount indicates group is online. */
186190
atomic_set(&xg->xg_active_ref, 1);
187191

fs/xfs/libxfs/xfs_group.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ struct xfs_group {
1111
enum xfs_group_type xg_type;
1212
atomic_t xg_ref; /* passive reference count */
1313
atomic_t xg_active_ref; /* active reference count */
14+
15+
#ifdef __KERNEL__
16+
/* -- kernel only structures below this line -- */
17+
18+
/*
19+
* Bitsets of per-ag metadata that have been checked and/or are sick.
20+
* Callers should hold xg_state_lock before accessing this field.
21+
*/
22+
uint16_t xg_checked;
23+
uint16_t xg_sick;
24+
spinlock_t xg_state_lock;
25+
#endif /* __KERNEL__ */
1426
};
1527

1628
struct xfs_group *xfs_group_get(struct xfs_mount *mp, uint32_t index,

fs/xfs/libxfs/xfs_health.h

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef __XFS_HEALTH_H__
77
#define __XFS_HEALTH_H__
88

9+
struct xfs_group;
10+
911
/*
1012
* In-Core Filesystem Health Assessments
1113
* =====================================
@@ -197,10 +199,12 @@ void xfs_rt_measure_sickness(struct xfs_mount *mp, unsigned int *sick,
197199

198200
void xfs_agno_mark_sick(struct xfs_mount *mp, xfs_agnumber_t agno,
199201
unsigned int mask);
200-
void xfs_ag_mark_sick(struct xfs_perag *pag, unsigned int mask);
201-
void xfs_ag_mark_corrupt(struct xfs_perag *pag, unsigned int mask);
202-
void xfs_ag_mark_healthy(struct xfs_perag *pag, unsigned int mask);
203-
void xfs_ag_measure_sickness(struct xfs_perag *pag, unsigned int *sick,
202+
void xfs_group_mark_sick(struct xfs_group *xg, unsigned int mask);
203+
#define xfs_ag_mark_sick(pag, mask) \
204+
xfs_group_mark_sick(pag_group(pag), (mask))
205+
void xfs_group_mark_corrupt(struct xfs_group *xg, unsigned int mask);
206+
void xfs_group_mark_healthy(struct xfs_group *xg, unsigned int mask);
207+
void xfs_group_measure_sickness(struct xfs_group *xg, unsigned int *sick,
204208
unsigned int *checked);
205209

206210
void xfs_inode_mark_sick(struct xfs_inode *ip, unsigned int mask);
@@ -227,22 +231,19 @@ xfs_fs_has_sickness(struct xfs_mount *mp, unsigned int mask)
227231
}
228232

229233
static inline bool
230-
xfs_rt_has_sickness(struct xfs_mount *mp, unsigned int mask)
234+
xfs_group_has_sickness(
235+
struct xfs_group *xg,
236+
unsigned int mask)
231237
{
232-
unsigned int sick, checked;
233-
234-
xfs_rt_measure_sickness(mp, &sick, &checked);
235-
return sick & mask;
236-
}
237-
238-
static inline bool
239-
xfs_ag_has_sickness(struct xfs_perag *pag, unsigned int mask)
240-
{
241-
unsigned int sick, checked;
238+
unsigned int sick, checked;
242239

243-
xfs_ag_measure_sickness(pag, &sick, &checked);
240+
xfs_group_measure_sickness(xg, &sick, &checked);
244241
return sick & mask;
245242
}
243+
#define xfs_ag_has_sickness(pag, mask) \
244+
xfs_group_has_sickness(pag_group(pag), (mask))
245+
#define xfs_ag_is_healthy(pag) \
246+
(!xfs_ag_has_sickness((pag), UINT_MAX))
246247

247248
static inline bool
248249
xfs_inode_has_sickness(struct xfs_inode *ip, unsigned int mask)
@@ -259,18 +260,6 @@ xfs_fs_is_healthy(struct xfs_mount *mp)
259260
return !xfs_fs_has_sickness(mp, -1U);
260261
}
261262

262-
static inline bool
263-
xfs_rt_is_healthy(struct xfs_mount *mp)
264-
{
265-
return !xfs_rt_has_sickness(mp, -1U);
266-
}
267-
268-
static inline bool
269-
xfs_ag_is_healthy(struct xfs_perag *pag)
270-
{
271-
return !xfs_ag_has_sickness(pag, -1U);
272-
}
273-
274263
static inline bool
275264
xfs_inode_is_healthy(struct xfs_inode *ip)
276265
{

fs/xfs/scrub/health.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ xchk_mark_all_healthy(
165165
xfs_fs_mark_healthy(mp, XFS_SICK_FS_INDIRECT);
166166
xfs_rt_mark_healthy(mp, XFS_SICK_RT_INDIRECT);
167167
while ((pag = xfs_perag_next(mp, pag)))
168-
xfs_ag_mark_healthy(pag, XFS_SICK_AG_INDIRECT);
168+
xfs_group_mark_healthy(pag_group(pag), XFS_SICK_AG_INDIRECT);
169169
}
170170

171171
/*
@@ -206,9 +206,9 @@ xchk_update_health(
206206
case XHG_AG:
207207
pag = xfs_perag_get(sc->mp, sc->sm->sm_agno);
208208
if (bad)
209-
xfs_ag_mark_corrupt(pag, sc->sick_mask);
209+
xfs_group_mark_corrupt(pag_group(pag), sc->sick_mask);
210210
else
211-
xfs_ag_mark_healthy(pag, sc->sick_mask);
211+
xfs_group_mark_healthy(pag_group(pag), sc->sick_mask);
212212
xfs_perag_put(pag);
213213
break;
214214
case XHG_INO:
@@ -306,7 +306,7 @@ xchk_health_record(
306306
xchk_set_corrupt(sc);
307307

308308
while ((pag = xfs_perag_next(mp, pag))) {
309-
xfs_ag_measure_sickness(pag, &sick, &checked);
309+
xfs_group_measure_sickness(pag_group(pag), &sick, &checked);
310310
if (sick & XFS_SICK_AG_PRIMARY)
311311
xchk_set_corrupt(sc);
312312
}

fs/xfs/xfs_health.c

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ xfs_health_unmount(
3838

3939
/* Measure AG corruption levels. */
4040
while ((pag = xfs_perag_next(mp, pag))) {
41-
xfs_ag_measure_sickness(pag, &sick, &checked);
41+
xfs_group_measure_sickness(pag_group(pag), &sick, &checked);
4242
if (sick) {
43-
trace_xfs_ag_unfixed_corruption(pag, sick);
43+
trace_xfs_group_unfixed_corruption(pag_group(pag),
44+
sick);
4445
warn = true;
4546
}
4647
}
@@ -227,61 +228,65 @@ xfs_agno_mark_sick(
227228

228229
/* Mark unhealthy per-ag metadata. */
229230
void
230-
xfs_ag_mark_sick(
231-
struct xfs_perag *pag,
231+
xfs_group_mark_sick(
232+
struct xfs_group *xg,
232233
unsigned int mask)
233234
{
234235
ASSERT(!(mask & ~XFS_SICK_AG_ALL));
235-
trace_xfs_ag_mark_sick(pag, mask);
236+
trace_xfs_group_mark_sick(xg, mask);
236237

237-
spin_lock(&pag->pag_state_lock);
238-
pag->pag_sick |= mask;
239-
spin_unlock(&pag->pag_state_lock);
238+
spin_lock(&xg->xg_state_lock);
239+
xg->xg_sick |= mask;
240+
spin_unlock(&xg->xg_state_lock);
240241
}
241242

242-
/* Mark per-ag metadata as having been checked and found unhealthy by fsck. */
243+
/*
244+
* Mark per-group metadata as having been checked and found unhealthy by fsck.
245+
*/
243246
void
244-
xfs_ag_mark_corrupt(
245-
struct xfs_perag *pag,
247+
xfs_group_mark_corrupt(
248+
struct xfs_group *xg,
246249
unsigned int mask)
247250
{
248251
ASSERT(!(mask & ~XFS_SICK_AG_ALL));
249-
trace_xfs_ag_mark_corrupt(pag, mask);
252+
trace_xfs_group_mark_corrupt(xg, mask);
250253

251-
spin_lock(&pag->pag_state_lock);
252-
pag->pag_sick |= mask;
253-
pag->pag_checked |= mask;
254-
spin_unlock(&pag->pag_state_lock);
254+
spin_lock(&xg->xg_state_lock);
255+
xg->xg_sick |= mask;
256+
xg->xg_checked |= mask;
257+
spin_unlock(&xg->xg_state_lock);
255258
}
256259

257-
/* Mark per-ag metadata ok. */
260+
/*
261+
* Mark per-group metadata ok.
262+
*/
258263
void
259-
xfs_ag_mark_healthy(
260-
struct xfs_perag *pag,
264+
xfs_group_mark_healthy(
265+
struct xfs_group *xg,
261266
unsigned int mask)
262267
{
263268
ASSERT(!(mask & ~XFS_SICK_AG_ALL));
264-
trace_xfs_ag_mark_healthy(pag, mask);
265-
266-
spin_lock(&pag->pag_state_lock);
267-
pag->pag_sick &= ~mask;
268-
if (!(pag->pag_sick & XFS_SICK_AG_PRIMARY))
269-
pag->pag_sick &= ~XFS_SICK_AG_SECONDARY;
270-
pag->pag_checked |= mask;
271-
spin_unlock(&pag->pag_state_lock);
269+
trace_xfs_group_mark_healthy(xg, mask);
270+
271+
spin_lock(&xg->xg_state_lock);
272+
xg->xg_sick &= ~mask;
273+
if (!(xg->xg_sick & XFS_SICK_AG_PRIMARY))
274+
xg->xg_sick &= ~XFS_SICK_AG_SECONDARY;
275+
xg->xg_checked |= mask;
276+
spin_unlock(&xg->xg_state_lock);
272277
}
273278

274279
/* Sample which per-ag metadata are unhealthy. */
275280
void
276-
xfs_ag_measure_sickness(
277-
struct xfs_perag *pag,
281+
xfs_group_measure_sickness(
282+
struct xfs_group *xg,
278283
unsigned int *sick,
279284
unsigned int *checked)
280285
{
281-
spin_lock(&pag->pag_state_lock);
282-
*sick = pag->pag_sick;
283-
*checked = pag->pag_checked;
284-
spin_unlock(&pag->pag_state_lock);
286+
spin_lock(&xg->xg_state_lock);
287+
*sick = xg->xg_sick;
288+
*checked = xg->xg_checked;
289+
spin_unlock(&xg->xg_state_lock);
285290
}
286291

287292
/* Mark the unhealthy parts of an inode. */
@@ -447,7 +452,7 @@ xfs_ag_geom_health(
447452
ageo->ag_sick = 0;
448453
ageo->ag_checked = 0;
449454

450-
xfs_ag_measure_sickness(pag, &sick, &checked);
455+
xfs_group_measure_sickness(pag_group(pag), &sick, &checked);
451456
for (m = ag_map; m->sick_mask; m++) {
452457
if (checked & m->sick_mask)
453458
ageo->ag_checked |= m->ioctl_mask;

fs/xfs/xfs_trace.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4215,31 +4215,34 @@ DEFINE_FS_CORRUPT_EVENT(xfs_rt_mark_corrupt);
42154215
DEFINE_FS_CORRUPT_EVENT(xfs_rt_mark_healthy);
42164216
DEFINE_FS_CORRUPT_EVENT(xfs_rt_unfixed_corruption);
42174217

4218-
DECLARE_EVENT_CLASS(xfs_ag_corrupt_class,
4219-
TP_PROTO(const struct xfs_perag *pag, unsigned int flags),
4220-
TP_ARGS(pag, flags),
4218+
DECLARE_EVENT_CLASS(xfs_group_corrupt_class,
4219+
TP_PROTO(const struct xfs_group *xg, unsigned int flags),
4220+
TP_ARGS(xg, flags),
42214221
TP_STRUCT__entry(
42224222
__field(dev_t, dev)
4223-
__field(xfs_agnumber_t, agno)
4223+
__field(enum xfs_group_type, type)
4224+
__field(uint32_t, index)
42244225
__field(unsigned int, flags)
42254226
),
42264227
TP_fast_assign(
4227-
__entry->dev = pag_mount(pag)->m_super->s_dev;
4228-
__entry->agno = pag_agno(pag);
4228+
__entry->dev = xg->xg_mount->m_super->s_dev;
4229+
__entry->type = xg->xg_type;
4230+
__entry->index = xg->xg_gno;
42294231
__entry->flags = flags;
42304232
),
4231-
TP_printk("dev %d:%d agno 0x%x flags 0x%x",
4233+
TP_printk("dev %d:%d %sno 0x%x flags 0x%x",
42324234
MAJOR(__entry->dev), MINOR(__entry->dev),
4233-
__entry->agno, __entry->flags)
4235+
__print_symbolic(__entry->type, XG_TYPE_STRINGS),
4236+
__entry->index, __entry->flags)
42344237
);
4235-
#define DEFINE_AG_CORRUPT_EVENT(name) \
4236-
DEFINE_EVENT(xfs_ag_corrupt_class, name, \
4237-
TP_PROTO(const struct xfs_perag *pag, unsigned int flags), \
4238-
TP_ARGS(pag, flags))
4239-
DEFINE_AG_CORRUPT_EVENT(xfs_ag_mark_sick);
4240-
DEFINE_AG_CORRUPT_EVENT(xfs_ag_mark_corrupt);
4241-
DEFINE_AG_CORRUPT_EVENT(xfs_ag_mark_healthy);
4242-
DEFINE_AG_CORRUPT_EVENT(xfs_ag_unfixed_corruption);
4238+
#define DEFINE_GROUP_CORRUPT_EVENT(name) \
4239+
DEFINE_EVENT(xfs_group_corrupt_class, name, \
4240+
TP_PROTO(const struct xfs_group *xg, unsigned int flags), \
4241+
TP_ARGS(xg, flags))
4242+
DEFINE_GROUP_CORRUPT_EVENT(xfs_group_mark_sick);
4243+
DEFINE_GROUP_CORRUPT_EVENT(xfs_group_mark_corrupt);
4244+
DEFINE_GROUP_CORRUPT_EVENT(xfs_group_mark_healthy);
4245+
DEFINE_GROUP_CORRUPT_EVENT(xfs_group_unfixed_corruption);
42434246

42444247
DECLARE_EVENT_CLASS(xfs_inode_corrupt_class,
42454248
TP_PROTO(struct xfs_inode *ip, unsigned int flags),

0 commit comments

Comments
 (0)