mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									e58ace1a0f
								
							
						
					
					
						commit
						fbdc2f6c40
					
				
					 1 changed files with 18 additions and 6 deletions
				
			
		| 
						 | 
					@ -470,10 +470,8 @@ void mnt_drop_write_file(struct file *file)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
EXPORT_SYMBOL(mnt_drop_write_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;
 | 
						mnt->mnt.mnt_flags |= MNT_WRITE_HOLD;
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * After storing MNT_WRITE_HOLD, we'll read the counters. This store
 | 
						 * 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.
 | 
						 * we're counting up here.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	if (mnt_get_writers(mnt) > 0)
 | 
						if (mnt_get_writers(mnt) > 0)
 | 
				
			||||||
		ret = -EBUSY;
 | 
							return -EBUSY;
 | 
				
			||||||
	else
 | 
					
 | 
				
			||||||
		mnt->mnt.mnt_flags |= MNT_READONLY;
 | 
						return 0;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static inline void mnt_unhold_writers(struct mount *mnt)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
	/*
 | 
						/*
 | 
				
			||||||
	 * MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers
 | 
						 * MNT_READONLY must become visible before ~MNT_WRITE_HOLD, so writers
 | 
				
			||||||
	 * that become unheld will see MNT_READONLY.
 | 
						 * that become unheld will see MNT_READONLY.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	smp_wmb();
 | 
						smp_wmb();
 | 
				
			||||||
	mnt->mnt.mnt_flags &= ~MNT_WRITE_HOLD;
 | 
						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;
 | 
						return ret;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue