Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

jbd2: preserve original nofs flag during journal restart

When a transaction starts, start_this_handle() saves current
PF_MEMALLOC_NOFS value so that it can be restored at journal stop time.
Journal restart is a special case that calls start_this_handle() without
stopping the transaction. start_this_handle() isn't aware that the
original value is already stored so it overwrites it with current value.

For instance, a call sequence like below leaves PF_MEMALLOC_NOFS flag set
at the end:

jbd2_journal_start()
jbd2__journal_restart()
jbd2_journal_stop()

Make jbd2__journal_restart() restore the original value before calling
start_this_handle().

Fixes: 81378da64de6 ("jbd2: mark the transaction context with the scope GFP_NOFS context")
Signed-off-by: Tahsin Erdogan <tahsin@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>

authored by

Tahsin Erdogan and committed by
Theodore Ts'o
b4709067 964edf66

+6
+6
fs/jbd2/transaction.c
··· 680 680 681 681 rwsem_release(&journal->j_trans_commit_map, 1, _THIS_IP_); 682 682 handle->h_buffer_credits = nblocks; 683 + /* 684 + * Restore the original nofs context because the journal restart 685 + * is basically the same thing as journal stop and start. 686 + * start_this_handle will start a new nofs context. 687 + */ 688 + memalloc_nofs_restore(handle->saved_alloc_context); 683 689 ret = start_this_handle(journal, handle, gfp_mask); 684 690 return ret; 685 691 }