From: Ye Bin Commit ccf370e43e08 (quota: Forbid Q_GETQUOTA and Q_GETNEXTQUOTA for frozen filesystem) forbade Q_GETQUOTA and Q_GETNEXTQUOTA on a frozen filesystem because ext4_acquire_dquot() prepares for allocating space for a new quota structure and OCFS2 needs to update the on-disk structure use count when a new cluster node loads quota information from disk. The same applies to Q_XGETQUOTA and Q_XGETNEXTQUOTA: userspace treats them as read-only commands, but if the queried dquot is not cached yet, ->get_dqblk()/->get_nextdqblk() call dqget() -> ->acquire_dquot(), which may write to the filesystem. Until now this only made ext4 warn about starting a transaction on a frozen filesystem. Now that ext4_acquire_dquot() also takes sb_start_intwrite() to protect against freezing, it turns into a deadlock: the query holds s_umount for reading and blocks on the SB_FREEZE_FS freeze protection, which thaw_super() can only release after taking s_umount exclusively. So forbid Q_XGETQUOTA and Q_XGETNEXTQUOTA on a frozen filesystem as well by moving them out of the read-only set in quotactl_cmd_write(), just like Q_GETQUOTA and Q_GETNEXTQUOTA. This also makes quotactl_fd() take write access for them, so a query on a read-only mount now fails with -EROFS; that is the same behavior the generic quota commands already have. If someone needs read-only querying on a frozen or read-only filesystem, proper read-only dquot lookup can be implemented separately. Suggested-by: Jan Kara Signed-off-by: Ye Bin --- fs/quota/quota.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fs/quota/quota.c b/fs/quota/quota.c index 94e6407734c7..1669bb09b9f7 100644 --- a/fs/quota/quota.c +++ b/fs/quota/quota.c @@ -834,9 +834,10 @@ static int do_quotactl(struct super_block *sb, int type, int cmd, qid_t id, static int quotactl_cmd_write(int cmd) { /* - * We cannot allow Q_GETQUOTA and Q_GETNEXTQUOTA without write access - * as dquot_acquire() may allocate space for new structure and OCFS2 - * needs to increment on-disk use count. + * We cannot allow Q_GETQUOTA, Q_GETNEXTQUOTA, Q_XGETQUOTA and + * Q_XGETNEXTQUOTA without write access as dquot_acquire() may allocate + * space for new structure and OCFS2 needs to increment on-disk use + * count. */ switch (cmd) { case Q_GETFMT: @@ -844,8 +845,6 @@ static int quotactl_cmd_write(int cmd) case Q_SYNC: case Q_XGETQSTAT: case Q_XGETQSTATV: - case Q_XGETQUOTA: - case Q_XGETNEXTQUOTA: case Q_XQUOTASYNC: return 0; } -- 2.34.1