btrfs: add helpers for compression type and level
[sfrench/cifs-2.6.git] / fs / btrfs / compression.c
index 2955a4ea2fa8cb82a5969274805e9f4abbde5b3d..94a0b0a3a301e880f768576f3b9599be2dddc7c6 100644 (file)
@@ -229,7 +229,6 @@ static noinline void end_compressed_writeback(struct inode *inode,
  */
 static void end_compressed_bio_write(struct bio *bio)
 {
-       struct extent_io_tree *tree;
        struct compressed_bio *cb = bio->bi_private;
        struct inode *inode;
        struct page *page;
@@ -248,14 +247,10 @@ static void end_compressed_bio_write(struct bio *bio)
         * call back into the FS and do all the end_io operations
         */
        inode = cb->inode;
-       tree = &BTRFS_I(inode)->io_tree;
        cb->compressed_pages[0]->mapping = cb->inode->i_mapping;
-       tree->ops->writepage_end_io_hook(cb->compressed_pages[0],
-                                        cb->start,
-                                        cb->start + cb->len - 1,
-                                        NULL,
-                                        bio->bi_status ?
-                                        BLK_STS_OK : BLK_STS_NOTSUPP);
+       btrfs_writepage_endio_finish_ordered(cb->compressed_pages[0],
+                       cb->start, cb->start + cb->len - 1,
+                       bio->bi_status ? BLK_STS_OK : BLK_STS_NOTSUPP);
        cb->compressed_pages[0]->mapping = NULL;
 
        end_compressed_writeback(inode, cb);
@@ -306,7 +301,7 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
        blk_status_t ret;
        int skip_sum = BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM;
 
-       WARN_ON(start & ((u64)PAGE_SIZE - 1));
+       WARN_ON(!PAGE_ALIGNED(start));
        cb = kmalloc(compressed_bio_size(fs_info, compressed_len), GFP_NOFS);
        if (!cb)
                return BLK_STS_RESOURCE;
@@ -337,7 +332,8 @@ blk_status_t btrfs_submit_compressed_write(struct inode *inode, u64 start,
                page = compressed_pages[pg_index];
                page->mapping = inode->i_mapping;
                if (bio->bi_iter.bi_size)
-                       submit = btrfs_merge_bio_hook(page, 0, PAGE_SIZE, bio, 0);
+                       submit = btrfs_bio_fits_in_stripe(page, PAGE_SIZE, bio,
+                                                         0);
 
                page->mapping = NULL;
                if (submit || bio_add_page(bio, page, PAGE_SIZE, 0) <
@@ -481,7 +477,7 @@ static noinline int add_ra_bio_pages(struct inode *inode,
 
                if (page->index == end_index) {
                        char *userpage;
-                       size_t zero_offset = isize & (PAGE_SIZE - 1);
+                       size_t zero_offset = offset_in_page(isize);
 
                        if (zero_offset) {
                                int zeros;
@@ -615,8 +611,8 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
                page->index = em_start >> PAGE_SHIFT;
 
                if (comp_bio->bi_iter.bi_size)
-                       submit = btrfs_merge_bio_hook(page, 0, PAGE_SIZE,
-                                       comp_bio, 0);
+                       submit = btrfs_bio_fits_in_stripe(page, PAGE_SIZE,
+                                                         comp_bio, 0);
 
                page->mapping = NULL;
                if (submit || bio_add_page(comp_bio, page, PAGE_SIZE, 0) <
@@ -1040,9 +1036,9 @@ int btrfs_compress_pages(unsigned int type_level, struct address_space *mapping,
                         unsigned long *total_in,
                         unsigned long *total_out)
 {
+       int type = btrfs_compress_type(type_level);
        struct list_head *workspace;
        int ret;
-       int type = type_level & 0xF;
 
        workspace = find_workspace(type);
 
@@ -1207,7 +1203,7 @@ int btrfs_decompress_buf2page(const char *buf, unsigned long buf_start,
 /*
  * Shannon Entropy calculation
  *
- * Pure byte distribution analysis fails to determine compressiability of data.
+ * Pure byte distribution analysis fails to determine compressibility of data.
  * Try calculating entropy to estimate the average minimum number of bits
  * needed to encode the sampled data.
  *
@@ -1271,7 +1267,7 @@ static u8 get4bits(u64 num, int shift) {
 
 /*
  * Use 4 bits as radix base
- * Use 16 u32 counters for calculating new possition in buf array
+ * Use 16 u32 counters for calculating new position in buf array
  *
  * @array     - array that will be sorted
  * @array_buf - buffer array to store sorting results