@@ -1619,14 +1619,14 @@ static struct inode *ext4_xattr_inode_lookup_create(handle_t *handle,
1619
1619
static int ext4_xattr_set_entry (struct ext4_xattr_info * i ,
1620
1620
struct ext4_xattr_search * s ,
1621
1621
handle_t * handle , struct inode * inode ,
1622
+ struct inode * new_ea_inode ,
1622
1623
bool is_block )
1623
1624
{
1624
1625
struct ext4_xattr_entry * last , * next ;
1625
1626
struct ext4_xattr_entry * here = s -> here ;
1626
1627
size_t min_offs = s -> end - s -> base , name_len = strlen (i -> name );
1627
1628
int in_inode = i -> in_inode ;
1628
1629
struct inode * old_ea_inode = NULL ;
1629
- struct inode * new_ea_inode = NULL ;
1630
1630
size_t old_size , new_size ;
1631
1631
int ret ;
1632
1632
@@ -1711,38 +1711,11 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
1711
1711
old_ea_inode = NULL ;
1712
1712
goto out ;
1713
1713
}
1714
- }
1715
- if (i -> value && in_inode ) {
1716
- WARN_ON_ONCE (!i -> value_len );
1717
-
1718
- new_ea_inode = ext4_xattr_inode_lookup_create (handle , inode ,
1719
- i -> value , i -> value_len );
1720
- if (IS_ERR (new_ea_inode )) {
1721
- ret = PTR_ERR (new_ea_inode );
1722
- new_ea_inode = NULL ;
1723
- goto out ;
1724
- }
1725
- }
1726
1714
1727
- if (old_ea_inode ) {
1728
1715
/* We are ready to release ref count on the old_ea_inode. */
1729
1716
ret = ext4_xattr_inode_dec_ref (handle , old_ea_inode );
1730
- if (ret ) {
1731
- /* Release newly required ref count on new_ea_inode. */
1732
- if (new_ea_inode ) {
1733
- int err ;
1734
-
1735
- err = ext4_xattr_inode_dec_ref (handle ,
1736
- new_ea_inode );
1737
- if (err )
1738
- ext4_warning_inode (new_ea_inode ,
1739
- "dec ref new_ea_inode err=%d" ,
1740
- err );
1741
- ext4_xattr_inode_free_quota (inode , new_ea_inode ,
1742
- i -> value_len );
1743
- }
1717
+ if (ret )
1744
1718
goto out ;
1745
- }
1746
1719
1747
1720
ext4_xattr_inode_free_quota (inode , old_ea_inode ,
1748
1721
le32_to_cpu (here -> e_value_size ));
@@ -1866,7 +1839,6 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
1866
1839
ret = 0 ;
1867
1840
out :
1868
1841
iput (old_ea_inode );
1869
- iput (new_ea_inode );
1870
1842
return ret ;
1871
1843
}
1872
1844
@@ -1929,9 +1901,21 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
1929
1901
size_t old_ea_inode_quota = 0 ;
1930
1902
unsigned int ea_ino ;
1931
1903
1932
-
1933
1904
#define header (x ) ((struct ext4_xattr_header *)(x))
1934
1905
1906
+ /* If we need EA inode, prepare it before locking the buffer */
1907
+ if (i -> value && i -> in_inode ) {
1908
+ WARN_ON_ONCE (!i -> value_len );
1909
+
1910
+ ea_inode = ext4_xattr_inode_lookup_create (handle , inode ,
1911
+ i -> value , i -> value_len );
1912
+ if (IS_ERR (ea_inode )) {
1913
+ error = PTR_ERR (ea_inode );
1914
+ ea_inode = NULL ;
1915
+ goto cleanup ;
1916
+ }
1917
+ }
1918
+
1935
1919
if (s -> base ) {
1936
1920
int offset = (char * )s -> here - bs -> bh -> b_data ;
1937
1921
@@ -1940,6 +1924,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
1940
1924
EXT4_JTR_NONE );
1941
1925
if (error )
1942
1926
goto cleanup ;
1927
+
1943
1928
lock_buffer (bs -> bh );
1944
1929
1945
1930
if (header (s -> base )-> h_refcount == cpu_to_le32 (1 )) {
@@ -1966,7 +1951,7 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
1966
1951
}
1967
1952
ea_bdebug (bs -> bh , "modifying in-place" );
1968
1953
error = ext4_xattr_set_entry (i , s , handle , inode ,
1969
- true /* is_block */ );
1954
+ ea_inode , true /* is_block */ );
1970
1955
ext4_xattr_block_csum_set (inode , bs -> bh );
1971
1956
unlock_buffer (bs -> bh );
1972
1957
if (error == - EFSCORRUPTED )
@@ -2034,29 +2019,13 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
2034
2019
s -> end = s -> base + sb -> s_blocksize ;
2035
2020
}
2036
2021
2037
- error = ext4_xattr_set_entry (i , s , handle , inode , true /* is_block */ );
2022
+ error = ext4_xattr_set_entry (i , s , handle , inode , ea_inode ,
2023
+ true /* is_block */ );
2038
2024
if (error == - EFSCORRUPTED )
2039
2025
goto bad_block ;
2040
2026
if (error )
2041
2027
goto cleanup ;
2042
2028
2043
- if (i -> value && s -> here -> e_value_inum ) {
2044
- /*
2045
- * A ref count on ea_inode has been taken as part of the call to
2046
- * ext4_xattr_set_entry() above. We would like to drop this
2047
- * extra ref but we have to wait until the xattr block is
2048
- * initialized and has its own ref count on the ea_inode.
2049
- */
2050
- ea_ino = le32_to_cpu (s -> here -> e_value_inum );
2051
- error = ext4_xattr_inode_iget (inode , ea_ino ,
2052
- le32_to_cpu (s -> here -> e_hash ),
2053
- & ea_inode );
2054
- if (error ) {
2055
- ea_inode = NULL ;
2056
- goto cleanup ;
2057
- }
2058
- }
2059
-
2060
2029
inserted :
2061
2030
if (!IS_LAST_ENTRY (s -> first )) {
2062
2031
new_bh = ext4_xattr_block_cache_find (inode , header (s -> base ),
@@ -2209,17 +2178,16 @@ ext4_xattr_block_set(handle_t *handle, struct inode *inode,
2209
2178
2210
2179
cleanup :
2211
2180
if (ea_inode ) {
2212
- int error2 ;
2213
-
2214
- error2 = ext4_xattr_inode_dec_ref (handle , ea_inode );
2215
- if (error2 )
2216
- ext4_warning_inode (ea_inode , "dec ref error=%d" ,
2217
- error2 );
2181
+ if (error ) {
2182
+ int error2 ;
2218
2183
2219
- /* If there was an error, revert the quota charge. */
2220
- if (error )
2184
+ error2 = ext4_xattr_inode_dec_ref (handle , ea_inode );
2185
+ if (error2 )
2186
+ ext4_warning_inode (ea_inode , "dec ref error=%d" ,
2187
+ error2 );
2221
2188
ext4_xattr_inode_free_quota (inode , ea_inode ,
2222
2189
i_size_read (ea_inode ));
2190
+ }
2223
2191
iput (ea_inode );
2224
2192
}
2225
2193
if (ce )
@@ -2277,14 +2245,38 @@ int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
2277
2245
{
2278
2246
struct ext4_xattr_ibody_header * header ;
2279
2247
struct ext4_xattr_search * s = & is -> s ;
2248
+ struct inode * ea_inode = NULL ;
2280
2249
int error ;
2281
2250
2282
2251
if (!EXT4_INODE_HAS_XATTR_SPACE (inode ))
2283
2252
return - ENOSPC ;
2284
2253
2285
- error = ext4_xattr_set_entry (i , s , handle , inode , false /* is_block */ );
2286
- if (error )
2254
+ /* If we need EA inode, prepare it before locking the buffer */
2255
+ if (i -> value && i -> in_inode ) {
2256
+ WARN_ON_ONCE (!i -> value_len );
2257
+
2258
+ ea_inode = ext4_xattr_inode_lookup_create (handle , inode ,
2259
+ i -> value , i -> value_len );
2260
+ if (IS_ERR (ea_inode ))
2261
+ return PTR_ERR (ea_inode );
2262
+ }
2263
+ error = ext4_xattr_set_entry (i , s , handle , inode , ea_inode ,
2264
+ false /* is_block */ );
2265
+ if (error ) {
2266
+ if (ea_inode ) {
2267
+ int error2 ;
2268
+
2269
+ error2 = ext4_xattr_inode_dec_ref (handle , ea_inode );
2270
+ if (error2 )
2271
+ ext4_warning_inode (ea_inode , "dec ref error=%d" ,
2272
+ error2 );
2273
+
2274
+ ext4_xattr_inode_free_quota (inode , ea_inode ,
2275
+ i_size_read (ea_inode ));
2276
+ iput (ea_inode );
2277
+ }
2287
2278
return error ;
2279
+ }
2288
2280
header = IHDR (inode , ext4_raw_inode (& is -> iloc ));
2289
2281
if (!IS_LAST_ENTRY (s -> first )) {
2290
2282
header -> h_magic = cpu_to_le32 (EXT4_XATTR_MAGIC );
@@ -2293,6 +2285,7 @@ int ext4_xattr_ibody_set(handle_t *handle, struct inode *inode,
2293
2285
header -> h_magic = cpu_to_le32 (0 );
2294
2286
ext4_clear_inode_state (inode , EXT4_STATE_XATTR );
2295
2287
}
2288
+ iput (ea_inode );
2296
2289
return 0 ;
2297
2290
}
2298
2291
0 commit comments