compression.c (b7c15a3ce6fea5da3aa836c897a78ac628467d54) compression.c (dd137dd1f2d719682b522d4eabe6dec461b7d6fa)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2008 Oracle. All rights reserved.
4 */
5
6#include <linux/kernel.h>
7#include <linux/bio.h>
8#include <linux/file.h>

--- 795 unchanged lines hidden (view full) ---

804 */
805blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
806 int mirror_num, unsigned long bio_flags)
807{
808 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
809 struct extent_map_tree *em_tree;
810 struct compressed_bio *cb;
811 unsigned int compressed_len;
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2008 Oracle. All rights reserved.
4 */
5
6#include <linux/kernel.h>
7#include <linux/bio.h>
8#include <linux/file.h>

--- 795 unchanged lines hidden (view full) ---

804 */
805blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
806 int mirror_num, unsigned long bio_flags)
807{
808 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
809 struct extent_map_tree *em_tree;
810 struct compressed_bio *cb;
811 unsigned int compressed_len;
812 unsigned int nr_pages;
813 unsigned int pg_index;
814 struct bio *comp_bio = NULL;
815 const u64 disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT;
816 u64 cur_disk_byte = disk_bytenr;
817 u64 next_stripe_start;
818 u64 file_offset;
819 u64 em_len;
820 u64 em_start;
821 struct extent_map *em;
822 blk_status_t ret;
812 struct bio *comp_bio = NULL;
813 const u64 disk_bytenr = bio->bi_iter.bi_sector << SECTOR_SHIFT;
814 u64 cur_disk_byte = disk_bytenr;
815 u64 next_stripe_start;
816 u64 file_offset;
817 u64 em_len;
818 u64 em_start;
819 struct extent_map *em;
820 blk_status_t ret;
823 int faili = 0;
821 int ret2;
822 int i;
824 u8 *sums;
825
826 em_tree = &BTRFS_I(inode)->extent_tree;
827
828 file_offset = bio_first_bvec_all(bio)->bv_offset +
829 page_offset(bio_first_page_all(bio));
830
831 /* we need the actual starting offset of this extent in the file */

--- 26 unchanged lines hidden (view full) ---

858 free_extent_map(em);
859 em = NULL;
860
861 cb->len = bio->bi_iter.bi_size;
862 cb->compressed_len = compressed_len;
863 cb->compress_type = extent_compress_type(bio_flags);
864 cb->orig_bio = bio;
865
823 u8 *sums;
824
825 em_tree = &BTRFS_I(inode)->extent_tree;
826
827 file_offset = bio_first_bvec_all(bio)->bv_offset +
828 page_offset(bio_first_page_all(bio));
829
830 /* we need the actual starting offset of this extent in the file */

--- 26 unchanged lines hidden (view full) ---

857 free_extent_map(em);
858 em = NULL;
859
860 cb->len = bio->bi_iter.bi_size;
861 cb->compressed_len = compressed_len;
862 cb->compress_type = extent_compress_type(bio_flags);
863 cb->orig_bio = bio;
864
866 nr_pages = DIV_ROUND_UP(compressed_len, PAGE_SIZE);
867 cb->compressed_pages = kcalloc(nr_pages, sizeof(struct page *),
868 GFP_NOFS);
865 cb->nr_pages = DIV_ROUND_UP(compressed_len, PAGE_SIZE);
866 cb->compressed_pages = kcalloc(cb->nr_pages, sizeof(struct page *), GFP_NOFS);
869 if (!cb->compressed_pages) {
870 ret = BLK_STS_RESOURCE;
867 if (!cb->compressed_pages) {
868 ret = BLK_STS_RESOURCE;
871 goto fail1;
869 goto fail;
872 }
873
870 }
871
874 for (pg_index = 0; pg_index < nr_pages; pg_index++) {
875 cb->compressed_pages[pg_index] = alloc_page(GFP_NOFS);
876 if (!cb->compressed_pages[pg_index]) {
877 faili = pg_index - 1;
878 ret = BLK_STS_RESOURCE;
879 goto fail2;
880 }
872 ret2 = btrfs_alloc_page_array(cb->nr_pages, cb->compressed_pages);
873 if (ret2) {
874 ret = BLK_STS_RESOURCE;
875 goto fail;
881 }
876 }
882 faili = nr_pages - 1;
883 cb->nr_pages = nr_pages;
884
885 add_ra_bio_pages(inode, em_start + em_len, cb);
886
887 /* include any pages we added in add_ra-bio_pages */
888 cb->len = bio->bi_iter.bi_size;
889
890 while (cur_disk_byte < disk_bytenr + compressed_len) {
891 u64 offset = cur_disk_byte - disk_bytenr;

--- 60 unchanged lines hidden (view full) ---

952 ret = submit_compressed_bio(fs_info, cb, comp_bio, mirror_num);
953 if (ret)
954 goto finish_cb;
955 comp_bio = NULL;
956 }
957 }
958 return BLK_STS_OK;
959
877
878 add_ra_bio_pages(inode, em_start + em_len, cb);
879
880 /* include any pages we added in add_ra-bio_pages */
881 cb->len = bio->bi_iter.bi_size;
882
883 while (cur_disk_byte < disk_bytenr + compressed_len) {
884 u64 offset = cur_disk_byte - disk_bytenr;

--- 60 unchanged lines hidden (view full) ---

945 ret = submit_compressed_bio(fs_info, cb, comp_bio, mirror_num);
946 if (ret)
947 goto finish_cb;
948 comp_bio = NULL;
949 }
950 }
951 return BLK_STS_OK;
952
960fail2:
961 while (faili >= 0) {
962 __free_page(cb->compressed_pages[faili]);
963 faili--;
953fail:
954 if (cb->compressed_pages) {
955 for (i = 0; i < cb->nr_pages; i++) {
956 if (cb->compressed_pages[i])
957 __free_page(cb->compressed_pages[i]);
958 }
964 }
965
966 kfree(cb->compressed_pages);
959 }
960
961 kfree(cb->compressed_pages);
967fail1:
968 kfree(cb);
969out:
970 free_extent_map(em);
971 bio->bi_status = ret;
972 bio_endio(bio);
973 return ret;
974finish_cb:
975 if (comp_bio) {

--- 934 unchanged lines hidden ---
962 kfree(cb);
963out:
964 free_extent_map(em);
965 bio->bi_status = ret;
966 bio_endio(bio);
967 return ret;
968finish_cb:
969 if (comp_bio) {

--- 934 unchanged lines hidden ---