From: Al Viro <viro@zeniv.linux.org.uk>
To: linux-fsdevel@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Mo Zou <lostzoumo@gmail.com>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 8/9] kill lock_two_inodes()
Date: Sat, 25 Nov 2023 20:11:46 +0000 [thread overview]
Message-ID: <20231125201147.753695-8-viro@zeniv.linux.org.uk> (raw)
In-Reply-To: <20231125201147.753695-1-viro@zeniv.linux.org.uk>
There's only one caller left (lock_two_nondirectories()), and it
needs less complexity. Fold lock_two_inodes() in there and
simplify.
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
fs/inode.c | 49 ++++++-------------------------------------------
fs/internal.h | 2 --
2 files changed, 6 insertions(+), 45 deletions(-)
diff --git a/fs/inode.c b/fs/inode.c
index edcd8a61975f..453d5be1a014 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1087,48 +1087,6 @@ void discard_new_inode(struct inode *inode)
}
EXPORT_SYMBOL(discard_new_inode);
-/**
- * lock_two_inodes - lock two inodes (may be regular files but also dirs)
- *
- * Lock any non-NULL argument. The caller must make sure that if he is passing
- * in two directories, one is not ancestor of the other. Zero, one or two
- * objects may be locked by this function.
- *
- * @inode1: first inode to lock
- * @inode2: second inode to lock
- * @subclass1: inode lock subclass for the first lock obtained
- * @subclass2: inode lock subclass for the second lock obtained
- */
-void lock_two_inodes(struct inode *inode1, struct inode *inode2,
- unsigned subclass1, unsigned subclass2)
-{
- if (!inode1 || !inode2) {
- /*
- * Make sure @subclass1 will be used for the acquired lock.
- * This is not strictly necessary (no current caller cares) but
- * let's keep things consistent.
- */
- if (!inode1)
- swap(inode1, inode2);
- goto lock;
- }
-
- /*
- * If one object is directory and the other is not, we must make sure
- * to lock directory first as the other object may be its child.
- */
- if (S_ISDIR(inode2->i_mode) == S_ISDIR(inode1->i_mode)) {
- if (inode1 > inode2)
- swap(inode1, inode2);
- } else if (!S_ISDIR(inode1->i_mode))
- swap(inode1, inode2);
-lock:
- if (inode1)
- inode_lock_nested(inode1, subclass1);
- if (inode2 && inode2 != inode1)
- inode_lock_nested(inode2, subclass2);
-}
-
/**
* lock_two_nondirectories - take two i_mutexes on non-directory objects
*
@@ -1144,7 +1102,12 @@ void lock_two_nondirectories(struct inode *inode1, struct inode *inode2)
WARN_ON_ONCE(S_ISDIR(inode1->i_mode));
if (inode2)
WARN_ON_ONCE(S_ISDIR(inode2->i_mode));
- lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2);
+ if (inode1 > inode2)
+ swap(inode1, inode2);
+ if (inode1)
+ inode_lock(inode1);
+ if (inode2 && inode2 != inode1)
+ inode_lock_nested(inode2, I_MUTEX_NONDIR2);
}
EXPORT_SYMBOL(lock_two_nondirectories);
diff --git a/fs/internal.h b/fs/internal.h
index 58e43341aebf..de67b02226e5 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -196,8 +196,6 @@ extern long prune_icache_sb(struct super_block *sb, struct shrink_control *sc);
int dentry_needs_remove_privs(struct mnt_idmap *, struct dentry *dentry);
bool in_group_or_capable(struct mnt_idmap *idmap,
const struct inode *inode, vfsgid_t vfsgid);
-void lock_two_inodes(struct inode *inode1, struct inode *inode2,
- unsigned subclass1, unsigned subclass2);
/*
* fs-writeback.c
--
2.39.2
next prev parent reply other threads:[~2023-11-25 20:12 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 19:30 [PATCHES][CFT] rename deadlock fixes Al Viro
2023-11-22 19:36 ` [PATCH 1/9] reiserfs: Avoid touching renamed directory if parent does not change Al Viro
2023-11-22 19:36 ` [PATCH 2/9] ocfs2: " Al Viro
2023-11-22 19:36 ` [PATCH 3/9] udf_rename(): only access the child content on cross-directory rename Al Viro
2023-11-23 9:22 ` Jan Kara
2023-11-22 19:36 ` [PATCH 4/9] ext2: Avoid reading renamed directory if parent does not change Al Viro
2023-11-22 19:36 ` [PATCH 5/9] ext4: don't access the source subdirectory content on same-directory rename Al Viro
2023-11-23 9:31 ` Jan Kara
2023-11-22 19:36 ` [PATCH 6/9] f2fs: Avoid reading renamed directory if parent does not change Al Viro
2023-11-22 19:36 ` [PATCH 7/9] rename(): fix the locking of subdirectories Al Viro
2023-11-23 9:50 ` Jan Kara
2023-11-22 19:36 ` [PATCH 8/9] kill lock_two_inodes() Al Viro
2023-11-23 9:53 ` Jan Kara
2023-11-22 19:36 ` [PATCH 9/9] rename(): avoid a deadlock in the case of parents having no common ancestor Al Viro
2023-11-23 10:36 ` Jan Kara
2023-11-24 6:15 ` Al Viro
2023-11-24 7:24 ` Amir Goldstein
2023-11-25 20:10 ` [PATCHES v2][CFT] rename deadlock fixes Al Viro
2023-11-25 20:11 ` [PATCH v2 1/9] reiserfs: Avoid touching renamed directory if parent does not change Al Viro
2023-11-25 20:11 ` [PATCH v2 2/9] ocfs2: " Al Viro
2023-11-25 20:11 ` [PATCH v2 3/9] udf_rename(): only access the child content on cross-directory rename Al Viro
2023-11-25 20:11 ` [PATCH v2 4/9] ext2: Avoid reading renamed directory if parent does not change Al Viro
2023-11-25 20:11 ` [PATCH v2 5/9] ext4: don't access the source subdirectory content on same-directory rename Al Viro
2023-11-25 20:11 ` [PATCH v2 6/9] f2fs: Avoid reading renamed directory if parent does not change Al Viro
2023-11-25 20:11 ` [PATCH v2 7/9] rename(): fix the locking of subdirectories Al Viro
2023-11-25 20:11 ` Al Viro [this message]
2023-11-25 20:11 ` [PATCH v2 9/9] rename(): avoid a deadlock in the case of parents having no common ancestor Al Viro
2023-12-05 2:21 [RFC][PATCHES v2] checksum stuff Al Viro
2023-12-05 2:23 ` [PATCH v2 01/18] make net/checksum.h self-contained Al Viro
2023-12-05 2:24 ` [PATCH v2 8/9] kill lock_two_inodes() Al Viro
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=20231125201147.753695-8-viro@zeniv.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lostzoumo@gmail.com \
--cc=torvalds@linux-foundation.org \
/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®