eCryptfs: Read/write entire page during page IO
When reading and writing encrypted pages, perform IO using the entire page all at once rather than 4096 bytes at a time. This only affects architectures where PAGE_CACHE_SIZE is larger than 4096 bytes. Signed-off-by: Tyler Hicks <tyhicks@canonical.com>
This commit is contained in:
parent
12003e5b18
commit
0f89617623
1 changed files with 31 additions and 35 deletions
|
@ -490,6 +490,7 @@ int ecryptfs_encrypt_page(struct page *page)
|
||||||
char *enc_extent_virt;
|
char *enc_extent_virt;
|
||||||
struct page *enc_extent_page = NULL;
|
struct page *enc_extent_page = NULL;
|
||||||
loff_t extent_offset;
|
loff_t extent_offset;
|
||||||
|
loff_t lower_offset;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
ecryptfs_inode = page->mapping->host;
|
ecryptfs_inode = page->mapping->host;
|
||||||
|
@ -503,12 +504,10 @@ int ecryptfs_encrypt_page(struct page *page)
|
||||||
"encrypted extent\n");
|
"encrypted extent\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
enc_extent_virt = kmap(enc_extent_page);
|
|
||||||
for (extent_offset = 0;
|
for (extent_offset = 0;
|
||||||
extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size);
|
extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size);
|
||||||
extent_offset++) {
|
extent_offset++) {
|
||||||
loff_t offset;
|
|
||||||
|
|
||||||
rc = ecryptfs_encrypt_extent(enc_extent_page, crypt_stat, page,
|
rc = ecryptfs_encrypt_extent(enc_extent_page, crypt_stat, page,
|
||||||
extent_offset);
|
extent_offset);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -516,25 +515,24 @@ int ecryptfs_encrypt_page(struct page *page)
|
||||||
"rc = [%d]\n", __func__, rc);
|
"rc = [%d]\n", __func__, rc);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
ecryptfs_lower_offset_for_extent(
|
}
|
||||||
&offset, ((((loff_t)page->index)
|
|
||||||
* (PAGE_CACHE_SIZE
|
ecryptfs_lower_offset_for_extent(&lower_offset,
|
||||||
/ crypt_stat->extent_size))
|
page->index * (PAGE_CACHE_SIZE / crypt_stat->extent_size),
|
||||||
+ extent_offset), crypt_stat);
|
crypt_stat);
|
||||||
rc = ecryptfs_write_lower(ecryptfs_inode, (enc_extent_virt +
|
enc_extent_virt = kmap(enc_extent_page);
|
||||||
extent_offset * crypt_stat->extent_size),
|
rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, lower_offset,
|
||||||
offset, crypt_stat->extent_size);
|
PAGE_CACHE_SIZE);
|
||||||
if (rc < 0) {
|
kunmap(enc_extent_page);
|
||||||
ecryptfs_printk(KERN_ERR, "Error attempting "
|
if (rc < 0) {
|
||||||
"to write lower page; rc = [%d]"
|
ecryptfs_printk(KERN_ERR,
|
||||||
"\n", rc);
|
"Error attempting to write lower page; rc = [%d]\n",
|
||||||
goto out;
|
rc);
|
||||||
}
|
goto out;
|
||||||
}
|
}
|
||||||
rc = 0;
|
rc = 0;
|
||||||
out:
|
out:
|
||||||
if (enc_extent_page) {
|
if (enc_extent_page) {
|
||||||
kunmap(enc_extent_page);
|
|
||||||
__free_page(enc_extent_page);
|
__free_page(enc_extent_page);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -599,6 +597,7 @@ int ecryptfs_decrypt_page(struct page *page)
|
||||||
char *enc_extent_virt;
|
char *enc_extent_virt;
|
||||||
struct page *enc_extent_page = NULL;
|
struct page *enc_extent_page = NULL;
|
||||||
unsigned long extent_offset;
|
unsigned long extent_offset;
|
||||||
|
loff_t lower_offset;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
ecryptfs_inode = page->mapping->host;
|
ecryptfs_inode = page->mapping->host;
|
||||||
|
@ -612,26 +611,24 @@ int ecryptfs_decrypt_page(struct page *page)
|
||||||
"encrypted extent\n");
|
"encrypted extent\n");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ecryptfs_lower_offset_for_extent(&lower_offset,
|
||||||
|
page->index * (PAGE_CACHE_SIZE / crypt_stat->extent_size),
|
||||||
|
crypt_stat);
|
||||||
enc_extent_virt = kmap(enc_extent_page);
|
enc_extent_virt = kmap(enc_extent_page);
|
||||||
|
rc = ecryptfs_read_lower(enc_extent_virt, lower_offset, PAGE_CACHE_SIZE,
|
||||||
|
ecryptfs_inode);
|
||||||
|
kunmap(enc_extent_page);
|
||||||
|
if (rc < 0) {
|
||||||
|
ecryptfs_printk(KERN_ERR,
|
||||||
|
"Error attempting to read lower page; rc = [%d]\n",
|
||||||
|
rc);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
for (extent_offset = 0;
|
for (extent_offset = 0;
|
||||||
extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size);
|
extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size);
|
||||||
extent_offset++) {
|
extent_offset++) {
|
||||||
loff_t offset;
|
|
||||||
|
|
||||||
ecryptfs_lower_offset_for_extent(
|
|
||||||
&offset, ((page->index * (PAGE_CACHE_SIZE
|
|
||||||
/ crypt_stat->extent_size))
|
|
||||||
+ extent_offset), crypt_stat);
|
|
||||||
rc = ecryptfs_read_lower((enc_extent_virt +
|
|
||||||
extent_offset * crypt_stat->extent_size),
|
|
||||||
offset, crypt_stat->extent_size,
|
|
||||||
ecryptfs_inode);
|
|
||||||
if (rc < 0) {
|
|
||||||
ecryptfs_printk(KERN_ERR, "Error attempting "
|
|
||||||
"to read lower page; rc = [%d]"
|
|
||||||
"\n", rc);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
rc = ecryptfs_decrypt_extent(page, crypt_stat, enc_extent_page,
|
rc = ecryptfs_decrypt_extent(page, crypt_stat, enc_extent_page,
|
||||||
extent_offset);
|
extent_offset);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
@ -642,7 +639,6 @@ int ecryptfs_decrypt_page(struct page *page)
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
if (enc_extent_page) {
|
if (enc_extent_page) {
|
||||||
kunmap(enc_extent_page);
|
|
||||||
__free_page(enc_extent_page);
|
__free_page(enc_extent_page);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Add table
Reference in a new issue