Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 174397
b: refs/heads/master
c: b9a4207
h: refs/heads/master
i:
  174395: 9ee9694
v: v3
  • Loading branch information
Jan Kara authored and Theodore Ts'o committed Dec 9, 2009
1 parent 7949e6a commit b85ce38
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 24b584240a0006ea7436cd35f5e8983eb76f1e6f
refs/heads/master: b9a4207d5e911b938f73079a83cc2ae10524ec7f
20 changes: 15 additions & 5 deletions trunk/fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1492,6 +1492,16 @@ static int do_journal_get_write_access(handle_t *handle,
return ext4_journal_get_write_access(handle, bh);
}

/*
* Truncate blocks that were not used by write. We have to truncate the
* pagecache as well so that corresponding buffers get properly unmapped.
*/
static void ext4_truncate_failed_write(struct inode *inode)
{
truncate_inode_pages(inode->i_mapping, inode->i_size);
ext4_truncate(inode);
}

static int ext4_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
Expand Down Expand Up @@ -1557,7 +1567,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,

ext4_journal_stop(handle);
if (pos + len > inode->i_size) {
ext4_truncate(inode);
ext4_truncate_failed_write(inode);
/*
* If truncate failed early the inode might
* still be on the orphan list; we need to
Expand Down Expand Up @@ -1667,7 +1677,7 @@ static int ext4_ordered_write_end(struct file *file,
ret = ret2;

if (pos + len > inode->i_size) {
ext4_truncate(inode);
ext4_truncate_failed_write(inode);
/*
* If truncate failed early the inode might still be
* on the orphan list; we need to make sure the inode
Expand Down Expand Up @@ -1709,7 +1719,7 @@ static int ext4_writeback_write_end(struct file *file,
ret = ret2;

if (pos + len > inode->i_size) {
ext4_truncate(inode);
ext4_truncate_failed_write(inode);
/*
* If truncate failed early the inode might still be
* on the orphan list; we need to make sure the inode
Expand Down Expand Up @@ -1772,7 +1782,7 @@ static int ext4_journalled_write_end(struct file *file,
if (!ret)
ret = ret2;
if (pos + len > inode->i_size) {
ext4_truncate(inode);
ext4_truncate_failed_write(inode);
/*
* If truncate failed early the inode might still be
* on the orphan list; we need to make sure the inode
Expand Down Expand Up @@ -3048,7 +3058,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
* i_size_read because we hold i_mutex.
*/
if (pos + len > inode->i_size)
ext4_truncate(inode);
ext4_truncate_failed_write(inode);
}

if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
Expand Down

0 comments on commit b85ce38

Please sign in to comment.