Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1127714ybl; Sat, 18 Jan 2020 19:27:40 -0800 (PST) X-Google-Smtp-Source: APXvYqyrQSZwSdU8dO9LfRV3ctZC1+S6T+wTJmLDJkeootrEPuzexgTfQOg01a/RmHZVn6j+slaR X-Received: by 2002:a9d:674f:: with SMTP id w15mr11780591otm.243.1579404460704; Sat, 18 Jan 2020 19:27:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579404460; cv=none; d=google.com; s=arc-20160816; b=AeiYS/rkMV4HldygiJN4/y0ZdTxQ6IGPQ5a1AztiDZTwiIr4HZtJaUKd9wvg4xziKu fFjqbsmEjdI3V7MB2UchE9YjuiefwRBNeCYKz2hdqzgcg1EfIGRS9ulOdb079cQrsgC0 myCvoN80yLTUPyd4NoZIj0WRVqtXfWBUz7+qf4FJJCuNkd1ZoqbMfNjeLLE/4DKIrc3W E9t7gZS5yIh7DOl86wk/kUDhqgCenGTuWK1n8Fi+ohbNifPitNamixTBEBEwEgSSuPwO 45PmLY5VWidi7LHyAOOLXsndn31xDa7wMSjAXzL7xFfarJo8MFd6TpKQMgruMaCp3L8h 5tsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=3apK/Jir+/rP0sqsCy0Jhu/522Y7zsISNCHa61hLxZ4=; b=OhkQcs86VHlbKDJQSiF41FxGrJygy9+tTEw0vV+7FK1tXJoiocSrwZc+XbcLrAjzM6 EvcVXrQxOEHW+ucDcYhNZxr+iRkUj1kxhVYslxl2OmcK4RsGxiYIumNpqR21RKoOzoIL ayBuyhEY2vGXOx5jmLYeI83MrK/OBwfU4HF6o1ZmOIY4qVcxU9zQcHi3jjmC0rYgF6cd zyobmtUCB3Pv5GzQvsplqD+xJQE1Wk+WKihF7ySbOKm0vxW77e9P2X7ji/XqDxWzQnMR /s+c1LfMArF2vqooKSHuG8dkyKyjWcAtQeSdWrvP4hgTIa+CGH2ek/lY/9/pM9ECBJ/K b/qA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si6175862otc.272.2020.01.18.19.27.28; Sat, 18 Jan 2020 19:27:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726999AbgASD0S (ORCPT + 99 others); Sat, 18 Jan 2020 22:26:18 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:57032 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725497AbgASD0R (ORCPT ); Sat, 18 Jan 2020 22:26:17 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1it1Dg-00BFmW-4K; Sun, 19 Jan 2020 03:25:51 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Aleksa Sarai , David Howells , Eric Biederman , Christian Brauner , Al Viro Subject: [PATCH 8/9] massage __follow_mount_rcu() a bit Date: Sun, 19 Jan 2020 03:17:37 +0000 Message-Id: <20200119031738.2681033-25-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200119031738.2681033-1-viro@ZenIV.linux.org.uk> References: <20200119031423.GV8904@ZenIV.linux.org.uk> <20200119031738.2681033-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro make the loop more similar to that in follow_managed(), with explicit tracking of flags, etc. Signed-off-by: Al Viro --- fs/namei.c | 70 +++++++++++++++++++++++++++--------------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 40263f89a54f..310c5ccddf42 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -1268,12 +1268,6 @@ int follow_down_one(struct path *path) } EXPORT_SYMBOL(follow_down_one); -static inline int managed_dentry_rcu(const struct path *path) -{ - return (path->dentry->d_flags & DCACHE_MANAGE_TRANSIT) ? - path->dentry->d_op->d_manage(path, true) : 0; -} - /* * Try to skip to top of mountpoint pile in rcuwalk mode. Fail if * we meet a managed dentry that would need blocking. @@ -1281,43 +1275,49 @@ static inline int managed_dentry_rcu(const struct path *path) static bool __follow_mount_rcu(struct nameidata *nd, struct path *path, struct inode **inode, unsigned *seqp) { + struct dentry *dentry = path->dentry; + unsigned int flags = dentry->d_flags; + + if (likely(!(flags & DCACHE_MANAGED_DENTRY))) + return true; + + if (unlikely(nd->flags & LOOKUP_NO_XDEV)) + return false; + for (;;) { - struct mount *mounted; /* * Don't forget we might have a non-mountpoint managed dentry * that wants to block transit. */ - switch (managed_dentry_rcu(path)) { - case -ECHILD: - default: - return false; - case -EISDIR: - return true; - case 0: - break; + if (unlikely(flags & DCACHE_MANAGE_TRANSIT)) { + int res = dentry->d_op->d_manage(path, true); + if (res) + return res == -EISDIR; + flags = dentry->d_flags; } - if (!d_mountpoint(path->dentry)) - return !(path->dentry->d_flags & DCACHE_NEED_AUTOMOUNT); - - mounted = __lookup_mnt(path->mnt, path->dentry); - if (!mounted) - break; - if (unlikely(nd->flags & LOOKUP_NO_XDEV)) - return false; - path->mnt = &mounted->mnt; - path->dentry = mounted->mnt.mnt_root; - nd->flags |= LOOKUP_JUMPED; - *seqp = read_seqcount_begin(&path->dentry->d_seq); - /* - * Update the inode too. We don't need to re-check the - * dentry sequence number here after this d_inode read, - * because a mount-point is always pinned. - */ - *inode = path->dentry->d_inode; + if (flags & DCACHE_MOUNTED) { + struct mount *mounted = __lookup_mnt(path->mnt, dentry); + if (mounted) { + path->mnt = &mounted->mnt; + dentry = path->dentry = mounted->mnt.mnt_root; + nd->flags |= LOOKUP_JUMPED; + *seqp = read_seqcount_begin(&dentry->d_seq); + *inode = dentry->d_inode; + /* + * We don't need to re-check ->d_seq after this + * ->d_inode read - there will be an RCU delay + * between mount hash removal and ->mnt_root + * becoming unpinned. + */ + flags = dentry->d_flags; + continue; + } + if (read_seqretry(&mount_lock, nd->m_seq)) + return false; + } + return !(flags & DCACHE_NEED_AUTOMOUNT); } - return !read_seqretry(&mount_lock, nd->m_seq) && - !(path->dentry->d_flags & DCACHE_NEED_AUTOMOUNT); } static inline int handle_mounts(struct nameidata *nd, struct dentry *dentry, -- 2.20.1