Commit ec8e2f74 authored by Jan Kara's avatar Jan Kara Committed by Linus Torvalds

reiserfs: truncate blocks not used by a write

It can happen that write does not use all the blocks allocated in
write_begin either because of some filesystem error (like ENOSPC) or
because page with data to write has been removed from memory.  We truncate
these blocks so that we don't have dangling blocks beyond i_size.

Cc: Jeff Mahoney <jeffm@suse.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2bf212b9
...@@ -2538,6 +2538,12 @@ static int reiserfs_writepage(struct page *page, struct writeback_control *wbc) ...@@ -2538,6 +2538,12 @@ static int reiserfs_writepage(struct page *page, struct writeback_control *wbc)
return reiserfs_write_full_page(page, wbc); return reiserfs_write_full_page(page, wbc);
} }
static void reiserfs_truncate_failed_write(struct inode *inode)
{
truncate_inode_pages(inode->i_mapping, inode->i_size);
reiserfs_truncate_file(inode, 0);
}
static int reiserfs_write_begin(struct file *file, static int reiserfs_write_begin(struct file *file,
struct address_space *mapping, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags, loff_t pos, unsigned len, unsigned flags,
...@@ -2604,6 +2610,8 @@ static int reiserfs_write_begin(struct file *file, ...@@ -2604,6 +2610,8 @@ static int reiserfs_write_begin(struct file *file,
if (ret) { if (ret) {
unlock_page(page); unlock_page(page);
page_cache_release(page); page_cache_release(page);
/* Truncate allocated blocks */
reiserfs_truncate_failed_write(inode);
} }
return ret; return ret;
} }
...@@ -2701,9 +2709,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, ...@@ -2701,9 +2709,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping,
** transaction tracking stuff when the size changes. So, we have ** transaction tracking stuff when the size changes. So, we have
** to do the i_size updates here. ** to do the i_size updates here.
*/ */
pos += copied; if (pos + copied > inode->i_size) {
if (pos > inode->i_size) {
struct reiserfs_transaction_handle myth; struct reiserfs_transaction_handle myth;
lock_depth = reiserfs_write_lock_once(inode->i_sb); lock_depth = reiserfs_write_lock_once(inode->i_sb);
locked = true; locked = true;
...@@ -2721,7 +2727,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, ...@@ -2721,7 +2727,7 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping,
goto journal_error; goto journal_error;
reiserfs_update_inode_transaction(inode); reiserfs_update_inode_transaction(inode);
inode->i_size = pos; inode->i_size = pos + copied;
/* /*
* this will just nest into our transaction. It's important * this will just nest into our transaction. It's important
* to use mark_inode_dirty so the inode gets pushed around on the * to use mark_inode_dirty so the inode gets pushed around on the
...@@ -2751,6 +2757,10 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping, ...@@ -2751,6 +2757,10 @@ static int reiserfs_write_end(struct file *file, struct address_space *mapping,
reiserfs_write_unlock_once(inode->i_sb, lock_depth); reiserfs_write_unlock_once(inode->i_sb, lock_depth);
unlock_page(page); unlock_page(page);
page_cache_release(page); page_cache_release(page);
if (pos + len > inode->i_size)
reiserfs_truncate_failed_write(inode);
return ret == 0 ? copied : ret; return ret == 0 ? copied : ret;
journal_error: journal_error:
......
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