From: Jan Kara <jack@suse.cz>
To: Amir Goldstein <amir73il@gmail.com>
Cc: Jan Kara <jack@suse.cz>, Al Viro <viro@zeniv.linux.org.uk>,
linux-fsdevel@vger.kernel.org,
Christian Brauner <brauner@kernel.org>,
Miklos Szeredi <miklos@szeredi.hu>,
"Darrick J. Wong" <djwong@kernel.org>, Ted Tso <tytso@mit.edu>,
Jaegeuk Kim <jaegeuk@kernel.org>,
linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-xfs@vger.kernel.org
Subject: Re: [PATCH 6/6] fs: Restrict lock_two_nondirectories() to non-directory inodes
Date: Mon, 29 May 2023 14:42:08 +0200 [thread overview]
Message-ID: <20230529124208.2oou7jt3iitwxk4v@quack3> (raw)
In-Reply-To: <CAOQ4uxhL0w+yqg2u_xW6r4J_gJX=_zoZjo3vh0ONqAbgxm2VTA@mail.gmail.com>
On Fri 26-05-23 15:13:06, Amir Goldstein wrote:
> On Thu, May 25, 2023 at 1:17 PM Jan Kara <jack@suse.cz> wrote:
> >
> > Currently lock_two_nondirectories() is skipping any passed directories.
> > After vfs_rename() uses lock_two_inodes(), all the remaining four users
> > of this function pass only regular files to it. So drop the somewhat
> > unusual "skip directory" logic and instead warn if anybody passes
> > directory to it. This also allows us to use lock_two_inodes() in
> > lock_two_nondirectories() to concentrate the lock ordering logic in less
> > places.
> >
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> > fs/inode.c | 12 ++++--------
> > 1 file changed, 4 insertions(+), 8 deletions(-)
> >
> > diff --git a/fs/inode.c b/fs/inode.c
> > index 2015fa50d34a..accf5125a049 100644
> > --- a/fs/inode.c
> > +++ b/fs/inode.c
> > @@ -1140,7 +1140,7 @@ void lock_two_inodes(struct inode *inode1, struct inode *inode2,
> > /**
> > * lock_two_nondirectories - take two i_mutexes on non-directory objects
> > *
> > - * Lock any non-NULL argument that is not a directory.
> > + * Lock any non-NULL argument. Passed objects must not be directories.
> > * Zero, one or two objects may be locked by this function.
> > *
> > * @inode1: first inode to lock
> > @@ -1148,13 +1148,9 @@ void lock_two_inodes(struct inode *inode1, struct inode *inode2,
> > */
> > 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);
> > + WARN_ON_ONCE(S_ISDIR(inode1->i_mode));
> > + WARN_ON_ONCE(S_ISDIR(inode2->i_mode));
> > + lock_two_inodes(inode1, inode2, I_MUTEX_NORMAL, I_MUTEX_NONDIR2);
> > }
> > EXPORT_SYMBOL(lock_two_nondirectories);
> >
>
> Need the same treatment to unlock_two_nondirectories() because now if
> someone does pass a directory they will get a warning but also a leaked lock.
Yes, probably that is good defensive programming. I'll update the patch.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2023-05-29 15:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-25 10:16 [PATCH 0/6] fs: Fix directory corruption when moving directories Jan Kara
2023-05-25 10:16 ` [PATCH 1/6] ext4: Remove ext4 locking of moved directory Jan Kara
2023-05-25 10:16 ` [PATCH 2/6] Revert "udf: Protect rename against modification of moved directory" Jan Kara
2023-05-25 10:16 ` [PATCH 3/6] Revert "f2fs: fix potential corruption when moving a directory" Jan Kara
2023-05-25 10:16 ` [PATCH 4/6] fs: Establish locking order for unrelated directories Jan Kara
2023-05-26 9:45 ` Christian Brauner
2023-05-29 12:41 ` Jan Kara
2023-05-30 12:42 ` Christian Brauner
2023-05-25 10:16 ` [PATCH 5/6] fs: Lock moved directories Jan Kara
2023-05-25 10:16 ` [PATCH 6/6] fs: Restrict lock_two_nondirectories() to non-directory inodes Jan Kara
2023-05-26 12:13 ` Amir Goldstein
2023-05-29 12:42 ` Jan Kara [this message]
2023-05-26 15:58 ` [PATCH 0/6] fs: Fix directory corruption when moving directories Christian Brauner
2023-05-31 14:09 ` Christian Brauner
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=20230529124208.2oou7jt3iitwxk4v@quack3 \
--to=jack@suse.cz \
--cc=amir73il@gmail.com \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=tytso@mit.edu \
--cc=viro@zeniv.linux.org.uk \
/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