Skip to content

Commit 01daf94

Browse files
committed
ext4: propagate error values from ext4_inline_data_truncate()
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent b907f2d commit 01daf94

3 files changed

Lines changed: 27 additions & 19 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3023,7 +3023,7 @@ extern int ext4_inline_data_fiemap(struct inode *inode,
30233023
extern int ext4_try_to_evict_inline_data(handle_t *handle,
30243024
struct inode *inode,
30253025
int needed);
3026-
extern void ext4_inline_data_truncate(struct inode *inode, int *has_inline);
3026+
extern int ext4_inline_data_truncate(struct inode *inode, int *has_inline);
30273027

30283028
extern int ext4_convert_inline_data(struct inode *inode);
30293029

‎fs/ext4/inline.c‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,10 +1896,10 @@ int ext4_try_to_evict_inline_data(handle_t *handle,
18961896
return error;
18971897
}
18981898

1899-
void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
1899+
int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
19001900
{
19011901
handle_t *handle;
1902-
int inline_size, value_len, needed_blocks, no_expand;
1902+
int inline_size, value_len, needed_blocks, no_expand, err = 0;
19031903
size_t i_size;
19041904
void *value = NULL;
19051905
struct ext4_xattr_ibody_find is = {
@@ -1914,19 +1914,19 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
19141914
needed_blocks = ext4_writepage_trans_blocks(inode);
19151915
handle = ext4_journal_start(inode, EXT4_HT_INODE, needed_blocks);
19161916
if (IS_ERR(handle))
1917-
return;
1917+
return PTR_ERR(handle);
19181918

19191919
ext4_write_lock_xattr(inode, &no_expand);
19201920
if (!ext4_has_inline_data(inode)) {
19211921
*has_inline = 0;
19221922
ext4_journal_stop(handle);
1923-
return;
1923+
return 0;
19241924
}
19251925

1926-
if (ext4_orphan_add(handle, inode))
1926+
if ((err = ext4_orphan_add(handle, inode)) != 0)
19271927
goto out;
19281928

1929-
if (ext4_get_inode_loc(inode, &is.iloc))
1929+
if ((err = ext4_get_inode_loc(inode, &is.iloc)) != 0)
19301930
goto out;
19311931

19321932
down_write(&EXT4_I(inode)->i_data_sem);
@@ -1937,24 +1937,29 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
19371937
if (i_size < inline_size) {
19381938
/* Clear the content in the xattr space. */
19391939
if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) {
1940-
if (ext4_xattr_ibody_find(inode, &i, &is))
1940+
if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0)
19411941
goto out_error;
19421942

19431943
BUG_ON(is.s.not_found);
19441944

19451945
value_len = le32_to_cpu(is.s.here->e_value_size);
19461946
value = kmalloc(value_len, GFP_NOFS);
1947-
if (!value)
1947+
if (!value) {
1948+
err = -ENOMEM;
19481949
goto out_error;
1950+
}
19491951

1950-
if (ext4_xattr_ibody_get(inode, i.name_index, i.name,
1951-
value, value_len))
1952+
err = ext4_xattr_ibody_get(inode, i.name_index,
1953+
i.name, value, value_len);
1954+
if (err <= 0)
19521955
goto out_error;
19531956

19541957
i.value = value;
19551958
i.value_len = i_size > EXT4_MIN_INLINE_DATA_SIZE ?
19561959
i_size - EXT4_MIN_INLINE_DATA_SIZE : 0;
1957-
if (ext4_xattr_ibody_inline_set(handle, inode, &i, &is))
1960+
err = ext4_xattr_ibody_inline_set(handle, inode,
1961+
&i, &is);
1962+
if (err)
19581963
goto out_error;
19591964
}
19601965

@@ -1979,13 +1984,14 @@ void ext4_inline_data_truncate(struct inode *inode, int *has_inline)
19791984
if (inode->i_nlink)
19801985
ext4_orphan_del(handle, inode);
19811986

1982-
inode->i_mtime = inode->i_ctime = current_time(inode);
1983-
ext4_mark_inode_dirty(handle, inode);
1984-
if (IS_SYNC(inode))
1985-
ext4_handle_sync(handle);
1986-
1987+
if (err == 0) {
1988+
inode->i_mtime = inode->i_ctime = current_time(inode);
1989+
err = ext4_mark_inode_dirty(handle, inode);
1990+
if (IS_SYNC(inode))
1991+
ext4_handle_sync(handle);
1992+
}
19871993
ext4_journal_stop(handle);
1988-
return;
1994+
return err;
19891995
}
19901996

19911997
int ext4_convert_inline_data(struct inode *inode)

‎fs/ext4/inode.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4222,7 +4222,9 @@ int ext4_truncate(struct inode *inode)
42224222
if (ext4_has_inline_data(inode)) {
42234223
int has_inline = 1;
42244224

4225-
ext4_inline_data_truncate(inode, &has_inline);
4225+
err = ext4_inline_data_truncate(inode, &has_inline);
4226+
if (err)
4227+
return err;
42264228
if (has_inline)
42274229
return 0;
42284230
}

0 commit comments

Comments
 (0)