Commit 7df26ca1d80e22cd080f7a8d9ffc307ef1661d3a

Authored by Filipe Manana
Committed by Greg Kroah-Hartman
1 parent 580b02787e

Btrfs: send, account for orphan directories when building path strings

commit c992ec94f24c3e7135d6c23860615f269f0b1d87 upstream.

If we have directories with a pending move/rename operation, we must take into
account any orphan directories that got created before executing the pending
move/rename. Those orphan directories are directories with an inode number higher
then the current send progress and that don't exist in the parent snapshot, they
are created before current progress reaches their inode number, with a generated
name of the form oN-M-I and at the root of the filesystem tree, and later when
progress matches their inode number, moved/renamed to their final location.

Reproducer:

          $ mkfs.btrfs -f /dev/sdd
          $ mount /dev/sdd /mnt

          $ mkdir -p /mnt/a/b/c/d
          $ mkdir /mnt/a/b/e
          $ mv /mnt/a/b/c /mnt/a/b/e/CC
          $ mkdir /mnt/a/b/e/CC/d/f
	  $ mkdir /mnt/a/g

          $ btrfs subvolume snapshot -r /mnt /mnt/snap1
          $ btrfs send /mnt/snap1 -f /tmp/base.send

          $ mkdir /mnt/a/g/h
	  $ mv /mnt/a/b/e /mnt/a/g/h/EE
          $ mv /mnt/a/g/h/EE/CC/d /mnt/a/g/h/EE/DD

          $ btrfs subvolume snapshot -r /mnt /mnt/snap2
          $ btrfs send -p /mnt/snap1 /mnt/snap2 -f /tmp/incremental.send

The second receive command failed with the following error:

    ERROR: rename a/b/e/CC/d -> o264-7-0/EE/DD failed. No such file or directory

A test case for xfstests follows soon.

Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com>
Signed-off-by: Chris Mason <clm@fb.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 9 additions and 24 deletions Side-by-side Diff

... ... @@ -3054,32 +3054,17 @@
3054 3054 if (ret < 0)
3055 3055 goto out;
3056 3056  
3057   - if (parent_ino == sctx->cur_ino) {
3058   - /* child only renamed, not moved */
3059   - ASSERT(parent_gen == sctx->cur_inode_gen);
3060   - ret = get_cur_path(sctx, sctx->cur_ino, sctx->cur_inode_gen,
3061   - from_path);
3062   - if (ret < 0)
3063   - goto out;
3064   - ret = fs_path_add_path(from_path, name);
3065   - if (ret < 0)
3066   - goto out;
3067   - } else {
3068   - /* child moved and maybe renamed too */
3069   - sctx->send_progress = pm->ino;
3070   - ret = get_cur_path(sctx, pm->ino, pm->gen, from_path);
3071   - if (ret < 0)
3072   - goto out;
3073   - }
  3057 + ret = get_cur_path(sctx, parent_ino, parent_gen,
  3058 + from_path);
  3059 + if (ret < 0)
  3060 + goto out;
  3061 + ret = fs_path_add_path(from_path, name);
  3062 + if (ret < 0)
  3063 + goto out;
3074 3064  
3075   - fs_path_free(name);
  3065 + fs_path_reset(name);
  3066 + to_path = name;
3076 3067 name = NULL;
3077   -
3078   - to_path = fs_path_alloc();
3079   - if (!to_path) {
3080   - ret = -ENOMEM;
3081   - goto out;
3082   - }
3083 3068  
3084 3069 sctx->send_progress = sctx->cur_ino + 1;
3085 3070 ret = get_cur_path(sctx, pm->ino, pm->gen, to_path);