author: Christian Brauner <christian.brauner@ubuntu.com> 2021-01-21 14:19:51 +0100
committer: Christian Brauner <christian.brauner@ubuntu.com> 2021-01-24 14:29:34 +0100
commit: fbdc2f6c40f6528fa0db79c73e844451234f3e26
parent: e58ace1a0fa9d578f85f556b4b88c5fe9b871d08
Commit Summary:
Diffstat:
1 file changed, 14 insertions, 6 deletions
diff --git a/fs/namespace.c b/fs/namespace.c
index 367f1c7cb6db..774ae5f74716 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -470,10 +470,8 @@ void mnt_drop_write_file(struct file *file)
}
EXPORT_SYMBOL(mnt_drop_write_file);
-static int mnt_make_readonly(struct mount *mnt)
+static inline int mnt_hold_writers(struct mount *mnt)
{
- int ret = 0;
-
mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
/*
* After storing MNT_WRITE_HOLD, we'll read the counters. This store
@@ -498,15 +496,29 @@ static int mnt_make_readonly(struct mount *mnt)
* we're counting up here.
*/
if (mnt_get_writers(mnt) > 0)
- ret = -EBUSY;
- else
- mnt->mnt.mnt_flags |= MNT_READONLY;
+ return -EBUSY;
+
+ return 0;
+}
+
+static inline void mnt_unhold_writers(struct mount *mnt)
+{
/*
* MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers
* that become unheld will see MNT_READONLY.
*/
smp_wmb();
mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
+}
+
+static int mnt_make_readonly(struct mount *mnt)
+{
+ int ret;
+
+ ret = mnt_hold_writers(mnt);
+ if (!ret)
+ mnt->mnt.mnt_flags |= MNT_READONLY;
+ mnt_unhold_writers(mnt);
return ret;
}