@@ -6780,22 +6780,29 @@ static int ext4_statfs_project(struct super_block *sb,
67806780 dquot -> dq_dqb .dqb_bhardlimit );
67816781 limit >>= sb -> s_blocksize_bits ;
67826782
6783- if (limit && buf -> f_blocks > limit ) {
6783+ if (limit ) {
6784+ uint64_t remaining = 0 ;
6785+
67846786 curblock = (dquot -> dq_dqb .dqb_curspace +
67856787 dquot -> dq_dqb .dqb_rsvspace ) >> sb -> s_blocksize_bits ;
6786- buf -> f_blocks = limit ;
6787- buf -> f_bfree = buf -> f_bavail =
6788- (buf -> f_blocks > curblock ) ?
6789- (buf -> f_blocks - curblock ) : 0 ;
6788+ if (limit > curblock )
6789+ remaining = limit - curblock ;
6790+
6791+ buf -> f_blocks = min (buf -> f_blocks , limit );
6792+ buf -> f_bfree = min (buf -> f_bfree , remaining );
6793+ buf -> f_bavail = min (buf -> f_bavail , remaining );
67906794 }
67916795
67926796 limit = min_not_zero (dquot -> dq_dqb .dqb_isoftlimit ,
67936797 dquot -> dq_dqb .dqb_ihardlimit );
6794- if (limit && buf -> f_files > limit ) {
6795- buf -> f_files = limit ;
6796- buf -> f_ffree =
6797- (buf -> f_files > dquot -> dq_dqb .dqb_curinodes ) ?
6798- (buf -> f_files - dquot -> dq_dqb .dqb_curinodes ) : 0 ;
6798+ if (limit ) {
6799+ uint64_t remaining = 0 ;
6800+
6801+ if (limit > dquot -> dq_dqb .dqb_curinodes )
6802+ remaining = limit - dquot -> dq_dqb .dqb_curinodes ;
6803+
6804+ buf -> f_files = min (buf -> f_files , limit );
6805+ buf -> f_ffree = min (buf -> f_ffree , remaining );
67996806 }
68006807
68016808 spin_unlock (& dquot -> dq_dqb_lock );
0 commit comments