diff options
Diffstat (limited to 'fs/btrfs/ioctl.c')
-rw-r--r-- | fs/btrfs/ioctl.c | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 3066da468c6d..6a706e691377 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c | |||
@@ -587,19 +587,9 @@ static int btrfs_defrag_file(struct file *file, | |||
587 | if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) | 587 | if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) |
588 | BTRFS_I(inode)->force_compress = 1; | 588 | BTRFS_I(inode)->force_compress = 1; |
589 | 589 | ||
590 | ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE); | 590 | ret = btrfs_delalloc_reserve_space(inode, PAGE_CACHE_SIZE); |
591 | if (ret) { | 591 | if (ret) |
592 | ret = -ENOSPC; | 592 | goto err_unlock; |
593 | break; | ||
594 | } | ||
595 | |||
596 | ret = btrfs_reserve_metadata_for_delalloc(root, inode, 1); | ||
597 | if (ret) { | ||
598 | btrfs_free_reserved_data_space(root, inode, | ||
599 | PAGE_CACHE_SIZE); | ||
600 | ret = -ENOSPC; | ||
601 | break; | ||
602 | } | ||
603 | again: | 593 | again: |
604 | if (inode->i_size == 0 || | 594 | if (inode->i_size == 0 || |
605 | i > ((inode->i_size - 1) >> PAGE_CACHE_SHIFT)) { | 595 | i > ((inode->i_size - 1) >> PAGE_CACHE_SHIFT)) { |
@@ -608,8 +598,10 @@ again: | |||
608 | } | 598 | } |
609 | 599 | ||
610 | page = grab_cache_page(inode->i_mapping, i); | 600 | page = grab_cache_page(inode->i_mapping, i); |
611 | if (!page) | 601 | if (!page) { |
602 | ret = -ENOMEM; | ||
612 | goto err_reservations; | 603 | goto err_reservations; |
604 | } | ||
613 | 605 | ||
614 | if (!PageUptodate(page)) { | 606 | if (!PageUptodate(page)) { |
615 | btrfs_readpage(NULL, page); | 607 | btrfs_readpage(NULL, page); |
@@ -617,6 +609,7 @@ again: | |||
617 | if (!PageUptodate(page)) { | 609 | if (!PageUptodate(page)) { |
618 | unlock_page(page); | 610 | unlock_page(page); |
619 | page_cache_release(page); | 611 | page_cache_release(page); |
612 | ret = -EIO; | ||
620 | goto err_reservations; | 613 | goto err_reservations; |
621 | } | 614 | } |
622 | } | 615 | } |
@@ -630,8 +623,7 @@ again: | |||
630 | wait_on_page_writeback(page); | 623 | wait_on_page_writeback(page); |
631 | 624 | ||
632 | if (PageDirty(page)) { | 625 | if (PageDirty(page)) { |
633 | btrfs_free_reserved_data_space(root, inode, | 626 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); |
634 | PAGE_CACHE_SIZE); | ||
635 | goto loop_unlock; | 627 | goto loop_unlock; |
636 | } | 628 | } |
637 | 629 | ||
@@ -669,7 +661,6 @@ loop_unlock: | |||
669 | page_cache_release(page); | 661 | page_cache_release(page); |
670 | mutex_unlock(&inode->i_mutex); | 662 | mutex_unlock(&inode->i_mutex); |
671 | 663 | ||
672 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
673 | balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1); | 664 | balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1); |
674 | i++; | 665 | i++; |
675 | } | 666 | } |
@@ -699,9 +690,9 @@ loop_unlock: | |||
699 | return 0; | 690 | return 0; |
700 | 691 | ||
701 | err_reservations: | 692 | err_reservations: |
693 | btrfs_delalloc_release_space(inode, PAGE_CACHE_SIZE); | ||
694 | err_unlock: | ||
702 | mutex_unlock(&inode->i_mutex); | 695 | mutex_unlock(&inode->i_mutex); |
703 | btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); | ||
704 | btrfs_unreserve_metadata_for_delalloc(root, inode, 1); | ||
705 | return ret; | 696 | return ret; |
706 | } | 697 | } |
707 | 698 | ||