OSDN Git Service

btrfs: fix invalid removal of root ref
authorJosef Bacik <josef@toxicpanda.com>
Wed, 18 Dec 2019 22:20:28 +0000 (17:20 -0500)
committerDavid Sterba <dsterba@suse.com>
Wed, 8 Jan 2020 13:44:23 +0000 (14:44 +0100)
commitd49d3287e74ffe55ae7430d1e795e5f9bf7359ea
tree9ecc5de1460a5b482e2c75284a27e5cb33a7310b
parent045d3967b6920b663fc010ad414ade1b24143bd1
btrfs: fix invalid removal of root ref

If we have the following sequence of events

  btrfs sub create A
  btrfs sub create A/B
  btrfs sub snap A C
  mkdir C/foo
  mv A/B C/foo
  rm -rf *

We will end up with a transaction abort.

The reason for this is because we create a root ref for B pointing to A.
When we create a snapshot of C we still have B in our tree, but because
the root ref points to A and not C we will make it appear to be empty.

The problem happens when we move B into C.  This removes the root ref
for B pointing to A and adds a ref of B pointing to C.  When we rmdir C
we'll see that we have a ref to our root and remove the root ref,
despite not actually matching our reference name.

Now btrfs_del_root_ref() allowing this to work is a bug as well, however
we know that this inode does not actually point to a root ref in the
first place, so we shouldn't be calling btrfs_del_root_ref() in the
first place and instead simply look up our dir index for this item and
do the rest of the removal.

CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/inode.c