mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-01-14 21:48:49 +00:00
ext4: improve journal credit handling in set xattr paths
Both ext4_set_acl() and ext4_set_context() need to be made aware of ea_inode feature when it comes to credits calculation. Also add a sufficient credits check in ext4_xattr_set_handle() right after xattr write lock is grabbed. Original credits calculation is done outside the lock so there is a possiblity that the initially calculated credits are not sufficient anymore. Signed-off-by: Tahsin Erdogan <tahsin@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This commit is contained in:
parent
65d3000520
commit
c1a5d5f6ab
@ -231,14 +231,15 @@ int
|
|||||||
ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
ext4_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||||
{
|
{
|
||||||
handle_t *handle;
|
handle_t *handle;
|
||||||
int error, retries = 0;
|
int error, credits, retries = 0;
|
||||||
|
size_t acl_size = acl ? ext4_acl_size(acl->a_count) : 0;
|
||||||
|
|
||||||
error = dquot_initialize(inode);
|
error = dquot_initialize(inode);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
retry:
|
retry:
|
||||||
handle = ext4_journal_start(inode, EXT4_HT_XATTR,
|
credits = ext4_xattr_set_credits(inode, acl_size);
|
||||||
ext4_jbd2_credits_xattr(inode));
|
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
|
||||||
if (IS_ERR(handle))
|
if (IS_ERR(handle))
|
||||||
return PTR_ERR(handle);
|
return PTR_ERR(handle);
|
||||||
|
|
||||||
|
@ -111,20 +111,6 @@
|
|||||||
#define EXT4_MAXQUOTAS_INIT_BLOCKS(sb) (EXT4_MAXQUOTAS*EXT4_QUOTA_INIT_BLOCKS(sb))
|
#define EXT4_MAXQUOTAS_INIT_BLOCKS(sb) (EXT4_MAXQUOTAS*EXT4_QUOTA_INIT_BLOCKS(sb))
|
||||||
#define EXT4_MAXQUOTAS_DEL_BLOCKS(sb) (EXT4_MAXQUOTAS*EXT4_QUOTA_DEL_BLOCKS(sb))
|
#define EXT4_MAXQUOTAS_DEL_BLOCKS(sb) (EXT4_MAXQUOTAS*EXT4_QUOTA_DEL_BLOCKS(sb))
|
||||||
|
|
||||||
static inline int ext4_jbd2_credits_xattr(struct inode *inode)
|
|
||||||
{
|
|
||||||
int credits = EXT4_DATA_TRANS_BLOCKS(inode->i_sb);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* In case of inline data, we may push out the data to a block,
|
|
||||||
* so we need to reserve credits for this eventuality
|
|
||||||
*/
|
|
||||||
if (ext4_has_inline_data(inode))
|
|
||||||
credits += ext4_writepage_trans_blocks(inode) + 1;
|
|
||||||
return credits;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Ext4 handle operation types -- for logging purposes
|
* Ext4 handle operation types -- for logging purposes
|
||||||
*/
|
*/
|
||||||
|
@ -1143,7 +1143,7 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
|
|||||||
void *fs_data)
|
void *fs_data)
|
||||||
{
|
{
|
||||||
handle_t *handle = fs_data;
|
handle_t *handle = fs_data;
|
||||||
int res, res2, retries = 0;
|
int res, res2, credits, retries = 0;
|
||||||
|
|
||||||
res = ext4_convert_inline_data(inode);
|
res = ext4_convert_inline_data(inode);
|
||||||
if (res)
|
if (res)
|
||||||
@ -1178,8 +1178,8 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,
|
|||||||
if (res)
|
if (res)
|
||||||
return res;
|
return res;
|
||||||
retry:
|
retry:
|
||||||
handle = ext4_journal_start(inode, EXT4_HT_MISC,
|
credits = ext4_xattr_set_credits(inode, len);
|
||||||
ext4_jbd2_credits_xattr(inode));
|
handle = ext4_journal_start(inode, EXT4_HT_MISC, credits);
|
||||||
if (IS_ERR(handle))
|
if (IS_ERR(handle))
|
||||||
return PTR_ERR(handle);
|
return PTR_ERR(handle);
|
||||||
|
|
||||||
|
@ -1471,6 +1471,17 @@ ext4_xattr_set_handle(handle_t *handle, struct inode *inode, int name_index,
|
|||||||
|
|
||||||
ext4_write_lock_xattr(inode, &no_expand);
|
ext4_write_lock_xattr(inode, &no_expand);
|
||||||
|
|
||||||
|
/* Check journal credits under write lock. */
|
||||||
|
if (ext4_handle_valid(handle)) {
|
||||||
|
int credits;
|
||||||
|
|
||||||
|
credits = ext4_xattr_set_credits(inode, value_len);
|
||||||
|
if (!ext4_handle_has_enough_credits(handle, credits)) {
|
||||||
|
error = -ENOSPC;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
error = ext4_reserve_inode_write(handle, inode, &is.iloc);
|
error = ext4_reserve_inode_write(handle, inode, &is.iloc);
|
||||||
if (error)
|
if (error)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1568,6 +1579,36 @@ cleanup:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ext4_xattr_set_credits(struct inode *inode, size_t value_len)
|
||||||
|
{
|
||||||
|
struct super_block *sb = inode->i_sb;
|
||||||
|
int credits;
|
||||||
|
|
||||||
|
if (!EXT4_SB(sb)->s_journal)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
credits = EXT4_DATA_TRANS_BLOCKS(inode->i_sb);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* In case of inline data, we may push out the data to a block,
|
||||||
|
* so we need to reserve credits for this eventuality
|
||||||
|
*/
|
||||||
|
if (ext4_has_inline_data(inode))
|
||||||
|
credits += ext4_writepage_trans_blocks(inode) + 1;
|
||||||
|
|
||||||
|
if (ext4_has_feature_ea_inode(sb)) {
|
||||||
|
int nrblocks = (value_len + sb->s_blocksize - 1) >>
|
||||||
|
sb->s_blocksize_bits;
|
||||||
|
|
||||||
|
/* For new inode */
|
||||||
|
credits += EXT4_SINGLEDATA_TRANS_BLOCKS(sb) + 3;
|
||||||
|
|
||||||
|
/* For data blocks of EA inode */
|
||||||
|
credits += ext4_meta_trans_blocks(inode, nrblocks, 0);
|
||||||
|
}
|
||||||
|
return credits;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ext4_xattr_set()
|
* ext4_xattr_set()
|
||||||
*
|
*
|
||||||
@ -1583,24 +1624,14 @@ ext4_xattr_set(struct inode *inode, int name_index, const char *name,
|
|||||||
handle_t *handle;
|
handle_t *handle;
|
||||||
struct super_block *sb = inode->i_sb;
|
struct super_block *sb = inode->i_sb;
|
||||||
int error, retries = 0;
|
int error, retries = 0;
|
||||||
int credits = ext4_jbd2_credits_xattr(inode);
|
int credits;
|
||||||
|
|
||||||
error = dquot_initialize(inode);
|
error = dquot_initialize(inode);
|
||||||
if (error)
|
if (error)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
if (ext4_has_feature_ea_inode(sb)) {
|
|
||||||
int nrblocks = (value_len + sb->s_blocksize - 1) >>
|
|
||||||
sb->s_blocksize_bits;
|
|
||||||
|
|
||||||
/* For new inode */
|
|
||||||
credits += EXT4_SINGLEDATA_TRANS_BLOCKS(sb) + 3;
|
|
||||||
|
|
||||||
/* For data blocks of EA inode */
|
|
||||||
credits += ext4_meta_trans_blocks(inode, nrblocks, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
|
credits = ext4_xattr_set_credits(inode, value_len);
|
||||||
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
|
handle = ext4_journal_start(inode, EXT4_HT_XATTR, credits);
|
||||||
if (IS_ERR(handle)) {
|
if (IS_ERR(handle)) {
|
||||||
error = PTR_ERR(handle);
|
error = PTR_ERR(handle);
|
||||||
|
@ -160,6 +160,7 @@ extern ssize_t ext4_listxattr(struct dentry *, char *, size_t);
|
|||||||
extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);
|
extern int ext4_xattr_get(struct inode *, int, const char *, void *, size_t);
|
||||||
extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
|
extern int ext4_xattr_set(struct inode *, int, const char *, const void *, size_t, int);
|
||||||
extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
|
extern int ext4_xattr_set_handle(handle_t *, struct inode *, int, const char *, const void *, size_t, int);
|
||||||
|
extern int ext4_xattr_set_credits(struct inode *inode, size_t value_len);
|
||||||
|
|
||||||
extern int ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino);
|
extern int ext4_xattr_inode_unlink(struct inode *inode, unsigned long ea_ino);
|
||||||
extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
|
extern int ext4_xattr_delete_inode(handle_t *handle, struct inode *inode,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user