Skip to content

Commit

Permalink
xfs: create simplified inode walk function
Browse files Browse the repository at this point in the history
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: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
  • Loading branch information
Darrick J. Wong committed Jul 2, 2019
1 parent 5bb46e3 commit a211432
Show file tree
Hide file tree
Showing 8 changed files with 496 additions and 6 deletions.
1 change: 1 addition & 0 deletions fs/xfs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ xfs-y += xfs_aops.o \
xfs_iops.o \
xfs_inode.o \
xfs_itable.o \
xfs_iwalk.o \
xfs_message.o \
xfs_mount.o \
xfs_mru_cache.o \
Expand Down
37 changes: 33 additions & 4 deletions fs/xfs/libxfs/xfs_ialloc_btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,36 @@ xfs_inobt_max_size(
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
xfs_inobt_count_blocks(
struct xfs_mount *mp,
Expand All @@ -570,15 +600,14 @@ xfs_inobt_count_blocks(
xfs_btnum_t btnum,
xfs_extlen_t *tree_blocks)
{
struct xfs_buf *agbp;
struct xfs_btree_cur *cur;
struct xfs_buf *agbp = NULL;
struct xfs_btree_cur *cur = NULL;
int error;

error = xfs_ialloc_read_agi(mp, tp, agno, &agbp);
error = xfs_inobt_cur(mp, tp, agno, btnum, &cur, &agbp);
if (error)
return error;

cur = xfs_inobt_init_cursor(mp, tp, agbp, agno, btnum);
error = xfs_btree_count_blocks(cur, tree_blocks);
xfs_btree_del_cursor(cur, error);
xfs_trans_brelse(tp, agbp);
Expand Down
3 changes: 3 additions & 0 deletions fs/xfs/libxfs/xfs_ialloc_btree.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
extern xfs_extlen_t xfs_iallocbt_calc_size(struct xfs_mount *mp,
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__ */
5 changes: 3 additions & 2 deletions fs/xfs/xfs_itable.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "xfs_error.h"
#include "xfs_icache.h"
#include "xfs_health.h"
#include "xfs_iwalk.h"

/*
* Return stat information for one inode.
Expand Down Expand Up @@ -160,7 +161,7 @@ xfs_bulkstat_one(
* 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.
*/
STATIC void
void
xfs_bulkstat_ichunk_ra(
struct xfs_mount *mp,
xfs_agnumber_t agno,
Expand Down Expand Up @@ -194,7 +195,7 @@ xfs_bulkstat_ichunk_ra(
* are some left allocated, update the data for the pointed-to record as well as
* return the count of grabbed inodes.
*/
STATIC int
int
xfs_bulkstat_grab_ichunk(
struct xfs_btree_cur *cur, /* btree cursor */
xfs_agino_t agino, /* starting inode of chunk */
Expand Down
8 changes: 8 additions & 0 deletions fs/xfs/xfs_itable.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,12 @@ xfs_inumbers(
void __user *buffer, /* buffer with inode info */
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__ */
Loading

0 comments on commit a211432

Please sign in to comment.