Skip to content

Commit c5e298a

Browse files
committed
ext4: prevent ext4_quota_write() from failing due to ENOSPC
In order to prevent quota block tracking to be inaccurate when ext4_quota_write() fails with ENOSPC, we make two changes. The quota file can now use the reserved block (since the quota file is arguably file system metadata), and ext4_quota_write() now uses ext4_should_retry_alloc() to retry the block allocation after a commit has completed and released some blocks for allocation. This fixes failures of xfstests generic/270: Quota error (device vdc): write_blk: dquota write failed Quota error (device vdc): qtree_write_dquot: Error -28 occurred while creating quota Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 89d96a6 commit c5e298a

5 files changed

Lines changed: 17 additions & 7 deletions

File tree

‎fs/ext4/extents.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,6 +4456,8 @@ int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
44564456
ar.flags |= EXT4_MB_HINT_NOPREALLOC;
44574457
if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
44584458
ar.flags |= EXT4_MB_DELALLOC_RESERVED;
4459+
if (flags & EXT4_GET_BLOCKS_METADATA_NOFAIL)
4460+
ar.flags |= EXT4_MB_USE_RESERVED;
44594461
newblock = ext4_mb_new_blocks(handle, &ar, &err);
44604462
if (!newblock)
44614463
goto out2;

‎fs/ext4/indirect.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,8 @@ int ext4_ind_map_blocks(handle_t *handle, struct inode *inode,
576576
ar.flags = EXT4_MB_HINT_DATA;
577577
if (flags & EXT4_GET_BLOCKS_DELALLOC_RESERVE)
578578
ar.flags |= EXT4_MB_DELALLOC_RESERVED;
579+
if (flags & EXT4_GET_BLOCKS_METADATA_NOFAIL)
580+
ar.flags |= EXT4_MB_USE_RESERVED;
579581

580582
ar.goal = ext4_find_goal(inode, map->m_lblk, partial);
581583

‎fs/ext4/inode.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -731,18 +731,18 @@ int ext4_get_block(struct inode *inode, sector_t iblock,
731731
* `handle' can be NULL if create is zero
732732
*/
733733
struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
734-
ext4_lblk_t block, int create)
734+
ext4_lblk_t block, int map_flags)
735735
{
736736
struct ext4_map_blocks map;
737737
struct buffer_head *bh;
738+
int create = map_flags & EXT4_GET_BLOCKS_CREATE;
738739
int err;
739740

740741
J_ASSERT(handle != NULL || create == 0);
741742

742743
map.m_lblk = block;
743744
map.m_len = 1;
744-
err = ext4_map_blocks(handle, inode, &map,
745-
create ? EXT4_GET_BLOCKS_CREATE : 0);
745+
err = ext4_map_blocks(handle, inode, &map, map_flags);
746746

747747
if (err == 0)
748748
return create ? ERR_PTR(-ENOSPC) : NULL;
@@ -788,11 +788,11 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode,
788788
}
789789

790790
struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
791-
ext4_lblk_t block, int create)
791+
ext4_lblk_t block, int map_flags)
792792
{
793793
struct buffer_head *bh;
794794

795-
bh = ext4_getblk(handle, inode, block, create);
795+
bh = ext4_getblk(handle, inode, block, map_flags);
796796
if (IS_ERR(bh))
797797
return bh;
798798
if (!bh || buffer_uptodate(bh))

‎fs/ext4/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ static struct buffer_head *ext4_append(handle_t *handle,
6161

6262
*block = inode->i_size >> inode->i_sb->s_blocksize_bits;
6363

64-
bh = ext4_bread(handle, inode, *block, 1);
64+
bh = ext4_bread(handle, inode, *block, EXT4_GET_BLOCKS_CREATE);
6565
if (IS_ERR(bh))
6666
return bh;
6767
inode->i_size += inode->i_sb->s_blocksize;

‎fs/ext4/super.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5438,6 +5438,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
54385438
struct inode *inode = sb_dqopt(sb)->files[type];
54395439
ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
54405440
int err, offset = off & (sb->s_blocksize - 1);
5441+
int retries = 0;
54415442
struct buffer_head *bh;
54425443
handle_t *handle = journal_current_handle();
54435444

@@ -5458,7 +5459,12 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
54585459
return -EIO;
54595460
}
54605461

5461-
bh = ext4_bread(handle, inode, blk, 1);
5462+
do {
5463+
bh = ext4_bread(handle, inode, blk,
5464+
EXT4_GET_BLOCKS_CREATE |
5465+
EXT4_GET_BLOCKS_METADATA_NOFAIL);
5466+
} while (IS_ERR(bh) && (PTR_ERR(bh) == -ENOSPC) &&
5467+
ext4_should_retry_alloc(inode->i_sb, &retries));
54625468
if (IS_ERR(bh))
54635469
return PTR_ERR(bh);
54645470
if (!bh)

0 commit comments

Comments
 (0)