mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 06/14] fs/ntfs3: Changing locking in ntfs_rename
Date: Fri, 28 Oct 2022 20:04:26 +0300	[thread overview]
Message-ID: <721e9a74-607c-fb85-8cbf-5bfed49b266e@paragon-software.com> (raw)
In-Reply-To: <fc5957cc-a71b-cfa3-f291-cb63b23800d1@paragon-software.com>

In some cases we can be in deadlock
because we tried to lock the same dir.

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
  fs/ntfs3/namei.c   | 4 ++++
  fs/ntfs3/ntfs_fs.h | 6 ++++++
  2 files changed, 10 insertions(+)

diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c
index 1af02d4f6b4d..13d6acc0747f 100644
--- a/fs/ntfs3/namei.c
+++ b/fs/ntfs3/namei.c
@@ -305,6 +305,8 @@ static int ntfs_rename(struct user_namespace *mnt_userns, struct inode *dir,
  
  	ni_lock_dir(dir_ni);
  	ni_lock(ni);
+	if (dir_ni != new_dir_ni)
+		ni_lock_dir2(new_dir_ni);
  
  	is_bad = false;
  	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,
  			ntfs_sync_inode(inode);
  	}
  
+	if (dir_ni != new_dir_ni)
+		ni_unlock(new_dir_ni);
  	ni_unlock(ni);
  	ni_unlock(dir_ni);
  out:
diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h
index c45a411f82f6..5fad93a2c3fd 100644
--- a/fs/ntfs3/ntfs_fs.h
+++ b/fs/ntfs3/ntfs_fs.h
@@ -333,6 +333,7 @@ enum ntfs_inode_mutex_lock_class {
  	NTFS_INODE_MUTEX_REPARSE,
  	NTFS_INODE_MUTEX_NORMAL,
  	NTFS_INODE_MUTEX_PARENT,
+	NTFS_INODE_MUTEX_PARENT2,
  };
  
  /*
@@ -1119,6 +1120,11 @@ static inline void ni_lock_dir(struct ntfs_inode *ni)
  	mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT);
  }
  
+static inline void ni_lock_dir2(struct ntfs_inode *ni)
+{
+	mutex_lock_nested(&ni->ni_lock, NTFS_INODE_MUTEX_PARENT2);
+}
+
  static inline void ni_unlock(struct ntfs_inode *ni)
  {
  	mutex_unlock(&ni->ni_lock);
-- 
2.37.0



  parent reply	other threads:[~2022-10-28 17:06 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-28 17:00 [PATCH 00/14] fs/ntfs3: Additional bugfix and refactoring Konstantin Komarov
2022-10-28 17:01 ` [PATCH 01/14] fs/ntfs3: Fixing work with sparse clusters Konstantin Komarov
2022-10-28 17:02 ` [PATCH 02/14] fs/ntfs3: Change new sparse cluster processing Konstantin Komarov
2022-10-28 17:02 ` [PATCH 03/14] fs/ntfs3: Fix wrong indentations Konstantin Komarov
2022-10-28 17:03 ` [PATCH 04/14] fs/ntfs3: atomic_open implementation Konstantin Komarov
2022-10-28 17:03 ` [PATCH 05/14] fs/ntfs3: Fixing wrong logic in attr_set_size and ntfs_fallocate Konstantin Komarov
2022-10-28 17:04 ` Konstantin Komarov [this message]
2022-10-28 17:04 ` [PATCH 07/14] fs/ntfs3: Restore correct state after ENOSPC in attr_data_get_block Konstantin Komarov
2022-10-28 17:05 ` [PATCH 08/14] fs/ntfs3: Correct ntfs_check_for_free_space Konstantin Komarov
2022-10-28 17:05 ` [PATCH 09/14] fs/ntfs3: Check fields while reading Konstantin Komarov
2023-06-19  9:41   ` Lee Jones
2023-06-27 13:49     ` Lee Jones
2022-10-28 17:06 ` [PATCH 10/14] fs/ntfs3: Fix incorrect if in ntfs_set_acl_ex Konstantin Komarov
2022-10-28 17:06 ` [PATCH 11/14] fs/ntfs3: Use ALIGN kernel macro Konstantin Komarov
2022-10-28 17:07 ` [PATCH 12/14] fs/ntfs3: Fix wrong if in hdr_first_de Konstantin Komarov
2022-10-28 17:07 ` [PATCH 13/14] fs/ntfs3: Improve checking of bad clusters Konstantin Komarov
2022-10-28 17:08 ` [PATCH 14/14] fs/ntfs3: Make if more readable Konstantin Komarov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=721e9a74-607c-fb85-8cbf-5bfed49b266e@paragon-software.com \
    --to=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®