From patchwork Mon Mar 23 02:37:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 6068871 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D61269F2A9 for ; Mon, 23 Mar 2015 02:41:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 109FD20219 for ; Mon, 23 Mar 2015 02:41:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 22A8E201FE for ; Mon, 23 Mar 2015 02:41:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752508AbbCWCjd (ORCPT ); Sun, 22 Mar 2015 22:39:33 -0400 Received: from cantor2.suse.de ([195.135.220.15]:34529 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752053AbbCWCj3 (ORCPT ); Sun, 22 Mar 2015 22:39:29 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id C1631ACFC; Mon, 23 Mar 2015 02:39:27 +0000 (UTC) From: NeilBrown To: Al Viro Date: Mon, 23 Mar 2015 13:37:40 +1100 Subject: [PATCH 15/20] VFS/namei: enhance follow_link to support RCU-walk. Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <20150323023740.8161.13594.stgit@notabene.brown> In-Reply-To: <20150323023258.8161.32467.stgit@notabene.brown> References: <20150323023258.8161.32467.stgit@notabene.brown> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If LOOKUP_RCU is set, follow_link will not take/drop reference counts. Replace cond_resched() with _cond_resched() as the latter is a no-op if rcu_read_lock() is held while the former will give a warning in that case. After taking a copy of dentry->d_inode, check d_seq to ensure this is still the symlink we were looking for. Signed-off-by: NeilBrown --- fs/namei.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/namei.c b/fs/namei.c index 72f5a4f91855..40ff4cb04244 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -897,16 +897,21 @@ follow_link(struct path *link, struct nameidata *nd, void **p) char *s; nd->flags &= ~LOOKUP_LINK_RCU; - if (nd->flags & LOOKUP_RCU) + if (nd->flags & LOOKUP_RCU) { nd->flags |= LOOKUP_LINK_RCU; - else if (link->mnt == nd->path.mnt) + if (__read_seqcount_retry(&dentry->d_seq, nd->seq)) { + error = -ECHILD; + goto out_put_nd_path; + } + } else if (link->mnt == nd->path.mnt) mntget(link->mnt); error = -ELOOP; if (unlikely(nd->total_link_count >= 40)) goto out_put_nd_path; - cond_resched(); + /* If rcu_read_locked(), this will not resched, and will not warn */ + _cond_resched(); nd->total_link_count++; if (nd->flags & LOOKUP_RCU) { @@ -938,11 +943,17 @@ follow_link(struct path *link, struct nameidata *nd, void **p) return PTR_ERR(s); } if (*s == '/') { - if (!nd->root.mnt) - set_root(nd); - path_put(&nd->path); - nd->path = nd->root; - path_get(&nd->root); + if (nd->flags & LOOKUP_RCU) { + if (!nd->root.mnt) + set_root_rcu(nd); + nd->path = nd->root; + } else { + if (!nd->root.mnt) + set_root(nd); + path_put(&nd->path); + nd->path = nd->root; + path_get(&nd->root); + } nd->flags |= LOOKUP_JUMPED; } nd->inode = nd->path.dentry->d_inode;