Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fscrypt: move fscrypt_set_bio_crypt_ctx_bh to buffer.c

fscrypt_set_bio_crypt_ctx_bh is only used by submit_bh_wbc now. Move it
there and merge bh_get_inode_and_lblk_num into it.

Note that this does not add ifdefs for fscrypt as the compiler will
optimize away the dead code if it is not built in.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20260302141922.370070-6-hch@lst.de
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

authored by

Christoph Hellwig and committed by
Eric Biggers
a18b1ab8 588e7c04

+20 -55
+20 -1
fs/buffer.c
··· 2774 2774 bio_put(bio); 2775 2775 } 2776 2776 2777 + static void buffer_set_crypto_ctx(struct bio *bio, const struct buffer_head *bh, 2778 + gfp_t gfp_mask) 2779 + { 2780 + const struct address_space *mapping = folio_mapping(bh->b_folio); 2781 + const struct inode *inode; 2782 + u64 lblk; 2783 + 2784 + /* 2785 + * The ext4 journal (jbd2) can submit a buffer_head it directly created 2786 + * for a non-pagecache page. fscrypt doesn't care about these. 2787 + */ 2788 + if (!mapping) 2789 + return; 2790 + inode = mapping->host; 2791 + lblk = (folio_pos(bh->b_folio) + bh_offset(bh)) >> inode->i_blkbits; 2792 + fscrypt_set_bio_crypt_ctx(bio, inode, lblk, gfp_mask); 2793 + } 2794 + 2777 2795 static void submit_bh_wbc(blk_opf_t opf, struct buffer_head *bh, 2778 2796 enum rw_hint write_hint, 2779 2797 struct writeback_control *wbc) ··· 2818 2800 2819 2801 bio = bio_alloc(bh->b_bdev, 1, opf, GFP_NOIO); 2820 2802 2821 - fscrypt_set_bio_crypt_ctx_bh(bio, bh, GFP_NOIO); 2803 + if (IS_ENABLED(CONFIG_FS_ENCRYPTION)) 2804 + buffer_set_crypto_ctx(bio, bh, GFP_NOIO); 2822 2805 2823 2806 bio->bi_iter.bi_sector = bh->b_blocknr * (bh->b_size >> 9); 2824 2807 bio->bi_write_hint = write_hint;
-45
fs/crypto/inline_crypt.c
··· 314 314 } 315 315 EXPORT_SYMBOL_GPL(fscrypt_set_bio_crypt_ctx); 316 316 317 - /* Extract the inode and logical block number from a buffer_head. */ 318 - static bool bh_get_inode_and_lblk_num(const struct buffer_head *bh, 319 - const struct inode **inode_ret, 320 - u64 *lblk_num_ret) 321 - { 322 - struct folio *folio = bh->b_folio; 323 - const struct address_space *mapping; 324 - const struct inode *inode; 325 - 326 - /* 327 - * The ext4 journal (jbd2) can submit a buffer_head it directly created 328 - * for a non-pagecache page. fscrypt doesn't care about these. 329 - */ 330 - mapping = folio_mapping(folio); 331 - if (!mapping) 332 - return false; 333 - inode = mapping->host; 334 - 335 - *inode_ret = inode; 336 - *lblk_num_ret = (folio_pos(folio) + bh_offset(bh)) >> inode->i_blkbits; 337 - return true; 338 - } 339 - 340 - /** 341 - * fscrypt_set_bio_crypt_ctx_bh() - prepare a file contents bio for inline 342 - * crypto 343 - * @bio: a bio which will eventually be submitted to the file 344 - * @first_bh: the first buffer_head for which I/O will be submitted 345 - * @gfp_mask: memory allocation flags 346 - * 347 - * Same as fscrypt_set_bio_crypt_ctx(), except this takes a buffer_head instead 348 - * of an inode and block number directly. 349 - */ 350 - void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio, 351 - const struct buffer_head *first_bh, 352 - gfp_t gfp_mask) 353 - { 354 - const struct inode *inode; 355 - u64 first_lblk; 356 - 357 - if (bh_get_inode_and_lblk_num(first_bh, &inode, &first_lblk)) 358 - fscrypt_set_bio_crypt_ctx(bio, inode, first_lblk, gfp_mask); 359 - } 360 - EXPORT_SYMBOL_GPL(fscrypt_set_bio_crypt_ctx_bh); 361 - 362 317 /** 363 318 * fscrypt_mergeable_bio() - test whether data can be added to a bio 364 319 * @bio: the bio being built up
-9
include/linux/fscrypt.h
··· 869 869 const struct inode *inode, u64 first_lblk, 870 870 gfp_t gfp_mask); 871 871 872 - void fscrypt_set_bio_crypt_ctx_bh(struct bio *bio, 873 - const struct buffer_head *first_bh, 874 - gfp_t gfp_mask); 875 - 876 872 bool fscrypt_mergeable_bio(struct bio *bio, const struct inode *inode, 877 873 u64 next_lblk); 878 874 ··· 886 890 static inline void fscrypt_set_bio_crypt_ctx(struct bio *bio, 887 891 const struct inode *inode, 888 892 u64 first_lblk, gfp_t gfp_mask) { } 889 - 890 - static inline void fscrypt_set_bio_crypt_ctx_bh( 891 - struct bio *bio, 892 - const struct buffer_head *first_bh, 893 - gfp_t gfp_mask) { } 894 893 895 894 static inline bool fscrypt_mergeable_bio(struct bio *bio, 896 895 const struct inode *inode,