Skip to content

Commit 0d29663

Browse files
author
Darrick J. Wong
committed
xfs: hide xfs_inode_is_allocated in scrub common code
This function is only used by online fsck, so let's move it there. In the next patch, we'll fix it to work properly and to require that the caller hold the AGI buffer locked. No major changes aside from adjusting the signature a bit. Signed-off-by: Darrick J. Wong <djwong@kernel.org> Reviewed-by: Dave Chinner <dchinner@redhat.com>
1 parent a634c0a commit 0d29663

File tree

5 files changed

+40
-44
lines changed

5 files changed

+40
-44
lines changed

fs/xfs/scrub/common.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,3 +1230,40 @@ xchk_fsgates_enable(
12301230

12311231
sc->flags |= scrub_fsgates;
12321232
}
1233+
1234+
/*
1235+
* Decide if this is this a cached inode that's also allocated.
1236+
*
1237+
* Look up an inode by number in the given file system. If the inode is
1238+
* in cache and isn't in purgatory, return 1 if the inode is allocated
1239+
* and 0 if it is not. For all other cases (not in cache, being torn
1240+
* down, etc.), return a negative error code.
1241+
*
1242+
* The caller has to prevent inode allocation and freeing activity,
1243+
* presumably by locking the AGI buffer. This is to ensure that an
1244+
* inode cannot transition from allocated to freed until the caller is
1245+
* ready to allow that. If the inode is in an intermediate state (new,
1246+
* reclaimable, or being reclaimed), -EAGAIN will be returned; if the
1247+
* inode is not in the cache, -ENOENT will be returned. The caller must
1248+
* deal with these scenarios appropriately.
1249+
*
1250+
* This is a specialized use case for the online scrubber; if you're
1251+
* reading this, you probably want xfs_iget.
1252+
*/
1253+
int
1254+
xchk_inode_is_allocated(
1255+
struct xfs_scrub *sc,
1256+
xfs_ino_t ino,
1257+
bool *inuse)
1258+
{
1259+
struct xfs_inode *ip;
1260+
int error;
1261+
1262+
error = xfs_iget(sc->mp, sc->tp, ino, XFS_IGET_INCORE, 0, &ip);
1263+
if (error)
1264+
return error;
1265+
1266+
*inuse = !!(VFS_I(ip)->i_mode);
1267+
xfs_irele(ip);
1268+
return 0;
1269+
}

fs/xfs/scrub/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,6 @@ static inline bool xchk_need_intent_drain(struct xfs_scrub *sc)
203203

204204
void xchk_fsgates_enable(struct xfs_scrub *sc, unsigned int scrub_fshooks);
205205

206+
int xchk_inode_is_allocated(struct xfs_scrub *sc, xfs_ino_t ino, bool *inuse);
207+
206208
#endif /* __XFS_SCRUB_COMMON_H__ */

fs/xfs/scrub/ialloc.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ xchk_iallocbt_check_cluster_ifree(
328328
goto out;
329329
}
330330

331-
error = xfs_icache_inode_is_allocated(mp, bs->cur->bc_tp, fsino,
332-
&ino_inuse);
331+
error = xchk_inode_is_allocated(bs->sc, fsino, &ino_inuse);
333332
if (error == -ENODATA) {
334333
/* Not cached, just read the disk buffer */
335334
freemask_ok = irec_free ^ !!(dip->di_mode);

fs/xfs/xfs_icache.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -802,44 +802,6 @@ xfs_iget(
802802
return error;
803803
}
804804

805-
/*
806-
* "Is this a cached inode that's also allocated?"
807-
*
808-
* Look up an inode by number in the given file system. If the inode is
809-
* in cache and isn't in purgatory, return 1 if the inode is allocated
810-
* and 0 if it is not. For all other cases (not in cache, being torn
811-
* down, etc.), return a negative error code.
812-
*
813-
* The caller has to prevent inode allocation and freeing activity,
814-
* presumably by locking the AGI buffer. This is to ensure that an
815-
* inode cannot transition from allocated to freed until the caller is
816-
* ready to allow that. If the inode is in an intermediate state (new,
817-
* reclaimable, or being reclaimed), -EAGAIN will be returned; if the
818-
* inode is not in the cache, -ENOENT will be returned. The caller must
819-
* deal with these scenarios appropriately.
820-
*
821-
* This is a specialized use case for the online scrubber; if you're
822-
* reading this, you probably want xfs_iget.
823-
*/
824-
int
825-
xfs_icache_inode_is_allocated(
826-
struct xfs_mount *mp,
827-
struct xfs_trans *tp,
828-
xfs_ino_t ino,
829-
bool *inuse)
830-
{
831-
struct xfs_inode *ip;
832-
int error;
833-
834-
error = xfs_iget(mp, tp, ino, XFS_IGET_INCORE, 0, &ip);
835-
if (error)
836-
return error;
837-
838-
*inuse = !!(VFS_I(ip)->i_mode);
839-
xfs_irele(ip);
840-
return 0;
841-
}
842-
843805
/*
844806
* Grab the inode for reclaim exclusively.
845807
*

fs/xfs/xfs_icache.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,6 @@ void xfs_inode_set_cowblocks_tag(struct xfs_inode *ip);
7171
void xfs_inode_clear_cowblocks_tag(struct xfs_inode *ip);
7272

7373
void xfs_blockgc_worker(struct work_struct *work);
74-
75-
int xfs_icache_inode_is_allocated(struct xfs_mount *mp, struct xfs_trans *tp,
76-
xfs_ino_t ino, bool *inuse);
77-
7874
void xfs_blockgc_stop(struct xfs_mount *mp);
7975
void xfs_blockgc_start(struct xfs_mount *mp);
8076

0 commit comments

Comments
 (0)