diff options
author | Theodore Ts'o <tytso@mit.edu> | 2016-03-30 22:36:24 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2016-03-30 22:36:24 -0400 |
commit | 1028b55bafb7611dda1d8fed2aeca16a436b7dff (patch) | |
tree | c6881992855b87775897afe3712e6c72811856a0 | |
parent | de17e793b104d690e1d007dfc5cb6b4f649598ca (diff) |
ext4: allow readdir()'s of large empty directories to be interrupted
If a directory has a large number of empty blocks, iterating over all
of them can take a long time, leading to scheduler warnings and users
getting irritated when they can't kill a process in the middle of one
of these long-running readdir operations. Fix this by adding checks to
ext4_readdir() and ext4_htree_fill_tree().
Reported-by: Benjamin LaHaise <bcrl@kvack.org>
Google-Bug-Id: 27880676
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r-- | fs/ext4/dir.c | 5 | ||||
-rw-r--r-- | fs/ext4/namei.c | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 33f5e2a50cf8..ebfcb8999db2 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c | |||
@@ -150,6 +150,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx) | |||
150 | while (ctx->pos < inode->i_size) { | 150 | while (ctx->pos < inode->i_size) { |
151 | struct ext4_map_blocks map; | 151 | struct ext4_map_blocks map; |
152 | 152 | ||
153 | if (fatal_signal_pending(current)) { | ||
154 | err = -ERESTARTSYS; | ||
155 | goto errout; | ||
156 | } | ||
157 | cond_resched(); | ||
153 | map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb); | 158 | map.m_lblk = ctx->pos >> EXT4_BLOCK_SIZE_BITS(sb); |
154 | map.m_len = 1; | 159 | map.m_len = 1; |
155 | err = ext4_map_blocks(NULL, inode, &map, 0); | 160 | err = ext4_map_blocks(NULL, inode, &map, 0); |
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 48e4b8907826..db98f89f737f 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c | |||
@@ -1107,6 +1107,11 @@ int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, | |||
1107 | } | 1107 | } |
1108 | 1108 | ||
1109 | while (1) { | 1109 | while (1) { |
1110 | if (signal_pending(current)) { | ||
1111 | err = -ERESTARTSYS; | ||
1112 | goto errout; | ||
1113 | } | ||
1114 | cond_resched(); | ||
1110 | block = dx_get_block(frame->at); | 1115 | block = dx_get_block(frame->at); |
1111 | ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo, | 1116 | ret = htree_dirblock_to_tree(dir_file, dir, block, &hinfo, |
1112 | start_hash, start_minor_hash); | 1117 | start_hash, start_minor_hash); |