Skip to content

Commit 9dced18

Browse files
Miao XieChris Mason
authored andcommitted
Btrfs: fix the free space write out failure when there is no data space
After running space balance on a new fs, the fs check program outputed the following warning message: free space inode generation (0) did not match free space cache generation (20) Steps to reproduce: # mkfs.btrfs -f <dev> # mount <dev> <mnt> # btrfs balance start <mnt> # umount <mnt> # btrfs check <dev> It was because there was no data space after the space balance, and the free space write out task didn't try to allocate a new data chunk for the free space inode when doing the reservation. So the data space reservation failed, and in order to tell the free space loader that this free space inode could not be trusted, the generation of the free space inode wasn't updated. Then the check program found this problem and outputed the above message. But in fact, it is safe that we try to allocate a new data chunk when we find the data space is not enough. The patch fixes the above problem by this way. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent 9e6a0c5 commit 9dced18

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

‎fs/btrfs/extent-tree.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,10 +3621,9 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes)
36213621
/* make sure bytes are sectorsize aligned */
36223622
bytes = ALIGN(bytes, root->sectorsize);
36233623

3624-
if (root == root->fs_info->tree_root ||
3625-
BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) {
3626-
alloc_chunk = 0;
3624+
if (btrfs_is_free_space_inode(inode)) {
36273625
committed = 1;
3626+
ASSERT(current->journal_info);
36283627
}
36293628

36303629
data_sinfo = fs_info->data_sinfo;
@@ -3652,6 +3651,16 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes)
36523651
spin_unlock(&data_sinfo->lock);
36533652
alloc:
36543653
alloc_target = btrfs_get_alloc_profile(root, 1);
3654+
/*
3655+
* It is ugly that we don't call nolock join
3656+
* transaction for the free space inode case here.
3657+
* But it is safe because we only do the data space
3658+
* reservation for the free space cache in the
3659+
* transaction context, the common join transaction
3660+
* just increase the counter of the current transaction
3661+
* handler, doesn't try to acquire the trans_lock of
3662+
* the fs.
3663+
*/
36553664
trans = btrfs_join_transaction(root);
36563665
if (IS_ERR(trans))
36573666
return PTR_ERR(trans);

0 commit comments

Comments
 (0)