linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: linux-fsdevel@vger.kernel.org
Cc: Seth Forshee <seth.forshee@digitalocean.com>,
	Christoph Hellwig <hch@lst.de>, Al Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>
Subject: [PATCH 5/7] fs: simplify check in mount_setattr_commit()
Date: Thu,  3 Feb 2022 14:14:09 +0100	[thread overview]
Message-ID: <20220203131411.3093040-6-brauner@kernel.org> (raw)
In-Reply-To: <20220203131411.3093040-1-brauner@kernel.org>

In order to determine whether we need to call mnt_unhold_writers() in
mount_setattr_commit() we currently do not just check whether
MNT_WRITE_HOLD is set but also if a read-only mount was requested.

However, checking whether MNT_WRITE_HOLD is set is enough. Setting
MNT_WRITE_HOLD requires lock_mount_hash() to be held and it must be
unset before calling unlock_mount_hash(). This guarantees that if we see
MNT_WRITE_HOLD we know that we were the ones who set it earlier. We
don't need to care about why we set it. Plus, leaving this additional
read-only check in makes the code more confusing because it implies that
MNT_WRITE_HOLD could've been set by another thread when it really can't.
Remove it and update the associated comment.

Cc: Seth Forshee <seth.forshee@digitalocean.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
 fs/namespace.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index 7e5535ed155d..ddae5c08ea8c 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -4096,13 +4096,8 @@ static void mount_setattr_commit(struct mount_kattr *kattr,
 			WRITE_ONCE(m->mnt.mnt_flags, flags);
 		}
 
-		/*
-		 * We either set MNT_READONLY above so make it visible
-		 * before ~MNT_WRITE_HOLD or we failed to recursively
-		 * apply mount options.
-		 */
-		if ((kattr->attr_set & MNT_READONLY) &&
-		    (m->mnt.mnt_flags & MNT_WRITE_HOLD))
+		/* If we had to hold writers unblock them. */
+		if (m->mnt.mnt_flags & MNT_WRITE_HOLD)
 			mnt_unhold_writers(m);
 
 		if (!err && kattr->propagation)
-- 
2.32.0


  parent reply	other threads:[~2022-02-03 13:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-03 13:14 [PATCH 0/7] mount_setattr fixes Christian Brauner
2022-02-03 13:14 ` [PATCH 1/7] tests: fix idmapped mount_setattr test Christian Brauner
2022-02-07  6:50   ` Christoph Hellwig
2022-02-03 13:14 ` [PATCH 2/7] MAINTAINERS: add entry for idmapped mounts Christian Brauner
2022-02-07  6:50   ` Christoph Hellwig
2022-02-03 13:14 ` [PATCH 3/7] fs: add kernel doc for mnt_{hold,unhold}_writers() Christian Brauner
2022-02-07  6:51   ` Christoph Hellwig
2022-02-03 13:14 ` [PATCH 4/7] fs: add mnt_allow_writers() and simplify mount_setattr_prepare() Christian Brauner
2022-02-07  6:51   ` Christoph Hellwig
2022-02-03 13:14 ` Christian Brauner [this message]
2022-02-07  6:52   ` [PATCH 5/7] fs: simplify check in mount_setattr_commit() Christoph Hellwig
2022-02-03 13:14 ` [PATCH 6/7] fs: don't open-code mnt_hold_writers() Christian Brauner
2022-02-07  6:52   ` Christoph Hellwig
2022-02-03 13:14 ` [PATCH 7/7] fs: clean up mount_setattr control flow Christian Brauner
2022-02-07  6:53   ` Christoph Hellwig

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=20220203131411.3093040-6-brauner@kernel.org \
    --to=brauner@kernel.org \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=seth.forshee@digitalocean.com \
    --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).