mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 23:58:05 +00:00
ext4: allow ext4_truncate() to return an error
This allows us to properly propagate errors back up to ext4_truncate()'s callers. This also means we no longer have to silently ignore some errors (e.g., when trying to add the inode to the orphan inode list). Signed-off-by: Theodore Ts'o <tytso@mit.edu> Reviewed-by: Jan Kara <jack@suse.cz>
This commit is contained in:
parent
6da22013bb
commit
2c98eb5ea2
4 changed files with 36 additions and 20 deletions
|
@ -2491,7 +2491,7 @@ extern int ext4_change_inode_journal_flag(struct inode *, int);
|
||||||
extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
|
extern int ext4_get_inode_loc(struct inode *, struct ext4_iloc *);
|
||||||
extern int ext4_inode_attach_jinode(struct inode *inode);
|
extern int ext4_inode_attach_jinode(struct inode *inode);
|
||||||
extern int ext4_can_truncate(struct inode *inode);
|
extern int ext4_can_truncate(struct inode *inode);
|
||||||
extern void ext4_truncate(struct inode *);
|
extern int ext4_truncate(struct inode *);
|
||||||
extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length);
|
extern int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length);
|
||||||
extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
|
extern int ext4_truncate_restart_trans(handle_t *, struct inode *, int nblocks);
|
||||||
extern void ext4_set_inode_flags(struct inode *);
|
extern void ext4_set_inode_flags(struct inode *);
|
||||||
|
|
|
@ -261,8 +261,15 @@ void ext4_evict_inode(struct inode *inode)
|
||||||
"couldn't mark inode dirty (err %d)", err);
|
"couldn't mark inode dirty (err %d)", err);
|
||||||
goto stop_handle;
|
goto stop_handle;
|
||||||
}
|
}
|
||||||
if (inode->i_blocks)
|
if (inode->i_blocks) {
|
||||||
ext4_truncate(inode);
|
err = ext4_truncate(inode);
|
||||||
|
if (err) {
|
||||||
|
ext4_error(inode->i_sb,
|
||||||
|
"couldn't truncate inode %lu (err %d)",
|
||||||
|
inode->i_ino, err);
|
||||||
|
goto stop_handle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ext4_ext_truncate() doesn't reserve any slop when it
|
* ext4_ext_truncate() doesn't reserve any slop when it
|
||||||
|
@ -4097,10 +4104,11 @@ int ext4_inode_attach_jinode(struct inode *inode)
|
||||||
* that's fine - as long as they are linked from the inode, the post-crash
|
* that's fine - as long as they are linked from the inode, the post-crash
|
||||||
* ext4_truncate() run will find them and release them.
|
* ext4_truncate() run will find them and release them.
|
||||||
*/
|
*/
|
||||||
void ext4_truncate(struct inode *inode)
|
int ext4_truncate(struct inode *inode)
|
||||||
{
|
{
|
||||||
struct ext4_inode_info *ei = EXT4_I(inode);
|
struct ext4_inode_info *ei = EXT4_I(inode);
|
||||||
unsigned int credits;
|
unsigned int credits;
|
||||||
|
int err = 0;
|
||||||
handle_t *handle;
|
handle_t *handle;
|
||||||
struct address_space *mapping = inode->i_mapping;
|
struct address_space *mapping = inode->i_mapping;
|
||||||
|
|
||||||
|
@ -4114,7 +4122,7 @@ void ext4_truncate(struct inode *inode)
|
||||||
trace_ext4_truncate_enter(inode);
|
trace_ext4_truncate_enter(inode);
|
||||||
|
|
||||||
if (!ext4_can_truncate(inode))
|
if (!ext4_can_truncate(inode))
|
||||||
return;
|
return 0;
|
||||||
|
|
||||||
ext4_clear_inode_flag(inode, EXT4_INODE_EOFBLOCKS);
|
ext4_clear_inode_flag(inode, EXT4_INODE_EOFBLOCKS);
|
||||||
|
|
||||||
|
@ -4126,13 +4134,13 @@ void ext4_truncate(struct inode *inode)
|
||||||
|
|
||||||
ext4_inline_data_truncate(inode, &has_inline);
|
ext4_inline_data_truncate(inode, &has_inline);
|
||||||
if (has_inline)
|
if (has_inline)
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we zero-out tail of the page, we have to create jinode for jbd2 */
|
/* If we zero-out tail of the page, we have to create jinode for jbd2 */
|
||||||
if (inode->i_size & (inode->i_sb->s_blocksize - 1)) {
|
if (inode->i_size & (inode->i_sb->s_blocksize - 1)) {
|
||||||
if (ext4_inode_attach_jinode(inode) < 0)
|
if (ext4_inode_attach_jinode(inode) < 0)
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
|
if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))
|
||||||
|
@ -4141,10 +4149,8 @@ void ext4_truncate(struct inode *inode)
|
||||||
credits = ext4_blocks_for_truncate(inode);
|
credits = ext4_blocks_for_truncate(inode);
|
||||||
|
|
||||||
handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
|
handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits);
|
||||||
if (IS_ERR(handle)) {
|
if (IS_ERR(handle))
|
||||||
ext4_std_error(inode->i_sb, PTR_ERR(handle));
|
return PTR_ERR(handle);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (inode->i_size & (inode->i_sb->s_blocksize - 1))
|
if (inode->i_size & (inode->i_sb->s_blocksize - 1))
|
||||||
ext4_block_truncate_page(handle, mapping, inode->i_size);
|
ext4_block_truncate_page(handle, mapping, inode->i_size);
|
||||||
|
@ -4158,7 +4164,8 @@ void ext4_truncate(struct inode *inode)
|
||||||
* Implication: the file must always be in a sane, consistent
|
* Implication: the file must always be in a sane, consistent
|
||||||
* truncatable state while each transaction commits.
|
* truncatable state while each transaction commits.
|
||||||
*/
|
*/
|
||||||
if (ext4_orphan_add(handle, inode))
|
err = ext4_orphan_add(handle, inode);
|
||||||
|
if (err)
|
||||||
goto out_stop;
|
goto out_stop;
|
||||||
|
|
||||||
down_write(&EXT4_I(inode)->i_data_sem);
|
down_write(&EXT4_I(inode)->i_data_sem);
|
||||||
|
@ -4191,6 +4198,7 @@ void ext4_truncate(struct inode *inode)
|
||||||
ext4_journal_stop(handle);
|
ext4_journal_stop(handle);
|
||||||
|
|
||||||
trace_ext4_truncate_exit(inode);
|
trace_ext4_truncate_exit(inode);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -5205,12 +5213,15 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
|
||||||
* in data=journal mode to make pages freeable.
|
* in data=journal mode to make pages freeable.
|
||||||
*/
|
*/
|
||||||
truncate_pagecache(inode, inode->i_size);
|
truncate_pagecache(inode, inode->i_size);
|
||||||
if (shrink)
|
if (shrink) {
|
||||||
ext4_truncate(inode);
|
rc = ext4_truncate(inode);
|
||||||
|
if (rc)
|
||||||
|
error = rc;
|
||||||
|
}
|
||||||
up_write(&EXT4_I(inode)->i_mmap_sem);
|
up_write(&EXT4_I(inode)->i_mmap_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rc) {
|
if (!error) {
|
||||||
setattr_copy(inode, attr);
|
setattr_copy(inode, attr);
|
||||||
mark_inode_dirty(inode);
|
mark_inode_dirty(inode);
|
||||||
}
|
}
|
||||||
|
@ -5222,7 +5233,7 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
|
||||||
if (orphan && inode->i_nlink)
|
if (orphan && inode->i_nlink)
|
||||||
ext4_orphan_del(NULL, inode);
|
ext4_orphan_del(NULL, inode);
|
||||||
|
|
||||||
if (!rc && (ia_valid & ATTR_MODE))
|
if (!error && (ia_valid & ATTR_MODE))
|
||||||
rc = posix_acl_chmod(inode, inode->i_mode);
|
rc = posix_acl_chmod(inode, inode->i_mode);
|
||||||
|
|
||||||
err_out:
|
err_out:
|
||||||
|
|
|
@ -248,8 +248,11 @@ static int ext4_ioctl_setflags(struct inode *inode,
|
||||||
err = -EOPNOTSUPP;
|
err = -EOPNOTSUPP;
|
||||||
goto flags_out;
|
goto flags_out;
|
||||||
}
|
}
|
||||||
} else if (oldflags & EXT4_EOFBLOCKS_FL)
|
} else if (oldflags & EXT4_EOFBLOCKS_FL) {
|
||||||
ext4_truncate(inode);
|
err = ext4_truncate(inode);
|
||||||
|
if (err)
|
||||||
|
goto flags_out;
|
||||||
|
}
|
||||||
|
|
||||||
handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
|
handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
|
||||||
if (IS_ERR(handle)) {
|
if (IS_ERR(handle)) {
|
||||||
|
|
|
@ -2330,7 +2330,7 @@ static void ext4_orphan_cleanup(struct super_block *sb,
|
||||||
struct ext4_super_block *es)
|
struct ext4_super_block *es)
|
||||||
{
|
{
|
||||||
unsigned int s_flags = sb->s_flags;
|
unsigned int s_flags = sb->s_flags;
|
||||||
int nr_orphans = 0, nr_truncates = 0;
|
int ret, nr_orphans = 0, nr_truncates = 0;
|
||||||
#ifdef CONFIG_QUOTA
|
#ifdef CONFIG_QUOTA
|
||||||
int i;
|
int i;
|
||||||
#endif
|
#endif
|
||||||
|
@ -2412,7 +2412,9 @@ static void ext4_orphan_cleanup(struct super_block *sb,
|
||||||
inode->i_ino, inode->i_size);
|
inode->i_ino, inode->i_size);
|
||||||
inode_lock(inode);
|
inode_lock(inode);
|
||||||
truncate_inode_pages(inode->i_mapping, inode->i_size);
|
truncate_inode_pages(inode->i_mapping, inode->i_size);
|
||||||
ext4_truncate(inode);
|
ret = ext4_truncate(inode);
|
||||||
|
if (ret)
|
||||||
|
ext4_std_error(inode->i_sb, ret);
|
||||||
inode_unlock(inode);
|
inode_unlock(inode);
|
||||||
nr_truncates++;
|
nr_truncates++;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue