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 4/7] fs: add mnt_allow_writers() and simplify mount_setattr_prepare()
Date: Thu, 3 Feb 2022 14:14:08 +0100 [thread overview]
Message-ID: <20220203131411.3093040-5-brauner@kernel.org> (raw)
In-Reply-To: <20220203131411.3093040-1-brauner@kernel.org>
Add a tiny helper that lets us simplify the control-flow and can be used
in the next patch to avoid adding another condition open-coded into
mount_setattr_prepare(). Instead we can add it into the new helper.
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 | 28 ++++++++++++++++++++++------
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index de6fae84f1a1..7e5535ed155d 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3998,6 +3998,22 @@ static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt)
return 0;
}
+/**
+ * mnt_allow_writers() - check whether the attribute change allows writers
+ * @kattr: the new mount attributes
+ * @mnt: the mount to which @kattr will be applied
+ *
+ * Check whether thew new mount attributes in @kattr allow concurrent writers.
+ *
+ * Return: true if writers need to be held, false if not
+ */
+static inline bool mnt_allow_writers(const struct mount_kattr *kattr,
+ const struct mount *mnt)
+{
+ return !(kattr->attr_set & MNT_READONLY) ||
+ (mnt->mnt.mnt_flags & MNT_READONLY);
+}
+
static struct mount *mount_setattr_prepare(struct mount_kattr *kattr,
struct mount *mnt, int *err)
{
@@ -4028,12 +4044,12 @@ static struct mount *mount_setattr_prepare(struct mount_kattr *kattr,
last = m;
- if ((kattr->attr_set & MNT_READONLY) &&
- !(m->mnt.mnt_flags & MNT_READONLY)) {
- *err = mnt_hold_writers(m);
- if (*err)
- goto out;
- }
+ if (mnt_allow_writers(kattr, m))
+ continue;
+
+ *err = mnt_hold_writers(m);
+ if (*err)
+ goto out;
} while (kattr->recurse && (m = next_mnt(m, mnt)));
out:
--
2.32.0
next prev 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 ` Christian Brauner [this message]
2022-02-07 6:51 ` [PATCH 4/7] fs: add mnt_allow_writers() and simplify mount_setattr_prepare() Christoph Hellwig
2022-02-03 13:14 ` [PATCH 5/7] fs: simplify check in mount_setattr_commit() Christian Brauner
2022-02-07 6:52 ` 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-5-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).