Skip to content

Commit

Permalink
ext4: fix xattr block allocation/release with bigalloc
Browse files Browse the repository at this point in the history
Currently when new xattr block is created or released we we would call
dquot_free_block() or dquot_alloc_block() respectively, among the else
decrementing or incrementing the number of blocks assigned to the
inode by one block.

This however does not work for bigalloc file system because we always
allocate/free the whole cluster so we have to count with that in
dquot_free_block() and dquot_alloc_block() as well.

Use the clusters-to-blocks conversion EXT4_C2B() when passing number of
blocks to the dquot_alloc/free functions to fix the problem.

The problem has been revealed by xfstests zen-kernel#117 (and possibly others).

Signed-off-by: Lukas Czerner <[email protected]>
Signed-off-by: "Theodore Ts'o" <[email protected]>
Reviewed-by: Eric Sandeen <[email protected]>
Cc: [email protected]
  • Loading branch information
Lukas Czerner authored and tytso committed Feb 18, 2013
1 parent 74cd15c commit 1231b3a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fs/ext4/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ ext4_xattr_release_block(handle_t *handle, struct inode *inode,
error = ext4_handle_dirty_xattr_block(handle, inode, bh);
if (IS_SYNC(inode))
ext4_handle_sync(handle);
dquot_free_block(inode, 1);
dquot_free_block(inode, EXT4_C2B(EXT4_SB(inode->i_sb), 1));
ea_bdebug(bh, "refcount now=%d; releasing",
le32_to_cpu(BHDR(bh)->h_refcount));
}
Expand Down Expand Up @@ -832,7 +832,8 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
else {
/* The old block is released after updating
the inode. */
error = dquot_alloc_block(inode, 1);
error = dquot_alloc_block(inode,
EXT4_C2B(EXT4_SB(sb), 1));
if (error)
goto cleanup;
error = ext4_journal_get_write_access(handle,
Expand Down Expand Up @@ -929,7 +930,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
return error;

cleanup_dquot:
dquot_free_block(inode, 1);
dquot_free_block(inode, EXT4_C2B(EXT4_SB(sb), 1));
goto cleanup;

bad_block:
Expand Down

0 comments on commit 1231b3a

Please sign in to comment.