summaryrefslogtreecommitdiffstats
path: root/fs/namespace.c
diff options
context:
space:
mode:
authorChristian Brauner <brauner@kernel.org>2022-02-03 14:14:08 +0100
committerChristian Brauner <brauner@kernel.org>2022-02-14 08:37:39 +0100
commita26f788b6e7a10d193c4cc6889818e4d625e9461 (patch)
treec4fbe3e3f699fdbe95d2bba6a93ce775c58c15b5 /fs/namespace.c
parent538f4f022a4612f969d5324ee227403c9f8b1d72 (diff)
downloadlinux-a26f788b6e7a10d193c4cc6889818e4d625e9461.tar.bz2
fs: add mnt_allow_writers() and simplify mount_setattr_prepare()
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. Link: https://lore.kernel.org/r/20220203131411.3093040-5-brauner@kernel.org 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 Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r--fs/namespace.c28
1 files 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: