aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ecryptfs
diff options
context:
space:
mode:
authorMichael Halcrow <mhalcrow@us.ibm.com>2007-02-12 03:53:48 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-02-12 12:48:37 -0500
commit9d8b8ce5561890464c54645cdea4d6b157159fec (patch)
tree94e7f2cdd3a392806ba7b35e5d2722024ddf4098 /fs/ecryptfs
parent70456600f42f85cfcbdd9d7a6029c03b6f9c5d1e (diff)
[PATCH] eCryptfs: convert kmap() to kmap_atomic()
Replace kmap() with kmap_atomic(). Reduce the amount of time that mappings are held. Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com> Signed-off-by: Trevor Highland <tshighla@us.ibm.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ecryptfs')
-rw-r--r--fs/ecryptfs/crypto.c8
-rw-r--r--fs/ecryptfs/ecryptfs_kernel.h4
-rw-r--r--fs/ecryptfs/mmap.c121
3 files changed, 39 insertions, 94 deletions
diff --git a/fs/ecryptfs/crypto.c b/fs/ecryptfs/crypto.c
index 2d7db61b9d6c..b817a1a39e70 100644
--- a/fs/ecryptfs/crypto.c
+++ b/fs/ecryptfs/crypto.c
@@ -429,10 +429,10 @@ static int ecryptfs_read_in_page(struct ecryptfs_page_crypt_context *ctx,
429 goto out; 429 goto out;
430 } 430 }
431 } else { 431 } else {
432 rc = ecryptfs_grab_and_map_lower_page(lower_page, NULL, 432 *lower_page = grab_cache_page(lower_inode->i_mapping,
433 lower_inode, 433 lower_page_idx);
434 lower_page_idx); 434 if (!(*lower_page)) {
435 if (rc) { 435 rc = -EINVAL;
436 ecryptfs_printk( 436 ecryptfs_printk(
437 KERN_ERR, "Error attempting to grab and map " 437 KERN_ERR, "Error attempting to grab and map "
438 "lower page with index [0x%.16x]; rc = [%d]\n", 438 "lower page with index [0x%.16x]; rc = [%d]\n",
diff --git a/fs/ecryptfs/ecryptfs_kernel.h b/fs/ecryptfs/ecryptfs_kernel.h
index ec526df4235e..31e628a3a1fa 100644
--- a/fs/ecryptfs/ecryptfs_kernel.h
+++ b/fs/ecryptfs/ecryptfs_kernel.h
@@ -514,10 +514,6 @@ int ecryptfs_copy_page_to_lower(struct page *page, struct inode *lower_inode,
514 struct file *lower_file); 514 struct file *lower_file);
515int ecryptfs_do_readpage(struct file *file, struct page *page, 515int ecryptfs_do_readpage(struct file *file, struct page *page,
516 pgoff_t lower_page_index); 516 pgoff_t lower_page_index);
517int ecryptfs_grab_and_map_lower_page(struct page **lower_page,
518 char **lower_virt,
519 struct inode *lower_inode,
520 unsigned long lower_page_index);
521int ecryptfs_writepage_and_release_lower_page(struct page *lower_page, 517int ecryptfs_writepage_and_release_lower_page(struct page *lower_page,
522 struct inode *lower_inode, 518 struct inode *lower_inode,
523 struct writeback_control *wbc); 519 struct writeback_control *wbc);
diff --git a/fs/ecryptfs/mmap.c b/fs/ecryptfs/mmap.c
index 3386014becc6..f5f962d7a123 100644
--- a/fs/ecryptfs/mmap.c
+++ b/fs/ecryptfs/mmap.c
@@ -234,22 +234,11 @@ int ecryptfs_do_readpage(struct file *file, struct page *page,
234 goto out; 234 goto out;
235 } 235 }
236 wait_on_page_locked(lower_page); 236 wait_on_page_locked(lower_page);
237 page_data = (char *)kmap(page); 237 page_data = kmap_atomic(page, KM_USER0);
238 if (!page_data) { 238 lower_page_data = kmap_atomic(lower_page, KM_USER1);
239 rc = -ENOMEM;
240 ecryptfs_printk(KERN_ERR, "Error mapping page\n");
241 goto out;
242 }
243 lower_page_data = (char *)kmap(lower_page);
244 if (!lower_page_data) {
245 rc = -ENOMEM;
246 ecryptfs_printk(KERN_ERR, "Error mapping page\n");
247 kunmap(page);
248 goto out;
249 }
250 memcpy(page_data, lower_page_data, PAGE_CACHE_SIZE); 239 memcpy(page_data, lower_page_data, PAGE_CACHE_SIZE);
251 kunmap(lower_page); 240 kunmap_atomic(lower_page_data, KM_USER1);
252 kunmap(page); 241 kunmap_atomic(page_data, KM_USER0);
253 rc = 0; 242 rc = 0;
254out: 243out:
255 if (likely(lower_page)) 244 if (likely(lower_page))
@@ -325,19 +314,14 @@ static int ecryptfs_readpage(struct file *file, struct page *page)
325 if (page->index < num_pages_in_header_region) { 314 if (page->index < num_pages_in_header_region) {
326 char *page_virt; 315 char *page_virt;
327 316
328 page_virt = (char *)kmap(page); 317 page_virt = kmap_atomic(page, KM_USER0);
329 if (!page_virt) {
330 rc = -ENOMEM;
331 printk(KERN_ERR "Error mapping page\n");
332 goto out;
333 }
334 memset(page_virt, 0, PAGE_CACHE_SIZE); 318 memset(page_virt, 0, PAGE_CACHE_SIZE);
335 if (page->index == 0) { 319 if (page->index == 0) {
336 rc = ecryptfs_read_xattr_region( 320 rc = ecryptfs_read_xattr_region(
337 page_virt, file->f_path.dentry); 321 page_virt, file->f_path.dentry);
338 set_header_info(page_virt, crypt_stat); 322 set_header_info(page_virt, crypt_stat);
339 } 323 }
340 kunmap(page); 324 kunmap_atomic(page_virt, KM_USER0);
341 if (rc) { 325 if (rc) {
342 printk(KERN_ERR "Error reading xattr " 326 printk(KERN_ERR "Error reading xattr "
343 "region\n"); 327 "region\n");
@@ -387,26 +371,19 @@ static int fill_zeros_to_end_of_page(struct page *page, unsigned int to)
387{ 371{
388 struct inode *inode = page->mapping->host; 372 struct inode *inode = page->mapping->host;
389 int end_byte_in_page; 373 int end_byte_in_page;
390 int rc = 0;
391 char *page_virt; 374 char *page_virt;
392 375
393 if ((i_size_read(inode) / PAGE_CACHE_SIZE) == page->index) { 376 if ((i_size_read(inode) / PAGE_CACHE_SIZE) != page->index)
394 end_byte_in_page = i_size_read(inode) % PAGE_CACHE_SIZE; 377 goto out;
395 if (to > end_byte_in_page) 378 end_byte_in_page = i_size_read(inode) % PAGE_CACHE_SIZE;
396 end_byte_in_page = to; 379 if (to > end_byte_in_page)
397 page_virt = kmap(page); 380 end_byte_in_page = to;
398 if (!page_virt) { 381 page_virt = kmap_atomic(page, KM_USER0);
399 rc = -ENOMEM; 382 memset((page_virt + end_byte_in_page), 0,
400 ecryptfs_printk(KERN_WARNING, 383 (PAGE_CACHE_SIZE - end_byte_in_page));
401 "Could not map page\n"); 384 kunmap_atomic(page_virt, KM_USER0);
402 goto out;
403 }
404 memset((page_virt + end_byte_in_page), 0,
405 (PAGE_CACHE_SIZE - end_byte_in_page));
406 kunmap(page);
407 }
408out: 385out:
409 return rc; 386 return 0;
410} 387}
411 388
412static int ecryptfs_prepare_write(struct file *file, struct page *page, 389static int ecryptfs_prepare_write(struct file *file, struct page *page,
@@ -414,7 +391,6 @@ static int ecryptfs_prepare_write(struct file *file, struct page *page,
414{ 391{
415 int rc = 0; 392 int rc = 0;
416 393
417 kmap(page);
418 if (from == 0 && to == PAGE_CACHE_SIZE) 394 if (from == 0 && to == PAGE_CACHE_SIZE)
419 goto out; /* If we are writing a full page, it will be 395 goto out; /* If we are writing a full page, it will be
420 up to date. */ 396 up to date. */
@@ -424,30 +400,6 @@ out:
424 return rc; 400 return rc;
425} 401}
426 402
427int ecryptfs_grab_and_map_lower_page(struct page **lower_page,
428 char **lower_virt,
429 struct inode *lower_inode,
430 unsigned long lower_page_index)
431{
432 int rc = 0;
433
434 (*lower_page) = grab_cache_page(lower_inode->i_mapping,
435 lower_page_index);
436 if (!(*lower_page)) {
437 ecryptfs_printk(KERN_ERR, "grab_cache_page for "
438 "lower_page_index = [0x%.16x] failed\n",
439 lower_page_index);
440 rc = -EINVAL;
441 goto out;
442 }
443 if (lower_virt)
444 (*lower_virt) = kmap((*lower_page));
445 else
446 kmap((*lower_page));
447out:
448 return rc;
449}
450
451int ecryptfs_writepage_and_release_lower_page(struct page *lower_page, 403int ecryptfs_writepage_and_release_lower_page(struct page *lower_page,
452 struct inode *lower_inode, 404 struct inode *lower_inode,
453 struct writeback_control *wbc) 405 struct writeback_control *wbc)
@@ -466,11 +418,8 @@ out:
466 return rc; 418 return rc;
467} 419}
468 420
469static void ecryptfs_unmap_and_release_lower_page(struct page *lower_page) 421static void ecryptfs_release_lower_page(struct page *lower_page)
470{ 422{
471 kunmap(lower_page);
472 ecryptfs_printk(KERN_DEBUG, "Unlocking lower page with index = "
473 "[0x%.16x]\n", lower_page->index);
474 unlock_page(lower_page); 423 unlock_page(lower_page);
475 page_cache_release(lower_page); 424 page_cache_release(lower_page);
476} 425}
@@ -492,11 +441,11 @@ static int ecryptfs_write_inode_size_to_header(struct file *lower_file,
492 const struct address_space_operations *lower_a_ops; 441 const struct address_space_operations *lower_a_ops;
493 u64 file_size; 442 u64 file_size;
494 443
495 rc = ecryptfs_grab_and_map_lower_page(&header_page, &header_virt, 444 header_page = grab_cache_page(lower_inode->i_mapping, 0);
496 lower_inode, 0); 445 if (!header_page) {
497 if (rc) { 446 ecryptfs_printk(KERN_ERR, "grab_cache_page for "
498 ecryptfs_printk(KERN_ERR, "grab_cache_page for header page " 447 "lower_page_index 0 failed\n");
499 "failed\n"); 448 rc = -EINVAL;
500 goto out; 449 goto out;
501 } 450 }
502 lower_a_ops = lower_inode->i_mapping->a_ops; 451 lower_a_ops = lower_inode->i_mapping->a_ops;
@@ -504,12 +453,14 @@ static int ecryptfs_write_inode_size_to_header(struct file *lower_file,
504 file_size = (u64)i_size_read(inode); 453 file_size = (u64)i_size_read(inode);
505 ecryptfs_printk(KERN_DEBUG, "Writing size: [0x%.16x]\n", file_size); 454 ecryptfs_printk(KERN_DEBUG, "Writing size: [0x%.16x]\n", file_size);
506 file_size = cpu_to_be64(file_size); 455 file_size = cpu_to_be64(file_size);
456 header_virt = kmap_atomic(header_page, KM_USER0);
507 memcpy(header_virt, &file_size, sizeof(u64)); 457 memcpy(header_virt, &file_size, sizeof(u64));
458 kunmap_atomic(header_virt, KM_USER0);
508 rc = lower_a_ops->commit_write(lower_file, header_page, 0, 8); 459 rc = lower_a_ops->commit_write(lower_file, header_page, 0, 8);
509 if (rc < 0) 460 if (rc < 0)
510 ecryptfs_printk(KERN_ERR, "Error commiting header page " 461 ecryptfs_printk(KERN_ERR, "Error commiting header page "
511 "write\n"); 462 "write\n");
512 ecryptfs_unmap_and_release_lower_page(header_page); 463 ecryptfs_release_lower_page(header_page);
513 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME; 464 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME;
514 mark_inode_dirty_sync(inode); 465 mark_inode_dirty_sync(inode);
515out: 466out:
@@ -597,10 +548,10 @@ int ecryptfs_get_lower_page(struct page **lower_page, struct inode *lower_inode,
597{ 548{
598 int rc = 0; 549 int rc = 0;
599 550
600 rc = ecryptfs_grab_and_map_lower_page(lower_page, NULL, lower_inode, 551 *lower_page = grab_cache_page(lower_inode->i_mapping, lower_page_index);
601 lower_page_index); 552 if (!(*lower_page)) {
602 if (rc) { 553 rc = -EINVAL;
603 ecryptfs_printk(KERN_ERR, "Error attempting to grab and map " 554 ecryptfs_printk(KERN_ERR, "Error attempting to grab "
604 "lower page with index [0x%.16x]\n", 555 "lower page with index [0x%.16x]\n",
605 lower_page_index); 556 lower_page_index);
606 goto out; 557 goto out;
@@ -616,7 +567,7 @@ int ecryptfs_get_lower_page(struct page **lower_page, struct inode *lower_inode,
616 } 567 }
617out: 568out:
618 if (rc && (*lower_page)) { 569 if (rc && (*lower_page)) {
619 ecryptfs_unmap_and_release_lower_page(*lower_page); 570 ecryptfs_release_lower_page(*lower_page);
620 (*lower_page) = NULL; 571 (*lower_page) = NULL;
621 } 572 }
622 return rc; 573 return rc;
@@ -641,7 +592,7 @@ ecryptfs_commit_lower_page(struct page *lower_page, struct inode *lower_inode,
641 "Error committing write; rc = [%d]\n", rc); 592 "Error committing write; rc = [%d]\n", rc);
642 } else 593 } else
643 rc = 0; 594 rc = 0;
644 ecryptfs_unmap_and_release_lower_page(lower_page); 595 ecryptfs_release_lower_page(lower_page);
645 return rc; 596 return rc;
646} 597}
647 598
@@ -747,7 +698,6 @@ static int ecryptfs_commit_write(struct file *file, struct page *page,
747 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME; 698 lower_inode->i_mtime = lower_inode->i_ctime = CURRENT_TIME;
748 mark_inode_dirty_sync(inode); 699 mark_inode_dirty_sync(inode);
749out: 700out:
750 kunmap(page); /* mapped in prior call (prepare_write) */
751 if (rc < 0) 701 if (rc < 0)
752 ClearPageUptodate(page); 702 ClearPageUptodate(page);
753 else 703 else
@@ -772,6 +722,7 @@ int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros)
772{ 722{
773 int rc = 0; 723 int rc = 0;
774 struct page *tmp_page; 724 struct page *tmp_page;
725 char *tmp_page_virt;
775 726
776 tmp_page = ecryptfs_get1page(file, index); 727 tmp_page = ecryptfs_get1page(file, index);
777 if (IS_ERR(tmp_page)) { 728 if (IS_ERR(tmp_page)) {
@@ -780,28 +731,26 @@ int write_zeros(struct file *file, pgoff_t index, int start, int num_zeros)
780 rc = PTR_ERR(tmp_page); 731 rc = PTR_ERR(tmp_page);
781 goto out; 732 goto out;
782 } 733 }
783 kmap(tmp_page);
784 rc = ecryptfs_prepare_write(file, tmp_page, start, start + num_zeros); 734 rc = ecryptfs_prepare_write(file, tmp_page, start, start + num_zeros);
785 if (rc) { 735 if (rc) {
786 ecryptfs_printk(KERN_ERR, "Error preparing to write zero's " 736 ecryptfs_printk(KERN_ERR, "Error preparing to write zero's "
787 "to remainder of page at index [0x%.16x]\n", 737 "to remainder of page at index [0x%.16x]\n",
788 index); 738 index);
789 kunmap(tmp_page);
790 page_cache_release(tmp_page); 739 page_cache_release(tmp_page);
791 goto out; 740 goto out;
792 } 741 }
793 memset(((char *)page_address(tmp_page) + start), 0, num_zeros); 742 tmp_page_virt = kmap_atomic(tmp_page, KM_USER0);
743 memset(((char *)tmp_page_virt + start), 0, num_zeros);
744 kunmap_atomic(tmp_page_virt, KM_USER0);
794 rc = ecryptfs_commit_write(file, tmp_page, start, start + num_zeros); 745 rc = ecryptfs_commit_write(file, tmp_page, start, start + num_zeros);
795 if (rc < 0) { 746 if (rc < 0) {
796 ecryptfs_printk(KERN_ERR, "Error attempting to write zero's " 747 ecryptfs_printk(KERN_ERR, "Error attempting to write zero's "
797 "to remainder of page at index [0x%.16x]\n", 748 "to remainder of page at index [0x%.16x]\n",
798 index); 749 index);
799 kunmap(tmp_page);
800 page_cache_release(tmp_page); 750 page_cache_release(tmp_page);
801 goto out; 751 goto out;
802 } 752 }
803 rc = 0; 753 rc = 0;
804 kunmap(tmp_page);
805 page_cache_release(tmp_page); 754 page_cache_release(tmp_page);
806out: 755out:
807 return rc; 756 return rc;