Skip to content

Commit 8650910

Browse files
adam900710kdave
authored andcommitted
btrfs: enable encoded read/write/send for bs > ps cases
Since the read verification and read repair are all supporting bs > ps without large folios now, we can enable encoded read/write/send. Now we can relax the alignment in assert_bbio_alignment() to min(blocksize, PAGE_SIZE). But also add the extra blocksize based alignment check for the logical and length of the bbio. There is a pitfall in btrfs_add_compress_bio_folios(), which relies on the folios passed in to meet the minimal folio order. But now we can pass regular page sized folios in, update it to check each folio's size instead of using the minimal folio size. This allows btrfs_add_compress_bio_folios() to even handle folios array with different sizes, thankfully we don't yet need to handle such crazy situation. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 7ee7fd8 commit 8650910

File tree

4 files changed

+17
-44
lines changed

4 files changed

+17
-44
lines changed

fs/btrfs/bio.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -867,21 +867,23 @@ static void assert_bbio_alignment(struct btrfs_bio *bbio)
867867
struct bio_vec bvec;
868868
struct bvec_iter iter;
869869
const u32 blocksize = fs_info->sectorsize;
870+
const u32 alignment = min(blocksize, PAGE_SIZE);
871+
const u64 logical = bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT;
872+
const u32 length = bbio->bio.bi_iter.bi_size;
870873

871-
/* Metadata has no extra bs > ps alignment requirement. */
872-
if (!is_data_bbio(bbio))
873-
return;
874+
/* The logical and length should still be aligned to blocksize. */
875+
ASSERT(IS_ALIGNED(logical, blocksize) && IS_ALIGNED(length, blocksize) &&
876+
length != 0, "root=%llu inode=%llu logical=%llu length=%u",
877+
btrfs_root_id(bbio->inode->root),
878+
btrfs_ino(bbio->inode), logical, length);
874879

875880
bio_for_each_bvec(bvec, &bbio->bio, iter)
876-
ASSERT(IS_ALIGNED(bvec.bv_offset, blocksize) &&
877-
IS_ALIGNED(bvec.bv_len, blocksize),
881+
ASSERT(IS_ALIGNED(bvec.bv_offset, alignment) &&
882+
IS_ALIGNED(bvec.bv_len, alignment),
878883
"root=%llu inode=%llu logical=%llu length=%u index=%u bv_offset=%u bv_len=%u",
879884
btrfs_root_id(bbio->inode->root),
880-
btrfs_ino(bbio->inode),
881-
bbio->bio.bi_iter.bi_sector << SECTOR_SHIFT,
882-
bbio->bio.bi_iter.bi_size, iter.bi_idx,
883-
bvec.bv_offset,
884-
bvec.bv_len);
885+
btrfs_ino(bbio->inode), logical, length, iter.bi_idx,
886+
bvec.bv_offset, bvec.bv_len);
885887
#endif
886888
}
887889

fs/btrfs/compression.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -340,21 +340,20 @@ static void end_bbio_compressed_write(struct btrfs_bio *bbio)
340340

341341
static void btrfs_add_compressed_bio_folios(struct compressed_bio *cb)
342342
{
343-
struct btrfs_fs_info *fs_info = cb->bbio.inode->root->fs_info;
344343
struct bio *bio = &cb->bbio.bio;
345344
u32 offset = 0;
345+
unsigned int findex = 0;
346346

347347
while (offset < cb->compressed_len) {
348-
struct folio *folio;
348+
struct folio *folio = cb->compressed_folios[findex];
349+
u32 len = min_t(u32, cb->compressed_len - offset, folio_size(folio));
349350
int ret;
350-
u32 len = min_t(u32, cb->compressed_len - offset,
351-
btrfs_min_folio_size(fs_info));
352351

353-
folio = cb->compressed_folios[offset >> (PAGE_SHIFT + fs_info->block_min_order)];
354352
/* Maximum compressed extent is smaller than bio size limit. */
355353
ret = bio_add_folio(bio, folio, len, 0);
356354
ASSERT(ret);
357355
offset += len;
356+
findex++;
358357
}
359358
}
360359

fs/btrfs/ioctl.c

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4408,10 +4408,6 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp,
44084408
goto out_acct;
44094409
}
44104410

4411-
if (fs_info->sectorsize > PAGE_SIZE) {
4412-
ret = -ENOTTY;
4413-
goto out_acct;
4414-
}
44154411
if (compat) {
44164412
#if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT)
44174413
struct btrfs_ioctl_encoded_io_args_32 args32;
@@ -4503,7 +4499,6 @@ static int btrfs_ioctl_encoded_read(struct file *file, void __user *argp,
45034499

45044500
static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool compat)
45054501
{
4506-
struct btrfs_fs_info *fs_info = inode_to_fs_info(file->f_inode);
45074502
struct btrfs_ioctl_encoded_io_args args;
45084503
struct iovec iovstack[UIO_FASTIOV];
45094504
struct iovec *iov = iovstack;
@@ -4517,11 +4512,6 @@ static int btrfs_ioctl_encoded_write(struct file *file, void __user *argp, bool
45174512
goto out_acct;
45184513
}
45194514

4520-
if (fs_info->sectorsize > PAGE_SIZE) {
4521-
ret = -ENOTTY;
4522-
goto out_acct;
4523-
}
4524-
45254515
if (!(file->f_mode & FMODE_WRITE)) {
45264516
ret = -EBADF;
45274517
goto out_acct;
@@ -4803,11 +4793,6 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
48034793
ret = -EPERM;
48044794
goto out_acct;
48054795
}
4806-
if (fs_info->sectorsize > PAGE_SIZE) {
4807-
ret = -ENOTTY;
4808-
goto out_acct;
4809-
}
4810-
48114796
sqe_addr = u64_to_user_ptr(READ_ONCE(cmd->sqe->addr));
48124797

48134798
if (issue_flags & IO_URING_F_COMPAT) {
@@ -4935,7 +4920,6 @@ static int btrfs_uring_encoded_read(struct io_uring_cmd *cmd, unsigned int issue
49354920
static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issue_flags)
49364921
{
49374922
struct file *file = cmd->file;
4938-
struct btrfs_fs_info *fs_info = inode_to_fs_info(file->f_inode);
49394923
loff_t pos;
49404924
struct kiocb kiocb;
49414925
ssize_t ret;
@@ -4950,11 +4934,6 @@ static int btrfs_uring_encoded_write(struct io_uring_cmd *cmd, unsigned int issu
49504934
ret = -EPERM;
49514935
goto out_acct;
49524936
}
4953-
if (fs_info->sectorsize > PAGE_SIZE) {
4954-
ret = -ENOTTY;
4955-
goto out_acct;
4956-
}
4957-
49584937
sqe_addr = u64_to_user_ptr(READ_ONCE(cmd->sqe->addr));
49594938

49604939
if (!(file->f_mode & FMODE_WRITE)) {

fs/btrfs/send.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5634,14 +5634,7 @@ static int send_extent_data(struct send_ctx *sctx, struct btrfs_path *path,
56345634

56355635
ei = btrfs_item_ptr(leaf, path->slots[0],
56365636
struct btrfs_file_extent_item);
5637-
/*
5638-
* Do not go through encoded read for bs > ps cases.
5639-
*
5640-
* Encoded send is using vmallocated pages as buffer, which we can
5641-
* not ensure every folio is large enough to contain a block.
5642-
*/
5643-
if (sctx->send_root->fs_info->sectorsize <= PAGE_SIZE &&
5644-
(sctx->flags & BTRFS_SEND_FLAG_COMPRESSED) &&
5637+
if ((sctx->flags & BTRFS_SEND_FLAG_COMPRESSED) &&
56455638
btrfs_file_extent_compression(leaf, ei) != BTRFS_COMPRESS_NONE) {
56465639
bool is_inline = (btrfs_file_extent_type(leaf, ei) ==
56475640
BTRFS_FILE_EXTENT_INLINE);

0 commit comments

Comments
 (0)