Thread (72 messages) 72 messages, 8 authors, 2021-07-07

RE: [PATCH 03/14] d_path: regularize handling of root dentry in __dentry_path()

From: Justin He <hidden>
Date: 2021-07-07 04:50:55
Also in: linux-doc, linux-fsdevel, lkml

-----Original Message-----
From: Al Viro <redacted> On Behalf Of Al Viro
Sent: Wednesday, May 19, 2021 8:49 AM
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Justin He <redacted>; Petr Mladek <pmladek@suse.com>; Steven
Rostedt [off-list ref]; Sergey Senozhatsky
[off-list ref]; Andy Shevchenko
[off-list ref]; Rasmus Villemoes
[off-list ref]; Jonathan Corbet [off-list ref]; Heiko
Carstens [off-list ref]; Vasily Gorbik [off-list ref]; Christian
Borntraeger [off-list ref]; Eric W . Biederman
[off-list ref]; Darrick J. Wong [off-list ref]; Peter
Zijlstra (Intel) [off-list ref]; Ira Weiny [off-list ref];
Eric Biggers [off-list ref]; Ahmed S. Darwish
[off-list ref]; open list:DOCUMENTATION <linux-
doc@vger.kernel.org>; Linux Kernel Mailing List <linux-
kernel@vger.kernel.org>; linux-s390 [off-list ref]; linux-
fsdevel [off-list ref]
Subject: [PATCH 03/14] d_path: regularize handling of root dentry in
__dentry_path()

All path-forming primitives boil down to sequence of prepend_name()
on dentries encountered along the way toward root.  Each time we prepend
/ + dentry name to the buffer.  Normally that does exactly what we want,
but there's a corner case when we don't call prepend_name() at all (in case
of __dentry_path() that happens if we are given root dentry).  We obviously
want to end up with "/", rather than "", so this corner case needs to be
handled.

__dentry_path() used to manually put '/' in the end of buffer before
doing anything else, to be overwritten by the first call of prepend_name()
if one happens and to be left in place if we don't call prepend_name() at
all.  That required manually checking that we had space in the buffer
(prepend_name() and prepend() take care of such checks themselves) and lead
to clumsy keeping track of return value.

A better approach is to check if the main loop has added anything
into the buffer and prepend "/" if it hasn't.  A side benefit of using
prepend()
is that it does the right thing if we'd already run out of buffer, making
the overflow-handling logics simpler.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Reviewed-by: Jia He <redacted>


--
Cheers,
Justin (Jia He)


IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help