NFS: Cleanup file handle allocations in fs/nfs/super.c
[safe/jmp/linux-2.6] / fs / btrfs / compression.c
index ad72741..396039b 100644 (file)
 #include <linux/time.h>
 #include <linux/init.h>
 #include <linux/string.h>
-#include <linux/smp_lock.h>
 #include <linux/backing-dev.h>
 #include <linux/mpage.h>
 #include <linux/swap.h>
 #include <linux/writeback.h>
 #include <linux/bit_spinlock.h>
-#include <linux/version.h>
-#include <linux/pagevec.h>
+#include <linux/slab.h>
 #include "compat.h"
 #include "ctree.h"
 #include "disk-io.h"
@@ -124,8 +122,7 @@ static int check_compressed_csum(struct inode *inode,
        u32 csum;
        u32 *cb_sum = &cb->sums;
 
-       if (btrfs_test_opt(root, NODATASUM) ||
-           btrfs_test_flag(inode, NODATASUM))
+       if (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)
                return 0;
 
        for (i = 0; i < cb->nr_pages; i++) {
@@ -138,7 +135,8 @@ static int check_compressed_csum(struct inode *inode,
                kunmap_atomic(kaddr, KM_USER0);
 
                if (csum != *cb_sum) {
-                       printk("btrfs csum failed ino %lu extent %llu csum %u "
+                       printk(KERN_INFO "btrfs csum failed ino %lu "
+                              "extent %llu csum %u "
                               "wanted %u mirror %d\n", inode->i_ino,
                               (unsigned long long)disk_start,
                               csum, *cb_sum, cb->mirror_num);
@@ -218,7 +216,7 @@ csum_failed:
                 * we have verified the checksum already, set page
                 * checked so the end_io handlers know about it
                 */
-               while(bio_index < cb->orig_bio->bi_vcnt) {
+               while (bio_index < cb->orig_bio->bi_vcnt) {
                        SetPageChecked(bvec->bv_page);
                        bvec++;
                        bio_index++;
@@ -247,7 +245,7 @@ static noinline int end_compressed_writeback(struct inode *inode, u64 start,
        int i;
        int ret;
 
-       while(nr_pages > 0) {
+       while (nr_pages > 0) {
                ret = find_get_pages_contig(inode->i_mapping, index,
                                     min_t(unsigned long,
                                     nr_pages, ARRAY_SIZE(pages)), pages);
@@ -447,7 +445,6 @@ static noinline int add_ra_bio_pages(struct inode *inode,
        unsigned long nr_pages = 0;
        struct extent_map *em;
        struct address_space *mapping = inode->i_mapping;
-       struct pagevec pvec;
        struct extent_map_tree *em_tree;
        struct extent_io_tree *tree;
        u64 end;
@@ -463,8 +460,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
 
        end_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT;
 
-       pagevec_init(&pvec, 0);
-       while(last_offset < compressed_end) {
+       while (last_offset < compressed_end) {
                page_index = last_offset >> PAGE_CACHE_SHIFT;
 
                if (page_index > end_index)
@@ -480,26 +476,17 @@ static noinline int add_ra_bio_pages(struct inode *inode,
                        goto next;
                }
 
-               page = alloc_page(mapping_gfp_mask(mapping) | GFP_NOFS);
+               page = __page_cache_alloc(mapping_gfp_mask(mapping) &
+                                                               ~__GFP_FS);
                if (!page)
                        break;
 
-               page->index = page_index;
-               /*
-                * what we want to do here is call add_to_page_cache_lru,
-                * but that isn't exported, so we reproduce it here
-                */
-               if (add_to_page_cache(page, mapping,
-                                     page->index, GFP_NOFS)) {
+               if (add_to_page_cache_lru(page, mapping, page_index,
+                                                               GFP_NOFS)) {
                        page_cache_release(page);
                        goto next;
                }
 
-               /* open coding of lru_cache_add, also not exported */
-               page_cache_get(page);
-               if (!pagevec_add(&pvec, page))
-                       __pagevec_lru_add_file(&pvec);
-
                end = last_offset + PAGE_CACHE_SIZE - 1;
                /*
                 * at this point, we have a locked page in the page cache
@@ -508,10 +495,10 @@ static noinline int add_ra_bio_pages(struct inode *inode,
                 */
                set_page_extent_mapped(page);
                lock_extent(tree, last_offset, end, GFP_NOFS);
-               spin_lock(&em_tree->lock);
+               read_lock(&em_tree->lock);
                em = lookup_extent_mapping(em_tree, last_offset,
                                           PAGE_CACHE_SIZE);
-               spin_unlock(&em_tree->lock);
+               read_unlock(&em_tree->lock);
 
                if (!em || last_offset < em->start ||
                    (last_offset + PAGE_CACHE_SIZE > extent_map_end(em)) ||
@@ -553,8 +540,6 @@ static noinline int add_ra_bio_pages(struct inode *inode,
 next:
                last_offset += PAGE_CACHE_SIZE;
        }
-       if (pagevec_count(&pvec))
-               __pagevec_lru_add_file(&pvec);
        return 0;
 }
 
@@ -595,11 +580,11 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
        em_tree = &BTRFS_I(inode)->extent_tree;
 
        /* we need the actual starting offset of this extent in the file */
-       spin_lock(&em_tree->lock);
+       read_lock(&em_tree->lock);
        em = lookup_extent_mapping(em_tree,
                                   page_offset(bio->bi_io_vec->bv_page),
                                   PAGE_CACHE_SIZE);
-       spin_unlock(&em_tree->lock);
+       read_unlock(&em_tree->lock);
 
        compressed_len = em->block_len;
        cb = kmalloc(compressed_bio_size(root, compressed_len), GFP_NOFS);
@@ -671,8 +656,7 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
                         */
                        atomic_inc(&cb->pending_bios);
 
-                       if (!btrfs_test_opt(root, NODATASUM) &&
-                           !btrfs_test_flag(inode, NODATASUM)) {
+                       if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM)) {
                                btrfs_lookup_bio_sums(root, inode, comp_bio,
                                                      sums);
                        }
@@ -699,10 +683,8 @@ int btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
        ret = btrfs_bio_wq_end_io(root->fs_info, comp_bio, 0);
        BUG_ON(ret);
 
-       if (!btrfs_test_opt(root, NODATASUM) &&
-           !btrfs_test_flag(inode, NODATASUM)) {
+       if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM))
                btrfs_lookup_bio_sums(root, inode, comp_bio, sums);
-       }
 
        ret = btrfs_map_bio(root, READ, comp_bio, mirror_num, 0);
        BUG_ON(ret);