From patchwork Tue Oct 11 05:33:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Kent X-Patchwork-Id: 9370149 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 51E5160772 for ; Tue, 11 Oct 2016 05:35:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41D4E293A7 for ; Tue, 11 Oct 2016 05:35:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3431E296B3; Tue, 11 Oct 2016 05:35:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB94A293A7 for ; Tue, 11 Oct 2016 05:35:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751752AbcJKFeD (ORCPT ); Tue, 11 Oct 2016 01:34:03 -0400 Received: from out5-smtp.messagingengine.com ([66.111.4.29]:43512 "EHLO out5-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751638AbcJKFeC (ORCPT ); Tue, 11 Oct 2016 01:34:02 -0400 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 0C8782076C; Tue, 11 Oct 2016 01:34:01 -0400 (EDT) Received: from frontend1 ([10.202.2.160]) by compute7.internal (MEProxy); Tue, 11 Oct 2016 01:34:01 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=themaw.net; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=Vvl0KD7IiHe3FsE343LhScnULjo=; b=j2x95Q VO81oiZEojAN6tG8ywF5FCo+eGOB58z63zizr5zelEq8F2ER7m41iI3o7xXMRWz5 9X31ErrstgVfuSKdurZCgT/tlHtxF6+DRhBiCjJ338F52pz3AX8biwnWvefJZ1se OXMOPjDwwjBURc+XT/VH8Ve0MGODGFPm4PBQ4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=Vvl0KD7IiHe3FsE 343LhScnULjo=; b=uADOy/r2qkR2F05KK1touHWLcCGO+oZ36Cf14U29N6/QB+a vD52aUJzfPLcn9+c/3WhIKdMBOgcvB0facJhPjmbul+AMtI0dDHZVuVNmw8xCv/A kewYCIGGf+jf5Ca7XlwxIf4y7PyekpXe7vXRs5nW2FCHj7gXFg+0T4EZp4ps= X-Sasl-enc: ePJpUUMx23CUHwUNa5fYrrGeoStGSobs5z7ESoI9iJ0K 1476164040 Received: from pluto.themaw.net (203-59-161-156.dyn.iinet.net.au [203.59.161.156]) by mail.messagingengine.com (Postfix) with ESMTPA id 617A6F2985; Tue, 11 Oct 2016 01:34:00 -0400 (EDT) Received: from pluto.themaw.net (localhost [127.0.0.1]) by pluto.themaw.net (Postfix) with ESMTP id 194EBA008A; Tue, 11 Oct 2016 13:33:58 +0800 (AWST) Subject: [PATCH 2/8] vfs - add path_is_mountpoint() helper From: Ian Kent To: Andrew Morton Cc: autofs mailing list , Kernel Mailing List , "Eric W. Biederman" , linux-fsdevel , Omar Sandoval , Al Viro Date: Tue, 11 Oct 2016 13:33:58 +0800 Message-ID: <20161011053358.27645.9729.stgit@pluto.themaw.net> In-Reply-To: <20161011053352.27645.83962.stgit@pluto.themaw.net> References: <20161011053352.27645.83962.stgit@pluto.themaw.net> 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-Virus-Scanned: ClamAV using ClamSMTP From: Ian Kent d_mountpoint() can only be used reliably to establish if a dentry is not mounted in any namespace. It isn't aware of the possibility there may be multiple mounts using a given dentry that may be in a different namespace. Add helper functions, path_is_mountpoint() and an rcu version , that checks if a struct path is a mountpoint for this case. Signed-off-by: Ian Kent Cc: Al Viro Cc: Eric W. Biederman Cc: Omar Sandoval --- fs/namespace.c | 43 +++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 45 insertions(+) -- 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/namespace.c b/fs/namespace.c index ff1cd14..5ef9618 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1160,6 +1160,49 @@ struct vfsmount *mntget(struct vfsmount *mnt) } EXPORT_SYMBOL(mntget); +static bool __path_is_mountpoint(struct path *path) +{ + struct mount *mount; + struct vfsmount *mnt; + unsigned seq; + + do { + seq = read_seqbegin(&mount_lock); + mount = __lookup_mnt(path->mnt, path->dentry); + mnt = mount ? &mount->mnt : NULL; + } while (mnt && + !(mnt->mnt_flags & MNT_SYNC_UMOUNT) && + read_seqretry(&mount_lock, seq)); + + return mnt != NULL; +} + +/* Check if path is a mount in current namespace */ +bool path_is_mountpoint(struct path *path) +{ + bool res; + + if (!d_mountpoint(path->dentry)) + return 0; + + rcu_read_lock(); + res = __path_is_mountpoint(path); + rcu_read_unlock(); + + return res; +} +EXPORT_SYMBOL(path_is_mountpoint); + +/* Check if path is a mount in current namespace */ +bool path_is_mountpoint_rcu(struct path *path) +{ + if (!d_mountpoint(path->dentry)) + return 0; + + return __path_is_mountpoint(path); +} +EXPORT_SYMBOL(path_is_mountpoint_rcu); + struct vfsmount *mnt_clone_internal(struct path *path) { struct mount *p; diff --git a/include/linux/fs.h b/include/linux/fs.h index 09a8c41..deaf08b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2142,6 +2142,8 @@ extern int vfs_ustat(dev_t, struct kstatfs *); extern int freeze_super(struct super_block *super); extern int thaw_super(struct super_block *super); extern bool our_mnt(struct vfsmount *mnt); +extern bool path_is_mountpoint(struct path *); +extern bool path_is_mountpoint_rcu(struct path *); extern int current_umask(void);