@@ -399,15 +399,17 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
399
399
EXPORT_SYMBOL (dquot_mark_dquot_dirty );
400
400
401
401
/* Dirtify all the dquots - this can block when journalling */
402
- static inline int mark_all_dquot_dirty (struct dquot * const * dquot )
402
+ static inline int mark_all_dquot_dirty (struct dquot * const * dquots )
403
403
{
404
404
int ret , err , cnt ;
405
+ struct dquot * dquot ;
405
406
406
407
ret = err = 0 ;
407
408
for (cnt = 0 ; cnt < MAXQUOTAS ; cnt ++ ) {
408
- if (dquot [cnt ])
409
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
410
+ if (dquot )
409
411
/* Even in case of error we have to continue */
410
- ret = mark_dquot_dirty (dquot [ cnt ] );
412
+ ret = mark_dquot_dirty (dquot );
411
413
if (!err )
412
414
err = ret ;
413
415
}
@@ -1674,6 +1676,7 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags)
1674
1676
struct dquot_warn warn [MAXQUOTAS ];
1675
1677
int reserve = flags & DQUOT_SPACE_RESERVE ;
1676
1678
struct dquot * * dquots ;
1679
+ struct dquot * dquot ;
1677
1680
1678
1681
if (!inode_quota_active (inode )) {
1679
1682
if (reserve ) {
@@ -1693,27 +1696,26 @@ int __dquot_alloc_space(struct inode *inode, qsize_t number, int flags)
1693
1696
index = srcu_read_lock (& dquot_srcu );
1694
1697
spin_lock (& inode -> i_lock );
1695
1698
for (cnt = 0 ; cnt < MAXQUOTAS ; cnt ++ ) {
1696
- if (!dquots [cnt ])
1699
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1700
+ if (!dquot )
1697
1701
continue ;
1698
1702
if (reserve ) {
1699
- ret = dquot_add_space (dquots [cnt ], 0 , number , flags ,
1700
- & warn [cnt ]);
1703
+ ret = dquot_add_space (dquot , 0 , number , flags , & warn [cnt ]);
1701
1704
} else {
1702
- ret = dquot_add_space (dquots [cnt ], number , 0 , flags ,
1703
- & warn [cnt ]);
1705
+ ret = dquot_add_space (dquot , number , 0 , flags , & warn [cnt ]);
1704
1706
}
1705
1707
if (ret ) {
1706
1708
/* Back out changes we already did */
1707
1709
for (cnt -- ; cnt >= 0 ; cnt -- ) {
1708
- if (!dquots [cnt ])
1710
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1711
+ if (!dquot )
1709
1712
continue ;
1710
- spin_lock (& dquots [ cnt ] -> dq_dqb_lock );
1713
+ spin_lock (& dquot -> dq_dqb_lock );
1711
1714
if (reserve )
1712
- dquot_free_reserved_space (dquots [cnt ],
1713
- number );
1715
+ dquot_free_reserved_space (dquot , number );
1714
1716
else
1715
- dquot_decr_space (dquots [ cnt ] , number );
1716
- spin_unlock (& dquots [ cnt ] -> dq_dqb_lock );
1717
+ dquot_decr_space (dquot , number );
1718
+ spin_unlock (& dquot -> dq_dqb_lock );
1717
1719
}
1718
1720
spin_unlock (& inode -> i_lock );
1719
1721
goto out_flush_warn ;
@@ -1744,6 +1746,7 @@ int dquot_alloc_inode(struct inode *inode)
1744
1746
int cnt , ret = 0 , index ;
1745
1747
struct dquot_warn warn [MAXQUOTAS ];
1746
1748
struct dquot * const * dquots ;
1749
+ struct dquot * dquot ;
1747
1750
1748
1751
if (!inode_quota_active (inode ))
1749
1752
return 0 ;
@@ -1754,17 +1757,19 @@ int dquot_alloc_inode(struct inode *inode)
1754
1757
index = srcu_read_lock (& dquot_srcu );
1755
1758
spin_lock (& inode -> i_lock );
1756
1759
for (cnt = 0 ; cnt < MAXQUOTAS ; cnt ++ ) {
1757
- if (!dquots [cnt ])
1760
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1761
+ if (!dquot )
1758
1762
continue ;
1759
- ret = dquot_add_inodes (dquots [ cnt ] , 1 , & warn [cnt ]);
1763
+ ret = dquot_add_inodes (dquot , 1 , & warn [cnt ]);
1760
1764
if (ret ) {
1761
1765
for (cnt -- ; cnt >= 0 ; cnt -- ) {
1762
- if (!dquots [cnt ])
1766
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1767
+ if (!dquot )
1763
1768
continue ;
1764
1769
/* Back out changes we already did */
1765
- spin_lock (& dquots [ cnt ] -> dq_dqb_lock );
1766
- dquot_decr_inodes (dquots [ cnt ] , 1 );
1767
- spin_unlock (& dquots [ cnt ] -> dq_dqb_lock );
1770
+ spin_lock (& dquot -> dq_dqb_lock );
1771
+ dquot_decr_inodes (dquot , 1 );
1772
+ spin_unlock (& dquot -> dq_dqb_lock );
1768
1773
}
1769
1774
goto warn_put_all ;
1770
1775
}
@@ -1786,6 +1791,7 @@ EXPORT_SYMBOL(dquot_alloc_inode);
1786
1791
void dquot_claim_space_nodirty (struct inode * inode , qsize_t number )
1787
1792
{
1788
1793
struct dquot * * dquots ;
1794
+ struct dquot * dquot ;
1789
1795
int cnt , index ;
1790
1796
1791
1797
if (!inode_quota_active (inode )) {
@@ -1801,9 +1807,8 @@ void dquot_claim_space_nodirty(struct inode *inode, qsize_t number)
1801
1807
spin_lock (& inode -> i_lock );
1802
1808
/* Claim reserved quotas to allocated quotas */
1803
1809
for (cnt = 0 ; cnt < MAXQUOTAS ; cnt ++ ) {
1804
- if (dquots [cnt ]) {
1805
- struct dquot * dquot = dquots [cnt ];
1806
-
1810
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1811
+ if (dquot ) {
1807
1812
spin_lock (& dquot -> dq_dqb_lock );
1808
1813
if (WARN_ON_ONCE (dquot -> dq_dqb .dqb_rsvspace < number ))
1809
1814
number = dquot -> dq_dqb .dqb_rsvspace ;
@@ -1828,6 +1833,7 @@ EXPORT_SYMBOL(dquot_claim_space_nodirty);
1828
1833
void dquot_reclaim_space_nodirty (struct inode * inode , qsize_t number )
1829
1834
{
1830
1835
struct dquot * * dquots ;
1836
+ struct dquot * dquot ;
1831
1837
int cnt , index ;
1832
1838
1833
1839
if (!inode_quota_active (inode )) {
@@ -1843,9 +1849,8 @@ void dquot_reclaim_space_nodirty(struct inode *inode, qsize_t number)
1843
1849
spin_lock (& inode -> i_lock );
1844
1850
/* Claim reserved quotas to allocated quotas */
1845
1851
for (cnt = 0 ; cnt < MAXQUOTAS ; cnt ++ ) {
1846
- if (dquots [cnt ]) {
1847
- struct dquot * dquot = dquots [cnt ];
1848
-
1852
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1853
+ if (dquot ) {
1849
1854
spin_lock (& dquot -> dq_dqb_lock );
1850
1855
if (WARN_ON_ONCE (dquot -> dq_dqb .dqb_curspace < number ))
1851
1856
number = dquot -> dq_dqb .dqb_curspace ;
@@ -1872,6 +1877,7 @@ void __dquot_free_space(struct inode *inode, qsize_t number, int flags)
1872
1877
unsigned int cnt ;
1873
1878
struct dquot_warn warn [MAXQUOTAS ];
1874
1879
struct dquot * * dquots ;
1880
+ struct dquot * dquot ;
1875
1881
int reserve = flags & DQUOT_SPACE_RESERVE , index ;
1876
1882
1877
1883
if (!inode_quota_active (inode )) {
@@ -1892,17 +1898,18 @@ void __dquot_free_space(struct inode *inode, qsize_t number, int flags)
1892
1898
int wtype ;
1893
1899
1894
1900
warn [cnt ].w_type = QUOTA_NL_NOWARN ;
1895
- if (!dquots [cnt ])
1901
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1902
+ if (!dquot )
1896
1903
continue ;
1897
- spin_lock (& dquots [ cnt ] -> dq_dqb_lock );
1898
- wtype = info_bdq_free (dquots [ cnt ] , number );
1904
+ spin_lock (& dquot -> dq_dqb_lock );
1905
+ wtype = info_bdq_free (dquot , number );
1899
1906
if (wtype != QUOTA_NL_NOWARN )
1900
- prepare_warning (& warn [cnt ], dquots [ cnt ] , wtype );
1907
+ prepare_warning (& warn [cnt ], dquot , wtype );
1901
1908
if (reserve )
1902
- dquot_free_reserved_space (dquots [ cnt ] , number );
1909
+ dquot_free_reserved_space (dquot , number );
1903
1910
else
1904
- dquot_decr_space (dquots [ cnt ] , number );
1905
- spin_unlock (& dquots [ cnt ] -> dq_dqb_lock );
1911
+ dquot_decr_space (dquot , number );
1912
+ spin_unlock (& dquot -> dq_dqb_lock );
1906
1913
}
1907
1914
if (reserve )
1908
1915
* inode_reserved_space (inode ) -= number ;
@@ -1927,6 +1934,7 @@ void dquot_free_inode(struct inode *inode)
1927
1934
unsigned int cnt ;
1928
1935
struct dquot_warn warn [MAXQUOTAS ];
1929
1936
struct dquot * const * dquots ;
1937
+ struct dquot * dquot ;
1930
1938
int index ;
1931
1939
1932
1940
if (!inode_quota_active (inode ))
@@ -1937,16 +1945,16 @@ void dquot_free_inode(struct inode *inode)
1937
1945
spin_lock (& inode -> i_lock );
1938
1946
for (cnt = 0 ; cnt < MAXQUOTAS ; cnt ++ ) {
1939
1947
int wtype ;
1940
-
1941
1948
warn [cnt ].w_type = QUOTA_NL_NOWARN ;
1942
- if (!dquots [cnt ])
1949
+ dquot = srcu_dereference (dquots [cnt ], & dquot_srcu );
1950
+ if (!dquot )
1943
1951
continue ;
1944
- spin_lock (& dquots [ cnt ] -> dq_dqb_lock );
1945
- wtype = info_idq_free (dquots [ cnt ] , 1 );
1952
+ spin_lock (& dquot -> dq_dqb_lock );
1953
+ wtype = info_idq_free (dquot , 1 );
1946
1954
if (wtype != QUOTA_NL_NOWARN )
1947
- prepare_warning (& warn [cnt ], dquots [ cnt ] , wtype );
1948
- dquot_decr_inodes (dquots [ cnt ] , 1 );
1949
- spin_unlock (& dquots [ cnt ] -> dq_dqb_lock );
1955
+ prepare_warning (& warn [cnt ], dquot , wtype );
1956
+ dquot_decr_inodes (dquot , 1 );
1957
+ spin_unlock (& dquot -> dq_dqb_lock );
1950
1958
}
1951
1959
spin_unlock (& inode -> i_lock );
1952
1960
mark_all_dquot_dirty (dquots );
@@ -1973,7 +1981,7 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
1973
1981
qsize_t rsv_space = 0 ;
1974
1982
qsize_t inode_usage = 1 ;
1975
1983
struct dquot * transfer_from [MAXQUOTAS ] = {};
1976
- int cnt , ret = 0 ;
1984
+ int cnt , index , ret = 0 ;
1977
1985
char is_valid [MAXQUOTAS ] = {};
1978
1986
struct dquot_warn warn_to [MAXQUOTAS ];
1979
1987
struct dquot_warn warn_from_inodes [MAXQUOTAS ];
@@ -2062,8 +2070,16 @@ int __dquot_transfer(struct inode *inode, struct dquot **transfer_to)
2062
2070
spin_unlock (& inode -> i_lock );
2063
2071
spin_unlock (& dq_data_lock );
2064
2072
2073
+ /*
2074
+ * These arrays are local and we hold dquot references so we don't need
2075
+ * the srcu protection but still take dquot_srcu to avoid warning in
2076
+ * mark_all_dquot_dirty().
2077
+ */
2078
+ index = srcu_read_lock (& dquot_srcu );
2065
2079
mark_all_dquot_dirty (transfer_from );
2066
2080
mark_all_dquot_dirty (transfer_to );
2081
+ srcu_read_unlock (& dquot_srcu , index );
2082
+
2067
2083
flush_warnings (warn_to );
2068
2084
flush_warnings (warn_from_inodes );
2069
2085
flush_warnings (warn_from_space );
0 commit comments