Skip to content

Commit fbdc2f6

Browse files
author
Christian Brauner
committed
fs: split out functions to hold writers
When a mount is marked read-only we set MNT_WRITE_HOLD on it if there aren't currently any active writers. Split this logic out into simple helpers that we can use in follow-up patches. Link: https://lore.kernel.org/r/20210121131959.646623-33-christian.brauner@ubuntu.com Cc: David Howells <dhowells@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: linux-fsdevel@vger.kernel.org Suggested-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
1 parent e58ace1 commit fbdc2f6

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

fs/namespace.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,8 @@ void mnt_drop_write_file(struct file *file)
470470
}
471471
EXPORT_SYMBOL(mnt_drop_write_file);
472472

473-
static int mnt_make_readonly(struct mount *mnt)
473+
static inline int mnt_hold_writers(struct mount *mnt)
474474
{
475-
int ret = 0;
476-
477475
mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
478476
/*
479477
* After storing MNT_WRITE_HOLD, we'll read the counters. This store
@@ -498,15 +496,29 @@ static int mnt_make_readonly(struct mount *mnt)
498496
* we're counting up here.
499497
*/
500498
if (mnt_get_writers(mnt) > 0)
501-
ret = -EBUSY;
502-
else
503-
mnt->mnt.mnt_flags |= MNT_READONLY;
499+
return -EBUSY;
500+
501+
return 0;
502+
}
503+
504+
static inline void mnt_unhold_writers(struct mount *mnt)
505+
{
504506
/*
505507
* MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers
506508
* that become unheld will see MNT_READONLY.
507509
*/
508510
smp_wmb();
509511
mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
512+
}
513+
514+
static int mnt_make_readonly(struct mount *mnt)
515+
{
516+
int ret;
517+
518+
ret = mnt_hold_writers(mnt);
519+
if (!ret)
520+
mnt->mnt.mnt_flags |= MNT_READONLY;
521+
mnt_unhold_writers(mnt);
510522
return ret;
511523
}
512524

0 commit comments

Comments
 (0)