|
29 | 29 | #include <linux/backing-dev.h>
|
30 | 30 | #include <linux/bug.h>
|
31 | 31 | #include <linux/module.h>
|
| 32 | +#include <linux/sched/mm.h> |
32 | 33 |
|
33 | 34 | #include <trace/events/jbd2.h>
|
34 | 35 |
|
@@ -388,6 +389,11 @@ static int start_this_handle(journal_t *journal, handle_t *handle,
|
388 | 389 |
|
389 | 390 | rwsem_acquire_read(&journal->j_trans_commit_map, 0, 0, _THIS_IP_);
|
390 | 391 | jbd2_journal_free_transaction(new_transaction);
|
| 392 | + /* |
| 393 | + * Ensure that no allocations done while the transaction is open are |
| 394 | + * going to recurse back to the fs layer. |
| 395 | + */ |
| 396 | + handle->saved_alloc_context = memalloc_nofs_save(); |
391 | 397 | return 0;
|
392 | 398 | }
|
393 | 399 |
|
@@ -466,6 +472,7 @@ handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int rsv_blocks,
|
466 | 472 | trace_jbd2_handle_start(journal->j_fs_dev->bd_dev,
|
467 | 473 | handle->h_transaction->t_tid, type,
|
468 | 474 | line_no, nblocks);
|
| 475 | + |
469 | 476 | return handle;
|
470 | 477 | }
|
471 | 478 | EXPORT_SYMBOL(jbd2__journal_start);
|
@@ -1760,6 +1767,11 @@ int jbd2_journal_stop(handle_t *handle)
|
1760 | 1767 | if (handle->h_rsv_handle)
|
1761 | 1768 | jbd2_journal_free_reserved(handle->h_rsv_handle);
|
1762 | 1769 | free_and_exit:
|
| 1770 | + /* |
| 1771 | + * Scope of the GFP_NOFS context is over here and so we can restore the |
| 1772 | + * original alloc context. |
| 1773 | + */ |
| 1774 | + memalloc_nofs_restore(handle->saved_alloc_context); |
1763 | 1775 | jbd2_free_handle(handle);
|
1764 | 1776 | return err;
|
1765 | 1777 | }
|
|
0 commit comments