From: Zhao Lei Date: Thu, 9 Apr 2015 04:34:43 +0000 (+0800) Subject: btrfs: wait for delayed iputs on no space X-Git-Tag: v4.1.12-92~150^2~105 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f0ac011c520670588e9ce0ba5f17ad8edde16bd0;p=users%2Fjedix%2Flinux-maple.git btrfs: wait for delayed iputs on no space Orabug: 23331038 [ Upstream commit 9a4e7276d39071576d369e607d7accb84b41d0b4 ] btrfs will report no_space when we run following write and delete file loop: # FILE_SIZE_M=[ 75% of fs space ] # DEV=[ some dev ] # MNT=[ some dir ] # # mkfs.btrfs -f "$DEV" # mount -o nodatacow "$DEV" "$MNT" # for ((i = 0; i < 100; i++)); do dd if=/dev/zero of="$MNT"/file0 bs=1M count="$FILE_SIZE_M"; rm -f "$MNT"/file0; done # Reason: iput() and evict() is run after write pages to block device, if write pages work is not finished before next write, the "rm"ed space is not freed, and caused above bug. Fix: We can add "-o flushoncommit" mount option to avoid above bug, but it have performance problem. Actually, we can to wait for on-the-fly writes only when no-space happened, it is which this patch do. Signed-off-by: Zhao Lei Signed-off-by: Chris Mason Signed-off-by: Sasha Levin (cherry picked from commit 42bd8f4fda813558c3045c60ad6436b1c7430ec7) Signed-off-by: Dan Duval --- diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 3c1938000a5d..98a4d5274d7d 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -3975,6 +3975,9 @@ commit_trans: !atomic_read(&root->fs_info->open_ioctl_trans)) { need_commit--; + if (need_commit > 0) + btrfs_wait_ordered_roots(fs_info, -1); + trans = btrfs_join_transaction(root); if (IS_ERR(trans)) return PTR_ERR(trans);