Skip to content

Commit 0add491

Browse files
Eric Whitneytytso
authored andcommitted
ext4: remove extent cache entries when truncating inline data
Conditionally remove all cached extents belonging to an inode when truncating its inline data. It's only necessary to attempt to remove cached extents when a conversion from inline to extent storage has been initiated (!EXT4_STATE_MAY_INLINE_DATA). This avoids unnecessary es lock overhead in the more common inline case. Signed-off-by: Eric Whitney <[email protected]> Signed-off-by: Theodore Ts'o <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 11ef08c commit 0add491

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

fs/ext4/inline.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/iomap.h>
88
#include <linux/fiemap.h>
99
#include <linux/iversion.h>
10+
#include <linux/backing-dev.h>
1011

1112
#include "ext4_jbd2.h"
1213
#include "ext4.h"
@@ -1918,6 +1919,24 @@ int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
19181919
EXT4_I(inode)->i_disksize = i_size;
19191920

19201921
if (i_size < inline_size) {
1922+
/*
1923+
* if there's inline data to truncate and this file was
1924+
* converted to extents after that inline data was written,
1925+
* the extent status cache must be cleared to avoid leaving
1926+
* behind stale delayed allocated extent entries
1927+
*/
1928+
if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
1929+
retry:
1930+
err = ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
1931+
if (err == -ENOMEM) {
1932+
cond_resched();
1933+
congestion_wait(BLK_RW_ASYNC, HZ/50);
1934+
goto retry;
1935+
}
1936+
if (err)
1937+
goto out_error;
1938+
}
1939+
19211940
/* Clear the content in the xattr space. */
19221941
if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) {
19231942
if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0)

0 commit comments

Comments
 (0)