Skip to content

Commit 9f09020

Browse files
committed
xfs: Do not allow norecovery mount with quotacheck
Mounting a filesystem that requires quota state changing will generate a transaction. We already check for a read-only device; we should do that for norecovery too. A quotacheck on a norecovery mount, and with the right log size, will cause the mount process to hang on: [<0>] xlog_grant_head_wait+0x5d/0x2a0 [xfs] [<0>] xlog_grant_head_check+0x112/0x180 [xfs] [<0>] xfs_log_reserve+0xe3/0x260 [xfs] [<0>] xfs_trans_reserve+0x179/0x250 [xfs] [<0>] xfs_trans_alloc+0x101/0x260 [xfs] [<0>] xfs_sync_sb+0x3f/0x80 [xfs] [<0>] xfs_qm_mount_quotas+0xe3/0x2f0 [xfs] [<0>] xfs_mountfs+0x7ad/0xc20 [xfs] [<0>] xfs_fs_fill_super+0x762/0xa50 [xfs] [<0>] get_tree_bdev_flags+0x131/0x1d0 [<0>] vfs_get_tree+0x26/0xd0 [<0>] vfs_cmd_create+0x59/0xe0 [<0>] __do_sys_fsconfig+0x4e3/0x6b0 [<0>] do_syscall_64+0x82/0x160 [<0>] entry_SYSCALL_64_after_hwframe+0x76/0x7e This is caused by a transaction running with bogus initialized head/tail I initially hit this while running generic/050, with random log sizes, but I managed to reproduce it reliably here with the steps below: mkfs.xfs -f -lsize=1025M -f -b size=4096 -m crc=1,reflink=1,rmapbt=1, -i sparse=1 /dev/vdb2 > /dev/null mount -o usrquota,grpquota,prjquota /dev/vdb2 /mnt xfs_io -x -c 'shutdown -f' /mnt umount /mnt mount -o ro,norecovery,usrquota,grpquota,prjquota /dev/vdb2 /mnt Last mount hangs up As we add yet another validation if quota state is changing, this also add a new helper named xfs_qm_validate_state_change(), factoring the quota state changes out of xfs_qm_newmount() to reduce cluttering within it. Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 9e00163 commit 9f09020

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

fs/xfs/xfs_qm_bhv.c

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@ xfs_qm_statvfs(
7878
}
7979
}
8080

81+
STATIC int
82+
xfs_qm_validate_state_change(
83+
struct xfs_mount *mp,
84+
uint uqd,
85+
uint gqd,
86+
uint pqd)
87+
{
88+
int state;
89+
90+
/* Is quota state changing? */
91+
state = ((uqd && !XFS_IS_UQUOTA_ON(mp)) ||
92+
(!uqd && XFS_IS_UQUOTA_ON(mp)) ||
93+
(gqd && !XFS_IS_GQUOTA_ON(mp)) ||
94+
(!gqd && XFS_IS_GQUOTA_ON(mp)) ||
95+
(pqd && !XFS_IS_PQUOTA_ON(mp)) ||
96+
(!pqd && XFS_IS_PQUOTA_ON(mp)));
97+
98+
return state &&
99+
(xfs_dev_is_read_only(mp, "changing quota state") ||
100+
xfs_has_norecovery(mp));
101+
}
102+
81103
int
82104
xfs_qm_newmount(
83105
xfs_mount_t *mp,
@@ -97,24 +119,25 @@ xfs_qm_newmount(
97119
}
98120

99121
/*
100-
* If the device itself is read-only, we can't allow
101-
* the user to change the state of quota on the mount -
102-
* this would generate a transaction on the ro device,
103-
* which would lead to an I/O error and shutdown
122+
* If the device itself is read-only and/or in norecovery
123+
* mode, we can't allow the user to change the state of
124+
* quota on the mount - this would generate a transaction
125+
* on the ro device, which would lead to an I/O error and
126+
* shutdown.
104127
*/
105128

106-
if (((uquotaondisk && !XFS_IS_UQUOTA_ON(mp)) ||
107-
(!uquotaondisk && XFS_IS_UQUOTA_ON(mp)) ||
108-
(gquotaondisk && !XFS_IS_GQUOTA_ON(mp)) ||
109-
(!gquotaondisk && XFS_IS_GQUOTA_ON(mp)) ||
110-
(pquotaondisk && !XFS_IS_PQUOTA_ON(mp)) ||
111-
(!pquotaondisk && XFS_IS_PQUOTA_ON(mp))) &&
112-
xfs_dev_is_read_only(mp, "changing quota state")) {
113-
xfs_warn(mp, "please mount with%s%s%s%s.",
114-
(!quotaondisk ? "out quota" : ""),
115-
(uquotaondisk ? " usrquota" : ""),
116-
(gquotaondisk ? " grpquota" : ""),
117-
(pquotaondisk ? " prjquota" : ""));
129+
if (xfs_qm_validate_state_change(mp, uquotaondisk,
130+
gquotaondisk, pquotaondisk)) {
131+
132+
if (xfs_has_metadir(mp))
133+
xfs_warn(mp,
134+
"metadir enabled, please mount without any quota mount options");
135+
else
136+
xfs_warn(mp, "please mount with%s%s%s%s.",
137+
(!quotaondisk ? "out quota" : ""),
138+
(uquotaondisk ? " usrquota" : ""),
139+
(gquotaondisk ? " grpquota" : ""),
140+
(pquotaondisk ? " prjquota" : ""));
118141
return -EPERM;
119142
}
120143

0 commit comments

Comments
 (0)