• Filipe Manana's avatar
    Btrfs: send, don't send rmdir for same target multiple times · 29d6d30f
    Filipe Manana authored
    When doing an incremental send, if we delete a directory that has N > 1
    hardlinks for the same file and that file has the highest inode number
    inside the directory contents, an incremental send would send N times an
    rmdir operation against the directory. This made the btrfs receive command
    fail on the second rmdir instruction, as the target directory didn't exist
    anymore.
    
    Steps to reproduce the issue:
    
        $ mkfs.btrfs -f /dev/sdb3
        $ mount /dev/sdb3 /mnt/btrfs
        $ mkdir -p /mnt/btrfs/a/b/c
        $ echo 'ola mundo' > /mnt/btrfs/a/b/c/foo.txt
        $ ln /mnt/btrfs/a/b/c/foo.txt /mnt/btrfs/a/b/c/bar.txt
        $ btrfs subvolume snapshot -r /mnt/btrfs /mnt/btrfs/snap1
        $ btrfs send /mnt/btrfs/snap1 -f /tmp/base.send
        $ rm -f /mnt/btrfs/a/b/c/foo.txt
        $ rm -f /mnt/btrfs/a/b/c/bar.txt
        $ rmdir /mnt/btrfs/a/b/c
        $ btrfs subvolume snapshot -r /mnt/btrfs /mnt/btrfs/snap2
        $ btrfs send -p /mnt/btrfs/snap1 /mnt/btrfs/snap2 -f /tmp/incremental.send
    
        $ umount /mnt/btrfs
        $ mkfs.btrfs -f /dev/sdb3
        $ mount /dev/sdb3 /mnt/btrfs
        $ btrfs receive /mnt/btrfs -f /tmp/base.send
        $ btrfs receive /mnt/btrfs -f /tmp/incremental.send
    
    The second btrfs receive command failed with:
    
        ERROR: rmdir o259-6-0 failed. No such file or directory
    
    A test case for xfstests follows.
    Signed-off-by: default avatarFilipe David Borba Manana <fdmanana@gmail.com>
    Signed-off-by: default avatarJosef Bacik <jbacik@fb.com>
    29d6d30f
send.c 127 KB