Message ID | 20210528113951.6225-2-justin.he@arm.com (mailing list archive) |
---|---|
State | RFC |
Delegated to: | Johannes Berg |
Headers | show |
Series | make '%pD' print full path for file | expand |
On Fri, May 28, 2021 at 07:39:49PM +0800, Jia He wrote: > +/** > + * d_path_fast - fast return the full path of a dentry without taking > + * any seqlock/spinlock. This helper is typical for debugging purpose > + */ > +char *d_path_fast(const struct path *path, char *buf, int buflen) > +{ > + struct path root; > + struct mount *mnt = real_mount(path->mnt); > + DECLARE_BUFFER(b, buf, buflen); > + > + rcu_read_lock(); > + get_fs_root_rcu(current->fs, &root); > + > + prepend(&b, "", 1); > + __prepend_path(path->dentry, mnt, &root, &b); > + rcu_read_unlock(); > + > + return extract_string(&b); > +} > +EXPORT_SYMBOL(d_path_fast); Umm... I'd suggest failing if __prepend_path() returns 3 (at least)...
On Fri, May 28, 2021 at 07:39:49PM +0800, Jia He wrote: > +/** > + * d_path_fast - fast return the full path of a dentry without taking > + * any seqlock/spinlock. This helper is typical for debugging purpose > + */ > +char *d_path_fast(const struct path *path, char *buf, int buflen) I'd suggest calling it d_path_unsafe(). Otherwise people will call it instead of d_path because who doesn't like fast? > +{ > + struct path root; > + struct mount *mnt = real_mount(path->mnt); > + DECLARE_BUFFER(b, buf, buflen); > + > + rcu_read_lock(); > + get_fs_root_rcu(current->fs, &root); > + > + prepend(&b, "", 1); > + __prepend_path(path->dentry, mnt, &root, &b); > + rcu_read_unlock(); > + > + return extract_string(&b); > +} > +EXPORT_SYMBOL(d_path_fast); Why export it? What module needs this?
> -----Original Message----- > From: Matthew Wilcox <willy@infradead.org> > Sent: Friday, May 28, 2021 8:52 PM > To: Justin He <Justin.He@arm.com> > Cc: Linus Torvalds <torvalds@linux-foundation.org>; Petr Mladek > <pmladek@suse.com>; Steven Rostedt <rostedt@goodmis.org>; Sergey > Senozhatsky <senozhatsky@chromium.org>; Andy Shevchenko > <andriy.shevchenko@linux.intel.com>; Rasmus Villemoes > <linux@rasmusvillemoes.dk>; Jonathan Corbet <corbet@lwn.net>; Alexander > Viro <viro@zeniv.linux.org.uk>; Luca Coelho <luciano.coelho@intel.com>; > Kalle Valo <kvalo@codeaurora.org>; David S. Miller <davem@davemloft.net>; > Jakub Kicinski <kuba@kernel.org>; Heiko Carstens <hca@linux.ibm.com>; > Vasily Gorbik <gor@linux.ibm.com>; Christian Borntraeger > <borntraeger@de.ibm.com>; Johannes Berg <johannes.berg@intel.com>; linux- > doc@vger.kernel.org; linux-kernel@vger.kernel.org; linux- > wireless@vger.kernel.org; netdev@vger.kernel.org; linux- > s390@vger.kernel.org > Subject: Re: [PATCH RFCv2 1/3] fs: introduce helper d_path_fast() > > On Fri, May 28, 2021 at 07:39:49PM +0800, Jia He wrote: > > +/** > > + * d_path_fast - fast return the full path of a dentry without taking > > + * any seqlock/spinlock. This helper is typical for debugging purpose > > + */ > > +char *d_path_fast(const struct path *path, char *buf, int buflen) > > I'd suggest calling it d_path_unsafe(). Otherwise people will call it > instead of d_path because who doesn't like fast? > Okay, thanks > > +{ > > + struct path root; > > + struct mount *mnt = real_mount(path->mnt); > > + DECLARE_BUFFER(b, buf, buflen); > > + > > + rcu_read_lock(); > > + get_fs_root_rcu(current->fs, &root); > > + > > + prepend(&b, "", 1); > > + __prepend_path(path->dentry, mnt, &root, &b); > > + rcu_read_unlock(); > > + > > + return extract_string(&b); > > +} > > +EXPORT_SYMBOL(d_path_fast); > > Why export it? What module needs this? Okay, indeed -- 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.
diff --git a/fs/d_path.c b/fs/d_path.c index 23a53f7b5c71..f9df68d62786 100644 --- a/fs/d_path.c +++ b/fs/d_path.c @@ -263,6 +263,27 @@ char *d_path(const struct path *path, char *buf, int buflen) } EXPORT_SYMBOL(d_path); +/** + * d_path_fast - fast return the full path of a dentry without taking + * any seqlock/spinlock. This helper is typical for debugging purpose + */ +char *d_path_fast(const struct path *path, char *buf, int buflen) +{ + struct path root; + struct mount *mnt = real_mount(path->mnt); + DECLARE_BUFFER(b, buf, buflen); + + rcu_read_lock(); + get_fs_root_rcu(current->fs, &root); + + prepend(&b, "", 1); + __prepend_path(path->dentry, mnt, &root, &b); + rcu_read_unlock(); + + return extract_string(&b); +} +EXPORT_SYMBOL(d_path_fast); + /* * Helper function for dentry_operations.d_dname() members */ diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 9e23d33bb6f1..c4483fc887a5 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -301,6 +301,7 @@ char *dynamic_dname(struct dentry *, char *, int, const char *, ...); extern char *__d_path(const struct path *, const struct path *, char *, int); extern char *d_absolute_path(const struct path *, char *, int); extern char *d_path(const struct path *, char *, int); +extern char *d_path_fast(const struct path *, char *, int); extern char *dentry_path_raw(const struct dentry *, char *, int); extern char *dentry_path(const struct dentry *, char *, int);
This helper is similar to d_path except that it doesn't take any seqlock/spinlock. It is typical for debugging purpose. Signed-off-by: Jia He <justin.he@arm.com> --- fs/d_path.c | 21 +++++++++++++++++++++ include/linux/dcache.h | 1 + 2 files changed, 22 insertions(+)