|
21 | 21 | #include "dev-replace.h"
|
22 | 22 | #include "qgroup.h"
|
23 | 23 | #include "block-group.h"
|
| 24 | +#include "space-info.h" |
24 | 25 |
|
25 | 26 | #define BTRFS_ROOT_TRANS_TAG 0
|
26 | 27 |
|
@@ -523,6 +524,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
|
523 | 524 | u64 num_bytes = 0;
|
524 | 525 | u64 qgroup_reserved = 0;
|
525 | 526 | bool reloc_reserved = false;
|
| 527 | + bool do_chunk_alloc = false; |
526 | 528 | int ret;
|
527 | 529 |
|
528 | 530 | /* Send isn't supposed to start transactions. */
|
@@ -585,6 +587,9 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
|
585 | 587 | delayed_refs_bytes);
|
586 | 588 | num_bytes -= delayed_refs_bytes;
|
587 | 589 | }
|
| 590 | + |
| 591 | + if (rsv->space_info->force_alloc) |
| 592 | + do_chunk_alloc = true; |
588 | 593 | } else if (num_items == 0 && flush == BTRFS_RESERVE_FLUSH_ALL &&
|
589 | 594 | !delayed_refs_rsv->full) {
|
590 | 595 | /*
|
@@ -666,6 +671,19 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
|
666 | 671 | if (!current->journal_info)
|
667 | 672 | current->journal_info = h;
|
668 | 673 |
|
| 674 | + /* |
| 675 | + * If the space_info is marked ALLOC_FORCE then we'll get upgraded to |
| 676 | + * ALLOC_FORCE the first run through, and then we won't allocate for |
| 677 | + * anybody else who races in later. We don't care about the return |
| 678 | + * value here. |
| 679 | + */ |
| 680 | + if (do_chunk_alloc && num_bytes) { |
| 681 | + u64 flags = h->block_rsv->space_info->flags; |
| 682 | + |
| 683 | + btrfs_chunk_alloc(h, btrfs_get_alloc_profile(fs_info, flags), |
| 684 | + CHUNK_ALLOC_NO_FORCE); |
| 685 | + } |
| 686 | + |
669 | 687 | /*
|
670 | 688 | * btrfs_record_root_in_trans() needs to alloc new extents, and may
|
671 | 689 | * call btrfs_join_transaction() while we're also starting a
|
|
0 commit comments