Discussion:
btrfs clone ordering of mutex
Steve French
2013-11-11 21:50:18 UTC
Permalink
Pavel pointed out (as we were discussing clone) that this mutex
locking sequence in btrfs_ioctl_clone in btrfs/ioctl.c will unlock the
mutexes in the wrong order much of the time. Shouldn't the unlock of
two mutexes be done in the reverse order from the lock of the mutexes
to avoid other users of these mutexes potentially deadlocking? See
this small section of btrfs_ioctl_clone

if (!same_inode) {
if (inode < src) {
mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT);
mutex_lock_nested(&src->i_mutex, I_MUTEX_CHILD);
} else {
mutex_lock_nested(&src->i_mutex, I_MUTEX_PARENT);
mutex_lock_nested(&inode->i_mutex, I_MUTEX_CHILD);
}
} else {
mutex_lock(&src->i_mutex);
}

followed by:

mutex_unlock(&src->i_mutex);
if (!same_inode)
mutex_unlock(&inode->i_mutex);
--
Thanks,

Steve
Loading...