bio_set_dev(bio, inode->i_sb->s_bdev);
bio->bi_iter.bi_sector =
pblk << (inode->i_sb->s_blocksize_bits - 9);
- bio_set_op_attrs(bio, REQ_OP_WRITE, 0);
+ bio_set_op_attrs(bio, REQ_OP_WRITE, REQ_NOENCRYPT);
ret = bio_add_page(bio, ciphertext_page,
inode->i_sb->s_blocksize, 0);
if (ret != inode->i_sb->s_blocksize) {
if (!buffer_uptodate(bh) && !buffer_delay(bh) &&
!buffer_unwritten(bh) &&
(block_start < from || block_end > to)) {
- int bi_opf = 0;
+ int bi_opf = 0;
- if (S_ISREG(inode->i_mode) && ext4_encrypted_inode(inode)
- && fscrypt_has_encryption_key(inode)) {
- bh->b_private = fscrypt_get_diskcipher(inode);
- if (bh->b_private)
- bi_opf = REQ_CRYPT | REQ_AUX_PRIV;
+ decrypt = ext4_encrypted_inode(inode) &&
+ S_ISREG(inode->i_mode);
+ bi_opf = decrypt ? REQ_NOENCRYPT : 0;
+ if (decrypt && fscrypt_has_encryption_key(inode)) {
+ bh->b_private = fscrypt_get_diskcipher(inode);
+ if (bh->b_private) {
+ bi_opf |= (REQ_CRYPT | REQ_AUX_PRIV);
+ decrypt = 0;
}
+ }
ll_rw_block(REQ_OP_READ, bi_opf, 1, &bh);
crypto_diskcipher_debug(FS_BLOCK_WRITE, bi_opf);
*wait_bh++ = bh;
- decrypt = ext4_encrypted_inode(inode) &&
- S_ISREG(inode->i_mode) && !bh->b_private;
}
}
/*
struct inode *inode = mapping->host;
struct buffer_head *bh;
struct page *page;
+ bool decrypt;
int err = 0;
page = find_or_create_page(mapping, from >> PAGE_SHIFT,
if (!buffer_uptodate(bh)) {
err = -EIO;
- if (S_ISREG(inode->i_mode) && ext4_encrypted_inode(inode)
- && fscrypt_has_encryption_key(inode))
+ decrypt = S_ISREG(inode->i_mode) &&
+ ext4_encrypted_inode(inode);
+ if (decrypt && fscrypt_has_encryption_key(inode))
bh->b_private = fscrypt_get_diskcipher(inode);
+ else
+ bh->b_private = NULL;
if (bh->b_private)
- ll_rw_block(REQ_OP_READ, REQ_CRYPT, 1, &bh);
+ ll_rw_block(REQ_OP_READ, REQ_CRYPT | REQ_NOENCRYPT, 1, &bh);
else
- ll_rw_block(REQ_OP_READ, 0, 1, &bh);
+ ll_rw_block(REQ_OP_READ, (decrypt ? REQ_NOENCRYPT : 0), 1, &bh);
wait_on_buffer(bh);
/* Uhhuh. Read error. Complain and punt. */
if (!buffer_uptodate(bh))
goto unlock;
- if (S_ISREG(inode->i_mode) &&
- ext4_encrypted_inode(inode)) {
+ if (decrypt) {
/* We expect the key to be set. */
BUG_ON(!fscrypt_has_encryption_key(inode));
BUG_ON(blocksize != PAGE_SIZE);
int io_op_flags = io->io_wbc->sync_mode == WB_SYNC_ALL ?
REQ_SYNC : 0;
io->io_bio->bi_write_hint = io->io_end->inode->i_write_hint;
+ if (io->io_flags & EXT4_IO_ENCRYPTED)
+ io_op_flags |= REQ_NOENCRYPT;
bio_set_op_attrs(io->io_bio, REQ_OP_WRITE, io_op_flags);
if (ext4_encrypted_inode(io->io_end->inode) &&
S_ISREG(io->io_end->inode->i_mode)) {
void ext4_io_submit_init(struct ext4_io_submit *io,
struct writeback_control *wbc)
{
+ io->io_flags = 0;
io->io_wbc = wbc;
io->io_bio = NULL;
io->io_end = NULL;
do {
if (!buffer_async_write(bh))
continue;
+ if (data_page)
+ io->io_flags |= EXT4_IO_ENCRYPTED;
ret = io_submit_add_bh(io, inode,
data_page ? data_page : page, bh);
if (ret) {
bio->bi_iter.bi_sector = blocks[0] << (blkbits - 9);
bio->bi_end_io = mpage_end_io;
bio->bi_private = ctx;
- bio_set_op_attrs(bio, REQ_OP_READ, 0);
+ bio_set_op_attrs(bio, REQ_OP_READ,
+ ctx ? REQ_NOENCRYPT : 0);
if (ext4_encrypted_inode(inode) && S_ISREG(inode->i_mode)) {
fscrypt_set_bio(inode, bio);
crypto_diskcipher_debug(FS_READP, bio->bi_opf);