Skip to content

Commit 588e7c0

Browse files
Christoph HellwigEric Biggers
authored andcommitted
ext4, fscrypt: merge fscrypt_mergeable_bio_bh into io_submit_need_new_bio
ext4 already has the inode and folio and can't have a NULL folio->mapping in this path. Open code fscrypt_mergeable_bio_bh in io_submit_need_new_bio based on these simplifying assumptions. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20260302141922.370070-5-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 5f18a9d commit 588e7c0

3 files changed

Lines changed: 5 additions & 34 deletions

File tree

fs/crypto/inline_crypt.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -406,29 +406,6 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
406406
}
407407
EXPORT_SYMBOL_GPL(fscrypt_mergeable_bio);
408408

409-
/**
410-
* fscrypt_mergeable_bio_bh() - test whether data can be added to a bio
411-
* @bio: the bio being built up
412-
* @next_bh: the next buffer_head for which I/O will be submitted
413-
*
414-
* Same as fscrypt_mergeable_bio(), except this takes a buffer_head instead of
415-
* an inode and block number directly.
416-
*
417-
* Return: true iff the I/O is mergeable
418-
*/
419-
bool fscrypt_mergeable_bio_bh(struct bio *bio,
420-
const struct buffer_head *next_bh)
421-
{
422-
const struct inode *inode;
423-
u64 next_lblk;
424-
425-
if (!bh_get_inode_and_lblk_num(next_bh, &inode, &next_lblk))
426-
return !bio->bi_crypt_context;
427-
428-
return fscrypt_mergeable_bio(bio, inode, next_lblk);
429-
}
430-
EXPORT_SYMBOL_GPL(fscrypt_mergeable_bio_bh);
431-
432409
/**
433410
* fscrypt_dio_supported() - check whether DIO (direct I/O) is supported on an
434411
* inode, as far as encryption is concerned

fs/ext4/page-io.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,11 +440,14 @@ static void io_submit_init_bio(struct ext4_io_submit *io,
440440
}
441441

442442
static bool io_submit_need_new_bio(struct ext4_io_submit *io,
443+
struct inode *inode,
444+
struct folio *folio,
443445
struct buffer_head *bh)
444446
{
445447
if (bh->b_blocknr != io->io_next_block)
446448
return true;
447-
if (!fscrypt_mergeable_bio_bh(io->io_bio, bh))
449+
if (!fscrypt_mergeable_bio(io->io_bio, inode,
450+
(folio_pos(folio) + bh_offset(bh)) >> inode->i_blkbits))
448451
return true;
449452
return false;
450453
}
@@ -455,7 +458,7 @@ static void io_submit_add_bh(struct ext4_io_submit *io,
455458
struct folio *io_folio,
456459
struct buffer_head *bh)
457460
{
458-
if (io->io_bio && io_submit_need_new_bio(io, bh)) {
461+
if (io->io_bio && io_submit_need_new_bio(io, inode, folio, bh)) {
459462
submit_and_retry:
460463
ext4_io_submit(io);
461464
}

include/linux/fscrypt.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,6 @@ void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio,
876876
bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
877877
u64 next_lblk);
878878

879-
bool fscrypt_mergeable_bio_bh(struct bio *bio,
880-
const struct buffer_head *next_bh);
881-
882879
bool fscrypt_dio_supported(struct inode *inode);
883880

884881
u64 fscrypt_limit_io_blocks(const struct inode *inode, u64 lblk, u64 nr_blocks);
@@ -906,12 +903,6 @@ static inline bool fscrypt_mergeable_bio(struct bio *bio,
906903
return true;
907904
}
908905

909-
static inline bool fscrypt_mergeable_bio_bh(struct bio *bio,
910-
const struct buffer_head *next_bh)
911-
{
912-
return true;
913-
}
914-
915906
static inline bool fscrypt_dio_supported(struct inode *inode)
916907
{
917908
return !fscrypt_needs_contents_encryption(inode);

0 commit comments

Comments
 (0)