Commit d611935b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by David Sterba

btrfs: pass an ordered_extent to btrfs_submit_compressed_write

btrfs_submit_compressed_write always operates on a single ordered_extent.
Make that explicit by using btrfs_alloc_ordered_extent in the callers
and passing the ordered_extent to btrfs_submit_compressed_write.  This
will help with storing and ordered_extent pointer in the btrfs_bio in
subsequent patches.
Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Reviewed-by: default avatarJosef Bacik <josef@toxicpanda.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 34bfaf15
...@@ -279,33 +279,34 @@ static void btrfs_add_compressed_bio_pages(struct compressed_bio *cb) ...@@ -279,33 +279,34 @@ static void btrfs_add_compressed_bio_pages(struct compressed_bio *cb)
* This also checksums the file bytes and gets things ready for * This also checksums the file bytes and gets things ready for
* the end io hooks. * the end io hooks.
*/ */
void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered,
unsigned int len, u64 disk_start,
unsigned int compressed_len,
struct page **compressed_pages, struct page **compressed_pages,
unsigned int nr_pages, unsigned int nr_pages,
blk_opf_t write_flags, blk_opf_t write_flags,
bool writeback) bool writeback)
{ {
struct btrfs_inode *inode = BTRFS_I(ordered->inode);
struct btrfs_fs_info *fs_info = inode->root->fs_info; struct btrfs_fs_info *fs_info = inode->root->fs_info;
struct compressed_bio *cb; struct compressed_bio *cb;
ASSERT(IS_ALIGNED(start, fs_info->sectorsize) && ASSERT(IS_ALIGNED(ordered->file_offset, fs_info->sectorsize));
IS_ALIGNED(len, fs_info->sectorsize)); ASSERT(IS_ALIGNED(ordered->num_bytes, fs_info->sectorsize));
cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags, cb = alloc_compressed_bio(inode, ordered->file_offset,
REQ_OP_WRITE | write_flags,
end_compressed_bio_write); end_compressed_bio_write);
cb->start = start; cb->start = ordered->file_offset;
cb->len = len; cb->len = ordered->num_bytes;
cb->compressed_pages = compressed_pages; cb->compressed_pages = compressed_pages;
cb->compressed_len = compressed_len; cb->compressed_len = ordered->disk_num_bytes;
cb->writeback = writeback; cb->writeback = writeback;
INIT_WORK(&cb->write_end_work, btrfs_finish_compressed_write_work); INIT_WORK(&cb->write_end_work, btrfs_finish_compressed_write_work);
cb->nr_pages = nr_pages; cb->nr_pages = nr_pages;
cb->bbio.bio.bi_iter.bi_sector = disk_start >> SECTOR_SHIFT; cb->bbio.bio.bi_iter.bi_sector = ordered->disk_bytenr >> SECTOR_SHIFT;
btrfs_add_compressed_bio_pages(cb); btrfs_add_compressed_bio_pages(cb);
btrfs_submit_bio(&cb->bbio, 0); btrfs_submit_bio(&cb->bbio, 0);
btrfs_put_ordered_extent(ordered);
} }
/* /*
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "bio.h" #include "bio.h"
struct btrfs_inode; struct btrfs_inode;
struct btrfs_ordered_extent;
/* /*
* We want to make sure that amount of RAM required to uncompress an extent is * We want to make sure that amount of RAM required to uncompress an extent is
...@@ -86,9 +87,7 @@ int btrfs_decompress(int type, const u8 *data_in, struct page *dest_page, ...@@ -86,9 +87,7 @@ int btrfs_decompress(int type, const u8 *data_in, struct page *dest_page,
int btrfs_decompress_buf2page(const char *buf, u32 buf_len, int btrfs_decompress_buf2page(const char *buf, u32 buf_len,
struct compressed_bio *cb, u32 decompressed); struct compressed_bio *cb, u32 decompressed);
void btrfs_submit_compressed_write(struct btrfs_inode *inode, u64 start, void btrfs_submit_compressed_write(struct btrfs_ordered_extent *ordered,
unsigned int len, u64 disk_start,
unsigned int compressed_len,
struct page **compressed_pages, struct page **compressed_pages,
unsigned int nr_pages, unsigned int nr_pages,
blk_opf_t write_flags, blk_opf_t write_flags,
......
...@@ -1182,6 +1182,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, ...@@ -1182,6 +1182,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode,
struct extent_io_tree *io_tree = &inode->io_tree; struct extent_io_tree *io_tree = &inode->io_tree;
struct btrfs_root *root = inode->root; struct btrfs_root *root = inode->root;
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_ordered_extent *ordered;
struct btrfs_key ins; struct btrfs_key ins;
struct page *locked_page = NULL; struct page *locked_page = NULL;
struct extent_map *em; struct extent_map *em;
...@@ -1243,7 +1244,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, ...@@ -1243,7 +1244,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode,
} }
free_extent_map(em); free_extent_map(em);
ret = btrfs_add_ordered_extent(inode, start, /* file_offset */ ordered = btrfs_alloc_ordered_extent(inode, start, /* file_offset */
async_extent->ram_size, /* num_bytes */ async_extent->ram_size, /* num_bytes */
async_extent->ram_size, /* ram_bytes */ async_extent->ram_size, /* ram_bytes */
ins.objectid, /* disk_bytenr */ ins.objectid, /* disk_bytenr */
...@@ -1251,8 +1252,9 @@ static int submit_one_async_extent(struct btrfs_inode *inode, ...@@ -1251,8 +1252,9 @@ static int submit_one_async_extent(struct btrfs_inode *inode,
0, /* offset */ 0, /* offset */
1 << BTRFS_ORDERED_COMPRESSED, 1 << BTRFS_ORDERED_COMPRESSED,
async_extent->compress_type); async_extent->compress_type);
if (ret) { if (IS_ERR(ordered)) {
btrfs_drop_extent_map_range(inode, start, end, false); btrfs_drop_extent_map_range(inode, start, end, false);
ret = PTR_ERR(ordered);
goto out_free_reserve; goto out_free_reserve;
} }
btrfs_dec_block_group_reservations(fs_info, ins.objectid); btrfs_dec_block_group_reservations(fs_info, ins.objectid);
...@@ -1261,11 +1263,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode, ...@@ -1261,11 +1263,7 @@ static int submit_one_async_extent(struct btrfs_inode *inode,
extent_clear_unlock_delalloc(inode, start, end, extent_clear_unlock_delalloc(inode, start, end,
NULL, EXTENT_LOCKED | EXTENT_DELALLOC, NULL, EXTENT_LOCKED | EXTENT_DELALLOC,
PAGE_UNLOCK | PAGE_START_WRITEBACK); PAGE_UNLOCK | PAGE_START_WRITEBACK);
btrfs_submit_compressed_write(ordered,
btrfs_submit_compressed_write(inode, start, /* file_offset */
async_extent->ram_size, /* num_bytes */
ins.objectid, /* disk_bytenr */
ins.offset, /* compressed_len */
async_extent->pages, /* compressed_pages */ async_extent->pages, /* compressed_pages */
async_extent->nr_pages, async_extent->nr_pages,
async_chunk->write_flags, true); async_chunk->write_flags, true);
...@@ -10274,6 +10272,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -10274,6 +10272,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
struct extent_io_tree *io_tree = &inode->io_tree; struct extent_io_tree *io_tree = &inode->io_tree;
struct extent_changeset *data_reserved = NULL; struct extent_changeset *data_reserved = NULL;
struct extent_state *cached_state = NULL; struct extent_state *cached_state = NULL;
struct btrfs_ordered_extent *ordered;
int compression; int compression;
size_t orig_count; size_t orig_count;
u64 start, end; u64 start, end;
...@@ -10450,14 +10449,15 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -10450,14 +10449,15 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
} }
free_extent_map(em); free_extent_map(em);
ret = btrfs_add_ordered_extent(inode, start, num_bytes, ram_bytes, ordered = btrfs_alloc_ordered_extent(inode, start, num_bytes, ram_bytes,
ins.objectid, ins.offset, ins.objectid, ins.offset,
encoded->unencoded_offset, encoded->unencoded_offset,
(1 << BTRFS_ORDERED_ENCODED) | (1 << BTRFS_ORDERED_ENCODED) |
(1 << BTRFS_ORDERED_COMPRESSED), (1 << BTRFS_ORDERED_COMPRESSED),
compression); compression);
if (ret) { if (IS_ERR(ordered)) {
btrfs_drop_extent_map_range(inode, start, end, false); btrfs_drop_extent_map_range(inode, start, end, false);
ret = PTR_ERR(ordered);
goto out_free_reserved; goto out_free_reserved;
} }
btrfs_dec_block_group_reservations(fs_info, ins.objectid); btrfs_dec_block_group_reservations(fs_info, ins.objectid);
...@@ -10469,8 +10469,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from, ...@@ -10469,8 +10469,7 @@ ssize_t btrfs_do_encoded_write(struct kiocb *iocb, struct iov_iter *from,
btrfs_delalloc_release_extents(inode, num_bytes); btrfs_delalloc_release_extents(inode, num_bytes);
btrfs_submit_compressed_write(inode, start, num_bytes, ins.objectid, btrfs_submit_compressed_write(ordered, pages, nr_pages, 0, false);
ins.offset, pages, nr_pages, 0, false);
ret = orig_count; ret = orig_count;
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment