Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b4df2030 authored by Theodore Ts'o's avatar Theodore Ts'o
Browse files

ext4: Fix potential truncate BUG due to i_prealloc_list being non-empty



We need to call ext4_discard_reservation() earlier in ext4_truncate(),
to avoid a BUG() in ext4_mb_return_to_preallocation(), which is called
(ultimately) by ext4_free_blocks().  So we must ditch the blocks on
i_prealloc_list before we start freeing the data blocks.

Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent bf068ee2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -3494,6 +3494,9 @@ void ext4_truncate(struct inode *inode)
	 * modify the block allocation tree.
	 */
	down_write(&ei->i_data_sem);

	ext4_discard_reservation(inode);

	/*
	 * The orphan list entry will now protect us from any crash which
	 * occurs before the truncate completes, so it is now safe to propagate
@@ -3563,8 +3566,6 @@ void ext4_truncate(struct inode *inode)
		;
	}

	ext4_discard_reservation(inode);

	up_write(&ei->i_data_sem);
	inode->i_mtime = inode->i_ctime = ext4_current_time(inode);
	ext4_mark_inode_dirty(handle, inode);