Skip to content

Commit 064fe6b

Browse files
Matthew Wilcox (Oracle)brauner
authored andcommitted
ecryptfs: Use a folio throughout ecryptfs_read_folio()
Remove the conversion to a struct page. Removes a few hidden calls to compound_head(). Use 'err' instead of 'rc' for clarity. Also remove the unnecessary call to ClearPageUptodate(); the uptodate flag is already clear if this function is being called. That lets us switch to folio_end_read() which does one atomic flag operation instead of two. Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
1 parent 807a11d commit 064fe6b

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed

fs/ecryptfs/mmap.c

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -178,55 +178,51 @@ ecryptfs_copy_up_encrypted_with_header(struct page *page,
178178
*/
179179
static int ecryptfs_read_folio(struct file *file, struct folio *folio)
180180
{
181-
struct page *page = &folio->page;
181+
struct inode *inode = folio->mapping->host;
182182
struct ecryptfs_crypt_stat *crypt_stat =
183-
&ecryptfs_inode_to_private(page->mapping->host)->crypt_stat;
184-
int rc = 0;
183+
&ecryptfs_inode_to_private(inode)->crypt_stat;
184+
int err = 0;
185185

186186
if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
187-
rc = ecryptfs_read_lower_page_segment(page, page->index, 0,
188-
PAGE_SIZE,
189-
page->mapping->host);
187+
err = ecryptfs_read_lower_page_segment(&folio->page, folio->index, 0,
188+
folio_size(folio),
189+
inode);
190190
} else if (crypt_stat->flags & ECRYPTFS_VIEW_AS_ENCRYPTED) {
191191
if (crypt_stat->flags & ECRYPTFS_METADATA_IN_XATTR) {
192-
rc = ecryptfs_copy_up_encrypted_with_header(page,
192+
err = ecryptfs_copy_up_encrypted_with_header(&folio->page,
193193
crypt_stat);
194-
if (rc) {
194+
if (err) {
195195
printk(KERN_ERR "%s: Error attempting to copy "
196196
"the encrypted content from the lower "
197197
"file whilst inserting the metadata "
198-
"from the xattr into the header; rc = "
199-
"[%d]\n", __func__, rc);
198+
"from the xattr into the header; err = "
199+
"[%d]\n", __func__, err);
200200
goto out;
201201
}
202202

203203
} else {
204-
rc = ecryptfs_read_lower_page_segment(
205-
page, page->index, 0, PAGE_SIZE,
206-
page->mapping->host);
207-
if (rc) {
208-
printk(KERN_ERR "Error reading page; rc = "
209-
"[%d]\n", rc);
204+
err = ecryptfs_read_lower_page_segment(&folio->page,
205+
folio->index, 0, folio_size(folio),
206+
inode);
207+
if (err) {
208+
printk(KERN_ERR "Error reading page; err = "
209+
"[%d]\n", err);
210210
goto out;
211211
}
212212
}
213213
} else {
214-
rc = ecryptfs_decrypt_page(page);
215-
if (rc) {
214+
err = ecryptfs_decrypt_page(&folio->page);
215+
if (err) {
216216
ecryptfs_printk(KERN_ERR, "Error decrypting page; "
217-
"rc = [%d]\n", rc);
217+
"err = [%d]\n", err);
218218
goto out;
219219
}
220220
}
221221
out:
222-
if (rc)
223-
ClearPageUptodate(page);
224-
else
225-
SetPageUptodate(page);
226-
ecryptfs_printk(KERN_DEBUG, "Unlocking page with index = [0x%.16lx]\n",
227-
page->index);
228-
unlock_page(page);
229-
return rc;
222+
ecryptfs_printk(KERN_DEBUG, "Unlocking folio with index = [0x%.16lx]\n",
223+
folio->index);
224+
folio_end_read(folio, err == 0);
225+
return err;
230226
}
231227

232228
/*

0 commit comments

Comments
 (0)