quota locking question
According to dquot.c locking rules: dq_data_lock guards consistency of dquot->dq_dqb with inode->i_blocks, i_bytes.
It is no clear to me what is the reason. Why do we need it ? What use-case causes this requirement?
Jan Kara
reviewerHi,
Quoted 2 lines · Dmitry Monakhov
According to
dquot.clocking rules:dq_data_lockguards consistency ofdquot->dq_dqbwithinode->i_blocks,i_bytes.
Yes.
Quoted 2 lines
It is no clear to me what is the reason. Why do we need it ? What use-case causes this requirement?
The clearliest reason is for example so that we are sure that dquot does
not change between we check limits and we update usage (generally that dquot isn't updated concurrently by two processes).
The consistency between amount of space consumed by inode (as accounted
in i_blocks + i_bytes) and space consumed by user accounted in dquot is another aspect. Currently, dqptr_sem assures that dquot_transfer() cannot run in parallel to dquot_alloc_space() (and similar functions) and AFAICS dquot_transfer() is the only function that relies on this consistency. But this is mostly a side-effect of the way we do reference counting on dquots and thus I feel it's better to have this consistency defined to be guarded by dq_data_lock.
Honza
PS: Other locks (especially i_mutex) make some of the above races impossible but quota code is written so that it's independent of filesystem's locking...
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR