Skip to content

Commit

Permalink
Btrfs: fix send dealing with file renames and directory moves
Browse files Browse the repository at this point in the history
This fixes a case that the commit titled:

   Btrfs: fix infinite path build loops in incremental send

didn't cover. If the parent-child relationship between 2 directories
is inverted, both get renamed, and the former parent has a file that
got renamed too (but remains a child of that directory), the incremental
send operation would use the file's old path after sending an unlink
operation for that old path, causing receive to fail on future operations
like changing owner, permissions or utimes of the corresponding inode.

This is not a regression from the commit mentioned before, as without
that commit we would fall into the issues that commit fixed, so it's
just one case that wasn't covered before.

Simple steps to reproduce this issue are:

      $ mkfs.btrfs -f /dev/sdb3
      $ mount /dev/sdb3 /mnt/btrfs
      $ mkdir -p /mnt/btrfs/a/b/c/d
      $ touch /mnt/btrfs/a/b/c/d/file
      $ mkdir -p /mnt/btrfs/a/b/x
      $ btrfs subvol snapshot -r /mnt/btrfs /mnt/btrfs/snap1
      $ mv /mnt/btrfs/a/b/x /mnt/btrfs/a/b/c/x2
      $ mv /mnt/btrfs/a/b/c/d /mnt/btrfs/a/b/c/x2/d2
      $ mv /mnt/btrfs/a/b/c/x2/d2/file /mnt/btrfs/a/b/c/x2/d2/file2
      $ btrfs subvol snapshot -r /mnt/btrfs /mnt/btrfs/snap2
      $ btrfs send -p /mnt/btrfs/snap1 /mnt/btrfs/snap2 > /tmp/incremental.send

A patch to update the test btrfs/030 from xfstests, so that it covers
this case, will be submitted soon.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
  • Loading branch information
Filipe David Borba Manana authored and Josef Bacik committed Mar 10, 2014
1 parent 98cfee2 commit 03cb4fb
Showing 1 changed file with 1 addition and 9 deletions.
10 changes: 1 addition & 9 deletions fs/btrfs/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -2131,8 +2131,6 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen,
u64 parent_inode = 0;
u64 parent_gen = 0;
int stop = 0;
u64 start_ino = ino;
u64 start_gen = gen;
int skip_name_cache = 0;

name = fs_path_alloc();
Expand All @@ -2144,7 +2142,6 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen,
if (is_waiting_for_move(sctx, ino))
skip_name_cache = 1;

again:
dest->reversed = 1;
fs_path_reset(dest);

Expand All @@ -2159,13 +2156,8 @@ static int get_cur_path(struct send_ctx *sctx, u64 ino, u64 gen,
stop = 1;

if (!skip_name_cache &&
is_waiting_for_move(sctx, parent_inode)) {
ino = start_ino;
gen = start_gen;
stop = 0;
is_waiting_for_move(sctx, parent_inode))
skip_name_cache = 1;
goto again;
}

ret = fs_path_add_path(dest, name);
if (ret < 0)
Expand Down

0 comments on commit 03cb4fb

Please sign in to comment.