Skip to content

Commit 22be86a

Browse files
Christoph HellwigEric Biggers
authored andcommitted
fscrypt: pass a byte offset to fscrypt_mergeable_bio
Logical offsets into an inode are usually expressed as bytes in the VFS. Switch fscrypt_mergeable_bio to that convention. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20260302141922.370070-8-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 60b4fcb commit 22be86a

6 files changed

Lines changed: 12 additions & 9 deletions

File tree

fs/crypto/bio.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
100100
len -= blocks_this_page;
101101
lblk += blocks_this_page;
102102
sector += (bytes_this_page >> SECTOR_SHIFT);
103-
if (!len || !fscrypt_mergeable_bio(bio, inode, lblk))
103+
if (!len || !fscrypt_mergeable_bio(bio, inode,
104+
(loff_t)lblk << blockbits))
104105
break;
105106
}
106107

fs/crypto/inline_crypt.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(fscrypt_set_bio_crypt_ctx);
316316
* fscrypt_mergeable_bio() - test whether data can be added to a bio
317317
* @bio: the bio being built up
318318
* @inode: the inode for the next part of the I/O
319-
* @next_lblk: the next file logical block number in the I/O
319+
* @pos: the next file position (in bytes) in the I/O
320320
*
321321
* When building a bio which may contain data which should undergo inline
322322
* encryption (or decryption) via fscrypt, filesystems should call this function
@@ -334,7 +334,7 @@ EXPORT_SYMBOL_GPL(fscrypt_set_bio_crypt_ctx);
334334
* Return: true iff the I/O is mergeable
335335
*/
336336
bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
337-
u64 next_lblk)
337+
loff_t pos)
338338
{
339339
const struct bio_crypt_ctx *bc = bio->bi_crypt_context;
340340
const struct fscrypt_inode_info *ci;
@@ -354,7 +354,7 @@ bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
354354
if (bc->bc_key != ci->ci_enc_key.blk_key)
355355
return false;
356356

357-
fscrypt_generate_dun(ci, next_lblk << inode->i_blkbits, next_dun);
357+
fscrypt_generate_dun(ci, pos, next_dun);
358358
return bio_crypt_dun_is_contiguous(bc, bio->bi_iter.bi_size, next_dun);
359359
}
360360
EXPORT_SYMBOL_GPL(fscrypt_mergeable_bio);

fs/ext4/page-io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ static bool io_submit_need_new_bio(struct ext4_io_submit *io,
447447
if (bh->b_blocknr != io->io_next_block)
448448
return true;
449449
if (!fscrypt_mergeable_bio(io->io_bio, inode,
450-
(folio_pos(folio) + bh_offset(bh)) >> inode->i_blkbits))
450+
folio_pos(folio) + bh_offset(bh)))
451451
return true;
452452
return false;
453453
}

fs/ext4/readpage.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,8 @@ static int ext4_mpage_readpages(struct inode *inode, struct fsverity_info *vi,
342342
* BIO off first?
343343
*/
344344
if (bio && (last_block_in_bio != first_block - 1 ||
345-
!fscrypt_mergeable_bio(bio, inode, next_block))) {
345+
!fscrypt_mergeable_bio(bio, inode,
346+
(loff_t)next_block << blkbits))) {
346347
submit_and_realloc:
347348
blk_crypto_submit_bio(bio);
348349
bio = NULL;

fs/f2fs/data.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ static bool f2fs_crypt_mergeable_bio(struct bio *bio, const struct inode *inode,
541541
if (fio && fio->encrypted_page)
542542
return !bio_has_crypt_ctx(bio);
543543

544-
return fscrypt_mergeable_bio(bio, inode, next_idx);
544+
return fscrypt_mergeable_bio(bio, inode,
545+
(loff_t)next_idx << inode->i_blkbits);
545546
}
546547

547548
void f2fs_submit_read_bio(struct f2fs_sb_info *sbi, struct bio *bio,

include/linux/fscrypt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio,
870870
gfp_t gfp_mask);
871871

872872
bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode,
873-
u64 next_lblk);
873+
loff_t pos);
874874

875875
bool fscrypt_dio_supported(struct inode *inode);
876876

@@ -889,7 +889,7 @@ static inline void fscrypt_set_bio_crypt_ctx(struct bio *bio,
889889

890890
static inline bool fscrypt_mergeable_bio(struct bio *bio,
891891
const struct inode *inode,
892-
u64 next_lblk)
892+
loff_t pos)
893893
{
894894
return true;
895895
}

0 commit comments

Comments
 (0)