btrfs: Remove delalloc_end argument from extent_clear_unlock_delalloc
[linux-2.6-block.git] / fs / btrfs / inode.c
index ee582a36653d30ee1f833153f9bc00225f7978ae..d038fc6b3e2fed3f2f722cb92c754699ce58ed07 100644 (file)
@@ -80,9 +80,9 @@ static int btrfs_truncate(struct inode *inode, bool skip_writeback);
 static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent);
 static noinline int cow_file_range(struct inode *inode,
                                   struct page *locked_page,
-                                  u64 start, u64 end, u64 delalloc_end,
-                                  int *page_started, unsigned long *nr_written,
-                                  int unlock, struct btrfs_dedupe_hash *hash);
+                                  u64 start, u64 end, int *page_started,
+                                  unsigned long *nr_written, int unlock,
+                                  struct btrfs_dedupe_hash *hash);
 static struct extent_map *create_io_em(struct inode *inode, u64 start, u64 len,
                                       u64 orig_start, u64 block_start,
                                       u64 block_len, u64 orig_block_len,
@@ -462,8 +462,7 @@ static inline void inode_should_defrag(struct btrfs_inode *inode,
  * are written in the same order that the flusher thread sent them
  * down.
  */
-static noinline void compress_file_range(struct async_chunk *async_chunk,
-                                        int *num_added)
+static noinline int compress_file_range(struct async_chunk *async_chunk)
 {
        struct inode *inode = async_chunk->inode;
        struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
@@ -479,6 +478,7 @@ static noinline void compress_file_range(struct async_chunk *async_chunk,
        int i;
        int will_compress;
        int compress_type = fs_info->compress_type;
+       int compressed_extents = 0;
        int redirty = 0;
 
        inode_should_defrag(BTRFS_I(inode), start, end, end - start + 1,
@@ -615,14 +615,21 @@ cont:
                         * our outstanding extent for clearing delalloc for this
                         * range.
                         */
-                       extent_clear_unlock_delalloc(inode, start, end, end,
-                                                    NULL, clear_flags,
+                       extent_clear_unlock_delalloc(inode, start, end, NULL,
+                                                    clear_flags,
                                                     PAGE_UNLOCK |
                                                     PAGE_CLEAR_DIRTY |
                                                     PAGE_SET_WRITEBACK |
                                                     page_error_op |
                                                     PAGE_END_WRITEBACK);
-                       goto free_pages_out;
+
+                       for (i = 0; i < nr_pages; i++) {
+                               WARN_ON(pages[i]->mapping);
+                               put_page(pages[i]);
+                       }
+                       kfree(pages);
+
+                       return 0;
                }
        }
 
@@ -641,7 +648,7 @@ cont:
                 */
                total_in = ALIGN(total_in, PAGE_SIZE);
                if (total_compressed + blocksize <= total_in) {
-                       *num_added += 1;
+                       compressed_extents++;
 
                        /*
                         * The async work queues will take care of doing actual
@@ -658,7 +665,7 @@ cont:
                                cond_resched();
                                goto again;
                        }
-                       return;
+                       return compressed_extents;
                }
        }
        if (pages) {
@@ -697,16 +704,9 @@ cleanup_and_bail_uncompressed:
                extent_range_redirty_for_io(inode, start, end);
        add_async_extent(async_chunk, start, end - start + 1, 0, NULL, 0,
                         BTRFS_COMPRESS_NONE);
-       *num_added += 1;
+       compressed_extents++;
 
-       return;
-
-free_pages_out:
-       for (i = 0; i < nr_pages; i++) {
-               WARN_ON(pages[i]->mapping);
-               put_page(pages[i]);
-       }
-       kfree(pages);
+       return compressed_extents;
 }
 
 static void free_async_extent_pages(struct async_extent *async_extent)
@@ -762,8 +762,6 @@ retry:
                                             async_extent->start,
                                             async_extent->start +
                                             async_extent->ram_size - 1,
-                                            async_extent->start +
-                                            async_extent->ram_size - 1,
                                             &page_started, &nr_written, 0,
                                             NULL);
 
@@ -853,8 +851,6 @@ retry:
                 * clear dirty, set writeback and unlock the pages.
                 */
                extent_clear_unlock_delalloc(inode, async_extent->start,
-                               async_extent->start +
-                               async_extent->ram_size - 1,
                                async_extent->start +
                                async_extent->ram_size - 1,
                                NULL, EXTENT_LOCKED | EXTENT_DELALLOC,
@@ -875,7 +871,7 @@ retry:
                        btrfs_writepage_endio_finish_ordered(p, start, end, 0);
 
                        p->mapping = NULL;
-                       extent_clear_unlock_delalloc(inode, start, end, end,
+                       extent_clear_unlock_delalloc(inode, start, end,
                                                     NULL, 0,
                                                     PAGE_END_WRITEBACK |
                                                     PAGE_SET_ERROR);
@@ -891,8 +887,6 @@ out_free_reserve:
        btrfs_free_reserved_extent(fs_info, ins.objectid, ins.offset, 1);
 out_free:
        extent_clear_unlock_delalloc(inode, async_extent->start,
-                                    async_extent->start +
-                                    async_extent->ram_size - 1,
                                     async_extent->start +
                                     async_extent->ram_size - 1,
                                     NULL, EXTENT_LOCKED | EXTENT_DELALLOC |
@@ -953,9 +947,9 @@ static u64 get_extent_allocation_hint(struct inode *inode, u64 start,
  */
 static noinline int cow_file_range(struct inode *inode,
                                   struct page *locked_page,
-                                  u64 start, u64 end, u64 delalloc_end,
-                                  int *page_started, unsigned long *nr_written,
-                                  int unlock, struct btrfs_dedupe_hash *hash)
+                                  u64 start, u64 end, int *page_started,
+                                  unsigned long *nr_written, int unlock,
+                                  struct btrfs_dedupe_hash *hash)
 {
        struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
        struct btrfs_root *root = BTRFS_I(inode)->root;
@@ -994,8 +988,7 @@ static noinline int cow_file_range(struct inode *inode,
                         * our outstanding extent for clearing delalloc for this
                         * range.
                         */
-                       extent_clear_unlock_delalloc(inode, start, end,
-                                    delalloc_end, NULL,
+                       extent_clear_unlock_delalloc(inode, start, end, NULL,
                                     EXTENT_LOCKED | EXTENT_DELALLOC |
                                     EXTENT_DELALLOC_NEW | EXTENT_DEFRAG |
                                     EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
@@ -1078,7 +1071,7 @@ static noinline int cow_file_range(struct inode *inode,
 
                extent_clear_unlock_delalloc(inode, start,
                                             start + ram_size - 1,
-                                            delalloc_end, locked_page,
+                                            locked_page,
                                             EXTENT_LOCKED | EXTENT_DELALLOC,
                                             page_ops);
                if (num_bytes < cur_alloc_size)
@@ -1122,7 +1115,6 @@ out_unlock:
         */
        if (extent_reserved) {
                extent_clear_unlock_delalloc(inode, start,
-                                            start + cur_alloc_size,
                                             start + cur_alloc_size,
                                             locked_page,
                                             clear_bits,
@@ -1131,8 +1123,7 @@ out_unlock:
                if (start >= end)
                        goto out;
        }
-       extent_clear_unlock_delalloc(inode, start, end, delalloc_end,
-                                    locked_page,
+       extent_clear_unlock_delalloc(inode, start, end, locked_page,
                                     clear_bits | EXTENT_CLEAR_DATA_RESV,
                                     page_ops);
        goto out;
@@ -1144,12 +1135,12 @@ out_unlock:
 static noinline void async_cow_start(struct btrfs_work *work)
 {
        struct async_chunk *async_chunk;
-       int num_added = 0;
+       int compressed_extents;
 
        async_chunk = container_of(work, struct async_chunk, work);
 
-       compress_file_range(async_chunk, &num_added);
-       if (num_added == 0) {
+       compressed_extents = compress_file_range(async_chunk);
+       if (compressed_extents == 0) {
                btrfs_add_delayed_iput(async_chunk->inode);
                async_chunk->inode = NULL;
        }
@@ -1235,7 +1226,7 @@ static int cow_file_range_async(struct inode *inode, struct page *locked_page,
                        PAGE_SET_WRITEBACK | PAGE_END_WRITEBACK |
                        PAGE_SET_ERROR;
 
-               extent_clear_unlock_delalloc(inode, start, end, 0, locked_page,
+               extent_clear_unlock_delalloc(inode, start, end, locked_page,
                                             clear_bits, page_ops);
                return -ENOMEM;
        }
@@ -1338,8 +1329,7 @@ static noinline int run_delalloc_nocow(struct inode *inode,
 
        path = btrfs_alloc_path();
        if (!path) {
-               extent_clear_unlock_delalloc(inode, start, end, end,
-                                            locked_page,
+               extent_clear_unlock_delalloc(inode, start, end, locked_page,
                                             EXTENT_LOCKED | EXTENT_DELALLOC |
                                             EXTENT_DO_ACCOUNTING |
                                             EXTENT_DEFRAG, PAGE_UNLOCK |
@@ -1516,7 +1506,7 @@ out_check:
                if (cow_start != (u64)-1) {
                        ret = cow_file_range(inode, locked_page,
                                             cow_start, found_key.offset - 1,
-                                            end, page_started, nr_written, 1,
+                                            page_started, nr_written, 1,
                                             NULL);
                        if (ret) {
                                if (nocow)
@@ -1570,7 +1560,7 @@ out_check:
                                                      num_bytes);
 
                extent_clear_unlock_delalloc(inode, cur_offset,
-                                            cur_offset + num_bytes - 1, end,
+                                            cur_offset + num_bytes - 1,
                                             locked_page, EXTENT_LOCKED |
                                             EXTENT_DELALLOC |
                                             EXTENT_CLEAR_DATA_RESV,
@@ -1595,7 +1585,7 @@ out_check:
 
        if (cow_start != (u64)-1) {
                cur_offset = end;
-               ret = cow_file_range(inode, locked_page, cow_start, end, end,
+               ret = cow_file_range(inode, locked_page, cow_start, end,
                                     page_started, nr_written, 1, NULL);
                if (ret)
                        goto error;
@@ -1603,7 +1593,7 @@ out_check:
 
 error:
        if (ret && cur_offset < end)
-               extent_clear_unlock_delalloc(inode, cur_offset, end, end,
+               extent_clear_unlock_delalloc(inode, cur_offset, end,
                                             locked_page, EXTENT_LOCKED |
                                             EXTENT_DELALLOC | EXTENT_DEFRAG |
                                             EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
@@ -1654,7 +1644,7 @@ int btrfs_run_delalloc_range(struct inode *inode, struct page *locked_page,
                                         page_started, 0, nr_written);
        } else if (!inode_can_compress(inode) ||
                   !inode_need_compress(inode, start, end)) {
-               ret = cow_file_range(inode, locked_page, start, end, end,
+               ret = cow_file_range(inode, locked_page, start, end,
                                      page_started, nr_written, 1, NULL);
        } else {
                set_bit(BTRFS_INODE_HAS_ASYNC_EXTENT,