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]>
---
 fs/erofs/dir.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/erofs/dir.c b/fs/erofs/dir.c
index 2fae209d0274..cff61c5a172b 100644
--- a/fs/erofs/dir.c
+++ b/fs/erofs/dir.c
@@ -58,6 +58,13 @@ static int erofs_readdir(struct file *f, struct dir_context 
*ctx)
                struct erofs_dirent *de;
                unsigned int nameoff, maxsize;
 
+               /* allow readdir() to be interrupted */
+               if (fatal_signal_pending(current)) {
+                       err = -ERESTARTSYS;
+                       break;
+               }
+               cond_resched();
+
                de = erofs_bread(&buf, dbstart, true);
                if (IS_ERR(de)) {
                        erofs_err(sb, "failed to readdir of logical block %llu 
of nid %llu",
-- 
2.49.0


Reply via email to