@@ -1351,8 +1351,8 @@ xfs_qm_dqusage_adjust(
13511351 void * data )
13521352{
13531353 struct xfs_inode * ip ;
1354- xfs_qcnt_t nblks ;
1355- xfs_filblks_t rtblks = 0 ; /* total rt blks */
1354+ xfs_filblks_t nblks , rtblks ;
1355+ unsigned int lock_mode ;
13561356 int error ;
13571357
13581358 ASSERT (XFS_IS_QUOTA_ON (mp ));
@@ -1393,18 +1393,17 @@ xfs_qm_dqusage_adjust(
13931393
13941394 ASSERT (ip -> i_delayed_blks == 0 );
13951395
1396+ lock_mode = xfs_ilock_data_map_shared (ip );
13961397 if (XFS_IS_REALTIME_INODE (ip )) {
1397- struct xfs_ifork * ifp = xfs_ifork_ptr (ip , XFS_DATA_FORK );
1398-
13991398 error = xfs_iread_extents (tp , ip , XFS_DATA_FORK );
1400- if (error )
1399+ if (error ) {
1400+ xfs_iunlock (ip , lock_mode );
14011401 goto error0 ;
1402-
1403- xfs_bmap_count_leaves (ifp , & rtblks );
1402+ }
14041403 }
1405-
1406- nblks = (xfs_qcnt_t )ip -> i_nblocks - rtblks ;
1404+ xfs_inode_count_blocks (tp , ip , & nblks , & rtblks );
14071405 xfs_iflags_clear (ip , XFS_IQUOTAUNCHECKED );
1406+ xfs_iunlock (ip , lock_mode );
14081407
14091408 /*
14101409 * Add the (disk blocks and inode) resources occupied by this
@@ -1664,10 +1663,11 @@ xfs_qm_mount_quotas(
16641663 uint sbf ;
16651664
16661665 /*
1667- * If quotas on realtime volumes is not supported, we disable
1668- * quotas immediately.
1666+ * If quotas on realtime volumes is not supported, disable quotas
1667+ * immediately. We only support rtquota if rtgroups are enabled to
1668+ * avoid problems with older kernels.
16691669 */
1670- if (mp -> m_sb .sb_rextents ) {
1670+ if (mp -> m_sb .sb_rextents && ! xfs_has_rtgroups ( mp ) ) {
16711671 xfs_notice (mp , "Cannot turn on quotas for realtime filesystem" );
16721672 mp -> m_qflags = 0 ;
16731673 goto write_changes ;
@@ -2043,9 +2043,8 @@ xfs_qm_vop_chown(
20432043 struct xfs_dquot * newdq )
20442044{
20452045 struct xfs_dquot * prevdq ;
2046- uint bfield = XFS_IS_REALTIME_INODE (ip ) ?
2047- XFS_TRANS_DQ_RTBCOUNT : XFS_TRANS_DQ_BCOUNT ;
2048-
2046+ xfs_filblks_t dblocks , rblocks ;
2047+ bool isrt = XFS_IS_REALTIME_INODE (ip );
20492048
20502049 xfs_assert_ilocked (ip , XFS_ILOCK_EXCL );
20512050 ASSERT (XFS_IS_QUOTA_ON (ip -> i_mount ));
@@ -2056,11 +2055,17 @@ xfs_qm_vop_chown(
20562055 ASSERT (prevdq );
20572056 ASSERT (prevdq != newdq );
20582057
2059- xfs_trans_mod_ino_dquot (tp , ip , prevdq , bfield , - (ip -> i_nblocks ));
2058+ xfs_inode_count_blocks (tp , ip , & dblocks , & rblocks );
2059+
2060+ xfs_trans_mod_ino_dquot (tp , ip , prevdq , XFS_TRANS_DQ_BCOUNT ,
2061+ - (xfs_qcnt_t )dblocks );
2062+ xfs_trans_mod_ino_dquot (tp , ip , prevdq , XFS_TRANS_DQ_RTBCOUNT ,
2063+ - (xfs_qcnt_t )rblocks );
20602064 xfs_trans_mod_ino_dquot (tp , ip , prevdq , XFS_TRANS_DQ_ICOUNT , -1 );
20612065
20622066 /* the sparkling new dquot */
2063- xfs_trans_mod_ino_dquot (tp , ip , newdq , bfield , ip -> i_nblocks );
2067+ xfs_trans_mod_ino_dquot (tp , ip , newdq , XFS_TRANS_DQ_BCOUNT , dblocks );
2068+ xfs_trans_mod_ino_dquot (tp , ip , newdq , XFS_TRANS_DQ_RTBCOUNT , rblocks );
20642069 xfs_trans_mod_ino_dquot (tp , ip , newdq , XFS_TRANS_DQ_ICOUNT , 1 );
20652070
20662071 /*
@@ -2070,7 +2075,8 @@ xfs_qm_vop_chown(
20702075 * (having already bumped up the real counter) so that we don't have
20712076 * any reservation to give back when we commit.
20722077 */
2073- xfs_trans_mod_dquot (tp , newdq , XFS_TRANS_DQ_RES_BLKS ,
2078+ xfs_trans_mod_dquot (tp , newdq ,
2079+ isrt ? XFS_TRANS_DQ_RES_RTBLKS : XFS_TRANS_DQ_RES_BLKS ,
20742080 - ip -> i_delayed_blks );
20752081
20762082 /*
@@ -2082,8 +2088,13 @@ xfs_qm_vop_chown(
20822088 */
20832089 tp -> t_flags |= XFS_TRANS_DIRTY ;
20842090 xfs_dqlock (prevdq );
2085- ASSERT (prevdq -> q_blk .reserved >= ip -> i_delayed_blks );
2086- prevdq -> q_blk .reserved -= ip -> i_delayed_blks ;
2091+ if (isrt ) {
2092+ ASSERT (prevdq -> q_rtb .reserved >= ip -> i_delayed_blks );
2093+ prevdq -> q_rtb .reserved -= ip -> i_delayed_blks ;
2094+ } else {
2095+ ASSERT (prevdq -> q_blk .reserved >= ip -> i_delayed_blks );
2096+ prevdq -> q_blk .reserved -= ip -> i_delayed_blks ;
2097+ }
20872098 xfs_dqunlock (prevdq );
20882099
20892100 /*
@@ -2168,6 +2179,8 @@ xfs_inode_near_dquot_enforcement(
21682179 xfs_dqtype_t type )
21692180{
21702181 struct xfs_dquot * dqp ;
2182+ struct xfs_dquot_res * res ;
2183+ struct xfs_dquot_pre * pre ;
21712184 int64_t freesp ;
21722185
21732186 /* We only care for quotas that are enabled and enforced. */
@@ -2176,21 +2189,30 @@ xfs_inode_near_dquot_enforcement(
21762189 return false;
21772190
21782191 if (xfs_dquot_res_over_limits (& dqp -> q_ino ) ||
2192+ xfs_dquot_res_over_limits (& dqp -> q_blk ) ||
21792193 xfs_dquot_res_over_limits (& dqp -> q_rtb ))
21802194 return true;
21812195
2196+ if (XFS_IS_REALTIME_INODE (ip )) {
2197+ res = & dqp -> q_rtb ;
2198+ pre = & dqp -> q_rtb_prealloc ;
2199+ } else {
2200+ res = & dqp -> q_blk ;
2201+ pre = & dqp -> q_blk_prealloc ;
2202+ }
2203+
21822204 /* For space on the data device, check the various thresholds. */
2183- if (!dqp -> q_prealloc_hi_wmark )
2205+ if (!pre -> q_prealloc_hi_wmark )
21842206 return false;
21852207
2186- if (dqp -> q_blk . reserved < dqp -> q_prealloc_lo_wmark )
2208+ if (res -> reserved < pre -> q_prealloc_lo_wmark )
21872209 return false;
21882210
2189- if (dqp -> q_blk . reserved >= dqp -> q_prealloc_hi_wmark )
2211+ if (res -> reserved >= pre -> q_prealloc_hi_wmark )
21902212 return true;
21912213
2192- freesp = dqp -> q_prealloc_hi_wmark - dqp -> q_blk . reserved ;
2193- if (freesp < dqp -> q_low_space [XFS_QLOWSP_5_PCNT ])
2214+ freesp = pre -> q_prealloc_hi_wmark - res -> reserved ;
2215+ if (freesp < pre -> q_low_space [XFS_QLOWSP_5_PCNT ])
21942216 return true;
21952217
21962218 return false;
0 commit comments