checkpoint ext4 patches
[ext4-patch-queue.git] / allow-resched-and-interruption-of-large-empty-directories
blob2565916b4abc5946a310b9d42b984ac6d83bf30a
1 ext4: allow readdir()'s of large empty directories to be interrupted
3 If a directory has a large number of empty blocks, iterating over all
4 of them can take a long time, leading to scheduler warnings and users
5 getting irritated when they can't kill a process in the middle of one
6 of these long-running readdir operations.  Fix this by adding checks to
7 ext4_readdir() and ext4_htree_fill_tree().
9 Reported-by: Benjamin LaHaise <bcrl@kvack.org>
10 Google-Bug-Id: 27880676
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 ---
13  fs/ext4/dir.c   | 5 +++++
14  fs/ext4/namei.c | 5 +++++
15  2 files changed, 10 insertions(+)
17 diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
18 index 33f5e2a..ebfcb89 100644
19 --- a/fs/ext4/dir.c
20 +++ b/fs/ext4/dir.c
21 @@ -150,6 +150,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
22         while (ctx->pos < inode->i_size) {
23                 struct ext4_map_blocks map;
25 +               if (fatal_signal_pending(current)) {
26 +                       err = -ERESTARTSYS;
27 +                       goto errout;
28 +               }
29 +               cond_resched();
30                 map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb);
31                 map.m_len = 1;
32                 err = ext4_map_blocks(NULL, inode, &map, 0);
33 diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
34 index 48e4b89..db98f89f 100644
35 --- a/fs/ext4/namei.c
36 +++ b/fs/ext4/namei.c
37 @@ -1107,6 +1107,11 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
38         }
40         while (1) {
41 +               if (signal_pending(current)) {
42 +                       err = -ERESTARTSYS;
43 +                       goto errout;
44 +               }
45 +               cond_resched();
46                 block = dx_get_block(frame->at);
47                 ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo,
48                                              start_hash, start_minor_hash);