Skip to content

Commit 8feb473

Browse files
committed
xfs: allow parent directory scans to be interrupted with fatal signals
Allow a fatal signal to interrupt us when we're scanning a directory to verify a parent pointer. Signed-off-by: Darrick J. Wong <[email protected]> Reviewed-by: Brian Foster <[email protected]>
1 parent 2911edb commit 8feb473

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

fs/xfs/scrub/parent.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ xchk_setup_parent(
3232

3333
struct xchk_parent_ctx {
3434
struct dir_context dc;
35+
struct xfs_scrub *sc;
3536
xfs_ino_t ino;
3637
xfs_nlink_t nlink;
38+
bool cancelled;
3739
};
3840

3941
/* Look for a single entry in a directory pointing to an inode. */
@@ -47,11 +49,21 @@ xchk_parent_actor(
4749
unsigned type)
4850
{
4951
struct xchk_parent_ctx *spc;
52+
int error = 0;
5053

5154
spc = container_of(dc, struct xchk_parent_ctx, dc);
5255
if (spc->ino == ino)
5356
spc->nlink++;
54-
return 0;
57+
58+
/*
59+
* If we're facing a fatal signal, bail out. Store the cancellation
60+
* status separately because the VFS readdir code squashes error codes
61+
* into short directory reads.
62+
*/
63+
if (xchk_should_terminate(spc->sc, &error))
64+
spc->cancelled = true;
65+
66+
return error;
5567
}
5668

5769
/* Count the number of dentries in the parent dir that point to this inode. */
@@ -62,10 +74,9 @@ xchk_parent_count_parent_dentries(
6274
xfs_nlink_t *nlink)
6375
{
6476
struct xchk_parent_ctx spc = {
65-
.dc.actor = xchk_parent_actor,
66-
.dc.pos = 0,
67-
.ino = sc->ip->i_ino,
68-
.nlink = 0,
77+
.dc.actor = xchk_parent_actor,
78+
.ino = sc->ip->i_ino,
79+
.sc = sc,
6980
};
7081
size_t bufsize;
7182
loff_t oldpos;
@@ -97,6 +108,10 @@ xchk_parent_count_parent_dentries(
97108
error = xfs_readdir(sc->tp, parent, &spc.dc, bufsize);
98109
if (error)
99110
goto out;
111+
if (spc.cancelled) {
112+
error = -EAGAIN;
113+
goto out;
114+
}
100115
if (oldpos == spc.dc.pos)
101116
break;
102117
oldpos = spc.dc.pos;

0 commit comments

Comments
 (0)