Skip to content

Commit 4c6bb69

Browse files
committed
quota: Fix quota corruption with generic/232 test
Eric has reported that since commit d2faa41 "quota: Do not acquire dqio_sem for dquot overwrites in v2 format" test generic/232 occasionally fails due to quota information being incorrect. Indeed that commit was too eager to remove dqio_sem completely from the path that just overwrites quota structure with updated information. Although that is innocent on its own, another process that inserts new quota structure to the same block can perform read-modify-write cycle of that block thus effectively discarding quota information update if they race in a wrong way. Fix the problem by acquiring dqio_sem for reading for overwrites of quota structure. Note that it *is* possible to completely avoid taking dqio_sem in the overwrite path however that will require modifying path inserting / deleting quota structures to avoid RMW cycles of the full block and for now it is not clear whether it is worth the hassle. Fixes: d2faa41 Reported-and-tested-by: Eric Whitney <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 0ab0b27 commit 4c6bb69

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

fs/quota/quota_v2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,16 @@ static int v2_write_dquot(struct dquot *dquot)
328328
if (!dquot->dq_off) {
329329
alloc = true;
330330
down_write(&dqopt->dqio_sem);
331+
} else {
332+
down_read(&dqopt->dqio_sem);
331333
}
332334
ret = qtree_write_dquot(
333335
sb_dqinfo(dquot->dq_sb, dquot->dq_id.type)->dqi_priv,
334336
dquot);
335337
if (alloc)
336338
up_write(&dqopt->dqio_sem);
339+
else
340+
up_read(&dqopt->dqio_sem);
337341
return ret;
338342
}
339343

0 commit comments

Comments
 (0)