Skip to content

Commit 1730853

Browse files
author
Darrick J. Wong
committed
xfs: get our own reference to inodes that we want to scrub
When we want to scrub a file, get our own reference to the inode unconditionally. This will make disposal rules simpler in the long run. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Dave Chinner <[email protected]>
1 parent d7a74ca commit 1730853

File tree

6 files changed

+36
-13
lines changed

6 files changed

+36
-13
lines changed

fs/xfs/scrub/common.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,25 @@ xchk_install_handle_inode(
831831
return 0;
832832
}
833833

834+
/*
835+
* Install an already-referenced inode for scrubbing. Get our own reference to
836+
* the inode to make disposal simpler. The inode must not be in I_FREEING or
837+
* I_WILL_FREE state!
838+
*/
839+
int
840+
xchk_install_live_inode(
841+
struct xfs_scrub *sc,
842+
struct xfs_inode *ip)
843+
{
844+
if (!igrab(VFS_I(ip))) {
845+
xchk_ino_set_corrupt(sc, ip->i_ino);
846+
return -EFSCORRUPTED;
847+
}
848+
849+
sc->ip = ip;
850+
return 0;
851+
}
852+
834853
/*
835854
* In preparation to scrub metadata structures that hang off of an inode,
836855
* grab either the inode referenced in the scrub control structure or the
@@ -854,10 +873,8 @@ xchk_iget_for_scrubbing(
854873
ASSERT(sc->tp == NULL);
855874

856875
/* We want to scan the inode we already had opened. */
857-
if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) {
858-
sc->ip = ip_in;
859-
return 0;
860-
}
876+
if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino)
877+
return xchk_install_live_inode(sc, ip_in);
861878

862879
/* Reject internal metadata files and obviously bad inode numbers. */
863880
if (xfs_internal_inum(mp, sc->sm->sm_ino))

fs/xfs/scrub/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ int xchk_count_rmap_ownedby_ag(struct xfs_scrub *sc, struct xfs_btree_cur *cur,
137137
int xchk_setup_ag_btree(struct xfs_scrub *sc, bool force_log);
138138
int xchk_iget_for_scrubbing(struct xfs_scrub *sc);
139139
int xchk_setup_inode_contents(struct xfs_scrub *sc, unsigned int resblks);
140+
int xchk_install_live_inode(struct xfs_scrub *sc, struct xfs_inode *ip);
140141
void xchk_buffer_recheck(struct xfs_scrub *sc, struct xfs_buf *bp);
141142

142143
int xchk_iget(struct xfs_scrub *sc, xfs_ino_t inum, struct xfs_inode **ipp);

fs/xfs/scrub/inode.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ xchk_setup_inode(
8383

8484
/* We want to scan the opened inode, so lock it and exit. */
8585
if (sc->sm->sm_ino == 0 || sc->sm->sm_ino == ip_in->i_ino) {
86-
sc->ip = ip_in;
86+
error = xchk_install_live_inode(sc, ip_in);
87+
if (error)
88+
return error;
89+
8790
return xchk_prepare_iscrub(sc);
8891
}
8992

fs/xfs/scrub/quota.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ xchk_setup_quota(
5959
error = xchk_setup_fs(sc);
6060
if (error)
6161
return error;
62-
sc->ip = xfs_quota_inode(sc->mp, dqtype);
62+
63+
error = xchk_install_live_inode(sc, xfs_quota_inode(sc->mp, dqtype));
64+
if (error)
65+
return error;
66+
6367
xfs_ilock(sc->ip, XFS_ILOCK_EXCL);
6468
sc->ilock_flags = XFS_ILOCK_EXCL;
6569
return 0;

fs/xfs/scrub/rtbitmap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ xchk_setup_rt(
2828
if (error)
2929
return error;
3030

31+
error = xchk_install_live_inode(sc, sc->mp->m_rbmip);
32+
if (error)
33+
return error;
34+
3135
sc->ilock_flags = XFS_ILOCK_EXCL | XFS_ILOCK_RTBITMAP;
32-
sc->ip = sc->mp->m_rbmip;
3336
xfs_ilock(sc->ip, sc->ilock_flags);
34-
3537
return 0;
3638
}
3739

fs/xfs/scrub/scrub.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,6 @@ xchk_teardown(
167167
struct xfs_scrub *sc,
168168
int error)
169169
{
170-
struct xfs_inode *ip_in = XFS_I(file_inode(sc->file));
171-
172170
xchk_ag_free(sc, &sc->sa);
173171
if (sc->tp) {
174172
if (error == 0 && (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR))
@@ -180,9 +178,7 @@ xchk_teardown(
180178
if (sc->ip) {
181179
if (sc->ilock_flags)
182180
xfs_iunlock(sc->ip, sc->ilock_flags);
183-
if (sc->ip != ip_in &&
184-
!xfs_internal_inum(sc->mp, sc->ip->i_ino))
185-
xchk_irele(sc, sc->ip);
181+
xchk_irele(sc, sc->ip);
186182
sc->ip = NULL;
187183
}
188184
if (sc->sm->sm_flags & XFS_SCRUB_IFLAG_REPAIR)

0 commit comments

Comments
 (0)