Skip to content

Commit d31fbdc

Browse files
chaseyuhsiangkao
authored andcommitted
erofs: allow readdir() to be interrupted
In a quick slow device, readdir() may loop for long time in large directory, let's give a chance to allow it to be interrupted by userspace. Signed-off-by: Chao Yu <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Link: https://lore.kernel.org/r/[email protected] [ Gao Xiang: move cond_resched() to the end of the while loop. ] Signed-off-by: Gao Xiang <[email protected]>
1 parent 27917e8 commit d31fbdc

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/erofs/dir.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
5858
struct erofs_dirent *de;
5959
unsigned int nameoff, maxsize;
6060

61+
if (fatal_signal_pending(current)) {
62+
err = -ERESTARTSYS;
63+
break;
64+
}
65+
6166
de = erofs_bread(&buf, dbstart, true);
6267
if (IS_ERR(de)) {
6368
erofs_err(sb, "failed to readdir of logical block %llu of nid %llu",
@@ -88,6 +93,7 @@ static int erofs_readdir(struct file *f, struct dir_context *ctx)
8893
break;
8994
ctx->pos = dbstart + maxsize;
9095
ofs = 0;
96+
cond_resched();
9197
}
9298
erofs_put_metabuf(&buf);
9399
if (EROFS_I(dir)->dot_omitted && ctx->pos == dir->i_size) {

0 commit comments

Comments
 (0)