Skip to content

Commit 0ad9dfc

Browse files
fs/ntfs3: Changing locking in ntfs_rename
In some cases we can be in deadlock because we tried to lock the same dir. Signed-off-by: Konstantin Komarov <[email protected]>
1 parent ad26a9c commit 0ad9dfc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

fs/ntfs3/namei.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir,
305305

306306
ni_lock_dir(dir_ni);
307307
ni_lock(ni);
308+
if (dir_ni != new_dir_ni)
309+
ni_lock_dir2(new_dir_ni);
308310

309311
is_bad = false;
310312
err = ni_rename(dir_ni, new_dir_ni, ni, de, new_de, &is_bad);
@@ -328,6 +330,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir,
328330
ntfs_sync_inode(inode);
329331
}
330332

333+
if (dir_ni != new_dir_ni)
334+
ni_unlock(new_dir_ni);
331335
ni_unlock(ni);
332336
ni_unlock(dir_ni);
333337
out:

fs/ntfs3/ntfs_fs.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ enum ntfs_inode_mutex_lock_class {
334334
NTFS_INODE_MUTEX_REPARSE,
335335
NTFS_INODE_MUTEX_NORMAL,
336336
NTFS_INODE_MUTEX_PARENT,
337+
NTFS_INODE_MUTEX_PARENT2,
337338
};
338339

339340
/*
@@ -1121,6 +1122,11 @@ static inline void ni_lock_dir(struct ntfs_inode *ni)
11211122
mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT);
11221123
}
11231124

1125+
static inline void ni_lock_dir2(struct ntfs_inode *ni)
1126+
{
1127+
mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT2);
1128+
}
1129+
11241130
static inline void ni_unlock(struct ntfs_inode *ni)
11251131
{
11261132
mutex_unlock(&ni->ni_lock);

0 commit comments

Comments
 (0)