Since commit
3eaf5f082c4c ("btrfs: extract inlined creation into a
dedicated delalloc helper"), even for inlined compressed extents the cb
range will be exact one block, aka [0, sector).
And several attempts to bring back the old compression range [0, i_size]
all failed with extra races against i_size.
So I think the behavior will stay. With that said, we can further
simplify the lzo compression path.
Since the range is always aligned to block size, and lzo compression is
already done block by block, there is no reason to handle sub-block
sized range.
We can safely remove the @sectorsize_mask, @sector_off and @in_len
variables, and always use @sectorsize as input length for each
compression iteration.
Finally add two ASSERT()s to make sure the range passed into
btrfs_compress_bio() is always block aligned.
Reviewed-by: Daniel Vacek <neelx@suse.com>
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
struct compressed_bio *cb;
int ret;
+ ASSERT(IS_ALIGNED(start, fs_info->sectorsize));
+ ASSERT(IS_ALIGNED(len, fs_info->sectorsize));
+
cb = alloc_compressed_bio(inode, start, REQ_OP_WRITE | write_flags,
end_bbio_compressed_write);
cb->start = start;
while (cur_in < start + len) {
char *data_in;
- const u32 sectorsize_mask = sectorsize - 1;
- u32 sector_off = (cur_in - start) & sectorsize_mask;
- u32 in_len;
size_t out_len;
/* Get the input page first. */
goto out;
}
- /* Compress at most one sector of data each time. */
- in_len = min_t(u32, start + len - cur_in, sectorsize - sector_off);
- ASSERT(in_len);
+ /* Compress one sector of data each time. */
data_in = kmap_local_folio(folio_in, offset_in_folio(folio_in, cur_in));
- ret = lzo1x_1_compress(data_in, in_len, workspace->cbuf, &out_len,
+ ret = lzo1x_1_compress(data_in, sectorsize, workspace->cbuf, &out_len,
workspace->mem);
kunmap_local(data_in);
if (unlikely(ret < 0)) {
if (ret < 0)
goto out;
- cur_in += in_len;
+ cur_in += sectorsize;
/*
* Check if we're making it bigger after two sectors. And if