quota: Hold s_umount in exclusive mode when enabling / disabling quotas
Currently we hold s_umount semaphore only in shared mode when enabling or disabling quotas and use dqonoff_mutex for serializing quota state changes on a filesystem and also quota state changes with other places depending on current quota state. Using dedicated mutex for this causes possible deadlocks during filesystem freezing (see following commit for details) so we transition to using s_umount semaphore for the necessary synchronization whose lock ordering is properly handled by the filesystem freezing code. As a start grab s_umount in exclusive mode when enabling / disabling quotas. Signed-off-by: Jan Kara <jack@suse.cz>
This commit is contained in:
parent
ba6379f7e6
commit
7d6cd73d33
|
@ -2107,6 +2107,10 @@ int dquot_disable(struct super_block *sb, int type, unsigned int flags)
|
||||||
struct quota_info *dqopt = sb_dqopt(sb);
|
struct quota_info *dqopt = sb_dqopt(sb);
|
||||||
struct inode *toputinode[MAXQUOTAS];
|
struct inode *toputinode[MAXQUOTAS];
|
||||||
|
|
||||||
|
/* s_umount should be held in exclusive mode */
|
||||||
|
if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount)))
|
||||||
|
up_read(&sb->s_umount);
|
||||||
|
|
||||||
/* Cannot turn off usage accounting without turning off limits, or
|
/* Cannot turn off usage accounting without turning off limits, or
|
||||||
* suspend quotas and simultaneously turn quotas off. */
|
* suspend quotas and simultaneously turn quotas off. */
|
||||||
if ((flags & DQUOT_USAGE_ENABLED && !(flags & DQUOT_LIMITS_ENABLED))
|
if ((flags & DQUOT_USAGE_ENABLED && !(flags & DQUOT_LIMITS_ENABLED))
|
||||||
|
@ -2371,6 +2375,10 @@ int dquot_resume(struct super_block *sb, int type)
|
||||||
int ret = 0, cnt;
|
int ret = 0, cnt;
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
|
||||||
|
/* s_umount should be held in exclusive mode */
|
||||||
|
if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount)))
|
||||||
|
up_read(&sb->s_umount);
|
||||||
|
|
||||||
for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
|
for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
|
||||||
if (type != -1 && cnt != type)
|
if (type != -1 && cnt != type)
|
||||||
continue;
|
continue;
|
||||||
|
@ -2430,6 +2438,9 @@ int dquot_enable(struct inode *inode, int type, int format_id,
|
||||||
|
|
||||||
/* Just unsuspend quotas? */
|
/* Just unsuspend quotas? */
|
||||||
BUG_ON(flags & DQUOT_SUSPENDED);
|
BUG_ON(flags & DQUOT_SUSPENDED);
|
||||||
|
/* s_umount should be held in exclusive mode */
|
||||||
|
if (WARN_ON_ONCE(down_read_trylock(&sb->s_umount)))
|
||||||
|
up_read(&sb->s_umount);
|
||||||
|
|
||||||
if (!flags)
|
if (!flags)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -789,9 +789,14 @@ static int quotactl_cmd_write(int cmd)
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* CONFIG_BLOCK */
|
#endif /* CONFIG_BLOCK */
|
||||||
|
|
||||||
|
/* Return true if quotactl command is manipulating quota on/off state */
|
||||||
|
static bool quotactl_cmd_onoff(int cmd)
|
||||||
|
{
|
||||||
|
return (cmd == Q_QUOTAON) || (cmd == Q_QUOTAOFF);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* look up a superblock on which quota ops will be performed
|
* look up a superblock on which quota ops will be performed
|
||||||
* - use the name of a block device to find the superblock thereon
|
* - use the name of a block device to find the superblock thereon
|
||||||
|
@ -809,7 +814,9 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)
|
||||||
putname(tmp);
|
putname(tmp);
|
||||||
if (IS_ERR(bdev))
|
if (IS_ERR(bdev))
|
||||||
return ERR_CAST(bdev);
|
return ERR_CAST(bdev);
|
||||||
if (quotactl_cmd_write(cmd))
|
if (quotactl_cmd_onoff(cmd))
|
||||||
|
sb = get_super_exclusive_thawed(bdev);
|
||||||
|
else if (quotactl_cmd_write(cmd))
|
||||||
sb = get_super_thawed(bdev);
|
sb = get_super_thawed(bdev);
|
||||||
else
|
else
|
||||||
sb = get_super(bdev);
|
sb = get_super(bdev);
|
||||||
|
@ -872,7 +879,10 @@ SYSCALL_DEFINE4(quotactl, unsigned int, cmd, const char __user *, special,
|
||||||
|
|
||||||
ret = do_quotactl(sb, type, cmds, id, addr, pathp);
|
ret = do_quotactl(sb, type, cmds, id, addr, pathp);
|
||||||
|
|
||||||
drop_super(sb);
|
if (!quotactl_cmd_onoff(cmds))
|
||||||
|
drop_super(sb);
|
||||||
|
else
|
||||||
|
drop_super_exclusive(sb);
|
||||||
out:
|
out:
|
||||||
if (pathp && !IS_ERR(pathp))
|
if (pathp && !IS_ERR(pathp))
|
||||||
path_put(pathp);
|
path_put(pathp);
|
||||||
|
|
Loading…
Reference in New Issue