From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC425C43460 for ; Sat, 8 May 2021 21:06:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81DAE6140F for ; Sat, 8 May 2021 21:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229549AbhEHVHb (ORCPT ); Sat, 8 May 2021 17:07:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbhEHVHa (ORCPT ); Sat, 8 May 2021 17:07:30 -0400 Received: from zeniv-ca.linux.org.uk (zeniv-ca.linux.org.uk [IPv6:2607:5300:60:148a::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9E13C061574; Sat, 8 May 2021 14:06:28 -0700 (PDT) Received: from viro by zeniv-ca.linux.org.uk with local (Exim 4.94 #2 (Red Hat Linux)) id 1lfU8u-00Cktr-Je; Sat, 08 May 2021 21:05:44 +0000 Date: Sat, 8 May 2021 21:05:44 +0000 From: Al Viro To: Linus Torvalds Cc: Jia He , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Al Viro , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , "Eric W . Biederman" , "Darrick J. Wong" , "Peter Zijlstra (Intel)" , Ira Weiny , Eric Biggers , "Ahmed S. Darwish" , "open list:DOCUMENTATION" , Linux Kernel Mailing List , linux-s390 , linux-fsdevel Subject: Re: [PATCH RFC 1/3] fs: introduce helper d_path_fast() Message-ID: References: <20210508122530.1971-1-justin.he@arm.com> <20210508122530.1971-2-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: Al Viro Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On Sat, May 08, 2021 at 01:39:45PM -0700, Linus Torvalds wrote: > +static inline int prepend_entries(struct prepend_buffer *b, const struct path *path, const struct path *root, struct mount *mnt) If anything, s/path/dentry/, since vfsmnt here will be equal to &mnt->mnt all along. > +{ > + struct dentry *dentry = path->dentry; > + struct vfsmount *vfsmnt = path->mnt; > + > + while (dentry != root->dentry || vfsmnt != root->mnt) { > + int error; > + struct dentry * parent; > + > + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) { > + struct mount *parent = READ_ONCE(mnt->mnt_parent); > + struct mnt_namespace *mnt_ns; > + > + /* Escaped? */ > + if (dentry != vfsmnt->mnt_root) > + return 3; > + > + /* Global root? */ > + if (mnt != parent) { > + dentry = READ_ONCE(mnt->mnt_mountpoint); > + mnt = parent; > + vfsmnt = &mnt->mnt; > + continue; > + } > + mnt_ns = READ_ONCE(mnt->mnt_ns); > + /* open-coded is_mounted() to use local mnt_ns */ > + if (!IS_ERR_OR_NULL(mnt_ns) && !is_anon_ns(mnt_ns)) > + return 1; // absolute root > + > + return 2; // detached or not attached yet > + break; ? > + } > + parent = dentry->d_parent; > + prefetch(parent); > + error = prepend_name(b, &dentry->d_name); > + if (error) > + break; return error, surely? > + dentry = parent; > + } > + return 0; > +} FWIW, if we go that way, I would make that while (dentry != root->dentry || &mnt->mnt != root->mnt) { int error; struct dentry *parent = READ_ONCE(dentry->d_parent); if (unlikely(dentry == mnt->mnt.mnt_root)) { struct mount *m = READ_ONCE(mnt->mnt_parent); /* Global root? */ if (unlikely(mnt == m) { struct mnt_namespace *mnt_ns; mnt_ns = READ_ONCE(mnt->mnt_ns); /* open-coded is_mounted() to use local mnt_ns */ if (!IS_ERR_OR_NULL(mnt_ns) && !is_anon_ns(mnt_ns)) return 1; // absolute root else return 2; // detached or not attached yet } // cross into whatever it's mounted on dentry = READ_ONCE(mnt->mnt_mountpoint); mnt = m; continue; } /* Escaped? */ if (unlikely(dentry == parent)) return 3; prefetch(parent); error = prepend_name(b, &dentry->d_name); if (error) return error; dentry = parent; } return 0;