Commit 8208c41c authored by Jan Kara's avatar Jan Kara Committed by Theodore Ts'o

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: default avatarJan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20240209112107.10585-1-jack@suse.czSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent 4fbf8bc7
...@@ -1565,46 +1565,49 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value, ...@@ -1565,46 +1565,49 @@ ext4_xattr_inode_cache_find(struct inode *inode, const void *value,
/* /*
* Add value of the EA in an inode. * Add value of the EA in an inode.
*/ */
static int ext4_xattr_inode_lookup_create(handle_t *handle, struct inode *inode, static struct inode *ext4_xattr_inode_lookup_create(handle_t *handle,
const void *value, size_t value_len, struct inode *inode, const void *value, size_t value_len)
struct inode **ret_inode)
{ {
struct inode *ea_inode; struct inode *ea_inode;
u32 hash; u32 hash;
int err; int err;
/* Account inode & space to quota even if sharing... */
err = ext4_xattr_inode_alloc_quota(inode, value_len);
if (err)
return ERR_PTR(err);
hash = ext4_xattr_inode_hash(EXT4_SB(inode->i_sb), value, value_len); hash = ext4_xattr_inode_hash(EXT4_SB(inode->i_sb), value, value_len);
ea_inode = ext4_xattr_inode_cache_find(inode, value, value_len, hash); ea_inode = ext4_xattr_inode_cache_find(inode, value, value_len, hash);
if (ea_inode) { if (ea_inode) {
err = ext4_xattr_inode_inc_ref(handle, ea_inode); err = ext4_xattr_inode_inc_ref(handle, ea_inode);
if (err) { if (err)
iput(ea_inode); goto out_err;
return err; return ea_inode;
}
*ret_inode = ea_inode;
return 0;
} }
/* Create an inode for the EA value */ /* Create an inode for the EA value */
ea_inode = ext4_xattr_inode_create(handle, inode, hash); ea_inode = ext4_xattr_inode_create(handle, inode, hash);
if (IS_ERR(ea_inode)) if (IS_ERR(ea_inode)) {
return PTR_ERR(ea_inode); ext4_xattr_inode_free_quota(inode, NULL, value_len);
return ea_inode;
}
err = ext4_xattr_inode_write(handle, ea_inode, value, value_len); err = ext4_xattr_inode_write(handle, ea_inode, value, value_len);
if (err) { if (err) {
if (ext4_xattr_inode_dec_ref(handle, ea_inode)) if (ext4_xattr_inode_dec_ref(handle, ea_inode))
ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err); ext4_warning_inode(ea_inode, "cleanup dec ref error %d", err);
iput(ea_inode); goto out_err;
return err;
} }
if (EA_INODE_CACHE(inode)) if (EA_INODE_CACHE(inode))
mb_cache_entry_create(EA_INODE_CACHE(inode), GFP_NOFS, hash, mb_cache_entry_create(EA_INODE_CACHE(inode), GFP_NOFS, hash,
ea_inode->i_ino, true /* reusable */); ea_inode->i_ino, true /* reusable */);
return ea_inode;
*ret_inode = ea_inode; out_err:
return 0; iput(ea_inode);
ext4_xattr_inode_free_quota(inode, NULL, value_len);
return ERR_PTR(err);
} }
/* /*
...@@ -1712,16 +1715,11 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i, ...@@ -1712,16 +1715,11 @@ static int ext4_xattr_set_entry(struct ext4_xattr_info *i,
if (i->value && in_inode) { if (i->value && in_inode) {
WARN_ON_ONCE(!i->value_len); WARN_ON_ONCE(!i->value_len);
ret = ext4_xattr_inode_alloc_quota(inode, i->value_len); new_ea_inode = ext4_xattr_inode_lookup_create(handle, inode,
if (ret) i->value, i->value_len);
goto out; if (IS_ERR(new_ea_inode)) {
ret = PTR_ERR(new_ea_inode);
ret = ext4_xattr_inode_lookup_create(handle, inode, i->value,
i->value_len,
&new_ea_inode);
if (ret) {
new_ea_inode = NULL; new_ea_inode = NULL;
ext4_xattr_inode_free_quota(inode, NULL, i->value_len);
goto out; goto out;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment