Commit a211432c authored by Darrick J. Wong's avatar Darrick J. Wong

xfs: create simplified inode walk function

Create a new iterator function to simplify walking inodes in an XFS
filesystem.  This new iterator will replace the existing open-coded
walking that goes on in various places.
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: default avatarBrian Foster <bfoster@redhat.com>
parent 5bb46e3e
...@@ -81,6 +81,7 @@ xfs-y += xfs_aops.o \ ...@@ -81,6 +81,7 @@ xfs-y += xfs_aops.o \
xfs_iops.o \ xfs_iops.o \
xfs_inode.o \ xfs_inode.o \
xfs_itable.o \ xfs_itable.o \
xfs_iwalk.o \
xfs_message.o \ xfs_message.o \
xfs_mount.o \ xfs_mount.o \
xfs_mru_cache.o \ xfs_mru_cache.o \
......
...@@ -562,6 +562,36 @@ xfs_inobt_max_size( ...@@ -562,6 +562,36 @@ xfs_inobt_max_size(
XFS_INODES_PER_CHUNK); XFS_INODES_PER_CHUNK);
} }
/* Read AGI and create inobt cursor. */
int
xfs_inobt_cur(
struct xfs_mount *mp,
struct xfs_trans *tp,
xfs_agnumber_t agno,
xfs_btnum_t which,
struct xfs_btree_cur **curpp,
struct xfs_buf **agi_bpp)
{
struct xfs_btree_cur *cur;
int error;
ASSERT(*agi_bpp == NULL);
ASSERT(*curpp == NULL);
error = xfs_ialloc_read_agi(mp, tp, agno, agi_bpp);
if (error)
return error;
cur = xfs_inobt_init_cursor(mp, tp, *agi_bpp, agno, which);
if (!cur) {
xfs_trans_brelse(tp, *agi_bpp);
*agi_bpp = NULL;
return -ENOMEM;
}
*curpp = cur;
return 0;
}
static int static int
xfs_inobt_count_blocks( xfs_inobt_count_blocks(
struct xfs_mount *mp, struct xfs_mount *mp,
...@@ -570,15 +600,14 @@ xfs_inobt_count_blocks( ...@@ -570,15 +600,14 @@ xfs_inobt_count_blocks(
xfs_btnum_t btnum, xfs_btnum_t btnum,
xfs_extlen_t *tree_blocks) xfs_extlen_t *tree_blocks)
{ {
struct xfs_buf *agbp; struct xfs_buf *agbp = NULL;
struct xfs_btree_cur *cur; struct xfs_btree_cur *cur = NULL;
int error; int error;
error = xfs_ialloc_read_agi(mp, tp, agno, &agbp); error = xfs_inobt_cur(mp, tp, agno, btnum, &cur, &agbp);
if (error) if (error)
return error; return error;
cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, btnum);
error = xfs_btree_count_blocks(cur, tree_blocks); error = xfs_btree_count_blocks(cur, tree_blocks);
xfs_btree_del_cursor(cur, error); xfs_btree_del_cursor(cur, error);
xfs_trans_brelse(tp, agbp); xfs_trans_brelse(tp, agbp);
......
...@@ -64,5 +64,8 @@ int xfs_finobt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp, ...@@ -64,5 +64,8 @@ int xfs_finobt_calc_reserves(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_agnumber_t agno, xfs_extlen_t *ask, xfs_extlen_t *used); xfs_agnumber_t agno, xfs_extlen_t *ask, xfs_extlen_t *used);
extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp, extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp,
unsigned long long len); unsigned long long len);
int xfs_inobt_cur(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_agnumber_t agno, xfs_btnum_t btnum,
struct xfs_btree_cur **curpp, struct xfs_buf **agi_bpp);
#endif /* __XFS_IALLOC_BTREE_H__ */ #endif /* __XFS_IALLOC_BTREE_H__ */
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "xfs_error.h" #include "xfs_error.h"
#include "xfs_icache.h" #include "xfs_icache.h"
#include "xfs_health.h" #include "xfs_health.h"
#include "xfs_iwalk.h"
/* /*
* Return stat information for one inode. * Return stat information for one inode.
...@@ -160,7 +161,7 @@ xfs_bulkstat_one( ...@@ -160,7 +161,7 @@ xfs_bulkstat_one(
* Loop over all clusters in a chunk for a given incore inode allocation btree * Loop over all clusters in a chunk for a given incore inode allocation btree
* record. Do a readahead if there are any allocated inodes in that cluster. * record. Do a readahead if there are any allocated inodes in that cluster.
*/ */
STATIC void void
xfs_bulkstat_ichunk_ra( xfs_bulkstat_ichunk_ra(
struct xfs_mount *mp, struct xfs_mount *mp,
xfs_agnumber_t agno, xfs_agnumber_t agno,
...@@ -194,7 +195,7 @@ xfs_bulkstat_ichunk_ra( ...@@ -194,7 +195,7 @@ xfs_bulkstat_ichunk_ra(
* are some left allocated, update the data for the pointed-to record as well as * are some left allocated, update the data for the pointed-to record as well as
* return the count of grabbed inodes. * return the count of grabbed inodes.
*/ */
STATIC int int
xfs_bulkstat_grab_ichunk( xfs_bulkstat_grab_ichunk(
struct xfs_btree_cur *cur, /* btree cursor */ struct xfs_btree_cur *cur, /* btree cursor */
xfs_agino_t agino, /* starting inode of chunk */ xfs_agino_t agino, /* starting inode of chunk */
......
...@@ -84,4 +84,12 @@ xfs_inumbers( ...@@ -84,4 +84,12 @@ xfs_inumbers(
void __user *buffer, /* buffer with inode info */ void __user *buffer, /* buffer with inode info */
inumbers_fmt_pf formatter); inumbers_fmt_pf formatter);
/* Temporarily needed while we refactor functions. */
struct xfs_btree_cur;
struct xfs_inobt_rec_incore;
void xfs_bulkstat_ichunk_ra(struct xfs_mount *mp, xfs_agnumber_t agno,
struct xfs_inobt_rec_incore *irec);
int xfs_bulkstat_grab_ichunk(struct xfs_btree_cur *cur, xfs_agino_t agino,
int *icount, struct xfs_inobt_rec_incore *irec);
#endif /* __XFS_ITABLE_H__ */ #endif /* __XFS_ITABLE_H__ */
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright (C) 2019 Oracle. All Rights Reserved.
* Author: Darrick J. Wong <darrick.wong@oracle.com>
*/
#ifndef __XFS_IWALK_H__
#define __XFS_IWALK_H__
/* Walk all inodes in the filesystem starting from @startino. */
typedef int (*xfs_iwalk_fn)(struct xfs_mount *mp, struct xfs_trans *tp,
xfs_ino_t ino, void *data);
/* Return values for xfs_iwalk_fn. */
#define XFS_IWALK_CONTINUE (XFS_ITER_CONTINUE)
#define XFS_IWALK_ABORT (XFS_ITER_ABORT)
int xfs_iwalk(struct xfs_mount *mp, struct xfs_trans *tp, xfs_ino_t startino,
xfs_iwalk_fn iwalk_fn, unsigned int inode_records, void *data);
#endif /* __XFS_IWALK_H__ */
...@@ -3517,6 +3517,46 @@ DEFINE_EVENT(xfs_inode_corrupt_class, name, \ ...@@ -3517,6 +3517,46 @@ DEFINE_EVENT(xfs_inode_corrupt_class, name, \
DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_sick); DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_sick);
DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_healthy); DEFINE_INODE_CORRUPT_EVENT(xfs_inode_mark_healthy);
TRACE_EVENT(xfs_iwalk_ag,
TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
xfs_agino_t startino),
TP_ARGS(mp, agno, startino),
TP_STRUCT__entry(
__field(dev_t, dev)
__field(xfs_agnumber_t, agno)
__field(xfs_agino_t, startino)
),
TP_fast_assign(
__entry->dev = mp->m_super->s_dev;
__entry->agno = agno;
__entry->startino = startino;
),
TP_printk("dev %d:%d agno %d startino %u",
MAJOR(__entry->dev), MINOR(__entry->dev), __entry->agno,
__entry->startino)
)
TRACE_EVENT(xfs_iwalk_ag_rec,
TP_PROTO(struct xfs_mount *mp, xfs_agnumber_t agno,
struct xfs_inobt_rec_incore *irec),
TP_ARGS(mp, agno, irec),
TP_STRUCT__entry(
__field(dev_t, dev)
__field(xfs_agnumber_t, agno)
__field(xfs_agino_t, startino)
__field(uint64_t, freemask)
),
TP_fast_assign(
__entry->dev = mp->m_super->s_dev;
__entry->agno = agno;
__entry->startino = irec->ir_startino;
__entry->freemask = irec->ir_free;
),
TP_printk("dev %d:%d agno %d startino %u freemask 0x%llx",
MAJOR(__entry->dev), MINOR(__entry->dev), __entry->agno,
__entry->startino, __entry->freemask)
)
#endif /* _TRACE_XFS_H */ #endif /* _TRACE_XFS_H */
#undef TRACE_INCLUDE_PATH #undef TRACE_INCLUDE_PATH
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment