[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wgSFUUWJKW1DXa67A0DXVzQ+OATwnC3FCwhqfTJZsvj1A@mail.gmail.com>
Date: Sat, 8 May 2021 08:30:43 -0700
From: Linus Torvalds <torvalds@...ux-foundation.org>
To: Jia He <justin.he@....com>
Cc: Petr Mladek <pmladek@...e.com>,
Steven Rostedt <rostedt@...dmis.org>,
Sergey Senozhatsky <senozhatsky@...omium.org>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Jonathan Corbet <corbet@....net>,
Alexander Viro <viro@...iv.linux.org.uk>,
Al Viro <viro@....linux.org.uk>,
Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ibm.com>,
"Eric W . Biederman" <ebiederm@...ssion.com>,
"Darrick J. Wong" <darrick.wong@...cle.com>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>,
Ira Weiny <ira.weiny@...el.com>,
Eric Biggers <ebiggers@...gle.com>,
"Ahmed S. Darwish" <a.darwish@...utronix.de>,
"open list:DOCUMENTATION" <linux-doc@...r.kernel.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
linux-s390 <linux-s390@...r.kernel.org>,
linux-fsdevel <linux-fsdevel@...r.kernel.org>
Subject: Re: [PATCH RFC 1/3] fs: introduce helper d_path_fast()
On Sat, May 8, 2021 at 5:29 AM Jia He <justin.he@....com> wrote:
>
> This helper is similar to d_path except for not taking seqlock/spinlock.
I see why you did it that way, but conditional locking is something we
really really try to avoid in the kernel.
It basically makes a lot of static tools unable to follow the locking
rules, and it makes it hard for people to se what's going on too.
So instead of passing a "bool need_lock" thing down, the way to do
these things is generally to extract the code inside the locked region
into a helper function of its own, and then you have
__unlocked_version(...)
{
.. do the actual work
}
locked_version(..)
{
take_lock(..)
retval = __unlocked_version(..);
release_lock(..);
return retval;
}
this prepend_path() case is a bit more complicated because there's two
layers of locking, but I think the pattern should still work fine.
In fact, I think it would clean up prepend_path() and make it more
legible to have the two layers of mount_lock / rename_lock be done in
callers with the restarting being done as a loop in the caller rather
than as "goto restart_*".
Linus
Powered by blists - more mailing lists