Skip to content

Commit

Permalink
ext4: Handle -EDQUOT error on write
Browse files Browse the repository at this point in the history
We need to release the journal before we do a write_inode.  Otherwise
we could deadlock.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
  • Loading branch information
Aneesh Kumar K.V authored and Theodore Ts'o committed Jan 22, 2010
1 parent 74d2e4f commit 1db9138
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions fs/ext4/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1835,24 +1835,12 @@ static int ext4_da_reserve_space(struct inode *inode, sector_t lblock)
* later. Real quota accounting is done at pages writeout
* time.
*/
if (vfs_dq_reserve_block(inode, md_needed + 1)) {
/*
* We tend to badly over-estimate the amount of
* metadata blocks which are needed, so if we have
* reserved any metadata blocks, try to force out the
* inode and see if we have any better luck.
*/
if (md_reserved && retries++ <= 3)
goto retry;
if (vfs_dq_reserve_block(inode, md_needed + 1))
return -EDQUOT;
}

if (ext4_claim_free_blocks(sbi, md_needed + 1)) {
vfs_dq_release_reservation_block(inode, md_needed + 1);
if (ext4_should_retry_alloc(inode->i_sb, &retries)) {
retry:
if (md_reserved)
write_inode_now(inode, (retries == 3));
yield();
goto repeat;
}
Expand Down Expand Up @@ -3032,7 +3020,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{
int ret, retries = 0;
int ret, retries = 0, quota_retries = 0;
struct page *page;
pgoff_t index;
unsigned from, to;
Expand Down Expand Up @@ -3091,6 +3079,22 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,

if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
goto retry;

if ((ret == -EDQUOT) &&
EXT4_I(inode)->i_reserved_meta_blocks &&
(quota_retries++ < 3)) {
/*
* Since we often over-estimate the number of meta
* data blocks required, we may sometimes get a
* spurios out of quota error even though there would
* be enough space once we write the data blocks and
* find out how many meta data blocks were _really_
* required. So try forcing the inode write to see if
* that helps.
*/
write_inode_now(inode, (quota_retries == 3));
goto retry;
}
out:
return ret;
}
Expand Down

0 comments on commit 1db9138

Please sign in to comment.