aboutsummaryrefslogtreecommitdiffstats
path: root/mm/filemap.c
diff options
context:
space:
mode:
authorDmitry Monakhov <dmonakhov@openvz.org>2013-04-29 18:08:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 18:54:38 -0400
commit865ffef3797da2cac85b3354b5b6050dc9660978 (patch)
tree831324f5fe5b1f0ed91318f5de7669045f4f941e /mm/filemap.c
parent209ff86d61d6b50979cffb47878fc77ca2f6c8a2 (diff)
fs: fix fsync() error reporting
There are two convenient ways to report errors to userspace 1) retun error to original syscall for example write(2) 2) mark mapping with error flag and return it on later fsync(2) Second one is broken if (mapping->nrpages == 0) This is real-life situation because after error pages are likey to be truncated or invalidated. We have to return an error regardless to number of pages in the mapping. #Original testcase: git@github.com:dmonakhov/xfstests.git MOUNT_OPTIONS="-b1024" ./check shared/305 Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org> Reviewed-by: Jan Kara <jack@suse.cz> Cc: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'mm/filemap.c')
-rw-r--r--mm/filemap.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/mm/filemap.c b/mm/filemap.c
index 2581826409f2..e989fb1eaa72 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -188,6 +188,17 @@ static int sleep_on_page_killable(void *word)
188 return fatal_signal_pending(current) ? -EINTR : 0; 188 return fatal_signal_pending(current) ? -EINTR : 0;
189} 189}
190 190
191static int filemap_check_errors(struct address_space *mapping)
192{
193 int ret = 0;
194 /* Check for outstanding write errors */
195 if (test_and_clear_bit(AS_ENOSPC, &mapping->flags))
196 ret = -ENOSPC;
197 if (test_and_clear_bit(AS_EIO, &mapping->flags))
198 ret = -EIO;
199 return ret;
200}
201
191/** 202/**
192 * __filemap_fdatawrite_range - start writeback on mapping dirty pages in range 203 * __filemap_fdatawrite_range - start writeback on mapping dirty pages in range
193 * @mapping: address space structure to write 204 * @mapping: address space structure to write
@@ -269,10 +280,10 @@ int filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte,
269 pgoff_t end = end_byte >> PAGE_CACHE_SHIFT; 280 pgoff_t end = end_byte >> PAGE_CACHE_SHIFT;
270 struct pagevec pvec; 281 struct pagevec pvec;
271 int nr_pages; 282 int nr_pages;
272 int ret = 0; 283 int ret2, ret = 0;
273 284
274 if (end_byte < start_byte) 285 if (end_byte < start_byte)
275 return 0; 286 goto out;
276 287
277 pagevec_init(&pvec, 0); 288 pagevec_init(&pvec, 0);
278 while ((index <= end) && 289 while ((index <= end) &&
@@ -295,12 +306,10 @@ int filemap_fdatawait_range(struct address_space *mapping, loff_t start_byte,
295 pagevec_release(&pvec); 306 pagevec_release(&pvec);
296 cond_resched(); 307 cond_resched();
297 } 308 }
298 309out:
299 /* Check for outstanding write errors */ 310 ret2 = filemap_check_errors(mapping);
300 if (test_and_clear_bit(AS_ENOSPC, &mapping->flags)) 311 if (!ret)
301 ret = -ENOSPC; 312 ret = ret2;
302 if (test_and_clear_bit(AS_EIO, &mapping->flags))
303 ret = -EIO;
304 313
305 return ret; 314 return ret;
306} 315}
@@ -341,6 +350,8 @@ int filemap_write_and_wait(struct address_space *mapping)
341 if (!err) 350 if (!err)
342 err = err2; 351 err = err2;
343 } 352 }
353 } else {
354 err = filemap_check_errors(mapping);
344 } 355 }
345 return err; 356 return err;
346} 357}
@@ -372,6 +383,8 @@ int filemap_write_and_wait_range(struct address_space *mapping,
372 if (!err) 383 if (!err)
373 err = err2; 384 err = err2;
374 } 385 }
386 } else {
387 err = filemap_check_errors(mapping);
375 } 388 }
376 return err; 389 return err;
377} 390}