Skip to content

Commit 8208c41

Browse files
jankaratytso
authored andcommitted
ext4: fold quota accounting into ext4_xattr_inode_lookup_create()
When allocating EA inode, quota accounting is done just before ext4_xattr_inode_lookup_create(). Logically these two operations belong together so just fold quota accounting into ext4_xattr_inode_lookup_create(). We also make ext4_xattr_inode_lookup_create() return the looked up / created inode to convert the function to a more standard calling convention. Signed-off-by: Jan Kara <jack@suse.cz> Link: https://lore.kernel.org/r/20240209112107.10585-1-jack@suse.cz Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent 4fbf8bc commit 8208c41

1 file changed

Lines changed: 24 additions & 26 deletions

File tree

fs/ext4/xattr.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,46 +1565,49 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value,
15651565
/*
15661566
* Add value of the EA in an inode.
15671567
*/
1568-
static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode,
1569-
const void *value, size_t value_len,
1570-
struct inode **ret_inode)
1568+
static struct inode *ext4_xattr_inode_lookup_create(handle_t *handle,
1569+
struct inode *inode, const void *value, size_t value_len)
15711570
{
15721571
struct inode *ea_inode;
15731572
u32 hash;
15741573
int err;
15751574

1575+
/* Account inode & space to quota even if sharing... */
1576+
err = ext4_xattr_inode_alloc_quota(inode, value_len);
1577+
if (err)
1578+
return ERR_PTR(err);
1579+
15761580
hash = ext4_xattr_inode_hash(EXT4_SB(inode->i_sb), value, value_len);
15771581
ea_inode = ext4_xattr_inode_cache_find(inode, value, value_len, hash);
15781582
if (ea_inode) {
15791583
err = ext4_xattr_inode_inc_ref(handle, ea_inode);
1580-
if (err) {
1581-
iput(ea_inode);
1582-
return err;
1583-
}
1584-
1585-
*ret_inode = ea_inode;
1586-
return 0;
1584+
if (err)
1585+
goto out_err;
1586+
return ea_inode;
15871587
}
15881588

15891589
/* Create an inode for the EA value */
15901590
ea_inode = ext4_xattr_inode_create(handle, inode, hash);
1591-
if (IS_ERR(ea_inode))
1592-
return PTR_ERR(ea_inode);
1591+
if (IS_ERR(ea_inode)) {
1592+
ext4_xattr_inode_free_quota(inode, NULL, value_len);
1593+
return ea_inode;
1594+
}
15931595

15941596
err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
15951597
if (err) {
15961598
if (ext4_xattr_inode_dec_ref(handle, ea_inode))
15971599
ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err);
1598-
iput(ea_inode);
1599-
return err;
1600+
goto out_err;
16001601
}
16011602

16021603
if (EA_INODE_CACHE(inode))
16031604
mb_cache_entry_create(EA_INODE_CACHE(inode), GFP_NOFS, hash,
16041605
ea_inode->i_ino, true /* reusable */);
1605-
1606-
*ret_inode = ea_inode;
1607-
return 0;
1606+
return ea_inode;
1607+
out_err:
1608+
iput(ea_inode);
1609+
ext4_xattr_inode_free_quota(inode, NULL, value_len);
1610+
return ERR_PTR(err);
16081611
}
16091612

16101613
/*
@@ -1712,16 +1715,11 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
17121715
if (i->value && in_inode) {
17131716
WARN_ON_ONCE(!i->value_len);
17141717

1715-
ret = ext4_xattr_inode_alloc_quota(inode, i->value_len);
1716-
if (ret)
1717-
goto out;
1718-
1719-
ret = ext4_xattr_inode_lookup_create(handle, inode, i->value,
1720-
i->value_len,
1721-
&new_ea_inode);
1722-
if (ret) {
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);
17231722
new_ea_inode = NULL;
1724-
ext4_xattr_inode_free_quota(inode, NULL, i->value_len);
17251723
goto out;
17261724
}
17271725
}

0 commit comments

Comments
 (0)