mirror of
https://github.com/torvalds/linux.git
synced 2026-04-18 06:44:00 -04:00
fscrypt: pass a byte offset to fscrypt_set_bio_crypt_ctx
Logical offsets into an inode are usually expressed as bytes in the VFS. Switch fscrypt_set_bio_crypt_ctx to that convention. Signed-off-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20260302141922.370070-9-hch@lst.de Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
committed by
Eric Biggers
parent
22be86a23c
commit
3c7eaa775d
@@ -75,6 +75,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
|
||||
{
|
||||
const unsigned int blockbits = inode->i_blkbits;
|
||||
const unsigned int blocks_per_page = 1 << (PAGE_SHIFT - blockbits);
|
||||
loff_t pos = (loff_t)lblk << blockbits;
|
||||
struct fscrypt_zero_done done = {
|
||||
.pending = ATOMIC_INIT(1),
|
||||
.done = COMPLETION_INITIALIZER_ONSTACK(done.done),
|
||||
@@ -89,7 +90,7 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
|
||||
bio->bi_iter.bi_sector = sector;
|
||||
bio->bi_private = &done;
|
||||
bio->bi_end_io = fscrypt_zeroout_range_end_io;
|
||||
fscrypt_set_bio_crypt_ctx(bio, inode, lblk, GFP_NOFS);
|
||||
fscrypt_set_bio_crypt_ctx(bio, inode, pos, GFP_NOFS);
|
||||
|
||||
for (n = 0; n < BIO_MAX_VECS; n++) {
|
||||
unsigned int blocks_this_page =
|
||||
@@ -98,10 +99,9 @@ static int fscrypt_zeroout_range_inline_crypt(const struct inode *inode,
|
||||
|
||||
__bio_add_page(bio, ZERO_PAGE(0), bytes_this_page, 0);
|
||||
len -= blocks_this_page;
|
||||
lblk += blocks_this_page;
|
||||
pos += bytes_this_page;
|
||||
sector += (bytes_this_page >> SECTOR_SHIFT);
|
||||
if (!len || !fscrypt_mergeable_bio(bio, inode,
|
||||
(loff_t)lblk << blockbits))
|
||||
if (!len || !fscrypt_mergeable_bio(bio, inode, pos))
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -285,7 +285,7 @@ static void fscrypt_generate_dun(const struct fscrypt_inode_info *ci,
|
||||
* fscrypt_set_bio_crypt_ctx() - prepare a file contents bio for inline crypto
|
||||
* @bio: a bio which will eventually be submitted to the file
|
||||
* @inode: the file's inode
|
||||
* @first_lblk: the first file logical block number in the I/O
|
||||
* @pos: the first file position (in bytes) in the I/O
|
||||
* @gfp_mask: memory allocation flags - these must be a waiting mask so that
|
||||
* bio_crypt_set_ctx can't fail.
|
||||
*
|
||||
@@ -298,7 +298,7 @@ static void fscrypt_generate_dun(const struct fscrypt_inode_info *ci,
|
||||
* The encryption context will be freed automatically when the bio is freed.
|
||||
*/
|
||||
void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
|
||||
u64 first_lblk, gfp_t gfp_mask)
|
||||
loff_t pos, gfp_t gfp_mask)
|
||||
{
|
||||
const struct fscrypt_inode_info *ci;
|
||||
u64 dun[BLK_CRYPTO_DUN_ARRAY_SIZE];
|
||||
@@ -307,7 +307,7 @@ void fscrypt_set_bio_crypt_ctx(struct bio *bio, const struct inode *inode,
|
||||
return;
|
||||
ci = fscrypt_get_inode_info_raw(inode);
|
||||
|
||||
fscrypt_generate_dun(ci, first_lblk << inode->i_blkbits, dun);
|
||||
fscrypt_generate_dun(ci, pos, dun);
|
||||
bio_crypt_set_ctx(bio, ci->ci_enc_key.blk_key, dun, gfp_mask);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(fscrypt_set_bio_crypt_ctx);
|
||||
|
||||
Reference in New Issue
Block a user