linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andrii@kernel.org>
To: <viro@zeniv.linux.org.uk>, <linux-fsdevel@vger.kernel.org>
Cc: <torvalds@linux-foundation.org>, <kernel-team@fb.com>,
	<linux-kernel@vger.kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>
Subject: [PATCH] fs: clean up is_mounted() check with extra helper
Date: Wed, 14 Oct 2020 18:37:39 -0700	[thread overview]
Message-ID: <20201015013739.1969680-1-andrii@kernel.org> (raw)

Add is_real_ns() helper validating that mount namespace is a valid one.
Use that from is_mounted() and clean up prepare_path() that open-coded similar
check.

Suggested-by: Alexander Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
---
 fs/d_path.c | 3 +--
 fs/mount.h  | 9 +++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/fs/d_path.c b/fs/d_path.c
index a69e2cd36e6e..300bf675f097 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -119,8 +119,7 @@ static int prepend_path(const struct path *path,
 				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))
+			if (is_real_ns(mnt_ns) && !is_anon_ns(mnt_ns))
 				error = 1;	// absolute root
 			else
 				error = 2;	// detached or not attached yet
diff --git a/fs/mount.h b/fs/mount.h
index c7abb7b394d8..0b0eb18ba80a 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -92,10 +92,15 @@ static inline int mnt_has_parent(struct mount *mnt)
 	return mnt != mnt->mnt_parent;
 }
 
-static inline int is_mounted(struct vfsmount *mnt)
+static inline bool is_real_ns(const struct mnt_namespace *mnt_ns)
 {
 	/* neither detached nor internal? */
-	return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
+	return mnt_ns && mnt_ns != MNT_NS_INTERNAL;
+}
+
+static inline int is_mounted(struct vfsmount *mnt)
+{
+	return is_real_ns(real_mount(mnt)->mnt_ns);
 }
 
 extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
-- 
2.24.1


                 reply	other threads:[~2020-10-15  1:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201015013739.1969680-1-andrii@kernel.org \
    --to=andrii@kernel.org \
    --cc=kernel-team@fb.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).