diff options
author | Tyler Hicks <tyhicks@canonical.com> | 2013-04-15 19:16:24 -0400 |
---|---|---|
committer | Tyler Hicks <tyhicks@canonical.com> | 2013-06-07 20:28:22 -0400 |
commit | 0f89617623fed9541ead9497043e907466848a9f (patch) | |
tree | a67e630c543c1d44f041acd789ec8420b457065c /fs | |
parent | 12003e5b18ca33807b3f9448309ec92184192b85 (diff) |
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>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ecryptfs/crypto.c | 66 |
1 files changed, 31 insertions, 35 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c index e8976c004669..4185584594f5 100644 --- a/fs/ecryptfs/crypto.c +++ b/fs/ecryptfs/crypto.c | |||
@@ -490,6 +490,7 @@ int ecryptfs_encrypt_page(struct page *page) | |||
490 | char *enc_extent_virt; | 490 | char *enc_extent_virt; |
491 | struct page *enc_extent_page = NULL; | 491 | struct page *enc_extent_page = NULL; |
492 | loff_t extent_offset; | 492 | loff_t extent_offset; |
493 | loff_t lower_offset; | ||
493 | int rc = 0; | 494 | int rc = 0; |
494 | 495 | ||
495 | ecryptfs_inode = page->mapping->host; | 496 | ecryptfs_inode = page->mapping->host; |
@@ -503,12 +504,10 @@ int ecryptfs_encrypt_page(struct page *page) | |||
503 | "encrypted extent\n"); | 504 | "encrypted extent\n"); |
504 | goto out; | 505 | goto out; |
505 | } | 506 | } |
506 | enc_extent_virt = kmap(enc_extent_page); | 507 | |
507 | for (extent_offset = 0; | 508 | for (extent_offset = 0; |
508 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); | 509 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); |
509 | extent_offset++) { | 510 | extent_offset++) { |
510 | loff_t offset; | ||
511 | |||
512 | rc = ecryptfs_encrypt_extent(enc_extent_page, crypt_stat, page, | 511 | rc = ecryptfs_encrypt_extent(enc_extent_page, crypt_stat, page, |
513 | extent_offset); | 512 | extent_offset); |
514 | if (rc) { | 513 | if (rc) { |
@@ -516,25 +515,24 @@ int ecryptfs_encrypt_page(struct page *page) | |||
516 | "rc = [%d]\n", __func__, rc); | 515 | "rc = [%d]\n", __func__, rc); |
517 | goto out; | 516 | goto out; |
518 | } | 517 | } |
519 | ecryptfs_lower_offset_for_extent( | 518 | } |
520 | &offset, ((((loff_t)page->index) | 519 | |
521 | * (PAGE_CACHE_SIZE | 520 | ecryptfs_lower_offset_for_extent(&lower_offset, |
522 | / crypt_stat->extent_size)) | 521 | page->index * (PAGE_CACHE_SIZE / crypt_stat->extent_size), |
523 | + extent_offset), crypt_stat); | 522 | crypt_stat); |
524 | rc = ecryptfs_write_lower(ecryptfs_inode, (enc_extent_virt + | 523 | enc_extent_virt = kmap(enc_extent_page); |
525 | extent_offset * crypt_stat->extent_size), | 524 | rc = ecryptfs_write_lower(ecryptfs_inode, enc_extent_virt, lower_offset, |
526 | offset, crypt_stat->extent_size); | 525 | PAGE_CACHE_SIZE); |
527 | if (rc < 0) { | 526 | kunmap(enc_extent_page); |
528 | ecryptfs_printk(KERN_ERR, "Error attempting " | 527 | if (rc < 0) { |
529 | "to write lower page; rc = [%d]" | 528 | ecryptfs_printk(KERN_ERR, |
530 | "\n", rc); | 529 | "Error attempting to write lower page; rc = [%d]\n", |
531 | goto out; | 530 | rc); |
532 | } | 531 | goto out; |
533 | } | 532 | } |
534 | rc = 0; | 533 | rc = 0; |
535 | out: | 534 | out: |
536 | if (enc_extent_page) { | 535 | if (enc_extent_page) { |
537 | kunmap(enc_extent_page); | ||
538 | __free_page(enc_extent_page); | 536 | __free_page(enc_extent_page); |
539 | } | 537 | } |
540 | return rc; | 538 | return rc; |
@@ -599,6 +597,7 @@ int ecryptfs_decrypt_page(struct page *page) | |||
599 | char *enc_extent_virt; | 597 | char *enc_extent_virt; |
600 | struct page *enc_extent_page = NULL; | 598 | struct page *enc_extent_page = NULL; |
601 | unsigned long extent_offset; | 599 | unsigned long extent_offset; |
600 | loff_t lower_offset; | ||
602 | int rc = 0; | 601 | int rc = 0; |
603 | 602 | ||
604 | ecryptfs_inode = page->mapping->host; | 603 | ecryptfs_inode = page->mapping->host; |
@@ -612,26 +611,24 @@ int ecryptfs_decrypt_page(struct page *page) | |||
612 | "encrypted extent\n"); | 611 | "encrypted extent\n"); |
613 | goto out; | 612 | goto out; |
614 | } | 613 | } |
614 | |||
615 | ecryptfs_lower_offset_for_extent(&lower_offset, | ||
616 | page->index * (PAGE_CACHE_SIZE / crypt_stat->extent_size), | ||
617 | crypt_stat); | ||
615 | enc_extent_virt = kmap(enc_extent_page); | 618 | enc_extent_virt = kmap(enc_extent_page); |
619 | rc = ecryptfs_read_lower(enc_extent_virt, lower_offset, PAGE_CACHE_SIZE, | ||
620 | ecryptfs_inode); | ||
621 | kunmap(enc_extent_page); | ||
622 | if (rc < 0) { | ||
623 | ecryptfs_printk(KERN_ERR, | ||
624 | "Error attempting to read lower page; rc = [%d]\n", | ||
625 | rc); | ||
626 | goto out; | ||
627 | } | ||
628 | |||
616 | for (extent_offset = 0; | 629 | for (extent_offset = 0; |
617 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); | 630 | extent_offset < (PAGE_CACHE_SIZE / crypt_stat->extent_size); |
618 | extent_offset++) { | 631 | extent_offset++) { |
619 | loff_t offset; | ||
620 | |||
621 | ecryptfs_lower_offset_for_extent( | ||
622 | &offset, ((page->index * (PAGE_CACHE_SIZE | ||
623 | / crypt_stat->extent_size)) | ||
624 | + extent_offset), crypt_stat); | ||
625 | rc = ecryptfs_read_lower((enc_extent_virt + | ||
626 | extent_offset * crypt_stat->extent_size), | ||
627 | offset, crypt_stat->extent_size, | ||
628 | ecryptfs_inode); | ||
629 | if (rc < 0) { | ||
630 | ecryptfs_printk(KERN_ERR, "Error attempting " | ||
631 | "to read lower page; rc = [%d]" | ||
632 | "\n", rc); | ||
633 | goto out; | ||
634 | } | ||
635 | rc = ecryptfs_decrypt_extent(page, crypt_stat, enc_extent_page, | 632 | rc = ecryptfs_decrypt_extent(page, crypt_stat, enc_extent_page, |
636 | extent_offset); | 633 | extent_offset); |
637 | if (rc) { | 634 | if (rc) { |
@@ -642,7 +639,6 @@ int ecryptfs_decrypt_page(struct page *page) | |||
642 | } | 639 | } |
643 | out: | 640 | out: |
644 | if (enc_extent_page) { | 641 | if (enc_extent_page) { |
645 | kunmap(enc_extent_page); | ||
646 | __free_page(enc_extent_page); | 642 | __free_page(enc_extent_page); |
647 | } | 643 | } |
648 | return rc; | 644 | return rc; |