ordered-data.c (93858769172c4e3678917810e9d5de360eb991cc) | ordered-data.c (b02441999efcc6152b87cd58e7970bb7843f76cf) |
---|---|
1/* 2 * Copyright (C) 2007 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 551 unchanged lines hidden (view full) --- 560 btrfs_start_ordered_extent(ordered->inode, ordered, 1); 561 complete(&ordered->completion); 562} 563 564/* 565 * wait for all the ordered extents in a root. This is done when balancing 566 * space between drives. 567 */ | 1/* 2 * Copyright (C) 2007 Oracle. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public 6 * License v2 as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, --- 551 unchanged lines hidden (view full) --- 560 btrfs_start_ordered_extent(ordered->inode, ordered, 1); 561 complete(&ordered->completion); 562} 563 564/* 565 * wait for all the ordered extents in a root. This is done when balancing 566 * space between drives. 567 */ |
568void btrfs_wait_ordered_extents(struct btrfs_root *root) | 568int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr) |
569{ 570 struct list_head splice, works; 571 struct btrfs_ordered_extent *ordered, *next; | 569{ 570 struct list_head splice, works; 571 struct btrfs_ordered_extent *ordered, *next; |
572 int count = 0; |
|
572 573 INIT_LIST_HEAD(&splice); 574 INIT_LIST_HEAD(&works); 575 576 mutex_lock(&root->fs_info->ordered_operations_mutex); 577 spin_lock(&root->ordered_extent_lock); 578 list_splice_init(&root->ordered_extents, &splice); | 573 574 INIT_LIST_HEAD(&splice); 575 INIT_LIST_HEAD(&works); 576 577 mutex_lock(&root->fs_info->ordered_operations_mutex); 578 spin_lock(&root->ordered_extent_lock); 579 list_splice_init(&root->ordered_extents, &splice); |
579 while (!list_empty(&splice)) { | 580 while (!list_empty(&splice) && nr) { |
580 ordered = list_first_entry(&splice, struct btrfs_ordered_extent, 581 root_extent_list); 582 list_move_tail(&ordered->root_extent_list, 583 &root->ordered_extents); 584 atomic_inc(&ordered->refs); 585 spin_unlock(&root->ordered_extent_lock); 586 587 ordered->flush_work.func = btrfs_run_ordered_extent_work; 588 list_add_tail(&ordered->work_list, &works); 589 btrfs_queue_worker(&root->fs_info->flush_workers, 590 &ordered->flush_work); 591 592 cond_resched(); 593 spin_lock(&root->ordered_extent_lock); | 581 ordered = list_first_entry(&splice, struct btrfs_ordered_extent, 582 root_extent_list); 583 list_move_tail(&ordered->root_extent_list, 584 &root->ordered_extents); 585 atomic_inc(&ordered->refs); 586 spin_unlock(&root->ordered_extent_lock); 587 588 ordered->flush_work.func = btrfs_run_ordered_extent_work; 589 list_add_tail(&ordered->work_list, &works); 590 btrfs_queue_worker(&root->fs_info->flush_workers, 591 &ordered->flush_work); 592 593 cond_resched(); 594 spin_lock(&root->ordered_extent_lock); |
595 if (nr != -1) 596 nr--; 597 count++; |
|
594 } | 598 } |
599 list_splice_tail(&splice, &root->ordered_extents); |
|
595 spin_unlock(&root->ordered_extent_lock); 596 597 list_for_each_entry_safe(ordered, next, &works, work_list) { 598 list_del_init(&ordered->work_list); 599 wait_for_completion(&ordered->completion); 600 btrfs_put_ordered_extent(ordered); 601 cond_resched(); 602 } 603 mutex_unlock(&root->fs_info->ordered_operations_mutex); | 600 spin_unlock(&root->ordered_extent_lock); 601 602 list_for_each_entry_safe(ordered, next, &works, work_list) { 603 list_del_init(&ordered->work_list); 604 wait_for_completion(&ordered->completion); 605 btrfs_put_ordered_extent(ordered); 606 cond_resched(); 607 } 608 mutex_unlock(&root->fs_info->ordered_operations_mutex); |
609 610 return count; |
|
604} 605 | 611} 612 |
606void btrfs_wait_all_ordered_extents(struct btrfs_fs_info *fs_info) | 613void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr) |
607{ 608 struct btrfs_root *root; 609 struct list_head splice; | 614{ 615 struct btrfs_root *root; 616 struct list_head splice; |
617 int done; |
|
610 611 INIT_LIST_HEAD(&splice); 612 613 spin_lock(&fs_info->ordered_root_lock); 614 list_splice_init(&fs_info->ordered_roots, &splice); | 618 619 INIT_LIST_HEAD(&splice); 620 621 spin_lock(&fs_info->ordered_root_lock); 622 list_splice_init(&fs_info->ordered_roots, &splice); |
615 while (!list_empty(&splice)) { | 623 while (!list_empty(&splice) && nr) { |
616 root = list_first_entry(&splice, struct btrfs_root, 617 ordered_root); 618 root = btrfs_grab_fs_root(root); 619 BUG_ON(!root); 620 list_move_tail(&root->ordered_root, 621 &fs_info->ordered_roots); 622 spin_unlock(&fs_info->ordered_root_lock); 623 | 624 root = list_first_entry(&splice, struct btrfs_root, 625 ordered_root); 626 root = btrfs_grab_fs_root(root); 627 BUG_ON(!root); 628 list_move_tail(&root->ordered_root, 629 &fs_info->ordered_roots); 630 spin_unlock(&fs_info->ordered_root_lock); 631 |
624 btrfs_wait_ordered_extents(root); | 632 done = btrfs_wait_ordered_extents(root, nr); |
625 btrfs_put_fs_root(root); 626 627 spin_lock(&fs_info->ordered_root_lock); | 633 btrfs_put_fs_root(root); 634 635 spin_lock(&fs_info->ordered_root_lock); |
636 if (nr != -1) { 637 nr -= done; 638 WARN_ON(nr < 0); 639 } |
|
628 } 629 spin_unlock(&fs_info->ordered_root_lock); 630} 631 632/* 633 * this is used during transaction commit to write all the inodes 634 * added to the ordered operation list. These files must be fully on 635 * disk before the transaction commits. --- 483 unchanged lines hidden --- | 640 } 641 spin_unlock(&fs_info->ordered_root_lock); 642} 643 644/* 645 * this is used during transaction commit to write all the inodes 646 * added to the ordered operation list. These files must be fully on 647 * disk before the transaction commits. --- 483 unchanged lines hidden --- |