Commit e736428d authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Fix ext3 bogus ENOSPC

With strange workloads which do a lot of quick truncation on small filesystems
it is possible to get into a situation where there are free blocks on the
disk, but they are not allocatable at this time due to their having been freed
up in the current JBD transaction.  Applications get unexpected ENOSPC errors.

We can fix that with this patch, originally by Andreas Dilger which forces a
single commit+retry when an ENOSPC is encountered.
parent 774882ea
...@@ -1081,15 +1081,28 @@ static int ext3_prepare_write(struct file *file, struct page *page, ...@@ -1081,15 +1081,28 @@ static int ext3_prepare_write(struct file *file, struct page *page,
struct inode *inode = page->mapping->host; struct inode *inode = page->mapping->host;
int ret, needed_blocks = ext3_writepage_trans_blocks(inode); int ret, needed_blocks = ext3_writepage_trans_blocks(inode);
handle_t *handle; handle_t *handle;
int tried_commit = 0;
retry:
handle = ext3_journal_start(inode, needed_blocks); handle = ext3_journal_start(inode, needed_blocks);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
goto out; goto out;
} }
ret = block_prepare_write(page, from, to, ext3_get_block); ret = block_prepare_write(page, from, to, ext3_get_block);
if (ret != 0) if (ret) {
goto prepare_write_failed; if (ret != -ENOSPC || tried_commit)
goto prepare_write_failed;
/*
* It could be that there _is_ free space, but it's all tied up
* in uncommitted bitmaps. So force a commit here, which makes
* those blocks allocatable and try again.
*/
tried_commit = 1;
handle->h_sync = 1;
ext3_journal_stop(handle);
goto retry;
}
if (ext3_should_journal_data(inode)) { if (ext3_should_journal_data(inode)) {
ret = walk_page_buffers(handle, page_buffers(page), ret = walk_page_buffers(handle, page_buffers(page),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment