From: David Sterba <dsterba@suse.cz>
To: fdmanana@kernel.org
Cc: linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] Btrfs: fix infinite loop during fsync after rename operations
Date: Tue, 21 Jan 2020 14:20:37 +0100 [thread overview]
Message-ID: <20200121132037.GQ3929@twin.jikos.cz> (raw)
In-Reply-To: <20200115132135.23994-1-fdmanana@kernel.org>
On Wed, Jan 15, 2020 at 01:21:35PM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
>
> Recently fsstress (from fstests) sporadically started to trigger an
> infinite loop during fsync operations. This turned out to be because
> support for the rename exchange and whiteout operations was added to
> fsstress in fstests. These operations, unlike any others in fsstress,
> cause file names to be reused, whence triggering this issue. However
> it's not necessary to use rename exchange and rename whiteout operations
> trigger this issue, simple rename operations and file creations are
> enough to trigger the issue.
>
> The issue boils down to when we are logging inodes that conflict (that
> had the name of any inode we need to log during the fsync operation),
> we keep logging them even if they were already logged before, and after
> that we check if there's any other inode that conflicts with them and
> then add it again to the list of inodes to log. Skipping already logged
> inodes fixes the issue.
>
> Consider the following example:
>
> $ mkfs.btrfs -f /dev/sdb
> $ mount /dev/sdb /mnt
>
> $ mkdir /mnt/testdir # inode 257
>
> $ touch /mnt/testdir/zz # inode 258
> $ ln /mnt/testdir/zz /mnt/testdir/zz_link
>
> $ touch /mnt/testdir/a # inode 259
>
> $ sync
>
> # The following 3 renames achieve the same result as a rename exchange
> # operation (<rename_exchange> /mnt/testdir/zz_link to /mnt/testdir/a).
>
> $ mv /mnt/testdir/a /mnt/testdir/a/tmp
> $ mv /mnt/testdir/zz_link /mnt/testdir/a
> $ mv /mnt/testdir/a/tmp /mnt/testdir/zz_link
>
> # The following rename and file creation give the same result as a
> # rename whiteout operation (<rename_whiteout> zz to a2).
>
> $ mv /mnt/testdir/zz /mnt/testdir/a2
> $ touch /mnt/testdir/zz # inode 260
>
> $ xfs_io -c fsync /mnt/testdir/zz
> --> results in the infinite loop
>
> The following steps happen:
>
> 1) When logging inode 260, we find that its reference named "zz" was
> used by inode 258 in the previous transaction (through the commit
> root), so inode 258 is added to the list of conflicting indoes that
> need to be logged;
>
> 2) After logging inode 258, we find that its reference named "a" was
> used by inode 259 in the previous transaction, and therefore we add
> inode 259 to the list of conflicting inodes to be logged;
>
> 3) After logging inode 259, we find that its reference named "zz_link"
> was used by inode 258 in the previous transaction - we add inode 258
> to the list of conflicting inodes to log, again - we had already
> logged it before at step 3. After logging it again, we find again
> that inode 259 conflicts with him, and we add again 259 to the list,
> etc - we end up repeating all the previous steps.
>
> So fix this by skipping logging of conflicting inodes that were already
> logged.
>
> Fixes: 6b5fc433a7ad67 ("Btrfs: fix fsync after succession of renames of different files")
> CC: stable@vger.kernel.org
> Signed-off-by: Filipe Manana <fdmanana@suse.com>
Added to misc-next, thanks.
prev parent reply other threads:[~2020-01-21 13:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-15 13:21 [PATCH] Btrfs: fix infinite loop during fsync after rename operations fdmanana
2020-01-16 16:03 ` Josef Bacik
2020-01-21 13:20 ` David Sterba [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200121132037.GQ3929@twin.jikos.cz \
--to=dsterba@suse.cz \
--cc=fdmanana@kernel.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).