]> git.baikalelectronics.ru Git - kernel.git/commit
Btrfs: fix deadlock between clone/dedupe and rename
authorFilipe Manana <fdmanana@suse.com>
Tue, 26 Feb 2019 12:06:09 +0000 (12:06 +0000)
committerDavid Sterba <dsterba@suse.com>
Wed, 27 Feb 2019 11:24:16 +0000 (12:24 +0100)
commit1552a78a580596143d8ba65a051bf48f0e9bda46
treed17fce72c97e7bd617523932ddca175cc83d0efd
parent0479bac51f381d438b9c3917513baaf3bb64db71
Btrfs: fix deadlock between clone/dedupe and rename

Reflinking (clone/dedupe) and rename are operations that operate on two
inodes and therefore need to lock them in the same order to avoid ABBA
deadlocks. It happens that Btrfs' reflink implementation always locked
them in a different order from VFS's lock_two_nondirectories() helper,
which is used by the rename code in VFS, resulting in ABBA type deadlocks.

Btrfs' locking order:

  static void btrfs_double_inode_lock(struct inode *inode1, struct inode *inode2)
  {
         if (inode1 < inode2)
                swap(inode1, inode2);

         inode_lock_nested(inode1, I_MUTEX_PARENT);
         inode_lock_nested(inode2, I_MUTEX_CHILD);
  }

VFS's locking order:

  void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
  {
        if (inode1 > inode2)
                swap(inode1, inode2);

        if (inode1 && !S_ISDIR(inode1->i_mode))
                inode_lock(inode1);
        if (inode2 && !S_ISDIR(inode2->i_mode) && inode2 != inode1)
                inode_lock_nested(inode2, I_MUTEX_NONDIR2);
}

Fix this by killing the btrfs helper function that does the double inode
locking and replace it with VFS's helper lock_two_nondirectories().

Reported-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Fixes: c9a002cdfe484b ("btrfs: offline dedupe")
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ioctl.c